Search in sources :

Example 56 with DeferredJavaObject

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.

the class TestGenericUDFSubstringIndex method runAndVerify.

private void runAndVerify(String str, String delim, Integer count, String expResult, GenericUDF udf) throws HiveException {
    DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new Text(str) : null);
    DeferredObject valueObj1 = new DeferredJavaObject(delim != null ? new Text(delim) : delim);
    DeferredObject valueObj2 = new DeferredJavaObject(count != null ? new IntWritable(count) : null);
    DeferredObject[] args = { valueObj0, valueObj1, valueObj2 };
    Text output = (Text) udf.evaluate(args);
    assertEquals("substring_index() test ", expResult, output != null ? output.toString() : null);
}
Also used : DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) Text(org.apache.hadoop.io.Text) IntWritable(org.apache.hadoop.io.IntWritable)

Example 57 with DeferredJavaObject

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.

the class TestGenericUDFInternalInterval method testDayInterval.

@Test
public void testDayInterval() throws Exception {
    try (GenericUDFInternalInterval udf = new GenericUDFInternalInterval()) {
        ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(HiveParser.TOK_INTERVAL_DAY_LITERAL)), PrimitiveObjectInspectorFactory.writableStringObjectInspector };
        DeferredObject[] args = { new DeferredJavaObject(new ByteWritable((byte) 4)), new DeferredJavaObject(new Text("8")) };
        PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
        Assert.assertEquals(TypeInfoFactory.intervalDayTimeTypeInfo, oi.getTypeInfo());
        HiveIntervalDayTimeWritable res = (HiveIntervalDayTimeWritable) udf.evaluate(args);
        Assert.assertEquals(8, res.getHiveIntervalDayTime().getDays());
    }
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) Text(org.apache.hadoop.io.Text) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) HiveIntervalDayTimeWritable(org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 58 with DeferredJavaObject

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.

the class TestGenericUDFLastDay method runAndVerify.

private void runAndVerify(String str, String expResult, GenericUDF udf) throws HiveException {
    DeferredObject valueObj0 = new DeferredJavaObject(str != null ? new Text(str) : null);
    DeferredObject[] args = { valueObj0 };
    Text output = (Text) udf.evaluate(args);
    assertEquals("last_day() test ", expResult, output != null ? output.toString() : null);
}
Also used : DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) Text(org.apache.hadoop.io.Text)

Example 59 with DeferredJavaObject

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.

the class TestGenericUDFLeast method runAndVerify.

private void runAndVerify(Object[] v, Object expResult, GenericUDF udf) throws HiveException {
    DeferredObject[] args = new DeferredObject[v.length];
    for (int i = 0; i < v.length; i++) {
        args[i] = new DeferredJavaObject(getWritable(v[i]));
    }
    Object output = udf.evaluate(args);
    output = parseOutput(output);
    assertEquals("greatest() test ", expResult, output != null ? output : null);
}
Also used : DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)

Example 60 with DeferredJavaObject

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject in project hive by apache.

the class TestGenericUDFNextDay method runAndVerify.

private void runAndVerify(String date, String dayOfWeek, String expResult, GenericUDF udf) throws HiveException {
    DeferredObject valueObj0 = new DeferredJavaObject(date != null ? new Text(date) : null);
    DeferredObject valueObj1 = new DeferredJavaObject(dayOfWeek != null ? new Text(dayOfWeek) : null);
    DeferredObject[] args = { valueObj0, valueObj1 };
    Text output = (Text) udf.evaluate(args);
    assertEquals("next_day() test ", expResult, output != null ? output.toString() : null);
}
Also used : DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) Text(org.apache.hadoop.io.Text)

Aggregations

DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)203 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)200 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)158 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)129 Test (org.junit.Test)123 Text (org.apache.hadoop.io.Text)53 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)39 LongWritable (org.apache.hadoop.io.LongWritable)34 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)29 IntWritable (org.apache.hadoop.io.IntWritable)28 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)26 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)21 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)20 FloatWritable (org.apache.hadoop.io.FloatWritable)14 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)13 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)12 HiveIntervalDayTimeWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable)10 Date (java.sql.Date)8 HiveIntervalYearMonthWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable)8 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)7