From 9c42280f16c864205cbf15dc0c6289febe179dce Mon Sep 17 00:00:00 2001 From: eldenmoon <15605149486@163.com> Date: Wed, 20 Dec 2023 10:57:20 +0800 Subject: [PATCH] [Fix](Variant) fix variant predicate rewrite OrToIn with wrong plan using the name without paths info will lead to wrong In plan, e.g. ``` where cast(v:a as text) = 'hello' or cast(v:b as text) = 'world' ``` will be rewrite to: ``` where cast(v as text) in ('hello', 'world') `` This is wrong, because they are different slots --- .../main/java/org/apache/doris/analysis/SlotRef.java | 3 +++ .../data/variant_p0/sql/rewrite_or_to_in.out | 12 ++++++++++++ .../suites/variant_p0/sql/rewrite_or_to_in.sql | 6 ++++++ 3 files changed, 21 insertions(+) create mode 100644 regression-test/data/variant_p0/sql/rewrite_or_to_in.out create mode 100644 regression-test/suites/variant_p0/sql/rewrite_or_to_in.sql diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java index 62238b4dfbadac..52894f033a2b5c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java @@ -540,6 +540,9 @@ public boolean hasCol() { } public String getColumnName() { + if (subColPath != null && !subColPath.isEmpty()) { + return col + "." + String.join(".", subColPath); + } return col; } diff --git a/regression-test/data/variant_p0/sql/rewrite_or_to_in.out b/regression-test/data/variant_p0/sql/rewrite_or_to_in.out new file mode 100644 index 00000000000000..81e664e6b10ad8 --- /dev/null +++ b/regression-test/data/variant_p0/sql/rewrite_or_to_in.out @@ -0,0 +1,12 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !rewrite_or_to_in -- +0 + +-- !rewrite_or_to_in_2 -- +DeleteEvent megan777/calculator 2021-01-02T16:37:26Z +DeleteEvent megan777/calculator 2021-01-02T16:37:26Z +DeleteEvent megan777/calculator 2021-01-02T16:37:27Z +PushEvent megan777/calculator 2021-01-02T16:39:09Z +CreateEvent megan777/calculator 2021-01-02T16:39:41Z +PullRequestEvent megan777/calculator 2021-01-02T16:39:41Z + diff --git a/regression-test/suites/variant_p0/sql/rewrite_or_to_in.sql b/regression-test/suites/variant_p0/sql/rewrite_or_to_in.sql new file mode 100644 index 00000000000000..e8fd6ac56052c0 --- /dev/null +++ b/regression-test/suites/variant_p0/sql/rewrite_or_to_in.sql @@ -0,0 +1,6 @@ +set rewrite_or_to_in_predicate_threshold = 2; +select + cast(v:type as string), cast(v:repo.name as string), cast(v:created_at as string) +from ghdata +where cast(v:type as string) = 'Delete' or cast(v:repo.name as string) = 'megan777/calculator' or cast(v:created_as as string) = '2021-01-02T16:37:26Z' +order by k limit 10; \ No newline at end of file