Search in sources :

Example 26 with RowFormatInfo

use of org.apache.inlong.sort.formats.common.RowFormatInfo in project incubator-inlong by apache.

the class TableFormatUtils method deriveLogicalType.

/**
 * Derive the LogicalType for the given FormatInfo.
 */
public static LogicalType deriveLogicalType(FormatInfo formatInfo) {
    if (formatInfo instanceof StringFormatInfo) {
        return new VarCharType();
    } else if (formatInfo instanceof BooleanFormatInfo) {
        return new BooleanType();
    } else if (formatInfo instanceof ByteFormatInfo) {
        return new TinyIntType();
    } else if (formatInfo instanceof ShortFormatInfo) {
        return new SmallIntType();
    } else if (formatInfo instanceof IntFormatInfo) {
        return new IntType();
    } else if (formatInfo instanceof LongFormatInfo) {
        return new BigIntType();
    } else if (formatInfo instanceof FloatFormatInfo) {
        return new FloatType();
    } else if (formatInfo instanceof DoubleFormatInfo) {
        return new DoubleType();
    } else if (formatInfo instanceof DecimalFormatInfo) {
        return new DecimalType();
    } else if (formatInfo instanceof TimeFormatInfo) {
        return new TimeType();
    } else if (formatInfo instanceof DateFormatInfo) {
        return new DateType();
    } else if (formatInfo instanceof TimestampFormatInfo) {
        return new TimestampType(DEFAULT_PRECISION_FOR_TIMESTAMP);
    } else if (formatInfo instanceof LocalZonedTimestampFormatInfo) {
        return new LocalZonedTimestampType();
    } else if (formatInfo instanceof ArrayFormatInfo) {
        FormatInfo elementFormatInfo = ((ArrayFormatInfo) formatInfo).getElementFormatInfo();
        return new ArrayType(deriveLogicalType(elementFormatInfo));
    } else if (formatInfo instanceof MapFormatInfo) {
        MapFormatInfo mapFormatInfo = (MapFormatInfo) formatInfo;
        FormatInfo keyFormatInfo = mapFormatInfo.getKeyFormatInfo();
        FormatInfo valueFormatInfo = mapFormatInfo.getValueFormatInfo();
        return new MapType(deriveLogicalType(keyFormatInfo), deriveLogicalType(valueFormatInfo));
    } else if (formatInfo instanceof RowFormatInfo) {
        RowFormatInfo rowFormatInfo = (RowFormatInfo) formatInfo;
        FormatInfo[] formatInfos = rowFormatInfo.getFieldFormatInfos();
        int formatInfosSize = formatInfos.length;
        LogicalType[] logicalTypes = new LogicalType[formatInfosSize];
        for (int i = 0; i < formatInfosSize; ++i) {
            logicalTypes[i] = deriveLogicalType(formatInfos[i]);
        }
        return RowType.of(logicalTypes, rowFormatInfo.getFieldNames());
    } else if (formatInfo instanceof BinaryFormatInfo) {
        return new BinaryType();
    } else if (formatInfo instanceof NullFormatInfo) {
        return new NullType();
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) LocalZonedTimestampFormatInfo(org.apache.inlong.sort.formats.common.LocalZonedTimestampFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) BigIntType(org.apache.flink.table.types.logical.BigIntType) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) MapType(org.apache.flink.table.types.logical.MapType) TinyIntType(org.apache.flink.table.types.logical.TinyIntType) IntType(org.apache.flink.table.types.logical.IntType) BigIntType(org.apache.flink.table.types.logical.BigIntType) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) FloatType(org.apache.flink.table.types.logical.FloatType) TimeType(org.apache.flink.table.types.logical.TimeType) ArrayType(org.apache.flink.table.types.logical.ArrayType) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) LocalZonedTimestampFormatInfo(org.apache.inlong.sort.formats.common.LocalZonedTimestampFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimestampType(org.apache.flink.table.types.logical.TimestampType) VarCharType(org.apache.flink.table.types.logical.VarCharType) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) DateType(org.apache.flink.table.types.logical.DateType) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) BinaryType(org.apache.flink.table.types.logical.BinaryType) BooleanType(org.apache.flink.table.types.logical.BooleanType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) TinyIntType(org.apache.flink.table.types.logical.TinyIntType) NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) DoubleType(org.apache.flink.table.types.logical.DoubleType) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) DecimalType(org.apache.flink.table.types.logical.DecimalType) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) NullType(org.apache.flink.table.types.logical.NullType) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) LocalZonedTimestampFormatInfo(org.apache.inlong.sort.formats.common.LocalZonedTimestampFormatInfo) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo)

Example 27 with RowFormatInfo

use of org.apache.inlong.sort.formats.common.RowFormatInfo in project incubator-inlong by apache.

the class TableFormatUtils method deriveRowFormatInfo.

/**
 * Derives the format from the given schema.
 *
 * @param descriptorProperties The properties of the descriptor.
 * @return The format derived from the schema in the descriptor.
 */
public static RowFormatInfo deriveRowFormatInfo(DescriptorProperties descriptorProperties) {
    TableSchema tableSchema = deriveSchema(descriptorProperties.asMap());
    int numFields = tableSchema.getFieldCount();
    String[] fieldNames = tableSchema.getFieldNames();
    DataType[] fieldTypes = tableSchema.getFieldDataTypes();
    FormatInfo[] fieldFormatInfos = new FormatInfo[numFields];
    for (int i = 0; i < numFields; ++i) {
        LogicalType fieldType = fieldTypes[i].getLogicalType();
        fieldFormatInfos[i] = deriveFormatInfo(fieldType);
    }
    return new RowFormatInfo(fieldNames, fieldFormatInfos);
}
Also used : TableSchema(org.apache.flink.table.api.TableSchema) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) DataType(org.apache.flink.table.types.DataType) LogicalType(org.apache.flink.table.types.logical.LogicalType) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) LocalZonedTimestampFormatInfo(org.apache.inlong.sort.formats.common.LocalZonedTimestampFormatInfo) DecimalFormatInfo(org.apache.inlong.sort.formats.common.DecimalFormatInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FloatFormatInfo(org.apache.inlong.sort.formats.common.FloatFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) TimeFormatInfo(org.apache.inlong.sort.formats.common.TimeFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) DateFormatInfo(org.apache.inlong.sort.formats.common.DateFormatInfo)

Example 28 with RowFormatInfo

use of org.apache.inlong.sort.formats.common.RowFormatInfo in project incubator-inlong by apache.

the class KvFormatFactory method createFormatSerializer.

@Override
public TableFormatSerializer createFormatSerializer(Map<String, String> properties) {
    final DescriptorProperties descriptorProperties = getValidatedProperties(properties);
    final RowFormatInfo rowFormatInfo = TableFormatUtils.getRowFormatInfo(descriptorProperties);
    final KvSerializationSchema serializationSchema = buildSerializationSchema(descriptorProperties, rowFormatInfo);
    boolean ignoreErrors = descriptorProperties.getOptionalBoolean(TableFormatConstants.FORMAT_IGNORE_ERRORS).orElse(TableFormatConstants.DEFAULT_IGNORE_ERRORS);
    return new DefaultTableFormatSerializer(serializationSchema, ignoreErrors);
}
Also used : DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) DefaultTableFormatSerializer(org.apache.inlong.sort.formats.base.DefaultTableFormatSerializer)

Example 29 with RowFormatInfo

use of org.apache.inlong.sort.formats.common.RowFormatInfo in project incubator-inlong by apache.

the class KvFormatFactory method createSerializationSchema.

@Override
public KvSerializationSchema createSerializationSchema(Map<String, String> properties) {
    final DescriptorProperties descriptorProperties = getValidatedProperties(properties);
    final RowFormatInfo rowFormatInfo = TableFormatUtils.getRowFormatInfo(descriptorProperties);
    return buildSerializationSchema(descriptorProperties, rowFormatInfo);
}
Also used : DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo)

Example 30 with RowFormatInfo

use of org.apache.inlong.sort.formats.common.RowFormatInfo in project incubator-inlong by apache.

the class KvFormatFactory method createProjectedSerializationSchema.

@Override
public SerializationSchema<Row> createProjectedSerializationSchema(Map<String, String> properties, int[] fields) {
    final DescriptorProperties descriptorProperties = getValidatedProperties(properties);
    final RowFormatInfo rowFormatInfo = TableFormatUtils.getRowFormatInfo(descriptorProperties);
    final RowFormatInfo projectedRowFormatInfo = TableFormatUtils.projectRowFormatInfo(rowFormatInfo, fields);
    return buildSerializationSchema(descriptorProperties, projectedRowFormatInfo);
}
Also used : DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo)

Aggregations

RowFormatInfo (org.apache.inlong.sort.formats.common.RowFormatInfo)34 DescriptorProperties (org.apache.flink.table.descriptors.DescriptorProperties)14 FormatInfo (org.apache.inlong.sort.formats.common.FormatInfo)14 BasicFormatInfo (org.apache.inlong.sort.formats.common.BasicFormatInfo)8 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)8 ArrayFormatInfo (org.apache.inlong.sort.formats.common.ArrayFormatInfo)6 IntFormatInfo (org.apache.inlong.sort.formats.common.IntFormatInfo)6 MapFormatInfo (org.apache.inlong.sort.formats.common.MapFormatInfo)6 ValidationException (org.apache.flink.table.api.ValidationException)5 BinaryFormatInfo (org.apache.inlong.sort.formats.common.BinaryFormatInfo)5 BooleanFormatInfo (org.apache.inlong.sort.formats.common.BooleanFormatInfo)5 ByteFormatInfo (org.apache.inlong.sort.formats.common.ByteFormatInfo)5 DateFormatInfo (org.apache.inlong.sort.formats.common.DateFormatInfo)5 DoubleFormatInfo (org.apache.inlong.sort.formats.common.DoubleFormatInfo)5 NullFormatInfo (org.apache.inlong.sort.formats.common.NullFormatInfo)5 ShortFormatInfo (org.apache.inlong.sort.formats.common.ShortFormatInfo)5 TimeFormatInfo (org.apache.inlong.sort.formats.common.TimeFormatInfo)5 TimestampFormatInfo (org.apache.inlong.sort.formats.common.TimestampFormatInfo)5 Row (org.apache.flink.types.Row)4 DecimalFormatInfo (org.apache.inlong.sort.formats.common.DecimalFormatInfo)4