You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by zs...@apache.org on 2009/08/20 05:31:26 UTC

svn commit: r806033 - in /hadoop/hive/branches/branch-0.4: ./ 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: zshao
Date: Thu Aug 20 03:31:25 2009
New Revision: 806033

URL: http://svn.apache.org/viewvc?rev=806033&view=rev
Log:
HIVE-774. Fix the behavior of / and add DIV. (Ning Zhang via zshao)

Added:
    hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPLongDivide.java
    hadoop/hive/branches/branch-0.4/ql/src/test/queries/clientpositive/udf_divider.q
    hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/udf_divider.q.out
Modified:
    hadoop/hive/branches/branch-0.4/CHANGES.txt
    hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
    hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java
    hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/show_functions.q.out

Modified: hadoop/hive/branches/branch-0.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/CHANGES.txt?rev=806033&r1=806032&r2=806033&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.4/CHANGES.txt (original)
+++ hadoop/hive/branches/branch-0.4/CHANGES.txt Thu Aug 20 03:31:25 2009
@@ -516,6 +516,8 @@
 
     HIVE-769. Fix bug in partition pruning - bug in patch (Zheng Shao via namit)
 
+    HIVE-774. Fix the behavior of "/" and add "DIV". (Ning Zhang via zshao)
+
 Release 0.3.1 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=806033&r1=806032&r2=806033&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (original)
+++ hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java Thu Aug 20 03:31:25 2009
@@ -132,6 +132,7 @@
     registerUDF("*", UDFOPMultiply.class, OperatorType.INFIX, true);
     registerUDF("/", UDFOPDivide.class, OperatorType.INFIX, true);
     registerUDF("%", UDFOPMod.class, OperatorType.INFIX, true);
+    registerUDF("div", UDFOPLongDivide.class, OperatorType.INFIX, true);
 
     registerUDF("&", UDFOPBitAnd.class, OperatorType.INFIX, true);
     registerUDF("|", UDFOPBitOr.class, OperatorType.INFIX, true);

Modified: hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java?rev=806033&r1=806032&r2=806033&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java (original)
+++ hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java Thu Aug 20 03:31:25 2009
@@ -28,72 +28,21 @@
 import org.apache.hadoop.io.FloatWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.ql.exec.NumericOpMethodResolver;
 
 @description(
     name = "/",
     value = "a _FUNC_ b - Divide a by b",
     extended = "Example:\n" +
-        "  > SELECT 10 _FUNC_ 2 FROM src LIMIT 1;\n" +
-        "  5"
+        "  > SELECT 3 _FUNC_ 2 FROM src LIMIT 1;\n" +
+        "  1.5"
 )
-public class UDFOPDivide extends UDFBaseNumericOp {
+public class UDFOPDivide extends UDF {
 
   private static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.udf.UDFOPDivide");
 
-  public UDFOPDivide() {
-  }
-
-  @Override
-  public ByteWritable evaluate(ByteWritable a, ByteWritable b)  {
-    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
-    if ((a == null) || (b == null))
-      return null;
-
-    byteWritable.set((byte)(a.get()/b.get()));
-    return byteWritable;
-  }
-
-  @Override
-  public ShortWritable evaluate(ShortWritable a, ShortWritable b)  {
-    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
-    if ((a == null) || (b == null))
-      return null;
-
-    shortWritable.set((short)(a.get()/b.get()));
-    return shortWritable;
-  }
-
-  @Override
-  public IntWritable evaluate(IntWritable a, IntWritable b)  {
-    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
-    if ((a == null) || (b == null))
-      return null;
-
-    intWritable.set((int)(a.get()/b.get()));
-    return intWritable;
-  }
-
-  @Override
-  public LongWritable evaluate(LongWritable a, LongWritable b)  {
-    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
-    if ((a == null) || (b == null))
-      return null;
-
-    longWritable.set(a.get()/b.get());
-    return longWritable;
-  }
-
-  @Override
-  public FloatWritable evaluate(FloatWritable a, FloatWritable b)  {
-    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
-    if ((a == null) || (b == null))
-      return null;
-
-    floatWritable.set(a.get()/b.get());
-    return floatWritable;
-  }
+  protected DoubleWritable doubleWritable = new DoubleWritable();
   
-  @Override
   public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b)  {
     // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
     if ((a == null) || (b == null))
@@ -102,5 +51,4 @@
     doubleWritable.set(a.get()/b.get());
     return doubleWritable;
   }
-
 }

Added: hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPLongDivide.java
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPLongDivide.java?rev=806033&view=auto
==============================================================================
--- hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPLongDivide.java (added)
+++ hadoop/hive/branches/branch-0.4/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPLongDivide.java Thu Aug 20 03:31:25 2009
@@ -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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.ql.exec.description;
+import org.apache.hadoop.hive.serde2.io.ByteWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.io.FloatWritable;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.LongWritable;
+
+@description(
+    name = "/",
+    value = "a _FUNC_ b - Divide a by b rounded to the long integer",
+    extended = "Example:\n" +
+        "  > SELECT 3 _FUNC_ 2 FROM src LIMIT 1;\n" +
+        "  1"
+)
+public class UDFOPLongDivide extends UDF {
+
+  private static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.udf.UDFOPLongDivide");
+
+  protected LongWritable longWritable = new LongWritable();
+  
+  public LongWritable evaluate(LongWritable a, LongWritable b)  {
+    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
+    if ((a == null) || (b == null))
+      return null;
+
+    longWritable.set((long)a.get()/b.get());
+    return longWritable;
+  }
+}

Added: hadoop/hive/branches/branch-0.4/ql/src/test/queries/clientpositive/udf_divider.q
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/ql/src/test/queries/clientpositive/udf_divider.q?rev=806033&view=auto
==============================================================================
--- hadoop/hive/branches/branch-0.4/ql/src/test/queries/clientpositive/udf_divider.q (added)
+++ hadoop/hive/branches/branch-0.4/ql/src/test/queries/clientpositive/udf_divider.q Thu Aug 20 03:31:25 2009
@@ -0,0 +1,3 @@
+SELECT 3 / 2 FROM SRC LIMIT 1;
+
+SELECT DIV(3, 2) FROM SRC LIMIT 1;

Modified: hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/show_functions.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/show_functions.q.out?rev=806033&r1=806032&r2=806033&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/show_functions.q.out (original)
+++ hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/show_functions.q.out Thu Aug 20 03:31:25 2009
@@ -37,6 +37,7 @@
 datediff
 day
 dayofmonth
+div
 double
 elt
 exp

Added: hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/udf_divider.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/udf_divider.q.out?rev=806033&view=auto
==============================================================================
--- hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/udf_divider.q.out (added)
+++ hadoop/hive/branches/branch-0.4/ql/src/test/results/clientpositive/udf_divider.q.out Thu Aug 20 03:31:25 2009
@@ -0,0 +1,8 @@
+query: SELECT 3 / 2 FROM SRC LIMIT 1
+Input: default/src
+Output: file:/data/users/nzhang/work/774/774-trunk-apache-hive/build/ql/tmp/2108880178/10000
+1.5
+query: SELECT DIV(3, 2) FROM SRC LIMIT 1
+Input: default/src
+Output: file:/data/users/nzhang/work/774/774-trunk-apache-hive/build/ql/tmp/166968095/10000
+1