Search in sources :

Example 21 with RowFormatInfo

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

the class CsvFormatFactory method createProjectedDeserializationSchema.

@Override
public DeserializationSchema<Row> createProjectedDeserializationSchema(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 buildDeserializationSchema(descriptorProperties, projectedRowFormatInfo);
}
Also used : DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo)

Example 22 with RowFormatInfo

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

the class CsvFormatFactory method createSerializationSchema.

@Override
public CsvSerializationSchema 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 23 with RowFormatInfo

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

the class CsvFormatFactory method buildDeserializationSchema.

private static CsvDeserializationSchema buildDeserializationSchema(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.");
        }
    }
    CsvDeserializationSchema.Builder builder = new CsvDeserializationSchema.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 24 with RowFormatInfo

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

the class CsvFormatFactory 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)

Example 25 with RowFormatInfo

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

the class CsvDeserializationSchemaTest method testBasicDeserialization.

private static <T> void testBasicDeserialization(Consumer<CsvDeserializationSchema.Builder> config, BasicFormatInfo<T> basicFormatInfo, T expectedRecord, String text) throws IOException {
    RowFormatInfo rowFormatInfo = new RowFormatInfo(new String[] { "f" }, new FormatInfo[] { basicFormatInfo });
    CsvDeserializationSchema.Builder builder = new CsvDeserializationSchema.Builder(rowFormatInfo);
    config.accept(builder);
    CsvDeserializationSchema deserializer = builder.build();
    Row row = deserializer.deserialize(text.getBytes());
    assertEquals(1, row.getArity());
    assertEquals(expectedRecord, row.getField(0));
}
Also used : RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) Row(org.apache.flink.types.Row)

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