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/05/07 11:23:40 UTC

[GitHub] [incubator-doris] xiepengcheng01 commented on a diff in pull request #9311: [feature]add vectorized vjson_scanner

xiepengcheng01 commented on code in PR #9311:
URL: https://github.com/apache/incubator-doris/pull/9311#discussion_r867340320


##########
be/src/exec/base_scanner.cpp:
##########
@@ -260,6 +279,33 @@ Status BaseScanner::_fill_dest_tuple(Tuple* dest_tuple, MemPool* mem_pool) {
     return Status::OK();
 }
 
+Status BaseScanner::filter_block(vectorized::Block* temp_block, size_t slot_num) {
+    // filter src tuple by preceding filter first

Review Comment:
   should modify this note



##########
be/src/exec/base_scanner.cpp:
##########
@@ -284,6 +330,12 @@ void BaseScanner::close() {
     if (!_pre_filter_ctxs.empty()) {
         Expr::close(_pre_filter_ctxs, _state);
     }
+
+    if (_state != nullptr && _state->enable_vectorized_exec()) {

Review Comment:
   no need `_state != nullptr`?



##########
be/src/vec/exec/vjson_scanner.cpp:
##########
@@ -0,0 +1,545 @@
+// 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 "vec/exec/vjson_scanner.h"
+
+#include <algorithm>
+#include <fmt/format.h>
+
+#include "env/env.h"
+#include "exec/broker_reader.h"
+#include "exec/buffered_reader.h"
+#include "exec/local_file_reader.h"
+#include "exec/plain_text_line_reader.h"
+#include "exec/s3_reader.h"
+#include "exprs/expr.h"
+#include "exprs/json_functions.h"
+#include "gutil/strings/split.h"
+#include "runtime/exec_env.h"
+#include "runtime/runtime_state.h"
+#include "util/time.h"
+
+namespace doris::vectorized {
+
+VJsonScanner::VJsonScanner(RuntimeState* state, RuntimeProfile* profile,
+                           const TBrokerScanRangeParams& params,
+                           const std::vector<TBrokerRangeDesc>& ranges,
+                           const std::vector<TNetworkAddress>& broker_addresses,
+                           const std::vector<TExpr>& pre_filter_texprs, ScannerCounter* counter)
+        : JsonScanner(state, profile, params, ranges, broker_addresses, pre_filter_texprs, counter),
+          _cur_vjson_reader(nullptr) {}
+
+VJsonScanner::~VJsonScanner() {
+    close();
+}
+
+Status VJsonScanner::open() {
+    RETURN_IF_ERROR(BaseScanner::open());
+    return Status::OK();
+}
+
+void VJsonScanner::close() {
+    BaseScanner::close();
+}
+
+Status VJsonScanner::get_next(vectorized::Block& output_block, bool* eof) {
+    SCOPED_TIMER(_read_timer);
+    Status status;
+    const int batch_size = _state->batch_size();
+    size_t slot_num = _src_slot_descs.size();
+    std::unique_ptr<vectorized::Block> temp_block(new vectorized::Block());
+    std::vector<vectorized::MutableColumnPtr> columns(slot_num);
+    auto string_type = make_nullable(std::make_shared<DataTypeString>());
+    for (int i = 0; i < slot_num; i++) {
+        columns[i] = string_type->create_column();
+    }
+
+    // Get one line
+    while (columns[0]->size() < batch_size && !_scanner_eof) {
+        if (_cur_file_reader == nullptr || _cur_reader_eof) {
+            RETURN_IF_ERROR(open_next_reader());
+            // If there isn't any more reader, break this
+            if (_scanner_eof) {
+                break;
+            }
+        }
+
+        if (_read_json_by_line && _skip_next_line) {
+            size_t size = 0;
+            const uint8_t* line_ptr = nullptr;
+            RETURN_IF_ERROR(_cur_line_reader->read_line(&line_ptr, &size, &_cur_reader_eof));
+            _skip_next_line = false;
+            continue;
+        }
+
+        bool is_empty_row = false;
+        RETURN_IF_ERROR(_cur_vjson_reader->read_json_column(columns, _src_slot_descs, &is_empty_row,
+                                                            &_cur_reader_eof));
+        if (is_empty_row) {
+            // Read empty row, just continue
+            continue;
+        }
+        COUNTER_UPDATE(_rows_read_counter, 1);
+        SCOPED_TIMER(_materialize_timer);
+    }
+
+    if (columns[0]->size() > 0) {
+        auto n_columns = 0;
+        for (const auto slot_desc : _src_slot_descs) {
+            temp_block->insert(ColumnWithTypeAndName(std::move(columns[n_columns++]),
+                                                     slot_desc->get_data_type_ptr(),
+                                                     slot_desc->col_name()));
+        }
+
+        RETURN_IF_ERROR(BaseScanner::filter_block(temp_block.get(), slot_num));

Review Comment:
   should update _counter->num_rows_unselected ?



-- 
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