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();
}
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());
}
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));
}
}
}
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!"));
}
}
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"));
}
}
Aggregations