use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestArrowColumnarBatchSerDe method testPositiveNegativeTSWithNanosSelected.
@Test
public void testPositiveNegativeTSWithNanosSelected() throws SerDeException {
String[][] schema = { { "timestamp1", "timestamp" } };
Object[][] tsRows = new Object[][] { { new TimestampWritableV2(Timestamp.valueOf("1963-04-01 09:01:10.123")) }, { new TimestampWritableV2(Timestamp.valueOf("1800-04-01 09:01:10.123999")) }, { new TimestampWritableV2(Timestamp.valueOf("1750-04-01 09:01:10.123999")) }, { new TimestampWritableV2(Timestamp.valueOf("1700-04-01 09:01:10.999999")) }, { new TimestampWritableV2(Timestamp.valueOf("2050-04-01 09:01:10.999999")) }, { new TimestampWritableV2(Timestamp.valueOf("1991-06-05 09:01:10.999999")) }, { new TimestampWritableV2(Timestamp.valueOf("1992-11-04 09:01:10.999999")) }, { new TimestampWritableV2(Timestamp.valueOf("1970-01-01 00:00:00")) }, { new TimestampWritableV2(Timestamp.valueOf("1964-01-01 00:00:04.78")) }, { new TimestampWritableV2(Timestamp.valueOf("1950-01-01 09:23:03.21")) }, { new TimestampWritableV2(Timestamp.valueOf("1956-01-01 10:09:03.00")) }, { new TimestampWritableV2(Timestamp.valueOf("1947-08-27 10:25:36.26")) } };
int[] selectedRows = new int[] { 0, 2, 5, 7, 9, 11 };
initAndSerializeAndDeserializeSelected(schema, tsRows, selectedRows);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestArrowColumnarBatchSerDe method testPrimitiveRandomTimestamp.
@Test
public void testPrimitiveRandomTimestamp() throws SerDeException {
String[][] schema = { { "timestamp1", "timestamp" } };
int size = HiveConf.getIntVar(conf, HiveConf.ConfVars.HIVE_ARROW_BATCH_SIZE);
Random rand = new Random(294722773L);
Object[][] rows = new Object[size][];
for (int i = 0; i < size; i++) {
long millis = ((long) rand.nextInt(Integer.MAX_VALUE)) * 1000;
Timestamp timestamp = Timestamp.ofEpochMilli(rand.nextBoolean() ? millis : -millis);
timestamp.setNanos(rand.nextInt(1000) * 1000);
rows[i] = new Object[] { new TimestampWritableV2(timestamp) };
}
initAndSerializeAndDeserialize(schema, rows);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestArrowColumnarBatchSerDe method testTimestampNanosPrecisionUpTo6Digits.
@Test
public void testTimestampNanosPrecisionUpTo6Digits() throws SerDeException {
String[][] schema = { { "timestamp1", "timestamp" } };
// Nanos precise upto 6 digits
Object[][] tsRows = new Object[][] { { new TimestampWritableV2(Timestamp.valueOf("1800-04-01 09:01:10.123999")) }, { new TimestampWritableV2(Timestamp.valueOf("2050-04-01 09:01:10.999999")) }, null };
initAndSerializeAndDeserialize(schema, tsRows);
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestVectorUDFDatetimeLegacyHybridCalendar method compareToUDFDatetimeLegacyHybridCalendar.
private void compareToUDFDatetimeLegacyHybridCalendar(GenericUDF udf, java.sql.Timestamp in, java.sql.Timestamp out) throws HiveException {
TimestampWritableV2 tswInput = new TimestampWritableV2(org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(in.getTime(), in.getNanos()));
TimestampWritableV2 tswOutput = (TimestampWritableV2) udf.evaluate(new GenericUDF.DeferredObject[] { new GenericUDF.DeferredJavaObject(tswInput) });
Assert.assertEquals(tswOutput.getTimestamp(), Timestamp.ofEpochMilli(out.getTime()));
Assert.assertEquals(tswOutput.getNanos(), out.getNanos());
}
use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.
the class TestVectorTimestampExpressions method compareToUDFYearLong.
private void compareToUDFYearLong(Timestamp t, int y) throws HiveException {
UDFYear udf = new UDFYear();
udf.initialize(new ObjectInspector[] { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector });
TimestampWritableV2 tsw = new TimestampWritableV2(org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(t.getTime(), t.getNanos()));
IntWritable res = (IntWritable) udf.evaluate(new GenericUDF.DeferredObject[] { new GenericUDF.DeferredJavaObject(tsw) });
Assert.assertEquals(res.get(), y);
}
Aggregations