diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java index bbe7fb0697..e7aa041c25 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java @@ -46,6 +46,7 @@ import org.apache.hadoop.hive.ql.udf.UDFAtan; import org.apache.hadoop.hive.ql.udf.UDFBase64; import org.apache.hadoop.hive.ql.udf.UDFBin; +import org.apache.hadoop.hive.ql.udf.UDFBuildVersion; import org.apache.hadoop.hive.ql.udf.UDFChr; import org.apache.hadoop.hive.ql.udf.UDFConv; import org.apache.hadoop.hive.ql.udf.UDFCos; @@ -394,6 +395,7 @@ // Utility UDFs system.registerUDF("version", UDFVersion.class, false); + system.registerUDF("buildversion", UDFBuildVersion.class, false); // Aliases for Java Class Names // These are used in getImplicitConvertUDFMethod diff --git ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBuildVersion.java ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBuildVersion.java new file mode 100644 index 0000000000..8c5e514bd2 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBuildVersion.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; + + +/** + * UDFBuildVersion + */ +@Description(name = "buildversion", + value="_FUNC_() - Returns the Hive build version string - includes base" + + "version, revision, User, Source Check Sum") +public class UDFBuildVersion extends UDF { + private static final String versionInfo = String.format("%s", + HiveVersionInfo.getBuildVersion()); + + public Text evaluate() { + return new Text(versionInfo); + } +} diff --git ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFBuildVersion.java ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFBuildVersion.java new file mode 100644 index 0000000000..c046d3f2f4 --- /dev/null +++ ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFBuildVersion.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 TestUDFBuildVersion extends TestCase { + public void testVersion(){ + UDFBuildVersion udf = new UDFBuildVersion(); + Text result = udf.evaluate(); + String expected = String.format("%s", + HiveVersionInfo.getBuildVersion()); + assertEquals(expected, result.toString()); + } +}