Search in sources :

Example 36 with HiveVarcharWritable

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

the class WritableHiveVarcharObjectInspector method copyObject.

@Override
public Object copyObject(Object o) {
    if (o == null) {
        return null;
    }
    if (o instanceof Text) {
        String str = ((Text) o).toString();
        HiveVarcharWritable hcw = new HiveVarcharWritable();
        hcw.set(str, ((VarcharTypeInfo) typeInfo).getLength());
        return hcw;
    }
    HiveVarcharWritable writable = (HiveVarcharWritable) o;
    if (doesWritableMatchTypeParams((HiveVarcharWritable) o)) {
        return new HiveVarcharWritable(writable);
    }
    return getWritableWithParams(writable);
}
Also used : HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) Text(org.apache.hadoop.io.Text)

Example 37 with HiveVarcharWritable

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

the class WritableHiveVarcharObjectInspector method getWritableWithParams.

private HiveVarcharWritable getWritableWithParams(HiveVarcharWritable val) {
    HiveVarcharWritable newValue = new HiveVarcharWritable();
    newValue.set(val, getMaxLength());
    return newValue;
}
Also used : HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)

Example 38 with HiveVarcharWritable

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

the class WritableHiveVarcharObjectInspector method set.

@Override
public Object set(Object o, String value) {
    if (value == null) {
        return null;
    }
    HiveVarcharWritable writable = (HiveVarcharWritable) o;
    writable.set(value, getMaxLength());
    return o;
}
Also used : HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)

Example 39 with HiveVarcharWritable

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

the class TestGenericUDFSortArrayByField method testSortPrimitiveTupleTwoField.

@Test
public void testSortPrimitiveTupleTwoField() 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 };
    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)) };
    runAndVerify(argas, asList(i5, i6, i4, i8, i9, i7, i3, i1, i2));
}
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 40 with HiveVarcharWritable

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

the class TestGenericUDFSortArrayByField method testSortPrimitiveTupleOneFieldOrderASC.

@Test
public void testSortPrimitiveTupleOneFieldOrderASC() throws HiveException {
    List<ObjectInspector> tuple = new ArrayList<ObjectInspector>();
    tuple.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    tuple.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
    ObjectInspector[] inputOIs = { ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(asList("Company", "Salary"), tuple)), PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector, PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector };
    udf.initialize(inputOIs);
    Object i1 = asList(new Text("Facebook"), new DoubleWritable(80223.25));
    Object i2 = asList(new Text("Facebook"), new DoubleWritable(50223.25));
    Object i3 = asList(new Text("Facebook"), new DoubleWritable(40223.25));
    Object i4 = asList(new Text("Facebook"), new DoubleWritable(60223.25));
    HiveVarchar vc = new HiveVarchar();
    vc.setValue("Salary");
    HiveVarchar order = new HiveVarchar();
    order.setValue("ASC");
    GenericUDF.DeferredJavaObject[] argas = { new GenericUDF.DeferredJavaObject(asList(i1, i2, i3, i4)), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)), new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(order)) };
    runAndVerify(argas, asList(i3, i2, i4, i1));
}
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) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Test(org.junit.Test)

Aggregations

HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)46 Text (org.apache.hadoop.io.Text)31 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)28 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)25 IntWritable (org.apache.hadoop.io.IntWritable)24 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)22 LongWritable (org.apache.hadoop.io.LongWritable)21 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)20 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)20 BooleanWritable (org.apache.hadoop.io.BooleanWritable)20 BytesWritable (org.apache.hadoop.io.BytesWritable)20 FloatWritable (org.apache.hadoop.io.FloatWritable)19 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)18 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)18 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)18 Test (org.junit.Test)18 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)17 ArrayList (java.util.ArrayList)15 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)15 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)15