[ 
https://issues.apache.org/jira/browse/CALCITE-3875?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17066951#comment-17066951
 ] 

Julian Hyde edited comment on CALCITE-3875 at 3/25/20, 6:22 PM:
----------------------------------------------------------------

I agree that such a utility would be useful. However, it will be messy and will 
have a lot of dependencies, so I think it should live with the test code (e.g. 
next to {{class TestUtil}}).  I'm not sure that a classic visitor would work - 
we'd have to add a lot of junky code to the RelNode classes. Probably a utility 
with a big "switch", or dynamic dispatch to methods (see 
{{RelToSqlConverter.dispatch(RelNode)}}).

There are two possible modes. One is to create the exact {{RelNode}}, by 
calling e.g. {{LogicalProject.create}}. The other is to use the nearest 
equivalent {{RelBuilder}} method, e.g. calling {{relBuilder.project(...)}}. The 
latter produces nicer code, but the former may be needed to reproduce some 
gnarly bugs that depend on exact field names or column types.

Probably best to do the former, but generate code like 
{{relBuilder.push(LogicalProject.create(...))}} at each step, so that someone 
can massage the code to use {{relBuilder}} calls if it makes the code simpler 
and still reproduces the bug.


was (Author: julianhyde):
I agree that such a utility would be useful. However, it will be messy and will 
have a lot of dependencies, so I think it should live with the test code (e.g. 
next to {{class TestUtil}}).  I'm not sure that a classic visitor would work - 
we'd have to add a lot of junky code to the RelNode classes. Probably a utility 
with a big "switch", or dynamic dispatch to methods (see 
{{RelToSqlConverter.dispatch(RelNode)}}).

> Create visitor to emit java code that would reproduce the visited rel
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-3875
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3875
>             Project: Calcite
>          Issue Type: New Feature
>    Affects Versions: 1.22.0
>            Reporter: Justin Swett
>            Priority: Minor
>
> It would be nice to have a visitor that would emit java code that could be 
> used to reproduce the visited rel node, e.g.
> Something like:
> {code:java}
>     ...
>     String javaCode = RelOptUtil.toCode( myComplicatedRel );
>     println(javaCode);
>     // outputs something
>     final RelBuilder builder = relBuilder();
>     final RelNode root = builder
>         .scan("EMP")
>         .aggregate(builder.groupKey(),
>             builder.aggregateCall(SqlStdOperatorTable.SUM0, false, false, 
> null,
>                 "s", builder.field(3)))
>         .build();
> {code}
> This could be useful setting up reproducible test cases that are somewhat 
> tricky to recreate in the wild.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to