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 2018/06/26 04:17:12 UTC
[53/58] [abbrv] hive git commit: HIVE-15976 Support CURRENT_CATALOG
and CURRENT_SCHEMA (Laszlo Bodor via Alan Gates)
HIVE-15976 Support CURRENT_CATALOG and CURRENT_SCHEMA (Laszlo Bodor via Alan Gates)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/1f2419dd
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/1f2419dd
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/1f2419dd
Branch: refs/heads/master-txnstats
Commit: 1f2419dd06d98aa42fabd77a82d4bf1d16a6f736
Parents: f37c5de
Author: Alan Gates <ga...@hortonworks.com>
Authored: Mon Jun 25 12:26:35 2018 -0700
Committer: Alan Gates <ga...@hortonworks.com>
Committed: Mon Jun 25 12:26:35 2018 -0700
----------------------------------------------------------------------
.../hadoop/hive/ql/exec/FunctionRegistry.java | 4 +-
.../udf/generic/GenericUDFCurrentCatalog.java | 52 +++++++++++++++
.../udf/generic/GenericUDFCurrentDatabase.java | 53 +++++++++++++++
.../ql/udf/generic/GenericUDFCurrentSchema.java | 37 +++++++++++
.../hive/ql/udf/generic/UDFCurrentDB.java | 68 --------------------
.../clientpositive/current_catalog_and_schema.q | 10 +++
.../current_catalog_and_schema.q.out | 54 ++++++++++++++++
.../results/clientpositive/show_functions.q.out | 4 ++
8 files changed, 213 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/1f2419dd/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
index e77fe18..63f8501 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
@@ -352,7 +352,9 @@ public final class FunctionRegistry {
system.registerGenericUDF("grouping", GenericUDFGrouping.class);
- system.registerGenericUDF("current_database", UDFCurrentDB.class);
+ system.registerGenericUDF("current_database", GenericUDFCurrentDatabase.class);
+ system.registerGenericUDF("current_schema", GenericUDFCurrentSchema.class);
+ system.registerGenericUDF("current_catalog", GenericUDFCurrentCatalog.class);
system.registerGenericUDF("current_date", GenericUDFCurrentDate.class);
system.registerGenericUDF("current_timestamp", GenericUDFCurrentTimestamp.class);
system.registerGenericUDF("current_user", GenericUDFCurrentUser.class);
http://git-wip-us.apache.org/repos/asf/hive/blob/1f2419dd/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentCatalog.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentCatalog.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentCatalog.java
new file mode 100644
index 0000000..e2684c8
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentCatalog.java
@@ -0,0 +1,52 @@
+/*
+ * 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.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.ql.udf.UDFType;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.io.Text;
+
+// This function is not a deterministic function, but a runtime constant.
+// The return value is constant within a query but can be different between queries.
+@UDFType(deterministic = false, runtimeConstant = true)
+@Description(name = "current_catalog", value = "_FUNC_() - returns currently used catalog name")
+@NDV(maxNdv = 1)
+public class GenericUDFCurrentCatalog extends GenericUDF {
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+ return PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
+ TypeInfoFactory.stringTypeInfo, new Text(SessionState.get().getCurrentCatalog()));
+ }
+
+ @Override
+ public Object evaluate(DeferredObject[] arguments) throws HiveException {
+ return SessionState.get().getCurrentCatalog();
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ return "current_catalog()";
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/1f2419dd/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentDatabase.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentDatabase.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentDatabase.java
new file mode 100644
index 0000000..29d3629
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentDatabase.java
@@ -0,0 +1,53 @@
+/*
+ * 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.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.ql.udf.UDFType;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.io.Text;
+
+// This function is not a deterministic function, but a runtime constant.
+// The return value is constant within a query but can be different between queries.
+@UDFType(deterministic = false, runtimeConstant = true)
+@Description(name = "current_database",
+ value = "_FUNC_() - returns currently using database name")
+@NDV(maxNdv = 1)
+public class GenericUDFCurrentDatabase extends GenericUDF {
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+ return PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
+ TypeInfoFactory.stringTypeInfo, new Text(SessionState.get().getCurrentDatabase()));
+ }
+
+ @Override
+ public Object evaluate(DeferredObject[] arguments) throws HiveException {
+ return SessionState.get().getCurrentDatabase();
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ return "current_database()";
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/1f2419dd/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentSchema.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentSchema.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentSchema.java
new file mode 100644
index 0000000..9e7895b
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFCurrentSchema.java
@@ -0,0 +1,37 @@
+/*
+ * 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.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.ql.udf.UDFType;
+
+// This function is not a deterministic function, but a runtime constant.
+// The return value is constant within a query but can be different between queries.
+@UDFType(deterministic = false, runtimeConstant = true)
+@Description(name = "current_schema", value = "_FUNC_() - returns currently used schema(database) name")
+@NDV(maxNdv = 1)
+public class GenericUDFCurrentSchema extends GenericUDFCurrentDatabase {
+ @Override
+ public String getDisplayString(String[] children) {
+ return "current_schema()";
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/1f2419dd/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/UDFCurrentDB.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/UDFCurrentDB.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/UDFCurrentDB.java
deleted file mode 100644
index 1eacc25..0000000
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/UDFCurrentDB.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.udf.generic;
-
-import org.apache.hadoop.hive.ql.exec.Description;
-import org.apache.hadoop.hive.ql.exec.MapredContext;
-import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
-import org.apache.hadoop.hive.ql.metadata.HiveException;
-import org.apache.hadoop.hive.ql.session.SessionState;
-import org.apache.hadoop.hive.ql.udf.UDFType;
-import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
-import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
-import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
-import org.apache.hadoop.io.Text;
-
-// This function is not a deterministic function, but a runtime constant.
-// The return value is constant within a query but can be different between queries.
-@UDFType(deterministic = false, runtimeConstant = true)
-@Description(name = "current_database",
- value = "_FUNC_() - returns currently using database name")
-@NDV(maxNdv = 1)
-public class UDFCurrentDB extends GenericUDF {
-
- private MapredContext context;
-
- @Override
- public void configure(MapredContext context) {
- this.context = context;
- }
-
- @Override
- public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
- String database;
- if (context != null) {
- database = context.getJobConf().get("hive.current.database");
- } else {
- database = SessionState.get().getCurrentDatabase();
- }
- return PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
- TypeInfoFactory.stringTypeInfo, new Text(database));
- }
-
- @Override
- public Object evaluate(DeferredObject[] arguments) throws HiveException {
- return SessionState.get().getCurrentDatabase();
- }
-
- @Override
- public String getDisplayString(String[] children) {
- return "current_database()";
- }
-}
http://git-wip-us.apache.org/repos/asf/hive/blob/1f2419dd/ql/src/test/queries/clientpositive/current_catalog_and_schema.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/current_catalog_and_schema.q b/ql/src/test/queries/clientpositive/current_catalog_and_schema.q
new file mode 100644
index 0000000..b4e4855
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/current_catalog_and_schema.q
@@ -0,0 +1,10 @@
+use default;
+
+select current_catalog();
+select current_schema();
+
+create database test_current_database;
+use test_current_database;
+
+select current_catalog();
+select current_schema();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/1f2419dd/ql/src/test/results/clientpositive/current_catalog_and_schema.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/current_catalog_and_schema.q.out b/ql/src/test/results/clientpositive/current_catalog_and_schema.q.out
new file mode 100644
index 0000000..145845c
--- /dev/null
+++ b/ql/src/test/results/clientpositive/current_catalog_and_schema.q.out
@@ -0,0 +1,54 @@
+PREHOOK: query: use default
+PREHOOK: type: SWITCHDATABASE
+PREHOOK: Input: database:default
+POSTHOOK: query: use default
+POSTHOOK: type: SWITCHDATABASE
+POSTHOOK: Input: database:default
+PREHOOK: query: select current_catalog()
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select current_catalog()
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+hive
+PREHOOK: query: select current_schema()
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select current_schema()
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+default
+PREHOOK: query: create database test_current_database
+PREHOOK: type: CREATEDATABASE
+PREHOOK: Output: database:test_current_database
+POSTHOOK: query: create database test_current_database
+POSTHOOK: type: CREATEDATABASE
+POSTHOOK: Output: database:test_current_database
+PREHOOK: query: use test_current_database
+PREHOOK: type: SWITCHDATABASE
+PREHOOK: Input: database:test_current_database
+POSTHOOK: query: use test_current_database
+POSTHOOK: type: SWITCHDATABASE
+POSTHOOK: Input: database:test_current_database
+PREHOOK: query: select current_catalog()
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select current_catalog()
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+hive
+PREHOOK: query: select current_schema()
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select current_schema()
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+test_current_database
http://git-wip-us.apache.org/repos/asf/hive/blob/1f2419dd/ql/src/test/results/clientpositive/show_functions.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/show_functions.q.out b/ql/src/test/results/clientpositive/show_functions.q.out
index 91d3660..e91cffd 100644
--- a/ql/src/test/results/clientpositive/show_functions.q.out
+++ b/ql/src/test/results/clientpositive/show_functions.q.out
@@ -64,9 +64,11 @@ crc32
create_union
cume_dist
current_authorizer
+current_catalog
current_database
current_date
current_groups
+current_schema
current_timestamp
current_user
date_add
@@ -321,9 +323,11 @@ crc32
create_union
cume_dist
current_authorizer
+current_catalog
current_database
current_date
current_groups
+current_schema
current_timestamp
current_user
PREHOOK: query: SHOW FUNCTIONS '.*e$'