Search in sources :

Example 6 with DeferredJavaObject

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

the class TestGenericUDFAddMonths method runAndVerify.

private void runAndVerify(String str, byte months, String expResult, GenericUDF udf) throws HiveException {
    DeferredObject valueObj0 = new DeferredJavaObject(new Text(str));
    DeferredObject valueObj1 = new DeferredJavaObject(new ByteWritable(months));
    DeferredObject[] args = { valueObj0, valueObj1 };
    Text output = (Text) udf.evaluate(args);
    assertEquals("add_months() 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) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable)

Example 7 with DeferredJavaObject

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

the class TestGenericUDFOPPlus method testTimestampPlusIntervalYearMonth.

@Test
public void testTimestampPlusIntervalYearMonth() throws Exception {
    GenericUDFOPPlus udf = new GenericUDFOPPlus();
    TimestampWritable left = new TimestampWritable(Timestamp.valueOf("2001-11-15 01:02:03.123456789"));
    HiveIntervalYearMonthWritable right = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2"));
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
    TimestampWritable res = (TimestampWritable) udf.evaluate(args);
    Assert.assertEquals(Timestamp.valueOf("2004-01-15 01:02:03.123456789"), res.getTimestamp());
}
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) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) HiveIntervalYearMonthWritable(org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable) Test(org.junit.Test)

Example 8 with DeferredJavaObject

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

the class TestGenericUDFOPPlus method testTimestampPlusIntervalDayTime.

@Test
public void testTimestampPlusIntervalDayTime() throws Exception {
    GenericUDFOPPlus udf = new GenericUDFOPPlus();
    TimestampWritable left = new TimestampWritable(Timestamp.valueOf("2001-01-01 00:00:00"));
    HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
    TimestampWritable res = (TimestampWritable) udf.evaluate(args);
    Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
}
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) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) HiveIntervalDayTimeWritable(org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 9 with DeferredJavaObject

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

the class TestGenericUDFOPPositive method testShort.

@Test
public void testShort() throws HiveException {
    GenericUDFOPPositive udf = new GenericUDFOPPositive();
    ShortWritable input = new ShortWritable((short) 74);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(input) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.shortTypeInfo, oi.getTypeInfo());
    ShortWritable res = (ShortWritable) udf.evaluate(args);
    Assert.assertEquals((short) 74, res.get());
}
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) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) Test(org.junit.Test)

Example 10 with DeferredJavaObject

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

the class TestGenericUDFOPPositive method testDecimal.

@Test
public void testDecimal() throws HiveException {
    GenericUDFOPPositive udf = new GenericUDFOPPositive();
    HiveDecimalWritable input = new HiveDecimalWritable(HiveDecimal.create("32300.004747"));
    DecimalTypeInfo inputTypeInfo = TypeInfoFactory.getDecimalTypeInfo(11, 6);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo) };
    DeferredObject[] args = { new DeferredJavaObject(input) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(inputTypeInfo, oi.getTypeInfo());
    HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
    Assert.assertEquals(HiveDecimal.create("32300.004747"), res.getHiveDecimal());
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) 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) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

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