hadoop-hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zs...@apache.org
Subject svn commit: r798774 - 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 Wed, 29 Jul 2009 04:05:41 GMT
Author: zshao
Date: Wed Jul 29 04:05:40 2009
New Revision: 798774

URL: http://svn.apache.org/viewvc?rev=798774&view=rev
Log:
HIVE-656. Add a PMOD (POSITIVE MOD) function. (Scott Chen via zshao)

Added:
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java
    hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_pmod.q
    hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_pmod.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/results/clientpositive/show_functions.q.out

Modified: hadoop/hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=798774&r1=798773&r2=798774&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Wed Jul 29 04:05:40 2009
@@ -101,6 +101,8 @@
     HIVE-580. add 'show functions {pattern}'
     (Scott Chen via namit)
 
+    HIVE-656. Add a PMOD (POSITIVE MOD) function. (Scott Chen via zshao)
+
   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=798774&r1=798773&r2=798774&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 Wed
Jul 29 04:05:40 2009
@@ -74,6 +74,7 @@
     registerUDF("ceiling", UDFCeil.class, OperatorType.PREFIX, false);
     registerUDF("rand", UDFRand.class, OperatorType.PREFIX, false);
     registerUDF("abs", UDFAbs.class, OperatorType.PREFIX, false);
+    registerUDF("pmod", UDFPosMod.class, OperatorType.PREFIX, false);
 
     registerUDF("ln", UDFLn.class, OperatorType.PREFIX, false);
     registerUDF("log2", UDFLog2.class, OperatorType.PREFIX, false);

Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java?rev=798774&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java (added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java Wed Jul 29
04:05:40 2009
@@ -0,0 +1,104 @@
+/**
+ * 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.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;
+
+
+/**
+ * class for computing positive modulo.
+ * Used for positive_mod command in Cli
+ * @ See {@link org.apache.hadoop.hive.ql.udf.UDFOPMod}
+ * @ See {@link org.apache.hadoop.hive.ql.exec.FunctionRegistry}
+ */
+public class UDFPosMod extends UDFBaseNumericOp {
+
+  private static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.udf.UDFPosMod");
+
+  public UDFPosMod() {
+  }
+
+
+  @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()) + b.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()) + b.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()) + b.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()) + b.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()) + b.get()) % b.get());
+    return floatWritable;
+  }
+  
+  @Override
+  public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b)  {
+    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
+    if ((a == null) || (b == null))
+      return null;
+
+    doubleWritable.set(((a.get() % b.get()) + b.get()) % b.get());
+    return doubleWritable;
+  }
+}

Added: hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_pmod.q
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_pmod.q?rev=798774&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_pmod.q (added)
+++ hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf_pmod.q Wed Jul 29 04:05:40 2009
@@ -0,0 +1,8 @@
+SELECT pmod(null, null)
+FROM src LIMIT 1;
+
+SELECT pmod(-100,9), pmod(-50,101), pmod(-1000,29)
+FROM src LIMIT 1;
+
+SELECT pmod(100,19), pmod(50,125), pmod(300,15)
+FROM src LIMIT 1;

Modified: hadoop/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out?rev=798774&r1=798773&r2=798774&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out (original)
+++ hadoop/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out Wed Jul 29 04:05:40
2009
@@ -70,6 +70,7 @@
 not
 or
 parse_url
+pmod
 positive
 pow
 power

Added: hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_pmod.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_pmod.q.out?rev=798774&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_pmod.q.out (added)
+++ hadoop/hive/trunk/ql/src/test/results/clientpositive/udf_pmod.q.out Wed Jul 29 04:05:40
2009
@@ -0,0 +1,15 @@
+query: SELECT pmod(null, null)
+FROM src LIMIT 1
+Input: default/src
+Output: file:/mnt/vol/devrs001.snc1/schen/hive-trunk/build/ql/tmp/770960285/10000
+NULL
+query: SELECT pmod(-100,9), pmod(-50,101), pmod(-1000,29)
+FROM src LIMIT 1
+Input: default/src
+Output: file:/mnt/vol/devrs001.snc1/schen/hive-trunk/build/ql/tmp/1004944279/10000
+8	51	15
+query: SELECT pmod(100,19), pmod(50,125), pmod(300,15)
+FROM src LIMIT 1
+Input: default/src
+Output: file:/mnt/vol/devrs001.snc1/schen/hive-trunk/build/ql/tmp/1063528154/10000
+5	50	0



Mime
View raw message