Search in sources :

Example 6 with DateWritable

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

the class BatchToRowReader method nextDate.

public static DateWritable nextDate(ColumnVector vector, int row, Object previous) {
    if (vector.isRepeating) {
        row = 0;
    }
    if (vector.noNulls || !vector.isNull[row]) {
        DateWritable result;
        if (previous == null || previous.getClass() != DateWritable.class) {
            result = new DateWritable();
        } else {
            result = (DateWritable) previous;
        }
        int date = (int) ((LongColumnVector) vector).vector[row];
        result.set(date);
        return result;
    } else {
        return null;
    }
}
Also used : DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Example 7 with DateWritable

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

the class ColumnStatsTask method unpackDateStats.

private void unpackDateStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) {
    if (fName.equals("countnulls")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getDateStats().setNumNulls(v);
    } else if (fName.equals("numdistinctvalues")) {
        long v = ((LongObjectInspector) oi).get(o);
        statsObj.getStatsData().getDateStats().setNumDVs(v);
    } else if (fName.equals("max")) {
        DateWritable v = ((DateObjectInspector) oi).getPrimitiveWritableObject(o);
        statsObj.getStatsData().getDateStats().setHighValue(new Date(v.getDays()));
    } else if (fName.equals("min")) {
        DateWritable v = ((DateObjectInspector) oi).getPrimitiveWritableObject(o);
        statsObj.getStatsData().getDateStats().setLowValue(new Date(v.getDays()));
    } else if (fName.equals("ndvbitvector")) {
        PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
        String v = ((StringObjectInspector) poi).getPrimitiveJavaObject(o);
        statsObj.getStatsData().getDateStats().setBitVectors(v);
        ;
    }
}
Also used : LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) DateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) Date(org.apache.hadoop.hive.metastore.api.Date)

Example 8 with DateWritable

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

the class TestGenericUDFNullif method testNotSupportedArgumentMix.

@Test(expected = UDFArgumentException.class)
public void testNotSupportedArgumentMix() throws HiveException {
    GenericUDFNullif udf = new GenericUDFNullif();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(new DateWritable(4)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
    udf.initialize(inputOIs);
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Test(org.junit.Test)

Example 9 with DateWritable

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

the class TestGenericUDFNullif method testDateCompareEq.

@Test
public void testDateCompareEq() throws HiveException {
    GenericUDFNullif udf = new GenericUDFNullif();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(new DateWritable(4)), new DeferredJavaObject(new DateWritable(4)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
    Assert.assertEquals(null, udf.evaluate(args));
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 10 with DateWritable

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

the class TestGenericUDFDateAdd method testDateWritablepToDate.

public void testDateWritablepToDate() throws HiveException {
    GenericUDFDateAdd udf = new GenericUDFDateAdd();
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
    ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    ObjectInspector[] arguments = { valueOI1, valueOI2 };
    udf.initialize(arguments);
    DeferredObject valueObj1 = new DeferredJavaObject(new DateWritable(new Date(109, 06, 20)));
    DeferredObject valueObj2 = new DeferredJavaObject(new Integer("4"));
    DeferredObject[] args = { valueObj1, valueObj2 };
    DateWritable output = (DateWritable) udf.evaluate(args);
    assertEquals("date_add() test for DATEWRITABLE failed ", "2009-07-24", output.toString());
    // Test with null args
    args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
    assertNull("date_add() 1st arg null", udf.evaluate(args));
    args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
    assertNull("date_add() 2nd arg null", udf.evaluate(args));
    args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
    assertNull("date_add() both args null", udf.evaluate(args));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) GenericUDFDateAdd(org.apache.hadoop.hive.ql.udf.generic.GenericUDFDateAdd) Date(java.sql.Date)

Aggregations

DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)77 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)36 Text (org.apache.hadoop.io.Text)36 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)35 Date (java.sql.Date)31 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)29 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)29 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)25 IntWritable (org.apache.hadoop.io.IntWritable)25 Timestamp (java.sql.Timestamp)24 BytesWritable (org.apache.hadoop.io.BytesWritable)24 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)22 LongWritable (org.apache.hadoop.io.LongWritable)22 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)20 BooleanWritable (org.apache.hadoop.io.BooleanWritable)20 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)19 HiveIntervalDayTimeWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable)19 FloatWritable (org.apache.hadoop.io.FloatWritable)19 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)18 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)18