You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by na...@apache.org on 2009/04/21 02:16:05 UTC
svn commit: r766926 - in /hadoop/hive/trunk: ./
ql/src/java/org/apache/hadoop/hive/ql/exec/
ql/src/java/org/apache/hadoop/hive/ql/udf/
ql/src/test/queries/clientpositive/ ql/src/test/results/clientpositive/
Author: namit
Date: Tue Apr 21 00:16:05 2009
New Revision: 766926
URL: http://svn.apache.org/viewvc?rev=766926&view=rev
Log:
HIVE-354. UDF for length of a string. (Neil Conway via namit).
Added:
hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLength.java
hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_length.q
hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_length.q.out
Modified:
hadoop/hive/trunk/CHANGES.txt
hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
Modified: hadoop/hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=766926&r1=766925&r2=766926&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Tue Apr 21 00:16:05 2009
@@ -9,6 +9,8 @@
NEW FEATURES
+ HIVE-354. UDF for length of a string. (Neil Conway via namit).
+
IMPROVEMENTS
HIVE-389. Option to build without ivy (jssarma)
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=766926&r1=766925&r2=766926&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java Tue Apr 21 00:16:05 2009
@@ -79,6 +79,7 @@
registerUDF("trim", UDFTrim.class, OperatorType.PREFIX, false);
registerUDF("ltrim", UDFLTrim.class, OperatorType.PREFIX, false);
registerUDF("rtrim", UDFRTrim.class, OperatorType.PREFIX, false);
+ registerUDF("length", UDFLength.class, OperatorType.PREFIX, false);
registerUDF("like", UDFLike.class, OperatorType.INFIX, true);
registerUDF("rlike", UDFRegExp.class, OperatorType.INFIX, true);
Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLength.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLength.java?rev=766926&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLength.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLength.java Tue Apr 21 00:16:05 2009
@@ -0,0 +1,35 @@
+/**
+ * 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.UDF;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.Text;
+
+public class UDFLength extends UDF {
+ private IntWritable result = new IntWritable();
+
+ public IntWritable evaluate(Text s) {
+ if (s == null) {
+ return null;
+ }
+
+ result.set(s.toString().length());
+ return result;
+ }
+}
Added: hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_length.q
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_length.q?rev=766926&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_length.q (added)
+++ hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_length.q Tue Apr 21 00:16:05 2009
@@ -0,0 +1,8 @@
+CREATE TABLE dest1(len INT);
+
+EXPLAIN
+FROM src INSERT OVERWRITE TABLE dest1 SELECT length(src.value);
+
+FROM src INSERT OVERWRITE TABLE dest1 SELECT length(src.value);
+
+SELECT dest1.* FROM dest1;
Added: hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_length.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_length.q.out?rev=766926&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_length.q.out (added)
+++ hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_length.q.out Tue Apr 21 00:16:05 2009
@@ -0,0 +1,540 @@
+ABSTRACT SYNTAX TREE:
+ (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_TAB dest1)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION length (TOK_COLREF src value))))))
+
+STAGE DEPENDENCIES:
+ Stage-1 is a root stage
+ Stage-0 depends on stages: Stage-1
+
+STAGE PLANS:
+ Stage: Stage-1
+ Map Reduce
+ Alias -> Map Operator Tree:
+ src
+ Select Operator
+ expressions:
+ expr: value
+ type: string
+ Select Operator
+ expressions:
+ expr: length(0)
+ type: int
+ File Output Operator
+ compressed: false
+ GlobalTableId: 1
+ table:
+ input format: org.apache.hadoop.mapred.TextInputFormat
+ output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+ serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+ name: dest1
+
+ Stage: Stage-0
+ Move Operator
+ tables:
+ replace: true
+ table:
+ input format: org.apache.hadoop.mapred.TextInputFormat
+ output format: org.apache.hado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