[Bug](function) Fix constant predicate evaluation (#13346)

This commit is contained in:
Gabriel
2022-10-15 01:05:29 +08:00
committed by GitHub
parent 79a5125eff
commit 8218cfed40
6 changed files with 72 additions and 9 deletions

View File

@ -543,11 +543,20 @@ void VScanNode::_eval_const_conjuncts(VExpr* vexpr, VExprContext* expr_ctx, Push
// But now we still don't cover all predicates for const expression.
// For example, for query `SELECT col FROM tbl WHERE 'PROMOTION' LIKE 'AAA%'`,
// predicate `like` will return a ColumnVector<UInt8> which contains a single value.
LOG(WARNING) << "Expr[" << vexpr->debug_string()
<< "] should return a const column but actually is "
<< vexpr->get_const_col(expr_ctx)->column_ptr->get_name();
DCHECK_EQ(bool_column->size(), 1);
constant_val = const_cast<char*>(bool_column->get_data_at(0).data);
if (constant_val == nullptr || *reinterpret_cast<bool*>(constant_val) == false) {
*pdt = PushDownType::ACCEPTABLE;
_eos = true;
if (bool_column->size() == 1) {
constant_val = const_cast<char*>(bool_column->get_data_at(0).data);
if (constant_val == nullptr || *reinterpret_cast<bool*>(constant_val) == false) {
*pdt = PushDownType::ACCEPTABLE;
_eos = true;
}
} else {
LOG(WARNING) << "Constant predicate in scan node should return a bool column with "
"`size == 1` but actually is "
<< bool_column->size();
}
} else {
LOG(WARNING) << "Expr[" << vexpr->debug_string()

View File

@ -1658,10 +1658,16 @@ void VOlapScanNode::eval_const_conjuncts(VExpr* vexpr, VExprContext* expr_ctx, b
<< "] should return a const column but actually is "
<< vexpr->get_const_col(expr_ctx)->column_ptr->get_name();
DCHECK_EQ(bool_column->size(), 1);
constant_val = const_cast<char*>(bool_column->get_data_at(0).data);
if (constant_val == nullptr || *reinterpret_cast<bool*>(constant_val) == false) {
*push_down = true;
_eos = true;
if (bool_column->size() == 1) {
constant_val = const_cast<char*>(bool_column->get_data_at(0).data);
if (constant_val == nullptr || *reinterpret_cast<bool*>(constant_val) == false) {
*push_down = true;
_eos = true;
}
} else {
LOG(WARNING) << "Constant predicate in scan node should return a bool column with "
"`size == 1` but actually is "
<< bool_column->size();
}
} else {
LOG(WARNING) << "Expr[" << vexpr->debug_string()

View File

@ -319,6 +319,9 @@ ColumnPtrWrapper* VExpr::get_const_col(VExprContext* context) {
int result = -1;
Block block;
// If block is empty, some functions will produce no result. So we insert a column with
// single value here.
block.insert({ColumnUInt8::create(1), std::make_shared<DataTypeUInt8>(), ""});
execute(context, &block, &result);
DCHECK(result != -1);
const auto& column = block.get_by_position(result).column;

View File

@ -31,7 +31,7 @@ public:
String get_name() const override { return name; }
bool use_default_implementation_for_constants() const override { return false; }
bool use_default_implementation_for_constants() const override { return true; }
bool use_default_implementation_for_nulls() const override { return false; }

View File

@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
1

View File

@ -0,0 +1,41 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
suite("test_pushdown_constant") {
sql """ DROP TABLE IF EXISTS `test_pushdown_constant` """
sql """
CREATE TABLE `test_pushdown_constant` (
`id` int
) ENGINE=OLAP
AGGREGATE KEY(`id`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
);
"""
sql """
insert into test_pushdown_constant values(1);
"""
qt_sql """
select 1 from test_pushdown_constant where BITMAP_MAX( BITMAP_AND(BITMAP_EMPTY(), coalesce(NULL, bitmap_empty()))) is NULL;
"""
}