Coverage Report

Created: 2024-11-21 12:31

/root/doris/be/src/vec/functions/uuid.cpp
Line
Count
Source (jump to first uncovered line)
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
#include <glog/logging.h>
19
#include <stddef.h>
20
21
#include <boost/uuid/random_generator.hpp>
22
#include <boost/uuid/uuid_io.hpp>
23
#include <memory>
24
#include <string>
25
#include <utility>
26
27
#include "common/status.h"
28
#include "vec/aggregate_functions/aggregate_function.h"
29
#include "vec/columns/column_string.h"
30
#include "vec/core/block.h"
31
#include "vec/core/column_numbers.h"
32
#include "vec/core/types.h"
33
#include "vec/data_types/data_type_string.h"
34
#include "vec/functions/function.h"
35
#include "vec/functions/simple_function_factory.h"
36
37
namespace doris {
38
class FunctionContext;
39
} // namespace doris
40
41
namespace doris::vectorized {
42
class Uuid : public IFunction {
43
public:
44
    static constexpr auto name = "uuid";
45
    static constexpr size_t uuid_length = 36; //uuid fixed length
46
47
1
    static FunctionPtr create() { return std::make_shared<Uuid>(); }
48
49
0
    String get_name() const override { return name; }
50
51
0
    bool use_default_implementation_for_constants() const override { return false; }
52
53
0
    size_t get_number_of_arguments() const override { return 0; }
54
55
0
    bool is_variadic() const override { return false; }
56
57
0
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
58
0
        return std::make_shared<DataTypeString>();
59
0
    }
60
61
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
62
0
                        uint32_t result, size_t input_rows_count) const override {
63
0
        auto col_res = ColumnString::create();
64
0
        col_res->get_offsets().reserve(input_rows_count);
65
0
        col_res->get_chars().reserve(input_rows_count * uuid_length);
66
67
0
        boost::uuids::random_generator generator;
68
0
        for (int i = 0; i < input_rows_count; i++) {
69
0
            std::string uuid = boost::uuids::to_string(generator());
70
0
            DCHECK(uuid.length() == uuid_length);
71
0
            col_res->insert_data_without_reserve(uuid.c_str(), uuid.length());
72
0
        }
73
74
0
        block.replace_by_position(result, std::move(col_res));
75
0
        return Status::OK();
76
0
    }
77
};
78
79
1
void register_function_uuid(SimpleFunctionFactory& factory) {
80
1
    factory.register_function<Uuid>();
81
1
}
82
83
} // namespace doris::vectorized