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()));
}
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());
}
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()));
}
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);
}
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);
}
Aggregations