### Eclipse Workspace Patch 1.0 #P open src hive code Index: ql/src/java/org/apache/hadoop/hive/ql/udf/UDFNow.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/UDFNow.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/UDFNow.java (revision 0) @@ -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; + +import java.text.SimpleDateFormat; +import java.util.Date; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDF; +import org.apache.hadoop.io.Text; + +/** + * UDFNow. + * + */ +@Description(name = "now", value = "_FUNC_( ) - Returns the current time in yyyy-mm-dd hh:mm:ss format", extended = "Examples:\n" + + " > SELECT _FUNC_( ) FROM src LIMIT 1;\n") +public class UDFNow extends UDF { + + private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); + private Text result = new Text(); + + public UDFNow() { + } + + /** + * Get the current time in "yyyy-mm-dd hh:mm:ss" format + * + * @return the current time + */ + public Text evaluate() { + Date date = new Date(); + String now = formatter.format(date); + result.set(now); + return result; + } + +} Index: ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (revision 1215064) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (working copy) @@ -77,6 +77,7 @@ import org.apache.hadoop.hive.ql.udf.UDFLpad; import org.apache.hadoop.hive.ql.udf.UDFMinute; import org.apache.hadoop.hive.ql.udf.UDFMonth; +import org.apache.hadoop.hive.ql.udf.UDFNow; import org.apache.hadoop.hive.ql.udf.UDFOPBitAnd; import org.apache.hadoop.hive.ql.udf.UDFOPBitNot; import org.apache.hadoop.hive.ql.udf.UDFOPBitOr; @@ -316,6 +317,7 @@ registerUDF("unix_timestamp", UDFUnixTimeStamp.class, false); registerUDF("to_date", UDFDate.class, false); registerUDF("weekofyear", UDFWeekOfYear.class, false); + registerUDF("now", UDFNow.class, false); registerUDF("date_add", UDFDateAdd.class, false); registerUDF("date_sub", UDFDateSub.class, false); Index: ql/src/test/results/clientpositive/udf_now.q.out =================================================================== --- ql/src/test/results/clientpositive/udf_now.q.out (revision 0) +++ ql/src/test/results/clientpositive/udf_now.q.out (revision 0) @@ -0,0 +1,13 @@ +PREHOOK: query: DESCRIBE FUNCTION now +PREHOOK: type: DESCFUNCTION +POSTHOOK: query: DESCRIBE FUNCTION now +POSTHOOK: type: DESCFUNCTION +now( ) - Returns the current time in yyyy-mm-dd hh:mm:ss format +PREHOOK: query: DESCRIBE FUNCTION EXTENDED now +PREHOOK: type: DESCFUNCTION +POSTHOOK: query: DESCRIBE FUNCTION EXTENDED now +POSTHOOK: type: DESCFUNCTION +now( ) - Returns the current time in yyyy-mm-dd hh:mm:ss format +Examples: + > SELECT now( ) FROM src LIMIT 1; + Index: ql/src/test/queries/clientpositive/udf_now.q =================================================================== --- ql/src/test/queries/clientpositive/udf_now.q (revision 0) +++ ql/src/test/queries/clientpositive/udf_now.q (revision 0) @@ -0,0 +1,2 @@ +DESCRIBE FUNCTION now; +DESCRIBE FUNCTION EXTENDED now; \ No newline at end of file Index: ql/src/test/results/clientpositive/show_functions.q.out =================================================================== --- ql/src/test/results/clientpositive/show_functions.q.out (revision 1215064) +++ ql/src/test/results/clientpositive/show_functions.q.out (working copy) @@ -99,6 +99,7 @@ negative ngrams not +now or parse_url parse_url_tuple