carlvinhust2012 commented on code in PR #9311: URL: https://github.com/apache/incubator-doris/pull/9311#discussion_r867463402
########## 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); Review Comment: I think it can be removed. -- 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-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org