Search in sources :

Example 51 with TimestampWritable

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

the class GenericUDFReflect2 method evaluate.

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    Object targetObject = targetOI.getPrimitiveJavaObject(arguments[0].get());
    if (targetObject == null) {
        return null;
    }
    Object result = null;
    try {
        result = method.invoke(targetObject, setupParameters(arguments, 2));
    } catch (InvocationTargetException e) {
        throw new HiveException(e.getCause());
    } catch (Exception e) {
        throw new HiveException(e);
    }
    if (result == null) {
        return null;
    }
    switch(returnOI.getPrimitiveCategory()) {
        case VOID:
            return null;
        case BOOLEAN:
            ((BooleanWritable) returnObj).set((Boolean) result);
            return returnObj;
        case BYTE:
            ((ByteWritable) returnObj).set((Byte) result);
            return returnObj;
        case SHORT:
            ((ShortWritable) returnObj).set((Short) result);
            return returnObj;
        case INT:
            ((IntWritable) returnObj).set((Integer) result);
            return returnObj;
        case LONG:
            ((LongWritable) returnObj).set((Long) result);
            return returnObj;
        case FLOAT:
            ((FloatWritable) returnObj).set((Float) result);
            return returnObj;
        case DOUBLE:
            ((DoubleWritable) returnObj).set((Double) result);
            return returnObj;
        case STRING:
            ((Text) returnObj).set((String) result);
            return returnObj;
        case TIMESTAMP:
            ((TimestampWritable) returnObj).set((Timestamp) result);
            return returnObj;
        case BINARY:
            ((BytesWritable) returnObj).set((byte[]) result, 0, ((byte[]) result).length);
            return returnObj;
        case DECIMAL:
            ((HiveDecimalWritable) returnObj).set((HiveDecimal) result);
            return returnObj;
    }
    throw new HiveException("Invalid type " + returnOI.getPrimitiveCategory());
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Text(org.apache.hadoop.io.Text) BytesWritable(org.apache.hadoop.io.BytesWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) InvocationTargetException(java.lang.reflect.InvocationTargetException) UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) FloatWritable(org.apache.hadoop.io.FloatWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) LongWritable(org.apache.hadoop.io.LongWritable) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Example 52 with TimestampWritable

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

the class TestVectorTimestampExpressions method compareToUDFDayOfMonthLong.

private void compareToUDFDayOfMonthLong(Timestamp t, int y) {
    UDFDayOfMonth udf = new UDFDayOfMonth();
    TimestampWritable tsw = new TimestampWritable(t);
    IntWritable res = udf.evaluate(tsw);
    Assert.assertEquals(res.get(), y);
}
Also used : UDFDayOfMonth(org.apache.hadoop.hive.ql.udf.UDFDayOfMonth) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Example 53 with TimestampWritable

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

the class TestVectorTimestampExpressions method compareToUDFHourLong.

private void compareToUDFHourLong(Timestamp t, int y) {
    UDFHour udf = new UDFHour();
    TimestampWritable tsw = new TimestampWritable(t);
    IntWritable res = udf.evaluate(tsw);
    Assert.assertEquals(res.get(), y);
}
Also used : UDFHour(org.apache.hadoop.hive.ql.udf.UDFHour) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Example 54 with TimestampWritable

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

the class TestVectorTimestampExpressions method compareToUDFSecondLong.

private void compareToUDFSecondLong(Timestamp t, int y) {
    UDFSecond udf = new UDFSecond();
    TimestampWritable tsw = new TimestampWritable(t);
    IntWritable res = udf.evaluate(tsw);
    Assert.assertEquals(res.get(), y);
}
Also used : UDFSecond(org.apache.hadoop.hive.ql.udf.UDFSecond) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Example 55 with TimestampWritable

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

the class TestVectorTimestampExpressions method compareToUDFWeekOfYearLong.

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

Aggregations

TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)87 IntWritable (org.apache.hadoop.io.IntWritable)41 Text (org.apache.hadoop.io.Text)34 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)33 Timestamp (java.sql.Timestamp)30 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)29 LongWritable (org.apache.hadoop.io.LongWritable)28 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)25 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)25 BooleanWritable (org.apache.hadoop.io.BooleanWritable)25 FloatWritable (org.apache.hadoop.io.FloatWritable)25 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)24 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)24 HiveIntervalDayTimeWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable)23 BytesWritable (org.apache.hadoop.io.BytesWritable)23 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)20 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)20 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)20 HiveIntervalYearMonthWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable)19 Test (org.junit.Test)19