use of org.apache.inlong.sort.formats.common.RowFormatInfo 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.RowFormatInfo in project incubator-inlong by apache.
the class TableFormatUtils method deriveRowFormatInfo.
/**
* Derives the format from the given schema.
*
* @param descriptorProperties The properties of the descriptor.
* @return The format derived from the schema in the descriptor.
*/
public static RowFormatInfo deriveRowFormatInfo(DescriptorProperties descriptorProperties) {
TableSchema tableSchema = deriveSchema(descriptorProperties.asMap());
int numFields = tableSchema.getFieldCount();
String[] fieldNames = tableSchema.getFieldNames();
DataType[] fieldTypes = tableSchema.getFieldDataTypes();
FormatInfo[] fieldFormatInfos = new FormatInfo[numFields];
for (int i = 0; i < numFields; ++i) {
LogicalType fieldType = fieldTypes[i].getLogicalType();
fieldFormatInfos[i] = deriveFormatInfo(fieldType);
}
return new RowFormatInfo(fieldNames, fieldFormatInfos);
}
use of org.apache.inlong.sort.formats.common.RowFormatInfo in project incubator-inlong by apache.
the class KvFormatFactory method createFormatSerializer.
@Override
public TableFormatSerializer createFormatSerializer(Map<String, String> properties) {
final DescriptorProperties descriptorProperties = getValidatedProperties(properties);
final RowFormatInfo rowFormatInfo = TableFormatUtils.getRowFormatInfo(descriptorProperties);
final KvSerializationSchema serializationSchema = buildSerializationSchema(descriptorProperties, rowFormatInfo);
boolean ignoreErrors = descriptorProperties.getOptionalBoolean(TableFormatConstants.FORMAT_IGNORE_ERRORS).orElse(TableFormatConstants.DEFAULT_IGNORE_ERRORS);
return new DefaultTableFormatSerializer(serializationSchema, ignoreErrors);
}
use of org.apache.inlong.sort.formats.common.RowFormatInfo in project incubator-inlong by apache.
the class KvFormatFactory method createSerializationSchema.
@Override
public KvSerializationSchema createSerializationSchema(Map<String, String> properties) {
final DescriptorProperties descriptorProperties = getValidatedProperties(properties);
final RowFormatInfo rowFormatInfo = TableFormatUtils.getRowFormatInfo(descriptorProperties);
return buildSerializationSchema(descriptorProperties, rowFormatInfo);
}
use of org.apache.inlong.sort.formats.common.RowFormatInfo in project incubator-inlong by apache.
the class KvFormatFactory method createProjectedSerializationSchema.
@Override
public SerializationSchema<Row> createProjectedSerializationSchema(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 buildSerializationSchema(descriptorProperties, projectedRowFormatInfo);
}
Aggregations