ClickHouse

Форк
0
/
visitParamExtractUInt.cpp 
48 строк · 1.7 Кб
1
#include <Functions/FunctionFactory.h>
2
#include <Functions/FunctionsVisitParam.h>
3
#include <Functions/FunctionsStringSearch.h>
4

5

6
namespace DB
7
{
8

9
struct NameSimpleJSONExtractUInt { static constexpr auto name = "simpleJSONExtractUInt"; };
10
using FunctionSimpleJSONExtractUInt = FunctionsStringSearch<ExtractParamImpl<NameSimpleJSONExtractUInt, ExtractNumericType<UInt64>>>;
11

12

13
REGISTER_FUNCTION(VisitParamExtractUInt)
14
{
15
    factory.registerFunction<FunctionSimpleJSONExtractUInt>(FunctionDocumentation{
16
        .description
17
        = "Parses UInt64 from the value of the field named field_name. If this is a string field, it tries to parse a number from the "
18
          "beginning of the string. If the field does not exist, or it exists but does not contain a number, it returns 0.",
19
        .syntax = "simpleJSONExtractUInt(json, field_name)",
20
        .arguments
21
        = {{"json", "The JSON in which the field is searched for. String."},
22
           {"field_name", "The name of the field to search for. String literal."}},
23
        .returned_value = "It returns the number parsed from the field if the field exists and contains a number, 0 otherwise.",
24
        .examples
25
        = {{.name = "simple",
26
            .query = R"(CREATE TABLE jsons
27
(
28
    json String
29
)
30
ENGINE = Memory;
31

32
INSERT INTO jsons VALUES ('{"foo":"4e3"}');
33
INSERT INTO jsons VALUES ('{"foo":3.4}');
34
INSERT INTO jsons VALUES ('{"foo":5}');
35
INSERT INTO jsons VALUES ('{"foo":"not1number"}');
36
INSERT INTO jsons VALUES ('{"baz":2}');
37

38
SELECT simpleJSONExtractUInt(json, 'foo') FROM jsons ORDER BY json;)",
39
            .result = R"(0
40
4
41
0
42
3
43
5)"}},
44
        .categories{"JSON"}});
45
    factory.registerAlias("visitParamExtractUInt", "simpleJSONExtractUInt");
46
}
47

48
}
49

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

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

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

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