You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2016/05/31 20:30:04 UTC
hive git commit: HIVE-12983 Provide a builtin function to get Hive
version (Lenni Kuff via Szehon Ho)
Repository: hive
Updated Branches:
refs/heads/master 1ca01701b -> a55f4a3a4
HIVE-12983 Provide a builtin function to get Hive version (Lenni Kuff via Szehon Ho)
Signed-off-by: Ashutosh Chauhan <ha...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/a55f4a3a
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/a55f4a3a
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/a55f4a3a
Branch: refs/heads/master
Commit: a55f4a3a4b017d7f3b9279ef7d843e4b5f7fcfa0
Parents: 1ca0170
Author: Ashutosh Chauhan <ha...@apache.org>
Authored: Tue May 31 13:28:44 2016 -0700
Committer: Ashutosh Chauhan <ha...@apache.org>
Committed: Tue May 31 13:28:44 2016 -0700
----------------------------------------------------------------------
.../hadoop/hive/ql/exec/FunctionRegistry.java | 4 ++
.../apache/hadoop/hive/ql/udf/UDFVersion.java | 40 ++++++++++++++++++++
.../hadoop/hive/ql/udf/TestUDFVersion.java | 34 +++++++++++++++++
.../test/queries/clientpositive/udf_version.q | 2 +
.../results/clientpositive/show_functions.q.out | 1 +
.../results/clientpositive/udf_version.q.out | 11 ++++++
6 files changed, 92 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/a55f4a3a/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 8217ad3..69a18cd 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
@@ -106,6 +106,7 @@ import org.apache.hadoop.hive.ql.udf.UDFType;
import org.apache.hadoop.hive.ql.udf.UDFUUID;
import org.apache.hadoop.hive.ql.udf.UDFUnbase64;
import org.apache.hadoop.hive.ql.udf.UDFUnhex;
+import org.apache.hadoop.hive.ql.udf.UDFVersion;
import org.apache.hadoop.hive.ql.udf.UDFWeekOfYear;
import org.apache.hadoop.hive.ql.udf.UDFYear;
import org.apache.hadoop.hive.ql.udf.generic.*;
@@ -350,6 +351,9 @@ public final class FunctionRegistry {
system.registerGenericUDF("ewah_bitmap_or", GenericUDFEWAHBitmapOr.class);
system.registerGenericUDF("ewah_bitmap_empty", GenericUDFEWAHBitmapEmpty.class);
+ // Utility UDFs
+ system.registerUDF("version", UDFVersion.class, false);
+
// Aliases for Java Class Names
// These are used in getImplicitConvertUDFMethod
system.registerUDF(serdeConstants.BOOLEAN_TYPE_NAME, UDFToBoolean.class, false, UDFToBoolean.class.getSimpleName());
http://git-wip-us.apache.org/repos/asf/hive/blob/a55f4a3a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFVersion.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFVersion.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFVersion.java
new file mode 100644
index 0000000..d9750c1
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFVersion.java
@@ -0,0 +1,40 @@
+/**
+ * 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;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.io.Text;
+import org.apache.hive.common.util.HiveVersionInfo;
+
+
+/**
+ * UDFVersion
+ */
+@Description(name = "version",
+ value="_FUNC_() - Returns the Hive build version string - includes base " +
+ "version and revision.")
+public class UDFVersion extends UDF {
+ private static final String versionInfo = String.format("%s r%s",
+ HiveVersionInfo.getVersion(), HiveVersionInfo.getRevision());
+
+ public Text evaluate() {
+ return new Text(versionInfo);
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/a55f4a3a/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFVersion.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFVersion.java b/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFVersion.java
new file mode 100644
index 0000000..12c63b1
--- /dev/null
+++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFVersion.java
@@ -0,0 +1,34 @@
+/**
+ * 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;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.io.Text;
+import org.apache.hive.common.util.HiveVersionInfo;
+
+public class TestUDFVersion extends TestCase {
+ public void testVersion(){
+ UDFVersion udf = new UDFVersion();
+ Text result = udf.evaluate();
+ String expected = String.format("%s r%s", HiveVersionInfo.getVersion(),
+ HiveVersionInfo.getRevision());
+ assertEquals(expected, result.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/a55f4a3a/ql/src/test/queries/clientpositive/udf_version.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/udf_version.q b/ql/src/test/queries/clientpositive/udf_version.q
new file mode 100644
index 0000000..7110f15
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/udf_version.q
@@ -0,0 +1,2 @@
+-- Normalize the version info
+SELECT regexp_replace(version(), '.+ r\\w+', 'VERSION rGITHASH');
http://git-wip-us.apache.org/repos/asf/hive/blob/a55f4a3a/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 6e3f9c8..68c24a6 100644
--- a/ql/src/test/results/clientpositive/show_functions.q.out
+++ b/ql/src/test/results/clientpositive/show_functions.q.out
@@ -225,6 +225,7 @@ uuid
var_pop
var_samp
variance
+version
weekofyear
when
windowingtablefunction
http://git-wip-us.apache.org/repos/asf/hive/blob/a55f4a3a/ql/src/test/results/clientpositive/udf_version.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/udf_version.q.out b/ql/src/test/results/clientpositive/udf_version.q.out
new file mode 100644
index 0000000..242e83f
--- /dev/null
+++ b/ql/src/test/results/clientpositive/udf_version.q.out
@@ -0,0 +1,11 @@
+PREHOOK: query: -- Normalize the version info
+SELECT regexp_replace(version(), '.+ r\\w+', 'VERSION rGITHASH')
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: -- Normalize the version info
+SELECT regexp_replace(version(), '.+ r\\w+', 'VERSION rGITHASH')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+VERSION rGITHASH