Hongze Zhang created CALCITE-2485:
-------------------------------------

             Summary: Missing Object-to-String convertion in 
ElasticsearchEnumerators.convert(Object o, Class clazz)
                 Key: CALCITE-2485
                 URL: https://issues.apache.org/jira/browse/CALCITE-2485
             Project: Calcite
          Issue Type: Bug
          Components: elasticsearch-adapter
    Affects Versions: 1.17.0
            Reporter: Hongze Zhang
            Assignee: Julian Hyde


SQL text:

{code:sql}
SELECT a."city_str", b."col" FROM (SELECT cast(_MAP['city'] AS VARCHAR(20)) AS 
"city_str" FROM ES_SCHEMA."es_table" LIMIT 10) a CROSS JOIN (SELECT "col" FROM 
DRUID_SCHEMA."druid_table" LIMIT 10) b;
{code}

Explain plan:

{code}
EnumerableCalc(expr#0..1=[{inputs}], city_str=[$t1], field5=[$t0])
  EnumerableJoin(condition=[true], joinType=[inner])
    EnumerableInterpreter
      DruidQuery(table=[[DRUID_SCHEMA, druid_table]], 
intervals=[[1900-01-01T00:00:00.000Z/3000-01-01T00:00:00.000Z]], 
projects=[[$11]], fetch=[10])
    ElasticsearchToEnumerableConverter
      ElasticsearchProject(city_str=[CAST(ITEM($0, 'city')):VARCHAR(20) 
CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary"])
        ElasticsearchSort(fetch=[10])
          ElasticsearchTableScan(table=[[ES_SCHEMA, es_table]])
{code}

Run into exception:
{code}
  <init>:58, ClassCastException (java.lang)
  apply:-1, Baz$2
  toLookup_:2662, EnumerableDefaults (org.apache.calcite.linq4j)
  toLookup:2652, EnumerableDefaults (org.apache.calcite.linq4j)
  toLookup:2628, EnumerableDefaults (org.apache.calcite.linq4j)
  toLookup:705, DefaultEnumerable (org.apache.calcite.linq4j)
  enumerator:1074, EnumerableDefaults$6 (org.apache.calcite.linq4j)
  <init>:-1, Baz$4$1
  enumerator:-1, Baz$4
  iterator:33, AbstractEnumerable (org.apache.calcite.linq4j)
  createCursor:90, MetaImpl (org.apache.calcite.avatica)
  execute:184, AvaticaResultSet (org.apache.calcite.avatica)
  execute:64, CalciteResultSet (org.apache.calcite.jdbc)
  execute:43, CalciteResultSet (org.apache.calcite.jdbc)
  execute:667, AvaticaConnection$1 (org.apache.calcite.avatica)
  prepareAndExecute:566, CalciteMetaImpl (org.apache.calcite.jdbc)
  prepareAndExecuteInternal:675, AvaticaConnection (org.apache.calcite.avatica)
  executeInternal:156, AvaticaStatement (org.apache.calcite.avatica)
  execute:217, AvaticaStatement (org.apache.calcite.avatica)
  execute:823, Commands (sqlline)
  sql:733, Commands (sqlline)
  dispatch:795, SqlLine (sqlline)
  begin:668, SqlLine (sqlline)
  start:373, SqlLine (sqlline)
  main:265, SqlLine (sqlline)
{code}
  
Reason:

# The logic of CAST function is actually to be done in method  
ElasticsearchEnumerators.convert(Object o, Class clazz) in Elasticsearch 
Adaptor;
# Map-to-String convertion is missing in that method;
# Because of 1 and 2, the hit map returned from 
ElasticsearchEnumerators.singletonGetter is directly returned to join 
enumerator;
# The implementation of EnumerableJoin performs a forcible type casting on 
select keys via method PhysType.generateAccessor(List<Integer> fields);
# The casting is from raw type to derived type of RexNode, which means 
EnumerableJoin forces a Map-to-String casting in this case.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to