hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ych...@apache.org
Subject hive git commit: HIVE-13991: Union All on view fail with no valid permission on underneath table (Yongzhi Chen, reviewed by Aihua Xu)
Date Mon, 27 Jun 2016 15:36:07 GMT
Repository: hive
Updated Branches:
  refs/heads/master a42fe46cc -> 6f9891607


HIVE-13991: Union All on view fail with no valid permission on underneath table (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/6f989160
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/6f989160
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/6f989160

Branch: refs/heads/master
Commit: 6f9891607fbe2609d5b890a229abf6bab22886a6
Parents: a42fe46
Author: Yongzhi Chen <ychena@apache.org>
Authored: Thu Jun 9 20:19:23 2016 -0400
Committer: Yongzhi Chen <ychena@apache.org>
Committed: Mon Jun 27 11:35:10 2016 -0400

----------------------------------------------------------------------
 .../hadoop/hive/ql/parse/SemanticAnalyzer.java  | 20 ++++++++++++++++++--
 .../apache/hadoop/hive/ql/plan/PlanUtils.java   |  9 ++++++++-
 .../clientpositive/authorization_view_sqlstd.q  |  2 ++
 .../authorization_view_sqlstd.q.out             | 10 ++++++++++
 4 files changed, 38 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/6f989160/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 bc8e9c0..20d9649 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
@@ -300,6 +300,9 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
   // derived from the alias V3:V2:V1:T
   private final Map<String, ReadEntity> viewAliasToInput;
 
+  //need merge isDirect flag to input even if the newInput does not have a parent
+  private boolean mergeIsDirect;
+
   // flag for no scan during analyze ... compute statistics
   protected boolean noscan;
 
@@ -380,6 +383,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
     aliasToCTEs = new HashMap<String, CTEClause>();
     globalLimitCtx = new GlobalLimitCtx();
     viewAliasToInput = new HashMap<String, ReadEntity>();
+    mergeIsDirect = true;
     noscan = partialscan = false;
     tabNameToTabObject = new HashMap<>();
   }
@@ -389,6 +393,13 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
     super.reset(true);
     if(clearPartsCache) {
       prunedPartitions.clear();
+
+      //When init(true) combine with genResolvedParseTree, it will generate Resolved Parse
tree from syntax tree
+      //ReadEntity created under these conditions should be all relevant to the syntax tree
even the ones without parents
+      //set mergeIsDirect to true here.
+      mergeIsDirect = true;
+    } else {
+      mergeIsDirect = false;
     }
     tabNameToTabObject.clear();
     loadTableWork.clear();
@@ -1951,7 +1962,12 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
         ReadEntity viewInput = new ReadEntity(tab, parentInput, !qb.isInsideView());
         viewInput = PlanUtils.addInput(inputs, viewInput);
         aliasToViewInfo.put(alias, new ObjectPair<String, ReadEntity>(fullViewName,
viewInput));
-        viewAliasToInput.put(getAliasId(alias, qb), viewInput);
+        String aliasId = getAliasId(alias, qb);
+        if (aliasId != null) {
+          aliasId = aliasId.replace(SemanticAnalyzer.SUBQUERY_TAG_1, "")
+            .replace(SemanticAnalyzer.SUBQUERY_TAG_2, "");
+        }
+        viewAliasToInput.put(aliasId, viewInput);
         continue;
       }
 
@@ -2003,7 +2019,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
 
       ReadEntity parentViewInfo = PlanUtils.getParentViewInfo(getAliasId(alias, qb), viewAliasToInput);
       PlanUtils.addInput(inputs,
-              new ReadEntity(tab, parentViewInfo, parentViewInfo == null));
+              new ReadEntity(tab, parentViewInfo, parentViewInfo == null),mergeIsDirect);
     }
 
     LOG.info("Get metadata for subqueries");

http://git-wip-us.apache.org/repos/asf/hive/blob/6f989160/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 37ae668..5dc3aa6 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
@@ -906,6 +906,10 @@ public final class PlanUtils {
     // prevent instantiation
   }
 
+  public static ReadEntity addInput(Set<ReadEntity> inputs, ReadEntity newInput) {
+    return addInput(inputs,newInput,false);
+  }
+
   // Add the input 'newInput' to the set of inputs for the query.
   // The input may or may not be already present.
   // The ReadEntity also contains the parents from it is derived (only populated
@@ -923,7 +927,8 @@ public final class PlanUtils {
   //
   // If the ReadEntity is already present and another ReadEntity with same name is
   // added, then the isDirect flag is updated to be the OR of values of both.
-  public static ReadEntity addInput(Set<ReadEntity> inputs, ReadEntity newInput) {
+  // mergeIsDirectFlag, need to merge isDirect flag even newInput does not have parent
+  public static ReadEntity addInput(Set<ReadEntity> inputs, ReadEntity newInput, boolean
mergeIsDirectFlag) {
     // If the input is already present, make sure the new parent is added to the input.
     if (inputs.contains(newInput)) {
       for (ReadEntity input : inputs) {
@@ -931,6 +936,8 @@ public final class PlanUtils {
           if ((newInput.getParents() != null) && (!newInput.getParents().isEmpty()))
{
             input.getParents().addAll(newInput.getParents());
             input.setDirect(input.isDirect() || newInput.isDirect());
+          } else if (mergeIsDirectFlag) {
+            input.setDirect(input.isDirect() || newInput.isDirect());
           }
           return input;
         }

http://git-wip-us.apache.org/repos/asf/hive/blob/6f989160/ql/src/test/queries/clientpositive/authorization_view_sqlstd.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/authorization_view_sqlstd.q b/ql/src/test/queries/clientpositive/authorization_view_sqlstd.q
index 8467c16..14044bf 100644
--- a/ql/src/test/queries/clientpositive/authorization_view_sqlstd.q
+++ b/ql/src/test/queries/clientpositive/authorization_view_sqlstd.q
@@ -38,6 +38,8 @@ select * from vt1;
 -- even if view is within a sub query
 select * from (select * from vt1) a;
 
+select * from vt1 union all select * from vt1;
+
 set user.name=user1;
 
 grant all on table vt2 to user user2;

http://git-wip-us.apache.org/repos/asf/hive/blob/6f989160/ql/src/test/results/clientpositive/authorization_view_sqlstd.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/authorization_view_sqlstd.q.out b/ql/src/test/results/clientpositive/authorization_view_sqlstd.q.out
index 461490b..d2fab2f 100644
--- a/ql/src/test/results/clientpositive/authorization_view_sqlstd.q.out
+++ b/ql/src/test/results/clientpositive/authorization_view_sqlstd.q.out
@@ -123,6 +123,16 @@ POSTHOOK: type: QUERY
 POSTHOOK: Input: default@t1
 POSTHOOK: Input: default@vt1
 #### A masked pattern was here ####
+PREHOOK: query: select * from vt1 union all select * from vt1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t1
+PREHOOK: Input: default@vt1
+#### A masked pattern was here ####
+POSTHOOK: query: select * from vt1 union all select * from vt1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t1
+POSTHOOK: Input: default@vt1
+#### A masked pattern was here ####
 PREHOOK: query: grant all on table vt2 to user user2
 PREHOOK: type: GRANT_PRIVILEGE
 PREHOOK: Output: default@vt2


Mime
View raw message