Search in sources :

Example 61 with DeferredObject

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject 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)

Example 62 with DeferredObject

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

the class TestGenericUDFNullif method testNotSupportedArgumentMix.

@Test(expected = UDFArgumentException.class)
public void testNotSupportedArgumentMix() throws HiveException {
    GenericUDFNullif udf = new GenericUDFNullif();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(new DateWritable(4)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
    udf.initialize(inputOIs);
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Test(org.junit.Test)

Example 63 with DeferredObject

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

the class TestGenericUDFNullif method testByteTypeEq.

@Test
public void testByteTypeEq() throws HiveException {
    GenericUDFNullif udf = new GenericUDFNullif();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(new ByteWritable((byte) 4)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.byteTypeInfo, oi.getTypeInfo());
    ByteWritable res = (ByteWritable) udf.evaluate(args);
    Assert.assertEquals(null, res);
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) 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) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Test(org.junit.Test)

Example 64 with DeferredObject

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

the class TestGenericUDFNullif method testConversionInSameGroup.

@Test
public void testConversionInSameGroup() throws HiveException {
    GenericUDFNullif udf = new GenericUDFNullif();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(new DoubleWritable(4.0)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) 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) DoubleWritable(org.apache.hadoop.io.DoubleWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Test(org.junit.Test)

Example 65 with DeferredObject

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

the class TestGenericUDFNullif method testDateCompareEq.

@Test
public void testDateCompareEq() throws HiveException {
    GenericUDFNullif udf = new GenericUDFNullif();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(new DateWritable(4)), new DeferredJavaObject(new DateWritable(4)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
    Assert.assertEquals(null, udf.evaluate(args));
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Aggregations

DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)204 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)201 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)158 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)128 Test (org.junit.Test)123 Text (org.apache.hadoop.io.Text)54 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)27 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