RexToLixTranslator offers some public static methods to help you translate
things to expressions (Ling4j). E.g. RexToLixTranslator.translateProjects
might be what you need the most.

After you get expressions, a way I know to execute it is by utilizing
Janino [1] to compile expressions to bytecode and execute the bytecode
directly. The following are some code examples how Apache Beam is doing:

1. translate projects to expressions. [2]
2. compile expressions. [3]
3. execute the compiled code. [4]


[1]: https://janino-compiler.github.io/janino/
[2]:
https://github.com/apache/beam/blob/master/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCalcRel.java#L159
[3]:
https://github.com/apache/beam/blob/7c80ecb8c354575e4332f0f1731f1b5a3f0c4362/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCalcRel.java#L232
[4]:
https://github.com/apache/beam/blob/7c80ecb8c354575e4332f0f1731f1b5a3f0c4362/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCalcRel.java#L259


-Rui

On Mon, May 18, 2020 at 7:43 AM Jon Pither <jon.pit...@gmail.com> wrote:

> Hi,
>
> Is it possible for an adapter to leverage RexImpTable to handle
> calculations?
>
> From RexImpTable I can get an Implementor for a given operation in a
> RexCall, but then the implement method that would generate an expression,
> takes a RexToLixTranslator. The RexToLixTranslator has a private
> constructor, so I'm not sure how to get hold of one. I also couldn't find
> any supporting prior art in the various adapters in the code-base.
>
> Does my approach make sense, to want to use Calcite for
> handling calculations across projects, filters & join conditions?
>
> Context is that our database is a rule-engine that runs in-process - I want
> to pass it arbitrary functions that could potentially wrap Linq
> expressions, to implement a wider range of SQL backed by Calcite.
>
> Regards,
>
> Jon.
>

Reply via email to