2017-07-28 11 views
3

を使用してMongoDBのデータを照会私はMongoDBの接続を取得することができ、ノードApache Calcite |リレーショナル代数

(LogicalTableScan(table=[[enlivenDev, collection1]])) 

を取得することができるが、私は、ノードを実行すると、私は、nullポインタ例外を取得しています。 java.sqlのヌル:クエリの実行中に例外:

完全なコード:MongoのDBコレクション SEVEREのrelnodeを実行しながら

private void executeMongoDB(){ 
     final FrameworkConfig config = mongoConfig().build(); 
     final RelBuilder builder = RelBuilder.create(config); 
     final RelNode node = builder.scan("collection1").build(); 
     System.out.println(RelOptUtil.toString(node)); 
     PreparedStatement ps = RelRunners.run(node); 
     ResultSet resultSet = ps.executeQuery(); 
} 
    public static Frameworks.ConfigBuilder mongoConfig() { 
      final SchemaPlus rootSchema = Frameworks.createRootSchema(true); 
      org.apache.calcite.tools.Frameworks.ConfigBuilder configBuilder =Frameworks.newConfigBuilder() 
        .parserConfig(SqlParser.Config.DEFAULT) 
        .defaultSchema(
         MongoDBConnection.addMongoSchema(rootSchema, CalciteAssert.SchemaSpec.MONGO_DB)) 
        .traitDefs((List<RelTraitDef>) null) 
        .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2)); 
      return configBuilder; 
     } 
public static SchemaPlus addMongoSchema(SchemaPlus rootSchema, SchemaSpec schema) { 
     switch (schema) { 
     case MONGO_DB: 
      return rootSchema.add("enlivenDev", 
        MongoSchemaFactory.create(rootSchema, "192.168.1.01", "enlivenDev", 27017, "mgp", "mg1")); 
     default: 
      throw new AssertionError("unknown schema " + schema); 
     } 
    } 

上記のコードから次の例外を取得するには、ヌル値を取得するスキーマがあります。 SQLException:クエリの実行中に例外が発生しました:null at org.apache.calcite.avatica.Helper.createException(Helper.java:56) at org.apache.calcite.avatica.Helper.createException(Helper.java:41) at org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:540) at org.apache.calcite.avatica.AvaticaPreparedStatement.executeQuery(AvaticaPreparedStatement.java:133) at org.ramyam.eis.core.ApachecalcitePOC.processMongoDB(ApachecalcitePOC.java:106) at org.ramyam.eis.core。 ApachecalcitePOC.main(ApachecalcitePOC.java:42)によって引き起こさ :Baz.bindでorg.apache.calcite.schema.Schemas.queryableでjava.lang.NullPointerExceptionが (Schemas.java:232) (不明なソース) でorg.apache.calcite.jdbc.CalcitePrepare $ CalciteSignature.enumerable(CalcitePrepare.java:335) at org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:294) at org.apache.calcite.jdbc。 CalciteMetaImpl._createIterable(CalciteMetaImpl.java:559) at org.apac org.apache.calcite.jdbc.CalciteResultSet.executeでorg.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:204) でhe.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:550) ( org.apache.calcite.avatica.AvaticaConnection.executeQueryInternalでorg.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:44) でCalciteResultSet.java:67) (AvaticaConnection.java:536)

+0

完全な例外を表示できますか? –

+0

は完全な例外を追加しました –

+0

誰かがこれを手伝ってくれます。 –

答えて

0

これは助けてください:

public void useCalcite(String modelPath) { 
    Connection connection = DriverManager.getConnection("jdbc:calcite:model=" + modelPath); 
    CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); 
    String query = "select count(*) from zips"; 
    Statement statement = calciteConnection.createStatement(); 
    ResultSet result = statement.executeQuery(query); 
    ... 
} 

あなたのコレクションのモデルが必要です。このように:model-example モデルファイルには、mongodbへの接続を確立するために必要なすべてのデータが含まれています。

関連する問題