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
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 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 000..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