use of org.apache.inlong.sort.formats.common.FormatInfo in project incubator-inlong by apache.
the class DorisRowConverter method setRow.
public static void setRow(FormatInfo[] formatInfos, String[] fieldNames, Row row, Map<String, Object> rowDataMap) {
for (int i = 0; i < row.getArity(); ++i) {
final FormatInfo formatInfo = formatInfos[i];
final String fieldName = fieldNames[i];
rowDataMap.put(fieldName, row.getField(i));
}
}
use of org.apache.inlong.sort.formats.common.FormatInfo in project incubator-inlong by apache.
the class TableFormatUtils method deriveFormatInfo.
/**
* Derive the format information for the given type.
*
* @param logicalType The type whose format is derived.
* @return The format information for the given type.
*/
public static FormatInfo deriveFormatInfo(LogicalType logicalType) {
if (logicalType instanceof VarCharType) {
return StringFormatInfo.INSTANCE;
} else if (logicalType instanceof BooleanType) {
return BooleanFormatInfo.INSTANCE;
} else if (logicalType instanceof TinyIntType) {
return ByteFormatInfo.INSTANCE;
} else if (logicalType instanceof SmallIntType) {
return ShortFormatInfo.INSTANCE;
} else if (logicalType instanceof IntType) {
return IntFormatInfo.INSTANCE;
} else if (logicalType instanceof BigIntType) {
return LongFormatInfo.INSTANCE;
} else if (logicalType instanceof FloatType) {
return FloatFormatInfo.INSTANCE;
} else if (logicalType instanceof DoubleType) {
return DoubleFormatInfo.INSTANCE;
} else if (logicalType instanceof DecimalType) {
return DecimalFormatInfo.INSTANCE;
} else if (logicalType instanceof DateType) {
return new DateFormatInfo();
} else if (logicalType instanceof TimeType) {
return new TimeFormatInfo();
} else if (logicalType instanceof TimestampType) {
return new TimestampFormatInfo();
} else if (logicalType instanceof LocalZonedTimestampType) {
return new LocalZonedTimestampFormatInfo();
} else if (logicalType instanceof ArrayType) {
ArrayType arrayType = (ArrayType) logicalType;
LogicalType elementType = arrayType.getElementType();
FormatInfo elementFormatInfo = deriveFormatInfo(elementType);
return new ArrayFormatInfo(elementFormatInfo);
} else if (logicalType instanceof MapType) {
MapType mapType = (MapType) logicalType;
LogicalType keyType = mapType.getKeyType();
LogicalType valueType = mapType.getValueType();
FormatInfo keyFormatInfo = deriveFormatInfo(keyType);
FormatInfo valueFormatInfo = deriveFormatInfo(valueType);
return new MapFormatInfo(keyFormatInfo, valueFormatInfo);
} else if (logicalType instanceof RowType) {
RowType rowType = (RowType) logicalType;
List<RowType.RowField> rowFields = rowType.getFields();
String[] fieldNames = new String[rowFields.size()];
FormatInfo[] fieldFormatInfos = new FormatInfo[rowFields.size()];
for (int i = 0; i < rowFields.size(); ++i) {
RowType.RowField rowField = rowFields.get(i);
fieldNames[i] = rowField.getName();
fieldFormatInfos[i] = deriveFormatInfo(rowField.getType());
}
return new RowFormatInfo(fieldNames, fieldFormatInfos);
} else if (logicalType instanceof BinaryType) {
return BinaryFormatInfo.INSTANCE;
} else if (logicalType instanceof NullType) {
return NullFormatInfo.INSTANCE;
} else {
throw new UnsupportedOperationException();
}
}
use of org.apache.inlong.sort.formats.common.FormatInfo in project incubator-inlong by apache.
the class TableFormatUtils method deserializeRowFormatInfo.
/**
* Returns the format defined in the given property.
*
* @param descriptorProperties The properties of the descriptor.
* @return The basic row format defined in the descriptor.
*/
public static RowFormatInfo deserializeRowFormatInfo(DescriptorProperties descriptorProperties) {
try {
String schema = descriptorProperties.getString(FORMAT_SCHEMA);
FormatInfo formatInfo = FormatUtils.demarshall(schema);
if (!(formatInfo instanceof RowFormatInfo)) {
throw new IllegalStateException("Unexpected format type.");
}
return (RowFormatInfo) formatInfo;
} catch (Exception e) {
throw new ValidationException("The schema is invalid.", e);
}
}
use of org.apache.inlong.sort.formats.common.FormatInfo in project incubator-inlong by apache.
the class CommonUtils method convertFieldInfosToLogicalType.
public static LogicalType convertFieldInfosToLogicalType(FieldInfo[] fieldInfos) {
int fieldLength = fieldInfos.length;
String[] fieldNames = new String[fieldLength];
FormatInfo[] fieldFormatInfos = new FormatInfo[fieldLength];
for (int i = 0; i < fieldLength; i++) {
fieldNames[i] = fieldInfos[i].getName();
fieldFormatInfos[i] = fieldInfos[i].getFormatInfo();
}
RowFormatInfo rowFormatInfo = new RowFormatInfo(fieldNames, fieldFormatInfos);
return deriveLogicalType(rowFormatInfo);
}
use of org.apache.inlong.sort.formats.common.FormatInfo in project incubator-inlong by apache.
the class CsvFormatFactory method buildSerializationSchema.
private static CsvSerializationSchema buildSerializationSchema(DescriptorProperties descriptorProperties, RowFormatInfo rowFormatInfo) {
for (FormatInfo formatInfo : rowFormatInfo.getFieldFormatInfos()) {
if (!(formatInfo instanceof BasicFormatInfo)) {
throw new ValidationException("Currently only basic formats " + "are supported in csv formats.");
}
}
CsvSerializationSchema.Builder builder = new CsvSerializationSchema.Builder(rowFormatInfo);
descriptorProperties.getOptionalString(TableFormatConstants.FORMAT_CHARSET).ifPresent(builder::setCharset);
descriptorProperties.getOptionalCharacter(TableFormatConstants.FORMAT_DELIMITER).ifPresent(builder::setDelimiter);
descriptorProperties.getOptionalCharacter(TableFormatConstants.FORMAT_ESCAPE_CHARACTER).ifPresent(builder::setEscapeCharacter);
descriptorProperties.getOptionalCharacter(TableFormatConstants.FORMAT_QUOTE_CHARACTER).ifPresent(builder::setQuoteCharacter);
descriptorProperties.getOptionalString(TableFormatConstants.FORMAT_NULL_LITERAL).ifPresent(builder::setNullLiteral);
return builder.build();
}
Aggregations