ClickHouse

Форк
0
/
visitParamExtractString.cpp 
59 строк · 2.2 Кб
1
#include <Functions/FunctionFactory.h>
2
#include <Functions/FunctionsVisitParam.h>
3
#include <Functions/FunctionsStringSearchToString.h>
4

5

6
namespace DB
7
{
8

9
struct ExtractString
10
{
11
    static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars & res_data)
12
    {
13
        size_t old_size = res_data.size();
14
        ReadBufferFromMemory in(pos, end - pos);
15
        if (!tryReadJSONStringInto(res_data, in, default_json_settings))
16
            res_data.resize(old_size);
17
    }
18

19
    static const FormatSettings::JSON constexpr default_json_settings;
20
};
21

22
struct NameSimpleJSONExtractString { static constexpr auto name = "simpleJSONExtractString"; };
23
using FunctionSimpleJSONExtractString = FunctionsStringSearchToString<ExtractParamToStringImpl<ExtractString>, NameSimpleJSONExtractString>;
24

25
REGISTER_FUNCTION(VisitParamExtractString)
26
{
27
    factory.registerFunction<FunctionSimpleJSONExtractString>(FunctionDocumentation{
28
        .description = R"(Parses String in double quotes from the value of the field named field_name.
29

30
        There is currently no support for code points in the format \uXXXX\uYYYY that are not from the basic multilingual plane (they are converted to CESU-8 instead of UTF-8).)",
31
        .syntax = "simpleJSONExtractString(json, field_name)",
32
        .arguments
33
        = {{"json", "The JSON in which the field is searched for. String."},
34
           {"field_name", "The name of the field to search for. String literal."}},
35
        .returned_value = "It returns the value of a field as a String, including separators. The value is unescaped. It returns an empty "
36
                          "String: if the field doesn't contain a double quoted string, if unescaping fails or if the field doesn't exist.",
37
        .examples
38
        = {{.name = "simple",
39
            .query = R"(CREATE TABLE jsons
40
(
41
    json String
42
)
43
ENGINE = Memory;
44

45
INSERT INTO jsons VALUES ('{"foo":"\\n\\u0000"}');
46
INSERT INTO jsons VALUES ('{"foo":"\\u263"}');
47
INSERT INTO jsons VALUES ('{"foo":"\\u263a"}');
48
INSERT INTO jsons VALUES ('{"foo":"hello}');
49

50
SELECT simpleJSONExtractString(json, 'foo') FROM jsons ORDER BY json;)",
51
            .result = R"(\n\0
52

53
54
)"}},
55
        .categories{"JSON"}});
56
    factory.registerAlias("visitParamExtractString", "simpleJSONExtractString");
57
}
58

59
}
60

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

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

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

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