You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ga...@apache.org on 2022/10/14 17:05:38 UTC
[doris] branch master updated: [Bug](function) Fix constant predicate evaluation (#13346)
This is an automated email from the ASF dual-hosted git repository.
gabriellee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 8218cfed40 [Bug](function) Fix constant predicate evaluation (#13346)
8218cfed40 is described below
commit 8218cfed4097f14c6dc273dcecdcb6aac26cd10b
Author: Gabriel <ga...@gmail.com>
AuthorDate: Sat Oct 15 01:05:29 2022 +0800
[Bug](function) Fix constant predicate evaluation (#13346)
---
be/src/vec/exec/scan/vscan_node.cpp | 17 ++++++---
be/src/vec/exec/volap_scan_node.cpp | 14 +++++---
be/src/vec/exprs/vexpr.cpp | 3 ++
be/src/vec/functions/function_coalesce.cpp | 2 +-
.../data/correctness_p0/test_pushdown_constant.out | 4 +++
.../correctness_p0/test_pushdown_constant.groovy | 41 ++++++++++++++++++++++
6 files changed, 72 insertions(+), 9 deletions(-)
diff --git a/be/src/vec/exec/scan/vscan_node.cpp b/be/src/vec/exec/scan/vscan_node.cpp
index 1718d83697..81a1c80d54 100644
--- a/be/src/vec/exec/scan/vscan_node.cpp
+++ b/be/src/vec/exec/scan/vscan_node.cpp
@@ -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()
diff --git a/be/src/vec/exec/volap_scan_node.cpp b/be/src/vec/exec/volap_scan_node.cpp
index b8eb4ae262..533d625226 100644
--- a/be/src/vec/exec/volap_scan_node.cpp
+++ b/be/src/vec/exec/volap_scan_node.cpp
@@ -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()
diff --git a/be/src/vec/exprs/vexpr.cpp b/be/src/vec/exprs/vexpr.cpp
index 3d1a0d847f..0fe5d9296f 100644
--- a/be/src/vec/exprs/vexpr.cpp
+++ b/be/src/vec/exprs/vexpr.cpp
@@ -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;
diff --git a/be/src/vec/functions/function_coalesce.cpp b/be/src/vec/functions/function_coalesce.cpp
index e90e054fd1..1d1ae5d593 100644
--- a/be/src/vec/functions/function_coalesce.cpp
+++ b/be/src/vec/functions/function_coalesce.cpp
@@ -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; }
diff --git a/regression-test/data/correctness_p0/test_pushdown_constant.out b/regression-test/data/correctness_p0/test_pushdown_constant.out
new file mode 100644
index 0000000000..095c7b2035
--- /dev/null
+++ b/regression-test/data/correctness_p0/test_pushdown_constant.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !sql --
+1
+
diff --git a/regression-test/suites/correctness_p0/test_pushdown_constant.groovy b/regression-test/suites/correctness_p0/test_pushdown_constant.groovy
new file mode 100644
index 0000000000..a831aef66c
--- /dev/null
+++ b/regression-test/suites/correctness_p0/test_pushdown_constant.groovy
@@ -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;
+ """
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org