use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class TestParquetTimestampsHive2Compatibility method testWriteHive2ReadHive4UsingLegacyConversion.
/**
* Tests that timestamps written using Hive2 APIs are read correctly by Hive4 APIs when legacy conversion is on.
*/
@ParameterizedTest(name = "{0}")
@MethodSource("generateTimestamps")
void testWriteHive2ReadHive4UsingLegacyConversion(String timestampString) {
NanoTime nt = writeHive2(timestampString);
Timestamp ts = readHive4(nt, TimeZone.getDefault().getID(), true);
assertEquals(timestampString, ts.toString());
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class TestParquetTimestampsHive2Compatibility method testWriteHive4ReadHive4UsingNewConversion.
/**
* Tests that timestamps written using Hive4 APIs are read correctly by Hive4 APIs when legacy conversion is off.
*/
@ParameterizedTest(name = "{0}")
@MethodSource("generateTimestamps")
void testWriteHive4ReadHive4UsingNewConversion(String timestampString) {
String zoneId = "US/Pacific";
NanoTime nt = writeHive4(timestampString, zoneId, false);
Timestamp ts = readHive4(nt, zoneId, false);
assertEquals(timestampString, ts.toString());
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class TestETypeConverter method testGetSmallBigIntConverter.
@Test
public void testGetSmallBigIntConverter() {
Timestamp timestamp = Timestamp.valueOf("1998-10-03 09:58:31.231");
long msTime = timestamp.toEpochMilli();
ByteBuffer buf = ByteBuffer.allocate(12);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.putLong(msTime);
buf.flip();
// Need TimeStamp logicalType annotation here
PrimitiveType primitiveType = createInt64TimestampType(false, TimeUnit.MILLIS);
Writable writable = getWritableFromBinaryConverter(createHiveTypeInfo("bigint"), primitiveType, Binary.fromByteBuffer(buf));
// Retrieve as BigInt
LongWritable longWritable = (LongWritable) writable;
assertEquals(msTime, longWritable.get());
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class TestETypeConverter method testGetInt64MillisTimestampConverter.
@Test
public void testGetInt64MillisTimestampConverter() throws Exception {
Timestamp timestamp = Timestamp.valueOf("2018-07-15 15:12:20.112");
PrimitiveType primitiveType = createInt64TimestampType(false, TimeUnit.MILLIS);
Writable writable = getWritableFromPrimitiveConverter(null, primitiveType, timestamp.toEpochMilli());
TimestampWritableV2 timestampWritable = (TimestampWritableV2) writable;
assertEquals(timestamp.toEpochMilli(), timestampWritable.getTimestamp().toEpochMilli());
}
use of org.apache.hadoop.hive.common.type.Timestamp in project hive by apache.
the class TestETypeConverter method testGetInt64NanosTimestampConverter.
@Test
public void testGetInt64NanosTimestampConverter() throws Exception {
Timestamp timestamp = Timestamp.valueOf("2018-07-15 15:12:20.11223344");
PrimitiveType primitiveType = createInt64TimestampType(false, TimeUnit.NANOS);
long time = timestamp.toEpochSecond() * 1000000000 + timestamp.getNanos();
Writable writable = getWritableFromPrimitiveConverter(null, primitiveType, time);
TimestampWritableV2 timestampWritable = (TimestampWritableV2) writable;
assertEquals(timestamp.toEpochMilli(), timestampWritable.getTimestamp().toEpochMilli());
assertEquals(timestamp.getNanos(), timestampWritable.getNanos());
}
Aggregations