HappenLee commented on a change in pull request #8448:
URL: https://github.com/apache/incubator-doris/pull/8448#discussion_r825620010



##########
File path: be/src/exprs/table_function/table_function_factory.cpp
##########
@@ -21,25 +21,30 @@
 #include "exprs/table_function/explode_bitmap.h"
 #include "exprs/table_function/explode_json_array.h"
 #include "exprs/table_function/explode_split.h"
+#include "vec/exprs/table_function/vexplode_split.h"
 
 namespace doris {
 
-Status TableFunctionFactory::get_fn(const std::string& fn_name, ObjectPool* 
pool, TableFunction** fn) {
+Status TableFunctionFactory::get_fn(const std::string& fn_name, ObjectPool* 
pool,

Review comment:
       `get_fn(const std::string& fn_name, ObjectPool* pool, bool is_vec,
                                       TableFunction** fn)` 

##########
File path: be/src/vec/exprs/table_function/vexplode_split.cpp
##########
@@ -0,0 +1,101 @@
+// 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/exprs/table_function/vexplode_split.h"
+
+#include "common/status.h"
+#include "gutil/strings/split.h"
+#include "vec/columns/column.h"
+#include "vec/exprs/vexpr.h"
+
+namespace doris {
+
+VExplodeSplitTableFunction::VExplodeSplitTableFunction() {
+    _fn_name = "vexplode_split";
+}
+
+Status VExplodeSplitTableFunction::open() {
+    return Status::OK();
+}
+
+Status VExplodeSplitTableFunction::process_init(vectorized::Block* block) {
+    CHECK(_vexpr_context->root()->children().size() == 2)
+            << "VExplodeSplitTableFunction must be have 2 children but have "
+            << _vexpr_context->root()->children().size();
+
+    int text_column_idx = -1;
+    int delimiter_column_idx = -1;
+
+    _vexpr_context->root()->children()[0]->execute(_vexpr_context, block, 
&text_column_idx);
+    _vexpr_context->root()->children()[1]->execute(_vexpr_context, block, 
&delimiter_column_idx);
+
+    _text_column = block->get_by_position(text_column_idx).column;
+    _delimiter_column = block->get_by_position(delimiter_column_idx).column;
+
+    _text_column = _text_column->convert_to_full_column_if_const();

Review comment:
       maybe not need do convert here

##########
File path: be/src/vec/exec/vtable_function_node.cpp
##########
@@ -0,0 +1,223 @@
+// 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/vtable_function_node.h"
+
+#include "exprs/expr.h"
+#include "exprs/expr_context.h"
+#include "exprs/table_function/table_function.h"
+#include "exprs/table_function/table_function_factory.h"
+#include "vec/exprs/vexpr.h"
+
+namespace doris::vectorized {
+
+VTableFunctionNode::VTableFunctionNode(ObjectPool* pool, const TPlanNode& 
tnode,
+                                       const DescriptorTbl& descs)
+        : TableFunctionNode(pool, tnode, descs) {}
+
+Status VTableFunctionNode::init(const TPlanNode& tnode, RuntimeState* state) {
+    RETURN_IF_ERROR(ExecNode::init(tnode, state));
+
+    for (const TExpr& texpr : tnode.table_function_node.fnCallExprList) {
+        VExprContext* ctx = nullptr;
+        RETURN_IF_ERROR(VExpr::create_expr_tree(_pool, texpr, &ctx));
+        _vfn_ctxs.push_back(ctx);
+
+        VExpr* root = ctx->root();
+        const std::string& tf_name = root->fn().name.function_name;
+        TableFunction* fn = nullptr;
+        RETURN_IF_ERROR(TableFunctionFactory::get_fn("v" + tf_name, _pool, 
&fn));
+        fn->set_vexpr_context(ctx);
+        _fns.push_back(fn);
+    }
+    _fn_num = _fns.size();
+    _fn_values.resize(_fn_num);
+    _fn_value_lengths.resize(_fn_num);
+
+    // Prepare output slot ids
+    RETURN_IF_ERROR(_prepare_output_slot_ids(tnode));
+    return Status::OK();
+}
+
+Status VTableFunctionNode::prepare(RuntimeState* state) {
+    SCOPED_TIMER(_runtime_profile->total_time_counter());
+    RETURN_IF_ERROR(TableFunctionNode::prepare(state));
+    RETURN_IF_ERROR(VExpr::prepare(_vfn_ctxs, state, _row_descriptor, 
expr_mem_tracker()));
+
+    // get current all output slots
+    for (const auto& tuple_desc : this->row_desc().tuple_descriptors()) {
+        for (const auto& slot_desc : tuple_desc->slots()) {
+            _output_slots.push_back(slot_desc);
+        }
+    }
+
+    // get all input slots
+    for (const auto& child_tuple_desc : 
child(0)->row_desc().tuple_descriptors()) {
+        for (const auto& child_slot_desc : child_tuple_desc->slots()) {
+            _child_slots.push_back(child_slot_desc);
+        }
+    }
+
+    _child_block.reset(new Block());
+    _cur_child_offset = -1;
+
+    return Status::OK();
+}
+
+Status VTableFunctionNode::get_next(RuntimeState* state, Block* block, bool* 
eos) {
+    SCOPED_TIMER(_runtime_profile->total_time_counter());
+
+    RETURN_IF_CANCELLED(state);
+
+    RETURN_IF_ERROR(get_expanded_block(state, block, eos));
+
+    _num_rows_returned += block->rows();

Review comment:
       consider the node may have limit, use `reach limited`?

##########
File path: be/src/exprs/table_function/table_function_factory.cpp
##########
@@ -21,25 +21,30 @@
 #include "exprs/table_function/explode_bitmap.h"
 #include "exprs/table_function/explode_json_array.h"
 #include "exprs/table_function/explode_split.h"
+#include "vec/exprs/table_function/vexplode_split.h"
 
 namespace doris {
 
-Status TableFunctionFactory::get_fn(const std::string& fn_name, ObjectPool* 
pool, TableFunction** fn) {
+Status TableFunctionFactory::get_fn(const std::string& fn_name, ObjectPool* 
pool,
+                                    TableFunction** fn) {

Review comment:
       Maybe we should do a better way to dispose table funciton. like 
"unorrder_map" 

##########
File path: be/src/vec/exprs/table_function/vexplode_split.cpp
##########
@@ -0,0 +1,101 @@
+// 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/exprs/table_function/vexplode_split.h"
+
+#include "common/status.h"
+#include "gutil/strings/split.h"
+#include "vec/columns/column.h"
+#include "vec/exprs/vexpr.h"
+
+namespace doris {
+
+VExplodeSplitTableFunction::VExplodeSplitTableFunction() {
+    _fn_name = "vexplode_split";
+}
+
+Status VExplodeSplitTableFunction::open() {
+    return Status::OK();
+}
+
+Status VExplodeSplitTableFunction::process_init(vectorized::Block* block) {
+    CHECK(_vexpr_context->root()->children().size() == 2)
+            << "VExplodeSplitTableFunction must be have 2 children but have "
+            << _vexpr_context->root()->children().size();
+
+    int text_column_idx = -1;
+    int delimiter_column_idx = -1;
+
+    _vexpr_context->root()->children()[0]->execute(_vexpr_context, block, 
&text_column_idx);
+    _vexpr_context->root()->children()[1]->execute(_vexpr_context, block, 
&delimiter_column_idx);
+
+    _text_column = block->get_by_position(text_column_idx).column;
+    _delimiter_column = block->get_by_position(delimiter_column_idx).column;
+
+    _text_column = _text_column->convert_to_full_column_if_const();
+    _delimiter_column = _delimiter_column->convert_to_full_column_if_const();
+
+    return Status::OK();
+}
+
+Status VExplodeSplitTableFunction::process_row(size_t row_idx) {
+    _is_current_empty = false;
+    _eos = false;
+
+    if (_text_column->is_null_at(row_idx)) {

Review comment:
       here may be should only use `get_data_at` to replace `is_null_at`

##########
File path: be/src/exprs/table_function/table_function.h
##########
@@ -34,24 +38,47 @@ class TableFunction {
 
     virtual Status prepare() = 0;
     virtual Status open() = 0;
+
     virtual Status process(TupleRow* tuple_row) = 0;
+
+    virtual Status process_init(vectorized::Block* block) {
+        return Status::NotSupported(
+                fmt::format("vectorized table function {} not supported now.", 
_fn_name));
+    }
+    virtual Status process_row(size_t row_idx) {
+        return Status::NotSupported(
+                fmt::format("vectorized table function {} not supported now.", 
_fn_name));
+    }
+    virtual Status process_close() {
+        return Status::NotSupported(
+                fmt::format("vectorized table function {} not supported now.", 
_fn_name));
+    }
+
     virtual Status reset() = 0;
+
     virtual Status get_value(void** output) = 0;
+    virtual Status get_value_length(int64_t* length) {

Review comment:
       only use in vec exec engine, need comment

##########
File path: be/src/vec/exprs/table_function/vexplode_split.cpp
##########
@@ -0,0 +1,101 @@
+// 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/exprs/table_function/vexplode_split.h"
+
+#include "common/status.h"
+#include "gutil/strings/split.h"
+#include "vec/columns/column.h"
+#include "vec/exprs/vexpr.h"
+
+namespace doris {
+
+VExplodeSplitTableFunction::VExplodeSplitTableFunction() {
+    _fn_name = "vexplode_split";
+}
+
+Status VExplodeSplitTableFunction::open() {
+    return Status::OK();
+}
+
+Status VExplodeSplitTableFunction::process_init(vectorized::Block* block) {
+    CHECK(_vexpr_context->root()->children().size() == 2)
+            << "VExplodeSplitTableFunction must be have 2 children but have "
+            << _vexpr_context->root()->children().size();
+
+    int text_column_idx = -1;
+    int delimiter_column_idx = -1;
+
+    _vexpr_context->root()->children()[0]->execute(_vexpr_context, block, 
&text_column_idx);
+    _vexpr_context->root()->children()[1]->execute(_vexpr_context, block, 
&delimiter_column_idx);
+
+    _text_column = block->get_by_position(text_column_idx).column;
+    _delimiter_column = block->get_by_position(delimiter_column_idx).column;
+
+    _text_column = _text_column->convert_to_full_column_if_const();
+    _delimiter_column = _delimiter_column->convert_to_full_column_if_const();
+
+    return Status::OK();
+}
+
+Status VExplodeSplitTableFunction::process_row(size_t row_idx) {
+    _is_current_empty = false;
+    _eos = false;
+
+    if (_text_column->is_null_at(row_idx)) {
+        _is_current_empty = true;
+        _cur_size = 0;
+        _cur_offset = 0;
+    } else {
+        StringRef text = _text_column->get_data_at(row_idx);
+        StringRef delimiter = _delimiter_column->get_data_at(row_idx);
+
+        _backup = strings::Split(StringPiece((char*)text.data, text.size),

Review comment:
       add TODO:use std::vector<string view> to repalce 
std::vector<std::string> 




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to