Search in sources :

Example 31 with DescriptorProperties

use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.

the class FileSystemTableFactoryTest method testFormatOptionsError.

@Test
public void testFormatOptionsError() {
    DescriptorProperties descriptor = new DescriptorProperties();
    descriptor.putString(FactoryUtil.CONNECTOR.key(), "filesystem");
    descriptor.putString("path", "/tmp");
    descriptor.putString("format", "test-format");
    Exception expected = new ValidationException("One or more required options are missing.\n\n" + "Missing required options are:\n\n" + "delimiter");
    try {
        createTableSource(SCHEMA, descriptor.asMap());
        fail("Should fail");
    } catch (Exception e) {
        assertThat(e.getCause().getCause(), containsCause(expected));
    }
    try {
        createTableSink(SCHEMA, descriptor.asMap());
        fail("Should fail");
    } catch (Exception e) {
        assertThat(e.getCause().getCause(), containsCause(expected));
    }
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) ValidationException(org.apache.flink.table.api.ValidationException) Test(org.junit.Test)

Example 32 with DescriptorProperties

use of org.apache.flink.table.descriptors.DescriptorProperties in project flink by apache.

the class FlinkCalciteCatalogReader method isLegacySourceOptions.

/**
 * Checks whether the {@link CatalogTable} uses legacy connector source options.
 */
private static boolean isLegacySourceOptions(CatalogSchemaTable schemaTable) {
    // normalize option keys
    DescriptorProperties properties = new DescriptorProperties(true);
    properties.putProperties(schemaTable.getContextResolvedTable().getTable().getOptions());
    if (properties.containsKey(ConnectorDescriptorValidator.CONNECTOR_TYPE)) {
        return true;
    } else {
        // some legacy factories uses the new 'connector' key
        try {
            TableFactoryUtil.findAndCreateTableSource(schemaTable.getContextResolvedTable().getCatalog().orElse(null), schemaTable.getContextResolvedTable().getIdentifier(), schemaTable.getContextResolvedTable().getTable(), new Configuration(), schemaTable.isTemporary());
            // success, then we will use the legacy factories
            return true;
        } catch (Throwable e) {
            // fail, then we will use new factories
            return false;
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties)

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