Search in sources :

Example 31 with DateWritableV2

use of org.apache.hadoop.hive.serde2.io.DateWritableV2 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 DateWritableV2(4)), new DeferredJavaObject(new DateWritableV2(4)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
    Assert.assertEquals(null, udf.evaluate(args));
}
Also used : StandardListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector) 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) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 32 with DateWritableV2

use of org.apache.hadoop.hive.serde2.io.DateWritableV2 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 DateWritableV2(4)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
    udf.initialize(inputOIs);
}
Also used : StandardListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector) 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) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Test(org.junit.Test)

Example 33 with DateWritableV2

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

the class TestGenericUDFOPPlus method testIntervalYearMonthPlusDate.

@Test
public void testIntervalYearMonthPlusDate() throws Exception {
    GenericUDFOPPlus udf = new GenericUDFOPPlus();
    HiveIntervalYearMonthWritable left = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-8"));
    DateWritableV2 right = new DateWritableV2(Date.valueOf("2001-06-15"));
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
    DateWritableV2 res = (DateWritableV2) udf.evaluate(args);
    Assert.assertEquals(Date.valueOf("2004-02-15"), res.get());
}
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) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) HiveIntervalYearMonthWritable(org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable) Test(org.junit.Test)

Example 34 with DateWritableV2

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

the class TestGenericUDFDateSub method testTimestampToDate.

@Test
public void testTimestampToDate() throws HiveException {
    GenericUDFDateSub udf = new GenericUDFDateSub();
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
    ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    ObjectInspector[] arguments = { valueOI1, valueOI2 };
    udf.initialize(arguments);
    DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 20, 4, 17, 52, 0).toString())));
    DeferredObject valueObj2 = new DeferredJavaObject(Integer.valueOf(3));
    DeferredObject[] args = { valueObj1, valueObj2 };
    DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
    assertEquals("date_sub() test for TIMESTAMP failed ", "0109-06-17", 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) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) Test(org.junit.Test)

Example 35 with DateWritableV2

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

the class TestGenericUDFDateSub method testStringToDate.

@Test
public void testStringToDate() throws HiveException {
    GenericUDFDateSub udf = new GenericUDFDateSub();
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    ObjectInspector[] arguments = { valueOI1, valueOI2 };
    udf.initialize(arguments);
    DeferredObject valueObj1 = new DeferredJavaObject(new Text("2009-07-20 04:17:52"));
    DeferredObject valueObj2 = new DeferredJavaObject(Integer.valueOf(2));
    DeferredObject[] args = { valueObj1, valueObj2 };
    DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
    assertEquals("date_sub() test for STRING failed ", "2009-07-18", 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) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Aggregations

DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)73 Test (org.junit.Test)36 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)34 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)29 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)29 Text (org.apache.hadoop.io.Text)29 TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)28 Date (org.apache.hadoop.hive.common.type.Date)24 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)23 Timestamp (org.apache.hadoop.hive.common.type.Timestamp)21 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)21 BytesWritable (org.apache.hadoop.io.BytesWritable)20 IntWritable (org.apache.hadoop.io.IntWritable)17 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)16 HiveIntervalDayTimeWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable)16 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)15 HiveIntervalYearMonthWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable)15 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)14 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)14 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)14