Search in sources :

Example 1 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class TestObjectInspectorConverters method testObjectInspectorConverters.

public void testObjectInspectorConverters() throws Throwable {
    try {
        // Boolean
        Converter booleanConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableBooleanObjectInspector);
        assertEquals("BooleanConverter", new BooleanWritable(false), booleanConverter.convert(Integer.valueOf(0)));
        assertEquals("BooleanConverter", new BooleanWritable(true), booleanConverter.convert(Integer.valueOf(1)));
        assertEquals("BooleanConverter", null, booleanConverter.convert(null));
        // Byte
        Converter byteConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector);
        assertEquals("ByteConverter", new ByteWritable((byte) 0), byteConverter.convert(Integer.valueOf(0)));
        assertEquals("ByteConverter", new ByteWritable((byte) 1), byteConverter.convert(Integer.valueOf(1)));
        assertEquals("ByteConverter", null, byteConverter.convert(null));
        // Short
        Converter shortConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector);
        assertEquals("ShortConverter", new ShortWritable((short) 0), shortConverter.convert(Integer.valueOf(0)));
        assertEquals("ShortConverter", new ShortWritable((short) 1), shortConverter.convert(Integer.valueOf(1)));
        assertEquals("ShortConverter", null, shortConverter.convert(null));
        // Int
        Converter intConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector);
        assertEquals("IntConverter", new IntWritable(0), intConverter.convert(Integer.valueOf(0)));
        assertEquals("IntConverter", new IntWritable(1), intConverter.convert(Integer.valueOf(1)));
        assertEquals("IntConverter", null, intConverter.convert(null));
        // Long
        Converter longConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableLongObjectInspector);
        assertEquals("LongConverter", new LongWritable(0), longConverter.convert(Integer.valueOf(0)));
        assertEquals("LongConverter", new LongWritable(1), longConverter.convert(Integer.valueOf(1)));
        assertEquals("LongConverter", null, longConverter.convert(null));
        // Float
        Converter floatConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector);
        assertEquals("LongConverter", new FloatWritable(0), floatConverter.convert(Integer.valueOf(0)));
        assertEquals("LongConverter", new FloatWritable(1), floatConverter.convert(Integer.valueOf(1)));
        assertEquals("LongConverter", null, floatConverter.convert(null));
        // Double
        Converter doubleConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
        assertEquals("DoubleConverter", new DoubleWritable(0), doubleConverter.convert(Integer.valueOf(0)));
        assertEquals("DoubleConverter", new DoubleWritable(1), doubleConverter.convert(Integer.valueOf(1)));
        assertEquals("DoubleConverter", null, doubleConverter.convert(null));
        // Char
        Converter charConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, PrimitiveObjectInspectorFactory.javaHiveCharObjectInspector);
        assertEquals("CharConverter", new HiveChar("TRUE", -1), charConverter.convert(Boolean.valueOf(true)));
        assertEquals("CharConverter", new HiveChar("FALSE", -1), charConverter.convert(Boolean.valueOf(false)));
        charConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, PrimitiveObjectInspectorFactory.writableHiveCharObjectInspector);
        assertEquals("CharConverter", new HiveCharWritable(new HiveChar("TRUE", -1)), charConverter.convert(Boolean.valueOf(true)));
        assertEquals("CharConverter", new HiveCharWritable(new HiveChar("FALSE", -1)), charConverter.convert(Boolean.valueOf(false)));
        charConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.javaHiveCharObjectInspector);
        assertEquals("CharConverter", new HiveChar("0", -1), charConverter.convert(Integer.valueOf(0)));
        assertEquals("CharConverter", new HiveChar("1", -1), charConverter.convert(Integer.valueOf(1)));
        charConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableHiveCharObjectInspector);
        assertEquals("CharConverter", new HiveCharWritable(new HiveChar("0", -1)), charConverter.convert(Integer.valueOf(0)));
        assertEquals("CharConverter", new HiveCharWritable(new HiveChar("1", -1)), charConverter.convert(Integer.valueOf(1)));
        charConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaHiveCharObjectInspector);
        assertEquals("CharConverter", new HiveChar("hive", -1), charConverter.convert(String.valueOf("hive")));
        charConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.writableHiveCharObjectInspector);
        assertEquals("CharConverter", new HiveCharWritable(new HiveChar("hive", -1)), charConverter.convert(String.valueOf("hive")));
        // VarChar
        Converter varcharConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector);
        assertEquals("VarCharConverter", new HiveVarchar("TRUE", -1), varcharConverter.convert(Boolean.valueOf(true)));
        assertEquals("VarCharConverter", new HiveVarchar("FALSE", -1), varcharConverter.convert(Boolean.valueOf(false)));
        varcharConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector);
        assertEquals("VarCharConverter", new HiveVarcharWritable(new HiveVarchar("TRUE", -1)), varcharConverter.convert(Boolean.valueOf(true)));
        assertEquals("VarCharConverter", new HiveVarcharWritable(new HiveVarchar("FALSE", -1)), varcharConverter.convert(Boolean.valueOf(false)));
        varcharConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector);
        assertEquals("VarCharConverter", new HiveVarchar("0", -1), varcharConverter.convert(Integer.valueOf(0)));
        assertEquals("VarCharConverter", new HiveVarchar("1", -1), varcharConverter.convert(Integer.valueOf(1)));
        varcharConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector);
        assertEquals("VarCharConverter", new HiveVarcharWritable(new HiveVarchar("0", -1)), varcharConverter.convert(Integer.valueOf(0)));
        assertEquals("VarCharConverter", new HiveVarcharWritable(new HiveVarchar("1", -1)), varcharConverter.convert(Integer.valueOf(1)));
        varcharConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector);
        assertEquals("VarCharConverter", new HiveVarchar("hive", -1), varcharConverter.convert(String.valueOf("hive")));
        varcharConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector);
        assertEquals("VarCharConverter", new HiveVarcharWritable(new HiveVarchar("hive", -1)), varcharConverter.convert(String.valueOf("hive")));
        // Text
        Converter textConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
        assertEquals("TextConverter", new Text("0"), textConverter.convert(Integer.valueOf(0)));
        assertEquals("TextConverter", new Text("1"), textConverter.convert(Integer.valueOf(1)));
        assertEquals("TextConverter", null, textConverter.convert(null));
        textConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.writableBinaryObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
        assertEquals("TextConverter", new Text("hive"), textConverter.convert(new BytesWritable(new byte[] { (byte) 'h', (byte) 'i', (byte) 'v', (byte) 'e' })));
        assertEquals("TextConverter", null, textConverter.convert(null));
        textConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
        assertEquals("TextConverter", new Text("hive"), textConverter.convert(new Text("hive")));
        assertEquals("TextConverter", null, textConverter.convert(null));
        textConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
        assertEquals("TextConverter", new Text("hive"), textConverter.convert(new String("hive")));
        assertEquals("TextConverter", null, textConverter.convert(null));
        textConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaHiveDecimalObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
        assertEquals("TextConverter", new Text("100.001"), textConverter.convert(HiveDecimal.create("100.001")));
        assertEquals("TextConverter", null, textConverter.convert(null));
        // Binary
        Converter baConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.writableBinaryObjectInspector);
        assertEquals("BAConverter", new BytesWritable(new byte[] { (byte) 'h', (byte) 'i', (byte) 'v', (byte) 'e' }), baConverter.convert("hive"));
        assertEquals("BAConverter", null, baConverter.convert(null));
        baConverter = ObjectInspectorConverters.getConverter(PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableBinaryObjectInspector);
        assertEquals("BAConverter", new BytesWritable(new byte[] { (byte) 'h', (byte) 'i', (byte) 'v', (byte) 'e' }), baConverter.convert(new Text("hive")));
        assertEquals("BAConverter", null, baConverter.convert(null));
        // Union
        ArrayList<String> fieldNames = new ArrayList<String>();
        fieldNames.add("firstInteger");
        fieldNames.add("secondString");
        fieldNames.add("thirdBoolean");
        ArrayList<ObjectInspector> fieldObjectInspectors = new ArrayList<ObjectInspector>();
        fieldObjectInspectors.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
        fieldObjectInspectors.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
        fieldObjectInspectors.add(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector);
        ArrayList<String> fieldNames2 = new ArrayList<String>();
        fieldNames2.add("firstString");
        fieldNames2.add("secondInteger");
        fieldNames2.add("thirdBoolean");
        ArrayList<ObjectInspector> fieldObjectInspectors2 = new ArrayList<ObjectInspector>();
        fieldObjectInspectors2.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
        fieldObjectInspectors2.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
        fieldObjectInspectors2.add(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector);
        Converter unionConverter0 = ObjectInspectorConverters.getConverter(ObjectInspectorFactory.getStandardUnionObjectInspector(fieldObjectInspectors), ObjectInspectorFactory.getStandardUnionObjectInspector(fieldObjectInspectors2));
        Object convertedObject0 = unionConverter0.convert(new StandardUnion((byte) 0, 1));
        StandardUnion expectedObject0 = new StandardUnion();
        expectedObject0.setTag((byte) 0);
        expectedObject0.setObject("1");
        assertEquals(expectedObject0, convertedObject0);
        Converter unionConverter1 = ObjectInspectorConverters.getConverter(ObjectInspectorFactory.getStandardUnionObjectInspector(fieldObjectInspectors), ObjectInspectorFactory.getStandardUnionObjectInspector(fieldObjectInspectors2));
        Object convertedObject1 = unionConverter1.convert(new StandardUnion((byte) 1, "1"));
        StandardUnion expectedObject1 = new StandardUnion();
        expectedObject1.setTag((byte) 1);
        expectedObject1.setObject(1);
        assertEquals(expectedObject1, convertedObject1);
        Converter unionConverter2 = ObjectInspectorConverters.getConverter(ObjectInspectorFactory.getStandardUnionObjectInspector(fieldObjectInspectors), ObjectInspectorFactory.getStandardUnionObjectInspector(fieldObjectInspectors2));
        Object convertedObject2 = unionConverter2.convert(new StandardUnion((byte) 2, true));
        StandardUnion expectedObject2 = new StandardUnion();
        expectedObject2.setTag((byte) 2);
        expectedObject2.setObject(true);
        assertEquals(expectedObject2, convertedObject2);
        // Union (extra fields)
        ArrayList<String> fieldNamesExtra = new ArrayList<String>();
        fieldNamesExtra.add("firstInteger");
        fieldNamesExtra.add("secondString");
        fieldNamesExtra.add("thirdBoolean");
        ArrayList<ObjectInspector> fieldObjectInspectorsExtra = new ArrayList<ObjectInspector>();
        fieldObjectInspectorsExtra.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
        fieldObjectInspectorsExtra.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
        fieldObjectInspectorsExtra.add(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector);
        ArrayList<String> fieldNamesExtra2 = new ArrayList<String>();
        fieldNamesExtra2.add("firstString");
        fieldNamesExtra2.add("secondInteger");
        ArrayList<ObjectInspector> fieldObjectInspectorsExtra2 = new ArrayList<ObjectInspector>();
        fieldObjectInspectorsExtra2.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
        fieldObjectInspectorsExtra2.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
        Converter unionConverterExtra = ObjectInspectorConverters.getConverter(ObjectInspectorFactory.getStandardUnionObjectInspector(fieldObjectInspectorsExtra), ObjectInspectorFactory.getStandardUnionObjectInspector(fieldObjectInspectorsExtra2));
        Object convertedObjectExtra = unionConverterExtra.convert(new StandardUnion((byte) 2, true));
        StandardUnion expectedObjectExtra = new StandardUnion();
        expectedObjectExtra.setTag((byte) -1);
        expectedObjectExtra.setObject(null);
        // we should get back null
        assertEquals(expectedObjectExtra, convertedObjectExtra);
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : HiveChar(org.apache.hadoop.hive.common.type.HiveChar) ArrayList(java.util.ArrayList) HiveCharWritable(org.apache.hadoop.hive.serde2.io.HiveCharWritable) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Text(org.apache.hadoop.io.Text) BytesWritable(org.apache.hadoop.io.BytesWritable) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) FloatWritable(org.apache.hadoop.io.FloatWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) StandardUnion(org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector.StandardUnion) Converter(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter) LongWritable(org.apache.hadoop.io.LongWritable) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Example 2 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class GenericUDFIn method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length < 2) {
        throw new UDFArgumentLengthException("The function IN requires at least two arguments, got " + arguments.length);
    }
    argumentOIs = arguments;
    // We want to use the ReturnObjectInspectorResolver because otherwise
    // ObjectInspectorUtils.compare() will return != for two objects that have
    // different object inspectors, e.g. 238 and "238". The ROIR will help convert
    // both values to a common type so that they can be compared reasonably.
    conversionHelper = new GenericUDFUtils.ReturnObjectInspectorResolver(true);
    for (ObjectInspector oi : arguments) {
        if (!conversionHelper.updateForComparison(oi)) {
            StringBuilder sb = new StringBuilder();
            sb.append("Type mismatch: {");
            sb.append(arguments[0].getTypeName());
            sb.append(" IN (");
            for (int i = 1; i < arguments.length; i++) {
                if (i != 1) {
                    sb.append(", ");
                }
                sb.append(arguments[i].getTypeName());
            }
            sb.append(")}");
            throw new UDFArgumentException(sb.toString());
        }
    }
    compareOI = conversionHelper.get();
    checkIfInSetConstant();
    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
Also used : ReturnObjectInspectorResolver(org.apache.hadoop.hive.ql.udf.generic.GenericUDFUtils.ReturnObjectInspectorResolver) UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)

Example 3 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class GenericUDFLikeAll method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length < 2) {
        throw new UDFArgumentLengthException("The like all operator requires at least one pattern for matching, got " + (arguments.length - 1));
    }
    inputTypes = new PrimitiveCategory[arguments.length];
    converters = new Converter[arguments.length];
    /**
     *expects string or null arguments
     */
    for (int idx = 0; idx < arguments.length; idx++) {
        checkArgPrimitive(arguments, idx);
        checkArgGroups(arguments, idx, inputTypes, PrimitiveGrouping.STRING_GROUP, PrimitiveGrouping.VOID_GROUP);
        PrimitiveCategory inputType = ((PrimitiveObjectInspector) arguments[idx]).getPrimitiveCategory();
        if (arguments[idx] instanceof ConstantObjectInspector && idx != 0) {
            Object constValue = ((ConstantObjectInspector) arguments[idx]).getWritableConstantValue();
            if (!isConstantNullPatternContain && constValue == null) {
                isConstantNullPatternContain = true;
            }
        } else if (idx != 0 && isAllPatternsConstant) {
            isAllPatternsConstant = false;
        }
        converters[idx] = ObjectInspectorConverters.getConverter(arguments[idx], getOutputOI(inputType));
        inputTypes[idx] = inputType;
    }
    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
Also used : UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)

Example 4 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class GenericUDFRegExp method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    SessionState ss = SessionState.get();
    if (ss != null) {
        this.useGoogleRegexEngine = ss.getConf().getBoolVar(HiveConf.ConfVars.HIVEUSEGOOGLEREGEXENGINE);
    }
    checkArgsSize(arguments, 2, 2);
    checkArgPrimitive(arguments, 0);
    checkArgPrimitive(arguments, 1);
    checkArgGroups(arguments, 0, inputTypes, STRING_GROUP);
    checkArgGroups(arguments, 1, inputTypes, STRING_GROUP);
    obtainStringConverter(arguments, 0, inputTypes, converters);
    obtainStringConverter(arguments, 1, inputTypes, converters);
    if (arguments[1] instanceof ConstantObjectInspector) {
        regexConst = getConstantStringValue(arguments, 1);
        if (regexConst != null) {
            if (!useGoogleRegexEngine) {
                // if(!HiveConf.getVar(hiveConf, HiveConf.ConfVars.HIVEUSEGOOGLEREGEXENGINE)){
                patternConst = Pattern.compile(regexConst);
            } else {
                patternConstR2j = com.google.re2j.Pattern.compile(regexConst);
            }
        }
        isRegexConst = true;
    }
    ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
    return outputOI;
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)

Example 5 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class TestGenericUDFOPAnd method testFalseAndNull.

@Test
public void testFalseAndNull() throws HiveException, IOException {
    GenericUDFOPAnd udf = new GenericUDFOPAnd();
    BooleanWritable left = new BooleanWritable(false);
    Writable right = null;
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableBooleanObjectInspector, PrimitiveObjectInspectorFactory.writableVoidObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.booleanTypeInfo);
    BooleanWritable res = (BooleanWritable) udf.evaluate(args);
    Assert.assertEquals(false, res.get());
    udf.close();
}
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) BooleanWritable(org.apache.hadoop.io.BooleanWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) BooleanWritable(org.apache.hadoop.io.BooleanWritable) Writable(org.apache.hadoop.io.Writable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)17 BooleanWritable (org.apache.hadoop.io.BooleanWritable)14 Test (org.junit.Test)14 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)13 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)10 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)10 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)5 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)3 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)3 Writable (org.apache.hadoop.io.Writable)3 ArrayList (java.util.ArrayList)2 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)2 Converter (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter)2 StandardStructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector)2 BigDecimal (java.math.BigDecimal)1 Timestamp (java.sql.Timestamp)1 DataTypePhysicalVariation (org.apache.hadoop.hive.common.type.DataTypePhysicalVariation)1 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)1 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)1 DataConstraintViolationError (org.apache.hadoop.hive.ql.exec.errors.DataConstraintViolationError)1