Search in sources :

Example 56 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFQuarter method testQuarterStr.

public void testQuarterStr() throws HiveException {
    GenericUDFQuarter udf = new GenericUDFQuarter();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI0 };
    udf.initialize(arguments);
    // date str
    runAndVerifyStr("2014-01-10", 1, udf);
    runAndVerifyStr("2014-02-10", 1, udf);
    runAndVerifyStr("2014-03-31", 1, udf);
    runAndVerifyStr("2014-04-02", 2, udf);
    runAndVerifyStr("2014-05-28", 2, udf);
    runAndVerifyStr("2016-06-03", 2, udf);
    runAndVerifyStr("2016-07-28", 3, udf);
    runAndVerifyStr("2016-08-29", 3, udf);
    runAndVerifyStr("2016-09-29", 3, udf);
    runAndVerifyStr("2016-10-29", 4, udf);
    runAndVerifyStr("2016-11-29", 4, udf);
    runAndVerifyStr("2016-12-29", 4, udf);
    // negative Unix time
    runAndVerifyStr("1966-01-01", 1, udf);
    runAndVerifyStr("1966-03-31", 1, udf);
    runAndVerifyStr("1966-04-01", 2, udf);
    runAndVerifyStr("1966-12-31", 4, udf);
    // ts str
    runAndVerifyStr("2014-01-01 00:00:00", 1, udf);
    runAndVerifyStr("2014-02-10 15:23:00", 1, udf);
    runAndVerifyStr("2014-03-31 15:23:00", 1, udf);
    runAndVerifyStr("2014-04-02 15:23:00", 2, udf);
    runAndVerifyStr("2014-05-28 15:23:00", 2, udf);
    runAndVerifyStr("2016-06-03 15:23:00", 2, udf);
    runAndVerifyStr("2016-07-28 15:23:00", 3, udf);
    runAndVerifyStr("2016-08-29 15:23:00", 3, udf);
    runAndVerifyStr("2016-09-29 15:23:00", 3, udf);
    runAndVerifyStr("2016-10-29 15:23:00", 4, udf);
    runAndVerifyStr("2016-11-29 15:23:00", 4, udf);
    runAndVerifyStr("2016-12-31 23:59:59.999", 4, udf);
    // negative Unix time
    runAndVerifyStr("1966-01-01 00:00:00", 1, udf);
    runAndVerifyStr("1966-03-31 23:59:59.999", 1, udf);
    runAndVerifyStr("1966-04-01 00:00:00", 2, udf);
    runAndVerifyStr("1966-12-31 23:59:59.999", 4, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 57 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFSoundex method testSoundex.

public void testSoundex() throws HiveException {
    GenericUDFSoundex udf = new GenericUDFSoundex();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI0 };
    udf.initialize(arguments);
    runAndVerify("Miller", "M460", udf);
    runAndVerify("miler", "M460", udf);
    runAndVerify("myller", "M460", udf);
    runAndVerify("muller", "M460", udf);
    runAndVerify("m", "M000", udf);
    runAndVerify("mu", "M000", udf);
    runAndVerify("mil", "M400", udf);
    runAndVerify("Peterson", "P362", udf);
    runAndVerify("Pittersen", "P362", udf);
    runAndVerify("", "", udf);
    runAndVerify(null, null, udf);
    runAndVerify("\u3500\u3501\u3502\u3503", null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 58 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFFloor method testString.

@Test
public void testString() throws HiveException {
    GenericUDFFloor udf = new GenericUDFFloor();
    Text input = new Text("32300.004747");
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableStringObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(input) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
    LongWritable res = (LongWritable) udf.evaluate(args);
    Assert.assertEquals(32300L, 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) Text(org.apache.hadoop.io.Text) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) LongWritable(org.apache.hadoop.io.LongWritable) Test(org.junit.Test)

Example 59 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFFromUtcTimestamp method testToUtcTimestamp.

public void testToUtcTimestamp() throws Exception {
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    GenericUDFToUtcTimestamp udf = new GenericUDFToUtcTimestamp();
    ObjectInspector[] args2 = { valueOI, valueOI };
    udf.initialize(args2);
    runAndVerify(udf, new Text("2015-03-28 17:00:00"), new Text("Europe/London"), Timestamp.valueOf("2015-03-28 17:00:00"));
    runAndVerify(udf, new Text("2015-03-28 18:00:00"), new Text("Europe/London"), Timestamp.valueOf("2015-03-28 18:00:00"));
    runAndVerify(udf, new Text("2015-03-28 19:00:00"), new Text("Europe/London"), Timestamp.valueOf("2015-03-28 19:00:00"));
    // Make sure nanos are preserved
    runAndVerify(udf, new Text("2015-03-28 18:00:00.123456789"), new Text("Europe/London"), Timestamp.valueOf("2015-03-28 18:00:00.123456789"));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text)

Example 60 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFGreatest method testVoids.

public void testVoids() throws HiveException {
    GenericUDFGreatest udf = new GenericUDFGreatest();
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
    ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3 };
    udf.initialize(arguments);
    runAndVerify(new Object[] { null, 1, "test" }, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)105 Text (org.apache.hadoop.io.Text)46 Test (org.junit.Test)36 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)27 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)19 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)17 IntWritable (org.apache.hadoop.io.IntWritable)15 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)13 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)12 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)10 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)10 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)9 ArrayList (java.util.ArrayList)8 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)8 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)7 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)7 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)6 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)6 BooleanWritable (org.apache.hadoop.io.BooleanWritable)6 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)4