Search in sources :

Example 36 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFSortArray method testSortStruct.

@Test
public void testSortStruct() throws HiveException {
    ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("f1", "f2", "f3", "f4"), asList(PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableDateObjectInspector, ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableIntObjectInspector)))) };
    udf.initialize(inputOIs);
    Object i1 = asList(new Text("a"), new DoubleWritable(3.1415), new DateWritable(new Date(2015, 5, 26)), asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new IntWritable(4)));
    Object i2 = asList(new Text("b"), new DoubleWritable(3.14), new DateWritable(new Date(2015, 5, 26)), asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new IntWritable(4)));
    Object i3 = asList(new Text("a"), new DoubleWritable(3.1415), new DateWritable(new Date(2015, 5, 25)), asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new IntWritable(5)));
    Object i4 = asList(new Text("a"), new DoubleWritable(3.1415), new DateWritable(new Date(2015, 5, 25)), asList(new IntWritable(1), new IntWritable(3), new IntWritable(2), new IntWritable(4)));
    runAndVerify(asList(i1, i2, i3, i4), asList(i4, i3, i1, i2));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) Text(org.apache.hadoop.io.Text) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Date(java.sql.Date) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 37 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFSortArrayByField method testSortPrimitiveTupleTwoFieldOrderDESC.

@Test
public void testSortPrimitiveTupleTwoFieldOrderDESC() throws HiveException {
    List<ObjectInspector> tuple = new ArrayList<ObjectInspector>();
    tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("Company", "Department"), tuple)), PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector };
    udf.initialize(inputOIs);
    Object i1 = asList(new Text("Linkedin"), new Text("HR"));
    Object i2 = asList(new Text("Linkedin"), new Text("IT"));
    Object i3 = asList(new Text("Linkedin"), new Text("Finance"));
    Object i4 = asList(new Text("Facebook"), new Text("IT"));
    Object i5 = asList(new Text("Facebook"), new Text("Finance"));
    Object i6 = asList(new Text("Facebook"), new Text("HR"));
    Object i7 = asList(new Text("Google"), new Text("Logistics"));
    Object i8 = asList(new Text("Google"), new Text("Finance"));
    Object i9 = asList(new Text("Google"), new Text("HR"));
    HiveVarchar vc = new HiveVarchar();
    vc.setValue("Department");
    GenericUDF.DeferredJavaObject[] argas = { new GenericUDF.DeferredJavaObject(asList(i1, i2, i3, i4, i5, i6, i7, i8, i9)), new GenericUDF.DeferredJavaObject(new Text("Company")), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)), new GenericUDF.DeferredJavaObject(new Text("DESC")) };
    runAndVerify(argas, asList(i2, i1, i3, i7, i9, i8, i4, i6, i5));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ArrayList(java.util.ArrayList) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) Text(org.apache.hadoop.io.Text) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Test(org.junit.Test)

Example 38 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFRTrim method testTrim.

public void testTrim() throws HiveException {
    GenericUDFRTrim udf = new GenericUDFRTrim();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    runAndVerify(" Hello World! ", " Hello World!", udf);
    runAndVerify("Hello World! ", "Hello World!", udf);
    runAndVerify(" Hello World!", " Hello World!", udf);
    runAndVerify("Hello World!", "Hello World!", udf);
    runAndVerify("   ", "", udf);
}
Also used : GenericUDFRTrim(org.apache.hadoop.hive.ql.udf.generic.GenericUDFRTrim) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 39 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFRegexp method testConstant.

public void testConstant() throws HiveException {
    GenericUDFRegExp udf = new GenericUDFRegExp();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    Text regexText = new Text("^fo");
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, regexText);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    runAndVerifyConst("fofo", regexText, true, udf);
    runAndVerifyConst("fofofo", regexText, true, udf);
    runAndVerifyConst("fobar", regexText, true, udf);
    runAndVerifyConst("barfobar", regexText, false, udf);
    // null
    runAndVerifyConst(null, regexText, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text)

Example 40 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFRegexp method testEmptyConstant.

public void testEmptyConstant() throws HiveException {
    GenericUDFRegExp udf = new GenericUDFRegExp();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    Text regexText = new Text("");
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, regexText);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    // empty regex (should be one WARN message)
    runAndVerifyConst("foo", regexText, false, udf);
    runAndVerifyConst("bar", regexText, false, udf);
    // null
    runAndVerifyConst(null, regexText, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text)

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