Coverage Report

Created: 2026-03-12 16:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/function_reverse.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
#pragma once
18
19
#include "exprs/function/array/function_array_reverse.h"
20
#include "exprs/function/function_string.h"
21
22
namespace doris {
23
24
class FunctionReverseCommon : public IFunction {
25
public:
26
    static constexpr auto name = "reverse";
27
28
92
    static FunctionPtr create() { return std::make_shared<FunctionReverseCommon>(); }
29
30
1
    String get_name() const override { return name; }
31
32
83
    size_t get_number_of_arguments() const override { return 1; }
33
34
83
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
35
83
        DCHECK(is_string_type(arguments[0]->get_primitive_type()) ||
36
0
               arguments[0]->get_primitive_type() == TYPE_ARRAY)
37
0
                << fmt::format("Illegal type {} used for argument of function {}",
38
0
                               arguments[0]->get_name(), get_name());
39
40
83
        return arguments[0];
41
83
    }
42
43
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
44
82
                        uint32_t result, size_t input_rows_count) const override {
45
82
        ColumnPtr& src_column = block.get_by_position(arguments[0]).column;
46
82
        if (const ColumnString* col_string = check_and_get_column<ColumnString>(src_column.get())) {
47
61
            auto col_res = ColumnString::create();
48
61
            RETURN_IF_ERROR(ReverseImpl::vector(col_string->get_chars(), col_string->get_offsets(),
49
61
                                                col_res->get_chars(), col_res->get_offsets()));
50
61
            block.replace_by_position(result, std::move(col_res));
51
61
        } else if (is_column<ColumnArray>(src_column.get())) {
52
21
            return ArrayReverseImpl::_execute(block, arguments, result, input_rows_count);
53
21
        } else {
54
0
            return Status::RuntimeError("Illegal column {} used for argument of function {}",
55
0
                                        block.get_by_position(arguments[0]).column->get_name(),
56
0
                                        get_name());
57
0
        }
58
61
        return Status::OK();
59
82
    }
60
};
61
62
} // namespace doris