hadoop-hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r792772 - 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/
Date Fri, 10 Jul 2009 01:04:37 GMT
Author: namit
Date: Fri Jul 10 01:04:37 2009
New Revision: 792772

URL: http://svn.apache.org/viewvc?rev=792772&view=rev
Log:
HIVE-622. add UDF reverse
(Emil Ibrishimov via namit)


Added:
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFReverse.java
    hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_reverse.q
    hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_reverse.q.out
Modified:
    hadoop/hive/trunk/CHANGES.txt
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.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
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=792772&r1=792771&r2=792772&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Fri Jul 10 01:04:37 2009
@@ -65,6 +65,9 @@
     HIVE-553. add BinarySortableSerDe
     (Zheng Shao via namit)
 
+    HIVE-622. add UDF reverse
+    (Emil Ibrishimov 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=792772&r1=792771&r2=792772&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 Fri
Jul 10 01:04:37 2009
@@ -77,6 +77,7 @@
     registerUDF("ltrim", UDFLTrim.class, OperatorType.PREFIX, false);
     registerUDF("rtrim", UDFRTrim.class, OperatorType.PREFIX, false);
     registerUDF("length", UDFLength.class, OperatorType.PREFIX, false);
+    registerUDF("reverse", UDFReverse.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/UDFReverse.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFReverse.java?rev=792772&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFReverse.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFReverse.java Fri Jul 10
01:04:37 2009
@@ -0,0 +1,46 @@
+/**
+ * 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.Text;
+
+public class UDFReverse extends UDF { 
+  private Text result = new Text();
+  
+  public Text evaluate(Text s) {      
+    if (s == null) {
+      return null;
+    }
+
+    // Use a string because Text.getLength() returns the number of bytes.
+    // This can be optimized by walking over the utf8 characters and not
+    // creating a string at all.
+    String text = s.toString();
+    
+    // Append the text to a StringBuffer in reverse order.
+    StringBuffer revBuff = new StringBuffer();
+    for (int i = text.length() - 1; i >= 0; i--) {
+      revBuff.append(text.charAt(i));
+    }
+    
+    result.set(revBuff.toString());
+    return result;
+  }
+}

Modified: 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=792772&r1=792771&r2=792772&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_length.q (original)
+++ hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_length.q Fri Jul 10 01:04:37
2009
@@ -6,3 +6,5 @@
 FROM src INSERT OVERWRITE TABLE dest1 SELECT length(src.value);
 
 SELECT dest1.* FROM dest1;
+
+DROP TABLE dest1;

Added: hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_reverse.q
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_reverse.q?rev=792772&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_reverse.q (added)
+++ hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_reverse.q Fri Jul 10 01:04:37
2009
@@ -0,0 +1,10 @@
+CREATE TABLE dest1(len STRING);
+
+EXPLAIN
+FROM src1 INSERT OVERWRITE TABLE dest1 SELECT reverse(src1.value);
+
+FROM src1 INSERT OVERWRITE TABLE dest1 SELECT reverse(src1.value);
+
+SELECT dest1.* FROM dest1;
+
+DROP TABLE dest1;

Modified: 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=792772&r1=792771&r2=792772&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_length.q.out (original)
+++ hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_length.q.out Fri Jul 10 01:04:37
2009
@@ -33,10 +33,10 @@
           Move Operator
             files:
                 hdfs directory: true
-                destination: file:/data/users/njain/hive4/hive4/build/ql/tmp/683676336/10000
+                destination: file:/data/users/emil/hive1/hive1/build/ql/tmp/809193894/10000
           Map Reduce
             Alias -> Map Operator Tree:
-              file:/data/users/njain/hive4/hive4/build/ql/tmp/1465726405/10002 
+              file:/data/users/emil/hive1/hive1/build/ql/tmp/353629462/10002 
                   Reduce Output Operator
                     sort order: 
                     Map-reduce partition columns:
@@ -73,7 +73,7 @@
 Output: default/dest1
 query: SELECT dest1.* FROM dest1
 Input: default/dest1
-Output: file:/data/users/njain/hive4/hive4/build/ql/tmp/1272744999/10000
+Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1493924198/10000
 7
 6
 7
@@ -574,3 +574,4 @@
 7
 7
 6
+query: DROP TABLE dest1

Added: hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_reverse.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_reverse.q.out?rev=792772&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_reverse.q.out (added)
+++ hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_reverse.q.out Fri Jul 10 01:04:37
2009
@@ -0,0 +1,102 @@
+query: CREATE TABLE dest1(len STRING)
+query: EXPLAIN
+FROM src1 INSERT OVERWRITE TABLE dest1 SELECT reverse(src1.value)
+ABSTRACT SYNTAX TREE:
+  (TOK_QUERY (TOK_FROM (TOK_TABREF src1)) (TOK_INSERT (TOK_DESTINATION (TOK_TAB dest1)) (TOK_SELECT
(TOK_SELEXPR (TOK_FUNCTION reverse (. (TOK_TABLE_OR_COL src1) value))))))
+
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-4 depends on stages: Stage-1
+  Stage-0 depends on stages: Stage-4
+
+STAGE PLANS:
+  Stage: Stage-1
+    Map Reduce
+      Alias -> Map Operator Tree:
+        src1 
+            Select Operator
+              expressions:
+                    expr: reverse(value)
+                    type: string
+              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-4
+    Conditional Operator
+      list of dependent Tasks:
+          Move Operator
+            files:
+                hdfs directory: true
+                destination: file:/data/users/emil/hive1/hive1/build/ql/tmp/533825523/10000
+          Map Reduce
+            Alias -> Map Operator Tree:
+              file:/data/users/emil/hive1/hive1/build/ql/tmp/620216694/10002 
+                  Reduce Output Operator
+                    sort order: 
+                    Map-reduce partition columns:
+                          expr: rand()
+                          type: double
+                    tag: -1
+                    value expressions:
+                          expr: len
+                          type: string
+            Reduce Operator Tree:
+              Extract
+                File Output Operator
+                  compressed: false
+                  GlobalTableId: 0
+                  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.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+              serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+              name: dest1
+
+
+query: FROM src1 INSERT OVERWRITE TABLE dest1 SELECT reverse(src1.value)
+Input: default/src1
+Output: default/dest1
+query: SELECT dest1.* FROM dest1
+Input: default/dest1
+Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1181513979/10000
+832_lav
+
+113_lav
+72_lav
+561_lav
+904_lav
+552_lav
+872_lav
+89_lav
+484_lav
+562_lav
+391_lav
+104_lav
+051_lav
+372_lav
+
+
+66_lav
+
+312_lav
+641_lav
+604_lav
+
+
+
+query: DROP TABLE dest1



Mime
View raw message