zoov-w opened a new pull request, #3696:
URL: https://github.com/apache/calcite/pull/3696

   [CALCITE-6274](https://issues.apache.org/jira/browse/CALCITE-6274)
   Two index of Elasticsearch join return empty result even if the data from 
both indexes can match。
   
   create index test_01:
   `
   PUT /test_01/_doc/1
   {
     "doc_id" : 1,
     "doc_desc" : "doc01"
   } 
   `
   
   create index test_02:
   `
   PUT /test_02/_doc/1
   {
     "doc_id" : 1,
     "doc_score" : 90
   } 
   `
   
   execute sql:
   `
   select * from es.test_01 t1 join es.test_02 t2 on cast(t1._MAP['doc_id'] as 
bigint) = cast(t2._MAP['doc_id'] as bigint) 
   `
   
   the code generate by ElasticsearchToEnumerableConverter like this:
   subquery of index test_01:
   `
   {
     return 
((org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.ElasticsearchQueryable)
 org.apache.calcite.schema.Schemas.queryable(root, 
root.getRootSchema().getSubSchema("es"), java.lang.Object[].class, 
"test_01")).find(java.util.Collections.EMPTY_LIST, java.util.Arrays.asList(new 
org.apache.calcite.util.Pair[] {
         new org.apache.calcite.util.Pair(
           "_MAP",
           java.util.Map.class),
         new org.apache.calcite.util.Pair(
           "_1",
           java.lang.Long.class)}), java.util.Arrays.asList(new 
org.apache.calcite.util.Pair[] {
         new org.apache.calcite.util.Pair(
           "doc_id",
           org.apache.calcite.rel.RelFieldCollation.Direction.ASCENDING)}), 
java.util.Collections.EMPTY_LIST, java.util.Arrays.asList(new 
org.apache.calcite.util.Pair[] {}), 
com.google.common.collect.ImmutableMap.of("$f1", "doc_id"), null, null);
   }
   `
   project field names: `"_MAP", "_1"`
   
   subquery of index test_02:
   `
   {
     return 
((org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.ElasticsearchQueryable)
 org.apache.calcite.schema.Schemas.queryable(root, 
root.getRootSchema().getSubSchema("es"), java.lang.Object[].class, 
"test_02")).find(java.util.Collections.EMPTY_LIST, java.util.Arrays.asList(new 
org.apache.calcite.util.Pair[] {
         new org.apache.calcite.util.Pair(
           "_MAP",
           java.util.Map.class),
         new org.apache.calcite.util.Pair(
           "_1",
           java.lang.Long.class)}), java.util.Arrays.asList(new 
org.apache.calcite.util.Pair[] {
         new org.apache.calcite.util.Pair(
           "doc_id",
           org.apache.calcite.rel.RelFieldCollation.Direction.ASCENDING)}), 
java.util.Collections.EMPTY_LIST, java.util.Arrays.asList(new 
org.apache.calcite.util.Pair[] {}), 
com.google.common.collect.ImmutableMap.of("$f1", "doc_id"), null, null);
   }
   `
   project field names: `"_MAP", "_1"`
   
   This 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.ElasticsearchQueryable#find
 function actually execute request, subq-query result  projected according to 
second paramter fields. Field "_1" can not find from subq-query result.  "_1" 
not in mappings {"$f1":"doc_id"}, cause two sub-query join condition value is 
null, so the result of sql is empty.
   
   This PR fix the problem, the sub-query project field names is: `"_MAP", 
"$f1"`. join condition field `$f1` can be find in mappings. The result of sql 
match expectations. 
    
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to