use of org.apache.inlong.sort.formats.common.StringFormatInfo 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();
}
}
use of org.apache.inlong.sort.formats.common.StringFormatInfo in project incubator-inlong by apache.
the class MultiTenancyInLongMsgMixedDeserializerTest method testDeserialize.
@Test
public void testDeserialize() throws Exception {
final MultiTenancyInLongMsgMixedDeserializer deserializer = new MultiTenancyInLongMsgMixedDeserializer();
final FieldInfo stringField = new FieldInfo("not_important", new StringFormatInfo());
final FieldInfo longField = new FieldInfo("id", new LongFormatInfo());
final TubeSourceInfo tubeSourceInfo = new TubeSourceInfo("topic", "address", null, new InLongMsgCsvDeserializationInfo("tid", '|', false), new FieldInfo[] { stringField, longField });
final EmptySinkInfo sinkInfo = new EmptySinkInfo();
final DataFlowInfo dataFlowInfo = new DataFlowInfo(1L, tubeSourceInfo, sinkInfo);
deserializer.addDataFlow(dataFlowInfo);
final InLongMsg inLongMsg = InLongMsg.newInLongMsg();
final String attrs = "m=0&" + InLongMsgUtils.INLONGMSG_ATTR_STREAM_ID + "=tid&t=20210513";
final String body1 = "tianqiwan|29";
inLongMsg.addMsg(attrs, body1.getBytes());
final TestingCollector<Record> collector = new TestingCollector<>();
deserializer.deserialize(new InLongMsgMixedSerializedRecord("topic", 0, inLongMsg.buildArray()), collector);
assertEquals(1, collector.results.size());
assertEquals(1L, collector.results.get(0).getDataflowId());
assertEquals(4, collector.results.get(0).getRow().getArity());
final long time = new SimpleDateFormat("yyyyMMdd").parse("20210513").getTime();
assertEquals(new Timestamp(time), collector.results.get(0).getRow().getField(0));
final Map<String, String> attributes = new HashMap<>();
attributes.put("m", "0");
attributes.put(InLongMsgUtils.INLONGMSG_ATTR_STREAM_ID, "tid");
attributes.put("t", "20210513");
assertEquals(attributes, collector.results.get(0).getRow().getField(1));
assertEquals("tianqiwan", collector.results.get(0).getRow().getField(2));
assertEquals(29L, collector.results.get(0).getRow().getField(3));
}
Aggregations