Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor](BE) Uniform Expr, Block, Columns size-relative interface (Part II) #43218

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion be/src/vec/exprs/table_function/table_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
#pragma once

#include <fmt/core.h>
zclllyybb marked this conversation as resolved.
Show resolved Hide resolved
#include <stddef.h>

#include <cstddef>

#include "common/status.h"
#include "vec/core/block.h"
#include "vec/exprs/vexpr_context.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

constexpr auto COMBINATOR_SUFFIX_OUTER = "_outer";

Expand Down Expand Up @@ -101,4 +103,6 @@ class TableFunction {
bool _is_nullable = false;
bool _is_const = false;
};

#include "common/compile_check_end.h"
} // namespace doris::vectorized
3 changes: 2 additions & 1 deletion be/src/vec/exprs/table_function/table_function_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <memory>
#include <string_view>
#include <utility>

#include "common/object_pool.h"
#include "vec/exprs/table_function/table_function.h"
Expand All @@ -37,6 +36,7 @@
#include "vec/utils/util.hpp"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <typename TableFunctionType>
struct TableFunctionCreator {
Expand Down Expand Up @@ -91,4 +91,5 @@ Status TableFunctionFactory::get_fn(const TFunction& t_fn, ObjectPool* pool, Tab
return Status::NotSupported("Table function {} is not support", t_fn.name.function_name);
}

#include "common/compile_check_end.h"
} // namespace doris::vectorized
3 changes: 3 additions & 0 deletions be/src/vec/exprs/table_function/table_function_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "common/status.h"

namespace doris {
#include "common/compile_check_begin.h"

class ObjectPool;

namespace vectorized {
Expand All @@ -41,4 +43,5 @@ class TableFunctionFactory {
_function_map;
};
} // namespace vectorized
#include "common/compile_check_end.h"
} // namespace doris
4 changes: 4 additions & 0 deletions be/src/vec/exprs/table_function/udf_table_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "vec/exprs/vexpr_context.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

const char* EXECUTOR_CLASS = "org/apache/doris/udf/UdfExecutor";
const char* EXECUTOR_CTOR_SIGNATURE = "([B)V";
const char* EXECUTOR_EVALUATE_SIGNATURE = "(Ljava/util/Map;Ljava/util/Map;)J";
Expand Down Expand Up @@ -206,4 +208,6 @@ int UDFTableFunction::get_value(MutableColumnPtr& column, int max_step) {
forward(max_step);
return max_step;
}

#include "common/compile_check_end.h"
} // namespace doris::vectorized
2 changes: 2 additions & 0 deletions be/src/vec/exprs/table_function/udf_table_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "vec/functions/array/function_array_utils.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

class UDFTableFunction final : public TableFunction {
ENABLE_FACTORY_CREATOR(UDFTableFunction);
Expand Down Expand Up @@ -94,4 +95,5 @@ class UDFTableFunction final : public TableFunction {
size_t _array_offset = 0; // start offset of array[row_idx]
};

#include "common/compile_check_end.h"
} // namespace doris::vectorized
5 changes: 3 additions & 2 deletions be/src/vec/exprs/table_function/vexplode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@
#include <glog/logging.h>

#include <ostream>
#include <vector>

#include "common/status.h"
#include "vec/columns/column.h"
#include "vec/columns/column_object.h"
#include "vec/common/string_ref.h"
#include "vec/core/block.h"
#include "vec/core/column_with_type_and_name.h"
#include "vec/data_types/data_type.h"
#include "vec/exprs/vexpr.h"
#include "vec/exprs/vexpr_context.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

VExplodeTableFunction::VExplodeTableFunction() {
_fn_name = "vexplode";
Expand Down Expand Up @@ -124,4 +123,6 @@ int VExplodeTableFunction::get_value(MutableColumnPtr& column, int max_step) {
forward(max_step);
return max_step;
}

#include "common/compile_check_end.h"
} // namespace doris::vectorized
11 changes: 6 additions & 5 deletions be/src/vec/exprs/table_function/vexplode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

#pragma once

#include <stddef.h>
#include <cstddef>

#include "common/status.h"
#include "vec/data_types/data_type.h"
#include "vec/exprs/table_function/table_function.h"
#include "vec/functions/array/function_array_utils.h"

namespace doris {
namespace vectorized {
namespace doris::vectorized {
#include "common/compile_check_begin.h"

class Block;
} // namespace vectorized
} // namespace doris
} // namespace doris::vectorized

namespace doris::vectorized {

Expand All @@ -52,4 +52,5 @@ class VExplodeTableFunction : public TableFunction {
size_t _array_offset; // start offset of array[row_idx]
};

#include "common/compile_check_end.h"
} // namespace doris::vectorized
5 changes: 3 additions & 2 deletions be/src/vec/exprs/table_function/vexplode_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

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

#include "common/status.h"
#include "util/bitmap_value.h"
Expand All @@ -36,6 +35,7 @@
#include "vec/exprs/vexpr_context.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

VExplodeBitmapTableFunction::VExplodeBitmapTableFunction() {
_fn_name = "vexplode_bitmap";
Expand Down Expand Up @@ -126,7 +126,7 @@ int VExplodeBitmapTableFunction::get_value(MutableColumnPtr& column, int max_ste
}
auto origin_size = target->size();
target->resize(origin_size + max_step);
auto target_data = target->get_data().data();
auto* target_data = target->get_data().data();
for (int i = 0; i < max_step; ++i) {
target_data[i + origin_size] = **_cur_iter;
++(*_cur_iter);
Expand All @@ -135,4 +135,5 @@ int VExplodeBitmapTableFunction::get_value(MutableColumnPtr& column, int max_ste
TableFunction::forward(max_step);
return max_step;
}
#include "common/compile_check_end.h"
} // namespace doris::vectorized
13 changes: 5 additions & 8 deletions be/src/vec/exprs/table_function/vexplode_bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@

#pragma once

#include <stddef.h>

#include <cstddef>
#include <memory>

#include "common/status.h"
#include "util/bitmap_value.h"
#include "vec/data_types/data_type.h"
#include "vec/exprs/table_function/table_function.h"

namespace doris {
namespace vectorized {
class Block;
} // namespace vectorized
} // namespace doris

namespace doris::vectorized {
#include "common/compile_check_begin.h"

class Block;

class VExplodeBitmapTableFunction final : public TableFunction {
ENABLE_FACTORY_CREATOR(VExplodeBitmapTableFunction);
Expand Down Expand Up @@ -60,4 +56,5 @@ class VExplodeBitmapTableFunction final : public TableFunction {
ColumnPtr _value_column;
};

#include "common/compile_check_end.h"
} // namespace doris::vectorized
9 changes: 4 additions & 5 deletions be/src/vec/exprs/table_function/vexplode_json_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@
#include "vec/exprs/table_function/vexplode_json_array.h"

#include <glog/logging.h>
#include <inttypes.h>
#include <rapidjson/rapidjson.h>
#include <stdio.h>

#include <algorithm>
#include <limits>
#include <cstdio>

#include "common/status.h"
#include "util/jsonb_parser.h"
#include "util/jsonb_utils.h"
#include "vec/columns/column.h"
#include "vec/columns/column_nullable.h"
#include "vec/columns/columns_number.h"
Expand All @@ -38,6 +34,8 @@
#include "vec/exprs/vexpr_context.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <typename DataImpl>
VExplodeJsonArrayTableFunction<DataImpl>::VExplodeJsonArrayTableFunction() : TableFunction() {
_fn_name = "vexplode_json_array";
Expand Down Expand Up @@ -155,4 +153,5 @@ template class VExplodeJsonArrayTableFunction<ParsedDataDouble>;
template class VExplodeJsonArrayTableFunction<ParsedDataString>;
template class VExplodeJsonArrayTableFunction<ParsedDataJSON>;

#include "common/compile_check_end.h"
} // namespace doris::vectorized
13 changes: 7 additions & 6 deletions be/src/vec/exprs/table_function/vexplode_json_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@
#include <glog/logging.h>
zclllyybb marked this conversation as resolved.
Show resolved Hide resolved
#include <rapidjson/document.h>

#include <ostream>
#include <string>
#include <vector>

#include "common/status.h"
#include "gutil/integral_types.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "vec/common/string_ref.h"
#include "vec/core/types.h"
#include "vec/data_types/data_type.h"
#include "vec/exprs/table_function/table_function.h"
#include "vec/functions/function_string.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <typename T>
struct ParsedData {
Expand All @@ -50,7 +48,7 @@ struct ParsedData {
int max_step) = 0;
virtual void insert_many_same_value_from_parsed_data(MutableColumnPtr& column,
int64_t cur_offset, int length) = 0;
const char* get_null_flag_address(int cur_offset) {
const char* get_null_flag_address(size_t cur_offset) {
return reinterpret_cast<const char*>(_values_null_flag.data() + cur_offset);
}
std::vector<UInt8> _values_null_flag;
Expand All @@ -77,7 +75,8 @@ struct ParsedDataInt : public ParsedData<int64_t> {
}
} else if (v.IsDouble()) {
auto value = v.GetDouble();
if (value > MAX_VALUE) {
// target slot is int64(cast double to int64). so compare with int64_max
if (static_cast<int64_t>(value) > MAX_VALUE) {
_backup_data[i] = MAX_VALUE;
} else if (value < MIN_VALUE) {
_backup_data[i] = MIN_VALUE;
Expand Down Expand Up @@ -107,7 +106,8 @@ struct ParsedDataInt : public ParsedData<int64_t> {
_backup_data[i] = static_cast<const JsonbInt64Val&>(val).val();
} else if (val.isDouble()) {
auto value = static_cast<const JsonbDoubleVal&>(val).val();
if (value > MAX_VALUE) {
// target slot is int64(cast double to int64). so compare with int64_max
if (static_cast<int64_t>(value) > MAX_VALUE) {
_backup_data[i] = MAX_VALUE;
} else if (value < MIN_VALUE) {
_backup_data[i] = MIN_VALUE;
Expand Down Expand Up @@ -420,4 +420,5 @@ class VExplodeJsonArrayTableFunction final : public TableFunction {
DataTypePtr _text_datatype;
};

#include "common/compile_check_end.h"
} // namespace doris::vectorized
17 changes: 10 additions & 7 deletions be/src/vec/exprs/table_function/vexplode_json_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
#include <glog/logging.h>

#include <ostream>
#include <vector>

#include "common/status.h"
#include "vec/columns/column.h"
#include "vec/columns/column_struct.h"
#include "vec/common/string_ref.h"
#include "vec/core/block.h"
#include "vec/core/column_with_type_and_name.h"
#include "vec/exprs/vexpr.h"
#include "vec/exprs/vexpr_context.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

VExplodeJsonObjectTableFunction::VExplodeJsonObjectTableFunction() {
_fn_name = "vexplode_json_object";
Expand All @@ -55,7 +56,7 @@ void VExplodeJsonObjectTableFunction::process_row(size_t row_idx) {
StringRef text = _json_object_column->get_data_at(row_idx);
if (text.data != nullptr) {
JsonbDocument* doc = JsonbDocument::createDocument(text.data, text.size);
if (UNLIKELY(!doc || !doc->getValue())) {
if (!doc || !doc->getValue()) [[unlikely]] {
// error jsonb, put null into output, cur_size = 0 , we will insert_default
return;
}
Expand All @@ -64,18 +65,18 @@ void VExplodeJsonObjectTableFunction::process_row(size_t row_idx) {
auto writer = std::make_unique<JsonbWriter>();
if (value->isObject()) {
_cur_size = value->length();
ObjectVal* obj = (ObjectVal*)value;
auto* obj = (ObjectVal*)value;
_object_pairs.first =
ColumnNullable::create(ColumnString::create(), ColumnUInt8::create());
_object_pairs.second =
ColumnNullable::create(ColumnString::create(), ColumnUInt8::create());
_object_pairs.first->reserve(_cur_size);
_object_pairs.second->reserve(_cur_size);
for (auto it = obj->begin(); it != obj->end(); ++it) {
_object_pairs.first->insert_data(it->getKeyStr(), it->klen());
for (auto& it : *obj) {
_object_pairs.first->insert_data(it.getKeyStr(), it.klen());
writer->reset();
writer->writeValue(it->value());
if (it->value()->isNull()) {
writer->writeValue(it.value());
if (it.value()->isNull()) {
_object_pairs.second->insert_default();
} else {
const std::string_view& jsonb_value = std::string_view(
Expand Down Expand Up @@ -157,4 +158,6 @@ int VExplodeJsonObjectTableFunction::get_value(MutableColumnPtr& column, int max
forward(max_step);
return max_step;
}

#include "common/compile_check_end.h"
} // namespace doris::vectorized
11 changes: 3 additions & 8 deletions be/src/vec/exprs/table_function/vexplode_json_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,15 @@

#pragma once

#include <stddef.h>
#include <cstddef>

#include "common/status.h"
#include "vec/columns/column_map.h"
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_array.h"
#include "vec/data_types/data_type_map.h"
#include "vec/exprs/table_function/table_function.h"
#include "vec/functions/array/function_array_utils.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"
class Block;
} // namespace doris::vectorized

namespace doris::vectorized {

// explode_json_object("{\"a\": 1, \"b\": 2}") ->
// | key | value |
Expand All @@ -56,4 +50,5 @@ class VExplodeJsonObjectTableFunction : public TableFunction {
std::pair<MutableColumnPtr, MutableColumnPtr> _object_pairs; // ColumnNullable<ColumnString>
};

#include "common/compile_check_end.h"
} // namespace doris::vectorized
Loading
Loading