-
Notifications
You must be signed in to change notification settings - Fork 3.4k
support create table like in flink catalog #12199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c193d17
d4a464d
44d45af
b4d7ffe
8f90cd5
bf55619
6745fef
6beeb2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,17 +97,20 @@ public class FlinkCatalog extends AbstractCatalog { | |
| private final Namespace baseNamespace; | ||
| private final SupportsNamespaces asNamespaceCatalog; | ||
| private final Closeable closeable; | ||
| private final Map<String, String> catalogProps; | ||
| private final boolean cacheEnabled; | ||
|
|
||
| public FlinkCatalog( | ||
| String catalogName, | ||
| String defaultDatabase, | ||
| Namespace baseNamespace, | ||
| CatalogLoader catalogLoader, | ||
| Map<String, String> catalogProps, | ||
| boolean cacheEnabled, | ||
| long cacheExpirationIntervalMs) { | ||
| super(catalogName, defaultDatabase); | ||
| this.catalogLoader = catalogLoader; | ||
| this.catalogProps = catalogProps; | ||
| this.baseNamespace = baseNamespace; | ||
| this.cacheEnabled = cacheEnabled; | ||
|
|
||
|
|
@@ -332,7 +335,15 @@ public List<String> listTables(String databaseName) | |
| public CatalogTable getTable(ObjectPath tablePath) | ||
| throws TableNotExistException, CatalogException { | ||
| Table table = loadIcebergTable(tablePath); | ||
| return toCatalogTable(table); | ||
| Map<String, String> catalogAndTableProps = Maps.newHashMap(catalogProps); | ||
| catalogAndTableProps.put(FlinkCreateTableOptions.CATALOG_NAME.key(), getName()); | ||
| catalogAndTableProps.put( | ||
| FlinkCreateTableOptions.CATALOG_DATABASE.key(), tablePath.getDatabaseName()); | ||
| catalogAndTableProps.put( | ||
| FlinkCreateTableOptions.CATALOG_TABLE.key(), tablePath.getObjectName()); | ||
| catalogAndTableProps.put("connector", FlinkDynamicTableFactory.FACTORY_IDENTIFIER); | ||
| catalogAndTableProps.putAll(table.properties()); | ||
| return toCatalogTableWithProps(table, catalogAndTableProps); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you help me understand why is the table properties needed to be added here?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just thinking out loud:
Even if we decide to follow your approach, the parameter name of the method should reflect that at the declaration of WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah merged it here , as merging later on needs an extra map. Renamed the method to toCatalogTableWithCustomProps and modified parameter names. Hope it's more readable now. |
||
| } | ||
|
|
||
| private Table loadIcebergTable(ObjectPath tablePath) throws TableNotExistException { | ||
|
|
@@ -384,13 +395,6 @@ public void renameTable(ObjectPath tablePath, String newTableName, boolean ignor | |
| @Override | ||
| public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists) | ||
| throws CatalogException, TableAlreadyExistException { | ||
| if (Objects.equals( | ||
|
pvary marked this conversation as resolved.
|
||
| table.getOptions().get("connector"), FlinkDynamicTableFactory.FACTORY_IDENTIFIER)) { | ||
| throw new IllegalArgumentException( | ||
| "Cannot create the table with 'connector'='iceberg' table property in " | ||
| + "an iceberg catalog, Please create table with 'connector'='iceberg' property in a non-iceberg catalog or " | ||
| + "create table without 'connector'='iceberg' related properties in an iceberg table."); | ||
| } | ||
| Preconditions.checkArgument(table instanceof ResolvedCatalogTable, "table should be resolved"); | ||
| createIcebergTable(tablePath, (ResolvedCatalogTable) table, ignoreIfExists); | ||
| } | ||
|
|
@@ -625,7 +629,7 @@ private static List<String> toPartitionKeys(PartitionSpec spec, Schema icebergSc | |
| return partitionKeysBuilder.build(); | ||
| } | ||
|
|
||
| static CatalogTable toCatalogTable(Table table) { | ||
| static CatalogTable toCatalogTableWithProps(Table table, Map<String, String> props) { | ||
| TableSchema schema = FlinkSchemaUtil.toSchema(table.schema()); | ||
| List<String> partitionKeys = toPartitionKeys(table.spec(), table.schema()); | ||
|
|
||
|
|
@@ -634,7 +638,11 @@ static CatalogTable toCatalogTable(Table table) { | |
| // CatalogTableImpl to copy a new catalog table. | ||
| // Let's re-loading table from Iceberg catalog when creating source/sink operators. | ||
| // Iceberg does not have Table comment, so pass a null (Default comment value in Flink). | ||
| return new CatalogTableImpl(schema, partitionKeys, table.properties(), null); | ||
| return new CatalogTableImpl(schema, partitionKeys, props, null); | ||
| } | ||
|
|
||
| static CatalogTable toCatalogTable(Table table) { | ||
| return toCatalogTableWithProps(table, table.properties()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.iceberg.flink; | ||
|
|
||
| import org.apache.flink.configuration.ConfigOption; | ||
| import org.apache.flink.configuration.ConfigOptions; | ||
|
|
||
| public class FlinkCreateTableOptions { | ||
|
stevenzwu marked this conversation as resolved.
Outdated
|
||
|
|
||
| private FlinkCreateTableOptions() {} | ||
|
|
||
| public static final ConfigOption<String> CATALOG_NAME = | ||
| ConfigOptions.key("catalog-name") | ||
| .stringType() | ||
| .noDefaultValue() | ||
| .withDescription("Catalog name"); | ||
|
|
||
| public static final ConfigOption<String> CATALOG_TYPE = | ||
| ConfigOptions.key(FlinkCatalogFactory.ICEBERG_CATALOG_TYPE) | ||
| .stringType() | ||
| .noDefaultValue() | ||
| .withDescription("Catalog type, the optional types are: custom, hadoop, hive."); | ||
|
|
||
| public static final ConfigOption<String> CATALOG_DATABASE = | ||
| ConfigOptions.key("catalog-database") | ||
| .stringType() | ||
| .defaultValue(FlinkCatalogFactory.DEFAULT_DATABASE_NAME) | ||
| .withDescription("Database name managed in the iceberg catalog."); | ||
|
|
||
| public static final ConfigOption<String> CATALOG_TABLE = | ||
| ConfigOptions.key("catalog-table") | ||
| .stringType() | ||
| .noDefaultValue() | ||
| .withDescription("Table name managed in the underlying iceberg catalog and database."); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.