Search in sources :

Example 26 with ObjectIdentifier

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

the class SqlToOperationConverter method convertShowColumns.

/**
 * Convert SHOW COLUMNS statement.
 */
private Operation convertShowColumns(SqlShowColumns sqlShowColumns) {
    UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlShowColumns.fullTableName());
    ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
    return new ShowColumnsOperation(identifier, sqlShowColumns.getLikeSqlPattern(), sqlShowColumns.isWithLike(), sqlShowColumns.isNotLike(), sqlShowColumns.getPreposition());
}
Also used : UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) ShowColumnsOperation(org.apache.flink.table.operations.ShowColumnsOperation) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 27 with ObjectIdentifier

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

the class SqlCreateTableConverter method convertCreateTable.

/**
 * Convert the {@link SqlCreateTable} node.
 */
Operation convertCreateTable(SqlCreateTable sqlCreateTable) {
    sqlCreateTable.getTableConstraints().forEach(validateTableConstraint);
    CatalogTable catalogTable = createCatalogTable(sqlCreateTable);
    UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlCreateTable.fullTableName());
    ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
    return new CreateTableOperation(identifier, catalogTable, sqlCreateTable.isIfNotExists(), sqlCreateTable.isTemporary());
}
Also used : UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) CatalogTable(org.apache.flink.table.catalog.CatalogTable) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 28 with ObjectIdentifier

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

the class SqlToOperationConverterTest method prepareTable.

private void prepareTable(boolean managedTable, boolean hasPartition, boolean hasConstraint) throws Exception {
    Catalog catalog = new GenericInMemoryCatalog("default", "default");
    catalogManager.registerCatalog("cat1", catalog);
    catalog.createDatabase("db1", new CatalogDatabaseImpl(new HashMap<>(), null), true);
    Schema.Builder builder = Schema.newBuilder().column("a", DataTypes.STRING().notNull()).column("b", DataTypes.BIGINT().notNull()).column("c", DataTypes.BIGINT());
    Map<String, String> options = new HashMap<>();
    options.put("k", "v");
    if (!managedTable) {
        options.put("connector", "dummy");
    }
    CatalogTable catalogTable = CatalogTable.of(hasConstraint ? builder.primaryKeyNamed("ct1", "a", "b").build() : builder.build(), "tb1", hasPartition ? Arrays.asList("b", "c") : Collections.emptyList(), Collections.unmodifiableMap(options));
    catalogManager.setCurrentCatalog("cat1");
    catalogManager.setCurrentDatabase("db1");
    ObjectIdentifier tableIdentifier = ObjectIdentifier.of("cat1", "db1", "tb1");
    catalogManager.createTable(catalogTable, tableIdentifier, true);
}
Also used : HashMap(java.util.HashMap) TableSchema(org.apache.flink.table.api.TableSchema) OperationMatchers.withSchema(org.apache.flink.table.planner.utils.OperationMatchers.withSchema) CatalogManagerCalciteSchema(org.apache.flink.table.planner.catalog.CatalogManagerCalciteSchema) Schema(org.apache.flink.table.api.Schema) CalciteSchemaBuilder.asRootSchema(org.apache.calcite.jdbc.CalciteSchemaBuilder.asRootSchema) CatalogTable(org.apache.flink.table.catalog.CatalogTable) Catalog(org.apache.flink.table.catalog.Catalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 29 with ObjectIdentifier

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

the class TableEnvironmentTest method innerTestManagedTableFromDescriptor.

private void innerTestManagedTableFromDescriptor(boolean ignoreIfExists, boolean isTemporary) {
    final TableEnvironmentMock tEnv = TableEnvironmentMock.getStreamingInstance();
    final String catalog = tEnv.getCurrentCatalog();
    final String database = tEnv.getCurrentDatabase();
    final Schema schema = Schema.newBuilder().column("f0", DataTypes.INT()).build();
    final String tableName = UUID.randomUUID().toString();
    ObjectIdentifier identifier = ObjectIdentifier.of(catalog, database, tableName);
    // create table
    MANAGED_TABLES.put(identifier, new AtomicReference<>());
    CreateTableOperation createOperation = new CreateTableOperation(identifier, TableDescriptor.forManaged().schema(schema).option("a", "Test").build().toCatalogTable(), ignoreIfExists, isTemporary);
    tEnv.executeInternal(createOperation);
    // test ignore: create again
    if (ignoreIfExists) {
        tEnv.executeInternal(createOperation);
    } else {
        assertThatThrownBy(() -> tEnv.executeInternal(createOperation), isTemporary ? "already exists" : "Could not execute CreateTable");
    }
    // lookup table
    boolean isInCatalog = tEnv.getCatalog(catalog).orElseThrow(AssertionError::new).tableExists(new ObjectPath(database, tableName));
    if (isTemporary) {
        assertThat(isInCatalog).isFalse();
    } else {
        assertThat(isInCatalog).isTrue();
    }
    final Optional<ContextResolvedTable> lookupResult = tEnv.getCatalogManager().getTable(identifier);
    assertThat(lookupResult.isPresent()).isTrue();
    final CatalogBaseTable catalogTable = lookupResult.get().getTable();
    assertThat(catalogTable instanceof CatalogTable).isTrue();
    assertThat(catalogTable.getUnresolvedSchema()).isEqualTo(schema);
    assertThat(catalogTable.getOptions().get("a")).isEqualTo("Test");
    assertThat(catalogTable.getOptions().get(ENRICHED_KEY)).isEqualTo(ENRICHED_VALUE);
    AtomicReference<Map<String, String>> reference = MANAGED_TABLES.get(identifier);
    assertThat(reference.get()).isNotNull();
    assertThat(reference.get().get("a")).isEqualTo("Test");
    assertThat(reference.get().get(ENRICHED_KEY)).isEqualTo(ENRICHED_VALUE);
    DropTableOperation dropOperation = new DropTableOperation(identifier, ignoreIfExists, isTemporary);
    tEnv.executeInternal(dropOperation);
    assertThat(MANAGED_TABLES.get(identifier).get()).isNull();
    // test ignore: drop again
    if (ignoreIfExists) {
        tEnv.executeInternal(dropOperation);
    } else {
        assertThatThrownBy(() -> tEnv.executeInternal(dropOperation), "does not exist");
    }
    MANAGED_TABLES.remove(identifier);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) CatalogTable(org.apache.flink.table.catalog.CatalogTable) DropTableOperation(org.apache.flink.table.operations.ddl.DropTableOperation) ContextResolvedTable(org.apache.flink.table.catalog.ContextResolvedTable) TableEnvironmentMock(org.apache.flink.table.utils.TableEnvironmentMock) Map(java.util.Map) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 30 with ObjectIdentifier

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

the class LogicalTypeJsonDeserializer method deserializeDistinctType.

private static LogicalType deserializeDistinctType(JsonNode logicalTypeNode, SerdeContext serdeContext) {
    final ObjectIdentifier identifier = ObjectIdentifierJsonDeserializer.deserialize(logicalTypeNode.get(FIELD_NAME_OBJECT_IDENTIFIER).asText(), serdeContext);
    final CatalogPlanRestore restoreStrategy = serdeContext.getConfiguration().get(TableConfigOptions.PLAN_RESTORE_CATALOG_OBJECTS);
    switch(restoreStrategy) {
        case ALL:
            if (logicalTypeNode.has(FIELD_NAME_SOURCE_TYPE)) {
                return deserializeDistinctTypeFromPlan(identifier, logicalTypeNode, serdeContext);
            }
            return deserializeUserDefinedTypeFromCatalog(identifier, serdeContext);
        case ALL_ENFORCED:
            return deserializeDistinctTypeFromPlan(identifier, logicalTypeNode, serdeContext);
        case IDENTIFIER:
            return deserializeUserDefinedTypeFromCatalog(identifier, serdeContext);
        default:
            throw new TableException("Unsupported catalog restore strategy.");
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) CatalogPlanRestore(org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanRestore) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Aggregations

ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)185 CatalogTable (org.apache.flink.table.catalog.CatalogTable)66 UnresolvedIdentifier (org.apache.flink.table.catalog.UnresolvedIdentifier)60 ValidationException (org.apache.flink.table.api.ValidationException)59 HashMap (java.util.HashMap)57 LinkedHashMap (java.util.LinkedHashMap)48 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)42 ContextResolvedTable (org.apache.flink.table.catalog.ContextResolvedTable)41 ResolvedCatalogTable (org.apache.flink.table.catalog.ResolvedCatalogTable)33 ArrayList (java.util.ArrayList)30 Map (java.util.Map)27 UniqueConstraint (org.apache.flink.table.api.constraints.UniqueConstraint)27 CatalogPartitionSpec (org.apache.flink.table.catalog.CatalogPartitionSpec)24 NotNullConstraint (org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.NotNullConstraint)24 TableException (org.apache.flink.table.api.TableException)23 TableSchema (org.apache.flink.table.api.TableSchema)23 CatalogView (org.apache.flink.table.catalog.CatalogView)21 QueryOperation (org.apache.flink.table.operations.QueryOperation)18 HiveParserASTNode (org.apache.flink.table.planner.delegation.hive.copy.HiveParserASTNode)18 List (java.util.List)16