ClickHouse

Форк
0
/
h3GetResolution.cpp 
94 строки · 2.5 Кб
1
#include "config.h"
2

3
#if USE_H3
4

5
#include <Columns/ColumnsNumber.h>
6
#include <DataTypes/DataTypesNumber.h>
7
#include <Functions/FunctionFactory.h>
8
#include <Functions/IFunction.h>
9
#include <Common/typeid_cast.h>
10
#include <base/range.h>
11

12
#include <h3api.h>
13

14

15
namespace DB
16
{
17
namespace ErrorCodes
18
{
19
    extern const int ILLEGAL_TYPE_OF_ARGUMENT;
20
    extern const int ILLEGAL_COLUMN;
21
}
22

23
namespace
24
{
25

26
class FunctionH3GetResolution : public IFunction
27
{
28
public:
29
    static constexpr auto name = "h3GetResolution";
30

31
    static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionH3GetResolution>(); }
32

33
    std::string getName() const override { return name; }
34

35
    size_t getNumberOfArguments() const override { return 1; }
36
    bool useDefaultImplementationForConstants() const override { return true; }
37
    bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
38

39
    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
40
    {
41
        const auto * arg = arguments[0].get();
42
        if (!WhichDataType(arg).isUInt64())
43
            throw Exception(
44
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
45
                "Illegal type {} of argument {} of function {}. Must be UInt64",
46
                arg->getName(), 1, getName());
47

48
        return std::make_shared<DataTypeUInt8>();
49
    }
50

51
    ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
52
    {
53
        auto non_const_arguments = arguments;
54
        for (auto & argument : non_const_arguments)
55
            argument.column = argument.column->convertToFullColumnIfConst();
56

57
        const auto * column = checkAndGetColumn<ColumnUInt64>(non_const_arguments[0].column.get());
58
        if (!column)
59
            throw Exception(
60
                ErrorCodes::ILLEGAL_COLUMN,
61
                "Illegal type {} of argument {} of function {}. Must be UInt64.",
62
                arguments[0].type->getName(),
63
                1,
64
                getName());
65

66
        const auto & data = column->getData();
67

68
        auto dst = ColumnVector<UInt8>::create();
69
        auto & dst_data = dst->getData();
70
        dst_data.resize(input_rows_count);
71

72
        for (size_t row = 0; row < input_rows_count; ++row)
73
        {
74
            const UInt64 hindex = data[row];
75

76
            UInt8 res = getResolution(hindex);
77

78
            dst_data[row] = res;
79
        }
80

81
        return dst;
82
    }
83
};
84

85
}
86

87
REGISTER_FUNCTION(H3GetResolution)
88
{
89
    factory.registerFunction<FunctionH3GetResolution>();
90
}
91

92
}
93

94
#endif
95

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.