use of org.apache.flink.table.descriptors.OldCsvValidator.FORMAT_FIELD_DELIMITER in project flink by apache.
the class CsvTableSinkFactoryBase method createTableSink.
protected CsvTableSink createTableSink(Boolean isStreaming, Map<String, String> properties) {
DescriptorProperties params = new DescriptorProperties();
params.putProperties(properties);
// validate
new FileSystemValidator().validate(params);
new OldCsvValidator().validate(params);
new SchemaValidator(isStreaming, false, false).validate(params);
// build
TableSchema tableSchema = TableSchemaUtils.getPhysicalSchema(params.getTableSchema(SCHEMA));
// if a schema is defined, no matter derive schema is set or not, will use the defined
// schema
final boolean hasSchema = params.hasPrefix(FORMAT_FIELDS);
if (hasSchema) {
TableSchema formatSchema = params.getTableSchema(FORMAT_FIELDS);
if (!getFieldLogicalTypes(formatSchema).equals(getFieldLogicalTypes(tableSchema))) {
throw new TableException(String.format("Encodings that differ from the schema are not supported yet for" + " CsvTableSink, format schema is '%s', but table schema is '%s'.", formatSchema, tableSchema));
}
}
String path = params.getString(CONNECTOR_PATH);
String fieldDelimiter = params.getOptionalString(FORMAT_FIELD_DELIMITER).orElse(",");
Optional<String> writeModeParam = params.getOptionalString(FORMAT_WRITE_MODE);
FileSystem.WriteMode writeMode = (writeModeParam.isPresent()) ? FileSystem.WriteMode.valueOf(writeModeParam.get()) : null;
int numFiles = params.getOptionalInt(FORMAT_NUM_FILES).orElse(-1);
// bridge to java.sql.Timestamp/Time/Date
DataType[] dataTypes = Arrays.stream(tableSchema.getFieldDataTypes()).map(dt -> {
switch(dt.getLogicalType().getTypeRoot()) {
case TIMESTAMP_WITHOUT_TIME_ZONE:
return dt.bridgedTo(Timestamp.class);
case TIME_WITHOUT_TIME_ZONE:
return dt.bridgedTo(Time.class);
case DATE:
return dt.bridgedTo(Date.class);
default:
return dt;
}
}).toArray(DataType[]::new);
return new CsvTableSink(path, fieldDelimiter, numFiles, writeMode, tableSchema.getFieldNames(), dataTypes);
}
Aggregations