chaoyli closed pull request #514: Add rowset reader context builder
URL: https://github.com/apache/incubator-doris/pull/514
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/be/src/olap/rowset/alpha_rowset_reader.cpp 
b/be/src/olap/rowset/alpha_rowset_reader.cpp
index e44ad066..b7b29462 100644
--- a/be/src/olap/rowset/alpha_rowset_reader.cpp
+++ b/be/src/olap/rowset/alpha_rowset_reader.cpp
@@ -39,12 +39,11 @@ AlphaRowsetReader::AlphaRowsetReader(int num_key_fields, 
int num_short_key_field
 }
 
 OLAPStatus AlphaRowsetReader::init(ReaderContext* read_context) {
-    _current_read_context = read_context;
-    OLAPStatus status = _init_segment_groups(read_context);
-    if (status != OLAP_SUCCESS) {
-        return status;
+    if (read_context == nullptr) {
+        return OLAP_ERR_INIT_FAILED;
     }
-    status = _init_column_datas(read_context);
+    _current_read_context = read_context;
+    OLAPStatus status = _init_column_datas(read_context);
     return status;
 }
 
@@ -140,26 +139,20 @@ OLAPStatus 
AlphaRowsetReader::_init_column_datas(ReaderContext* read_context) {
         if (status != OLAP_SUCCESS) {
             return OLAP_ERR_READER_READING_ERROR; 
         }
-        new_column_data->set_delete_handler(read_context->delete_handler);
+        new_column_data->set_delete_handler(*read_context->delete_handler);
         new_column_data->set_stats(read_context->stats);
         new_column_data->set_lru_cache(read_context->lru_cache);
         std::vector<ColumnPredicate*> col_predicates;
-        for (auto& column_predicate : read_context->predicates) {
-            col_predicates.push_back(&column_predicate.second);
+        for (auto& column_predicate : *read_context->predicates) {
+            col_predicates.push_back(column_predicate.second);
         }
-        if (read_context->lower_bound_keys.size() != 
read_context->is_lower_keys_included.size()
-                || read_context->lower_bound_keys.size() != 
read_context->upper_bound_keys.size()
-                || read_context->upper_bound_keys.size() != 
read_context->is_upper_keys_included.size()) {
-            std::string error_msg = "invalid key range arguments";
-            LOG(WARNING) << error_msg;
-            return OLAP_ERR_INPUT_PARAMETER_ERROR;
-        }
-        new_column_data->set_read_params(read_context->return_columns,
-                                read_context->load_bf_columns,
-                                read_context->conditions,
+        
+        new_column_data->set_read_params(*read_context->return_columns,
+                                *read_context->load_bf_columns,
+                                *read_context->conditions,
                                 col_predicates,
-                                read_context->lower_bound_keys,
-                                read_context->upper_bound_keys,
+                                *read_context->lower_bound_keys,
+                                *read_context->upper_bound_keys,
                                 read_context->is_using_cache,
                                 read_context->runtime_state);
         // filter column data
@@ -183,13 +176,31 @@ OLAPStatus 
AlphaRowsetReader::_init_column_datas(ReaderContext* read_context) {
             new_column_data->set_delete_status(DEL_NOT_SATISFIED);
         }
         _column_datas.emplace_back(std::move(new_column_data));
-        _key_range_size = read_context->lower_bound_keys.size();
+        if (read_context->lower_bound_keys == nullptr) {
+            if (read_context->is_lower_keys_included != nullptr
+                || read_context->upper_bound_keys != nullptr
+                || read_context->is_upper_keys_included != nullptr) {
+                LOG(WARNING) << "invalid key range arguments";
+                return OLAP_ERR_INPUT_PARAMETER_ERROR;
+            }
+            _key_range_size = 0;
+        } else {
+            if (read_context->lower_bound_keys->size() != 
read_context->is_lower_keys_included->size()
+                || read_context->lower_bound_keys->size() != 
read_context->upper_bound_keys->size()
+                || read_context->upper_bound_keys->size() != 
read_context->is_upper_keys_included->size()) {
+                std::string error_msg = "invalid key range arguments";
+                LOG(WARNING) << error_msg;
+                return OLAP_ERR_INPUT_PARAMETER_ERROR;
+            }
+            _key_range_size = read_context->lower_bound_keys->size();
+        }
+        
         RowBlock* row_block = nullptr;
         if (_key_range_size > 0) {
-            status = 
new_column_data->prepare_block_read(read_context->lower_bound_keys[_key_range_index],
-                    read_context->is_lower_keys_included[_key_range_index],
-                    read_context->upper_bound_keys[_key_range_index],
-                    read_context->is_upper_keys_included[_key_range_index],
+            status = 
new_column_data->prepare_block_read(read_context->lower_bound_keys->at(_key_range_index),
+                    read_context->is_lower_keys_included->at(_key_range_index),
+                    read_context->upper_bound_keys->at(_key_range_index),
+                    read_context->is_upper_keys_included->at(_key_range_index),
                     &row_block);
             if (status != OLAP_SUCCESS) {
                 LOG(WARNING) << "prepare block read failed";
@@ -219,10 +230,10 @@ OLAPStatus 
AlphaRowsetReader::_refresh_next_block(ColumnData* column_data, RowBl
         // currently, SegmentReader can only support filter one key range a 
time
         // use the next predicate range to get data from segment here
         if (_key_range_size > 0 && _key_range_index < _key_range_size) {
-            status = 
column_data->prepare_block_read(_current_read_context->lower_bound_keys[_key_range_index],
-                    
_current_read_context->is_lower_keys_included[_key_range_index],
-                    _current_read_context->upper_bound_keys[_key_range_index],
-                    
_current_read_context->is_upper_keys_included[_key_range_index],
+            status = 
column_data->prepare_block_read(_current_read_context->lower_bound_keys->at(_key_range_index),
+                    
_current_read_context->is_lower_keys_included->at(_key_range_index),
+                    
_current_read_context->upper_bound_keys->at(_key_range_index),
+                    
_current_read_context->is_upper_keys_included->at(_key_range_index),
                     &next_block);
             if (status != OLAP_SUCCESS) {
                 LOG(WARNING) << "prepare block read failed";
diff --git a/be/src/olap/rowset/alpha_rowset_reader.h 
b/be/src/olap/rowset/alpha_rowset_reader.h
index f2f1b4d3..5ffd2f1e 100644
--- a/be/src/olap/rowset/alpha_rowset_reader.h
+++ b/be/src/olap/rowset/alpha_rowset_reader.h
@@ -46,7 +46,6 @@ class AlphaRowsetReader : public RowsetReader {
     virtual void close();
 
 private:
-    OLAPStatus _init_segment_groups(ReaderContext* read_context);
 
     OLAPStatus _init_column_datas(ReaderContext* read_context);
 
@@ -73,6 +72,6 @@ class AlphaRowsetReader : public RowsetReader {
     ReaderContext* _current_read_context;
 };
 
-}
+} // namespace doris
 
 #endif // DORIS_BE_SRC_OLAP_ROWSET_ALPHA_ROWSET_READER_H
diff --git a/be/src/olap/rowset/rowset_reader.h 
b/be/src/olap/rowset/rowset_reader.h
index c6ba7788..dd8c1cca 100644
--- a/be/src/olap/rowset/rowset_reader.h
+++ b/be/src/olap/rowset/rowset_reader.h
@@ -18,15 +18,7 @@
 #ifndef DORIS_BE_SRC_OLAP_ROWSET_ROWSET_READER_H
 #define DORIS_BE_SRC_OLAP_ROWSET_ROWSET_READER_H
 
-#include "olap/new_status.h"
-#include "olap/schema.h"
-#include "olap/column_predicate.h"
-#include "olap/row_cursor.h"
-#include "olap/row_block.h"
-#include "olap/lru_cache.h"
-#include "olap/olap_cond.h"
-#include "olap/delete_handler.h"
-#include "runtime/runtime_state.h"
+#include "olap/rowset/rowset_reader_context_builder.h"
 
 #include <memory>
 #include <unordered_map>
@@ -36,29 +28,6 @@ namespace doris {
 class RowsetReader;
 using RowsetReaderSharedPtr = std::shared_ptr<RowsetReader>;
 
-struct ReaderContext {
-       const RowFields& tablet_schema;
-    // projection columns
-    const std::vector<uint32_t>& return_columns;
-    // columns to load bloom filter index
-    // including columns in "=" or "in" conditions
-    const std::set<uint32_t>& load_bf_columns;
-    // column filter conditions by delete sql
-    const Conditions& conditions;
-    // column name -> column predicate
-    // adding column_name for predicate to make use of column selectivity
-    std::unordered_map<std::string, ColumnPredicate&> predicates;
-    const std::vector<RowCursor*>& lower_bound_keys;
-    std::vector<bool> is_lower_keys_included;
-    const std::vector<RowCursor*>& upper_bound_keys;
-    std::vector<bool> is_upper_keys_included;
-    const DeleteHandler& delete_handler;
-    OlapReaderStatistics* stats;
-    bool is_using_cache;
-    Cache* lru_cache;
-    RuntimeState* runtime_state;
-};
-
 class RowsetReader {
 public:
     static RowsetReader* create();
@@ -77,6 +46,6 @@ class RowsetReader {
     virtual void close() = 0;
 };
 
-}
+} // namespace doris
 
 #endif // DORIS_BE_SRC_OLAP_ROWSET_ROWSET_READER_H
diff --git a/be/src/olap/rowset/rowset_reader_context_builder.h 
b/be/src/olap/rowset/rowset_reader_context_builder.h
new file mode 100644
index 00000000..2197ebeb
--- /dev/null
+++ b/be/src/olap/rowset/rowset_reader_context_builder.h
@@ -0,0 +1,154 @@
+// 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.
+
+#ifndef DORIS_BE_SRC_OLAP_ROWSET_ROWSET_READER_CONTEXT_BUILDER_H
+#define DORIS_BE_SRC_OLAP_ROWSET_ROWSET_READER_CONTEXT_BUILDER_H
+
+#include "olap/schema.h"
+#include "olap/column_predicate.h"
+#include "olap/row_cursor.h"
+#include "olap/row_block.h"
+#include "olap/lru_cache.h"
+#include "olap/olap_cond.h"
+#include "olap/delete_handler.h"
+#include "runtime/runtime_state.h"
+
+namespace doris {
+
+struct ReaderContext {
+       RowFields* tablet_schema;
+    // projection columns
+    const std::vector<uint32_t>* return_columns;
+    // columns to load bloom filter index
+    // including columns in "=" or "in" conditions
+    const std::set<uint32_t>* load_bf_columns;
+    // column filter conditions by delete sql
+    const Conditions* conditions;
+    // column name -> column predicate
+    // adding column_name for predicate to make use of column selectivity
+    const std::unordered_map<std::string, ColumnPredicate*>* predicates;
+    const std::vector<RowCursor*>* lower_bound_keys;
+    const std::vector<bool>* is_lower_keys_included;
+    const std::vector<RowCursor*>* upper_bound_keys;
+    const std::vector<bool>* is_upper_keys_included;
+    const DeleteHandler* delete_handler;
+    OlapReaderStatistics* stats;
+    bool is_using_cache;
+    Cache* lru_cache;
+    RuntimeState* runtime_state;
+
+    ReaderContext() : tablet_schema(nullptr),
+        return_columns(nullptr),
+        load_bf_columns(nullptr),
+        conditions(nullptr),
+        predicates(nullptr),
+        lower_bound_keys(nullptr),
+        is_lower_keys_included(nullptr),
+        upper_bound_keys(nullptr),
+        is_upper_keys_included(nullptr),
+        delete_handler(nullptr),
+        stats(nullptr),
+        is_using_cache(false),
+        lru_cache(nullptr),
+        runtime_state(nullptr) {
+    }
+};
+
+class RowsetReaderContextBuilder {
+public:
+    RowsetReaderContextBuilder& set_tablet_schema(RowFields* tablet_schema) {
+        _reader_context.tablet_schema = tablet_schema;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_return_columns(const 
std::vector<uint32_t>* return_columns) {
+        _reader_context.return_columns = return_columns;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_load_bf_columns(const std::set<uint32_t>* 
load_bf_columns) {
+        _reader_context.load_bf_columns = load_bf_columns;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_conditions(const Conditions* conditions) {
+        _reader_context.conditions = conditions;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_predicates(
+            const std::unordered_map<std::string, ColumnPredicate*>* 
predicates) {
+        _reader_context.predicates = predicates;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_lower_bound_keys(const 
std::vector<RowCursor*>* lower_bound_keys) {
+        _reader_context.lower_bound_keys = lower_bound_keys;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_is_lower_keys_included(const 
std::vector<bool>* is_lower_keys_included) {
+        _reader_context.is_lower_keys_included = is_lower_keys_included;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_upper_bound_keys(const 
std::vector<RowCursor*>* upper_bound_keys) {
+        _reader_context.upper_bound_keys = upper_bound_keys;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_is_upper_keys_included(const 
std::vector<bool>* is_upper_keys_included) {
+        _reader_context.is_upper_keys_included = is_upper_keys_included;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_delete_handler(const DeleteHandler* 
delete_handler) {
+        _reader_context.delete_handler = delete_handler;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_stats(OlapReaderStatistics* stats) {
+        _reader_context.stats = stats;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_is_using_cache(bool is_using_cache) {
+        _reader_context.is_using_cache = is_using_cache;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_lru_cache(Cache* lru_cache) {
+        _reader_context.lru_cache = lru_cache;
+        return *this;
+    }
+
+    RowsetReaderContextBuilder& set_runtime_state(RuntimeState* runtime_state) 
{
+        _reader_context.runtime_state = runtime_state;
+        return *this;
+    }
+
+    ReaderContext build() {
+        return _reader_context;
+    }
+
+private:
+    ReaderContext _reader_context;
+};
+
+} // namespace doris
+
+#endif // DORIS_BE_SRC_OLAP_ROWSET_ROWSET_READER_CONTEXT_BUILDER_H
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org
For additional commands, e-mail: dev-h...@doris.apache.org

Reply via email to