Search in sources :

Example 91 with TimestampWritableV2

use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.

the class TestVectorTimestampExpressions method compareToUDFSecondLong.

private void compareToUDFSecondLong(Timestamp t, int y) throws HiveException {
    UDFSecond udf = new UDFSecond();
    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 : UDFSecond(org.apache.hadoop.hive.ql.udf.UDFSecond) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) IntWritable(org.apache.hadoop.io.IntWritable)

Example 92 with TimestampWritableV2

use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.

the class TestVectorTimestampExpressions method compareToUDFDayOfMonthLong.

private void compareToUDFDayOfMonthLong(Timestamp t, int y) throws HiveException {
    UDFDayOfMonth udf = new UDFDayOfMonth();
    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 : UDFDayOfMonth(org.apache.hadoop.hive.ql.udf.UDFDayOfMonth) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) IntWritable(org.apache.hadoop.io.IntWritable)

Example 93 with TimestampWritableV2

use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.

the class TestVectorTimestampExpressions method compareToUDFHourLong.

private void compareToUDFHourLong(Timestamp t, int y) throws HiveException {
    UDFHour udf = new UDFHour();
    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 : UDFHour(org.apache.hadoop.hive.ql.udf.UDFHour) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) IntWritable(org.apache.hadoop.io.IntWritable)

Example 94 with TimestampWritableV2

use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.

the class TestVectorTimestampExpressions method compareToUDFWeekOfYearLong.

private void compareToUDFWeekOfYearLong(Timestamp t, int y) {
    UDFWeekOfYear udf = new UDFWeekOfYear();
    TimestampWritableV2 tsw = new TimestampWritableV2(org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(t.getTime(), t.getNanos()));
    IntWritable res = udf.evaluate(tsw);
    Assert.assertEquals(res.get(), y);
}
Also used : UDFWeekOfYear(org.apache.hadoop.hive.ql.udf.UDFWeekOfYear) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) IntWritable(org.apache.hadoop.io.IntWritable)

Example 95 with TimestampWritableV2

use of org.apache.hadoop.hive.serde2.io.TimestampWritableV2 in project hive by apache.

the class TestVectorTypeCasts method getBatchTimestampDecimal.

private VectorizedRowBatch getBatchTimestampDecimal(HiveDecimal[] hiveDecimalValues) {
    Random r = new Random(994);
    VectorizedRowBatch b = new VectorizedRowBatch(2);
    TimestampColumnVector tcv;
    b.cols[0] = tcv = new TimestampColumnVector(hiveDecimalValues.length);
    b.cols[1] = new DecimalColumnVector(hiveDecimalValues.length, HiveDecimal.SYSTEM_DEFAULT_PRECISION, HiveDecimal.SYSTEM_DEFAULT_SCALE);
    for (int i = 0; i < hiveDecimalValues.length; i++) {
        int optionalNanos = 0;
        switch(r.nextInt(4)) {
            case 0:
                // No nanos.
                break;
            case 1:
                optionalNanos = r.nextInt((int) NANOSECONDS_PER_SECOND);
                break;
            case 2:
                // Limit to milliseconds only...
                optionalNanos = r.nextInt((int) MILLISECONDS_PER_SECOND) * (int) NANOSECONDS_PER_MILLISSECOND;
                break;
            case 3:
                // Limit to below milliseconds only...
                optionalNanos = r.nextInt((int) NANOSECONDS_PER_MILLISSECOND);
                break;
        }
        long millis = RandomTypeUtil.randomMillis(r);
        Timestamp ts = new Timestamp(millis);
        ts.setNanos(optionalNanos);
        TimestampWritableV2 tsw = new TimestampWritableV2(org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(ts.getTime(), ts.getNanos()));
        hiveDecimalValues[i] = tsw.getHiveDecimal();
        tcv.set(i, ts);
    }
    b.size = hiveDecimalValues.length;
    return b;
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) Random(java.util.Random) Timestamp(java.sql.Timestamp) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2)

Aggregations

TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)99 IntWritable (org.apache.hadoop.io.IntWritable)45 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)32 Text (org.apache.hadoop.io.Text)32 LongWritable (org.apache.hadoop.io.LongWritable)31 DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)30 BooleanWritable (org.apache.hadoop.io.BooleanWritable)27 FloatWritable (org.apache.hadoop.io.FloatWritable)27 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)25 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)22 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)21 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)21 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)21 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)20 HiveIntervalDayTimeWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable)19 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)18 ArrayList (java.util.ArrayList)16