Search in sources :

Example 16 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class TestGenericUDFOPOr method testTrueOrTrue.

@Test
public void testTrueOrTrue() throws HiveException, IOException {
    GenericUDFOPOr udf = new GenericUDFOPOr();
    BooleanWritable left = new BooleanWritable(true);
    BooleanWritable right = new BooleanWritable(true);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableBooleanObjectInspector, PrimitiveObjectInspectorFactory.writableBooleanObjectInspector };
    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(true, 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) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) Test(org.junit.Test)

Example 17 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class TestGenericUDFEnforceConstraint method testCorrect.

@Test
public void testCorrect() throws HiveException {
    GenericUDFEnforceConstraint udf = new GenericUDFEnforceConstraint();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    BooleanWritable input = new BooleanWritable(true);
    GenericUDF.DeferredObject[] args = { new GenericUDF.DeferredJavaObject(input) };
    BooleanWritable writable = (BooleanWritable) udf.evaluate(args);
    assertTrue("Not expected result: expected [true] actual  [ " + writable.get() + " ]", writable.get());
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) BooleanWritable(org.apache.hadoop.io.BooleanWritable) Test(org.junit.Test)

Example 18 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class TestKuduSerDe method testSerDeRoundTrip.

@Test
public void testSerDeRoundTrip() throws Exception {
    KuduSerDe serDe = new KuduSerDe();
    serDe.initialize(BASE_CONF, TBL_PROPS, null);
    PartialRow before = SCHEMA.newPartialRow();
    before.addByte("key", (byte) 1);
    before.addShort("int16", (short) 1);
    before.addInt("int32", 1);
    before.addLong("int64", 1L);
    before.addBoolean("bool", true);
    before.addFloat("float", 1.1f);
    before.addDouble("double", 1.1d);
    before.addString("string", "one");
    before.addBinary("binary", "one".getBytes(UTF_8));
    before.addTimestamp("timestamp", new Timestamp(NOW_MS));
    before.addDecimal("decimal", new BigDecimal("1.111"));
    before.setNull("null");
    before.addInt("default", 1);
    KuduWritable beforeWritable = new KuduWritable(before);
    Object object = serDe.deserialize(beforeWritable);
    // Capitalized `key` field to check for field case insensitivity.
    List<String> fieldNames = Arrays.asList("KEY", "int16", "int32", "int64", "bool", "float", "double", "string", "binary", "timestamp", "decimal", "null", "default");
    List<ObjectInspector> ois = Arrays.asList(PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector, PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.writableBooleanObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableBinaryObjectInspector, PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector);
    StandardStructObjectInspector objectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, ois);
    KuduWritable afterWritable = serDe.serialize(object, objectInspector);
    PartialRow after = afterWritable.getPartialRow();
    for (int i = 0; i < SCHEMA.getColumnCount(); i++) {
        if (SCHEMA.getColumnByIndex(i).getType() == Type.BINARY) {
            assertArrayEquals("Columns not equal at index: " + i, before.getBinaryCopy(i), after.getBinaryCopy(i));
        } else {
            assertEquals("Columns not equal at index: " + i, before.getObject(i), after.getObject(i));
        }
    }
}
Also used : StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PartialRow(org.apache.kudu.client.PartialRow) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 19 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class TestGenericUDFEnforceConstraint method testNull.

@Test
public void testNull() throws HiveException {
    try {
        GenericUDFEnforceConstraint udf = new GenericUDFEnforceConstraint();
        ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
        ObjectInspector[] arguments = { valueOI };
        udf.initialize(arguments);
        BooleanWritable input = new BooleanWritable(false);
        GenericUDF.DeferredObject[] args = { new GenericUDF.DeferredJavaObject(input) };
        udf.evaluate(args);
        fail("Unreachable line");
    } catch (DataConstraintViolationError e) {
        // DataConstraintViolationError is expected
        assertTrue(e.getMessage().contains("NOT NULL constraint violated!"));
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DataConstraintViolationError(org.apache.hadoop.hive.ql.exec.errors.DataConstraintViolationError) BooleanWritable(org.apache.hadoop.io.BooleanWritable) Test(org.junit.Test)

Example 20 with PrimitiveObjectInspectorFactory.writableBooleanObjectInspector

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

the class TestGenericUDFEnforceConstraint method testInvalidArgumentsLength.

@Test
public void testInvalidArgumentsLength() throws HiveException {
    try {
        GenericUDFEnforceConstraint udf = new GenericUDFEnforceConstraint();
        ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
        ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
        ObjectInspector[] arguments = { valueOI1, valueOI2 };
        udf.initialize(arguments);
        fail("Unreachable line");
    } catch (HiveException e) {
        // HiveException is expected
        assertTrue(e.getMessage().contains("Invalid number of arguments"));
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) 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