Search in sources :

Example 31 with RowFormatInfo

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

the class KvFormatFactory 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 32 with RowFormatInfo

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

the class KvFormatFactory method buildDeserializationSchema.

private static KvDeserializationSchema buildDeserializationSchema(DescriptorProperties descriptorProperties, RowFormatInfo rowFormatInfo) {
    for (FormatInfo formatInfo : rowFormatInfo.getFieldFormatInfos()) {
        if (!(formatInfo instanceof BasicFormatInfo)) {
            throw new ValidationException("Currently only basic formats " + "are supported in kv formats.");
        }
    }
    KvDeserializationSchema.Builder builder = new KvDeserializationSchema.Builder(rowFormatInfo);
    descriptorProperties.getOptionalString(TableFormatConstants.FORMAT_CHARSET).ifPresent(builder::setCharset);
    descriptorProperties.getOptionalCharacter(TableFormatConstants.FORMAT_ENTRY_DELIMITER).ifPresent(builder::setEntryDelimiter);
    descriptorProperties.getOptionalCharacter(TableFormatConstants.FORMAT_KV_DELIMITER).ifPresent(builder::setKvDelimiter);
    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 33 with RowFormatInfo

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

the class CsvSerializationSchemaTest method testBasicSerialization.

private static <T> void testBasicSerialization(Consumer<CsvSerializationSchema.Builder> config, BasicFormatInfo<T> basicFormatInfo, T record, String expectedText) {
    RowFormatInfo rowFormatInfo = new RowFormatInfo(new String[] { "f" }, new FormatInfo[] { basicFormatInfo });
    CsvSerializationSchema.Builder builder = new CsvSerializationSchema.Builder(rowFormatInfo);
    config.accept(builder);
    CsvSerializationSchema 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 34 with RowFormatInfo

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

the class MultiTopicPulsarSourceFunctionTest method producerMessageToPulsar.

protected void producerMessageToPulsar(String pulsarBrokerUrl) throws Exception {
    RowSerializer rowSerializer = CommonUtils.generateRowSerializer(new RowFormatInfo(new String[] { "f1", "f2" }, new FormatInfo[] { StringFormatInfo.INSTANCE, StringFormatInfo.INSTANCE }));
    DataOutputSerializer dataOutputSerializer = new DataOutputSerializer(1024);
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsarBrokerUrl).build();
        Producer<byte[]> producer = client.newProducer().topic(TEST_TOPIC).create()) {
        for (int cnt = 0; cnt < TOTAL_COUNT; cnt++) {
            Row row = Row.of(String.valueOf(cnt), String.valueOf(cnt));
            rowSerializer.serialize(row, dataOutputSerializer);
            ByteArrayOutputStream byt = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(byt);
            objectOutputStream.writeObject(new SerializedRecord(1L, 0, dataOutputSerializer.getCopyOfBuffer()));
            producer.send(byt.toByteArray());
        }
    }
}
Also used : SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) RowSerializer(org.apache.flink.api.java.typeutils.runtime.RowSerializer) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) PulsarClient(org.apache.pulsar.client.api.PulsarClient) Row(org.apache.flink.types.Row) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) ObjectOutputStream(java.io.ObjectOutputStream)

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