Hi Calcite Community Developers,

I have JSON array, which I  like to use as a table for query like "select *
from jsonTable".
I followed as given tutorials (youtube
<https://www.youtube.com/watch?v=p1O3E33FIs8>) but got a
ClassCastException [ com.google.gson.JsonObject cannot be cast to
[Ljava.lang.Object]
I checked implementations of org.apache.calcite.schema.ScannableTable which
can support for JsonArray. but didn't find any.

Any help would be appreciated.

// My code snippet .

JsonAray jsonArray = // JsonArray consists of employee details

RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl();

RelDataType tableType = typeFactory.builder()
    .add("name", SqlTypeName.VARCHAR)
    .add("dob",SqlTypeName.TIMESTAMP)
    .add("age",SqlTypeName.INTEGER)
    .build();
ListTable jsonTable = new ListTable(tableType,jsonArray);
getConnection().getRootSchema().add("jsonTable",jsonTable);


ListTable class :

public class ListTable extends AbstractTable implements ScannableTable {
  private final RelDataType rowType;
  private final JsonArray data;

@Override

public Enumerable scan(final DataContext root) { return
Linq4j.asEnumerable(data);}
@Override

public RelDataType getRowType(final RelDataTypeFactory typeFactory) {
return rowType;}

}


Reference for tutorials : youtube
<https://www.youtube.com/watch?v=p1O3E33FIs8> and github
<https://github.com/zabetak/calcite/blob/demo-january-2021/core/src/test/java/org/apache/calcite/examples/foodmart/java/EndToEndExampleBindable.java>


Regards,

Kartik

Reply via email to