Hi devs,

I am using the ZIPS dataset which is present in calcite rep. below is the
model.json file I have created -

 {
  "version": "1.0",
  "defaultSchema": "elasticsearch1",
  "schemas": [
    {
      "type": "custom",
      "name": "elasticsearch_raw",
      "factory":
"org.apache.calcite.adapter.elasticsearch2.Elasticsearch2SchemaFactory",
      "operand": {
        "coordinates": "{'127.0.0.1': 9300}",
        "userConfig": "{'bulk.flush.max.actions': 25,
'bulk.flush.max.size.mb': 1}",
        "index": "usa"
      }
    },
    {
      "name": "elasticsearch",
      "tables": [
        {
          "name": "ZIPS",
          "type": "view",
          "sql": [
            "select cast(_MAP['CITY'] AS varchar(20)) AS \"CITY\",\n",
            " cast(_MAP['LOC'][0] AS float) AS \"LONGITUDE\",\n",
            " cast(_MAP['LOC'][1] AS float) AS \"LATITUDE\",\n",
            " cast(_MAP['POP'] AS integer) AS \"POP\",\n",
            " cast(_MAP['STATE'] AS varchar(2)) AS \"STATE\",\n",
            " cast(_MAP['IDNUM'] AS varchar(5)) AS \"ID\"\n",
            "from \"elasticsearch_raw\".\"ZIPS\""
          ]
        }
      ]
    }
  ]
}

I am able to retrieve the state ,city from the elastisearch type ZIPS . But
I am not able to retrieve the integer values. I am getting the below error -

0: jdbc:calcite:model=./elasticsearch2/src/te> select POP from
"elasticsearch".ZIPS;
+------------+
|    POP     |
+------------+
java.lang.ClassCastException: java.util.HashMap cannot be cast to
java.lang.Integer
    at
org.apache.calcite.avatica.util.AbstractCursor$IntAccessor.getInt(AbstractCursor.java:531)
    at org.apache.calcite.avatica.AvaticaSite.get(AvaticaSite.java:339)
    at
org.apache.calcite.avatica.AvaticaResultSet.getObject(AvaticaResultSet.java:409)
    at sqlline.Rows$Row.<init>(Rows.java:157)
    at sqlline.IncrementalRows.hasNext(IncrementalRows.java:66)
    at sqlline.TableOutputFormat.print(TableOutputFormat.java:33)
    at sqlline.SqlLine.print(SqlLine.java:1648)
    at sqlline.Commands.execute(Commands.java:834)
    at sqlline.Commands.sql(Commands.java:733)
    at sqlline.SqlLine.dispatch(SqlLine.java:795)
    at sqlline.SqlLine.begin(SqlLine.java:668)
    at sqlline.SqlLine.start(SqlLine.java:373)
    at sqlline.SqlLine.main(SqlLine.java:265)
0: jdbc:calcite:model=./elasticsearch2/src/te> select STATE from
"elasticsearch".ZIPS;
+-------+
| STATE |
+-------+
| {STATE=MA} |
| {STATE=MA} |
| {STATE=MA} |
| {STATE=MA} |
| {STATE=MA} |
| {STATE=MA} |
| {STATE=MA} |
| {STATE=MA} |
| {STATE=MA} |
| {STATE=MA} |
+-------+
10 rows selected (0.355 seconds)


However the varchar values are getting displayed.

Could you please let me know what can be the issue here.

Thanks,
Ashwin

Reply via email to