This is an automated email from the ASF dual-hosted git repository.

ngangam pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 2fccdf1  HIVE-24182: Fix ranger authorization issue with permanent 
UDF(Kishen Das via Thejas Nair and Naveen Gangam)
2fccdf1 is described below

commit 2fccdf1cde50a0d326e4b95e1c3dfae9e8d44af6
Author: Kishen Das <kis...@cloudera.com>
AuthorDate: Sat Sep 19 03:13:57 2020 -0700

    HIVE-24182: Fix ranger authorization issue with permanent UDF(Kishen Das 
via Thejas Nair and Naveen Gangam)
---
 .../plugin/TestHiveAuthorizerCheckInvocation.java  | 19 ++++++++++
 .../apache/hadoop/hive/ql/exec/FunctionUtils.java  |  4 ++
 .../org/apache/hadoop/hive/ql/exec/Registry.java   |  2 +-
 .../hadoop/hive/ql/exec/TestFunctionUtils.java     | 43 ++++++++++++++++++++++
 4 files changed, 67 insertions(+), 1 deletion(-)

diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java
index 79d494f..d046822 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java
@@ -40,6 +40,7 @@ import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
 import org.apache.hadoop.hive.metastore.txn.TxnDbUtil;
 import org.apache.hadoop.hive.ql.Driver;
+import org.apache.hadoop.hive.ql.exec.Registry;
 import org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
 import org.apache.hadoop.hive.ql.security.HiveAuthenticationProvider;
 import org.apache.hadoop.hive.ql.security.SessionStateUserAuthenticator;
@@ -221,6 +222,24 @@ public class TestHiveAuthorizerCheckInvocation {
   }
 
   @Test
+  public void testWindowingFunction() throws Exception {
+
+    reset(mockedAuthorizer);
+    int status = driver.compile("select AVG(`i`) OVER (PARTITION BY `city`) AS 
iavg FROM " + tableName, true);
+    assertEquals(0, status);
+
+    List<HivePrivilegeObject> inputs = 
getHivePrivilegeObjectInputs().getLeft();
+    checkSingleTableInput(inputs);
+    HivePrivilegeObject tableObj = inputs.get(0);
+    // Make sure none of the hive privilege object contain DB name with 
WINDOW_FUNC_PREFIX prefix.
+    for (HivePrivilegeObject obj : inputs) {
+      assertTrue(!obj.getDbname().startsWith(Registry.WINDOW_FUNC_PREFIX));
+    }
+    assertEquals("no of columns used", 2, tableObj.getColumns().size());
+    assertEquals("Columns used", Arrays.asList("city", "i"), 
getSortedList(tableObj.getColumns()));
+  }
+
+  @Test
   public void testCreateTableWithDb() throws Exception {
     final String newTable = "ctTableWithDb";
     checkCreateViewOrTableWithDb(newTable, "create table " + dbName + "." + 
newTable + "(i int)");
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionUtils.java 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionUtils.java
index c86954c..9a91639 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionUtils.java
@@ -126,6 +126,10 @@ public final class FunctionUtils {
     } else if (names.length > 2) {
       throw new HiveException("Function name does not have correct format: " + 
functionName);
     }
+    // Remove the WINDOW_FUNC_PREFIX prefix, as that is not part of the 
database name.
+    if (names[0].startsWith(Registry.WINDOW_FUNC_PREFIX)) {
+      names[0] = names[0].substring(Registry.WINDOW_FUNC_PREFIX.length());
+    }
     return names;
   }
 
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java
index 1f6ae08..d686cf5 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/Registry.java
@@ -73,7 +73,7 @@ public class Registry {
   private static final Logger LOG = 
LoggerFactory.getLogger(FunctionRegistry.class);
 
   // prefix for window functions, to discern LEAD/LAG UDFs from window 
functions with the same name
-  private static final String WINDOW_FUNC_PREFIX = "@_";
+  public static final String WINDOW_FUNC_PREFIX = "@_";
 
   /**
    * The mapping from expression function names to expression classes.
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionUtils.java 
b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionUtils.java
new file mode 100644
index 0000000..39a36e7
--- /dev/null
+++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionUtils.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec;
+
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestFunctionUtils {
+
+  @Test
+  public void testSplitQualifiedFunctionName() throws HiveException {
+
+    String function1 = Registry.WINDOW_FUNC_PREFIX + "database1.function1";
+    String function2 = "database2.function2";
+
+    String[] output1 = FunctionUtils.splitQualifiedFunctionName(function1);
+    Assert.assertEquals("database1", output1[0]);
+    Assert.assertEquals("function1", output1[1]);
+
+    String[] output2 = FunctionUtils.splitQualifiedFunctionName(function2);
+    Assert.assertEquals("database2", output2[0]);
+    Assert.assertEquals("function2", output2[1]);
+
+  }
+
+}
\ No newline at end of file

Reply via email to