imay commented on a change in pull request #1527: Expose data pruned-filter-scan ability URL: https://github.com/apache/incubator-doris/pull/1527#discussion_r312307037
########## File path: be/src/runtime/memory_scratch_sink.cpp ########## @@ -0,0 +1,233 @@ +// 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 "runtime/memory_scratch_sink.h" + +#include <sstream> + +#include "common/logging.h" +#include "exprs/expr.h" +#include "gen_cpp/DorisExternalService_types.h" +#include "gen_cpp/Types_types.h" +#include "runtime/row_batch.h" +#include "runtime/exec_env.h" +#include "runtime/primitive_type.h" +#include "runtime/result_queue_mgr.h" +#include "runtime/runtime_state.h" +#include "runtime/tuple_row.h" +#include "util/date_func.h" +#include "util/types.h" + +namespace doris { + +MemoryScratchSink::MemoryScratchSink(const RowDescriptor& row_desc, const std::vector<TExpr>& t_output_expr, + const TMemoryScratchSink& sink) : _row_desc(row_desc),_t_output_expr(t_output_expr) { +} + +MemoryScratchSink::~MemoryScratchSink() { +} + +Status MemoryScratchSink::prepare_exprs(RuntimeState* state) { + // From the thrift expressions create the real exprs. + RETURN_IF_ERROR(Expr::create_expr_trees( + state->obj_pool(), _t_output_expr, &_output_expr_ctxs)); + // Prepare the exprs to run. + RETURN_IF_ERROR(Expr::prepare( + _output_expr_ctxs, state, _row_desc, _expr_mem_tracker.get())); + return Status::OK(); +} + +Status MemoryScratchSink::prepare(RuntimeState* state) { + RETURN_IF_ERROR(DataSink::prepare(state)); + // prepare output_expr + RETURN_IF_ERROR(prepare_exprs(state)); + // create queue + TUniqueId fragment_instance_id = state->fragment_instance_id(); + state->exec_env()->result_queue_mgr()->create_queue(fragment_instance_id, &_queue); + std::stringstream title; + title << "MemoryScratchSink (frag_id=" << fragment_instance_id << ")"; + // create profile + _profile = state->obj_pool()->add(new RuntimeProfile(state->obj_pool(), title.str())); + + return Status::OK(); +} + +Status MemoryScratchSink::send(RuntimeState* state, RowBatch* batch) { + if (NULL == batch || 0 == batch->num_rows()) { + return Status::OK(); + } + Status status; + // convert one batch + std::shared_ptr<TScanRowBatch> t_scan_row_batch = std::make_shared<TScanRowBatch>(); + t_scan_row_batch->__set_num_rows(batch->num_rows()); + int num_columns = _output_expr_ctxs.size(); + std::vector<TScanColumnData> cols; + for (int i =0 ; i < num_columns; i++) { + TScanColumnData all_col_data; + cols.push_back(all_col_data); + } + t_scan_row_batch->__set_cols(std::move(cols)); + for (int i = 0; status.ok() && i < batch->num_rows(); ++i) { + TupleRow* row = batch->get_row(i); + status = add_per_col(row, t_scan_row_batch); + if (!status.ok()) { + return Status::InternalError("convert row failed"); + } + } + _queue->blocking_put(t_scan_row_batch); + return Status::OK(); +} + +// add all col data for TScanRowBatch +Status MemoryScratchSink::add_per_col(TupleRow* row, std::shared_ptr<TScanRowBatch> result) { + int num_cols = _output_expr_ctxs.size(); + for (int i = 0; i < num_cols; ++i) { + void* item = _output_expr_ctxs[i]->get_value(row); + if (item == nullptr) { + result->cols[i].is_null.push_back(true); + continue; + } else { + result->cols[i].is_null.push_back(false); + } + switch (_output_expr_ctxs[i]->root()->type().type) { + case TYPE_BOOLEAN: + case TYPE_TINYINT: + result->cols[i].__isset.byte_vals = true; + result->cols[i].byte_vals.push_back(*static_cast<int8_t*>(item)); + break; + case TYPE_SMALLINT: + if (!result->cols[i].__isset.short_vals) { Review comment: change it ---------------------------------------------------------------- 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. 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