sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sra...@apache.org
Subject sentry git commit: SENTRY-1201: Sentry ignores database prefix for MSCK statement (Sravya Tirukkovalur, Reviewed by: Lenni Kuff)
Date Mon, 02 May 2016 19:11:11 GMT
Repository: sentry
Updated Branches:
  refs/heads/master dd8828cad -> df4524e97


SENTRY-1201: Sentry ignores database prefix for MSCK statement (Sravya Tirukkovalur, Reviewed
by: Lenni Kuff)

Change-Id: Id6ebd465a31a2306a11cb2a878b972b649ecf6c0


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/df4524e9
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/df4524e9
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/df4524e9

Branch: refs/heads/master
Commit: df4524e97d2e92f66bc7d619ea8c4932a8b7ca1d
Parents: dd8828c
Author: Sravya Tirukkovalur <sravya@apache.org>
Authored: Mon May 2 12:10:18 2016 -0700
Committer: Sravya Tirukkovalur <sravya@apache.org>
Committed: Mon May 2 12:10:18 2016 -0700

----------------------------------------------------------------------
 .../binding/hive/HiveAuthzBindingHookBase.java  | 12 ++++++++-
 .../binding/hive/HiveAuthzBindingHook.java      |  6 +----
 .../tests/e2e/hive/TestOperationsPart1.java     | 27 ++++++++++++++++++++
 3 files changed, 39 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/df4524e9/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHookBase.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHookBase.java
b/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHookBase.java
index df68dd3..dd16960 100644
--- a/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHookBase.java
+++ b/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHookBase.java
@@ -29,6 +29,7 @@ import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
 
+import com.google.common.base.Preconditions;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hive.common.JavaUtils;
@@ -232,6 +233,15 @@ public abstract class HiveAuthzBindingHookBase extends AbstractSemanticAnalyzerH
     return new Database(SessionState.get().getCurrentDatabase());
   }
 
+  protected void extractDbTableNameFromTOKTABLE(ASTNode astNode) throws SemanticException{
+    String[] fqTableName = BaseSemanticAnalyzer.getQualifiedTableName(astNode);
+    Preconditions.checkArgument(fqTableName.length == 2, "BaseSemanticAnalyzer.getQualifiedTableName
should return " +
+            "an array with dbName and tableName");
+    currOutDB = new Database(fqTableName[0]);
+    currOutTab = new Table(fqTableName[1]);
+  }
+
+  /*TODO: Deprecate */
   protected Database extractDatabase(ASTNode ast) throws SemanticException {
     String tableName = BaseSemanticAnalyzer.getUnescapedName(ast);
     if (tableName.contains(".")) {
@@ -240,7 +250,7 @@ public abstract class HiveAuthzBindingHookBase extends AbstractSemanticAnalyzerH
       return getCanonicalDb();
     }
   }
-
+  /*TODO: Deprecate */
   protected Table extractTable(ASTNode ast) throws SemanticException {
     String tableName = BaseSemanticAnalyzer.getUnescapedName(ast);
     if (tableName.contains(".")) {

http://git-wip-us.apache.org/repos/asf/sentry/blob/df4524e9/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
index 57fc1e4..ac8265f 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
@@ -182,11 +182,7 @@ public class HiveAuthzBindingHook extends HiveAuthzBindingHookBase {
         currDB = extractDatabase((ASTNode)ast.getChild(0));
         break;
       case HiveParser.TOK_MSCK:
-        // token name TOK_TABNAME is not properly set in this case and child(0) does
-        // not contain the table name.
-        // TODO: Fix Hive to capture the table and DB name
-        currOutTab = extractTable((ASTNode)ast.getChild(1));
-        currOutDB  = extractDatabase((ASTNode)ast.getChild(0));
+        extractDbTableNameFromTOKTABLE((ASTNode) ast.getChild(1));
         break;
       case HiveParser.TOK_ALTERTABLE_ADDPARTS:
         /*

http://git-wip-us.apache.org/repos/asf/sentry/blob/df4524e9/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperationsPart1.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperationsPart1.java
b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperationsPart1.java
index b474484..8539b4c 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperationsPart1.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperationsPart1.java
@@ -563,4 +563,31 @@ public class TestOperationsPart1 extends AbstractTestWithStaticConfiguration
{
     statement.close();
     connection.close();
   }
+
+  @Test
+  public void testDbPrefix() throws Exception {
+    Connection connection;
+    Statement statement;
+    connection = context.createConnection(ADMIN1);
+    statement = context.createStatement(connection);
+    //Create db1.table1
+    statement.execute("create database " + DB1);
+    statement.execute("create table " + DB1 + "." + tableName + "(a int)");
+    //Create db2.table1
+    statement.execute("create database " + DB2);
+    statement.execute("create table " + DB2 + "." + tableName + "(a int)");
+    //grant on db1.table1
+    policyFile
+      .addPermissionsToRole("all_db1_tb1", privileges.get("all_db1_tb1"))
+      .addRolesToGroup(USERGROUP1, "all_db1_tb1");
+    writePolicyFile(policyFile);
+
+    connection = context.createConnection(USER1_1);
+    statement = context.createStatement(connection);
+    //Use db2
+    statement.execute("use " + DB1);
+    //MSCK db1.table1
+    assertSemanticException(statement, "MSCK REPAIR TABLE " + DB2 + "." + tableName);
+    statement.execute("MSCK REPAIR TABLE " + DB1 + "." + tableName);
+  }
 }


Mime
View raw message