From b89ddd16fd5a666e430e8daec9b213402237bcf0 Mon Sep 17 00:00:00 2001 From: amorynan Date: Tue, 28 Nov 2023 21:17:39 +0800 Subject: [PATCH 1/4] fix array/map/struct impl hashcode and equals --- .../apache/doris/analysis/ArrayLiteral.java | 27 +++++++ .../org/apache/doris/analysis/MapLiteral.java | 27 +++++++ .../apache/doris/analysis/StructLiteral.java | 26 +++++++ .../sql_functions/array_functions/sql/q04.out | 24 +++++++ .../sql_functions/array_functions/sql/q04.sql | 72 +++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 regression-test/data/query_p0/sql_functions/array_functions/sql/q04.out create mode 100644 regression-test/suites/query_p0/sql_functions/array_functions/sql/q04.sql diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java index d73c4036c9573c..467a16e8a489a5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java @@ -134,6 +134,33 @@ protected void toThrift(TExprNode msg) { msg.setChildType(((ArrayType) type).getItemType().getPrimitiveType().toThrift()); } + @Override + public int hashCode() { + int code = 31 * super.hashCode(); + for (Expr c : children) { + code = code + c.hashCode(); + } + return code; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof ArrayLiteral)) { + return false; + } + if (this == o) { + return true; + } + + ArrayLiteral that = (ArrayLiteral) o; + for (int i = 0; i < children.size(); i++) { + if (!children.get(i).equals(that.children.get(i))) { + return false; + } + } + return true; + } + @Override public void write(DataOutput out) throws IOException { super.write(out); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java index ead27d9e985e15..4bfe5003c017ed 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java @@ -218,4 +218,31 @@ public void write(DataOutput out) throws IOException { Expr.writeTo(e, out); } } + + @Override + public int hashCode() { + int code = 31 * super.hashCode(); + for (Expr c : children) { + code = code + c.hashCode(); + } + return code; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof MapLiteral)) { + return false; + } + if (this == o) { + return true; + } + + MapLiteral that = (MapLiteral) o; + for (int i = 0; i < children.size(); i++) { + if (!children.get(i).equals(that.children.get(i))) { + return false; + } + } + return true; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java index 0198826eec6bbd..9bf313c65c1916 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java @@ -164,4 +164,30 @@ public void checkValueValid() throws AnalysisException { e.checkValueValid(); } } + + public int hashCode() { + int code = 31 * super.hashCode(); + for (Expr c : children) { + code = code + c.hashCode(); + } + return code; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof StructLiteral)) { + return false; + } + if (this == o) { + return true; + } + + StructLiteral that = (StructLiteral) o; + for (int i = 0; i < children.size(); i++) { + if (!children.get(i).equals(that.children.get(i))) { + return false; + } + } + return true; + } } diff --git a/regression-test/data/query_p0/sql_functions/array_functions/sql/q04.out b/regression-test/data/query_p0/sql_functions/array_functions/sql/q04.out new file mode 100644 index 00000000000000..e2e563600d25f2 --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/array_functions/sql/q04.out @@ -0,0 +1,24 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !q04 -- +0 + +-- !q04_2 -- +0 + +-- !q04_3 -- +1 + +-- !q04_4 -- +1 + +-- !q04_5 -- +1 + +-- !q04_6 -- +1 + +-- !q04_7 -- +22,25,34 + +-- !q04_8 -- + diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/sql/q04.sql b/regression-test/suites/query_p0/sql_functions/array_functions/sql/q04.sql new file mode 100644 index 00000000000000..0e26d95d0606a6 --- /dev/null +++ b/regression-test/suites/query_p0/sql_functions/array_functions/sql/q04.sql @@ -0,0 +1,72 @@ +DROP TABLE IF EXISTS ads_pi_cuser_all_info; +CREATE TABLE IF NOT EXISTS ads_pi_cuser_all_info ( + `corp_id` varchar(64) NOT NULL COMMENT '机构ID', + `staff_id` varchar(64) NOT NULL COMMENT '客户经理ID', + `external_user_id` varchar(64) NOT NULL COMMENT '外部联系人ID', + `is_deleted` int(11) REPLACE_IF_NOT_NULL NULL COMMENT '删除好友标识', + `main_id` largeint(40) REPLACE_IF_NOT_NULL NULL COMMENT '用户main_id', + `birthday` varchar(32) REPLACE_IF_NOT_NULL NULL COMMENT '客户生日', + `gender` tinyint(4) REPLACE_IF_NOT_NULL NULL COMMENT '用户性别', + `avater` text REPLACE_IF_NOT_NULL NULL COMMENT '用户头像地址', + `name` text REPLACE_IF_NOT_NULL NULL COMMENT '用户姓名', + `remark_name` text REPLACE_IF_NOT_NULL NULL COMMENT '客户经理备注姓名', + `type` tinyint(4) REPLACE_IF_NOT_NULL NULL, + `client_number` varchar(64) REPLACE_IF_NOT_NULL NULL COMMENT '上一次行为码', + `M0000001` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000002` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000003` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000004` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000005` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000006` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000007` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000008` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000009` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000010` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000011` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000012` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000013` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000014` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000015` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000016` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000017` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000018` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000019` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `M0000020` int(11) SUM NOT NULL DEFAULT "0" COMMENT '预设用例分值,1000000取余', + `product_reach_times` int(11) SUM NOT NULL DEFAULT "0" COMMENT '本周产品触达次数,每自然周自动清零', + `common_reach_times` int(11) SUM NOT NULL DEFAULT "0" COMMENT '本周通用触达次数,每自然周自动清零', + `last_action` varchar(64) REPLACE_IF_NOT_NULL NULL COMMENT '上一次行为码', + `qw_tag_ids` text REPLACE_IF_NOT_NULL NULL COMMENT '企微标签,使用逗号分隔', + `stgy_tag_ids` text REPLACE_IF_NOT_NULL NULL COMMENT '企微标签,使用逗号分隔', + `last_reached_task_id` largeint(40) REPLACE_IF_NOT_NULL NULL COMMENT '上一次触达任务ID', + `last_reached_task_score` int(11) REPLACE_IF_NOT_NULL NULL COMMENT '上一次触达阶段分值', + `current_max_score_mode` text REPLACE_IF_NOT_NULL NULL COMMENT '分值最高的用例字段名,逗号分隔' +) ENGINE=OLAP +AGGREGATE KEY(`corp_id`, `staff_id`, `external_user_id`) +COMMENT 'OLAP' +DISTRIBUTED BY HASH(`staff_id`) BUCKETS 3 +PROPERTIES ( +"replication_allocation" = "tag.location.default: 1", +"is_being_synced" = "false", +"storage_format" = "V2", +"light_schema_change" = "true", +"disable_auto_compaction" = "false", +"enable_single_replica_compaction" = "false" +); + +INSERT INTO ads_pi_cuser_all_info +(corp_id, staff_id, external_user_id, is_deleted, main_id, birthday, gender, avater, name, remark_name, `type`, client_number, M0000001, M0000002, M0000003, M0000004, M0000005, M0000006, M0000007, M0000008, M0000009, M0000010, M0000011, M0000012, M0000013, M0000014, M0000015, M0000016, M0000017, M0000018, M0000019, M0000020, product_reach_times, common_reach_times, last_action, qw_tag_ids, stgy_tag_ids, last_reached_task_id, last_reached_task_score, current_max_score_mode) +VALUES('ww36b98e83f52f6bcc', '0af73fc236bf444aadc801cd4c416539', 'wmfvPXDAAA7OrmzTSkEVRkphuGx3hSVA', 0, '1604732822185627669', '', 2, 'http://wx.qlogo.cn/mmhead/9M0PhLTmTIeHGOibG2yxg90drr4nhu6NuJ5O4J9bskXicNShwsiaukk6g/0', 'mate20.0410q', 'mate20.0410q', 1, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, '45,34,22', NULL, '275', 0, NULL); +INSERT INTO ads_pi_cuser_all_info +(corp_id, staff_id, external_user_id, is_deleted, main_id, birthday, gender, avater, name, remark_name, `type`, client_number, M0000001, M0000002, M0000003, M0000004, M0000005, M0000006, M0000007, M0000008, M0000009, M0000010, M0000011, M0000012, M0000013, M0000014, M0000015, M0000016, M0000017, M0000018, M0000019, M0000020, product_reach_times, common_reach_times, last_action, qw_tag_ids, stgy_tag_ids, last_reached_task_id, last_reached_task_score, current_max_score_mode) +VALUES('ww36b98e83f52f6bcc', '0af73fc236bf444aadc801cd4c416539', 'wmfvPXDAAAHCcW-cFR5U2yPG5zfAS4rg', 0, '1600777478614724671', '', 0, 'http://wx.qlogo.cn/mmhead/Q3auHgzwzM43qyI9vM4Q8jYrdl7ia8FakbibeTWnSmTVu7QjtxHLJib2g/0', 'iPhoneXS', 'iPhoneXS', 1, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, '56,34,35', NULL, NULL, NULL); +INSERT INTO ads_pi_cuser_all_info +(corp_id, staff_id, external_user_id, is_deleted, main_id, birthday, gender, avater, name, remark_name, `type`, client_number, M0000001, M0000002, M0000003, M0000004, M0000005, M0000006, M0000007, M0000008, M0000009, M0000010, M0000011, M0000012, M0000013, M0000014, M0000015, M0000016, M0000017, M0000018, M0000019, M0000020, product_reach_times, common_reach_times, last_action, qw_tag_ids, stgy_tag_ids, last_reached_task_id, last_reached_task_score, current_max_score_mode) +VALUES('ww36b98e83f52f6bcc1', '0af73fc236bf444aadc801cd4c416539', 'wmfvPXDAAA7OrmzTSkEVRkphuGx3hSVA', 0, '1604732822185627669', '', 2, 'http://wx.qlogo.cn/mmhead/9M0PhLTmTIeHGOibG2yxg90drr4nhu6NuJ5O4J9bskXicNShwsiaukk6g/0', 'mate20.0410q', 'mate20.0410q', 1, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, '45,34', '275', 0, NULL); +INSERT INTO ads_pi_cuser_all_info +(corp_id, staff_id, external_user_id, is_deleted, main_id, birthday, gender, avater, name, remark_name, `type`, client_number, M0000001, M0000002, M0000003, M0000004, M0000005, M0000006, M0000007, M0000008, M0000009, M0000010, M0000011, M0000012, M0000013, M0000014, M0000015, M0000016, M0000017, M0000018, M0000019, M0000020, product_reach_times, common_reach_times, last_action, qw_tag_ids, stgy_tag_ids, last_reached_task_id, last_reached_task_score, current_max_score_mode) +VALUES('ww36b98e83f52f6bcc2', '0af73fc236bf444aadc801cd4c416539', 'wmfvPXDAAAHCcW-cFR5U2yPG5zfAS4rg', 0, '1600777478614724671', '', 0, 'http://wx.qlogo.cn/mmhead/Q3auHgzwzM43qyI9vM4Q8jYrdl7ia8FakbibeTWnSmTVu7QjtxHLJib2g/0', 'iPhoneXS', 'iPhoneXS', 1, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, '22,25,34', NULL, NULL, NULL); + + +select stgy_tag_ids from ads_pi_cuser_all_info WHERE arrays_overlap(split_by_string(stgy_tag_ids,','),['23','22']); + +select * from ads_pi_cuser_all_info WHERE arrays_overlap(split_by_string(stgy_tag_ids,','),['23','22']) and arrays_overlap(split_by_string(stgy_tag_ids,','),['35']); \ No newline at end of file From 1e74341fdbd33fc4ca480e13b24b09713b4dc7dc Mon Sep 17 00:00:00 2001 From: amorynan Date: Wed, 29 Nov 2023 11:02:37 +0800 Subject: [PATCH 2/4] fixed --- .../apache/doris/analysis/ArrayLiteral.java | 19 ++++++++----------- .../org/apache/doris/analysis/MapLiteral.java | 18 ++++++++---------- .../apache/doris/analysis/StructLiteral.java | 18 ++++++++---------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java index 467a16e8a489a5..6fe0cbb7440b3d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; public class ArrayLiteral extends LiteralExpr { @@ -136,29 +137,25 @@ protected void toThrift(TExprNode msg) { @Override public int hashCode() { - int code = 31 * super.hashCode(); - for (Expr c : children) { - code = code + c.hashCode(); - } - return code; + return Objects.hashCode(children); } @Override public boolean equals(Object o) { + if (o == null) { + return false; + } if (!(o instanceof ArrayLiteral)) { return false; } if (this == o) { return true; } - ArrayLiteral that = (ArrayLiteral) o; - for (int i = 0; i < children.size(); i++) { - if (!children.get(i).equals(that.children.get(i))) { - return false; - } + if (that.children.size() != children.size()) { + return false; } - return true; + return Objects.equals(children, that.children); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java index 4bfe5003c017ed..eb7acfe590bc1d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; // INSERT INTO table_map VALUES ({'key1':1, 'key2':10, 'k3':100}), ({'key1':2,'key2':20}), ({'key1':3,'key2':30}); @@ -221,15 +222,14 @@ public void write(DataOutput out) throws IOException { @Override public int hashCode() { - int code = 31 * super.hashCode(); - for (Expr c : children) { - code = code + c.hashCode(); - } - return code; + return Objects.hashCode(children); } @Override public boolean equals(Object o) { + if (o == null) { + return false; + } if (!(o instanceof MapLiteral)) { return false; } @@ -238,11 +238,9 @@ public boolean equals(Object o) { } MapLiteral that = (MapLiteral) o; - for (int i = 0; i < children.size(); i++) { - if (!children.get(i).equals(that.children.get(i))) { - return false; - } + if (that.children.size() != children.size()) { + return false; } - return true; + return Objects.equals(children, that.children); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java index 9bf313c65c1916..cc53be627b3175 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class StructLiteral extends LiteralExpr { // only for persist @@ -166,15 +167,14 @@ public void checkValueValid() throws AnalysisException { } public int hashCode() { - int code = 31 * super.hashCode(); - for (Expr c : children) { - code = code + c.hashCode(); - } - return code; + return Objects.hashCode(children); } @Override public boolean equals(Object o) { + if (o == null) { + return false; + } if (!(o instanceof StructLiteral)) { return false; } @@ -183,11 +183,9 @@ public boolean equals(Object o) { } StructLiteral that = (StructLiteral) o; - for (int i = 0; i < children.size(); i++) { - if (!children.get(i).equals(that.children.get(i))) { - return false; - } + if (that.children.size() != children.size()) { + return false; } - return true; + return Objects.equals(children, that.children); } } From f7ef4a71467c4530d2dbc9a43b5d36da19a8cd64 Mon Sep 17 00:00:00 2001 From: amorynan Date: Wed, 29 Nov 2023 16:25:11 +0800 Subject: [PATCH 3/4] fix wrong if --- .../main/java/org/apache/doris/analysis/ArrayLiteral.java | 6 ------ .../src/main/java/org/apache/doris/analysis/MapLiteral.java | 6 ------ 2 files changed, 12 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java index 6fe0cbb7440b3d..415a4b6067caee 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java @@ -142,9 +142,6 @@ public int hashCode() { @Override public boolean equals(Object o) { - if (o == null) { - return false; - } if (!(o instanceof ArrayLiteral)) { return false; } @@ -152,9 +149,6 @@ public boolean equals(Object o) { return true; } ArrayLiteral that = (ArrayLiteral) o; - if (that.children.size() != children.size()) { - return false; - } return Objects.equals(children, that.children); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java index eb7acfe590bc1d..6135e04b731686 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java @@ -227,9 +227,6 @@ public int hashCode() { @Override public boolean equals(Object o) { - if (o == null) { - return false; - } if (!(o instanceof MapLiteral)) { return false; } @@ -238,9 +235,6 @@ public boolean equals(Object o) { } MapLiteral that = (MapLiteral) o; - if (that.children.size() != children.size()) { - return false; - } return Objects.equals(children, that.children); } } From 0e1e7b9a6ae9a891a9ff4973d8181196d3697d14 Mon Sep 17 00:00:00 2001 From: amorynan Date: Wed, 29 Nov 2023 16:28:04 +0800 Subject: [PATCH 4/4] fix if struct --- .../main/java/org/apache/doris/analysis/StructLiteral.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java index cc53be627b3175..d4327fb979b364 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java @@ -172,9 +172,6 @@ public int hashCode() { @Override public boolean equals(Object o) { - if (o == null) { - return false; - } if (!(o instanceof StructLiteral)) { return false; } @@ -183,9 +180,6 @@ public boolean equals(Object o) { } StructLiteral that = (StructLiteral) o; - if (that.children.size() != children.size()) { - return false; - } return Objects.equals(children, that.children); } }