Search in sources :

Example 6 with StringFormatInfo

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

the class CommonUtilsTest method testConvertFieldInfosToRowTypeInfo.

@Test
public void testConvertFieldInfosToRowTypeInfo() {
    org.apache.flink.api.java.typeutils.RowTypeInfo rowTypeInfoFlink = convertFieldInfosToRowTypeInfo(new FieldInfo[] { new FieldInfo("field1", new StringFormatInfo()), new FieldInfo("field2", new BooleanFormatInfo()) });
    assertArrayEquals(new String[] { "field1", "field2" }, rowTypeInfoFlink.getFieldNames());
    TypeInformation<?>[] fieldTypesFlink = rowTypeInfoFlink.getFieldTypes();
    assertEquals(Types.STRING, fieldTypesFlink[0]);
    assertEquals(Types.BOOLEAN, fieldTypesFlink[1]);
}
Also used : BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) Test(org.junit.Test)

Example 7 with StringFormatInfo

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

the class CommonUtilsTest method testBuildAvroRecordSchemaInJsonForRecursiveFields.

@Test
public void testBuildAvroRecordSchemaInJsonForRecursiveFields() throws IOException {
    FieldInfo[] testFieldInfos = new FieldInfo[] { new FieldInfo("f1", new ArrayFormatInfo(new MapFormatInfo(new StringFormatInfo(), new ArrayFormatInfo(new ArrayFormatInfo(new ShortFormatInfo()))))), new FieldInfo("f2", new MapFormatInfo(new StringFormatInfo(), new MapFormatInfo(new StringFormatInfo(), new RowFormatInfo(new String[] { "f21", "f22" }, new FormatInfo[] { new IntFormatInfo(), new ArrayFormatInfo(new ByteFormatInfo()) })))), new FieldInfo("f3", new RowFormatInfo(new String[] { "f31", "f32" }, new FormatInfo[] { new ArrayFormatInfo(new StringFormatInfo()), new RowFormatInfo(new String[] { "f321", "f322" }, new FormatInfo[] { new ArrayFormatInfo(new IntFormatInfo()), new MapFormatInfo(new StringFormatInfo(), new ArrayFormatInfo(new ByteFormatInfo())) }) })) };
    JsonNode expectedJsonNode = objectMapper.readTree("{\n" + "    \"type\":\"record\",\n" + "    \"name\":\"record\",\n" + "    \"fields\":[\n" + "        {\n" + "            \"name\":\"f1\",\n" + "            \"type\":[\n" + "                \"null\",\n" + "                {\n" + "                    \"type\":\"array\",\n" + "                    \"items\":[\n" + "                        \"null\",\n" + "                        {\n" + "                            \"type\":\"map\",\n" + "                            \"values\":[\n" + "                                \"null\",\n" + "                                {\n" + "                                    \"type\":\"array\",\n" + "                                    \"items\":[\n" + "                                        \"null\",\n" + "                                        {\n" + "                                            \"type\":\"array\",\n" + "                                            \"items\":[\n" + "                                                \"null\",\n" + "                                                \"int\"\n" + "                                            ]\n" + "                                        }\n" + "                                    ]\n" + "                                }\n" + "                            ]\n" + "                        }\n" + "                    ]\n" + "                }\n" + "            ],\n" + "            \"default\":null\n" + "        },\n" + "        {\n" + "            \"name\":\"f2\",\n" + "            \"type\":[\n" + "                \"null\",\n" + "                {\n" + "                    \"type\":\"map\",\n" + "                    \"values\":[\n" + "                        \"null\",\n" + "                        {\n" + "                            \"type\":\"map\",\n" + "                            \"values\":[\n" + "                                \"null\",\n" + "                                {\n" + "                                    \"type\":\"record\",\n" + "                                    \"name\":\"record_f2\",\n" + "                                    \"fields\":[\n" + "                                        {\n" + "                                            \"name\":\"f21\",\n" + "                                            \"type\":[\n" + "                                                \"null\",\n" + "                                                \"int\"\n" + "                                            ],\n" + "                                            \"default\":null\n" + "                                        },\n" + "                                        {\n" + "                                            \"name\":\"f22\",\n" + "                                            \"type\":[\n" + "                                                \"null\",\n" + "                                                {\n" + "                                                    \"type\":\"array\",\n" + "                                                    \"items\":[\n" + "                                                        \"null\",\n" + "                                                        \"int\"\n" + "                                                    ]\n" + "                                                }\n" + "                                            ],\n" + "                                            \"default\":null\n" + "                                        }\n" + "                                    ]\n" + "                                }\n" + "                            ]\n" + "                        }\n" + "                    ]\n" + "                }\n" + "            ],\n" + "            \"default\":null\n" + "        },\n" + "        {\n" + "            \"name\":\"f3\",\n" + "            \"type\":[\n" + "                \"null\",\n" + "                {\n" + "                    \"type\":\"record\",\n" + "                    \"name\":\"record_f3\",\n" + "                    \"fields\":[\n" + "                        {\n" + "                            \"name\":\"f31\",\n" + "                            \"type\":[\n" + "                                \"null\",\n" + "                                {\n" + "                                    \"type\":\"array\",\n" + "                                    \"items\":[\n" + "                                        \"null\",\n" + "                                        \"string\"\n" + "                                    ]\n" + "                                }\n" + "                            ],\n" + "                            \"default\":null\n" + "                        },\n" + "                        {\n" + "                            \"name\":\"f32\",\n" + "                            \"type\":[\n" + "                                \"null\",\n" + "                                {\n" + "                                    \"type\":\"record\",\n" + "                                    \"name\":\"record_f3_f32\",\n" + "                                    \"fields\":[\n" + "                                        {\n" + "                                            \"name\":\"f321\",\n" + "                                            \"type\":[\n" + "                                                \"null\",\n" + "                                                {\n" + "                                                    \"type\":\"array\",\n" + "                                                    \"items\":[\n" + "                                                        \"null\",\n" + "                                                        \"int\"\n" + "                                                    ]\n" + "                                                }\n" + "                                            ],\n" + "                                            \"default\":null\n" + "                                        },\n" + "                                        {\n" + "                                            \"name\":\"f322\",\n" + "                                            \"type\":[\n" + "                                                \"null\",\n" + "                                                {\n" + "                                                    \"type\":\"map\",\n" + "                                                    \"values\":[\n" + "                                                        \"null\",\n" + "                                                        {\n" + "                                                            \"type\":\"array\",\n" + "                                                            \"items\":[\n" + "                                                                \"null\",\n" + "                                                                \"int\"\n" + "                                                            ]\n" + "                                                        }\n" + "                                                    ]\n" + "                                                }\n" + "                                            ],\n" + "                                            \"default\":null\n" + "                                        }\n" + "                                    ]\n" + "                                }\n" + "                            ],\n" + "                            \"default\":null\n" + "                        }\n" + "                    ]\n" + "                }\n" + "            ],\n" + "            \"default\":null\n" + "        }\n" + "    ]\n" + "}");
    String actualJson = buildAvroRecordSchemaInJson(testFieldInfos);
    JsonNode actualJsonNode = objectMapper.readTree(actualJson);
    assertEquals(expectedJsonNode, actualJsonNode);
}
Also used : MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) ShortFormatInfo(org.apache.inlong.sort.formats.common.ShortFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) BooleanFormatInfo(org.apache.inlong.sort.formats.common.BooleanFormatInfo) ByteFormatInfo(org.apache.inlong.sort.formats.common.ByteFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) Test(org.junit.Test)

Example 8 with StringFormatInfo

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

the class FieldMappingTransformerTest method testTransform.

@Test
public void testTransform() {
    final FieldInfo[] fieldInfos = new FieldInfo[] { new BuiltInFieldInfo("dt", new TimestampFormatInfo(), BuiltInFieldInfo.BuiltInField.DATA_TIME), new FieldInfo("f1", IntFormatInfo.INSTANCE), new FieldInfo("f2", StringFormatInfo.INSTANCE), new FieldInfo("f3", IntFormatInfo.INSTANCE), new FieldInfo("f4", ShortFormatInfo.INSTANCE), new FieldInfo("f5", LongFormatInfo.INSTANCE), new BuiltInFieldInfo("event_type", new StringFormatInfo(), BuiltInField.MYSQL_METADATA_EVENT_TYPE) };
    final long ms = 10000000000L;
    final Configuration configuration = new Configuration();
    configuration.setBoolean(SINK_FIELD_TYPE_INT_NULLABLE, false);
    configuration.setBoolean(SINK_FIELD_TYPE_SHORT_NULLABLE, false);
    configuration.setBoolean(SINK_FIELD_TYPE_LONG_NULLABLE, false);
    FieldMappingTransformer transformer = new FieldMappingTransformer(configuration, fieldInfos);
    Row resultRow = transformer.transform(Row.of(new HashMap<>(), 1), ms);
    assertEquals(7, resultRow.getArity());
    assertEquals(new Timestamp(ms), resultRow.getField(0));
    assertEquals(1, resultRow.getField(1));
    assertEquals("", resultRow.getField(2));
    assertEquals(0, resultRow.getField(3));
    assertEquals(0, resultRow.getField(4));
    assertEquals(0L, resultRow.getField(5));
    assertEquals("+I", resultRow.getField(6));
}
Also used : Configuration(org.apache.inlong.sort.configuration.Configuration) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) HashMap(java.util.HashMap) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) Row(org.apache.flink.types.Row) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) Timestamp(java.sql.Timestamp) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) Test(org.junit.Test)

Example 9 with StringFormatInfo

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

the class RowToAvroKafkaSinkTest method prepareData.

@Override
protected void prepareData() throws IOException, ClassNotFoundException {
    fieldInfos = new FieldInfo[] { new FieldInfo("f1", new StringFormatInfo()), new FieldInfo("f2", new IntFormatInfo()), new FieldInfo("f3", new NullFormatInfo()), new FieldInfo("f4", new BinaryFormatInfo()), new FieldInfo("f5", new MapFormatInfo(new StringFormatInfo(), new RowFormatInfo(new String[] { "f51", "f52" }, new FormatInfo[] { new IntFormatInfo(), new ArrayFormatInfo(new DoubleFormatInfo()) }))) };
    topic = "test_kafka_row_to_avro";
    serializationSchema = SerializationSchemaFactory.build(fieldInfos, new AvroSerializationInfo());
    prepareTestRows();
}
Also used : NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) AvroSerializationInfo(org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo)

Example 10 with StringFormatInfo

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

the class RowToCanalKafkaSinkTest method prepareData.

@Override
protected void prepareData() throws IOException, ClassNotFoundException {
    topic = "test_kafka_row_to_canal";
    fieldInfos = new FieldInfo[] { new FieldInfo("f1", new StringFormatInfo()), new FieldInfo("f2", new IntFormatInfo()) };
    serializationSchema = SerializationSchemaFactory.build(fieldInfos, new CanalSerializationInfo());
    prepareTestData();
}
Also used : IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) CanalSerializationInfo(org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Aggregations

StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)17 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)16 Test (org.junit.Test)10 IntFormatInfo (org.apache.inlong.sort.formats.common.IntFormatInfo)7 LongFormatInfo (org.apache.inlong.sort.formats.common.LongFormatInfo)7 Row (org.apache.flink.types.Row)6 Record (org.apache.inlong.sort.flink.Record)6 DataFlowInfo (org.apache.inlong.sort.protocol.DataFlowInfo)6 BuiltInFieldInfo (org.apache.inlong.sort.protocol.BuiltInFieldInfo)5 TestingSinkInfo (org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo)5 SerializedRecord (org.apache.inlong.sort.flink.SerializedRecord)4 ArrayFormatInfo (org.apache.inlong.sort.formats.common.ArrayFormatInfo)4 DoubleFormatInfo (org.apache.inlong.sort.formats.common.DoubleFormatInfo)4 MapFormatInfo (org.apache.inlong.sort.formats.common.MapFormatInfo)4 EmptySourceInfo (org.apache.inlong.sort.util.TestingUtils.EmptySourceInfo)4 ByteFormatInfo (org.apache.inlong.sort.formats.common.ByteFormatInfo)3 FormatInfo (org.apache.inlong.sort.formats.common.FormatInfo)3 RowFormatInfo (org.apache.inlong.sort.formats.common.RowFormatInfo)3 Timestamp (java.sql.Timestamp)2 HashMap (java.util.HashMap)2