ClickHouse

Форк
0
/
h3ExactEdgeLengthKm.cpp 
94 строки · 2.6 Кб
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 <IO/WriteHelpers.h>
10
#include <Common/typeid_cast.h>
11
#include <base/range.h>
12

13
#include <constants.h>
14
#include <h3api.h>
15

16

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

25
namespace
26
{
27

28
class FunctionH3ExactEdgeLengthKm : public IFunction
29
{
30
public:
31
    static constexpr auto name = "h3ExactEdgeLengthKm";
32

33
    static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionH3ExactEdgeLengthKm>(); }
34

35
    std::string getName() const override { return name; }
36

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

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

50
        return std::make_shared<DataTypeFloat64>();
51
    }
52

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

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

68
        const auto & data = column->getData();
69

70
        auto dst = ColumnVector<Float64>::create();
71
        auto & dst_data = dst->getData();
72
        dst_data.resize(input_rows_count);
73

74
        for (size_t row = 0; row < input_rows_count; ++row)
75
        {
76
            const UInt64 index = data[row];
77
            Float64 res = exactEdgeLengthKm(index);
78
            dst_data[row] = res;
79
        }
80

81
        return dst;
82
    }
83
};
84

85
}
86

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

92
}
93

94
#endif
95

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

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

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

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