be/src/exprs/function/function_grouping.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 | | |
18 | | #pragma once |
19 | | |
20 | | #include <glog/logging.h> |
21 | | #include <stddef.h> |
22 | | |
23 | | #include <algorithm> |
24 | | #include <boost/iterator/iterator_facade.hpp> |
25 | | #include <memory> |
26 | | |
27 | | #include "common/status.h" |
28 | | #include "core/block/block.h" |
29 | | #include "core/block/column_numbers.h" |
30 | | #include "core/block/column_with_type_and_name.h" |
31 | | #include "core/block/columns_with_type_and_name.h" |
32 | | #include "core/column/column.h" |
33 | | #include "core/column/column_nullable.h" |
34 | | #include "core/data_type/data_type.h" |
35 | | #include "core/data_type/data_type_number.h" |
36 | | #include "core/types.h" |
37 | | #include "exprs/function/function.h" |
38 | | |
39 | | namespace doris { |
40 | | class FunctionContext; |
41 | | } // namespace doris |
42 | | |
43 | | namespace doris { |
44 | | |
45 | | class FunctionGroupingBase : public IFunction { |
46 | | public: |
47 | 0 | size_t get_number_of_arguments() const override { return 1; } |
48 | | |
49 | 0 | bool use_default_implementation_for_nulls() const override { return false; } |
50 | | |
51 | 0 | DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { |
52 | 0 | return std::make_shared<DataTypeInt64>(); |
53 | 0 | } |
54 | | |
55 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
56 | 0 | uint32_t result, size_t input_rows_count) const override { |
57 | 0 | const ColumnWithTypeAndName& src_column = block.get_by_position(arguments[0]); |
58 | 0 | DCHECK(src_column.column->size() == input_rows_count); |
59 | | // result of functions grouping and grouping_id is always not nullable, |
60 | | // but outer join will convert the column to nullable when necessary, |
61 | | // so need to remove nullable here when functions grouping and grouping_id are executed |
62 | 0 | block.get_by_position(result).column = remove_nullable(src_column.column); |
63 | 0 | return Status::OK(); |
64 | 0 | } |
65 | | }; |
66 | | |
67 | | class FunctionGrouping : public FunctionGroupingBase { |
68 | | public: |
69 | | static constexpr auto name = "grouping"; |
70 | | |
71 | 9 | static FunctionPtr create() { return std::make_shared<FunctionGrouping>(); } |
72 | | |
73 | 1 | String get_name() const override { return name; } |
74 | | }; |
75 | | |
76 | | class FunctionGroupingId : public FunctionGroupingBase { |
77 | | public: |
78 | | static constexpr auto name = "grouping_id"; |
79 | | |
80 | 9 | static FunctionPtr create() { return std::make_shared<FunctionGroupingId>(); } |
81 | | |
82 | 1 | String get_name() const override { return name; } |
83 | | }; |
84 | | } // namespace doris |