Configuring Default Values for Hudi Data Columns
This feature allows you to set default values for columns when you add columns to a table. When you query historical data, the default value is returned for the new column.
Constraints
- If data has been rewritten before default values are set for a new column, the default values of the column cannot be returned when historical data is queried. In this case, NULL values are returned. Some or all data will be rewritten when data is imported to the database, updated, compacted, or clustered.
- The default values of a column must match the column type. If they do not match, the type will be forcibly converted. This loses the precision of the default values or changes the default values to NULL.
- The default values of historical data are the default values set for the column for the first time. Changing the default values of a column for multiple times does not affect the query result of historical data.
- After the default value is set, it cannot be rolled back.
- Currently, Spark SQL does not support the function of viewing default column values. You can run the show create table SQL statements to view default column values.
- The default method of writing missing columns is not supported. Column names must be specified when writing.
Scope
Currently, only the int, bigint, float, double, decimal, string, date, timestamp, boolean, and binary data types are supported.
Engine |
DDL Operation Support |
Write Operation Support |
Read Operation Support |
---|---|---|---|
SparkSQL |
Y |
Y |
Y |
Spark DataSource |
N |
N |
Y |
Flink |
N |
N |
Y |
HetuEngine |
N |
N |
Y |
Hive |
N |
N |
Y |
Example
For details about the SQL syntax, see DLI Hudi SQL Syntax Reference.
Example:
- Create a table and specify default values for columns.
create table if not exists h3( id bigint, name string, price double default 12.34 ) using hudi options ( primaryKey = 'id', type = 'mor', preCombineField = 'name' );
- Add columns and specify default values for the columns.
alter table h3 add columns(col1 string default 'col1_value'); alter table h3 add columns(col2 string default 'col2_value', col3 int default 1);
- Change default values of columns.
alter table h3 alter column price set default 14.56;
- When inserting data using column default values, you need to specify the column names being written, corresponding one-to-one with the inserted data.
insert into h3(id, name) values(1, 'aaa'); insert into h3(id, name, price) select 2, 'bbb', 12.5;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.