You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "zoov-w (via GitHub)" <gi...@apache.org> on 2024/02/20 17:33:18 UTC

[PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "zoov-w (via GitHub)" <gi...@apache.org>.
zoov-w commented on code in PR #3696:
URL: https://github.com/apache/calcite/pull/3696#discussion_r1759705606


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java:
##########
@@ -113,8 +113,7 @@ static List<String> elasticsearchFieldNames(final RelDataType rowType) {
     return SqlValidatorUtil.uniquify(
         new AbstractList<String>() {
           @Override public String get(int index) {
-            final String name = rowType.getFieldList().get(index).getName();
-            return name.startsWith("$") ? "_" + name.substring(2) : name;
+            return rowType.getFieldList().get(index).getName();

Review Comment:
   I think it's not works. This function similar to org.apache.calcite.adapter.mongodb.MongoRules#mongoFieldNames which commit-id is ce0eb9c4. Mongodb adapter use it to rename fields name friendly.
   
   
   



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3696:
URL: https://github.com/apache/calcite/pull/3696#issuecomment-2522057021

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3696:
URL: https://github.com/apache/calcite/pull/3696#issuecomment-1954899207

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3696) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3696&resolved=false&inNewCodePeriod=true)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3696&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3696&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3696&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3696)
   
   


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu merged PR #3696:
URL: https://github.com/apache/calcite/pull/3696


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3696:
URL: https://github.com/apache/calcite/pull/3696#issuecomment-1955862733

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3696) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3696&resolved=false&inNewCodePeriod=true)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3696&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3696&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3696&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3696)
   
   


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "rubenada (via GitHub)" <gi...@apache.org>.
rubenada commented on code in PR #3696:
URL: https://github.com/apache/calcite/pull/3696#discussion_r1502433644


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java:
##########
@@ -113,8 +113,7 @@ static List<String> elasticsearchFieldNames(final RelDataType rowType) {
     return SqlValidatorUtil.uniquify(
         new AbstractList<String>() {
           @Override public String get(int index) {
-            final String name = rowType.getFieldList().get(index).getName();
-            return name.startsWith("$") ? "_" + name.substring(2) : name;
+            return rowType.getFieldList().get(index).getName();

Review Comment:
   Before tearing down this chesterton fence... do we know what was the logic behind this piece of code that you propose to remove?



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #3696:
URL: https://github.com/apache/calcite/pull/3696#issuecomment-1955739784

   The tools don't like the way you formatted your code; you can run ./gradlew build to find out what's wrong.


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3696:
URL: https://github.com/apache/calcite/pull/3696#issuecomment-1959418897

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3696) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3696&resolved=false&inNewCodePeriod=true)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3696&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3696&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3696&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3696)
   
   


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #3696:
URL: https://github.com/apache/calcite/pull/3696#issuecomment-2240168191

   What is the status of this PR?


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "zoov-w (via GitHub)" <gi...@apache.org>.
zoov-w commented on code in PR #3696:
URL: https://github.com/apache/calcite/pull/3696#discussion_r1759742374


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java:
##########
@@ -113,8 +113,7 @@ static List<String> elasticsearchFieldNames(final RelDataType rowType) {
     return SqlValidatorUtil.uniquify(
         new AbstractList<String>() {
           @Override public String get(int index) {
-            final String name = rowType.getFieldList().get(index).getName();
-            return name.startsWith("$") ? "_" + name.substring(2) : name;
+            return rowType.getFieldList().get(index).getName();

Review Comment:
   But elasticsearch adapter is different, In my above description,  when join condition push  down to project, _MAP['doc_id'] field name is "$f1",  correspond to "doc_id" field in _source of elasticsearch index. So the value of  fields is ["$f1"],  mappings values is  {"$f1": "doc_id"}, fields and mappings are paramter of   ElasticsearchTable.ElasticsearchQueryable#find.
   
   Function elasticsearchFieldNames called by ElasticsearchToEnumerableConverter transform "$f1" of fields to "_1"  but dose not transform key of mappings. so column value of "$f1" is null.
   
   
   



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3696:
URL: https://github.com/apache/calcite/pull/3696#discussion_r1969736817


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java:
##########
@@ -113,8 +113,7 @@ static List<String> elasticsearchFieldNames(final RelDataType rowType) {
     return SqlValidatorUtil.uniquify(
         new AbstractList<String>() {
           @Override public String get(int index) {
-            final String name = rowType.getFieldList().get(index).getName();
-            return name.startsWith("$") ? "_" + name.substring(2) : name;

Review Comment:
   I had test join operation of elasticsearch,it would return empty result. here name.substring(2) is not right which maybe copy from mongodb(mongodb is $_f1 and elasticsearch is $f1),and here not necessary to do this operation,return rowType.getFieldList().get(index).getName() directly is OK



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "zoov-w (via GitHub)" <gi...@apache.org>.
zoov-w commented on code in PR #3696:
URL: https://github.com/apache/calcite/pull/3696#discussion_r1759705606


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java:
##########
@@ -113,8 +113,7 @@ static List<String> elasticsearchFieldNames(final RelDataType rowType) {
     return SqlValidatorUtil.uniquify(
         new AbstractList<String>() {
           @Override public String get(int index) {
-            final String name = rowType.getFieldList().get(index).getName();
-            return name.startsWith("$") ? "_" + name.substring(2) : name;
+            return rowType.getFieldList().get(index).getName();

Review Comment:
   I think it's not works. This function similar to org.apache.calcite.adapter.mongodb.MongoRules#mongoFieldNames which commit-id is ce0eb9c4.
   
   
   



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3696:
URL: https://github.com/apache/calcite/pull/3696#discussion_r1969736817


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java:
##########
@@ -113,8 +113,7 @@ static List<String> elasticsearchFieldNames(final RelDataType rowType) {
     return SqlValidatorUtil.uniquify(
         new AbstractList<String>() {
           @Override public String get(int index) {
-            final String name = rowType.getFieldList().get(index).getName();
-            return name.startsWith("$") ? "_" + name.substring(2) : name;

Review Comment:
   I had test join operation of elasticsearch,it would return empty result. here name.substring(2) is not right which maybe copy from mongodb(mongodb is $_f1 and elasticsearch is $f1),and here not necessary to do this operation,return rowType.getFieldList().get(index).getName() directly is OK  @mihaibudiu @NobiGo 



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6274] Two Elasticsearch index join return empty result [calcite]

Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on PR #3696:
URL: https://github.com/apache/calcite/pull/3696#issuecomment-2681924469

   Due to this pr is stale for one more year and it is necessary to be fixed, currently maybe can merge this pr or I start a new pr to continue it?  @mihaibudiu @NobiGo 


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org