Search in sources :

Example 11 with TimestampWritableV2

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);
}
Also used : TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) Test(org.junit.Test)

Example 12 with TimestampWritableV2

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);
}
Also used : Random(java.util.Random) Timestamp(org.apache.hadoop.hive.common.type.Timestamp) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) Test(org.junit.Test)

Example 13 with TimestampWritableV2

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);
}
Also used : TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) Test(org.junit.Test)

Example 14 with TimestampWritableV2

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());
}
Also used : TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2)

Example 15 with TimestampWritableV2

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);
}
Also used : UDFYear(org.apache.hadoop.hive.ql.udf.UDFYear) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) IntWritable(org.apache.hadoop.io.IntWritable)

Aggregations

TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)99 IntWritable (org.apache.hadoop.io.IntWritable)44 Test (org.junit.Test)42 Timestamp (org.apache.hadoop.hive.common.type.Timestamp)36 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)36 BytesWritable (org.apache.hadoop.io.BytesWritable)31 Text (org.apache.hadoop.io.Text)31 DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)30 LongWritable (org.apache.hadoop.io.LongWritable)30 BooleanWritable (org.apache.hadoop.io.BooleanWritable)26 FloatWritable (org.apache.hadoop.io.FloatWritable)26 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)25 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)21 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)21 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)21 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)20 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)20 HiveIntervalDayTimeWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable)19 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)18 ArrayList (java.util.ArrayList)16