Merge pull request #35039 from zzsmdfj/issue/#34890_fix_input_format_null_as_default_bug

to #34890_fix_input_format_null_as_default_bug
This commit is contained in:
Kruglov Pavel 2022-03-21 12:42:17 +01:00 committed by GitHub
commit ed7b40253c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 4 deletions

View File

@ -187,7 +187,7 @@ void AddingDefaultsTransform::transform(Chunk & chunk)
{
const String & column_name = column_def.name;
if (column_defaults.count(column_name) == 0)
if (column_defaults.count(column_name) == 0 || !res.has(column_name))
continue;
size_t block_column_position = res.getPositionByName(column_name);

View File

@ -33,3 +33,9 @@ Values
1 world 3 2019-07-23 [1,2,3] ('tuple',3.14)
2 Hello 123 2019-06-19 [] ('test',2.71828)
3 Hello 42 2019-06-19 [1,2,3] ('default',0.75)
default_by_other_column
1 2 ('tuple',3)
10 10 ('default',2.5)
100 100 ('default',25)
100 100 ('default',25)
100 100 ('default',25)

View File

@ -5,7 +5,9 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../shell_config.sh
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS null_as_default";
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS default_by_other_column";
$CLICKHOUSE_CLIENT --query="CREATE TABLE null_as_default (i Int8, s String DEFAULT 'Hello', n UInt64 DEFAULT 42, d Date DEFAULT '2019-06-19', a Array(UInt8) DEFAULT [1, 2, 3], t Tuple(String, Float64) DEFAULT ('default', i / 4)) ENGINE = Memory";
$CLICKHOUSE_CLIENT --query="CREATE TABLE default_by_other_column (a Float32 DEFAULT 100, b Float64 DEFAULT a, c Tuple(String, Float64) DEFAULT ('default', b / 4)) ENGINE = Memory";
echo 'CSV'
echo '\N, 1, \N, "2019-07-22", "[10, 20, 30]", \N
@ -62,3 +64,12 @@ echo '(NULL, '\''1'\'', (null), '\''2019-07-22'\'', ([10, 20, 30]), (NuLl)),
(3, null, (null), null, (null), (null))' | $CLICKHOUSE_CLIENT --input_format_null_as_default=1 --query="INSERT INTO null_as_default VALUES";
$CLICKHOUSE_CLIENT --query="SELECT * FROM null_as_default ORDER BY i";
$CLICKHOUSE_CLIENT --query="DROP TABLE null_as_default";
echo 'default_by_other_column'
$CLICKHOUSE_CLIENT --input_format_null_as_default=1 --query="INSERT INTO default_by_other_column(c) VALUES(null)";
$CLICKHOUSE_CLIENT --input_format_null_as_default=1 --query="INSERT INTO default_by_other_column(b, c) VALUES(null, null)";
$CLICKHOUSE_CLIENT --input_format_null_as_default=1 --query="INSERT INTO default_by_other_column(a, b, c) VALUES(null, null, null)";
$CLICKHOUSE_CLIENT --input_format_null_as_default=1 --query="INSERT INTO default_by_other_column(a) VALUES(10)";
$CLICKHOUSE_CLIENT --input_format_null_as_default=1 --query="INSERT INTO default_by_other_column(a, b, c) VALUES(1, 2, ('tuple', 3))";
$CLICKHOUSE_CLIENT --query="SELECT * FROM default_by_other_column ORDER BY a";
$CLICKHOUSE_CLIENT --query="DROP TABLE default_by_other_column";

View File

@ -2,6 +2,7 @@ x UInt32 DEFAULT y
y UInt32 EPHEMERAL 17
z UInt32 DEFAULT 5
1 2
17 2
17 5
7 5
21 5

View File

@ -11,9 +11,10 @@ SELECT * FROM t_ephemeral_02205_1;
TRUNCATE TABLE t_ephemeral_02205_1;
# Attempt to use ephemeral through default of ordinary column should end up with error 10 -
# ephemeral only considered when explicitly mentioned in the columns list
INSERT INTO t_ephemeral_02205_1 VALUES (DEFAULT, 2); -- { clientError 10 }
INSERT INTO t_ephemeral_02205_1 VALUES (DEFAULT, 2);
SELECT * FROM t_ephemeral_02205_1;
TRUNCATE TABLE t_ephemeral_02205_1;
# Test INSERT using ephemerals default
INSERT INTO t_ephemeral_02205_1 (x, y) VALUES (DEFAULT, DEFAULT);