Allow to insert default instead of Null in insert-select / insert-select-union-all#23524
Conversation
|
As the feature is unrelated to formats, it will be better to make a separate setting. |
| auto nullable_column = ColumnNullable::create(query_columns[col_idx], ColumnUInt8::create(query_columns[col_idx]->size(), 0)); | ||
| ColumnWithTypeAndName new_column(std::move(nullable_column), std::make_shared<DataTypeNullable>(column.type), column.name); |
There was a problem hiding this comment.
Note: there are functions ColumnPtr makeNullable(const ColumnPtr & column); (in ColumnNullable.h) and DataTypePtr makeNullable(const DataTypePtr & type); (in DataTypeNullable.h)
There was a problem hiding this comment.
Also, could please add comment why do we need to change query_sample_block here?
And why it is safe (because AddingDefaultBlockOutputStream will remove nullable)
| addDefaultRequiredExpressionsRecursively(block, required_column_name, columns, default_expr_list_accum, added_columns); | ||
| if (is_column_in_query && convert_null_to_default) | ||
| { | ||
| auto null_as_default_expr = makeASTFunction("ifNull", std::make_shared<ASTIdentifier>(required_column_name), column_default_expr); |
There was a problem hiding this comment.
I think that we also need to add CAST here for column_default_expr. Similar as in else part
Suspicious. |
| SELECT * FROM test_null_as_default ORDER BY s; | ||
| SELECT ''; | ||
|
|
||
| REPLACE TABLE test_null_as_default (s String DEFAULT 'WORLD', ss String DEFAULT 'PEOPLE') ENGINE = Memory; |
There was a problem hiding this comment.
Also it is good to add cases:
- with different types, like
x UInt64, y UInt8 default x - 10 - with recursive defaults, like
x UInt32, y UInt32 default z + 1, z UInt32 default x + 1(and insert into (x, y))
KochetovNicolai
left a comment
There was a problem hiding this comment.
Looks fine in general.
|
There is still a bug: should be easy to reproduce |
4baff4f to
3a9b11e
Compare
|
Functional stateful tests - |
|
Internal documentation ticket: DOCSUP-8939. |
…able column
Required columns of the default expression should not be converted to NULL,
since this map value to default and MATERIALIZED values will not work.
Consider the following structure:
- A Nullable(Int64)
- X Int64 materialized coalesce(A, -1)
With recursive_null_as_default=true you will get:
_CAST(coalesce(A, -1), 'Int64') AS X, NULL AS A
And this will ignore default expression.
Fixes: ClickHouse#23524 (Cc: @kssenii)
Fixes: ClickHouse#29729 (Cc: @tavplubix)
Backport: 21.7+
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
If
insert_null_as_default= 1, insert default values instead of NULL inINSERT ... SELECTandINSERT ... SELECT ... UNION ALL ...queries. Closes #22832.