ClickHouse

Форк
0
/
visitParamExtractFloat.cpp 
47 строк · 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 NameSimpleJSONExtractFloat { static constexpr auto name = "simpleJSONExtractFloat"; };
10
using FunctionSimpleJSONExtractFloat = FunctionsStringSearch<ExtractParamImpl<NameSimpleJSONExtractFloat, ExtractNumericType<Float64>>>;
11

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

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

37
SELECT simpleJSONExtractFloat(json, 'foo') FROM jsons ORDER BY json;)",
38
            .result = R"(0
39
-4000
40
0
41
-3.4
42
5)"}},
43
        .categories{"JSON"}});
44
    factory.registerAlias("visitParamExtractFloat", "simpleJSONExtractFloat");
45
}
46

47
}
48

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

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

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

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