Skip to content

Commit a9f11e5

Browse files
TomaYokostephen
authored andcommitted
(topN)runtime_predicate is only triggered when the column name is obtained (apache#28419)
Issue Number: close apache#27485
1 parent 7af8592 commit a9f11e5

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

‎be/src/vec/exec/vsort_node.cpp‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ Status VSortNode::sink(RuntimeState* state, vectorized::Block* input_block, bool
148148
if (!new_top.is_null() && (old_top.is_null() || new_top != old_top)) {
149149
auto& sort_description = _sorter->get_sort_description();
150150
auto col = input_block->get_by_position(sort_description[0].column_number);
151-
bool is_reverse = sort_description[0].direction < 0;
152-
auto query_ctx = state->get_query_ctx();
153-
RETURN_IF_ERROR(
154-
query_ctx->get_runtime_predicate().update(new_top, col.name, is_reverse));
155-
old_top = std::move(new_top);
151+
if (!col.name.empty()) {
152+
bool is_reverse = sort_description[0].direction < 0;
153+
auto* query_ctx = state->get_query_ctx();
154+
RETURN_IF_ERROR(query_ctx->get_runtime_predicate().update(new_top, col.name,
155+
is_reverse));
156+
old_top = std::move(new_top);
157+
}
156158
}
157159
}
158160
if (!_reuse_mem) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !select --
3+
0
4+
0
5+
1
6+
7+
-- !select --
8+
0
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("topn_runtime_predicate") {
19+
def tableName = "topn_runtime_predicate"
20+
sql "DROP TABLE IF EXISTS ${tableName}"
21+
sql "CREATE TABLE if NOT EXISTS ${tableName} (c1 INT) DUPLICATE KEY(c1) DISTRIBUTED BY HASH (c1) BUCKETS 1 PROPERTIES ('replication_num' = '1');"
22+
sql """insert into ${tableName} values (1),
23+
(0),
24+
(0)"""
25+
qt_select " select * from (select cast(c1 as int) t1 from ${tableName}) t order by t1"
26+
qt_select " select * from (select cast(c1 as int) t1 from ${tableName}) t order by t1 limit 1"
27+
sql "DROP TABLE IF EXISTS ${tableName}"
28+
}

0 commit comments

Comments
 (0)