[
https://issues.apache.org/jira/browse/CALCITE-726?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14544768#comment-14544768
]
Julian Hyde commented on CALCITE-726:
-------------------------------------
The cause of the problem seems to be that I added SemiJoin.create. It uses
cluster.traitSetOf(Convention.NONE) rather than the left.getTraitSet(). This is
"correct" behavior, but it breaks Hive, because Hive has been creating a
SemiJoin with HiveRelNode.CONVENTION.
The ideal solution would be to create a class HiveSemiJoin. A temporary
solution is for Hive to use a SemiJoinFactory that creates SemiJoins that
inherit traits from the LHS. The following patch does that.
{noformat}
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveProject.java
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveProject.java
index cf0c462..8ffb3ef 100644
---
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveProject.java
+++
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveProject.java
@@ -68,6 +68,8 @@
public HiveProject(RelOptCluster cluster, RelTraitSet traitSet, RelNode
child,
List<? extends RexNode> exps, RelDataType rowType, int flags) {
super(cluster, traitSet, child, exps, rowType, flags);
+ assert traitSet.containsIfApplicable(HiveRelNode.CONVENTION);
virtualCols = ImmutableList.copyOf(HiveCalciteUtil.getVirtualCols(exps));
}
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
index 6e6923c..9b052b3 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
@@ -36,6 +36,7 @@
import org.antlr.runtime.tree.TreeVisitor;
import org.antlr.runtime.tree.TreeVisitorAction;
+import org.apache.calcite.plan.Convention;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptQuery;
@@ -57,6 +58,7 @@
import org.apache.calcite.rel.core.AggregateCall;
import org.apache.calcite.rel.core.Filter;
import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinInfo;
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.core.RelFactories;
@@ -942,7 +944,7 @@ private RelNode applyPreJoinOrderingTransforms(RelNode
basePlan, RelMetadataProv
// 5. Projection Pruning
RelFieldTrimmer fieldTrimmer = new RelFieldTrimmer(null,
HiveProject.DEFAULT_PROJECT_FACTORY,
HiveFilter.DEFAULT_FILTER_FACTORY, HiveJoin.HIVE_JOIN_FACTORY,
- RelFactories.DEFAULT_SEMI_JOIN_FACTORY,
HiveSort.HIVE_SORT_REL_FACTORY,
+ HiveSemiJoinFactory.INSTANCE, HiveSort.HIVE_SORT_REL_FACTORY,
HiveAggregate.HIVE_AGGR_REL_FACTORY, HiveUnion.UNION_REL_FACTORY);
basePlan = fieldTrimmer.trim(basePlan);
@@ -2958,4 +2960,18 @@ private QBParseInfo getQBParseInfo(QB qb) throws
CalciteSemanticException {
}
}
+ private static class HiveSemiJoinFactory
+ implements RelFactories.SemiJoinFactory {
+ public static final HiveSemiJoinFactory INSTANCE =
+ new HiveSemiJoinFactory();
+
+ public RelNode createSemiJoin(RelNode left, RelNode right,
+ RexNode condition) {
+ final JoinInfo joinInfo = JoinInfo.of(left, right, condition);
+ final RelOptCluster cluster = left.getCluster();
+ // TODO: Create HiveSemiJoin, and call HiveSemiJoin.create here.
+ return new SemiJoin(cluster, left.getTraitSet(), left, right, condition,
+ joinInfo.leftKeys, joinInfo.rightKeys);
+ }
+ }
}
{noformat}
> HiveRelNode.CONVENTION not present in TraitSet
> ----------------------------------------------
>
> Key: CALCITE-726
> URL: https://issues.apache.org/jira/browse/CALCITE-726
> Project: Calcite
> Issue Type: Bug
> Reporter: Jesus Camacho Rodriguez
> Assignee: Julian Hyde
> Fix For: next
>
>
> I have tested the latest Calcite snapshot against Hive.
> We get the following exception when we create a Project
> operator copy, that we were not getting in 1.2:
> {noformat}
> junit.framework.AssertionFailedError: Unexpected exception
> java.lang.AssertionError
> at
> org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject.copy(H
> iveProject.java:169)
> at org.apache.calcite.rel.core.Project.copy(Project.java:110)
> at
> org.apache.calcite.plan.hep.HepPlanner.addRelToGraph(HepPlanner.java:770)
> at
> org.apache.calcite.plan.hep.HepPlanner.addRelToGraph(HepPlanner.java:764)
> at
> org.apache.calcite.plan.hep.HepPlanner.addRelToGraph(HepPlanner.java:764)
> at
> org.apache.calcite.plan.hep.HepPlanner.addRelToGraph(HepPlanner.java:764)
> at org.apache.calcite.plan.hep.HepPlanner.setRoot(HepPlanner.java:150)
> at
> org.apache.hadoop.hive.ql.parse.CalcitePlanner$CalcitePlannerAction.hepPlan
> (CalcitePlanner.java:994)
> at
> org.apache.hadoop.hive.ql.parse.CalcitePlanner$CalcitePlannerAction.applyPr
> eJoinOrderingTransforms(CalcitePlanner.java:951)
> at
> org.apache.hadoop.hive.ql.parse.CalcitePlanner$CalcitePlannerAction.apply(C
> alcitePlanner.java:820)
> at
> org.apache.hadoop.hive.ql.parse.CalcitePlanner$CalcitePlannerAction.apply(C
> alcitePlanner.java:768)
> at org.apache.calcite.tools.Frameworks$1.apply(Frameworks.java:109)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.perform(CalcitePrepareImpl.ja
> va:741)
> at org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:145)
> at org.apache.calcite.tools.Frameworks.withPlanner(Frameworks.java:105)
> at
> org.apache.hadoop.hive.ql.parse.CalcitePlanner.getOptimizedAST(CalcitePlann
> er.java:607)
> at
> org.apache.hadoop.hive.ql.parse.CalcitePlanner.genOPTree(CalcitePlanner.jav
> a:244)
> at
> org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAn
> alyzer.java:10051)
> at
> org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlann
> er.java:207)
> at
> org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAn
> alyzer.java:227)
> at
> org.apache.hadoop.hive.ql.parse.ExplainSemanticAnalyzer.analyzeInternal(Exp
> lainSemanticAnalyzer.java:74)
> at
> org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAn
> alyzer.java:227)
> ...
> {noformat}
> The assertion that is not met is the following:
> {code}
> @Override
> public Project copy(RelTraitSet traitSet, RelNode input, List<RexNode>
> exps,
> RelDataType rowType) {
> assert traitSet.containsIfApplicable(HiveRelNode.CONVENTION);
> return new HiveProject(getCluster(), traitSet, input, exps, rowType,
> getFlags());
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)