Author: jdere
Date: Sat Jan 24 00:16:54 2015
New Revision: 1654440

URL: http://svn.apache.org/r1654440
Log:
HIVE-9402: Create GREATEST and LEAST udf (Alexander Pivovarov via Jason Dere)

Added:
    
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFGreatest.java
    
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLeast.java
    
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFGreatest.java
    
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLeast.java
    hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_1.q
    hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_2.q
    hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_3.q
    hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_4.q
    hive/trunk/ql/src/test/queries/clientpositive/udf_greatest.q
    hive/trunk/ql/src/test/queries/clientpositive/udf_least.q
    hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_1.q.out
    hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_2.q.out
    hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_3.q.out
    hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_4.q.out
    hive/trunk/ql/src/test/results/clientpositive/udf_greatest.q.out
    hive/trunk/ql/src/test/results/clientpositive/udf_least.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
    hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out

Modified: 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=1654440&r1=1654439&r2=1654440&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java 
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java 
Sat Jan 24 00:16:54 2015
@@ -423,6 +423,8 @@ public final class FunctionRegistry {
     registerGenericUDF("map_values", GenericUDFMapValues.class);
     registerGenericUDF("format_number", GenericUDFFormatNumber.class);
     registerGenericUDF("printf", GenericUDFPrintf.class);
+    registerGenericUDF("greatest", GenericUDFGreatest.class);
+    registerGenericUDF("least", GenericUDFLeast.class);
 
     registerGenericUDF("from_utc_timestamp", GenericUDFFromUtcTimestamp.class);
     registerGenericUDF("to_utc_timestamp", GenericUDFToUtcTimestamp.class);

Added: 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFGreatest.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFGreatest.java?rev=1654440&view=auto
==============================================================================
--- 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFGreatest.java
 (added)
+++ 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFGreatest.java
 Sat Jan 24 00:16:54 2015
@@ -0,0 +1,117 @@
+/**
+ * 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.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+
+/**
+ * GenericUDF Class for SQL construct "greatest(v1, v2, .. vn)".
+ *
+ * NOTES: 1. v1, v2 and vn should have the same TypeInfo, or an exception will
+ * be thrown.
+ */
+@Description(name = "greatest",
+    value = "_FUNC_(v1, v2, ...) - Returns the greatest value in a list of 
values",
+    extended = "Example:\n"
+    + "  > SELECT _FUNC_(2, 3, 1) FROM src LIMIT 1;\n" + "  3")
+public class GenericUDFGreatest extends GenericUDF {
+  private transient ObjectInspector[] argumentOIs;
+  private transient GenericUDFUtils.ReturnObjectInspectorResolver 
returnOIResolver;
+
+  @Override
+  public ObjectInspector initialize(ObjectInspector[] arguments) throws 
UDFArgumentException {
+    if (arguments.length < 2) {
+      throw new UDFArgumentLengthException(getFuncName() + " requires at least 
2 arguments, got "
+          + arguments.length);
+    }
+    if (arguments[0].getCategory() != Category.PRIMITIVE) {
+      throw new UDFArgumentException(getFuncName() + " only takes primitive 
types, got "
+          + arguments[0].getTypeName());
+    }
+
+    argumentOIs = arguments;
+
+    returnOIResolver = new 
GenericUDFUtils.ReturnObjectInspectorResolver(false);
+    for (int i = 0; i < arguments.length; i++) {
+      if (!returnOIResolver.update(arguments[i])) {
+        throw new UDFArgumentTypeException(i, "The expressions after " + 
getFuncName()
+            + " should all have the same type: \"" + 
returnOIResolver.get().getTypeName()
+            + "\" is expected but \"" + arguments[i].getTypeName() + "\" is 
found");
+      }
+    }
+    return returnOIResolver.get();
+  }
+
+  @SuppressWarnings({ "rawtypes", "unchecked" })
+  @Override
+  public Object evaluate(DeferredObject[] arguments) throws HiveException {
+    Comparable maxV = null;
+    int maxIndex = 0;
+    for (int i = 0; i < arguments.length; i++) {
+      Object ai = arguments[i].get();
+      if (ai == null) {
+        continue;
+      }
+      // all PRIMITIVEs are Comparable
+      Comparable v = (Comparable) ai;
+      if (maxV == null) {
+        maxV = v;
+        maxIndex = i;
+        continue;
+      }
+      if ((isGreatest() ? 1 : -1) * v.compareTo(maxV) > 0) {
+        maxV = v;
+        maxIndex = i;
+      }
+    }
+    if (maxV != null) {
+      return returnOIResolver.convertIfNecessary(maxV, argumentOIs[maxIndex]);
+    }
+    return null;
+  }
+
+  @Override
+  public String getDisplayString(String[] children) {
+    StringBuilder sb = new StringBuilder();
+    sb.append(getFuncName()).append("(");
+    if (children.length > 0) {
+      sb.append(children[0]);
+      for (int i = 1; i < children.length; i++) {
+        sb.append(",");
+        sb.append(children[i]);
+      }
+    }
+    sb.append(")");
+    return sb.toString();
+  }
+
+  protected String getFuncName() {
+    return "greatest";
+  }
+
+  protected boolean isGreatest() {
+    return true;
+  }
+}

Added: 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLeast.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLeast.java?rev=1654440&view=auto
==============================================================================
--- 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLeast.java
 (added)
+++ 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLeast.java
 Sat Jan 24 00:16:54 2015
@@ -0,0 +1,44 @@
+/**
+ * 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.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+
+/**
+ * GenericUDF Class for SQL construct "least(v1, v2, .. vn)".
+ *
+ * NOTES: 1. v1, v2 and vn should have the same TypeInfo, or an exception will
+ * be thrown.
+ */
+@Description(name = "least",
+    value = "_FUNC_(v1, v2, ...) - Returns the least value in a list of 
values",
+    extended = "Example:\n"
+    + "  > SELECT _FUNC_(2, 3, 1) FROM src LIMIT 1;\n" + "  1")
+public class GenericUDFLeast extends GenericUDFGreatest {
+
+  @Override
+  protected String getFuncName() {
+    return "least";
+  }
+
+  @Override
+  protected boolean isGreatest() {
+    return false;
+  }
+}

Added: 
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFGreatest.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFGreatest.java?rev=1654440&view=auto
==============================================================================
--- 
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFGreatest.java
 (added)
+++ 
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFGreatest.java
 Sat Jan 24 00:16:54 2015
@@ -0,0 +1,200 @@
+/**
+ * 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.generic;
+
+import java.sql.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject;
+import org.apache.hadoop.hive.serde2.io.DateWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.Text;
+
+public class TestGenericUDFGreatest extends TestCase {
+
+  public void testOneArg() throws HiveException {
+    @SuppressWarnings("resource")
+    GenericUDFGreatest udf = new GenericUDFGreatest();
+    ObjectInspector valueOI1 = 
PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+    ObjectInspector[] arguments = { valueOI1 };
+
+    UDFArgumentException ex = null;
+    try {
+      udf.initialize(arguments);
+    } catch (UDFArgumentException e) {
+      ex = e;
+    }
+    assertNotNull("greatest() test ", ex);
+  }
+
+  public void testDifferentType() throws HiveException {
+    @SuppressWarnings("resource")
+    GenericUDFGreatest udf = new GenericUDFGreatest();
+    ObjectInspector valueOI1 = 
PrimitiveObjectInspectorFactory.writableIntObjectInspector;
+    ObjectInspector valueOI2 = 
PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
+    ObjectInspector[] arguments = { valueOI1, valueOI2 };
+
+    UDFArgumentException ex = null;
+    try {
+      udf.initialize(arguments);
+    } catch (UDFArgumentException e) {
+      ex = e;
+    }
+    assertNotNull("greatest() test ", ex);
+  }
+
+  public void testGreatestStr() throws HiveException {
+    GenericUDFGreatest udf = new GenericUDFGreatest();
+    ObjectInspector[] arguments = new ObjectInspector[3];
+    for (int i = 0; i < arguments.length; i++) {
+      arguments[i] = 
PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+    }
+
+    udf.initialize(arguments);
+
+    runAndVerify(new String[] { "a", "b", "c" }, "c", udf);
+    runAndVerify(new String[] { "C", "a", "B" }, "a", udf);
+    runAndVerify(new String[] { "AAA", "AaA", "AAa" }, "AaA", udf);
+    runAndVerify(new String[] { "A", "AA", "AAA" }, "AAA", udf);
+
+    runAndVerify(new String[] { "11", "13", "12" }, "13", udf);
+    runAndVerify(new String[] { "11", "2", "12" }, "2", udf);
+    runAndVerify(new String[] { "01", "03", "02" }, "03", udf);
+    runAndVerify(new String[] { "01", "1", "02" }, "1", udf);
+
+    runAndVerify(new String[] { null, "b", "c" }, "c", udf);
+    runAndVerify(new String[] { "a", null, "c" }, "c", udf);
+    runAndVerify(new String[] { "a", "b", null }, "b", udf);
+
+    runAndVerify(new String[] { "a", null, null }, "a", udf);
+    runAndVerify(new String[] { null, "b", null }, "b", udf);
+    runAndVerify(new String[] { null, null, null }, null, udf);
+  }
+
+  public void testGreatestInt() throws HiveException {
+    GenericUDFGreatest udf = new GenericUDFGreatest();
+    ObjectInspector[] arguments = new ObjectInspector[3];
+    for (int i = 0; i < arguments.length; i++) {
+      arguments[i] = 
PrimitiveObjectInspectorFactory.writableIntObjectInspector;
+    }
+
+    udf.initialize(arguments);
+
+    runAndVerify(new Integer[] { 11, 13, 12 }, 13, udf);
+    runAndVerify(new Integer[] { 1, 13, 2 }, 13, udf);
+
+    runAndVerify(new Integer[] { -11, -13, -12 }, -11, udf);
+    runAndVerify(new Integer[] { 1, -13, 2 }, 2, udf);
+
+    runAndVerify(new Integer[] { null, 1, 2 }, 2, udf);
+    runAndVerify(new Integer[] { 1, null, 2 }, 2, udf);
+    runAndVerify(new Integer[] { 1, 2, null }, 2, udf);
+
+    runAndVerify(new Integer[] { null, null, null }, null, udf);
+  }
+
+  public void testGreatestDouble() throws HiveException {
+    GenericUDFGreatest udf = new GenericUDFGreatest();
+    ObjectInspector[] arguments = new ObjectInspector[3];
+    for (int i = 0; i < arguments.length; i++) {
+      arguments[i] = 
PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
+    }
+
+    udf.initialize(arguments);
+
+    runAndVerify(new Double[] { 11.4, 11.5, 11.2 }, 11.5, udf);
+    runAndVerify(new Double[] { 1.0, 13.3, 2.0 }, 13.3, udf);
+
+    runAndVerify(new Double[] { -11.4, -13.1, -12.2 }, -11.4, udf);
+    runAndVerify(new Double[] { 1.0, -13.3, 2.2 }, 2.2, udf);
+
+    runAndVerify(new Double[] { null, 1.1, 2.2 }, 2.2, udf);
+    runAndVerify(new Double[] { 1.1, null, 2.2 }, 2.2, udf);
+    runAndVerify(new Double[] { 1.1, 2.2, null }, 2.2, udf);
+
+    runAndVerify(new Double[] { null, null, null }, null, udf);
+  }
+
+  public void testGreatestDate() throws HiveException {
+    GenericUDFGreatest udf = new GenericUDFGreatest();
+    ObjectInspector[] arguments = new ObjectInspector[3];
+    for (int i = 0; i < arguments.length; i++) {
+      arguments[i] = 
PrimitiveObjectInspectorFactory.writableDateObjectInspector;
+    }
+
+    udf.initialize(arguments);
+
+    Date d1 = Date.valueOf("2015-03-20");
+    Date d2 = Date.valueOf("2015-03-21");
+    Date d3 = Date.valueOf("2014-03-20");
+
+    runAndVerify(new Date[] { d1, d2, d3 }, d2, udf);
+
+    runAndVerify(new Date[] { null, d2, d3 }, d2, udf);
+    runAndVerify(new Date[] { d1, null, d3 }, d1, udf);
+    runAndVerify(new Date[] { d1, d2, null }, d2, udf);
+
+    runAndVerify(new Date[] { null, null, null }, null, udf);
+  }
+
+  private void runAndVerify(String[] v, String expResult, GenericUDF udf) 
throws HiveException {
+    DeferredObject[] args = new DeferredObject[v.length];
+    for (int i = 0; i < v.length; i++) {
+      args[i] = new DeferredJavaObject(v[i] != null ? new Text(v[i]) : null);
+    }
+    Text output = (Text) udf.evaluate(args);
+    assertEquals("greatest() test ", expResult, output != null ? 
output.toString() : null);
+  }
+
+  private void runAndVerify(Integer[] v, Integer expResult, GenericUDF udf) 
throws HiveException {
+    DeferredObject[] args = new DeferredObject[v.length];
+    for (int i = 0; i < v.length; i++) {
+      args[i] = new DeferredJavaObject(v[i] != null ? new IntWritable(v[i]) : 
null);
+    }
+    IntWritable output = (IntWritable) udf.evaluate(args);
+    Integer res = output != null ? Integer.valueOf(output.get()) : null;
+    assertEquals("greatest() test ", expResult, res);
+  }
+
+  private void runAndVerify(Double[] v, Double expResult, GenericUDF udf) 
throws HiveException {
+    DeferredObject[] args = new DeferredObject[v.length];
+    for (int i = 0; i < v.length; i++) {
+      args[i] = new DeferredJavaObject(v[i] != null ? new DoubleWritable(v[i]) 
: null);
+    }
+    DoubleWritable output = (DoubleWritable) udf.evaluate(args);
+    Double res = output != null ? Double.valueOf(output.get()) : null;
+    assertEquals("greatest() test ", expResult, res);
+  }
+
+  private void runAndVerify(Date[] v, Date expResult, GenericUDF udf) throws 
HiveException {
+    DeferredObject[] args = new DeferredObject[v.length];
+    for (int i = 0; i < v.length; i++) {
+      args[i] = new DeferredJavaObject(v[i] != null ? new DateWritable(v[i]) : 
null);
+    }
+    DateWritable output = (DateWritable) udf.evaluate(args);
+    Date res = output != null ? output.get() : null;
+    assertEquals("greatest() test ", expResult, res);
+  }
+}

Added: 
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLeast.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLeast.java?rev=1654440&view=auto
==============================================================================
--- 
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLeast.java
 (added)
+++ 
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLeast.java
 Sat Jan 24 00:16:54 2015
@@ -0,0 +1,200 @@
+/**
+ * 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.generic;
+
+import java.sql.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject;
+import org.apache.hadoop.hive.serde2.io.DateWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.Text;
+
+public class TestGenericUDFLeast extends TestCase {
+
+  public void testOneArg() throws HiveException {
+    @SuppressWarnings("resource")
+    GenericUDFLeast udf = new GenericUDFLeast();
+    ObjectInspector valueOI1 = 
PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+    ObjectInspector[] arguments = { valueOI1 };
+
+    UDFArgumentException ex = null;
+    try {
+      udf.initialize(arguments);
+    } catch (UDFArgumentException e) {
+      ex = e;
+    }
+    assertNotNull("least() test ", ex);
+  }
+
+  public void testDifferentType() throws HiveException {
+    @SuppressWarnings("resource")
+    GenericUDFLeast udf = new GenericUDFLeast();
+    ObjectInspector valueOI1 = 
PrimitiveObjectInspectorFactory.writableIntObjectInspector;
+    ObjectInspector valueOI2 = 
PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
+    ObjectInspector[] arguments = { valueOI1, valueOI2 };
+
+    UDFArgumentException ex = null;
+    try {
+      udf.initialize(arguments);
+    } catch (UDFArgumentException e) {
+      ex = e;
+    }
+    assertNotNull("least() test ", ex);
+  }
+
+  public void testLeastStr() throws HiveException {
+    GenericUDFLeast udf = new GenericUDFLeast();
+    ObjectInspector[] arguments = new ObjectInspector[3];
+    for (int i = 0; i < arguments.length; i++) {
+      arguments[i] = 
PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+    }
+
+    udf.initialize(arguments);
+
+    runAndVerify(new String[] { "a", "b", "c" }, "a", udf);
+    runAndVerify(new String[] { "C", "a", "B" }, "B", udf);
+    runAndVerify(new String[] { "AAA", "AaA", "AAa" }, "AAA", udf);
+    runAndVerify(new String[] { "A", "AA", "AAA" }, "A", udf);
+
+    runAndVerify(new String[] { "11", "13", "12" }, "11", udf);
+    runAndVerify(new String[] { "11", "2", "12" }, "11", udf);
+    runAndVerify(new String[] { "01", "03", "02" }, "01", udf);
+    runAndVerify(new String[] { "01", "1", "02" }, "01", udf);
+
+    runAndVerify(new String[] { null, "b", "c" }, "b", udf);
+    runAndVerify(new String[] { "a", null, "c" }, "a", udf);
+    runAndVerify(new String[] { "a", "b", null }, "a", udf);
+
+    runAndVerify(new String[] { "a", null, null }, "a", udf);
+    runAndVerify(new String[] { null, "b", null }, "b", udf);
+    runAndVerify(new String[] { null, null, null }, null, udf);
+  }
+
+  public void testLeastInt() throws HiveException {
+    GenericUDFLeast udf = new GenericUDFLeast();
+    ObjectInspector[] arguments = new ObjectInspector[3];
+    for (int i = 0; i < arguments.length; i++) {
+      arguments[i] = 
PrimitiveObjectInspectorFactory.writableIntObjectInspector;
+    }
+
+    udf.initialize(arguments);
+
+    runAndVerify(new Integer[] { 11, 13, 12 }, 11, udf);
+    runAndVerify(new Integer[] { 1, 13, 2 }, 1, udf);
+
+    runAndVerify(new Integer[] { -11, -13, -12 }, -13, udf);
+    runAndVerify(new Integer[] { 1, -13, 2 }, -13, udf);
+
+    runAndVerify(new Integer[] { null, 1, 2 }, 1, udf);
+    runAndVerify(new Integer[] { 1, null, 2 }, 1, udf);
+    runAndVerify(new Integer[] { 1, 2, null }, 1, udf);
+
+    runAndVerify(new Integer[] { null, null, null }, null, udf);
+  }
+
+  public void testLeastDouble() throws HiveException {
+    GenericUDFLeast udf = new GenericUDFLeast();
+    ObjectInspector[] arguments = new ObjectInspector[3];
+    for (int i = 0; i < arguments.length; i++) {
+      arguments[i] = 
PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
+    }
+
+    udf.initialize(arguments);
+
+    runAndVerify(new Double[] { 11.4, 11.5, 11.2 }, 11.2, udf);
+    runAndVerify(new Double[] { 1.0, 13.3, 2.0 }, 1.0, udf);
+
+    runAndVerify(new Double[] { -11.4, -13.1, -12.2 }, -13.1, udf);
+    runAndVerify(new Double[] { 1.0, -13.3, 2.2 }, -13.3, udf);
+
+    runAndVerify(new Double[] { null, 1.1, 2.2 }, 1.1, udf);
+    runAndVerify(new Double[] { 1.1, null, 2.2 }, 1.1, udf);
+    runAndVerify(new Double[] { 1.1, 2.2, null }, 1.1, udf);
+
+    runAndVerify(new Double[] { null, null, null }, null, udf);
+  }
+
+  public void testLeastDate() throws HiveException {
+    GenericUDFLeast udf = new GenericUDFLeast();
+    ObjectInspector[] arguments = new ObjectInspector[3];
+    for (int i = 0; i < arguments.length; i++) {
+      arguments[i] = 
PrimitiveObjectInspectorFactory.writableDateObjectInspector;
+    }
+
+    udf.initialize(arguments);
+
+    Date d1 = Date.valueOf("2015-03-20");
+    Date d2 = Date.valueOf("2015-03-21");
+    Date d3 = Date.valueOf("2014-03-20");
+
+    runAndVerify(new Date[] { d1, d2, d3 }, d3, udf);
+
+    runAndVerify(new Date[] { null, d2, d3 }, d3, udf);
+    runAndVerify(new Date[] { d1, null, d3 }, d3, udf);
+    runAndVerify(new Date[] { d1, d2, null }, d1, udf);
+
+    runAndVerify(new Date[] { null, null, null }, null, udf);
+  }
+
+  private void runAndVerify(String[] v, String expResult, GenericUDF udf) 
throws HiveException {
+    DeferredObject[] args = new DeferredObject[v.length];
+    for (int i = 0; i < v.length; i++) {
+      args[i] = new DeferredJavaObject(v[i] != null ? new Text(v[i]) : null);
+    }
+    Text output = (Text) udf.evaluate(args);
+    assertEquals("least() test ", expResult, output != null ? 
output.toString() : null);
+  }
+
+  private void runAndVerify(Integer[] v, Integer expResult, GenericUDF udf) 
throws HiveException {
+    DeferredObject[] args = new DeferredObject[v.length];
+    for (int i = 0; i < v.length; i++) {
+      args[i] = new DeferredJavaObject(v[i] != null ? new IntWritable(v[i]) : 
null);
+    }
+    IntWritable output = (IntWritable) udf.evaluate(args);
+    Integer res = output != null ? Integer.valueOf(output.get()) : null;
+    assertEquals("least() test ", expResult, res);
+  }
+
+  private void runAndVerify(Double[] v, Double expResult, GenericUDF udf) 
throws HiveException {
+    DeferredObject[] args = new DeferredObject[v.length];
+    for (int i = 0; i < v.length; i++) {
+      args[i] = new DeferredJavaObject(v[i] != null ? new DoubleWritable(v[i]) 
: null);
+    }
+    DoubleWritable output = (DoubleWritable) udf.evaluate(args);
+    Double res = output != null ? Double.valueOf(output.get()) : null;
+    assertEquals("least() test ", expResult, res);
+  }
+
+  private void runAndVerify(Date[] v, Date expResult, GenericUDF udf) throws 
HiveException {
+    DeferredObject[] args = new DeferredObject[v.length];
+    for (int i = 0; i < v.length; i++) {
+      args[i] = new DeferredJavaObject(v[i] != null ? new DateWritable(v[i]) : 
null);
+    }
+    DateWritable output = (DateWritable) udf.evaluate(args);
+    Date res = output != null ? output.get() : null;
+    assertEquals("least() test ", expResult, res);
+  }
+}

Added: hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_1.q
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_1.q?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_1.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_1.q Sat 
Jan 24 00:16:54 2015
@@ -0,0 +1 @@
+SELECT GREATEST(array('a', 'b'), '2.0') FROM src LIMIT 1;

Added: hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_2.q
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_2.q?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_2.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_2.q Sat 
Jan 24 00:16:54 2015
@@ -0,0 +1 @@
+SELECT GREATEST(1, 2.2) FROM src LIMIT 1;

Added: hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_3.q
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_3.q?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_3.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_3.q Sat 
Jan 24 00:16:54 2015
@@ -0,0 +1 @@
+SELECT GREATEST(1, '2') FROM src LIMIT 1;

Added: hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_4.q
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_4.q?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_4.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/udf_greatest_error_4.q Sat 
Jan 24 00:16:54 2015
@@ -0,0 +1 @@
+SELECT GREATEST(1) FROM src LIMIT 1;

Added: hive/trunk/ql/src/test/queries/clientpositive/udf_greatest.q
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_greatest.q?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_greatest.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_greatest.q Sat Jan 24 
00:16:54 2015
@@ -0,0 +1,57 @@
+set hive.fetch.task.conversion=more;
+
+DESCRIBE FUNCTION greatest;
+DESCRIBE FUNCTION EXTENDED greatest;
+
+EXPLAIN
+SELECT GREATEST('a', 'b', 'c'),
+       GREATEST('C', 'a', 'B'),
+       GREATEST('AAA', 'AaA', 'AAa'),
+       GREATEST('A', 'AA', 'AAA'),
+       GREATEST('11', '13', '12'),
+       GREATEST('11', '2', '12'),
+       GREATEST('01', '03', '02'),
+       GREATEST('01', '1', '02'),
+       GREATEST(null, 'b', 'c' ),
+       GREATEST('a', null, 'c'),
+       GREATEST('a', 'b', null ),
+       GREATEST('a', null, null),
+       GREATEST(null, 'b', null),
+       GREATEST(cast(null as string), null, null)
+FROM src tablesample (1 rows);
+
+SELECT GREATEST('a', 'b', 'c'),
+       GREATEST('C', 'a', 'B'),
+       GREATEST('AAA', 'AaA', 'AAa'),
+       GREATEST('A', 'AA', 'AAA'),
+       GREATEST('11', '13', '12'),
+       GREATEST('11', '2', '12'),
+       GREATEST('01', '03', '02'),
+       GREATEST('01', '1', '02'),
+       GREATEST(null, 'b', 'c' ),
+       GREATEST('a', null, 'c'),
+       GREATEST('a', 'b', null ),
+       GREATEST('a', null, null),
+       GREATEST(null, 'b', null),
+       GREATEST(cast(null as string), null, null)
+FROM src tablesample (1 rows);
+
+SELECT GREATEST(11, 13, 12),
+       GREATEST(1, 13, 2),
+       GREATEST(-11, -13, -12),
+       GREATEST(1, -13, 2),
+       GREATEST(null, 1, 2),
+       GREATEST(1, null, 2),
+       GREATEST(1, 2, null),
+       GREATEST(cast(null as int), null, null)
+FROM src tablesample (1 rows);
+
+SELECT GREATEST(11.4, 13.5, 12.2),
+       GREATEST(1.0, 13.2, 2.0),
+       GREATEST(-11.4, -13.1, -12.2),
+       GREATEST(1.0, -13.3, 2.2),
+       GREATEST(null, 1.1, 2.2),
+       GREATEST(1.1, null, 2.2),
+       GREATEST(1.1, 2.2, null),
+       GREATEST(cast(null as double), null, null)
+FROM src tablesample (1 rows);

Added: hive/trunk/ql/src/test/queries/clientpositive/udf_least.q
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_least.q?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_least.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_least.q Sat Jan 24 
00:16:54 2015
@@ -0,0 +1,57 @@
+set hive.fetch.task.conversion=more;
+
+DESCRIBE FUNCTION least;
+DESCRIBE FUNCTION EXTENDED least;
+
+EXPLAIN
+SELECT LEAST('a', 'b', 'c'),
+       LEAST('C', 'a', 'B'),
+       LEAST('AAA', 'AaA', 'AAa'),
+       LEAST('A', 'AA', 'AAA'),
+       LEAST('11', '13', '12'),
+       LEAST('11', '2', '12'),
+       LEAST('01', '03', '02'),
+       LEAST('01', '1', '02'),
+       LEAST(null, 'b', 'c' ),
+       LEAST('a', null, 'c'),
+       LEAST('a', 'b', null ),
+       LEAST('a', null, null),
+       LEAST(null, 'b', null),
+       LEAST(cast(null as string), null, null)
+FROM src tablesample (1 rows);
+
+SELECT LEAST('a', 'b', 'c'),
+       LEAST('C', 'a', 'B'),
+       LEAST('AAA', 'AaA', 'AAa'),
+       LEAST('A', 'AA', 'AAA'),
+       LEAST('11', '13', '12'),
+       LEAST('11', '2', '12'),
+       LEAST('01', '03', '02'),
+       LEAST('01', '1', '02'),
+       LEAST(null, 'b', 'c' ),
+       LEAST('a', null, 'c'),
+       LEAST('a', 'b', null ),
+       LEAST('a', null, null),
+       LEAST(null, 'b', null),
+       LEAST(cast(null as string), null, null)
+FROM src tablesample (1 rows);
+
+SELECT LEAST(11, 13, 12),
+       LEAST(1, 13, 2),
+       LEAST(-11, -13, -12),
+       LEAST(1, -13, 2),
+       LEAST(null, 1, 2),
+       LEAST(1, null, 2),
+       LEAST(1, 2, null),
+       LEAST(cast(null as int), null, null)
+FROM src tablesample (1 rows);
+
+SELECT LEAST(11.4, 13.5, 12.2),
+       LEAST(1.0, 13.2, 2.0),
+       LEAST(-11.4, -13.1, -12.2),
+       LEAST(1.0, -13.3, 2.2),
+       LEAST(null, 1.1, 2.2),
+       LEAST(1.1, null, 2.2),
+       LEAST(1.1, 2.2, null),
+       LEAST(cast(null as double), null, null)
+FROM src tablesample (1 rows);

Added: hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_1.q.out
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_1.q.out?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_1.q.out 
(added)
+++ hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_1.q.out 
Sat Jan 24 00:16:54 2015
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments ''2.0'': 
greatest only takes primitive types, got array<string>

Added: hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_2.q.out
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_2.q.out?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_2.q.out 
(added)
+++ hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_2.q.out 
Sat Jan 24 00:16:54 2015
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10016]: Line 1:19 Argument type mismatch 
'2.2': The expressions after greatest should all have the same type: "int" is 
expected but "double" is found

Added: hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_3.q.out
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_3.q.out?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_3.q.out 
(added)
+++ hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_3.q.out 
Sat Jan 24 00:16:54 2015
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10016]: Line 1:19 Argument type mismatch 
''2'': The expressions after greatest should all have the same type: "int" is 
expected but "string" is found

Added: hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_4.q.out
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_4.q.out?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_4.q.out 
(added)
+++ hive/trunk/ql/src/test/results/clientnegative/udf_greatest_error_4.q.out 
Sat Jan 24 00:16:54 2015
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10015]: Line 1:7 Arguments length mismatch 
'1': greatest requires at least 2 arguments, got 1

Modified: hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out?rev=1654440&r1=1654439&r2=1654440&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out 
(original)
+++ hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out Sat Jan 
24 00:16:54 2015
@@ -79,6 +79,7 @@ format_number
 from_unixtime
 from_utc_timestamp
 get_json_object
+greatest
 hash
 hex
 histogram_numeric
@@ -99,6 +100,7 @@ last_day
 last_value
 lcase
 lead
+least
 length
 like
 ln

Added: hive/trunk/ql/src/test/results/clientpositive/udf_greatest.q.out
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_greatest.q.out?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_greatest.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_greatest.q.out Sat Jan 24 
00:16:54 2015
@@ -0,0 +1,152 @@
+PREHOOK: query: DESCRIBE FUNCTION greatest
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION greatest
+POSTHOOK: type: DESCFUNCTION
+greatest(v1, v2, ...) - Returns the greatest value in a list of values
+PREHOOK: query: DESCRIBE FUNCTION EXTENDED greatest
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION EXTENDED greatest
+POSTHOOK: type: DESCFUNCTION
+greatest(v1, v2, ...) - Returns the greatest value in a list of values
+Example:
+  > SELECT greatest(2, 3, 1) FROM src LIMIT 1;
+  3
+PREHOOK: query: EXPLAIN
+SELECT GREATEST('a', 'b', 'c'),
+       GREATEST('C', 'a', 'B'),
+       GREATEST('AAA', 'AaA', 'AAa'),
+       GREATEST('A', 'AA', 'AAA'),
+       GREATEST('11', '13', '12'),
+       GREATEST('11', '2', '12'),
+       GREATEST('01', '03', '02'),
+       GREATEST('01', '1', '02'),
+       GREATEST(null, 'b', 'c' ),
+       GREATEST('a', null, 'c'),
+       GREATEST('a', 'b', null ),
+       GREATEST('a', null, null),
+       GREATEST(null, 'b', null),
+       GREATEST(cast(null as string), null, null)
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+POSTHOOK: query: EXPLAIN
+SELECT GREATEST('a', 'b', 'c'),
+       GREATEST('C', 'a', 'B'),
+       GREATEST('AAA', 'AaA', 'AAa'),
+       GREATEST('A', 'AA', 'AAA'),
+       GREATEST('11', '13', '12'),
+       GREATEST('11', '2', '12'),
+       GREATEST('01', '03', '02'),
+       GREATEST('01', '1', '02'),
+       GREATEST(null, 'b', 'c' ),
+       GREATEST('a', null, 'c'),
+       GREATEST('a', 'b', null ),
+       GREATEST('a', null, null),
+       GREATEST(null, 'b', null),
+       GREATEST(cast(null as string), null, null)
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+STAGE DEPENDENCIES:
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+      Processor Tree:
+        TableScan
+          alias: src
+          Row Limit Per Split: 1
+          Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE 
Column stats: COMPLETE
+          Select Operator
+            expressions: 'c' (type: string), 'a' (type: string), 'AaA' (type: 
string), 'AAA' (type: string), '13' (type: string), '2' (type: string), '03' 
(type: string), '1' (type: string), greatest(null,'b','c') (type: string), 
greatest('a',null,'c') (type: string), greatest('a','b',null) (type: string), 
greatest('a',null,null) (type: string), greatest(null,'b',null) (type: string), 
greatest(UDFToString(null),null,null) (type: string)
+            outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, 
_col6, _col7, _col8, _col9, _col10, _col11, _col12, _col13
+            Statistics: Num rows: 500 Data size: 597500 Basic stats: COMPLETE 
Column stats: COMPLETE
+            ListSink
+
+PREHOOK: query: SELECT GREATEST('a', 'b', 'c'),
+       GREATEST('C', 'a', 'B'),
+       GREATEST('AAA', 'AaA', 'AAa'),
+       GREATEST('A', 'AA', 'AAA'),
+       GREATEST('11', '13', '12'),
+       GREATEST('11', '2', '12'),
+       GREATEST('01', '03', '02'),
+       GREATEST('01', '1', '02'),
+       GREATEST(null, 'b', 'c' ),
+       GREATEST('a', null, 'c'),
+       GREATEST('a', 'b', null ),
+       GREATEST('a', null, null),
+       GREATEST(null, 'b', null),
+       GREATEST(cast(null as string), null, null)
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT GREATEST('a', 'b', 'c'),
+       GREATEST('C', 'a', 'B'),
+       GREATEST('AAA', 'AaA', 'AAa'),
+       GREATEST('A', 'AA', 'AAA'),
+       GREATEST('11', '13', '12'),
+       GREATEST('11', '2', '12'),
+       GREATEST('01', '03', '02'),
+       GREATEST('01', '1', '02'),
+       GREATEST(null, 'b', 'c' ),
+       GREATEST('a', null, 'c'),
+       GREATEST('a', 'b', null ),
+       GREATEST('a', null, null),
+       GREATEST(null, 'b', null),
+       GREATEST(cast(null as string), null, null)
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+c      a       AaA     AAA     13      2       03      1       c       c       
b       a       b       NULL
+PREHOOK: query: SELECT GREATEST(11, 13, 12),
+       GREATEST(1, 13, 2),
+       GREATEST(-11, -13, -12),
+       GREATEST(1, -13, 2),
+       GREATEST(null, 1, 2),
+       GREATEST(1, null, 2),
+       GREATEST(1, 2, null),
+       GREATEST(cast(null as int), null, null)
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT GREATEST(11, 13, 12),
+       GREATEST(1, 13, 2),
+       GREATEST(-11, -13, -12),
+       GREATEST(1, -13, 2),
+       GREATEST(null, 1, 2),
+       GREATEST(1, null, 2),
+       GREATEST(1, 2, null),
+       GREATEST(cast(null as int), null, null)
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+13     13      -11     2       2       2       2       NULL
+PREHOOK: query: SELECT GREATEST(11.4, 13.5, 12.2),
+       GREATEST(1.0, 13.2, 2.0),
+       GREATEST(-11.4, -13.1, -12.2),
+       GREATEST(1.0, -13.3, 2.2),
+       GREATEST(null, 1.1, 2.2),
+       GREATEST(1.1, null, 2.2),
+       GREATEST(1.1, 2.2, null),
+       GREATEST(cast(null as double), null, null)
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT GREATEST(11.4, 13.5, 12.2),
+       GREATEST(1.0, 13.2, 2.0),
+       GREATEST(-11.4, -13.1, -12.2),
+       GREATEST(1.0, -13.3, 2.2),
+       GREATEST(null, 1.1, 2.2),
+       GREATEST(1.1, null, 2.2),
+       GREATEST(1.1, 2.2, null),
+       GREATEST(cast(null as double), null, null)
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+13.5   13.2    -11.4   2.2     2.2     2.2     2.2     NULL

Added: hive/trunk/ql/src/test/results/clientpositive/udf_least.q.out
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_least.q.out?rev=1654440&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_least.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_least.q.out Sat Jan 24 
00:16:54 2015
@@ -0,0 +1,152 @@
+PREHOOK: query: DESCRIBE FUNCTION least
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION least
+POSTHOOK: type: DESCFUNCTION
+least(v1, v2, ...) - Returns the least value in a list of values
+PREHOOK: query: DESCRIBE FUNCTION EXTENDED least
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION EXTENDED least
+POSTHOOK: type: DESCFUNCTION
+least(v1, v2, ...) - Returns the least value in a list of values
+Example:
+  > SELECT least(2, 3, 1) FROM src LIMIT 1;
+  1
+PREHOOK: query: EXPLAIN
+SELECT LEAST('a', 'b', 'c'),
+       LEAST('C', 'a', 'B'),
+       LEAST('AAA', 'AaA', 'AAa'),
+       LEAST('A', 'AA', 'AAA'),
+       LEAST('11', '13', '12'),
+       LEAST('11', '2', '12'),
+       LEAST('01', '03', '02'),
+       LEAST('01', '1', '02'),
+       LEAST(null, 'b', 'c' ),
+       LEAST('a', null, 'c'),
+       LEAST('a', 'b', null ),
+       LEAST('a', null, null),
+       LEAST(null, 'b', null),
+       LEAST(cast(null as string), null, null)
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+POSTHOOK: query: EXPLAIN
+SELECT LEAST('a', 'b', 'c'),
+       LEAST('C', 'a', 'B'),
+       LEAST('AAA', 'AaA', 'AAa'),
+       LEAST('A', 'AA', 'AAA'),
+       LEAST('11', '13', '12'),
+       LEAST('11', '2', '12'),
+       LEAST('01', '03', '02'),
+       LEAST('01', '1', '02'),
+       LEAST(null, 'b', 'c' ),
+       LEAST('a', null, 'c'),
+       LEAST('a', 'b', null ),
+       LEAST('a', null, null),
+       LEAST(null, 'b', null),
+       LEAST(cast(null as string), null, null)
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+STAGE DEPENDENCIES:
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+      Processor Tree:
+        TableScan
+          alias: src
+          Row Limit Per Split: 1
+          Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE 
Column stats: COMPLETE
+          Select Operator
+            expressions: 'a' (type: string), 'B' (type: string), 'AAA' (type: 
string), 'A' (type: string), '11' (type: string), '11' (type: string), '01' 
(type: string), '01' (type: string), least(null,'b','c') (type: string), 
least('a',null,'c') (type: string), least('a','b',null) (type: string), 
least('a',null,null) (type: string), least(null,'b',null) (type: string), 
least(UDFToString(null),null,null) (type: string)
+            outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, 
_col6, _col7, _col8, _col9, _col10, _col11, _col12, _col13
+            Statistics: Num rows: 500 Data size: 597500 Basic stats: COMPLETE 
Column stats: COMPLETE
+            ListSink
+
+PREHOOK: query: SELECT LEAST('a', 'b', 'c'),
+       LEAST('C', 'a', 'B'),
+       LEAST('AAA', 'AaA', 'AAa'),
+       LEAST('A', 'AA', 'AAA'),
+       LEAST('11', '13', '12'),
+       LEAST('11', '2', '12'),
+       LEAST('01', '03', '02'),
+       LEAST('01', '1', '02'),
+       LEAST(null, 'b', 'c' ),
+       LEAST('a', null, 'c'),
+       LEAST('a', 'b', null ),
+       LEAST('a', null, null),
+       LEAST(null, 'b', null),
+       LEAST(cast(null as string), null, null)
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT LEAST('a', 'b', 'c'),
+       LEAST('C', 'a', 'B'),
+       LEAST('AAA', 'AaA', 'AAa'),
+       LEAST('A', 'AA', 'AAA'),
+       LEAST('11', '13', '12'),
+       LEAST('11', '2', '12'),
+       LEAST('01', '03', '02'),
+       LEAST('01', '1', '02'),
+       LEAST(null, 'b', 'c' ),
+       LEAST('a', null, 'c'),
+       LEAST('a', 'b', null ),
+       LEAST('a', null, null),
+       LEAST(null, 'b', null),
+       LEAST(cast(null as string), null, null)
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+a      B       AAA     A       11      11      01      01      b       a       
a       a       b       NULL
+PREHOOK: query: SELECT LEAST(11, 13, 12),
+       LEAST(1, 13, 2),
+       LEAST(-11, -13, -12),
+       LEAST(1, -13, 2),
+       LEAST(null, 1, 2),
+       LEAST(1, null, 2),
+       LEAST(1, 2, null),
+       LEAST(cast(null as int), null, null)
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT LEAST(11, 13, 12),
+       LEAST(1, 13, 2),
+       LEAST(-11, -13, -12),
+       LEAST(1, -13, 2),
+       LEAST(null, 1, 2),
+       LEAST(1, null, 2),
+       LEAST(1, 2, null),
+       LEAST(cast(null as int), null, null)
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+11     1       -13     -13     1       1       1       NULL
+PREHOOK: query: SELECT LEAST(11.4, 13.5, 12.2),
+       LEAST(1.0, 13.2, 2.0),
+       LEAST(-11.4, -13.1, -12.2),
+       LEAST(1.0, -13.3, 2.2),
+       LEAST(null, 1.1, 2.2),
+       LEAST(1.1, null, 2.2),
+       LEAST(1.1, 2.2, null),
+       LEAST(cast(null as double), null, null)
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT LEAST(11.4, 13.5, 12.2),
+       LEAST(1.0, 13.2, 2.0),
+       LEAST(-11.4, -13.1, -12.2),
+       LEAST(1.0, -13.3, 2.2),
+       LEAST(null, 1.1, 2.2),
+       LEAST(1.1, null, 2.2),
+       LEAST(1.1, 2.2, null),
+       LEAST(cast(null as double), null, null)
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+11.4   1.0     -13.1   -13.3   1.1     1.1     1.1     NULL


Reply via email to