You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2015/04/02 00:07:52 UTC
svn commit: r1670783 -
/hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/PlanModifierForASTConv.java
Author: hashutosh
Date: Wed Apr 1 22:07:52 2015
New Revision: 1670783
URL: http://svn.apache.org/r1670783
Log:
HIVE-10183 : [CBO] self-join failing in a test case (Ashutosh Chauhan)
Modified:
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/PlanModifierForASTConv.java
Modified: hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/PlanModifierForASTConv.java
URL: http://svn.apache.org/viewvc/hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/PlanModifierForASTConv.java?rev=1670783&r1=1670782&r2=1670783&view=diff
==============================================================================
--- hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/PlanModifierForASTConv.java (original)
+++ hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/PlanModifierForASTConv.java Wed Apr 1 22:07:52 2015
@@ -50,9 +50,11 @@ import org.apache.commons.logging.LogFac
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException;
import org.apache.hadoop.hive.ql.optimizer.calcite.HiveCalciteUtil;
+import org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveAggregate;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSort;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
import com.google.common.collect.ImmutableList;
@@ -95,6 +97,23 @@ public class PlanModifierForASTConv {
return newTopNode;
}
+ private static String getTblAlias(RelNode rel) {
+
+ if (null == rel) {
+ return null;
+ }
+ if (rel instanceof HiveTableScan) {
+ return ((RelOptHiveTable)((HiveTableScan)rel).getTable()).getTableAlias();
+ }
+ if (rel instanceof Project) {
+ return null;
+ }
+ if (rel.getInputs().size() == 1) {
+ return getTblAlias(rel.getInput(0));
+ }
+ return null;
+ }
+
private static void convertOpTree(RelNode rel, RelNode parent) {
if (rel instanceof HepRelVertex) {
@@ -103,6 +122,12 @@ public class PlanModifierForASTConv {
if (!validJoinParent(rel, parent)) {
introduceDerivedTable(rel, parent);
}
+ String leftChild = getTblAlias(((Join)rel).getLeft());
+ if (null != leftChild && leftChild.equalsIgnoreCase(getTblAlias(((Join)rel).getRight()))) {
+ // introduce derived table above one child, if this is self-join
+ // since user provided aliases are lost at this point.
+ introduceDerivedTable(((Join)rel).getLeft(), rel);
+ }
} else if (rel instanceof MultiJoin) {
throw new RuntimeException("Found MultiJoin");
} else if (rel instanceof RelSubset) {