use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.booleanTypeInfo in project hive by apache.
the class TestGenericUDFMonthsBetween method testMonthsBetweenForTimestamp.
@Test
public void testMonthsBetweenForTimestamp() throws HiveException {
GenericUDFMonthsBetween udf = new GenericUDFMonthsBetween();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
testMonthsBetweenForTimestamp(udf);
// Run without round-off
GenericUDFMonthsBetween udfWithoutRoundOff = new GenericUDFMonthsBetween();
ObjectInspector vOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector vOI2 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector vOI3 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.booleanTypeInfo, new BooleanWritable(false));
ObjectInspector[] args = { vOI1, vOI2, vOI3 };
udfWithoutRoundOff.initialize(args);
testMonthsBetweenForTimestamp(udfWithoutRoundOff);
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.booleanTypeInfo in project hive by apache.
the class TestGenericUDFOPOr method testFalseOrFalse.
@Test
public void testFalseOrFalse() throws HiveException, IOException {
GenericUDFOPOr udf = new GenericUDFOPOr();
BooleanWritable left = new BooleanWritable(false);
BooleanWritable right = new BooleanWritable(false);
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(false, res.get());
udf.close();
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.booleanTypeInfo 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();
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.booleanTypeInfo in project hive by apache.
the class VectorizationContext method getCastToBoolean.
private VectorExpression getCastToBoolean(List<ExprNodeDesc> childExpr) throws HiveException {
ExprNodeDesc child = childExpr.get(0);
TypeInfo inputTypeInfo = child.getTypeInfo();
String inputType = inputTypeInfo.toString();
if (child instanceof ExprNodeConstantDesc) {
if (null == ((ExprNodeConstantDesc) child).getValue()) {
return getConstantVectorExpression(null, TypeInfoFactory.booleanTypeInfo, VectorExpressionDescriptor.Mode.PROJECTION);
}
// Family of related JIRAs: HIVE-7421, HIVE-7422, and HIVE-7424.
return null;
}
// Long and double are handled using descriptors, string needs to be specially handled.
if (isStringFamily(inputType)) {
VectorExpression lenExpr = createVectorExpression(CastStringToBoolean.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION, TypeInfoFactory.booleanTypeInfo);
return lenExpr;
}
return null;
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.booleanTypeInfo in project parquet-mr by apache.
the class ArrayWritableObjectInspector method getObjectInspector.
private ObjectInspector getObjectInspector(final TypeInfo typeInfo) {
if (typeInfo.equals(TypeInfoFactory.doubleTypeInfo)) {
return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
} else if (typeInfo.equals(TypeInfoFactory.booleanTypeInfo)) {
return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
} else if (typeInfo.equals(TypeInfoFactory.floatTypeInfo)) {
return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
} else if (typeInfo.equals(TypeInfoFactory.intTypeInfo)) {
return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
} else if (typeInfo.equals(TypeInfoFactory.longTypeInfo)) {
return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
} else if (typeInfo.equals(TypeInfoFactory.stringTypeInfo)) {
return ParquetPrimitiveInspectorFactory.parquetStringInspector;
} else if (typeInfo.getCategory().equals(Category.STRUCT)) {
return new ArrayWritableObjectInspector((StructTypeInfo) typeInfo);
} else if (typeInfo.getCategory().equals(Category.LIST)) {
final TypeInfo subTypeInfo = ((ListTypeInfo) typeInfo).getListElementTypeInfo();
return new ParquetHiveArrayInspector(getObjectInspector(subTypeInfo));
} else if (typeInfo.getCategory().equals(Category.MAP)) {
final TypeInfo keyTypeInfo = ((MapTypeInfo) typeInfo).getMapKeyTypeInfo();
final TypeInfo valueTypeInfo = ((MapTypeInfo) typeInfo).getMapValueTypeInfo();
if (keyTypeInfo.equals(TypeInfoFactory.stringTypeInfo) || keyTypeInfo.equals(TypeInfoFactory.byteTypeInfo) || keyTypeInfo.equals(TypeInfoFactory.shortTypeInfo)) {
return new DeepParquetHiveMapInspector(getObjectInspector(keyTypeInfo), getObjectInspector(valueTypeInfo));
} else {
return new StandardParquetHiveMapInspector(getObjectInspector(keyTypeInfo), getObjectInspector(valueTypeInfo));
}
} else if (typeInfo.equals(TypeInfoFactory.timestampTypeInfo)) {
throw new UnsupportedOperationException("timestamp not implemented yet");
} else if (typeInfo.equals(TypeInfoFactory.byteTypeInfo)) {
return ParquetPrimitiveInspectorFactory.parquetByteInspector;
} else if (typeInfo.equals(TypeInfoFactory.shortTypeInfo)) {
return ParquetPrimitiveInspectorFactory.parquetShortInspector;
} else {
throw new IllegalArgumentException("Unknown field info: " + typeInfo);
}
}
Aggregations