public void testGreatestMixed() throws HiveException { GenericUDFGreatest udf = new GenericUDFGreatest(); ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.writableDateObjectInspector; ObjectInspector valueOI4 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3, valueOI4 }; udf.initialize(arguments); runAndVerify(new Object[] { 1, 11.1, Date.valueOf("2015-03-20"), "test"}, "test", udf); //string comparisons }
public void testLeastTypes() throws HiveException { GenericUDFGreatest udf = new GenericUDFGreatest(); ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.writableDateObjectInspector; ObjectInspector valueOI4 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3, valueOI4 }; udf.initialize(arguments); runAndVerify(new Object[] { 1, 11.1, Date.valueOf("2015-03-20"), "test"}, "test", udf); //string comparisons }
public void testVoids() throws HiveException { GenericUDFGreatest udf = new GenericUDFGreatest(); ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableVoidObjectInspector; ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3 }; udf.initialize(arguments); runAndVerify(new Object[] { null, 1, "test"}, null, udf); }
public void testVoids() throws HiveException { GenericUDFGreatest udf = new GenericUDFGreatest(); ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableVoidObjectInspector; ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3 }; udf.initialize(arguments); runAndVerify(new Object[] { null, 1, "test"}, null, udf); }
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 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 }, null, udf); runAndVerify(new Date[] { d1, null, d3 }, null, udf); runAndVerify(new Date[] { d1, d2, null }, null, udf); runAndVerify(new Date[] { null, null, null }, null, udf); }
public void testGreatestIntTypes() throws HiveException { GenericUDFGreatest udf = new GenericUDFGreatest(); ObjectInspector[] arguments = new ObjectInspector[4]; arguments[0] = PrimitiveObjectInspectorFactory.writableByteObjectInspector; arguments[1] = PrimitiveObjectInspectorFactory.writableShortObjectInspector; arguments[2] = PrimitiveObjectInspectorFactory.writableIntObjectInspector; arguments[3] = PrimitiveObjectInspectorFactory.writableLongObjectInspector; udf.initialize(arguments); runAndVerify(new Object[] { (byte) 11, (short) 13, 12, 14L }, 14L, udf); runAndVerify(new Object[] { (byte) 1, (short) 13, 2, 0L }, 13L, udf); runAndVerify(new Object[] { (byte) -11, (short) -13, -12, 0L }, 0L, udf); runAndVerify(new Object[] { (byte) 1, (short) -13, 2, 0L}, 2L, udf); runAndVerify(new Object[] { null, (short) 1, 2, 0L }, null, udf); runAndVerify(new Object[] { (byte) 1, null, 2, -1L }, null, udf); runAndVerify(new Object[] { (byte) 1, (short) 2, null, -1L }, null, udf); runAndVerify(new Integer[] { null, 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 }, null, udf); runAndVerify(new Integer[] { 1, null, 2 }, null, udf); runAndVerify(new Integer[] { 1, 2, null }, null, 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 }, null, udf); runAndVerify(new Double[] { 1.1, null, 2.2 }, null, udf); runAndVerify(new Double[] { 1.1, 2.2, null }, null, udf); runAndVerify(new Double[] { null, null, null }, null, udf); }
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" }, null, udf); runAndVerify(new String[] { "a", null, "c" }, null, udf); runAndVerify(new String[] { "a", "b", null }, null, udf); runAndVerify(new String[] { "a", null, null }, null, udf); runAndVerify(new String[] { null, "b", null }, null, udf); runAndVerify(new String[] { null, null, null }, null, udf); }