3

Are there some examples about calcite cassandra adapters in java code? there are only a sqlline example on the calcite site. thanks very much

leoluan
  • 33
  • 6

1 Answers1

0

Below some basic code to query Cassandra through Calcite using SQL via Avatica/JDBC:

try (Connection connection = DriverManager.getConnection("jdbc:calcite:model=model.json");
     CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
     Statement stmt = connection.createStatement();
     ResultSet rs = stmt.executeQuery("select * from \"test_collection\"")) {

    while (rs.next()) {
      [...]
    }
}

Where model.json is along the line of the example in the documentation.

If you need to use more advanced functionalities (like reasoning on query planning), you have to register your schema, in this way:

SchemaPlus rootSchema = calciteConnection.getRootSchema();
rootSchema.add("CASSANDRA",
               new CassandraSchema("targethostname", "mykeyspace", rootSchema, "CASSANDRA"));

Please note that the information provided in CassandraSchema must match those of model.json. Your queries will need to reference the schema name. So the above query must be written in this way:

"select * from \"cassandra\".\"test_collection\""
Alessandro S.
  • 875
  • 12
  • 24