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 5353062..5a5c2aa 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 @@ -103,6 +103,7 @@ import org.apache.hadoop.hive.ql.udf.UDFType; 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.*; @@ -344,6 +345,9 @@ 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()); 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..a9d9258 --- /dev/null +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFVersion.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; + +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, revision, and build details.") +public class UDFVersion extends UDF { + public Text evaluate() { + return new Text(HiveVersionInfo.getBuildVersion()); + } +} \ No newline at end of file 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..370d41e --- /dev/null +++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFVersion.java @@ -0,0 +1,32 @@ +/** + * 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(); + assertEquals(HiveVersionInfo.getBuildVersion(), result.toString()); + } +} \ No newline at end of file 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..d6456be --- /dev/null +++ b/ql/src/test/queries/clientpositive/udf_version.q @@ -0,0 +1,2 @@ +-- Normalize the version info +SELECT regexp_replace(version(), '.+ from \\w+ by .+ \\w+ \\w+', 'VERSION from GITHASH by USER BUILD checksum HASH'); \ No newline at end of file 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..bf74f28 --- /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(), '.+ from \\w+ by .+ \\w+ \\w+', 'VERSION from GITHASH by USER BUILD checksum HASH') +PREHOOK: type: QUERY +PREHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +POSTHOOK: query: -- Normalize the version info +SELECT regexp_replace(version(), '.+ from \\w+ by .+ \\w+ \\w+', 'VERSION from GITHASH by USER BUILD checksum HASH') +POSTHOOK: type: QUERY +POSTHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +VERSION from GITHASH by USER BUILD checksum HASH