-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * 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 java.util.Map; | ||
| import org.apache.flink.configuration.ConfigOption; | ||
| import org.apache.flink.configuration.ConfigOptions; | ||
| import org.apache.iceberg.util.JsonUtil; | ||
|
|
||
| class FlinkCreateTableOptions { | ||
| private final String catalogName; | ||
| private final String catalogDb; | ||
| private final String catalogTable; | ||
| private final Map<String, String> catalogProps; | ||
|
|
||
| private FlinkCreateTableOptions( | ||
| String catalogName, String catalogDb, String catalogTable, Map<String, String> props) { | ||
| this.catalogName = catalogName; | ||
| this.catalogDb = catalogDb; | ||
| this.catalogTable = catalogTable; | ||
| this.catalogProps = props; | ||
| } | ||
|
|
||
| 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."); | ||
|
|
||
| public static final ConfigOption<Map<String, String>> CATALOG_PROPS = | ||
| ConfigOptions.key("catalog-props") | ||
| .mapType() | ||
| .noDefaultValue() | ||
| .withDescription("Properties for the underlying catalog for iceberg table."); | ||
|
|
||
| public static final String SRC_CATALOG_PROPS_KEY = "src-catalog"; | ||
stevenzwu marked this conversation as resolved.
Show resolved
Hide resolved
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. also does Flink create table ... like ... work for Hive tables as source? I assume no. otherwise, we can refer to how that is implemented. It feels tacky to use special property key to carry over catalog props and source table identifier. Does it make sense to modify Flink API to support this more elegantly?
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. Right this is not supported in hive, Supported in Kafka, but yeah there is no concept of catalog , mostly flat properties of cluster for kafka connector.
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. yeah, Kafka doesn't have catalog concept. we can take this discussion separately. it won't be a blocker for this PR |
||
| public static final String CONNECTOR_PROPS_KEY = "connector"; | ||
| public static final String LOCATION_KEY = "location"; | ||
|
|
||
| static String toJson( | ||
| String catalogName, String catalogDb, String catalogTable, Map<String, String> catalogProps) { | ||
| return JsonUtil.generate( | ||
| gen -> { | ||
| gen.writeStartObject(); | ||
| gen.writeStringField(CATALOG_NAME.key(), catalogName); | ||
| gen.writeStringField(CATALOG_DATABASE.key(), catalogDb); | ||
| gen.writeStringField(CATALOG_TABLE.key(), catalogTable); | ||
| JsonUtil.writeStringMap(CATALOG_PROPS.key(), catalogProps, gen); | ||
| gen.writeEndObject(); | ||
| }, | ||
| false); | ||
| } | ||
|
|
||
| static FlinkCreateTableOptions fromJson(String createTableOptions) { | ||
| return JsonUtil.parse( | ||
| createTableOptions, | ||
| node -> { | ||
| String catalogName = JsonUtil.getString(CATALOG_NAME.key(), node); | ||
| String catalogDb = JsonUtil.getString(CATALOG_DATABASE.key(), node); | ||
| String catalogTable = JsonUtil.getString(CATALOG_TABLE.key(), node); | ||
| Map<String, String> catalogProps = JsonUtil.getStringMap(CATALOG_PROPS.key(), node); | ||
|
|
||
| return new FlinkCreateTableOptions(catalogName, catalogDb, catalogTable, catalogProps); | ||
| }); | ||
| } | ||
|
|
||
| String catalogName() { | ||
| return catalogName; | ||
| } | ||
|
|
||
| String catalogDb() { | ||
| return catalogDb; | ||
| } | ||
|
|
||
| String catalogTable() { | ||
| return catalogTable; | ||
| } | ||
|
|
||
| Map<String, String> catalogProps() { | ||
| return catalogProps; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.