[calcite] branch main updated: [CALCITE-5391] JoinOnUniqueToSemiJoinRule should preserve field names, if possible

2022-11-26 Thread libenchao
This is an automated email from the ASF dual-hosted git repository.

libenchao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 725b71e5af [CALCITE-5391] JoinOnUniqueToSemiJoinRule should preserve 
field names, if possible
725b71e5af is described below

commit 725b71e5af13f2b8725a8da9762c21659c52e507
Author: Scott Reynolds 
AuthorDate: Fri Nov 18 15:12:45 2022 -0800

[CALCITE-5391] JoinOnUniqueToSemiJoinRule should preserve field names, if 
possible

Why:
When rewriting the query for a semi join, the
`JoinOnUniqueToSemiJoinRule` pushes a new project via
`RelBuilder`. This project is *almost* a good copy of the original
`Project` -- it is just missing the field names.

How:
This change uses `RelDataType` of the `Project` to get the field names
for the new `Project` pushed on the `Relbuilder` stack. This is
similar to what is done in `SemiJoinRule#perform`
---
 .../org/apache/calcite/rel/rules/SemiJoinRule.java |  2 +-
 .../org/apache/calcite/test/RelOptRulesTest.java   | 15 
 .../org/apache/calcite/test/RelOptRulesTest.xml| 27 ++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
index ef2623a710..d6f8941327 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
@@ -283,7 +283,7 @@ public abstract class SemiJoinRule
 default:
   throw new AssertionError(join.getJoinType());
 }
-builder.project(project.getProjects());
+builder.project(project.getProjects(), 
project.getRowType().getFieldNames());
 call.transformTo(builder.build());
   }
 }
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index a1262be913..08dd3edb15 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -1181,6 +1181,21 @@ class RelOptRulesTest extends RelOptTestBase {
 .check();
   }
 
+  /**
+   * Test case of
+   * https://issues.apache.org/jira/browse/CALCITE-5391";>[CALCITE-5391]
+   * JoinOnUniqueToSemiJoinRule should preserve field names, if possible. 
*/
+  @Test void testSemiJoinRuleWithJoinOnUniqueInputWithAlias() {
+final String sql = "select emp.deptno as department_id, emp.sal as 
salary\n"
++ "from emp\n"
++ "where exists(select * from dept where emp.deptno = dept.deptno)";
+sql(sql)
+  .withDecorrelate(true)
+  .withTrim(true)
+  .withRule(CoreRules.JOIN_ON_UNIQUE_TO_SEMI_JOIN)
+  .check();
+  }
+
   /** Test case for
* https://issues.apache.org/jira/browse/CALCITE-1495";>[CALCITE-1495]
* SemiJoinRule should not apply to RIGHT and FULL JOIN. */
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 27010f6367..333a84b07d 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -12362,6 +12362,33 @@ LogicalJoin(condition=[=($7, $9)], joinType=[semi])
   LogicalTableScan(table=[[CATALOG, SALES, EMP]])
   LogicalProject(DEPTNO=[$0])
 LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+]]>
+
+  
+  
+
+  
+
+
+  
+
+
+  
 
   



[GitHub] [calcite] libenchao merged pull request #2975: [CALCITE-5391] JoinOnUniqueToSemiJoinRule should preserve field names, if possible

2022-11-26 Thread GitBox


libenchao merged PR #2975:
URL: https://github.com/apache/calcite/pull/2975


-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] libenchao commented on a diff in pull request #2977: [CALCITE-5388] No result when using ROW_NUMBER in two common table expressions

2022-11-26 Thread GitBox


libenchao commented on code in PR #2977:
URL: https://github.com/apache/calcite/pull/2977#discussion_r1032795142


##
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java:
##
@@ -693,7 +696,7 @@ private static Pair 
getPartitionIterator(
 }
 Expression multiMap_ =
 builder.append(
-"multiMap", Expressions.new_(SortedMultiMap.class));
+"multiMap", Expressions.new_(SortedMultiMap.class), false);

Review Comment:
   Current test case would success without this change, it would be good to 
have a test to cover this change.



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli opened a new pull request, #2983: [CALCITE-5395] RelToSql converter fails when SELECT * is under a semi…

2022-11-26 Thread GitBox


JiajunBernoulli opened a new pull request, #2983:
URL: https://github.com/apache/calcite/pull/2983

   …-join node


-- 
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-unsubscr...@calcite.apache.org

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