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]);
}
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);
}
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));
}
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();
}
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();
}
Aggregations