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

Julian Hyde commented on CALCITE-4047:
--------------------------------------

Please improve the title and description indicating what you were doing that 
caused this bug. As it stands it is not very useful for other people who may 
run into this.

[~jamie12221] Having the planner continue in the presence of errors is not 
practical. Please provide details so that we can reproduce and fix the case. 
Please remember that we are all volunteers.

> at 
> org.apache.calcite.rel.rules.PushProjector.getAdjustments(java.lang.ArrayIndexOutOfBoundsException:
>  0)
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4047
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4047
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.23.0
>            Reporter: jamie12221
>            Priority: Trivial
>
>  
>  
> {code:java}
>   28:LogicalUnion(all=[true])
>     21:LogicalProject
>       20:LogicalTableScan(table=[[db1]])
>     23:LogicalProject
>       22:LogicalTableScan(table=[[db2]])
>     25:LogicalProject
>       24:LogicalTableScan(table=[[db3]])
>     27:LogicalProject
>       26:LogicalTableScan(table=[[db3]])
> {code}
>  
>  
> {code:java}
> 16:32:01 T=noBindingExecutor0 [org.apache.calcite.plan.RelOptPlanner fireRule 
> at 324]-[DEBUG] call#3: Apply rule [ProjectSetOpTransposeRule] to 
> [rel#44:LogicalProject.NONE.[](input=HepRelVertex#43,exprs=[1]), 
> rel#42:LogicalUnion.NONE.[](input#0=HepRelVertex#32,input#1=HepRelVertex#35,input#2=HepRelVertex#38,input#3=HepRelVertex#41,all=true)]16:32:01
>  T=noBindingExecutor0 [io.mycat.proxy.session.Session setLastMessage at 
> 122]-[ERROR] java.lang.ArrayIndexOutOfBoundsException: 0 at 
> org.apache.calcite.rel.rules.PushProjector.getAdjustments(PushProjector.java:572)
>  at 
> org.apache.calcite.rel.rules.ProjectSetOpTransposeRule.onMatch(ProjectSetOpTransposeRule.java:92)
>  at 
> org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:338)
>  at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:540) at 
> org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:405) at 
> org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:270)
>  at 
> org.apache.calcite.plan.hep.HepInstruction$RuleCollection.execute(HepInstruction.java:74)
>  at 
> org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:201) at 
> org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:188)
> {code}
>  
>  
> The test case:
> {code:java}
> public class Test {
>   /***/
>   public static class Author {
>     public final int id;
>     public final String fname;
>     public final String lname;
>     public Author(final int id, final String firstname, final String 
> lastname) {
>       this.id = id;
>       this.fname = firstname;
>       this.lname = lastname;
>     }
>   }
>   /***/
>   public static class Book {
>     public final int id;
>     public final String title;
>     public final int year;
>     public final Author author;
>     public Book(final int id, final String title, final int year, final 
> Author author) {
>       this.id = id;
>       this.title = title;
>       this.year = year;
>       this.author = author;
>     }
>   }
>   /***/
>   public static class BookStore {
>     public final Author[] author = new Author[]{
>         new Author(1, "Victor", "Hugo"),
>         new Author(2, "Alexandre", "Dumas")
>     };
>     public final Book[] book = new Book[]{
>         new Book(1, "Les Miserables", 1862, author[0]),
>         new Book(2, "The Hunchback of Notre-Dame", 1829, author[0]),
>         new Book(3, "The Last Day of a Condemned Man", 1829, author[0]),
>         new Book(4, "The three Musketeers", 1844, author[1]),
>         new Book(5, "The Count of Monte Cristo", 1884, author[1])
>     };
>   }
>   @org.junit.Test
>   public void example() throws Exception {
>     CalciteSchema schema = CalciteSchema.createRootSchema(true);
>     schema.add("bs", new ReflectiveSchema(new BookStore()));
>     RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl();
>     Properties props = new Properties();
>     props.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), 
> "false");
>     CalciteConnectionConfig config = new CalciteConnectionConfigImpl(props);
>     CalciteCatalogReader catalogReader = new CalciteCatalogReader(schema,
>         Collections.singletonList("bs"),
>         typeFactory, config);
>     RelOptCluster cluster = newCluster(typeFactory);
>     RelBuilder relBuilder = 
> SqlToRelConverter.Config.DEFAULT.getRelBuilderFactory().create(cluster, 
> catalogReader);
>     SchemaOnlyDataContext schemaOnlyDataContext = new 
> SchemaOnlyDataContext(schema);
>     Assert.assertEquals(5, new Interpreter(schemaOnlyDataContext, relBuilder
>             .scan("Book").build()).count());
>     RelNode relNode = relBuilder
>             .scan("Book").project()
>             .scan("Book").project()
>             .scan("Book").project()
>             .union(true, 3)
>             .project(ImmutableList.of(),ImmutableList.of(),true)
>             .build();
>     HepProgramBuilder builder = new HepProgramBuilder();
>     builder.addRuleInstance(ProjectSetOpTransposeRule.INSTANCE);
>     builder.addRuleInstance(ProjectFilterTransposeRule.INSTANCE);
>     builder.addRuleInstance(ProjectJoinTransposeRule.INSTANCE);
>     builder.addRuleInstance(ProjectCorrelateTransposeRule.INSTANCE);
>     HepProgram program = builder.build();
>     HepPlanner planner = new HepPlanner(program);
>     planner.setRoot(relNode);
>     relNode = planner.findBestExp();
>     Assert.assertEquals(15, new Interpreter(schemaOnlyDataContext,relNode 
> ).count());
>   }
>   private static RelOptCluster newCluster(RelDataTypeFactory factory) {
>     RelOptPlanner planner = new VolcanoPlanner();
>     planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
>     return RelOptCluster.create(planner, new RexBuilder(factory));
>   }
>   private static final RelOptTable.ViewExpander NOOP_EXPANDER = new 
> RelOptTable.ViewExpander() {
>     @Override public RelRoot expandView(final RelDataType rowType, final 
> String queryString,
>         final List<String> schemaPath,
>         final List<String> viewPath) {
>       return null;
>     }
>   };
>   /**
>    * A simple data context only with schema information.
>    */
>   private static final class SchemaOnlyDataContext implements DataContext {
>     private final SchemaPlus schema;
>     SchemaOnlyDataContext(CalciteSchema calciteSchema) {
>       this.schema = calciteSchema.plus();
>     }
>     @Override public SchemaPlus getRootSchema() {
>       return schema;
>     }
>     @Override public JavaTypeFactory getTypeFactory() {
>       return  new JavaTypeFactoryImpl();
>     }
>     @Override public QueryProvider getQueryProvider() {
>       return null;
>     }
>     @Override public Object get(final String name) {
>       return null;
>     }
>   }
> }
> {code}



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

Reply via email to