private static TColumnValue toTColumnValue()

in flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/util/ThriftObjectConversions.java [433:509]


    private static TColumnValue toTColumnValue(
            LogicalType fieldType, Object value, Function<Object, String> jsonValue) {
        switch (fieldType.getTypeRoot()) {
            case BOOLEAN:
                {
                    TBoolValue boolValue = new TBoolValue();
                    if (value != null) {
                        boolValue.setValue((Boolean) value);
                    }
                    return TColumnValue.boolVal(boolValue);
                }
            case TINYINT:
                {
                    TByteValue byteValue = new TByteValue();
                    if (value != null) {
                        byteValue.setValue((byte) value);
                    }
                    return TColumnValue.byteVal(byteValue);
                }
            case SMALLINT:
                {
                    TI16Value tI16Value = new TI16Value();
                    if (value != null) {
                        tI16Value.setValue((Short) value);
                    }
                    return TColumnValue.i16Val(tI16Value);
                }
            case INTEGER:
                {
                    TI32Value tI32Value = new TI32Value();
                    if (value != null) {
                        tI32Value.setValue((Integer) value);
                    }
                    return TColumnValue.i32Val(tI32Value);
                }
            case BIGINT:
                {
                    TI64Value tI64Value = new TI64Value();
                    if (value != null) {
                        tI64Value.setValue((Long) value);
                    }
                    return TColumnValue.i64Val(tI64Value);
                }
            case FLOAT:
            case DOUBLE:
                {
                    TDoubleValue tDoubleValue = new TDoubleValue();
                    if (value != null) {
                        if (value instanceof Double) {
                            tDoubleValue.setValue((Double) value);
                        } else if (value instanceof Float) {
                            tDoubleValue.setValue((Float) value);
                        }
                    }
                    return TColumnValue.doubleVal(tDoubleValue);
                }
            case BINARY:
            case VARBINARY:
                // For BINARY type, convert to STRING. Please refer to SerDeUtil#toThriftPayload
                {
                    TStringValue tStringValue = new TStringValue();
                    if (value != null) {
                        tStringValue.setValue(new String((byte[]) value));
                    }
                    return TColumnValue.stringVal(tStringValue);
                }
            default:
                {
                    TStringValue jsonString = new TStringValue();
                    if (fieldType.is(CONSTRUCTED) || value != null) {
                        // If field is ARRAY/MAP/MULTISET, convert to "null".
                        jsonString.setValue(jsonValue.apply(value));
                    }
                    return TColumnValue.stringVal(jsonString);
                }
        }
    }