This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch dev-1.0.0
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git

commit eb322f542cb37fa49d264b887bfe45fe7499046e
Author: HappenLee <[email protected]>
AuthorDate: Sun Mar 13 09:36:24 2022 +0800

    [improvement](vectorized) Support BetweenPredicate enable fold const expr 
(#8450)
---
 be/src/runtime/mysql_result_writer.cpp                              | 6 ++++--
 be/src/vec/columns/column.h                                         | 4 +++-
 be/src/vec/columns/column_nullable.cpp                              | 2 +-
 be/src/vec/columns/column_nullable.h                                | 2 +-
 be/src/vec/columns/column_vector.cpp                                | 4 ++--
 be/src/vec/exprs/vtuple_is_null_predicate.cpp                       | 6 ++----
 .../src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java   | 6 +++++-
 7 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/be/src/runtime/mysql_result_writer.cpp 
b/be/src/runtime/mysql_result_writer.cpp
index eaf1bd7..2a7de6c 100644
--- a/be/src/runtime/mysql_result_writer.cpp
+++ b/be/src/runtime/mysql_result_writer.cpp
@@ -159,8 +159,10 @@ int MysqlResultWriter::_add_row_value(int index, const 
TypeDescriptor& type, voi
 
     case TYPE_DECIMALV2: {
         DecimalV2Value decimal_val(reinterpret_cast<const 
PackedInt128*>(item)->value);
-        int output_scale = _output_expr_ctxs[index]->root()->output_scale();
-        buf_ret = _row_buffer->push_decimal(decimal_val, output_scale);
+        // TODO: Support decimal output_scale after we support FE can sure
+        // accuracy of output_scale
+        // int output_scale = _output_expr_ctxs[index]->root()->output_scale();
+        buf_ret = _row_buffer->push_decimal(decimal_val, -1);
         break;
     }
 
diff --git a/be/src/vec/columns/column.h b/be/src/vec/columns/column.h
index fdfd85b..07989f4 100644
--- a/be/src/vec/columns/column.h
+++ b/be/src/vec/columns/column.h
@@ -34,6 +34,8 @@ namespace doris::vectorized {
 
 class Arena;
 class Field;
+// TODO: Remove the trickly hint, after FE support better way to remove 
function tuple_is_null
+constexpr uint8_t JOIN_NULL_HINT = 2;
 
 /// Declares interface to store columns in memory.
 class IColumn : public COW<IColumn> {
@@ -164,7 +166,7 @@ public:
     /// indices_begin + indices_end represent the row indices of column src
     /// Warning:
     ///       if *indices == -1 means the row is null, only use in outer join, 
do not use in any other place
-    ///       insert -1 in null map to hint the null is produced by outer join
+    ///       insert JOIN_NULL_HINT in null map to hint the null is produced 
by outer join
     virtual void insert_indices_from(const IColumn& src, const int* 
indices_begin, const int* indices_end) = 0;
 
     /// Appends data located in specified memory chunk if it is possible 
(throws an exception if it cannot be implemented).
diff --git a/be/src/vec/columns/column_nullable.cpp 
b/be/src/vec/columns/column_nullable.cpp
index 9877903..69634ef 100644
--- a/be/src/vec/columns/column_nullable.cpp
+++ b/be/src/vec/columns/column_nullable.cpp
@@ -114,7 +114,7 @@ StringRef ColumnNullable::serialize_value_into_arena(size_t 
n, Arena& arena,
 
     void ColumnNullable::insert_join_null_data() {
         get_nested_column().insert_default();
-        get_null_map_data().push_back(-1);
+        get_null_map_data().push_back(JOIN_NULL_HINT);
     }
 
 const char* ColumnNullable::deserialize_and_insert_from_arena(const char* pos) 
{
diff --git a/be/src/vec/columns/column_nullable.h 
b/be/src/vec/columns/column_nullable.h
index 030ca13..1a792f7 100644
--- a/be/src/vec/columns/column_nullable.h
+++ b/be/src/vec/columns/column_nullable.h
@@ -80,7 +80,7 @@ public:
 
     /// Will insert null value if pos=nullptr
     void insert_data(const char* pos, size_t length) override;
-    /// -1 in null map means null is generated by join, only use in tuple is 
null
+    /// JOIN_NULL_HINT in null map means null is generated by join, only use 
in tuple is null
     void insert_join_null_data();
 
     StringRef serialize_value_into_arena(size_t n, Arena& arena, char const*& 
begin) const override;
diff --git a/be/src/vec/columns/column_vector.cpp 
b/be/src/vec/columns/column_vector.cpp
index 3188a93..dfe1bce 100644
--- a/be/src/vec/columns/column_vector.cpp
+++ b/be/src/vec/columns/column_vector.cpp
@@ -231,8 +231,8 @@ void ColumnVector<T>::insert_indices_from(const IColumn& 
src, const int* indices
             // Now Uint8 use to identify null and non null
             // 1. nullable column : offset == -1 means is null at the here, 
set true here
             // 2. real data column : offset == -1 what at is meaningless
-            // 3. -1 only use in outer join to hint the null is produced by 
outer join
-            data[origin_size + i] = (offset == -1) ? UInt8(-1) : 
src_vec.get_element(offset);
+            // 3. JOIN_NULL_HINT only use in outer join to hint the null is 
produced by outer join
+            data[origin_size + i] = (offset == -1) ? T{JOIN_NULL_HINT} : 
src_vec.get_element(offset);
         } else {
             data[origin_size + i] = (offset == -1) ? T{0} : 
src_vec.get_element(offset);
         }
diff --git a/be/src/vec/exprs/vtuple_is_null_predicate.cpp 
b/be/src/vec/exprs/vtuple_is_null_predicate.cpp
index 7900918..6a5c3eb 100644
--- a/be/src/vec/exprs/vtuple_is_null_predicate.cpp
+++ b/be/src/vec/exprs/vtuple_is_null_predicate.cpp
@@ -41,7 +41,7 @@ Status VTupleIsNullPredicate::prepare(RuntimeState* state, 
const RowDescriptor&
     DCHECK_GT(_tuple_ids.size(), 0);
 
     _column_to_check.reserve(_tuple_ids.size());
-    // Resolve tuple ids to tuple indexes.
+    // Resolve tuple ids to column id, one tuple only need check one column to 
speed up
     for (auto tuple_id : _tuple_ids) {
         uint32_t loc = 0;
         for (auto& tuple_desc : desc.tuple_descriptors()) {
@@ -57,8 +57,6 @@ Status VTupleIsNullPredicate::prepare(RuntimeState* state, 
const RowDescriptor&
 }
 
 Status VTupleIsNullPredicate::execute(VExprContext* context, Block* block, 
int* result_column_id) {
-    // TODO: not execute const expr again, but use the const column in 
function context
-    // call function
     size_t num_columns_without_result = block->columns();
     auto target_rows = block->rows();
     auto ans = ColumnVector<UInt8>::create(target_rows, 1);
@@ -69,7 +67,7 @@ Status VTupleIsNullPredicate::execute(VExprContext* context, 
Block* block, int*
                 
*block->get_by_position(col_id).column).get_null_map_column().get_data().data();
 
         for (int i = 0; i < target_rows; ++i) {
-            ans_map[i] &= null_map[i] == uint8_t(-1);
+            ans_map[i] &= null_map[i] == JOIN_NULL_HINT;
         }
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java
index 8f5137f..918eeeb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java
@@ -19,6 +19,7 @@ package org.apache.doris.rewrite;
 
 
 import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BetweenPredicate;
 import org.apache.doris.analysis.CaseExpr;
 import org.apache.doris.analysis.CastExpr;
 import org.apache.doris.analysis.Expr;
@@ -206,6 +207,10 @@ public class FoldConstantsRule implements ExprRewriteRule {
             if (expr instanceof LiteralExpr) {
                 return;
             }
+            // skip BetweenPredicate need to be rewrite to CompoundPredicate
+            if (expr instanceof BetweenPredicate) {
+                return;
+            }
             // collect sysVariableDesc expr
             if (expr.contains(Predicates.instanceOf(SysVariableDesc.class))) {
                 getSysVarDescExpr(expr, sysVarMap);
@@ -385,7 +390,6 @@ public class FoldConstantsRule implements ExprRewriteRule {
             LOG.warn("failed to get const expr value from be: {}", 
e.getMessage());
         }
         return resultMap;
-
     }
 }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to