-
Notifications
You must be signed in to change notification settings - Fork 3k
Docs: Add flink iceberg connector #3085
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| <!-- | ||
| - 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. | ||
| --> | ||
|
|
||
| Apache Flink supports creating Iceberg table directly without creating the explicit Flink catalog in Flink SQL. That means we can just create an iceberg table by specifying `'connector'='iceberg'` table option in Flink SQL which is similar to usage in the Flink official [document](https://nightlies.apache.org/flink/flink-docs-release-1.13/docs/connectors/table/overview/). | ||
|
|
||
| In Flink, the SQL `CREATE TABLE test (..) WITH ('connector'='iceberg', ...)` will create a Flink table in current Flink catalog (use [GenericInMemoryCatalog](https://ci.apache.org/projects/flink/flink-docs-release-1.13/docs/dev/table/catalogs/#genericinmemorycatalog) by default), | ||
| which is just mapping to the underlying iceberg table instead of maintaining iceberg table directly in current Flink catalog. | ||
|
|
||
| To create the table in Flink SQL by using SQL syntax `CREATE TABLE test (..) WITH ('connector'='iceberg', ...)`, Flink iceberg connector provides the following table properties: | ||
|
|
||
| * `connector`: Use the constant `iceberg`. | ||
| * `catalog-name`: User-specified catalog name. It's required because the connector don't have any default value. | ||
| * `catalog-type`: Default to use `hive` if don't specify any value. The optional values are: | ||
| * `hive`: The Hive metastore catalog. | ||
| * `hadoop`: The hadoop catalog. | ||
| * `custom`: The customized catalog, see [custom catalog](./custom-catalog.md) for more details. | ||
| * `catalog-database`: The iceberg database name in the backend catalog, use the current flink database name by default. | ||
| * `catalog-table`: The iceberg table name in the backend catalog. Default to use the table name in the flink `CREATE TABLE` sentence. | ||
|
|
||
| ## Table managed in Hive catalog. | ||
|
|
||
| Before executing the following SQL, please make sure you've configured the Flink SQL client correctly according to the quick start [document](./flink.md). | ||
|
|
||
| The following SQL will create a Flink table in the current Flink catalog, which maps to the iceberg table `default_database.iceberg_table` managed in iceberg catalog. | ||
|
|
||
| ```sql | ||
| CREATE TABLE flink_table ( | ||
| id BIGINT, | ||
| data STRING | ||
| ) WITH ( | ||
| 'connector'='iceberg', | ||
| 'catalog-name'='hive_prod', | ||
| 'uri'='thrift://localhost:9083', | ||
| 'warehouse'='hdfs://nn:8020/path/to/warehouse' | ||
| ); | ||
| ``` | ||
|
|
||
| If you want to create a Flink table mapping to a different iceberg table managed in Hive catalog (such as `hive_db.hive_iceberg_table` in Hive), then you can create Flink table as following: | ||
|
|
||
| ```sql | ||
| CREATE TABLE flink_table ( | ||
| id BIGINT, | ||
| data STRING | ||
| ) WITH ( | ||
| 'connector'='iceberg', | ||
| 'catalog-name'='hive_prod', | ||
| 'catalog-database'='hive_db', | ||
| 'catalog-table'='hive_iceberg_table', | ||
| 'uri'='thrift://localhost:9083', | ||
| 'warehouse'='hdfs://nn:8020/path/to/warehouse' | ||
| ); | ||
| ``` | ||
|
|
||
| !!! Note | ||
| The underlying catalog database (`hive_db` in the above example) will be created automatically if it does not exist when writing records into the Flink table. | ||
|
|
||
| ## Table managed in hadoop catalog | ||
|
|
||
| The following SQL will create a Flink table in current Flink catalog, which maps to the iceberg table `default_database.flink_table` managed in hadoop catalog. | ||
|
|
||
| ```sql | ||
| CREATE TABLE flink_table ( | ||
| id BIGINT, | ||
| data STRING | ||
| ) WITH ( | ||
| 'connector'='iceberg', | ||
| 'catalog-name'='hadoop_prod', | ||
| 'catalog-type'='hadoop', | ||
| 'warehouse'='hdfs://nn:8020/path/to/warehouse' | ||
| ); | ||
| ``` | ||
|
|
||
| ## Table managed in custom catalog | ||
|
|
||
| The following SQL will create a Flink table in current Flink catalog, which maps to the iceberg table `default_database.flink_table` managed in custom catalog. | ||
|
|
||
| ```sql | ||
| CREATE TABLE flink_table ( | ||
| id BIGINT, | ||
| data STRING | ||
| ) WITH ( | ||
| 'connector'='iceberg', | ||
| 'catalog-name'='custom_prod', | ||
| 'catalog-type'='custom', | ||
| 'catalog-impl'='com.my.custom.CatalogImpl', | ||
| -- More table properties for the customized catalog | ||
| 'my-additional-catalog-config'='my-value', | ||
| ... | ||
| ); | ||
| ``` | ||
|
|
||
| Please check sections under the Integrations tab for all custom catalogs. | ||
|
|
||
| ## A complete example. | ||
|
|
||
| Take the Hive catalog as an example: | ||
|
|
||
| ```sql | ||
| CREATE TABLE flink_table ( | ||
| id BIGINT, | ||
| data STRING | ||
| ) WITH ( | ||
| 'connector'='iceberg', | ||
| 'catalog-name'='hive_prod', | ||
| 'uri'='thrift://localhost:9083', | ||
| 'warehouse'='file:///path/to/warehouse' | ||
| ); | ||
|
|
||
| INSERT INTO flink_table VALUES (1, 'AAA'), (2, 'BBB'), (3, 'CCC'); | ||
|
|
||
| SET execution.result-mode=tableau; | ||
| SELECT * FROM flink_table; | ||
|
|
||
| +----+------+ | ||
| | id | data | | ||
| +----+------+ | ||
| | 1 | AAA | | ||
| | 2 | BBB | | ||
| | 3 | CCC | | ||
| +----+------+ | ||
| 3 rows in set | ||
| ``` | ||
|
|
||
| For more details, please refer to the Iceberg [Flink document](./flink.md). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking we might want to break down the flink documentation like Spark (no need to do in this PR), just to make it more consistent between the 2 and easier to navigate. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it's necessary to break the flink into more pages so that people could get the correct point in the separate page. We will also introduce more feature for iceberg flink integration work, such as flink table maintaince API , flip-27 unified source/sink etc.
I will prefer to publish a separate PR to address the break-down thing, let this one focus on adding the iceberg flink connector.