Hudi Partial Update
Scenarios
Hudi allows you to update columns partially. You can use the latest data under the same primary key to update specific column fields in each row one by one until the entire data record is complete.
The open-source community currently provides PartialUpdateAvroPayload for partial column updates. However, when multiple streams update different columns, data is mutually overwritten.
By introducing the sequence group, Hudi can solve this problem and implement real partial update.
Columns in a table are divided into different sequence groups as you need during table creation. Whether the columns in a sequence group are updated is determined by that group's precombine field. Sequence groups operate independently and do not affect one another.
Notes and Constraints
- This section applies only to MRS 3.3.1-LTS or later.
- Due to Hudi OCC limitations, we do not recommend concurrently writing data to a Hudi table from multiple streams. If you need to write from multiple streams simultaneously, union all streams before writing the data to Hudi.
- New columns can be added and grouped. To add the column to a new group, you need to modify tblproperties and serdeproperties of the table. Example statements are as follows:
- Add new columns col5,col6,group_3.
alter table testTable add columns (col5 int, col6 int, group_3 int);
- Add the new group information to tblproperties.
alter table testTable set tblproperties('fields.group_3.sequence-group' = 'col5,col6'); - Add the new group information to serdeproperties.
alter table testTable set serdeproperties('fields.group_3.sequence-group' = 'col5,col6');
- Add new columns col5,col6,group_3.
- Columns in different sequence groups must not overlap. For example, the same column col1 cannot exist in both sequence-1 and sequence-2.
- The group column supports only the following data types: int, bigint, float, double, date, and timestamp.
- If you enable partial updates for existing tables, you must comply with the following requirements. Otherwise, the data may not meet the expectation.
- Stop writing data to the table to be modified.
- Perform full compaction for MOR tables.
set hoodie.compaction.inline.max.delta.commits=1; set hoodie.compact.inline=true;
Perform full compaction.
run compaction on my_table; reset hoodie.compaction.inline.max.delta.commits;
- Add the new group information to tblproperties.
alter table testTable set tblproperties('fields.group_1.sequence-group' = 'col1,col2'); - Add the new group information to serdeproperties.
alter table testTable set serdeproperties('fields.group_1.sequence-group' = 'col1,col2');
Example
create table if not exists testTable( id INT, col1 INT, col2 INT, group_1 INT, col3 INT, col4 INT, group_2 INT, ts LONG ) using hudi tblproperties ( primaryKey = 'id', type = 'mor', 'hoodie.merge-engine' = 'partial-update', 'fields.group_1.sequence-group' = 'col1,col2',---- Divide update groups. Whether the col1 and col2 columns are updated is determined by group_1. That is, group_1 is the preCombine field of the group. 'fields.group_2.sequence-group' = 'col3,col4' ---- Divide update groups. Whether the col3 and col4 columns are updated is determined by group_2. That is, group_2 is the preCombine field of the group. ); ---Execute the insert statement. insert into testTable values (1, 1, 1, 1, 1, 1, 1, 1000); -- First write insert into testTable values (1, 2, 2, 2, 2, 2, null, 2000); -- Second write ---Query result select * from testTable; ---The result is 1, 2, 2, 2, 1, 1, 1, 2000. ---Result description: When data is written for the second time, the value of group_1 is 2, which is greater than the historical value 1 in the table. This means that col1 and col2 are updated. The value of group_2 is null, which means that col3 and col4 are not updated. ---Execute the insert statement again. insert into testTable values (1, null, 3, 2, 3, 3, 3, 4000); -- Third write select * from testTable; ---The result is 1, null, 3, 2, 3, 3, 3, 4000. ---Result description: When data is written for the third time, the value of group_1 is 2, which is equal to the historical value 2 in the table. This means that col1 and col2 are updated. The value of group_2 is 3, which is greater than the historical value 1 in the table. This means that col3 and col4 are updated.
Application Scenario Example
The union write simulates a multi-table join. (Flink can use this function to join streams.)
The following code uses Spark SQL as an example. Hudi is used to convert the join of t1 and t2 to a union and an insert operation to reduce join overhead.
create table if not exists t1( id INT, col1 INT, col2 INT ) using parquet; insert into t1 values(1, 1, 1); create table if not exists t2( id INT, col3 INT, col4 INT ) using parquet; insert into t2 values(1, 2, 2);
create table if not exists joinTable( id INT, col1 INT, col2 INT, group_1 INT, col3 INT, col4 INT, group_2 INT ) using hudi tblproperties ( primaryKey = 'id', type = 'mor', 'hoodie.index.type' = 'BUCKET', hoodie.bucket.index.num.buckets=1, 'hoodie.merge-engine' = 'partial-update', 'fields.group_1.sequence-group' = 'col1,col2', 'fields.group_2.sequence-group' = 'col3,col4' ); --- Union and insert are performed to simulate the join operation. insert into joinTable select id, col1, col2, 1, null, null, null from t1 --- Use any non-null value as the precombine of col1 and col2. union all select id, null, null, null, col3, col4, 1 from t2; --- Use any non-null value as the precombine of col3 and col4. ---Execute the query. select id,col1,col2,col3,col4 from joinTable; -- Result -- 1, 1, 1, 2, 2
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