use of org.apache.inlong.sort.formats.common.ByteFormatInfo 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.ByteFormatInfo in project incubator-inlong by apache.
the class CommonUtilsTest method testBuildAvroRecordSchemaInJsonForNormalFields.
@Test
public void testBuildAvroRecordSchemaInJsonForNormalFields() throws IOException {
FieldInfo[] testFieldInfos = new FieldInfo[] { new FieldInfo("f1", new StringFormatInfo()), new FieldInfo("f2", new ByteFormatInfo()) };
JsonNode expectedJsonNode = objectMapper.readTree("{\n" + " \"type\":\"record\",\n" + " \"name\":\"record\",\n" + " \"fields\":[\n" + " {\n" + " \"name\":\"f1\",\n" + " \"type\":[\n" + " \"null\",\n" + " \"string\"\n" + " ],\n" + " \"default\":null\n" + " },\n" + " {\n" + " \"name\":\"f2\",\n" + " \"type\":[\n" + " \"null\",\n" + " \"int\"\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.ByteFormatInfo in project incubator-inlong by apache.
the class TableFormatUtils method deriveLogicalType.
/**
* Derive the LogicalType for the given FormatInfo.
*/
public static LogicalType deriveLogicalType(FormatInfo formatInfo) {
if (formatInfo instanceof StringFormatInfo) {
return new VarCharType();
} else if (formatInfo instanceof BooleanFormatInfo) {
return new BooleanType();
} else if (formatInfo instanceof ByteFormatInfo) {
return new TinyIntType();
} else if (formatInfo instanceof ShortFormatInfo) {
return new SmallIntType();
} else if (formatInfo instanceof IntFormatInfo) {
return new IntType();
} else if (formatInfo instanceof LongFormatInfo) {
return new BigIntType();
} else if (formatInfo instanceof FloatFormatInfo) {
return new FloatType();
} else if (formatInfo instanceof DoubleFormatInfo) {
return new DoubleType();
} else if (formatInfo instanceof DecimalFormatInfo) {
return new DecimalType();
} else if (formatInfo instanceof TimeFormatInfo) {
return new TimeType();
} else if (formatInfo instanceof DateFormatInfo) {
return new DateType();
} else if (formatInfo instanceof TimestampFormatInfo) {
return new TimestampType(DEFAULT_PRECISION_FOR_TIMESTAMP);
} else if (formatInfo instanceof LocalZonedTimestampFormatInfo) {
return new LocalZonedTimestampType();
} else if (formatInfo instanceof ArrayFormatInfo) {
FormatInfo elementFormatInfo = ((ArrayFormatInfo) formatInfo).getElementFormatInfo();
return new ArrayType(deriveLogicalType(elementFormatInfo));
} else if (formatInfo instanceof MapFormatInfo) {
MapFormatInfo mapFormatInfo = (MapFormatInfo) formatInfo;
FormatInfo keyFormatInfo = mapFormatInfo.getKeyFormatInfo();
FormatInfo valueFormatInfo = mapFormatInfo.getValueFormatInfo();
return new MapType(deriveLogicalType(keyFormatInfo), deriveLogicalType(valueFormatInfo));
} else if (formatInfo instanceof RowFormatInfo) {
RowFormatInfo rowFormatInfo = (RowFormatInfo) formatInfo;
FormatInfo[] formatInfos = rowFormatInfo.getFieldFormatInfos();
int formatInfosSize = formatInfos.length;
LogicalType[] logicalTypes = new LogicalType[formatInfosSize];
for (int i = 0; i < formatInfosSize; ++i) {
logicalTypes[i] = deriveLogicalType(formatInfos[i]);
}
return RowType.of(logicalTypes, rowFormatInfo.getFieldNames());
} else if (formatInfo instanceof BinaryFormatInfo) {
return new BinaryType();
} else if (formatInfo instanceof NullFormatInfo) {
return new NullType();
} else {
throw new UnsupportedOperationException();
}
}
Aggregations