Skip to content

Commit

Permalink
[Fix](status) fix unhandled status in exprs apache#28218
Browse files Browse the repository at this point in the history
which marked static_cast<void> in https://github.com/apache/doris/pull/23395/files
partially fixed apache#28160
  • Loading branch information
zclllyybb authored Dec 11, 2023
1 parent 53802fe commit e158753
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 131 deletions.
1 change: 1 addition & 0 deletions be/src/common/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Exception : public std::exception {
public:
Exception() : _code(ErrorCode::OK) {}
Exception(int code, const std::string_view& msg);
Exception(const Status& status) : Exception(status.code(), status.msg()) {}
// add nested exception as first param, or the template may could not find
// the correct method for ...args
Exception(const Exception& nested, int code, const std::string_view& msg);
Expand Down
8 changes: 8 additions & 0 deletions be/src/common/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ inline std::string Status::to_string_no_stack() const {
} \
} while (false)

#define THROW_IF_ERROR(stmt) \
do { \
Status _status_ = (stmt); \
if (UNLIKELY(!_status_.ok())) { \
throw Exception(_status_); \
} \
} while (false)

#define RETURN_ERROR_IF_NON_VEC \
return Status::NotSupported("Non-vectorized engine is not supported since Doris 2.0.");

Expand Down
3 changes: 1 addition & 2 deletions be/src/exprs/runtime_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ PFilterType get_type(RuntimeFilterType type) {
}

Status create_literal(const TypeDescriptor& type, const void* data, vectorized::VExprSPtr& expr) {
TExprNode node = create_texpr_node_from(data, type.type, type.precision, type.scale);

try {
TExprNode node = create_texpr_node_from(data, type.type, type.precision, type.scale);
expr = vectorized::VLiteral::create_shared(node);
} catch (const Exception& e) {
return e.to_status();
Expand Down
20 changes: 9 additions & 11 deletions be/src/pipeline/exec/table_function_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int TableFunctionLocalState::_find_last_fn_eos_idx() const {
bool TableFunctionLocalState::_roll_table_functions(int last_eos_idx) {
int i = last_eos_idx - 1;
for (; i >= 0; --i) {
static_cast<void>(_fns[i]->forward());
_fns[i]->forward();
if (!_fns[i]->eos()) {
break;
}
Expand All @@ -127,7 +127,7 @@ bool TableFunctionLocalState::_roll_table_functions(int last_eos_idx) {
}

for (int j = i + 1; j < _parent->cast<TableFunctionOperatorX>()._fn_num; ++j) {
static_cast<void>(_fns[j]->reset());
_fns[j]->reset();
}

return true;
Expand Down Expand Up @@ -171,7 +171,7 @@ Status TableFunctionLocalState::get_expanded_block(RuntimeState* state,
if (idx == 0 || skip_child_row) {
_copy_output_slots(columns);
// all table functions' results are exhausted, process next child row.
RETURN_IF_ERROR(process_next_child_row());
process_next_child_row();
if (_cur_child_offset == -1) {
break;
}
Expand All @@ -196,7 +196,7 @@ Status TableFunctionLocalState::get_expanded_block(RuntimeState* state,
_fns[i]->get_value(columns[i + p._child_slots.size()]);
}
_current_row_insert_times++;
static_cast<void>(_fns[p._fn_num - 1]->forward());
_fns[p._fn_num - 1]->forward();
}
}
}
Expand All @@ -218,27 +218,25 @@ Status TableFunctionLocalState::get_expanded_block(RuntimeState* state,
return Status::OK();
}

Status TableFunctionLocalState::process_next_child_row() {
void TableFunctionLocalState::process_next_child_row() {
_cur_child_offset++;

if (_cur_child_offset >= _child_block->rows()) {
// release block use count.
for (vectorized::TableFunction* fn : _fns) {
RETURN_IF_ERROR(fn->process_close());
fn->process_close();
}

_child_block->clear_column_data(_parent->cast<TableFunctionOperatorX>()
._child_x->row_desc()
.num_materialized_slots());
_cur_child_offset = -1;
return Status::OK();
return;
}

for (vectorized::TableFunction* fn : _fns) {
RETURN_IF_ERROR(fn->process_row(_cur_child_offset));
fn->process_row(_cur_child_offset);
}

return Status::OK();
}

TableFunctionOperatorX::TableFunctionOperatorX(ObjectPool* pool, const TPlanNode& tnode,
Expand Down Expand Up @@ -289,7 +287,7 @@ Status TableFunctionOperatorX::init(const TPlanNode& tnode, RuntimeState* state)
Status TableFunctionOperatorX::prepare(RuntimeState* state) {
RETURN_IF_ERROR(Base::prepare(state));

for (auto fn : _fns) {
for (auto* fn : _fns) {
RETURN_IF_ERROR(fn->prepare());
}
RETURN_IF_ERROR(vectorized::VExpr::prepare(_vfn_ctxs, state, _row_descriptor));
Expand Down
4 changes: 2 additions & 2 deletions be/src/pipeline/exec/table_function_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TableFunctionLocalState final : public PipelineXLocalState<> {
~TableFunctionLocalState() override = default;

Status init(RuntimeState* state, LocalStateInfo& info) override;
Status process_next_child_row();
void process_next_child_row();
Status get_expanded_block(RuntimeState* state, vectorized::Block* output_block,
SourceState& source_state);

Expand Down Expand Up @@ -106,7 +106,7 @@ class TableFunctionOperatorX final : public StatefulOperatorX<TableFunctionLocal
for (auto* fn : local_state._fns) {
RETURN_IF_ERROR(fn->process_init(input_block, state));
}
RETURN_IF_ERROR(local_state.process_next_child_row());
local_state.process_next_child_row();
return Status::OK();
}

Expand Down
20 changes: 9 additions & 11 deletions be/src/vec/exec/vtable_function_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Status VTableFunctionNode::prepare(RuntimeState* state) {
SCOPED_TIMER(_exec_timer);

_num_rows_filtered_counter = ADD_COUNTER(_runtime_profile, "RowsFiltered", TUnit::UNIT);
for (auto fn : _fns) {
for (auto* fn : _fns) {
RETURN_IF_ERROR(fn->prepare());
}
RETURN_IF_ERROR(VExpr::prepare(_vfn_ctxs, state, _row_descriptor));
Expand Down Expand Up @@ -182,7 +182,7 @@ Status VTableFunctionNode::_get_expanded_block(RuntimeState* state, Block* outpu
if (idx == 0 || skip_child_row) {
_copy_output_slots(columns);
// all table functions' results are exhausted, process next child row.
RETURN_IF_ERROR(_process_next_child_row());
_process_next_child_row();
if (_cur_child_offset == -1) {
break;
}
Expand All @@ -207,7 +207,7 @@ Status VTableFunctionNode::_get_expanded_block(RuntimeState* state, Block* outpu
_fns[i]->get_value(columns[i + _child_slots.size()]);
}
_current_row_insert_times++;
static_cast<void>(_fns[_fn_num - 1]->forward());
_fns[_fn_num - 1]->forward();
}
}
}
Expand All @@ -226,25 +226,23 @@ Status VTableFunctionNode::_get_expanded_block(RuntimeState* state, Block* outpu
return Status::OK();
}

Status VTableFunctionNode::_process_next_child_row() {
void VTableFunctionNode::_process_next_child_row() {
_cur_child_offset++;

if (_cur_child_offset >= _child_block->rows()) {
// release block use count.
for (TableFunction* fn : _fns) {
RETURN_IF_ERROR(fn->process_close());
fn->process_close();
}

release_block_memory(*_child_block);
_cur_child_offset = -1;
return Status::OK();
return;
}

for (TableFunction* fn : _fns) {
RETURN_IF_ERROR(fn->process_row(_cur_child_offset));
fn->process_row(_cur_child_offset);
}

return Status::OK();
}

// Returns the index of fn of the last eos counted from back to front
Expand Down Expand Up @@ -287,7 +285,7 @@ int VTableFunctionNode::_find_last_fn_eos_idx() {
bool VTableFunctionNode::_roll_table_functions(int last_eos_idx) {
int i = last_eos_idx - 1;
for (; i >= 0; --i) {
static_cast<void>(_fns[i]->forward());
_fns[i]->forward();
if (!_fns[i]->eos()) {
break;
}
Expand All @@ -299,7 +297,7 @@ bool VTableFunctionNode::_roll_table_functions(int last_eos_idx) {
}

for (int j = i + 1; j < _fn_num; ++j) {
static_cast<void>(_fns[j]->reset());
_fns[j]->reset();
}

return true;
Expand Down
7 changes: 3 additions & 4 deletions be/src/vec/exec/vtable_function_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

#pragma once

#include <stdint.h>

#include <cstdint>
#include <vector>

#include "common/global_types.h"
Expand Down Expand Up @@ -81,7 +80,7 @@ class VTableFunctionNode final : public ExecNode {
for (TableFunction* fn : _fns) {
RETURN_IF_ERROR(fn->process_init(input_block, state));
}
RETURN_IF_ERROR(_process_next_child_row());
_process_next_child_row();
return Status::OK();
}

Expand All @@ -106,7 +105,7 @@ class VTableFunctionNode final : public ExecNode {

bool _roll_table_functions(int last_eos_idx);

Status _process_next_child_row();
void _process_next_child_row();

/* Now the output tuples for table function node is base_table_tuple + tf1 + tf2 + ...
But not all slots are used, the real used slots are inside table_function_node.outputSlotIds.
Expand Down
14 changes: 6 additions & 8 deletions be/src/vec/exprs/table_function/table_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,19 @@ class TableFunction {

virtual Status process_init(Block* block, RuntimeState* state) = 0;

virtual Status process_row(size_t row_idx) {
virtual void process_row(size_t row_idx) {
if (!_is_const) {
_cur_size = 0;
}
return reset();
reset();
}

// only used for vectorized.
virtual Status process_close() = 0;
virtual void process_close() = 0;

virtual Status reset() {
virtual void reset() {
_eos = false;
_cur_offset = 0;
return Status::OK();
}

virtual void get_value(MutableColumnPtr& column) = 0;
Expand All @@ -61,14 +60,14 @@ class TableFunction {
int i = 0;
for (; i < max_step && !eos(); i++) {
get_value(column);
static_cast<void>(forward());
forward();
}
return i;
}

virtual Status close() { return Status::OK(); }

virtual Status forward(int step = 1) {
virtual void forward(int step = 1) {
if (current_empty()) {
_eos = true;
} else {
Expand All @@ -77,7 +76,6 @@ class TableFunction {
_eos = true;
}
}
return Status::OK();
}

std::string name() const { return _fn_name; }
Expand Down
8 changes: 3 additions & 5 deletions be/src/vec/exprs/table_function/vexplode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,20 @@ Status VExplodeTableFunction::process_init(Block* block, RuntimeState* state) {
return Status::OK();
}

Status VExplodeTableFunction::process_row(size_t row_idx) {
void VExplodeTableFunction::process_row(size_t row_idx) {
DCHECK(row_idx < _array_column->size());
RETURN_IF_ERROR(TableFunction::process_row(row_idx));
TableFunction::process_row(row_idx);

if (!_detail.array_nullmap_data || !_detail.array_nullmap_data[row_idx]) {
_array_offset = (*_detail.offsets_ptr)[row_idx - 1];
_cur_size = (*_detail.offsets_ptr)[row_idx] - _array_offset;
}
return Status::OK();
}

Status VExplodeTableFunction::process_close() {
void VExplodeTableFunction::process_close() {
_array_column = nullptr;
_detail.reset();
_array_offset = 0;
return Status::OK();
}

void VExplodeTableFunction::get_value(MutableColumnPtr& column) {
Expand Down
4 changes: 2 additions & 2 deletions be/src/vec/exprs/table_function/vexplode.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class VExplodeTableFunction : public TableFunction {
~VExplodeTableFunction() override = default;

Status process_init(Block* block, RuntimeState* state) override;
Status process_row(size_t row_idx) override;
Status process_close() override;
void process_row(size_t row_idx) override;
void process_close() override;
void get_value(MutableColumnPtr& column) override;

private:
Expand Down
21 changes: 9 additions & 12 deletions be/src/vec/exprs/table_function/vexplode_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <glog/logging.h>

#include <memory>
#include <ostream>
#include <vector>

Expand Down Expand Up @@ -53,22 +54,21 @@ Status VExplodeBitmapTableFunction::process_init(Block* block, RuntimeState* sta
return Status::OK();
}

Status VExplodeBitmapTableFunction::reset() {
void VExplodeBitmapTableFunction::reset() {
_eos = false;
_cur_offset = 0;
if (!current_empty()) {
_cur_iter.reset(new BitmapValueIterator(*_cur_bitmap));
_cur_iter = std::make_unique<BitmapValueIterator>(*_cur_bitmap);
}
return Status::OK();
}

Status VExplodeBitmapTableFunction::forward(int step) {
void VExplodeBitmapTableFunction::forward(int step) {
if (!current_empty()) {
for (int i = 0; i < step; i++) {
++(*_cur_iter);
}
}
return TableFunction::forward(step);
TableFunction::forward(step);
}

void VExplodeBitmapTableFunction::get_value(MutableColumnPtr& column) {
Expand All @@ -88,8 +88,8 @@ void VExplodeBitmapTableFunction::get_value(MutableColumnPtr& column) {
}
}

Status VExplodeBitmapTableFunction::process_row(size_t row_idx) {
RETURN_IF_ERROR(TableFunction::process_row(row_idx));
void VExplodeBitmapTableFunction::process_row(size_t row_idx) {
TableFunction::process_row(row_idx);

StringRef value = _value_column->get_data_at(row_idx);

Expand All @@ -98,16 +98,13 @@ Status VExplodeBitmapTableFunction::process_row(size_t row_idx) {

_cur_size = _cur_bitmap->cardinality();
if (!current_empty()) {
_cur_iter.reset(new BitmapValueIterator(*_cur_bitmap));
_cur_iter = std::make_unique<BitmapValueIterator>(*_cur_bitmap);
}
}

return Status::OK();
}

Status VExplodeBitmapTableFunction::process_close() {
void VExplodeBitmapTableFunction::process_close() {
_value_column = nullptr;
return Status::OK();
}

} // namespace doris::vectorized
Loading

0 comments on commit e158753

Please sign in to comment.