2017-04-04 48 views
0

我正在嘗試使用ReflectiveSchema創建一個簡單的模式,然後嘗試使用Groovy作爲我的編程語言來投影一個Employee「table」。下面的代碼。Apache Calcite - ReflectiveSchema StackoverflowError

class CalciteDemo { 
    String doDemo() {   
     RelNode node = new CalciteAlgebraBuilder().build() 
     return RelOptUtil.toString(node)     
    } 

    class DummySchema { 
     public final Employee[] emp = [new Employee(1, "Ting"), new Employee(2, "Tong")] 

     @Override 
     String toString() { 
      return "DummySchema" 
     } 

     class Employee { 
      Employee(int id, String name) { 
       this.id = id 
       this.name = name 
      } 
      public final int id 
      public final String name 
     } 
    } 

    class CalciteAlgebraBuilder {   
     FrameworkConfig config 

     CalciteAlgebraBuilder() {    
      SchemaPlus rootSchema = Frameworks.createRootSchema(true) 
      Schema schema = new ReflectiveSchema(new DummySchema()) 
      SchemaPlus rootPlusDummy = rootSchema.add("dummySchema", schema) 
      this.config = Frameworks.newConfigBuilder().parserConfig(SqlParser.Config.DEFAULT).defaultSchema(rootPlusDummy).traitDefs((List<RelTraitDef>)null).build() 
     } 

     RelNode build() { 
      RelBuilder.create(config).scan("emp").build() 
     } 
    } 
} 

我似乎正確地傳遞在「模式」對象的ReflectiveSchema類的構造函數,但我認爲它的失敗嘗試獲取Employee類的領域。

這裏的錯誤

java.lang.StackOverflowError 
    at java.lang.Class.copyFields(Class.java:3115) 
    at java.lang.Class.getFields(Class.java:1557) 
    at org.apache.calcite.jdbc.JavaTypeFactoryImpl.createStructType(JavaTypeFactoryImpl.java:76) 
    at org.apache.calcite.jdbc.JavaTypeFactoryImpl.createType(JavaTypeFactoryImpl.java:160) 
    at org.apache.calcite.jdbc.JavaTypeFactoryImpl.createType(JavaTypeFactoryImpl.java:151) 
    at org.apache.calcite.jdbc.JavaTypeFactoryImpl.createStructType(JavaTypeFactoryImpl.java:84) 
    at org.apache.calcite.jdbc.JavaTypeFactoryImpl.createType(JavaTypeFactoryImpl.java:160) 
    at org.apache.calcite.jdbc.JavaTypeFactoryImpl.createStructType(JavaTypeFactoryImpl.java:84) 

什麼是錯的這個例子嗎?

回答

0

似乎只通過將Employee級移動到上面的級別,即。使其成爲DummySchema課程的兄弟姐妹,使問題消失。

我認爲編寫Calcite的org.apache.calcite.jdbc.JavaTypeFactoryImpl的方式並不能很好地處理Groovy的內部字段。