You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by se...@apache.org on 2017/02/02 02:03:16 UTC
[17/50] [abbrv] hive git commit: HIVE-15735: In some cases,
view objects inside a view do not have parents. (Yongzhi Chen,
reviewed by Aihua Xu)
HIVE-15735: In some cases, view objects inside a view do not have parents. (Yongzhi Chen, reviewed by Aihua Xu)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/77dfbe0b
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/77dfbe0b
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/77dfbe0b
Branch: refs/heads/hive-14535
Commit: 77dfbe0b52ed7098347d734fd5e7f42b3354c67a
Parents: 1c2c485
Author: Yongzhi Chen <yc...@apache.org>
Authored: Thu Jan 26 16:43:52 2017 -0500
Committer: Yongzhi Chen <yc...@apache.org>
Committed: Tue Jan 31 09:07:39 2017 -0500
----------------------------------------------------------------------
.../hadoop/hive/ql/parse/SemanticAnalyzer.java | 4 +++
.../apache/hadoop/hive/ql/plan/PlanUtils.java | 3 +-
.../hadoop/hive/ql/plan/TestViewEntity.java | 37 ++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/77dfbe0b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
index 6c0f300..248dd63 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
@@ -2005,6 +2005,10 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
replaceViewReferenceWithDefinition(qb, tab, tabName, alias);
// This is the last time we'll see the Table objects for views, so add it to the inputs
// now. isInsideView will tell if this view is embedded in another view.
+ // If the view is Inside another view, it should have at least one parent
+ if (qb.isInsideView() && parentInput == null) {
+ parentInput = PlanUtils.getParentViewInfo(getAliasId(alias, qb), viewAliasToInput);
+ }
ReadEntity viewInput = new ReadEntity(tab, parentInput, !qb.isInsideView());
viewInput = PlanUtils.addInput(inputs, viewInput);
aliasToViewInfo.put(alias, new ObjectPair<String, ReadEntity>(fullViewName, viewInput));
http://git-wip-us.apache.org/repos/asf/hive/blob/77dfbe0b/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java
index b2c5865..05d2c81 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java
@@ -1127,7 +1127,8 @@ public final class PlanUtils {
// For eg: for a query like 'select * from V3', where V3 -> V2, V2 -> V1, V1 -> T
// -> implies depends on.
// T's parent would be V1
- for (int pos = 0; pos < aliases.length; pos++) {
+ // do not check last alias in the array for parent can not be itself.
+ for (int pos = 0; pos < aliases.length -1; pos++) {
currentAlias = currentAlias == null ? aliases[pos] : currentAlias + ":" + aliases[pos];
currentAlias = currentAlias.replace(SemanticAnalyzer.SUBQUERY_TAG_1, "")
http://git-wip-us.apache.org/repos/asf/hive/blob/77dfbe0b/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java b/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java
index fa01416..4cc9d72 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java
@@ -168,8 +168,45 @@ public class TestViewEntity {
// table1 and view1 as second read entity
assertEquals("default@" + view1, CheckInputReadEntity.readEntities[1].getName());
assertFalse("Table is not direct input", CheckInputReadEntity.readEntities[1].isDirect());
+ Set<ReadEntity> parents = CheckInputReadEntity.readEntities[1].getParents();
+ assertTrue("Table does not have parent", parents != null && parents.size() > 0);
assertEquals("default@" + tab1, CheckInputReadEntity.readEntities[2].getName());
assertFalse("Table is not direct input", CheckInputReadEntity.readEntities[2].isDirect());
}
+
+ /**
+ * Verify that the the query with the subquery inside a view will have the correct
+ * direct and indirect inputs.
+ * @throws Exception
+ */
+ @Test
+ public void testUnionAllInSubView() throws Exception {
+ String prefix = "tvunionallinsubview" + NAME_PREFIX;
+ final String tab1 = prefix + "t";
+ final String view1 = prefix + "v";
+ final String view2 = prefix + "v2";
+
+ int ret = driver.run("create table " + tab1 + "(id int)").getResponseCode();
+ assertEquals("Checking command success", 0, ret);
+ ret = driver.run("create view " + view1 + " as select * from " + tab1).getResponseCode();
+ assertEquals("Checking command success", 0, ret);
+
+ ret = driver.run("create view " + view2 + " as select * from (select * from " + view1 + " union all select * from " + view1 + ") x").getResponseCode();
+ assertEquals("Checking command success", 0, ret);
+
+ driver.compile("select * from " + view2);
+ // view entity
+ assertEquals("default@" + view2, CheckInputReadEntity.readEntities[0].getName());
+
+ // table1 and view1 as second read entity
+ assertEquals("default@" + view1, CheckInputReadEntity.readEntities[1].getName());
+ assertFalse("Table is not direct input", CheckInputReadEntity.readEntities[1].isDirect());
+ Set<ReadEntity> parents = CheckInputReadEntity.readEntities[1].getParents();
+ assertTrue("Table does not have parent", parents != null && parents.size() > 0);
+ assertEquals("default@" + tab1, CheckInputReadEntity.readEntities[2].getName());
+ assertFalse("Table is not direct input", CheckInputReadEntity.readEntities[2].isDirect());
+
+ }
+
}