use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector in project hive by apache.
the class TestGenericUDFOPPlus method testIntervalYearMonthPlusTimestamp.
@Test
public void testIntervalYearMonthPlusTimestamp() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
HiveIntervalYearMonthWritable left = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2"));
TimestampWritableV2 right = new TimestampWritableV2(Timestamp.valueOf("2001-11-15 01:02:03.123456789"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector, PrimitiveObjectInspectorFactory.writableTimestampObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2004-01-15 01:02:03.123456789"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector in project hive by apache.
the class TestGenericUDFOPPlus method testIntervalDayTimePlusTimestamp.
@Test
public void testIntervalDayTimePlusTimestamp() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
HiveIntervalDayTimeWritable left = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 2:3:4.567"));
TimestampWritableV2 right = new TimestampWritableV2(Timestamp.valueOf("2001-01-01 00:00:00"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector, PrimitiveObjectInspectorFactory.writableTimestampObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritableV2 res = (TimestampWritableV2) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2001-01-02 2:3:4.567"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector in project hive by apache.
the class TestGenericUDFDate method testTimestampToDate.
@Test
public void testTimestampToDate() throws HiveException {
GenericUDFDate udf = new GenericUDFDate();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 30, 4, 17, 52, 0).toString())));
DeferredObject[] args = { valueObj };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("to_date() test for TIMESTAMP failed ", "0109-06-30", output.toString());
// Try with null args
DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
output = (DateWritableV2) udf.evaluate(nullArgs);
assertNull("to_date() with null TIMESTAMP", output);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector in project hive by apache.
the class TestGenericUDFDateDiff method testTimestampToDate.
@Test
public void testTimestampToDate() throws HiveException {
GenericUDFDateDiff udf = new GenericUDFDateDiff();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 20, 0, 0, 0, 0).toString())));
DeferredObject valueObj2 = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 17, 0, 0, 0, 0).toString())));
DeferredObject[] args = { valueObj1, valueObj2 };
IntWritable output = (IntWritable) udf.evaluate(args);
assertEquals("datediff() test for TIMESTAMP failed ", "3", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector in project hive by apache.
the class TestKuduSerDe method testSerDeRoundTrip.
@Test
public void testSerDeRoundTrip() throws Exception {
KuduSerDe serDe = new KuduSerDe();
serDe.initialize(BASE_CONF, TBL_PROPS, null);
PartialRow before = SCHEMA.newPartialRow();
before.addByte("key", (byte) 1);
before.addShort("int16", (short) 1);
before.addInt("int32", 1);
before.addLong("int64", 1L);
before.addBoolean("bool", true);
before.addFloat("float", 1.1f);
before.addDouble("double", 1.1d);
before.addString("string", "one");
before.addBinary("binary", "one".getBytes(UTF_8));
before.addTimestamp("timestamp", new Timestamp(NOW_MS));
before.addDecimal("decimal", new BigDecimal("1.111"));
before.setNull("null");
before.addInt("default", 1);
KuduWritable beforeWritable = new KuduWritable(before);
Object object = serDe.deserialize(beforeWritable);
// Capitalized `key` field to check for field case insensitivity.
List<String> fieldNames = Arrays.asList("KEY", "int16", "int32", "int64", "bool", "float", "double", "string", "binary", "timestamp", "decimal", "null", "default");
List<ObjectInspector> ois = Arrays.asList(PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector, PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.writableBooleanObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableBinaryObjectInspector, PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector);
StandardStructObjectInspector objectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, ois);
KuduWritable afterWritable = serDe.serialize(object, objectInspector);
PartialRow after = afterWritable.getPartialRow();
for (int i = 0; i < SCHEMA.getColumnCount(); i++) {
if (SCHEMA.getColumnByIndex(i).getType() == Type.BINARY) {
assertArrayEquals("Columns not equal at index: " + i, before.getBinaryCopy(i), after.getBinaryCopy(i));
} else {
assertEquals("Columns not equal at index: " + i, before.getObject(i), after.getObject(i));
}
}
}
Aggregations