Search in sources :

Example 1 with ResolvedCatalogTable

use of org.apache.flink.table.catalog.ResolvedCatalogTable in project flink by apache.

the class HiveTableFactoryTest method testHiveTable.

@Test
public void testHiveTable() throws Exception {
    final ResolvedSchema schema = ResolvedSchema.of(Column.physical("name", DataTypes.STRING()), Column.physical("age", DataTypes.INT()));
    catalog.createDatabase("mydb", new CatalogDatabaseImpl(new HashMap<>(), ""), true);
    final Map<String, String> options = Collections.singletonMap(FactoryUtil.CONNECTOR.key(), SqlCreateHiveTable.IDENTIFIER);
    final CatalogTable table = new CatalogTableImpl(TableSchema.fromResolvedSchema(schema), options, "hive table");
    catalog.createTable(new ObjectPath("mydb", "mytable"), table, true);
    final DynamicTableSource tableSource = FactoryUtil.createDynamicTableSource((DynamicTableSourceFactory) catalog.getFactory().orElseThrow(IllegalStateException::new), ObjectIdentifier.of("mycatalog", "mydb", "mytable"), new ResolvedCatalogTable(table, schema), new Configuration(), Thread.currentThread().getContextClassLoader(), false);
    assertTrue(tableSource instanceof HiveTableSource);
    final DynamicTableSink tableSink = FactoryUtil.createDynamicTableSink((DynamicTableSinkFactory) catalog.getFactory().orElseThrow(IllegalStateException::new), ObjectIdentifier.of("mycatalog", "mydb", "mytable"), new ResolvedCatalogTable(table, schema), new Configuration(), Thread.currentThread().getContextClassLoader(), false);
    assertTrue(tableSink instanceof HiveTableSink);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) Configuration(org.apache.flink.configuration.Configuration) HashMap(java.util.HashMap) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) CatalogTable(org.apache.flink.table.catalog.CatalogTable) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) CatalogTableImpl(org.apache.flink.table.catalog.CatalogTableImpl) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Example 2 with ResolvedCatalogTable

use of org.apache.flink.table.catalog.ResolvedCatalogTable in project flink by apache.

the class KinesisDynamicTableFactory method createDynamicTableSource.

@Override
public DynamicTableSource createDynamicTableSource(Context context) {
    FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context);
    ReadableConfig tableOptions = helper.getOptions();
    ResolvedCatalogTable catalogTable = context.getCatalogTable();
    DataType physicalDataType = catalogTable.getResolvedSchema().toPhysicalRowDataType();
    KinesisConnectorOptionsUtil optionsUtils = new KinesisConnectorOptionsUtil(catalogTable.getOptions(), tableOptions);
    // initialize the table format early in order to register its consumedOptionKeys
    // in the TableFactoryHelper, as those are needed for correct option validation
    DecodingFormat<DeserializationSchema<RowData>> decodingFormat = helper.discoverDecodingFormat(DeserializationFormatFactory.class, FORMAT);
    // validate the data types of the table options
    helper.validateExcept(optionsUtils.getNonValidatedPrefixes().toArray(new String[0]));
    Properties properties = optionsUtils.getValidatedSourceConfigurations();
    return new KinesisDynamicSource(physicalDataType, tableOptions.get(STREAM), properties, decodingFormat);
}
Also used : ReadableConfig(org.apache.flink.configuration.ReadableConfig) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) FactoryUtil(org.apache.flink.table.factories.FactoryUtil) DataType(org.apache.flink.table.types.DataType) Properties(java.util.Properties) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema)

Example 3 with ResolvedCatalogTable

use of org.apache.flink.table.catalog.ResolvedCatalogTable in project flink by apache.

the class TestManagedTableFactory method onCompactTable.

@Override
public Map<String, String> onCompactTable(Context context, CatalogPartitionSpec catalogPartitionSpec) {
    ObjectIdentifier tableIdentifier = context.getObjectIdentifier();
    ResolvedCatalogTable table = context.getCatalogTable();
    Map<String, String> newOptions = new HashMap<>(table.getOptions());
    resolveCompactFileBasePath(tableIdentifier).ifPresent(s -> newOptions.put(COMPACT_FILE_BASE_PATH.key(), s));
    validateAndResolveCompactFileEntries(tableIdentifier, catalogPartitionSpec).ifPresent(s -> newOptions.put(COMPACT_FILE_ENTRIES.key(), s));
    return newOptions;
}
Also used : ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 4 with ResolvedCatalogTable

use of org.apache.flink.table.catalog.ResolvedCatalogTable in project flink by apache.

the class TemporalTableSourceSpecSerdeTest method testTemporalTableSourceSpecSerde.

public static Stream<TemporalTableSourceSpec> testTemporalTableSourceSpecSerde() {
    Map<String, String> options1 = new HashMap<>();
    options1.put("connector", "filesystem");
    options1.put("format", "testcsv");
    options1.put("path", "/tmp");
    final ResolvedSchema resolvedSchema1 = new ResolvedSchema(Collections.singletonList(Column.physical("a", DataTypes.BIGINT())), Collections.emptyList(), null);
    final CatalogTable catalogTable1 = CatalogTable.of(Schema.newBuilder().fromResolvedSchema(resolvedSchema1).build(), null, Collections.emptyList(), options1);
    ResolvedCatalogTable resolvedCatalogTable = new ResolvedCatalogTable(catalogTable1, resolvedSchema1);
    RelDataType relDataType1 = FACTORY.createSqlType(SqlTypeName.BIGINT);
    LookupTableSource lookupTableSource = new TestValuesTableFactory.MockedLookupTableSource();
    TableSourceTable tableSourceTable1 = new TableSourceTable(null, relDataType1, FlinkStatistic.UNKNOWN(), lookupTableSource, true, ContextResolvedTable.temporary(ObjectIdentifier.of("default_catalog", "default_db", "MyTable"), resolvedCatalogTable), FLINK_CONTEXT, new SourceAbilitySpec[] { new LimitPushDownSpec(100) });
    TemporalTableSourceSpec temporalTableSourceSpec1 = new TemporalTableSourceSpec(tableSourceTable1);
    return Stream.of(temporalTableSourceSpec1);
}
Also used : LimitPushDownSpec(org.apache.flink.table.planner.plan.abilities.source.LimitPushDownSpec) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) HashMap(java.util.HashMap) TemporalTableSourceSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.TemporalTableSourceSpec) LookupTableSource(org.apache.flink.table.connector.source.LookupTableSource) RelDataType(org.apache.calcite.rel.type.RelDataType) CatalogTable(org.apache.flink.table.catalog.CatalogTable) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema)

Example 5 with ResolvedCatalogTable

use of org.apache.flink.table.catalog.ResolvedCatalogTable in project flink by apache.

the class ResolvedCatalogTableSerdeTest method testDontSerializeExternalInlineTable.

@Test
void testDontSerializeExternalInlineTable() {
    SerdeContext serdeCtx = configuredSerdeContext();
    ObjectWriter objectWriter = JsonSerdeUtil.createObjectWriter(serdeCtx);
    assertThatThrownBy(() -> objectWriter.writeValueAsString(new ResolvedCatalogTable(new ExternalCatalogTable(Schema.newBuilder().fromResolvedSchema(FULL_RESOLVED_SCHEMA).build()), FULL_RESOLVED_SCHEMA))).satisfies(FlinkAssertions.anyCauseMatches(ValidationException.class, "Cannot serialize the table as it's an external inline table"));
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) ExternalCatalogTable(org.apache.flink.table.catalog.ExternalCatalogTable) JsonSerdeTestUtil.configuredSerdeContext(org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeTestUtil.configuredSerdeContext) ObjectWriter(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ResolvedCatalogTable (org.apache.flink.table.catalog.ResolvedCatalogTable)23 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)11 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)8 HashMap (java.util.HashMap)7 ValidationException (org.apache.flink.table.api.ValidationException)5 CatalogTable (org.apache.flink.table.catalog.CatalogTable)5 List (java.util.List)4 CatalogManager (org.apache.flink.table.catalog.CatalogManager)4 ContextResolvedTable (org.apache.flink.table.catalog.ContextResolvedTable)4 ExternalCatalogTable (org.apache.flink.table.catalog.ExternalCatalogTable)4 QueryOperation (org.apache.flink.table.operations.QueryOperation)4 Test (org.junit.Test)4 Optional (java.util.Optional)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 SchemaTranslator (org.apache.flink.table.catalog.SchemaTranslator)3 JsonSerdeTestUtil.configuredSerdeContext (org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeTestUtil.configuredSerdeContext)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2