linrrzqqq commented on code in PR #67397:
URL: https://github.com/apache/doris/pull/67397#discussion_r3925630446
##########
be/src/exprs/function/array/function_array_pop.cpp:
##########
@@ -104,9 +106,74 @@ class FunctionArrayPopfront : public
FunctionArrayPop<FunctionArrayPopfront> {
static constexpr int start_offset = 2;
};
+class FunctionArrayTrim : public IFunction {
+public:
+ static constexpr auto name = "trim_array";
+ static FunctionPtr create() { return
std::make_shared<FunctionArrayTrim>(); }
+
+ String get_name() const override { return name; }
+
+ bool is_variadic() const override { return false; }
+
+ size_t get_number_of_arguments() const override { return 2; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ DCHECK(arguments[0]->get_primitive_type() == TYPE_ARRAY)
+ << "First argument for function: " << name
+ << " should be DataTypeArray but it has type " <<
arguments[0]->get_name() << ".";
+ DCHECK(arguments[1]->get_primitive_type() == TYPE_BIGINT)
+ << "Second argument for function: " << name << " should be
BigInt but it has type "
+ << arguments[1]->get_name() << ".";
+ return arguments[0];
+ }
+
+ Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
+ uint32_t result, size_t input_rows_count) const
override {
+ auto array_column =
+
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+ auto size_column =
+
block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+
+ ColumnArrayExecutionData src;
+ if (!extract_column_array_info(*array_column, src)) {
+ return Status::RuntimeError(
+ fmt::format("execute failed, unsupported types for
function {}({}, {})",
+ get_name(),
block.get_by_position(arguments[0]).type->get_name(),
+
block.get_by_position(arguments[1]).type->get_name()));
+ }
+
+ auto length_column = ColumnInt64::create();
+ length_column->reserve(input_rows_count);
+ const auto& sizes = assert_cast<const
ColumnInt64&>(*size_column).get_data();
+ for (size_t row = 0; row < input_rows_count; ++row) {
+ const auto size = sizes[row];
+ const size_t offset = (*src.offsets_ptr)[row - 1];
+ const size_t cardinality = (*src.offsets_ptr)[row] - offset;
+ if (UNLIKELY(size < 0)) {
+ return Status::InvalidArgument("size must not be negative:
{}", size);
+ }
+ if (UNLIKELY(static_cast<size_t>(size) > cardinality)) {
Review Comment:
这里估计得重写 `use_default_implementation_for_nulls`, 外层默认的 null 处理,对于 array
列来说会替换为`[]`, size == 0, 所以如果使用默认处理框架,应该会报错,得手动处理 null
--
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]