Search in sources :

Example 6 with RowFormatInfo

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

the class CsvFormatFactory method buildSerializationSchema.

private static CsvSerializationSchema buildSerializationSchema(DescriptorProperties descriptorProperties, RowFormatInfo rowFormatInfo) {
    for (FormatInfo formatInfo : rowFormatInfo.getFieldFormatInfos()) {
        if (!(formatInfo instanceof BasicFormatInfo)) {
            throw new ValidationException("Currently only basic formats " + "are supported in csv formats.");
        }
    }
    CsvSerializationSchema.Builder builder = new CsvSerializationSchema.Builder(rowFormatInfo);
    descriptorProperties.getOptionalString(TableFormatConstants.FORMAT_CHARSET).ifPresent(builder::setCharset);
    descriptorProperties.getOptionalCharacter(TableFormatConstants.FORMAT_DELIMITER).ifPresent(builder::setDelimiter);
    descriptorProperties.getOptionalCharacter(TableFormatConstants.FORMAT_ESCAPE_CHARACTER).ifPresent(builder::setEscapeCharacter);
    descriptorProperties.getOptionalCharacter(TableFormatConstants.FORMAT_QUOTE_CHARACTER).ifPresent(builder::setQuoteCharacter);
    descriptorProperties.getOptionalString(TableFormatConstants.FORMAT_NULL_LITERAL).ifPresent(builder::setNullLiteral);
    return builder.build();
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) BasicFormatInfo(org.apache.inlong.sort.formats.common.BasicFormatInfo)

Example 7 with RowFormatInfo

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

the class CsvFormatFactory method createDeserializationSchema.

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

Example 8 with RowFormatInfo

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

the class CsvFormatFactory method createFormatDeserializer.

@Override
public TableFormatDeserializer createFormatDeserializer(Map<String, String> properties) {
    final DescriptorProperties descriptorProperties = getValidatedProperties(properties);
    final RowFormatInfo rowFormatInfo = TableFormatUtils.getRowFormatInfo(descriptorProperties);
    final CsvDeserializationSchema deserializationSchema = buildDeserializationSchema(descriptorProperties, rowFormatInfo);
    boolean ignoreErrors = descriptorProperties.getOptionalBoolean(TableFormatConstants.FORMAT_IGNORE_ERRORS).orElse(TableFormatConstants.DEFAULT_IGNORE_ERRORS);
    return new DefaultTableFormatDeserializer(deserializationSchema, ignoreErrors);
}
Also used : DefaultTableFormatDeserializer(org.apache.inlong.sort.formats.base.DefaultTableFormatDeserializer) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo)

Example 9 with RowFormatInfo

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

the class KvSerializationSchemaTest method testBasicSerialization.

private static <T> void testBasicSerialization(Consumer<KvSerializationSchema.Builder> config, BasicFormatInfo<T> basicFormatInfo, T record, String expectedText) {
    RowFormatInfo rowFormatInfo = new RowFormatInfo(new String[] { "f" }, new FormatInfo[] { basicFormatInfo });
    KvSerializationSchema.Builder builder = new KvSerializationSchema.Builder(rowFormatInfo);
    config.accept(builder);
    KvSerializationSchema serializer = builder.build();
    String text = new String(serializer.serialize(Row.of(record)));
    assertEquals(expectedText, text);
}
Also used : RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo)

Example 10 with RowFormatInfo

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

the class InLongMsgCsvFormatFactory method createFormatDeserializer.

@Override
public TableFormatDeserializer createFormatDeserializer(Map<String, String> properties) {
    final DescriptorProperties descriptorProperties = new DescriptorProperties(true);
    descriptorProperties.putProperties(properties);
    final InLongMsgValidator validator = new InLongMsgValidator();
    validator.validate(descriptorProperties);
    RowFormatInfo rowFormatInfo = getDataFormatInfo(descriptorProperties);
    String timeFieldName = descriptorProperties.getOptionalString(FORMAT_TIME_FIELD_NAME).orElse(InLongMsgUtils.DEFAULT_TIME_FIELD_NAME);
    String attributesFieldName = descriptorProperties.getOptionalString(FORMAT_ATTRIBUTES_FIELD_NAME).orElse(InLongMsgUtils.DEFAULT_ATTRIBUTES_FIELD_NAME);
    validateFieldNames(timeFieldName, attributesFieldName, rowFormatInfo);
    String charset = descriptorProperties.getOptionalString(FORMAT_CHARSET).orElse(DEFAULT_CHARSET);
    Character delimiter = descriptorProperties.getOptionalCharacter(FORMAT_DELIMITER).orElse(DEFAULT_DELIMITER);
    Character escapeCharacter = descriptorProperties.getOptionalCharacter(FORMAT_ESCAPE_CHARACTER).orElse(null);
    Character quoteCharacter = descriptorProperties.getOptionalCharacter(FORMAT_QUOTE_CHARACTER).orElse(null);
    String nullLiteral = descriptorProperties.getOptionalString(FORMAT_NULL_LITERAL).orElse(null);
    Boolean deleteHeadDelimiter = descriptorProperties.getOptionalBoolean(FORMAT_DELETE_HEAD_DELIMITER).orElse(InLongMsgCsvUtils.DEFAULT_DELETE_HEAD_DELIMITER);
    boolean ignoreErrors = descriptorProperties.getOptionalBoolean(FORMAT_IGNORE_ERRORS).orElse(DEFAULT_IGNORE_ERRORS);
    return new InLongMsgCsvFormatDeserializer(rowFormatInfo, timeFieldName, attributesFieldName, charset, delimiter, escapeCharacter, quoteCharacter, nullLiteral, deleteHeadDelimiter, ignoreErrors);
}
Also used : DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) InLongMsgValidator(org.apache.inlong.sort.formats.inlongmsg.InLongMsgValidator)

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