[GitHub] [calcite] DonnyZone commented on a change in pull request #1988: [CALCITE-4019] Visit SqlInsert with SqlShuttle cause NullPointerException
DonnyZone commented on a change in pull request #1988: URL: https://github.com/apache/calcite/pull/1988#discussion_r430893526 ## File path: core/src/main/java/org/apache/calcite/sql/SqlInsert.java ## @@ -62,7 +62,11 @@ public SqlOperator getOperator() { } public List getOperandList() { -return ImmutableNullableList.of(keywords, targetTable, source, columnList); +if (columnList == null) { Review comment: Thanks for clarification. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] amaliujia commented on a change in pull request #1985: [CALCITE-4011] Support trait propagation for EnumerableProject and EnumerableFilter
amaliujia commented on a change in pull request #1985: URL: https://github.com/apache/calcite/pull/1985#discussion_r430885788 ## File path: core/src/test/resources/org/apache/calcite/test/TopDownOptTest.xml ## @@ -35,6 +35,136 @@ EnumerableLimit(fetch=[5]) EnumerableSortedAggregate(group=[{3}], EXPR$1=[COUNT()]) EnumerableSort(sort0=[$3], dir0=[DESC-nulls-last]) EnumerableTableScan(table=[[CATALOG, SALES, EMP]]) +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + Review comment: `max_sal+1` works like a charm. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] xy2953396112 commented on a change in pull request #1988: [CALCITE-4019] Visit SqlInsert with SqlShuttle cause NullPointerException
xy2953396112 commented on a change in pull request #1988: URL: https://github.com/apache/calcite/pull/1988#discussion_r430880649 ## File path: core/src/main/java/org/apache/calcite/sql/SqlInsert.java ## @@ -62,7 +62,11 @@ public SqlOperator getOperator() { } public List getOperandList() { -return ImmutableNullableList.of(keywords, targetTable, source, columnList); +if (columnList == null) { Review comment: @DonnyZone Thansk for review. targetTable and source should be not null. For example a sql such as `insert into emps` , it can’t be parsed. `insert into emps VALUES (true, 1)` be parsed as SqlInsert, source not 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] XuQianJin-Stars commented on a change in pull request #1964: Site: Add Tencent and TBDS logo in powered-by image
XuQianJin-Stars commented on a change in pull request #1964: URL: https://github.com/apache/calcite/pull/1964#discussion_r430877722 ## File path: site/_docs/powered_by.md ## @@ -137,3 +137,7 @@ It uses Calcite to transparently rewrite queries to use materialized views. is a SQL interface to a https://tinkerpop.apache.org/";>Apache TinkerPop-enabled graph database. + +### TBDS + +[TBDS](https://cloud.tencent.com/product/tbds) (Tencent Big Data Suite) is Big data computing and analysis platform, it uses calcite for query analysis. Review comment: > What does query analysis mean? Parser? or optimizer? SQL parsing and query optimization 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] hsyuan commented on a change in pull request #1964: Site: Add Tencent and TBDS logo in powered-by image
hsyuan commented on a change in pull request #1964: URL: https://github.com/apache/calcite/pull/1964#discussion_r430865452 ## File path: site/_docs/powered_by.md ## @@ -137,3 +137,7 @@ It uses Calcite to transparently rewrite queries to use materialized views. is a SQL interface to a https://tinkerpop.apache.org/";>Apache TinkerPop-enabled graph database. + +### TBDS + +[TBDS](https://cloud.tencent.com/product/tbds) (Tencent Big Data Suite) is Big data computing and analysis platform, it uses calcite for query analysis. Review comment: What does query analysis mean? Parser? or optimizer? 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] xy2953396112 commented on a change in pull request #1987: [CALCITE-4020] Support Calc operator in RelFieldTrimmer
xy2953396112 commented on a change in pull request #1987: URL: https://github.com/apache/calcite/pull/1987#discussion_r430136341 ## File path: core/src/test/java/org/apache/calcite/sql2rel/RelFieldTrimmerTest.java ## @@ -183,4 +190,96 @@ assertThat(trimmed, hasTree(expected)); } + @Test public void testCalcFieldTrimmer0() { +final RelBuilder builder = RelBuilder.create(config().build()); +final RelNode root = +builder.scan("EMP") +.project(builder.field("EMPNO"), builder.field("ENAME"), builder.field("DEPTNO")) +.exchange(RelDistributions.SINGLETON) +.project(builder.field("EMPNO"), builder.field("ENAME")) +.build(); + Review comment: `testCalcFieldTrimmer0` is used for check Project operator. `testCalcFieldTrimmer1` is used for check Filter operator. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] dasch-1 closed pull request #1938: [CALCITE-3946] Add parser support for MULTISET/SET and VOLATILE in CREATE TABLE statements
dasch-1 closed pull request #1938: URL: https://github.com/apache/calcite/pull/1938 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] DonnyZone commented on a change in pull request #1988: [CALCITE-4019] Visit SqlInsert with SqlShuttle cause NullPointerException
DonnyZone commented on a change in pull request #1988: URL: https://github.com/apache/calcite/pull/1988#discussion_r430830028 ## File path: core/src/main/java/org/apache/calcite/sql/SqlInsert.java ## @@ -62,7 +62,11 @@ public SqlOperator getOperator() { } public List getOperandList() { -return ImmutableNullableList.of(keywords, targetTable, source, columnList); +if (columnList == null) { Review comment: Is it possible that `targetTable` is `null` or `source` 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] yanlin-Lynn commented on a change in pull request #1988: [CALCITE-4019] Change SqlInsert getOperandList method
yanlin-Lynn commented on a change in pull request #1988: URL: https://github.com/apache/calcite/pull/1988#discussion_r430126757 ## File path: core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java ## @@ -5747,6 +5748,17 @@ public void subTestIntervalMonthFailsValidation() { .ok("INTERVAL '0' MONTH(0)"); } + @Test void testSqlParserPosPlus() throws Exception { +final String sql = "insert into emps select * from emps"; +final SqlNode sqlNode = getSqlParser(sql).parseStmt(); +sqlNode.accept(new SqlShuttle() { + @Override public SqlNode visit(SqlIdentifier identifier) { +return new SqlIdentifier(identifier.names, +identifier.getParserPosition()); + } +}); + } Review comment: how about add some checks for the result of accept 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] chunweilei commented on a change in pull request #1987: [CALCITE-4020] Support Calc operator in RelFieldTrimmer
chunweilei commented on a change in pull request #1987: URL: https://github.com/apache/calcite/pull/1987#discussion_r430128039 ## File path: core/src/test/java/org/apache/calcite/sql2rel/RelFieldTrimmerTest.java ## @@ -183,4 +190,96 @@ assertThat(trimmed, hasTree(expected)); } + @Test public void testCalcFieldTrimmer0() { +final RelBuilder builder = RelBuilder.create(config().build()); +final RelNode root = +builder.scan("EMP") +.project(builder.field("EMPNO"), builder.field("ENAME"), builder.field("DEPTNO")) +.exchange(RelDistributions.SINGLETON) +.project(builder.field("EMPNO"), builder.field("ENAME")) +.build(); + Review comment: What's the difference between `testCalcFieldTrimmer0 ` and `testCalcFieldTrimmer1`? 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] dasch-1 closed pull request #1984: [CALCITE-3987] Coerce NUMERIC to INTERVAL_DAY in DATE arithmetic
dasch-1 closed pull request #1984: URL: https://github.com/apache/calcite/pull/1984 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] hsyuan merged pull request #1989: [CALCITE-4009] Remove traitset remapping in ProjectJoinTransposeRule
hsyuan merged pull request #1989: URL: https://github.com/apache/calcite/pull/1989 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] amaliujia commented on a change in pull request #1985: [CALCITE-4011] Support trait propagation for EnumerableProject and EnumerableFilter
amaliujia commented on a change in pull request #1985: URL: https://github.com/apache/calcite/pull/1985#discussion_r430092458 ## File path: core/src/test/resources/org/apache/calcite/test/TopDownOptTest.xml ## @@ -35,6 +35,73 @@ EnumerableLimit(fetch=[5]) EnumerableSortedAggregate(group=[{3}], EXPR$1=[COUNT()]) EnumerableSort(sort0=[$3], dir0=[DESC-nulls-last]) EnumerableTableScan(table=[[CATALOG, SALES, EMP]]) +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Review comment: Ah the plan is the same even if remove trait derivation implementation. Honestly I don't have an explanation (still learning top-down optimization). The intention here is I explicitly add another project between the left sorted aggregation and join, to test if the sort collation is derived by Join thus Join can enforce right input has the same collation. (e.g. I add an extra `select ename, job, max_sal from` on top of the left aggregation). Any comment or suggestion on how should a project trait derivation should be properly tested? ## File path: core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java ## @@ -86,4 +100,52 @@ public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // EnumerableCalcRel is always better throw new UnsupportedOperationException(); } + + @Override public Pair> passThroughTraits( + RelTraitSet required) { +RelCollation collation = required.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { + return null; +} +final Mappings.TargetMapping map = +RelOptUtil.permutationIgnoreCast( +getProjects(), getInput().getRowType()); + +// Determine mapping between project input and output fields. If sort +// relies on non-trivial expressions, we can't push. +for (RelFieldCollation fc : collation.getFieldCollations()) { + if (map.getTargetOpt(fc.getFieldIndex()) < 0) { +return null; + } + final RexNode node = getProjects().get(fc.getFieldIndex()); + if (node.isA(SqlKind.CAST)) { +// Check whether it is a monotonic preserving cast, otherwise we cannot push +final RexCall cast = (RexCall) node; +RelFieldCollation newFc = Objects.requireNonNull(RexUtil.apply(map, fc)); +final RexCallBinding binding = +RexCallBinding.create(getCluster().getTypeFactory(), cast, +ImmutableList.of(RelCollations.of(newFc))); +if (cast.getOperator().getMonotonicity(binding) == SqlMonotonicity.NOT_MONOTONIC) { + return null; +} + } +} + +final RelCollation newCollation = collation.apply(map); +return Pair.of(required, ImmutableList.of(required.replace(newCollation))); + } + + @Override public Pair> deriveTraits( + final RelTraitSet childTraits, final int childId) { +RelCollation collation = childTraits.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { + return null; +} + +return Pair.of(getTraitSet().replace(collation), ImmutableList.of(childTraits)); Review comment: Could you explain a bit on why this is not correct based on your query? ## File path: core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableFilter.java ## @@ -68,4 +75,29 @@ public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // EnumerableCalc is always better throw new UnsupportedOperationException(); } + + @Override public Pair> passThroughTraits( + RelTraitSet required) { +RelCollation collation = required.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { + return null; +} + +// Filter, not like Project, does not change on which column that collation defines. +return Pair.of(required, ImmutableList.of(required)); + } + + @Override public Pair> deriveTraits( + final RelTraitSet childTraits, final int
[GitHub] [calcite] dasch-1 closed pull request #1980: [CALCITE-3974] Convert some existing private data fields of AST nodes to be public
dasch-1 closed pull request #1980: URL: https://github.com/apache/calcite/pull/1980 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] amaliujia commented on pull request #1985: [CALCITE-4011] Support trait propagation for EnumerableProject and EnumerableFilter
amaliujia commented on pull request #1985: URL: https://github.com/apache/calcite/pull/1985#issuecomment-633737408 Also implemented traits derivation for both Project and Filter. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] XuQianJin-Stars commented on a change in pull request #1964: Site: Add Tencent and TBDS logo in powered-by image
XuQianJin-Stars commented on a change in pull request #1964: URL: https://github.com/apache/calcite/pull/1964#discussion_r430829950 ## File path: site/_docs/powered_by.md ## @@ -137,3 +137,7 @@ It uses Calcite to transparently rewrite queries to use materialized views. is a SQL interface to a https://tinkerpop.apache.org/";>Apache TinkerPop-enabled graph database. + +### TBDS + +[TBDS](https://cloud.tencent.com/product/tbds) (Tencent Big Data Suite) is Big data computing and analysis platform, it uses calcite for query analysis. Review comment: > How about " is a platform for big data storage and processing. It uses calcite for query analysis."? well ,Let me change it. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] hsyuan commented on a change in pull request #1985: [CALCITE-4011] Support trait propagation for EnumerableProject and EnumerableFilter
hsyuan commented on a change in pull request #1985: URL: https://github.com/apache/calcite/pull/1985#discussion_r430114503 ## File path: core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableFilter.java ## @@ -68,4 +75,29 @@ public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // EnumerableCalc is always better throw new UnsupportedOperationException(); } + + @Override public Pair> passThroughTraits( + RelTraitSet required) { +RelCollation collation = required.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { + return null; +} + +// Filter, not like Project, does not change on which column that collation defines. +return Pair.of(required, ImmutableList.of(required)); + } + + @Override public Pair> deriveTraits( + final RelTraitSet childTraits, final int childId) { +RelCollation collation = childTraits.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { Review comment: I think the` size == 0` check is not necessary. Did you try remove it? ## File path: core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableFilter.java ## @@ -68,4 +75,29 @@ public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // EnumerableCalc is always better throw new UnsupportedOperationException(); } + + @Override public Pair> passThroughTraits( + RelTraitSet required) { +RelCollation collation = required.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { + return null; +} + +// Filter, not like Project, does not change on which column that collation defines. +return Pair.of(required, ImmutableList.of(required)); + } + + @Override public Pair> deriveTraits( + final RelTraitSet childTraits, final int childId) { +RelCollation collation = childTraits.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { + return null; +} + +return Pair.of(getTraitSet().replace(collation), ImmutableList.of(childTraits)); Review comment: Should it just childTraits? ## File path: core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java ## @@ -86,4 +100,52 @@ public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // EnumerableCalcRel is always better throw new UnsupportedOperationException(); } + + @Override public Pair> passThroughTraits( + RelTraitSet required) { +RelCollation collation = required.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { + return null; +} +final Mappings.TargetMapping map = +RelOptUtil.permutationIgnoreCast( +getProjects(), getInput().getRowType()); + +// Determine mapping between project input and output fields. If sort +// relies on non-trivial expressions, we can't push. +for (RelFieldCollation fc : collation.getFieldCollations()) { + if (map.getTargetOpt(fc.getFieldIndex()) < 0) { +return null; + } + final RexNode node = getProjects().get(fc.getFieldIndex()); + if (node.isA(SqlKind.CAST)) { +// Check whether it is a monotonic preserving cast, otherwise we cannot push +final RexCall cast = (RexCall) node; +RelFieldCollation newFc = Objects.requireNonNull(RexUtil.apply(map, fc)); +final RexCallBinding binding = +RexCallBinding.create(getCluster().getTypeFactory(), cast, +ImmutableList.of(RelCollations.of(newFc))); +if (cast.getOperator().getMonotonicity(binding) == SqlMonotonicity.NOT_MONOTONIC) { + return null; +} + } +} + +final RelCollation newCollation = collation.apply(map); +return Pair.of(required, ImmutableList.of(required.replace(newCollation))); + } + + @Override public Pair> deriveTraits( + final RelTraitSet childTraits, final int childId) { +RelCollation collation = childTraits.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { Review comment: same here ## File path: core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableFilter.java ## @@ -68,4 +75,29 @@ public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // EnumerableCalc is always better throw new UnsupportedOperationException(); } + + @Override public Pair> passThroughTraits( + RelTraitSet required) { +RelCollation collation = required.getCollation(); +if (collation == null || collation.getFieldCollations().size() == 0) { + return null; +} + +// Filter, not like Project, does not change on which column that collation defines. +return Pair.of(required, ImmutableList.of(required)); + } + + @Override public
[GitHub] [calcite] yanlin-Lynn commented on pull request #1988: [CALCITE-4019] Change SqlInsert getOperandList method
yanlin-Lynn commented on pull request #1988: URL: https://github.com/apache/calcite/pull/1988#issuecomment-633775868 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] DonnyZone commented on a change in pull request #1964: Site: Add Tencent and TBDS logo in powered-by image
DonnyZone commented on a change in pull request #1964: URL: https://github.com/apache/calcite/pull/1964#discussion_r430827330 ## File path: site/_docs/powered_by.md ## @@ -137,3 +137,7 @@ It uses Calcite to transparently rewrite queries to use materialized views. is a SQL interface to a https://tinkerpop.apache.org/";>Apache TinkerPop-enabled graph database. + +### TBDS + +[TBDS](https://cloud.tencent.com/product/tbds) (Tencent Big Data Suite) is Big data computing and analysis platform, it uses calcite for query analysis. Review comment: How about " is a platform for big data storage and processing. It uses calcite for query analysis."? 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [calcite] xy2953396112 commented on a change in pull request #1988: [CALCITE-4019] Visit SqlInsert with SqlShuttle cause NullPointerException
xy2953396112 commented on a change in pull request #1988: URL: https://github.com/apache/calcite/pull/1988#discussion_r430128274 ## File path: core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java ## @@ -5747,6 +5748,17 @@ public void subTestIntervalMonthFailsValidation() { .ok("INTERVAL '0' MONTH(0)"); } + @Test void testSqlParserPosPlus() throws Exception { +final String sql = "insert into emps select * from emps"; +final SqlNode sqlNode = getSqlParser(sql).parseStmt(); +sqlNode.accept(new SqlShuttle() { + @Override public SqlNode visit(SqlIdentifier identifier) { +return new SqlIdentifier(identifier.names, +identifier.getParserPosition()); + } +}); + } Review comment: Thanks, add check for it. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[calcite] branch master updated: [CALCITE-4009] Remove traitset remapping in ProjectJoinTransposeRule
This is an automated email from the ASF dual-hosted git repository. hyuan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 2b1254b [CALCITE-4009] Remove traitset remapping in ProjectJoinTransposeRule 2b1254b is described below commit 2b1254bdec18f9e869f3287fb8ab471903e97829 Author: Haisheng Yuan AuthorDate: Sun May 24 14:47:51 2020 -0500 [CALCITE-4009] Remove traitset remapping in ProjectJoinTransposeRule Remove traitset mapping that was added to ProjectJoinTransposeRule by CALCITE-3353. Now it becomes obsolete, we should fail fast if that happens. Otherwise, all the downstream projects that uses this rule will be wasted time to deal with traitsets they don't need. --- .../rel/rules/ProjectJoinTransposeRule.java| 40 +- .../org/apache/calcite/test/RelOptRulesTest.java | 49 -- 2 files changed, 2 insertions(+), 87 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java index 5d6510c..b0c1ef3 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java @@ -19,11 +19,6 @@ package org.apache.calcite.rel.rules; import org.apache.calcite.plan.RelOptRule; import org.apache.calcite.plan.RelOptRuleCall; import org.apache.calcite.plan.RelOptUtil; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelCollation; -import org.apache.calcite.rel.RelCollationTraitDef; -import org.apache.calcite.rel.RelCollations; -import org.apache.calcite.rel.RelFieldCollation; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.core.Join; import org.apache.calcite.rel.core.Project; @@ -35,9 +30,7 @@ import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexNode; import org.apache.calcite.rex.RexOver; import org.apache.calcite.rex.RexShuttle; -import org.apache.calcite.rex.RexUtil; import org.apache.calcite.tools.RelBuilderFactory; -import org.apache.calcite.util.mapping.Mappings; import java.util.ArrayList; import java.util.List; @@ -152,40 +145,11 @@ public class ProjectJoinTransposeRule extends RelOptRule implements Transformati projJoinFieldList, adjustments); } -RelTraitSet traits = join.getTraitSet(); -final List originCollations = traits.getTraits(RelCollationTraitDef.INSTANCE); - -if (originCollations != null && !originCollations.isEmpty()) { - List newCollations = new ArrayList<>(); - final int originLeftCnt = join.getLeft().getRowType().getFieldCount(); - final Mappings.TargetMapping leftMapping = RelOptUtil.permutationPushDownProject( - ((Project) leftProjRel).getProjects(), join.getLeft().getRowType(), - 0, 0); - final Mappings.TargetMapping rightMapping = RelOptUtil.permutationPushDownProject( - ((Project) rightProjRel).getProjects(), join.getRight().getRowType(), - originLeftCnt, leftProjRel.getRowType().getFieldCount()); - for (RelCollation collation: originCollations) { -List fc = new ArrayList<>(); -final List fieldCollations = collation.getFieldCollations(); -for (RelFieldCollation relFieldCollation: fieldCollations) { - final int fieldIndex = relFieldCollation.getFieldIndex(); - Mappings.TargetMapping mapping = fieldIndex < originLeftCnt ? leftMapping : rightMapping; - RelFieldCollation newFieldCollation = RexUtil.apply(mapping, relFieldCollation); - if (newFieldCollation == null) { -break; - } - fc.add(newFieldCollation); -} -newCollations.add(RelCollations.of(fc)); - } - if (!newCollations.isEmpty()) { -traits = traits.replace(newCollations); - } -} + // create a new join with the projected children Join newJoinRel = join.copy( -traits, +join.getTraitSet(), newJoinFilter, leftProjRel, rightProjRel, 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 9324d78..0c97896 100644 --- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java +++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java @@ -132,7 +132,6 @@ import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexInputRef; import org.apache.calcite.rex.RexNode; -import org.apache.calcite.rex.RexOver; import org.apache.calcite.runtime.Hook; import org.apache.calcite.sql.SqlFunction; import org.apache.calcite.sql.SqlFunctionCategory;