Search in sources :

Example 86 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFOPPlus method testDoulePlusDecimal.

@Test
public void testDoulePlusDecimal() throws HiveException {
    GenericUDFOPPlus udf = new GenericUDFOPPlus();
    // Double
    DoubleWritable left = new DoubleWritable(74.52);
    HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("234.97"));
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2)) };
    DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo());
    DoubleWritable res = (DoubleWritable) udf.evaluate(args);
    Assert.assertEquals(new Double(309.49), new Double(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) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 87 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFOPPlus method testIntervalYearMonthPlusDate.

@Test
public void testIntervalYearMonthPlusDate() throws Exception {
    GenericUDFOPPlus udf = new GenericUDFOPPlus();
    HiveIntervalYearMonthWritable left = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-8"));
    DateWritable right = new DateWritable(Date.valueOf("2001-06-15"));
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
    DateWritable res = (DateWritable) udf.evaluate(args);
    Assert.assertEquals(Date.valueOf("2004-02-15"), 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) 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) HiveIntervalYearMonthWritable(org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable) Test(org.junit.Test)

Example 88 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFOPPlus method testFloatPlusFloat.

@Test
public void testFloatPlusFloat() throws HiveException {
    GenericUDFOPPlus udf = new GenericUDFOPPlus();
    // Float
    FloatWritable f1 = new FloatWritable(4.5f);
    FloatWritable f2 = new FloatWritable(0.0f);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(f1), new DeferredJavaObject(f2) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.floatTypeInfo);
    FloatWritable res = (FloatWritable) udf.evaluate(args);
    Assert.assertEquals(new Float(4.5), new Float(res.get()));
}
Also used : FloatWritable(org.apache.hadoop.io.FloatWritable) 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) Test(org.junit.Test)

Example 89 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFQuarter method testQuarterStr.

public void testQuarterStr() throws HiveException {
    GenericUDFQuarter udf = new GenericUDFQuarter();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI0 };
    udf.initialize(arguments);
    // date str
    runAndVerifyStr("2014-01-10", 1, udf);
    runAndVerifyStr("2014-02-10", 1, udf);
    runAndVerifyStr("2014-03-31", 1, udf);
    runAndVerifyStr("2014-04-02", 2, udf);
    runAndVerifyStr("2014-05-28", 2, udf);
    runAndVerifyStr("2016-06-03", 2, udf);
    runAndVerifyStr("2016-07-28", 3, udf);
    runAndVerifyStr("2016-08-29", 3, udf);
    runAndVerifyStr("2016-09-29", 3, udf);
    runAndVerifyStr("2016-10-29", 4, udf);
    runAndVerifyStr("2016-11-29", 4, udf);
    runAndVerifyStr("2016-12-29", 4, udf);
    // wrong date str
    runAndVerifyStr("2016-03-35", 2, udf);
    runAndVerifyStr("2014-01-32", 1, udf);
    runAndVerifyStr("01/14/2014", null, udf);
    runAndVerifyStr(null, null, udf);
    // negative Unix time
    runAndVerifyStr("1966-01-01", 1, udf);
    runAndVerifyStr("1966-03-31", 1, udf);
    runAndVerifyStr("1966-04-01", 2, udf);
    runAndVerifyStr("1966-12-31", 4, udf);
    // ts str
    runAndVerifyStr("2014-01-01 00:00:00", 1, udf);
    runAndVerifyStr("2014-02-10 15:23:00", 1, udf);
    runAndVerifyStr("2014-03-31 15:23:00", 1, udf);
    runAndVerifyStr("2014-04-02 15:23:00", 2, udf);
    runAndVerifyStr("2014-05-28 15:23:00", 2, udf);
    runAndVerifyStr("2016-06-03 15:23:00", 2, udf);
    runAndVerifyStr("2016-07-28 15:23:00", 3, udf);
    runAndVerifyStr("2016-08-29 15:23:00", 3, udf);
    runAndVerifyStr("2016-09-29 15:23:00", 3, udf);
    runAndVerifyStr("2016-10-29 15:23:00", 4, udf);
    runAndVerifyStr("2016-11-29 15:23:00", 4, udf);
    runAndVerifyStr("2016-12-31 23:59:59.999", 4, udf);
    // wrong date str
    runAndVerifyStr("2016-03-35 15:23:00", 2, udf);
    runAndVerifyStr("2014-01-32 15:23:00", 1, udf);
    runAndVerifyStr("01/14/2014 15:23:00", null, udf);
    runAndVerifyStr(null, null, udf);
    // negative Unix time
    runAndVerifyStr("1966-01-01 00:00:00", 1, udf);
    runAndVerifyStr("1966-03-31 23:59:59.999", 1, udf);
    runAndVerifyStr("1966-04-01 00:00:00", 2, udf);
    runAndVerifyStr("1966-12-31 23:59:59.999", 4, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 90 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFQuarter method testQuarterTs.

public void testQuarterTs() throws HiveException {
    GenericUDFQuarter udf = new GenericUDFQuarter();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
    ObjectInspector[] arguments = { valueOI0 };
    udf.initialize(arguments);
    // positive Unix time
    runAndVerifyTs("2014-01-01 00:00:00", 1, udf);
    runAndVerifyTs("2014-02-10 15:23:00", 1, udf);
    runAndVerifyTs("2014-03-31 15:23:00", 1, udf);
    runAndVerifyTs("2014-04-02 15:23:00", 2, udf);
    runAndVerifyTs("2014-05-28 15:23:00", 2, udf);
    runAndVerifyTs("2016-06-03 15:23:00", 2, udf);
    runAndVerifyTs("2016-07-28 15:23:00", 3, udf);
    runAndVerifyTs("2016-08-29 15:23:00", 3, udf);
    runAndVerifyTs("2016-09-29 15:23:00", 3, udf);
    runAndVerifyTs("2016-10-29 15:23:00", 4, udf);
    runAndVerifyTs("2016-11-29 15:23:00", 4, udf);
    runAndVerifyTs("2016-12-31 23:59:59.999", 4, udf);
    // negative Unix time
    runAndVerifyTs("1966-01-01 00:00:00", 1, udf);
    runAndVerifyTs("1966-03-31 23:59:59", 1, udf);
    runAndVerifyTs("1966-04-01 00:00:00", 2, udf);
    runAndVerifyTs("1966-12-31 23:59:59.999", 4, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)700 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)299 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)261 Test (org.junit.Test)241 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)163 ArrayList (java.util.ArrayList)159 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)159 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)107 Text (org.apache.hadoop.io.Text)103 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)89 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)75 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)73 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)66 IntWritable (org.apache.hadoop.io.IntWritable)65 LongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector)58 LongWritable (org.apache.hadoop.io.LongWritable)54 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)53 IntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector)53 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)51 BytesWritable (org.apache.hadoop.io.BytesWritable)51