use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class CsvTableSinkFactoryTest method testAppendTableSinkFactory.
@Test
public void testAppendTableSinkFactory() {
DescriptorProperties descriptor = createDescriptor(testingSchema);
descriptor.putString("update-mode", "append");
TableSink sink = createTableSink(descriptor);
assertTrue(sink instanceof CsvTableSink);
assertEquals(testingSchema.toRowDataType(), sink.getConsumedDataType());
}
use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class CsvTableSinkFactoryTest method testBatchTableSinkFactory.
@Test
public void testBatchTableSinkFactory() {
DescriptorProperties descriptor = createDescriptor(testingSchema);
TableSink sink = createTableSink(descriptor);
assertTrue(sink instanceof CsvTableSink);
assertEquals(testingSchema.toRowDataType(), sink.getConsumedDataType());
}
use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class TableFormatFactoryBase method deriveSchema.
// --------------------------------------------------------------------------------------------
/**
* Finds the table schema that can be used for a format schema (without time attributes and
* generated columns).
*/
public static TableSchema deriveSchema(Map<String, String> properties) {
final DescriptorProperties descriptorProperties = new DescriptorProperties();
descriptorProperties.putProperties(properties);
final TableSchema.Builder builder = TableSchema.builder();
final TableSchema tableSchema = descriptorProperties.getTableSchema(SCHEMA);
for (int i = 0; i < tableSchema.getFieldCount(); i++) {
final TableColumn tableColumn = tableSchema.getTableColumns().get(i);
final String fieldName = tableColumn.getName();
final DataType dataType = tableColumn.getType();
if (!tableColumn.isPhysical()) {
// skip non-physical columns
continue;
}
final boolean isProctime = descriptorProperties.getOptionalBoolean(SCHEMA + '.' + i + '.' + SCHEMA_PROCTIME).orElse(false);
final String timestampKey = SCHEMA + '.' + i + '.' + ROWTIME_TIMESTAMPS_TYPE;
final boolean isRowtime = descriptorProperties.containsKey(timestampKey);
if (!isProctime && !isRowtime) {
// check for aliasing
final String aliasName = descriptorProperties.getOptionalString(SCHEMA + '.' + i + '.' + SCHEMA_FROM).orElse(fieldName);
builder.field(aliasName, dataType);
} else // only use the rowtime attribute if it references a field
if (isRowtime && descriptorProperties.isValue(timestampKey, ROWTIME_TIMESTAMPS_TYPE_VALUE_FROM_FIELD)) {
final String aliasName = descriptorProperties.getString(SCHEMA + '.' + i + '.' + ROWTIME_TIMESTAMPS_FROM);
builder.field(aliasName, dataType);
}
}
return builder.build();
}
use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class FileSystemTableFactoryTest method testUnsupportedOptionSink.
@Test
public void testUnsupportedOptionSink() {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "filesystem");
descriptor.putString("path", "/tmp");
descriptor.putString("format", "csv");
descriptor.putString("my_option", "my");
try {
createTableSink(SCHEMA, descriptor.asMap());
} catch (ValidationException e) {
Throwable cause = e.getCause();
assertTrue(cause.toString(), cause instanceof ValidationException);
assertTrue(cause.getMessage(), cause.getMessage().contains("Unsupported options:\n\nmy_option"));
return;
}
fail("Should fail by ValidationException.");
}
use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.
the class FileSystemTableFactoryTest method testUnsupportedOptionSource.
@Test
public void testUnsupportedOptionSource() {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "filesystem");
descriptor.putString("path", "/tmp");
descriptor.putString("format", "csv");
descriptor.putString("my_option", "my");
try {
createTableSource(SCHEMA, descriptor.asMap());
} catch (ValidationException e) {
Throwable cause = e.getCause();
assertTrue(cause.toString(), cause instanceof ValidationException);
assertTrue(cause.getMessage(), cause.getMessage().contains("Unsupported options:\n\nmy_option"));
return;
}
fail("Should fail by ValidationException.");
}
Aggregations