use of org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveVarcharObjectInspector in project flink by apache.
the class HiveInspectors method getObjectInspectorForPrimitiveConstant.
private static ObjectInspector getObjectInspectorForPrimitiveConstant(PrimitiveTypeInfo primitiveTypeInfo, @Nonnull Object value, HiveShim hiveShim) {
String className;
value = hiveShim.hivePrimitiveToWritable(value);
switch(primitiveTypeInfo.getPrimitiveCategory()) {
case BOOLEAN:
className = WritableConstantBooleanObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case BYTE:
className = WritableConstantByteObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case SHORT:
className = WritableConstantShortObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case INT:
className = WritableConstantIntObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case LONG:
className = WritableConstantLongObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case FLOAT:
className = WritableConstantFloatObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case DOUBLE:
className = WritableConstantDoubleObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case STRING:
className = WritableConstantStringObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case CHAR:
try {
Constructor<WritableConstantHiveCharObjectInspector> constructor = WritableConstantHiveCharObjectInspector.class.getDeclaredConstructor(CharTypeInfo.class, value.getClass());
constructor.setAccessible(true);
return constructor.newInstance(primitiveTypeInfo, value);
} catch (Exception e) {
throw new FlinkHiveUDFException("Failed to create writable constant object inspector", e);
}
case VARCHAR:
try {
Constructor<WritableConstantHiveVarcharObjectInspector> constructor = WritableConstantHiveVarcharObjectInspector.class.getDeclaredConstructor(VarcharTypeInfo.class, value.getClass());
constructor.setAccessible(true);
return constructor.newInstance(primitiveTypeInfo, value);
} catch (Exception e) {
throw new FlinkHiveUDFException("Failed to create writable constant object inspector", e);
}
case DATE:
className = WritableConstantDateObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case TIMESTAMP:
className = WritableConstantTimestampObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case DECIMAL:
try {
Constructor<WritableConstantHiveDecimalObjectInspector> constructor = WritableConstantHiveDecimalObjectInspector.class.getDeclaredConstructor(DecimalTypeInfo.class, value.getClass());
constructor.setAccessible(true);
return constructor.newInstance(primitiveTypeInfo, value);
} catch (Exception e) {
throw new FlinkHiveUDFException("Failed to create writable constant object inspector", e);
}
case BINARY:
className = WritableConstantBinaryObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value);
case UNKNOWN:
case VOID:
// If type is null, we use the Constant String to replace
className = WritableConstantStringObjectInspector.class.getName();
return HiveReflectionUtils.createConstantObjectInspector(className, value.toString());
default:
throw new FlinkHiveUDFException(String.format("Cannot find ConstantObjectInspector for %s", primitiveTypeInfo));
}
}
Aggregations