You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/06/30 06:03:54 UTC

[GitHub] [doris] wsjz opened a new pull request, #10512: [draft][vectorization][feature] parquet push down support

wsjz opened a new pull request, #10512:
URL: https://github.com/apache/doris/pull/10512

   # Proposed changes
   
   Issue Number: close #xxx
   
   ## Problem Summary:
   
   Describe the overview of changes.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (Yes/No/I Don't know)
   2. Has unit tests been added: (Yes/No/No Need)
   3. Has document been added or modified: (Yes/No/No Need)
   4. Does it need to update dependencies: (Yes/No)
   5. Are there any changes that cannot be rolled back: (Yes/No)
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] yinzhijian commented on pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
yinzhijian commented on PR #10512:
URL: https://github.com/apache/doris/pull/10512#issuecomment-1172261821

   We may need to add a check to the unit tests to see if the filter function really works


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] wsjz commented on pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
wsjz commented on PR #10512:
URL: https://github.com/apache/doris/pull/10512#issuecomment-1171432393

   这是来自QQ邮箱的假期自动回复邮件。
   好,我最近正在休假中
   
    
   您,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #10512:
URL: https://github.com/apache/doris/pull/10512#issuecomment-1178532580

   PR approved by at least one committer and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #10512:
URL: https://github.com/apache/doris/pull/10512#issuecomment-1178840627

   PR approved by at least one committer and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] wsjz commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
wsjz commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r912863720


##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();
+            std::string max = statistic->EncodeMax();
+
+            LOG(INFO) << "Stat min:" << parquet::FormatStatValue(statistic->physical_type(), min);
+            LOG(INFO) << "Stat max:" << parquet::FormatStatValue(statistic->physical_type(), max);
+            bool need_filter = false;
+            _determine_filter_row_group(slot_iter->second, min, max, need_filter);
+            if (need_filter) {
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    return Status::OK();
+}
+
+void RowGroupReader::_init_conjuncts(const TupleDescriptor* tuple_desc,
+                                     const std::map<std::string, int>& map_column,
+                                     const std::unordered_set<int>& include_column_ids) {
+    for (int i = 0; i < tuple_desc->slots().size(); i++) {
+        auto col_iter = map_column.find(tuple_desc->slots()[i]->col_name());
+        if (col_iter == map_column.end()) {
+            continue;
+        }
+        int parquet_col_id = col_iter->second;
+        if (include_column_ids.end() == include_column_ids.find(parquet_col_id)) {
+            continue;
+        }
+        for (int conj_idx = 0; conj_idx < _conjunct_ctxs.size(); conj_idx++) {
+            Expr* conjunct = _conjunct_ctxs[conj_idx]->root();
+            if (conjunct->get_num_children() == 0) {
+                continue;
+            }
+            Expr* raw_slot = conjunct->get_child(0);
+            if (TExprNodeType::SLOT_REF != raw_slot->node_type()) {
+                continue;
+            }
+            SlotRef* slot_ref = (SlotRef*)raw_slot;
+            SlotId conjunct_slot_id = slot_ref->slot_id();
+            if (conjunct_slot_id == tuple_desc->slots()[i]->id()) {
+                // Get conjuncts by conjunct_slot_id
+                auto iter = _slot_conjuncts.find(conjunct_slot_id);
+                if (_slot_conjuncts.end() == iter) {
+                    std::vector<ExprContext*> conjuncts;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                    _slot_conjuncts.emplace(std::make_pair(conjunct_slot_id, conjuncts));
+                } else {
+                    std::vector<ExprContext*> conjuncts = iter->second;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);

Review Comment:
   it has been in the map _slot_conjuncts  yet, just update



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morningman commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
morningman commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r911231300


##########
be/src/vec/exec/file_scan_node.cpp:
##########
@@ -315,6 +315,7 @@ std::unique_ptr<FileScanner> FileScanNode::create_scanner(const TFileScanRange&
         scan = new FileTextScanner(_runtime_state, runtime_profile(), scan_range.params,
                                    scan_range.ranges, _pre_filter_texprs, counter);
     }
+    scan->reg_conjunct_ctxs(_tuple_id, _conjunct_ctxs);

Review Comment:
   I think we should pass `_vconjunct_ctx_ptr` for vec engine, not `_conjunct_ctxs`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] yinzhijian commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
yinzhijian commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r911881793


##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();
+            std::string max = statistic->EncodeMax();
+
+            LOG(INFO) << "Stat min:" << parquet::FormatStatValue(statistic->physical_type(), min);
+            LOG(INFO) << "Stat max:" << parquet::FormatStatValue(statistic->physical_type(), max);
+            bool need_filter = false;
+            _determine_filter_row_group(slot_iter->second, min, max, need_filter);
+            if (need_filter) {
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    return Status::OK();
+}
+
+void RowGroupReader::_init_conjuncts(const TupleDescriptor* tuple_desc,
+                                     const std::map<std::string, int>& map_column,
+                                     const std::unordered_set<int>& include_column_ids) {
+    for (int i = 0; i < tuple_desc->slots().size(); i++) {
+        auto col_iter = map_column.find(tuple_desc->slots()[i]->col_name());
+        if (col_iter == map_column.end()) {
+            continue;
+        }
+        int parquet_col_id = col_iter->second;
+        if (include_column_ids.end() == include_column_ids.find(parquet_col_id)) {
+            continue;
+        }
+        for (int conj_idx = 0; conj_idx < _conjunct_ctxs.size(); conj_idx++) {
+            Expr* conjunct = _conjunct_ctxs[conj_idx]->root();
+            if (conjunct->get_num_children() == 0) {
+                continue;
+            }
+            Expr* raw_slot = conjunct->get_child(0);
+            if (TExprNodeType::SLOT_REF != raw_slot->node_type()) {
+                continue;
+            }
+            SlotRef* slot_ref = (SlotRef*)raw_slot;
+            SlotId conjunct_slot_id = slot_ref->slot_id();
+            if (conjunct_slot_id == tuple_desc->slots()[i]->id()) {
+                // Get conjuncts by conjunct_slot_id
+                auto iter = _slot_conjuncts.find(conjunct_slot_id);
+                if (_slot_conjuncts.end() == iter) {
+                    std::vector<ExprContext*> conjuncts;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                    _slot_conjuncts.emplace(std::make_pair(conjunct_slot_id, conjuncts));
+                } else {
+                    std::vector<ExprContext*> conjuncts = iter->second;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                }
+            }
+        }
+    }
+}
+
+void RowGroupReader::_determine_filter_row_group(const std::vector<ExprContext*>& conjuncts,
+                                                 const std::string& encoded_min,
+                                                 const std::string& encoded_max,
+                                                 bool& need_filter) {
+    const char* min_bytes = encoded_min.data();
+    const char* max_bytes = encoded_max.data();
+    for (int i = 0; i < conjuncts.size(); i++) {
+        Expr* conjunct = conjuncts[i]->root();
+        if (TExprNodeType::BINARY_PRED == conjunct->node_type()) {
+            _eval_binary_predicate(conjuncts[i], min_bytes, max_bytes, need_filter);
+        } else if (TExprNodeType::IN_PRED == conjunct->node_type()) {
+            _eval_in_predicate(conjuncts[i], min_bytes, max_bytes, need_filter);
+        }
+    }
+}
+
+void RowGroupReader::_eval_binary_predicate(ExprContext* ctx, const char* min_bytes,
+                                            const char* max_bytes, bool& need_filter) {
+    Expr* conjunct = ctx->root();
+    Expr* expr = conjunct->get_child(1);
+    auto conjunct_type = expr->type().type;
+    void* conjunct_value = ctx->get_value(expr, nullptr);
+    switch (conjunct->op()) {
+    case TExprOpcode::EQ:
+        need_filter = _eval_eq(conjunct_type, conjunct_value, min_bytes, max_bytes);
+        break;
+    case TExprOpcode::NE:
+        break;
+    case TExprOpcode::GT:
+        need_filter = _eval_gt(conjunct_type, conjunct_value, max_bytes);
+        break;
+    case TExprOpcode::GE:
+        need_filter = _eval_ge(conjunct_type, conjunct_value, max_bytes);
+        break;
+    case TExprOpcode::LT:
+        need_filter = _eval_lt(conjunct_type, conjunct_value, min_bytes);
+        break;
+    case TExprOpcode::LE:
+        need_filter = _eval_le(conjunct_type, conjunct_value, min_bytes);
+        break;
+    default:
+        break;
+    }
+}
+
+void RowGroupReader::_eval_in_predicate(ExprContext* ctx, const char* min_bytes,
+                                        const char* max_bytes, bool& need_filter) {
+    Expr* conjunct = ctx->root();
+    std::vector<void*> in_pred_values;
+    const InPredicate* pred = static_cast<const InPredicate*>(conjunct);
+    HybridSetBase::IteratorBase* iter = pred->hybrid_set()->begin();
+    while (iter->has_next()) {
+        if (nullptr == iter->get_value()) {
+            return;
+        }
+        in_pred_values.emplace_back(const_cast<void*>(iter->get_value()));
+        iter->next();
+    }
+    auto conjunct_type = conjunct->get_child(1)->type().type;
+    switch (conjunct->op()) {
+    case TExprOpcode::FILTER_IN:
+        _eval_in_val(conjunct_type, in_pred_values, min_bytes, max_bytes);
+        break;
+    case TExprOpcode::FILTER_NOT_IN:
+        break;
+    default:
+        break;
+    }
+}
+
+bool RowGroupReader::_eval_in_val(PrimitiveType conjunct_type, std::vector<void*> in_pred_values,
+                                  const char* min_bytes, const char* max_bytes) {
+    switch (conjunct_type) {
+    case TYPE_TINYINT: {
+        _FILTER_GROUP_BY_IN(int8_t, in_pred_values, min_bytes, max_bytes)
+        break;
+    }
+    case TYPE_SMALLINT: {
+        _FILTER_GROUP_BY_IN(int16_t, in_pred_values, min_bytes, max_bytes)
+        break;
+    }
+    case TYPE_INT: {
+        _FILTER_GROUP_BY_IN(int32_t, in_pred_values, min_bytes, max_bytes)
+        break;
+    }
+    case TYPE_BIGINT: {
+        _FILTER_GROUP_BY_IN(int64_t, in_pred_values, min_bytes, max_bytes)
+        break;
+    }
+    case TYPE_STRING:
+    case TYPE_DATE:
+    case TYPE_DATETIME: {
+        std::vector<char*> in_values;
+        for (auto val : in_pred_values) {
+            char* value = reinterpret_cast<char**>(val)[0];
+            in_values.emplace_back(value);
+        }
+        if (in_values.empty()) {
+            return false;
+        }
+        if (in_values.size() >= 2) {

Review Comment:
   There seems to be no need to determine whether >= 2, both can use this logic



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] SaintBacchus commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
SaintBacchus commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r914553110


##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,567 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes) \
+    std::vector<T> in_values;                                        \
+    for (auto val : in_pred_values) {                                \
+        T value = reinterpret_cast<T*>(val)[0];                      \
+        in_values.emplace_back(value);                               \
+    }                                                                \
+    if (in_values.empty()) {                                         \
+        return false;                                                \
+    }                                                                \
+    std::sort(in_values.begin(), in_values.end());                   \
+    T in_min = in_values.front();                                    \
+    T in_max = in_values.back();                                     \
+    const T group_min = reinterpret_cast<const T*>(min_bytes)[0];    \
+    const T group_max = reinterpret_cast<const T*>(max_bytes)[0];    \
+    if (in_max < group_min || in_min > group_max) {                  \
+        return true;                                                 \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(RuntimeProfile* profile,
+                               const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata,
+                               ParquetReaderWrap* parent)
+        : _conjunct_ctxs(conjunct_ctxs),
+          _file_metadata(file_metadata),
+          _profile(profile),
+          _parent(parent) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    _parent->statistics()->total_groups = total_group;
+    _parent->statistics()->total_rows = _file_metadata->num_rows();
+
+    int64_t filtered_num_row_groups = 0;
+    int64_t filtered_num_rows = 0;
+    int64_t filtered_total_byte_size = 0;
+    bool need_filter = false;
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            const std::string& col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            const std::string& min = statistic->EncodeMin();
+            const std::string& max = statistic->EncodeMax();
+
+            need_filter = _determine_filter_row_group(slot_iter->second, min, max);

Review Comment:
   is this `need_filter` determined by the last row_group?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morningman commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
morningman commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r916052685


##########
be/src/exec/arrow/parquet_reader.cpp:
##########
@@ -239,8 +240,32 @@ Status ParquetReaderWrap::handle_timestamp(const std::shared_ptr<arrow::Timestam
     return Status::OK();
 }
 
+Status ParquetReaderWrap::init_parquet_type() {

Review Comment:
   Why extract this method out of the `init_reader()`?



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,567 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes) \
+    std::vector<T> in_values;                                        \
+    for (auto val : in_pred_values) {                                \
+        T value = reinterpret_cast<T*>(val)[0];                      \
+        in_values.emplace_back(value);                               \
+    }                                                                \
+    if (in_values.empty()) {                                         \
+        return false;                                                \
+    }                                                                \
+    std::sort(in_values.begin(), in_values.end());                   \
+    T in_min = in_values.front();                                    \
+    T in_max = in_values.back();                                     \
+    const T group_min = reinterpret_cast<const T*>(min_bytes)[0];    \
+    const T group_max = reinterpret_cast<const T*>(max_bytes)[0];    \
+    if (in_max < group_min || in_min > group_max) {                  \
+        return true;                                                 \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(RuntimeProfile* profile,
+                               const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata,
+                               ParquetReaderWrap* parent)
+        : _conjunct_ctxs(conjunct_ctxs),
+          _file_metadata(file_metadata),
+          _profile(profile),
+          _parent(parent) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    _parent->statistics()->total_groups = total_group;
+    _parent->statistics()->total_rows = _file_metadata->num_rows();
+
+    int64_t filtered_num_row_groups = 0;
+    int64_t filtered_num_rows = 0;
+    int64_t filtered_total_byte_size = 0;
+    bool need_filter = false;
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            const std::string& col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            const std::string& min = statistic->EncodeMin();
+            const std::string& max = statistic->EncodeMax();
+
+            need_filter = _determine_filter_row_group(slot_iter->second, min, max);
+            if (need_filter) {
+                filtered_num_row_groups++;
+                filtered_num_rows += row_group_meta->num_rows();
+                filtered_total_byte_size += row_group_meta->total_byte_size();
+                row_group_meta->schema()->name();
+                LOG(INFO) << "Filter row group id: " << row_group_id;

Review Comment:
   VLOG



##########
be/src/exec/arrow/parquet_reader.cpp:
##########
@@ -239,8 +240,32 @@ Status ParquetReaderWrap::handle_timestamp(const std::shared_ptr<arrow::Timestam
     return Status::OK();
 }
 
+Status ParquetReaderWrap::init_parquet_type() {
+    // read batch
+    RETURN_IF_ERROR(read_next_batch());
+    _current_line_of_batch = 0;
+    if (_batch == nullptr) {
+        return Status::OK();
+    }
+    //save column type
+    std::shared_ptr<arrow::Schema> field_schema = _batch->schema();
+    for (int i = 0; i < _include_column_ids.size(); i++) {
+        std::shared_ptr<arrow::Field> field = field_schema->field(i);
+        if (!field) {
+            LOG(WARNING) << "Get field schema failed. Column order:" << i;
+            return Status::InternalError(_status.ToString());
+        }
+        _parquet_column_type.emplace_back(field->type()->id());
+    }
+    return Status::OK();
+}
+
 Status ParquetReaderWrap::read(Tuple* tuple, const std::vector<SlotDescriptor*>& tuple_slot_descs,
                                MemPool* mem_pool, bool* eof) {
+    if (_batch == nullptr) {

Review Comment:
   Remove this. I think we don't need to modify row-based engine's logic.



##########
be/src/exec/base_scanner.cpp:
##########
@@ -95,6 +95,11 @@ Status BaseScanner::open() {
     return Status::OK();
 }
 
+void BaseScanner::reg_conjunct_ctxs(TupleId tupleId, std::vector<ExprContext*> conjunct_ctxs) {

Review Comment:
   ```suggestion
   void BaseScanner::reg_conjunct_ctxs(const TupleId& tupleId, const std::vector<ExprContext*>& conjunct_ctxs) {
   ```



##########
be/src/exec/arrow/parquet_reader.cpp:
##########
@@ -118,6 +112,7 @@ Status ParquetReaderWrap::init_reader(const std::vector<SlotDescriptor*>& tuple_
 }
 
 void ParquetReaderWrap::close() {
+    LOG(INFO) << "ParquetReaderWrap _closed: " << _closed;

Review Comment:
   Change it to VLOG, or just remove it.



##########
be/src/exec/arrow/parquet_reader.cpp:
##########
@@ -554,6 +589,9 @@ void ParquetReaderWrap::prefetch_batch() {
 Status ParquetReaderWrap::read_next_batch() {
     std::unique_lock<std::mutex> lock(_mtx);
     while (!_closed && _queue.empty()) {

Review Comment:
   `read_next_batch()` is for row-based engine, no need to modify it.



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,567 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes) \
+    std::vector<T> in_values;                                        \
+    for (auto val : in_pred_values) {                                \
+        T value = reinterpret_cast<T*>(val)[0];                      \
+        in_values.emplace_back(value);                               \
+    }                                                                \
+    if (in_values.empty()) {                                         \
+        return false;                                                \
+    }                                                                \
+    std::sort(in_values.begin(), in_values.end());                   \
+    T in_min = in_values.front();                                    \
+    T in_max = in_values.back();                                     \
+    const T group_min = reinterpret_cast<const T*>(min_bytes)[0];    \
+    const T group_max = reinterpret_cast<const T*>(max_bytes)[0];    \
+    if (in_max < group_min || in_min > group_max) {                  \
+        return true;                                                 \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(RuntimeProfile* profile,
+                               const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata,
+                               ParquetReaderWrap* parent)
+        : _conjunct_ctxs(conjunct_ctxs),
+          _file_metadata(file_metadata),
+          _profile(profile),
+          _parent(parent) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    _parent->statistics()->total_groups = total_group;
+    _parent->statistics()->total_rows = _file_metadata->num_rows();
+
+    int64_t filtered_num_row_groups = 0;
+    int64_t filtered_num_rows = 0;
+    int64_t filtered_total_byte_size = 0;
+    bool need_filter = false;
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            const std::string& col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            const std::string& min = statistic->EncodeMin();
+            const std::string& max = statistic->EncodeMax();
+
+            need_filter = _determine_filter_row_group(slot_iter->second, min, max);
+            if (need_filter) {
+                filtered_num_row_groups++;
+                filtered_num_rows += row_group_meta->num_rows();
+                filtered_total_byte_size += row_group_meta->total_byte_size();
+                row_group_meta->schema()->name();
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);

Review Comment:
   Once this group has been filtered, we can skip the rest of conjunct and go to next row group.



##########
be/src/exec/base_scanner.h:
##########
@@ -142,6 +145,9 @@ class BaseScanner {
     vectorized::Block _src_block;
     int _num_of_columns_from_file;
 
+    TupleId _tupleId;

Review Comment:
   Add comment to explain what this tuple id is.



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,567 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes) \
+    std::vector<T> in_values;                                        \
+    for (auto val : in_pred_values) {                                \
+        T value = reinterpret_cast<T*>(val)[0];                      \
+        in_values.emplace_back(value);                               \
+    }                                                                \
+    if (in_values.empty()) {                                         \
+        return false;                                                \
+    }                                                                \
+    std::sort(in_values.begin(), in_values.end());                   \
+    T in_min = in_values.front();                                    \
+    T in_max = in_values.back();                                     \
+    const T group_min = reinterpret_cast<const T*>(min_bytes)[0];    \
+    const T group_max = reinterpret_cast<const T*>(max_bytes)[0];    \
+    if (in_max < group_min || in_min > group_max) {                  \
+        return true;                                                 \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(RuntimeProfile* profile,
+                               const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata,
+                               ParquetReaderWrap* parent)
+        : _conjunct_ctxs(conjunct_ctxs),
+          _file_metadata(file_metadata),
+          _profile(profile),
+          _parent(parent) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    _parent->statistics()->total_groups = total_group;
+    _parent->statistics()->total_rows = _file_metadata->num_rows();
+
+    int64_t filtered_num_row_groups = 0;
+    int64_t filtered_num_rows = 0;
+    int64_t filtered_total_byte_size = 0;
+    bool need_filter = false;
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            const std::string& col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            const std::string& min = statistic->EncodeMin();
+            const std::string& max = statistic->EncodeMax();
+
+            need_filter = _determine_filter_row_group(slot_iter->second, min, max);
+            if (need_filter) {
+                filtered_num_row_groups++;
+                filtered_num_rows += row_group_meta->num_rows();
+                filtered_total_byte_size += row_group_meta->total_byte_size();
+                row_group_meta->schema()->name();
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    if (need_filter) {
+        _parent->statistics()->filtered_row_groups = filtered_num_row_groups;
+        _parent->statistics()->filtered_rows = filtered_num_rows;
+        _parent->statistics()->filtered_total_bytes = filtered_total_byte_size;
+        LOG(INFO) << "Parquet file: " << _file_metadata->schema()->name()

Review Comment:
   VLOG



##########
be/src/vec/exec/file_scanner.h:
##########
@@ -85,6 +87,10 @@ class FileScanner {
     std::unique_ptr<vectorized::VExprContext*> _vpre_filter_ctx_ptr;
     int _num_of_columns_from_file;
 
+    // File formats based push down predicate
+    std::vector<ExprContext*> _conjunct_ctxs;
+    TupleId _tupleId;

Review Comment:
   Add comment for this tuple id



##########
be/src/vec/exec/file_scanner.cpp:
##########
@@ -69,6 +69,11 @@ Status FileScanner::open() {
     return Status::OK();
 }
 
+void FileScanner::reg_conjunct_ctxs(TupleId tupleId, std::vector<ExprContext*> conjunct_ctxs) {

Review Comment:
   ```suggestion
   void FileScanner::reg_conjunct_ctxs(const TupleId& tupleId, const std::vector<ExprContext*>& conjunct_ctxs) {
   ```



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,567 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes) \
+    std::vector<T> in_values;                                        \
+    for (auto val : in_pred_values) {                                \
+        T value = reinterpret_cast<T*>(val)[0];                      \
+        in_values.emplace_back(value);                               \
+    }                                                                \
+    if (in_values.empty()) {                                         \
+        return false;                                                \
+    }                                                                \
+    std::sort(in_values.begin(), in_values.end());                   \
+    T in_min = in_values.front();                                    \
+    T in_max = in_values.back();                                     \
+    const T group_min = reinterpret_cast<const T*>(min_bytes)[0];    \
+    const T group_max = reinterpret_cast<const T*>(max_bytes)[0];    \
+    if (in_max < group_min || in_min > group_max) {                  \
+        return true;                                                 \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(RuntimeProfile* profile,
+                               const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata,
+                               ParquetReaderWrap* parent)
+        : _conjunct_ctxs(conjunct_ctxs),
+          _file_metadata(file_metadata),
+          _profile(profile),
+          _parent(parent) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    _parent->statistics()->total_groups = total_group;
+    _parent->statistics()->total_rows = _file_metadata->num_rows();
+
+    int64_t filtered_num_row_groups = 0;
+    int64_t filtered_num_rows = 0;
+    int64_t filtered_total_byte_size = 0;
+    bool need_filter = false;
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            const std::string& col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            const std::string& min = statistic->EncodeMin();
+            const std::string& max = statistic->EncodeMax();
+
+            need_filter = _determine_filter_row_group(slot_iter->second, min, max);
+            if (need_filter) {
+                filtered_num_row_groups++;
+                filtered_num_rows += row_group_meta->num_rows();
+                filtered_total_byte_size += row_group_meta->total_byte_size();
+                row_group_meta->schema()->name();

Review Comment:
   unused row?



##########
be/src/exec/arrow/parquet_reader.cpp:
##########
@@ -187,19 +182,25 @@ Status ParquetReaderWrap::read_record_batch(bool* eof) {
 }
 
 Status ParquetReaderWrap::next_batch(std::shared_ptr<arrow::RecordBatch>* batch, bool* eof) {
-    if (_batch->num_rows() == 0 || _current_line_of_batch != 0 || _current_line_of_group != 0) {
-        RETURN_IF_ERROR(read_record_batch(eof));
+    std::unique_lock<std::mutex> lock(_mtx);
+    while (!_closed && _queue.empty()) {
+        if (_batch_eof) {
+            _include_column_ids.clear();
+            *eof = true;
+            _batch_eof = false;

Review Comment:
   Why set it back to false?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #10512:
URL: https://github.com/apache/doris/pull/10512#issuecomment-1179097460

   PR approved by at least one committer and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] yinzhijian commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
yinzhijian commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r911871372


##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();
+            std::string max = statistic->EncodeMax();
+
+            LOG(INFO) << "Stat min:" << parquet::FormatStatValue(statistic->physical_type(), min);
+            LOG(INFO) << "Stat max:" << parquet::FormatStatValue(statistic->physical_type(), max);
+            bool need_filter = false;
+            _determine_filter_row_group(slot_iter->second, min, max, need_filter);
+            if (need_filter) {
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    return Status::OK();
+}
+
+void RowGroupReader::_init_conjuncts(const TupleDescriptor* tuple_desc,
+                                     const std::map<std::string, int>& map_column,
+                                     const std::unordered_set<int>& include_column_ids) {
+    for (int i = 0; i < tuple_desc->slots().size(); i++) {
+        auto col_iter = map_column.find(tuple_desc->slots()[i]->col_name());
+        if (col_iter == map_column.end()) {
+            continue;
+        }
+        int parquet_col_id = col_iter->second;
+        if (include_column_ids.end() == include_column_ids.find(parquet_col_id)) {
+            continue;
+        }
+        for (int conj_idx = 0; conj_idx < _conjunct_ctxs.size(); conj_idx++) {
+            Expr* conjunct = _conjunct_ctxs[conj_idx]->root();
+            if (conjunct->get_num_children() == 0) {
+                continue;
+            }
+            Expr* raw_slot = conjunct->get_child(0);
+            if (TExprNodeType::SLOT_REF != raw_slot->node_type()) {
+                continue;
+            }
+            SlotRef* slot_ref = (SlotRef*)raw_slot;
+            SlotId conjunct_slot_id = slot_ref->slot_id();
+            if (conjunct_slot_id == tuple_desc->slots()[i]->id()) {
+                // Get conjuncts by conjunct_slot_id
+                auto iter = _slot_conjuncts.find(conjunct_slot_id);
+                if (_slot_conjuncts.end() == iter) {
+                    std::vector<ExprContext*> conjuncts;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                    _slot_conjuncts.emplace(std::make_pair(conjunct_slot_id, conjuncts));
+                } else {
+                    std::vector<ExprContext*> conjuncts = iter->second;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);

Review Comment:
   Are the conjuncts here useless?



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();
+            std::string max = statistic->EncodeMax();
+
+            LOG(INFO) << "Stat min:" << parquet::FormatStatValue(statistic->physical_type(), min);
+            LOG(INFO) << "Stat max:" << parquet::FormatStatValue(statistic->physical_type(), max);
+            bool need_filter = false;
+            _determine_filter_row_group(slot_iter->second, min, max, need_filter);
+            if (need_filter) {
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    return Status::OK();
+}
+
+void RowGroupReader::_init_conjuncts(const TupleDescriptor* tuple_desc,
+                                     const std::map<std::string, int>& map_column,
+                                     const std::unordered_set<int>& include_column_ids) {
+    for (int i = 0; i < tuple_desc->slots().size(); i++) {
+        auto col_iter = map_column.find(tuple_desc->slots()[i]->col_name());
+        if (col_iter == map_column.end()) {
+            continue;
+        }
+        int parquet_col_id = col_iter->second;
+        if (include_column_ids.end() == include_column_ids.find(parquet_col_id)) {
+            continue;
+        }
+        for (int conj_idx = 0; conj_idx < _conjunct_ctxs.size(); conj_idx++) {
+            Expr* conjunct = _conjunct_ctxs[conj_idx]->root();
+            if (conjunct->get_num_children() == 0) {
+                continue;
+            }
+            Expr* raw_slot = conjunct->get_child(0);
+            if (TExprNodeType::SLOT_REF != raw_slot->node_type()) {
+                continue;
+            }
+            SlotRef* slot_ref = (SlotRef*)raw_slot;
+            SlotId conjunct_slot_id = slot_ref->slot_id();
+            if (conjunct_slot_id == tuple_desc->slots()[i]->id()) {
+                // Get conjuncts by conjunct_slot_id
+                auto iter = _slot_conjuncts.find(conjunct_slot_id);
+                if (_slot_conjuncts.end() == iter) {
+                    std::vector<ExprContext*> conjuncts;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                    _slot_conjuncts.emplace(std::make_pair(conjunct_slot_id, conjuncts));
+                } else {
+                    std::vector<ExprContext*> conjuncts = iter->second;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                }
+            }
+        }
+    }
+}
+
+void RowGroupReader::_determine_filter_row_group(const std::vector<ExprContext*>& conjuncts,
+                                                 const std::string& encoded_min,
+                                                 const std::string& encoded_max,
+                                                 bool& need_filter) {
+    const char* min_bytes = encoded_min.data();
+    const char* max_bytes = encoded_max.data();
+    for (int i = 0; i < conjuncts.size(); i++) {
+        Expr* conjunct = conjuncts[i]->root();
+        if (TExprNodeType::BINARY_PRED == conjunct->node_type()) {
+            _eval_binary_predicate(conjuncts[i], min_bytes, max_bytes, need_filter);
+        } else if (TExprNodeType::IN_PRED == conjunct->node_type()) {
+            _eval_in_predicate(conjuncts[i], min_bytes, max_bytes, need_filter);
+        }
+    }
+}
+
+void RowGroupReader::_eval_binary_predicate(ExprContext* ctx, const char* min_bytes,

Review Comment:
   ```suggestion
   bool RowGroupReader::_eval_binary_predicate(ExprContext* ctx, const char* min_bytes,
   ```



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();
+            std::string max = statistic->EncodeMax();
+
+            LOG(INFO) << "Stat min:" << parquet::FormatStatValue(statistic->physical_type(), min);
+            LOG(INFO) << "Stat max:" << parquet::FormatStatValue(statistic->physical_type(), max);
+            bool need_filter = false;
+            _determine_filter_row_group(slot_iter->second, min, max, need_filter);
+            if (need_filter) {
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    return Status::OK();
+}
+
+void RowGroupReader::_init_conjuncts(const TupleDescriptor* tuple_desc,
+                                     const std::map<std::string, int>& map_column,
+                                     const std::unordered_set<int>& include_column_ids) {
+    for (int i = 0; i < tuple_desc->slots().size(); i++) {
+        auto col_iter = map_column.find(tuple_desc->slots()[i]->col_name());
+        if (col_iter == map_column.end()) {
+            continue;
+        }
+        int parquet_col_id = col_iter->second;
+        if (include_column_ids.end() == include_column_ids.find(parquet_col_id)) {
+            continue;
+        }
+        for (int conj_idx = 0; conj_idx < _conjunct_ctxs.size(); conj_idx++) {
+            Expr* conjunct = _conjunct_ctxs[conj_idx]->root();
+            if (conjunct->get_num_children() == 0) {
+                continue;
+            }
+            Expr* raw_slot = conjunct->get_child(0);
+            if (TExprNodeType::SLOT_REF != raw_slot->node_type()) {
+                continue;
+            }
+            SlotRef* slot_ref = (SlotRef*)raw_slot;
+            SlotId conjunct_slot_id = slot_ref->slot_id();
+            if (conjunct_slot_id == tuple_desc->slots()[i]->id()) {
+                // Get conjuncts by conjunct_slot_id
+                auto iter = _slot_conjuncts.find(conjunct_slot_id);
+                if (_slot_conjuncts.end() == iter) {
+                    std::vector<ExprContext*> conjuncts;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                    _slot_conjuncts.emplace(std::make_pair(conjunct_slot_id, conjuncts));
+                } else {
+                    std::vector<ExprContext*> conjuncts = iter->second;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                }
+            }
+        }
+    }
+}
+
+void RowGroupReader::_determine_filter_row_group(const std::vector<ExprContext*>& conjuncts,

Review Comment:
   Why not return bool directly here, but use the parameter to return the result



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #10512:
URL: https://github.com/apache/doris/pull/10512#issuecomment-1178532605

   PR approved by anyone and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] wsjz commented on pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
wsjz commented on PR #10512:
URL: https://github.com/apache/doris/pull/10512#issuecomment-1177470187

   
   TPCH sql  completed
   in be.conf  enable: parquet_predicate_push_down=true


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] yinzhijian commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
yinzhijian commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r911883502


##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();
+            std::string max = statistic->EncodeMax();
+
+            LOG(INFO) << "Stat min:" << parquet::FormatStatValue(statistic->physical_type(), min);
+            LOG(INFO) << "Stat max:" << parquet::FormatStatValue(statistic->physical_type(), max);
+            bool need_filter = false;
+            _determine_filter_row_group(slot_iter->second, min, max, need_filter);
+            if (need_filter) {
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    return Status::OK();
+}
+
+void RowGroupReader::_init_conjuncts(const TupleDescriptor* tuple_desc,
+                                     const std::map<std::string, int>& map_column,
+                                     const std::unordered_set<int>& include_column_ids) {
+    for (int i = 0; i < tuple_desc->slots().size(); i++) {
+        auto col_iter = map_column.find(tuple_desc->slots()[i]->col_name());
+        if (col_iter == map_column.end()) {
+            continue;
+        }
+        int parquet_col_id = col_iter->second;
+        if (include_column_ids.end() == include_column_ids.find(parquet_col_id)) {
+            continue;
+        }
+        for (int conj_idx = 0; conj_idx < _conjunct_ctxs.size(); conj_idx++) {
+            Expr* conjunct = _conjunct_ctxs[conj_idx]->root();
+            if (conjunct->get_num_children() == 0) {
+                continue;
+            }
+            Expr* raw_slot = conjunct->get_child(0);
+            if (TExprNodeType::SLOT_REF != raw_slot->node_type()) {
+                continue;
+            }
+            SlotRef* slot_ref = (SlotRef*)raw_slot;
+            SlotId conjunct_slot_id = slot_ref->slot_id();
+            if (conjunct_slot_id == tuple_desc->slots()[i]->id()) {
+                // Get conjuncts by conjunct_slot_id
+                auto iter = _slot_conjuncts.find(conjunct_slot_id);
+                if (_slot_conjuncts.end() == iter) {
+                    std::vector<ExprContext*> conjuncts;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                    _slot_conjuncts.emplace(std::make_pair(conjunct_slot_id, conjuncts));
+                } else {
+                    std::vector<ExprContext*> conjuncts = iter->second;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                }
+            }
+        }
+    }
+}
+
+void RowGroupReader::_determine_filter_row_group(const std::vector<ExprContext*>& conjuncts,
+                                                 const std::string& encoded_min,
+                                                 const std::string& encoded_max,
+                                                 bool& need_filter) {
+    const char* min_bytes = encoded_min.data();
+    const char* max_bytes = encoded_max.data();
+    for (int i = 0; i < conjuncts.size(); i++) {
+        Expr* conjunct = conjuncts[i]->root();
+        if (TExprNodeType::BINARY_PRED == conjunct->node_type()) {
+            _eval_binary_predicate(conjuncts[i], min_bytes, max_bytes, need_filter);
+        } else if (TExprNodeType::IN_PRED == conjunct->node_type()) {
+            _eval_in_predicate(conjuncts[i], min_bytes, max_bytes, need_filter);
+        }
+    }
+}
+
+void RowGroupReader::_eval_binary_predicate(ExprContext* ctx, const char* min_bytes,
+                                            const char* max_bytes, bool& need_filter) {
+    Expr* conjunct = ctx->root();
+    Expr* expr = conjunct->get_child(1);
+    auto conjunct_type = expr->type().type;
+    void* conjunct_value = ctx->get_value(expr, nullptr);
+    switch (conjunct->op()) {
+    case TExprOpcode::EQ:
+        need_filter = _eval_eq(conjunct_type, conjunct_value, min_bytes, max_bytes);
+        break;
+    case TExprOpcode::NE:
+        break;
+    case TExprOpcode::GT:
+        need_filter = _eval_gt(conjunct_type, conjunct_value, max_bytes);
+        break;
+    case TExprOpcode::GE:
+        need_filter = _eval_ge(conjunct_type, conjunct_value, max_bytes);
+        break;
+    case TExprOpcode::LT:
+        need_filter = _eval_lt(conjunct_type, conjunct_value, min_bytes);
+        break;
+    case TExprOpcode::LE:
+        need_filter = _eval_le(conjunct_type, conjunct_value, min_bytes);
+        break;
+    default:
+        break;
+    }
+}
+
+void RowGroupReader::_eval_in_predicate(ExprContext* ctx, const char* min_bytes,
+                                        const char* max_bytes, bool& need_filter) {
+    Expr* conjunct = ctx->root();
+    std::vector<void*> in_pred_values;
+    const InPredicate* pred = static_cast<const InPredicate*>(conjunct);
+    HybridSetBase::IteratorBase* iter = pred->hybrid_set()->begin();
+    while (iter->has_next()) {
+        if (nullptr == iter->get_value()) {
+            return;
+        }
+        in_pred_values.emplace_back(const_cast<void*>(iter->get_value()));
+        iter->next();
+    }
+    auto conjunct_type = conjunct->get_child(1)->type().type;
+    switch (conjunct->op()) {
+    case TExprOpcode::FILTER_IN:
+        _eval_in_val(conjunct_type, in_pred_values, min_bytes, max_bytes);
+        break;
+    case TExprOpcode::FILTER_NOT_IN:
+        break;
+    default:
+        break;
+    }
+}
+
+bool RowGroupReader::_eval_in_val(PrimitiveType conjunct_type, std::vector<void*> in_pred_values,
+                                  const char* min_bytes, const char* max_bytes) {
+    switch (conjunct_type) {
+    case TYPE_TINYINT: {
+        _FILTER_GROUP_BY_IN(int8_t, in_pred_values, min_bytes, max_bytes)
+        break;
+    }
+    case TYPE_SMALLINT: {
+        _FILTER_GROUP_BY_IN(int16_t, in_pred_values, min_bytes, max_bytes)
+        break;
+    }
+    case TYPE_INT: {
+        _FILTER_GROUP_BY_IN(int32_t, in_pred_values, min_bytes, max_bytes)
+        break;
+    }
+    case TYPE_BIGINT: {
+        _FILTER_GROUP_BY_IN(int64_t, in_pred_values, min_bytes, max_bytes)
+        break;
+    }
+    case TYPE_STRING:
+    case TYPE_DATE:
+    case TYPE_DATETIME: {
+        std::vector<char*> in_values;
+        for (auto val : in_pred_values) {
+            char* value = reinterpret_cast<char**>(val)[0];
+            in_values.emplace_back(value);
+        }
+        if (in_values.empty()) {
+            return false;
+        }
+        if (in_values.size() >= 2) {
+            std::sort(in_values.begin(), in_values.end());
+            char* in_min = in_values.front();
+            char* in_max = in_values.back();
+            if (strcmp(in_max, min_bytes) < 0 || strcmp(in_min, max_bytes) > 0) {
+                return true;
+            }
+        } else {
+            char* value = in_values[0];
+            if (strcmp(value, min_bytes) < 0 || strcmp(value, max_bytes) > 0) {
+                return true;
+            }
+        }
+        break;
+    }
+    default:
+        return false;
+    }
+    return false;
+}
+
+bool RowGroupReader::_eval_eq(PrimitiveType conjunct_type, void* value, const char* min_bytes,
+                              const char* max_bytes) {
+    switch (conjunct_type) {
+    case TYPE_TINYINT: {
+        _PLAIN_DECODE(int16_t, value, min_bytes, max_bytes, conjunct_value, min, max)
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)
+        break;
+    } break;
+    case TYPE_SMALLINT: {
+        _PLAIN_DECODE(int16_t, value, min_bytes, max_bytes, conjunct_value, min, max)
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)
+        break;
+    }
+    case TYPE_INT: {
+        _PLAIN_DECODE(int32_t, value, min_bytes, max_bytes, conjunct_value, min, max)
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)
+        break;
+    }
+    case TYPE_BIGINT: {
+        _PLAIN_DECODE(int64_t, value, min_bytes, max_bytes, conjunct_value, min, max)
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)
+        break;
+    }
+    case TYPE_DOUBLE: {
+        _PLAIN_DECODE(double, value, min_bytes, max_bytes, conjunct_value, min, max)
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)
+        break;
+    }
+    case TYPE_FLOAT: {
+        _PLAIN_DECODE(float, value, min_bytes, max_bytes, conjunct_value, min, max)
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)
+        break;
+    }
+    case TYPE_STRING:
+    case TYPE_DATE:
+    case TYPE_DATETIME: {
+        char* conjunct_value = (char*)value;
+        if (strcmp(conjunct_value, min_bytes) < 0 || strcmp(conjunct_value, max_bytes) > 0) {
+            return true;
+        }
+        break;
+    }
+    default:
+        return false;
+    }
+    return false;
+}
+
+bool RowGroupReader::_eval_gt(PrimitiveType conjunct_type, void* value, const char* max_bytes) {
+    switch (conjunct_type) {
+    case TYPE_TINYINT: {
+        _PLAIN_DECODE_SINGLE(int8_t, value, max_bytes, conjunct_value, max)
+        _FILTER_GROUP_BY_GT_PRED(conjunct_value, max)
+        break;
+    } break;

Review Comment:
   ```suggestion
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] wsjz commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
wsjz commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r912863720


##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();
+            std::string max = statistic->EncodeMax();
+
+            LOG(INFO) << "Stat min:" << parquet::FormatStatValue(statistic->physical_type(), min);
+            LOG(INFO) << "Stat max:" << parquet::FormatStatValue(statistic->physical_type(), max);
+            bool need_filter = false;
+            _determine_filter_row_group(slot_iter->second, min, max, need_filter);
+            if (need_filter) {
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    return Status::OK();
+}
+
+void RowGroupReader::_init_conjuncts(const TupleDescriptor* tuple_desc,
+                                     const std::map<std::string, int>& map_column,
+                                     const std::unordered_set<int>& include_column_ids) {
+    for (int i = 0; i < tuple_desc->slots().size(); i++) {
+        auto col_iter = map_column.find(tuple_desc->slots()[i]->col_name());
+        if (col_iter == map_column.end()) {
+            continue;
+        }
+        int parquet_col_id = col_iter->second;
+        if (include_column_ids.end() == include_column_ids.find(parquet_col_id)) {
+            continue;
+        }
+        for (int conj_idx = 0; conj_idx < _conjunct_ctxs.size(); conj_idx++) {
+            Expr* conjunct = _conjunct_ctxs[conj_idx]->root();
+            if (conjunct->get_num_children() == 0) {
+                continue;
+            }
+            Expr* raw_slot = conjunct->get_child(0);
+            if (TExprNodeType::SLOT_REF != raw_slot->node_type()) {
+                continue;
+            }
+            SlotRef* slot_ref = (SlotRef*)raw_slot;
+            SlotId conjunct_slot_id = slot_ref->slot_id();
+            if (conjunct_slot_id == tuple_desc->slots()[i]->id()) {
+                // Get conjuncts by conjunct_slot_id
+                auto iter = _slot_conjuncts.find(conjunct_slot_id);
+                if (_slot_conjuncts.end() == iter) {
+                    std::vector<ExprContext*> conjuncts;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);
+                    _slot_conjuncts.emplace(std::make_pair(conjunct_slot_id, conjuncts));
+                } else {
+                    std::vector<ExprContext*> conjuncts = iter->second;
+                    conjuncts.emplace_back(_conjunct_ctxs[conj_idx]);

Review Comment:
   it has been in map yet



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morningman commented on a diff in pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
morningman commented on code in PR #10512:
URL: https://github.com/apache/doris/pull/10512#discussion_r911199096


##########
be/src/exec/arrow/parquet_reader.cpp:
##########
@@ -118,6 +126,7 @@ Status ParquetReaderWrap::init_reader(const std::vector<SlotDescriptor*>& tuple_
 }
 
 void ParquetReaderWrap::close() {
+    LOG(INFO) << "ParquetReaderWrap _closed: " << _closed;

Review Comment:
   Use VLOG



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();
+            std::string max = statistic->EncodeMax();
+
+            LOG(INFO) << "Stat min:" << parquet::FormatStatValue(statistic->physical_type(), min);
+            LOG(INFO) << "Stat max:" << parquet::FormatStatValue(statistic->physical_type(), max);
+            bool need_filter = false;
+            _determine_filter_row_group(slot_iter->second, min, max, need_filter);
+            if (need_filter) {
+                LOG(INFO) << "Filter row group id: " << row_group_id;
+                _filter_group.emplace(row_group_id);
+            }
+        }
+    }
+    return Status::OK();
+}
+
+void RowGroupReader::_init_conjuncts(const TupleDescriptor* tuple_desc,
+                                     const std::map<std::string, int>& map_column,
+                                     const std::unordered_set<int>& include_column_ids) {
+    for (int i = 0; i < tuple_desc->slots().size(); i++) {
+        auto col_iter = map_column.find(tuple_desc->slots()[i]->col_name());
+        if (col_iter == map_column.end()) {
+            continue;
+        }
+        int parquet_col_id = col_iter->second;
+        if (include_column_ids.end() == include_column_ids.find(parquet_col_id)) {
+            continue;
+        }
+        for (int conj_idx = 0; conj_idx < _conjunct_ctxs.size(); conj_idx++) {
+            Expr* conjunct = _conjunct_ctxs[conj_idx]->root();
+            if (conjunct->get_num_children() == 0) {
+                continue;
+            }
+            Expr* raw_slot = conjunct->get_child(0);

Review Comment:
   Do we need to check whether the `child(1)` is constant value?



##########
be/src/vec/exec/file_scan_node.cpp:
##########
@@ -315,6 +315,7 @@ std::unique_ptr<FileScanner> FileScanNode::create_scanner(const TFileScanRange&
         scan = new FileTextScanner(_runtime_state, runtime_profile(), scan_range.params,
                                    scan_range.ranges, _pre_filter_texprs, counter);
     }
+    scan->reg_conjunct_ctxs(_tuple_id, _conjunct_ctxs);

Review Comment:
   I think we should pass `_vconjunct_ctx_ptr` for vec engine, not `_conjunct_ctxs`



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();
+            auto col_iter = map_column.find(col_name);
+            if (col_iter == map_column.end()) {
+                continue;
+            }
+            int parquet_col_id = col_iter->second;
+            if (parquet_column_ids.end() == parquet_column_ids.find(parquet_col_id)) {
+                // Column not exist in parquet file
+                continue;
+            }
+            auto slot_iter = _slot_conjuncts.find(slot_id);
+            if (slot_iter == _slot_conjuncts.end()) {
+                continue;
+            }
+            auto statistic = row_group_meta->ColumnChunk(parquet_col_id)->statistics();
+            if (!statistic->HasMinMax()) {
+                continue;
+            }
+            // Min-max of statistic is plain-encoded value
+            std::string min = statistic->EncodeMin();

Review Comment:
   ```suggestion
               const std::string& min = statistic->EncodeMin();
   ```



##########
be/src/exec/arrow/parquet_reader.cpp:
##########
@@ -535,6 +550,18 @@ void ParquetReaderWrap::prefetch_batch() {
         if (_closed || current_group >= _total_groups) {
             return;
         }
+
+        if (config::parquet_predicate_push_down) {
+            auto filter_group_set = _row_group_reader->filter_groups();
+            if (filter_group_set.end() != filter_group_set.find(current_group)) {
+                // find filter group, skip
+                LOG(INFO) << "Skip row group id: " << current_group;

Review Comment:
   Use VLOG



##########
be/src/exec/arrow/parquet_row_group_reader.cpp:
##########
@@ -0,0 +1,539 @@
+// 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.
+
+#include "exec/arrow/parquet_row_group_reader.h"
+
+#include <exprs/expr_context.h>
+#include <exprs/in_predicate.h>
+#include <parquet/encoding.h>
+
+#include <cstring>
+
+#define _PLAIN_DECODE(T, value, min_bytes, max_bytes, out_value, out_min, out_max) \
+    const T out_min = reinterpret_cast<const T*>(min_bytes)[0];                    \
+    const T out_max = reinterpret_cast<const T*>(max_bytes)[0];                    \
+    T out_value = *((T*)value);
+
+#define _PLAIN_DECODE_SINGLE(T, value, bytes, conjunct_value, out) \
+    const T out = reinterpret_cast<const T*>(bytes)[0];            \
+    T conjunct_value = *((T*)value);
+
+#define _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max) \
+    if (conjunct_value < min || conjunct_value > max) {    \
+        return true;                                       \
+    }
+
+#define _FILTER_GROUP_BY_GT_PRED(conjunct_value, max) \
+    if (max <= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_GE_PRED(conjunct_value, max) \
+    if (max < conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LT_PRED(conjunct_value, min) \
+    if (min >= conjunct_value) {                      \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_LE_PRED(conjunct_value, min) \
+    if (min > conjunct_value) {                       \
+        return true;                                  \
+    }
+
+#define _FILTER_GROUP_BY_IN(T, in_pred_values, min_bytes, max_bytes)            \
+    std::vector<T> in_values;                                                   \
+    for (auto val : in_pred_values) {                                           \
+        T value = reinterpret_cast<T*>(val)[0];                                 \
+        in_values.emplace_back(value);                                          \
+    }                                                                           \
+    if (in_values.empty()) {                                                    \
+        return false;                                                           \
+    }                                                                           \
+    if (in_values.size() >= 2) {                                                \
+        std::sort(in_values.begin(), in_values.end());                          \
+        T in_min = in_values.front();                                           \
+        T in_max = in_values.back();                                            \
+        const T conj_min = reinterpret_cast<const T*>(min_bytes)[0];            \
+        const T conj_max = reinterpret_cast<const T*>(max_bytes)[0];            \
+        if (in_max < conj_min || in_min > conj_max) {                           \
+            return true;                                                        \
+        }                                                                       \
+    } else {                                                                    \
+        T* value = &in_values[0];                                               \
+        _PLAIN_DECODE(T, value, min_bytes, max_bytes, conjunct_value, min, max) \
+        _FILTER_GROUP_BY_EQ_PRED(conjunct_value, min, max)                      \
+    }
+
+namespace doris {
+
+RowGroupReader::RowGroupReader(const std::vector<ExprContext*>& conjunct_ctxs,
+                               std::shared_ptr<parquet::FileMetaData>& file_metadata)
+        : _conjunct_ctxs(conjunct_ctxs), _file_metadata(file_metadata) {}
+
+RowGroupReader::~RowGroupReader() {
+    _slot_conjuncts.clear();
+    _filter_group.clear();
+}
+
+Status RowGroupReader::init_filter_groups(const TupleDescriptor* tuple_desc,
+                                          const std::map<std::string, int>& map_column,
+                                          const std::vector<int>& include_column_ids) {
+    std::unordered_set<int> parquet_column_ids(include_column_ids.begin(),
+                                               include_column_ids.end());
+    _init_conjuncts(tuple_desc, map_column, parquet_column_ids);
+    int total_group = _file_metadata->num_row_groups();
+    for (int row_group_id = 0; row_group_id < total_group; row_group_id++) {
+        auto row_group_meta = _file_metadata->RowGroup(row_group_id);
+        for (SlotId slot_id = 0; slot_id < tuple_desc->slots().size(); slot_id++) {
+            std::string col_name = tuple_desc->slots()[slot_id]->col_name();

Review Comment:
   ```suggestion
               const std::string& col_name = tuple_desc->slots()[slot_id]->col_name();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] morningman merged pull request #10512: [feature] (vectorization)parquet push down support

Posted by GitBox <gi...@apache.org>.
morningman merged PR #10512:
URL: https://github.com/apache/doris/pull/10512


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org