Hi Ravi, As Julian already mentioned, we are quite far from what you would like to achieve.
Nevertheless, I would like to mention that you can model certain kind of loops and recursion using the RepeatUnion [1] and Spool [2] relational expressions. Note that these APIs are experimental. Moreover, if your end goal is to push the computation in a DBMS, I have to warn you that the code to translate these expressions back to SQL is not there yet. Best, Stamatis [1] https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/core/RepeatUnion.java [2] https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/core/Spool.java On Mon, Apr 20, 2020 at 8:08 PM Julian Hyde <jh...@apache.org> wrote: > Calcite relational expressions can represent SELECT, INSERT etc. but not > procedural code. It’s a direction we could consider going. > > RexProgram is the closest thing we currently have to procedural code in > the algebra - single assignment of variables, use of variables in > expressions assigning to other variables - but it is a long way short > because there are no loops. > > > On Apr 19, 2020, at 12:47 PM, Ravi Kapoor <kapoorrav...@gmail.com> > wrote: > > > > Hi Team, > > > > I have my use where I need to convert my dialect specific stored > procedure > > constructs like while loop, If then else to Rel expression > > > > Basically this can contain control flow statements like below > > > > DECLARE heads BOOL; > > DECLARE heads_count INT64 DEFAULT 0; > > LOOP > > SET heads = RAND() < 0.5; > > IF heads THEN > > SELECT 'Heads!'; > > SET heads_count = heads_count + 1; > > ELSE > > SELECT 'Tails!'; > > BREAK; > > END IF; > > END LOOP; > > SELECT CONCAT(CAST(heads_count AS STRING), ' heads in a row'); > > > > > > I can create a Java AST model from the linq4j provided by calcite however > > this is only going to generate Java Result and I believe its only used by > > the calcite for relational expressions of enumerable calling convention > > which is used by adapters which does not support core relational > operations > > right? > > > > Is there a way I can convert the stored proc constructs into some > canonical > > form like Rel Tree and back to Stored proc of target dialect. > > -- > > > > Thanks, > > Ravi > >