From bb0d4ba787eef8373fdedada17bc62231155f189 Mon Sep 17 00:00:00 2001 From: AlexYue Date: Wed, 1 Feb 2023 20:07:43 +0800 Subject: [PATCH] [BugFix](sort) use correct agg function when using 2 phase sort for agg table (#16185) --- be/src/olap/tablet_schema.h | 2 ++ be/src/vec/exec/scan/new_olap_scanner.cpp | 2 ++ regression-test/data/query_p0/sort/sort.out | 2 ++ .../suites/query_p0/sort/sort.groovy | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+) diff --git a/be/src/olap/tablet_schema.h b/be/src/olap/tablet_schema.h index 5ae8ef6c48..b1e4a3c82d 100644 --- a/be/src/olap/tablet_schema.h +++ b/be/src/olap/tablet_schema.h @@ -77,6 +77,8 @@ public: int frac() const { return _frac; } inline bool visible() const { return _visible; } + void set_aggregation_method(FieldAggregationMethod agg) { _aggregation = agg; } + /** * Add a sub column. */ diff --git a/be/src/vec/exec/scan/new_olap_scanner.cpp b/be/src/vec/exec/scan/new_olap_scanner.cpp index a6410d85de..a36afecf68 100644 --- a/be/src/vec/exec/scan/new_olap_scanner.cpp +++ b/be/src/vec/exec/scan/new_olap_scanner.cpp @@ -102,6 +102,8 @@ Status NewOlapScanner::prepare(const TPaloScanRange& scan_range, rowid_column.set_has_default_value(true); // fake unique id rowid_column.set_unique_id(INT32_MAX); + rowid_column.set_aggregation_method( + FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE); rowid_column.set_type(FieldType::OLAP_FIELD_TYPE_STRING); _tablet_schema->append_column(rowid_column); } diff --git a/regression-test/data/query_p0/sort/sort.out b/regression-test/data/query_p0/sort/sort.out index 4e898a3f62..3d778981cc 100644 --- a/regression-test/data/query_p0/sort/sort.out +++ b/regression-test/data/query_p0/sort/sort.out @@ -10,3 +10,5 @@ -- !sort_string_on_fe -- true +-- !sql -- + diff --git a/regression-test/suites/query_p0/sort/sort.groovy b/regression-test/suites/query_p0/sort/sort.groovy index 2d41adf192..025ec3f198 100644 --- a/regression-test/suites/query_p0/sort/sort.groovy +++ b/regression-test/suites/query_p0/sort/sort.groovy @@ -23,4 +23,22 @@ suite("sort") { qt_sort_string_single_column """ select * from ( select '汇总' as a union all select '2022-01-01' as a ) a order by 1 """ qt_sort_string_multiple_columns """ select * from ( select '汇总' as a,1 as b union all select '2022-01-01' as a,1 as b ) a order by 1,2 """ qt_sort_string_on_fe """ select '汇总' > '2022-01-01' """ + + sql """CREATE TABLE IF NOT EXISTS Test2PhaseSortWhenAggTable + (`l1` VARCHAR(20) NOT NULL, `l2` VARCHAR(20) NOT NULL, `id` INT REPLACE NOT NULL, `maximum` INT MAX DEFAULT "0" ) + ENGINE=olap AGGREGATE KEY(`l1`, `l2`) PARTITION BY LIST(`l1`, `l2`) ( PARTITION `p1` VALUES IN (("a", "a"), ("b", "b"), ("c", "c")), + PARTITION `p2` VALUES IN (("d", "d"), ("e", "e"), ("f", "f")), PARTITION `p3` VALUES IN (("g", "g"), ("h", "h"), ("i", "i")) ) DISTRIBUTED BY HASH(`l1`) BUCKETS 2 PROPERTIES ( "replication_num" = "1" )""" + + sql """insert into Test2PhaseSortWhenAggTable values ("a", "a", 1, 1), ("b", "b", 3, 2), ("c", "c", 3, 3), ("d", "d", 4, 4), ("e", "e", 5, 5), ("f", "f", 6, 6), ("g", "g", 7, 7), ("h", "h", 8, 8), ("i", "i", 9, 9)""" + + qt_sql """ + SELECT /*+ SET_VAR(query_timeout = 600) */ ref_0.`l1` AS c0, + bitmap_empty() AS c1, + ref_0.`l1` AS c2 + FROM Test2PhaseSortWhenAggTable AS ref_0 + WHERE ref_0.`l2` IS NOT NULL + ORDER BY ref_0.`l1` DESC + LIMIT 110 + OFFSET 130 + """ }