Search in sources :

Example 11 with DescriptorProperties

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());
}
Also used : CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) TableSink(org.apache.flink.table.sinks.TableSink) CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) Test(org.junit.Test)

Example 12 with DescriptorProperties

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());
}
Also used : CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) TableSink(org.apache.flink.table.sinks.TableSink) CsvTableSink(org.apache.flink.table.sinks.CsvTableSink) Test(org.junit.Test)

Example 13 with DescriptorProperties

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();
}
Also used : TableSchema(org.apache.flink.table.api.TableSchema) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) DataType(org.apache.flink.table.types.DataType) TableColumn(org.apache.flink.table.api.TableColumn)

Example 14 with DescriptorProperties

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.");
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) Test(org.junit.Test)

Example 15 with DescriptorProperties

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.");
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) Test(org.junit.Test)

Aggregations

DescriptorProperties (org.apache.flink.table.descriptors.DescriptorProperties)32 Test (org.junit.Test)22 ValidationException (org.apache.flink.table.api.ValidationException)13 DataGeneratorSourceTest (org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSourceTest)9 HashMap (java.util.HashMap)6 TableSchema (org.apache.flink.table.api.TableSchema)6 GenericRowData (org.apache.flink.table.data.GenericRowData)3 RowData (org.apache.flink.table.data.RowData)3 ArrayList (java.util.ArrayList)2 TableException (org.apache.flink.table.api.TableException)2 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)2 FileSystemValidator (org.apache.flink.table.descriptors.FileSystemValidator)2 OldCsvValidator (org.apache.flink.table.descriptors.OldCsvValidator)2 SchemaValidator (org.apache.flink.table.descriptors.SchemaValidator)2 CsvTableSink (org.apache.flink.table.sinks.CsvTableSink)2 TableSink (org.apache.flink.table.sinks.TableSink)2 CsvTableSource (org.apache.flink.table.sources.CsvTableSource)2 TableSource (org.apache.flink.table.sources.TableSource)2 DataType (org.apache.flink.table.types.DataType)2 IOException (java.io.IOException)1