Search in sources :

Example 1 with WritableConstantHiveCharObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveCharObjectInspector 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));
    }
}
Also used : WritableConstantLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantLongObjectInspector) WritableConstantDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantDateObjectInspector) WritableConstantTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantTimestampObjectInspector) WritableConstantHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveCharObjectInspector) FlinkHiveUDFException(org.apache.flink.table.functions.hive.FlinkHiveUDFException) WritableConstantIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector) WritableConstantShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantShortObjectInspector) WritableConstantHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveDecimalObjectInspector) WritableConstantHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveVarcharObjectInspector) FlinkHiveUDFException(org.apache.flink.table.functions.hive.FlinkHiveUDFException) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) WritableConstantByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantByteObjectInspector) WritableConstantStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantStringObjectInspector) WritableConstantFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantFloatObjectInspector) WritableConstantBinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantBinaryObjectInspector) WritableConstantBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantBooleanObjectInspector) WritableConstantDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantDoubleObjectInspector)

Aggregations

CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)1 FlinkHiveUDFException (org.apache.flink.table.functions.hive.FlinkHiveUDFException)1 WritableConstantBinaryObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantBinaryObjectInspector)1 WritableConstantBooleanObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantBooleanObjectInspector)1 WritableConstantByteObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantByteObjectInspector)1 WritableConstantDateObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantDateObjectInspector)1 WritableConstantDoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantDoubleObjectInspector)1 WritableConstantFloatObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantFloatObjectInspector)1 WritableConstantHiveCharObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveCharObjectInspector)1 WritableConstantHiveDecimalObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveDecimalObjectInspector)1 WritableConstantHiveVarcharObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveVarcharObjectInspector)1 WritableConstantIntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector)1 WritableConstantLongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantLongObjectInspector)1 WritableConstantShortObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantShortObjectInspector)1 WritableConstantStringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantStringObjectInspector)1 WritableConstantTimestampObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantTimestampObjectInspector)1