INSERT INTO
Function
This command is used to insert the output of the SELECT statement to a Hudi table.
Syntax
INSERT INTO tableIndentifier select query;
Parameter Description
| Parameter | Description |
|---|---|
| tableIndentifier | Name of the Hudi table. |
| select query | SELECT statement. |
Precautions
- Insert mode: Hudi supports three insert modes for tables with primary keys. You can set hoodie.sql.insert.mode to specify the insert mode. The default value is upsert.
- In strict mode, the INSERT statement retains the primary key constraint of COW tables and is not allowed to insert duplicate records. If a record already exists during data insertion, HoodieDuplicateKeyException is thrown for COW tables. For MOR tables, the behavior in this mode is the same as that in upsert mode.
- In non-strict mode, records are inserted to primary key tables.
- In upsert mode, duplicate values in the primary key table are updated.
- When executing a Spark SQL statement, you can set hoodie.sql.bulk.insert.enable to true and hoodie.sql.insert.mode to non-strict to enable the insert statement to use bulk insert as the default write mode. In this mode, the primary key deduplication and small file merging are unavailable, but the write efficiency is higher than the other two modes. By default, bulk insert cannot be used for bucket indexes. To use bulk insert, configure hoodie.bucket.support.bulk.insert = true and hoodie.datasource.write.row.writer.enable = true. A table with bucket indexes can be written only once using bulk insert.
- When the Insert into ${table_name} values() statement is used to write data to the Hudi partitioned table, the partitioning field specified by partitioned by (par1, par2) in the table creation statement needs to be added to the end of values. For example:
values(,value of par1, value of par2)
Examples
insert into h0 select 1, 'a1', 20; -- insert static partition insert into h_p0 partition(dt = '2021-01-02') select 1, 'a1'; -- insert dynamic partition insert into h_p0 select 1, 'a1', dt; -- insert dynamic partition insert into h_p1 select 1 as id, 'a1', '2021-01-03' as dt, '19' as hh; -- insert overwrite table insert overwrite table h0 select 1, 'a1', 20; -- insert overwrite table with static partition insert overwrite h_p0 partition(dt = '2021-01-02') select 1, 'a1'; -- insert overwrite table with dynamic partition insert overwrite table h_p1 select 2 as id, 'a2', '2021-01-03' as dt, '19' as hh;
Response
You can view command execution results in the driver logs.
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