Managing Iceberg Catalogs
After configuring an Iceberg catalog for an AI DataLake Flink job, you can use AI DataLake Flink to directly access Iceberg tables in Huawei Cloud LakeFormation. This section describes how to create an Iceberg catalog in an AI DataLake Flink job and manage Iceberg databases and tables.
Procedure: Use a tool such as Postman to call the API for Creating a FlinkJob Job to submit a Flink job.
Creating an Iceberg LakeFormation Catalog
CREATE CATALOG lf_iceberg_catalog WITH ( 'type' = 'iceberg', 'catalog-type' = 'lakeformation' );
The following table lists the parameters.
| Parameter | Description | Mandatory (Yes/No) | Remarks |
|---|---|---|---|
| type | Catalog type. | Yes | The value is fixed to iceberg. |
| catalog-type | Catalog implementation type. | Yes | The value is fixed to lakeformation. |
| lakecat.catalogname.default | Name of the catalog to be accessed in LakeFormation. The name must be the same as the name of the catalog created in LakeFormation. | No | The default value is the catalog name on the Flink engine, that is, lf_iceberg_catalog. |
Managing Iceberg Databases
- Creating a database
After creating an Iceberg catalog, create the iceberg_db database in lf_iceberg_catalog.
CREATE DATABASE IF NOT EXISTS lf_iceberg_catalog.iceberg_db WITH ( 'location' = 'obs://bucket/iceberg_catalog/iceberg_db/' );
- Deleting a database
DROP DATABASE lf_iceberg_catalog.iceberg_db; -- Only deletes databases that do not contain any tables.
Managing Iceberg Tables
- Creating a table
Create a partitioned table in the my_db database under the iceberg-catalog catalog. The partition key is dt, and the primary keys are dt, shop_id, and user_id. The sample code is as follows:
CREATE TABLE lf_iceberg_catalog.iceberg_db.iceberg_table ( dt STRING, shop_id BIGINT, user_id BIGINT, num_orders INT, total_amount INT, PRIMARY KEY (dt, shop_id, user_id) NOT ENFORCED ) PARTITIONED BY (dt);
- Modifying a table
Operation
Code Example
Temporarily modifying table parameters
You can temporarily modify table parameters by adding an SQL hint after the table name when writing data to the table. These temporary modifications are only effective for the current SQL job.
- Temporarily set upsert-enabled to true when writing to the my_table table.
INSERT INTO tableName /*+ OPTIONS('upsert-enabled'='true') */ SELECT ...;
- Temporarily set monitor-interval to 10s when consuming the my_table table.
SELECT * FROM my_table /*+ OPTIONS('monitor-interval'='10s') */
Renaming a table
Rename the table from my_table to my_table_new. Only EXTERNAL and LAKE tables can be renamed.
ALTER TABLE my_table RENAME TO my_table_new;
Adding a column
Add the c1 column of the INT type and the c2 column of the STRING type to the end of the my_table table.
ALTER TABLE my_table ADD (c1 INT, c2 STRING);
Renaming a column
Rename the c0 column in the my_table table to c1.
ALTER TABLE my_table RENAME c0 TO c1;
Dropping a column
Drop columns c1 and c2 from the my_table table.
ALTER TABLE my_table DROP (c1, c2);
Modifying column comments
Change the comment of the buy_count column in the my_table table to this is buy count.
ALTER TABLE my_table MODIFY buy_count BIGINT COMMENT 'this is buy count';
Modifying the column order
- Move the col_a column of the DOUBLE type in the my_table table to the beginning.
ALTER TABLE my_table MODIFY col_a DOUBLE FIRST;
- Move the col_a column of the DOUBLE type in the my_table table to the end of the col_b column.
ALTER TABLE my_table MODIFY col_a DOUBLE AFTER col_b;
- Temporarily set upsert-enabled to true when writing to the my_table table.
- Deleting a table
DROP TABLE lf_iceberg_catalog.iceberg_db.iceberg_table;
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot