From f22876302e2c284aa29f0e5e2733860fe4f9c253 Mon Sep 17 00:00:00 2001 From: avogar Date: Thu, 5 Sep 2024 23:37:29 +0000 Subject: [PATCH 1/2] Mark Dynamic type as not safe primary key type to avoid issues with Fields --- src/Processors/QueryPlan/PartsSplitter.cpp | 13 ++----- .../queries/0_stateless/00000_test.reference | 37 +++++++++++++++++++ tests/queries/0_stateless/00000_test.sql | 12 ++++++ ...231_dynamic_not_safe_primary_key.reference | 0 .../03231_dynamic_not_safe_primary_key.sql | 10 +++++ 5 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 tests/queries/0_stateless/00000_test.reference create mode 100644 tests/queries/0_stateless/00000_test.sql create mode 100644 tests/queries/0_stateless/03231_dynamic_not_safe_primary_key.reference create mode 100644 tests/queries/0_stateless/03231_dynamic_not_safe_primary_key.sql diff --git a/src/Processors/QueryPlan/PartsSplitter.cpp b/src/Processors/QueryPlan/PartsSplitter.cpp index 63c10a11913..935af914827 100644 --- a/src/Processors/QueryPlan/PartsSplitter.cpp +++ b/src/Processors/QueryPlan/PartsSplitter.cpp @@ -50,6 +50,9 @@ bool isSafePrimaryDataKeyType(const IDataType & data_type) case TypeIndex::Float64: case TypeIndex::Nullable: case TypeIndex::ObjectDeprecated: + case TypeIndex::Object: + case TypeIndex::Variant: + case TypeIndex::Dynamic: return false; case TypeIndex::Array: { @@ -76,16 +79,6 @@ bool isSafePrimaryDataKeyType(const IDataType & data_type) const auto & data_type_map = static_cast(data_type); return isSafePrimaryDataKeyType(*data_type_map.getKeyType()) && isSafePrimaryDataKeyType(*data_type_map.getValueType()); } - case TypeIndex::Variant: - { - const auto & data_type_variant = static_cast(data_type); - const auto & data_type_variant_elements = data_type_variant.getVariants(); - for (const auto & data_type_variant_element : data_type_variant_elements) - if (!isSafePrimaryDataKeyType(*data_type_variant_element)) - return false; - - return false; - } default: { break; diff --git a/tests/queries/0_stateless/00000_test.reference b/tests/queries/0_stateless/00000_test.reference new file mode 100644 index 00000000000..5374971d501 --- /dev/null +++ b/tests/queries/0_stateless/00000_test.reference @@ -0,0 +1,37 @@ +a +a +a +b +xx +xx +\N +\N +\N +\N +\N +\N +\N +\N +\N +\N +\N +\N +--- + 4 + xx + xx +a 2020-01-01 00:00:00.000 +a 2020-01-01 10:10:10.000 +a 2020-01-01 10:10:10.110 +a 1 +a 1 +a 1 +a a +a a +a b +a \N +a \N +a \N +a \N +a \N +z a diff --git a/tests/queries/0_stateless/00000_test.sql b/tests/queries/0_stateless/00000_test.sql new file mode 100644 index 00000000000..d380f6f69de --- /dev/null +++ b/tests/queries/0_stateless/00000_test.sql @@ -0,0 +1,12 @@ +set max_threads = 1, read_in_order_two_level_merge_threshold = 1; + +CREATE OR REPLACE TABLE test( + key String, + val Map(String, String) +) engine = MergeTree +order by key settings min_bytes_for_wide_part = 0; +insert into test VALUES ('', {'x':'xx'}); +insert into test VALUES ('', {}); +SELECT key, arrayJoin(mapValues(val)) as v FROM test ORDER BY key, v; +DROP TABLE test; + diff --git a/tests/queries/0_stateless/03231_dynamic_not_safe_primary_key.reference b/tests/queries/0_stateless/03231_dynamic_not_safe_primary_key.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/03231_dynamic_not_safe_primary_key.sql b/tests/queries/0_stateless/03231_dynamic_not_safe_primary_key.sql new file mode 100644 index 00000000000..f207581f482 --- /dev/null +++ b/tests/queries/0_stateless/03231_dynamic_not_safe_primary_key.sql @@ -0,0 +1,10 @@ +SET allow_experimental_dynamic_type = 1; +DROP TABLE IF EXISTS t0; +DROP TABLE IF EXISTS t1; +CREATE TABLE t0 (c0 Int) ENGINE = AggregatingMergeTree() ORDER BY (c0); +CREATE TABLE t1 (c0 Array(Dynamic), c1 Int) ENGINE = MergeTree() ORDER BY (c0); +INSERT INTO t1 (c0, c1) VALUES ([18446717433683171873], 13623876564923702671), ([-4], 6111684076076982207); +SELECT 1 FROM t0 FINAL JOIN t1 ON TRUE; +DROP TABLE t0; +DROP TABLE t1; + From ff86b1872f7b0e11367d67dbdaee46a93fa00684 Mon Sep 17 00:00:00 2001 From: avogar Date: Thu, 5 Sep 2024 23:38:31 +0000 Subject: [PATCH 2/2] Remove extra files --- .../queries/0_stateless/00000_test.reference | 37 ------------------- tests/queries/0_stateless/00000_test.sql | 12 ------ 2 files changed, 49 deletions(-) delete mode 100644 tests/queries/0_stateless/00000_test.reference delete mode 100644 tests/queries/0_stateless/00000_test.sql diff --git a/tests/queries/0_stateless/00000_test.reference b/tests/queries/0_stateless/00000_test.reference deleted file mode 100644 index 5374971d501..00000000000 --- a/tests/queries/0_stateless/00000_test.reference +++ /dev/null @@ -1,37 +0,0 @@ -a -a -a -b -xx -xx -\N -\N -\N -\N -\N -\N -\N -\N -\N -\N -\N -\N ---- - 4 - xx - xx -a 2020-01-01 00:00:00.000 -a 2020-01-01 10:10:10.000 -a 2020-01-01 10:10:10.110 -a 1 -a 1 -a 1 -a a -a a -a b -a \N -a \N -a \N -a \N -a \N -z a diff --git a/tests/queries/0_stateless/00000_test.sql b/tests/queries/0_stateless/00000_test.sql deleted file mode 100644 index d380f6f69de..00000000000 --- a/tests/queries/0_stateless/00000_test.sql +++ /dev/null @@ -1,12 +0,0 @@ -set max_threads = 1, read_in_order_two_level_merge_threshold = 1; - -CREATE OR REPLACE TABLE test( - key String, - val Map(String, String) -) engine = MergeTree -order by key settings min_bytes_for_wide_part = 0; -insert into test VALUES ('', {'x':'xx'}); -insert into test VALUES ('', {}); -SELECT key, arrayJoin(mapValues(val)) as v FROM test ORDER BY key, v; -DROP TABLE test; -