ClickHouse

Форк
0
/
firstLine.cpp 
42 строки · 1.3 Кб
1
#include <Functions/FunctionFactory.h>
2
#include <Functions/FunctionStringToString.h>
3
#include <Functions/StringHelpers.h>
4
#include <base/find_symbols.h>
5

6
namespace DB
7
{
8

9
struct FirstLine
10
{
11
    static size_t getReserveLengthForElement() { return 16; }
12

13
    static void execute(Pos data, size_t size, Pos & res_data, size_t & res_size)
14
    {
15
        res_data = data;
16

17
        const Pos end = data + size;
18
        const Pos pos = find_first_symbols<'\r', '\n'>(data, end);
19
        res_size = pos - data;
20
    }
21
};
22

23
struct NameFirstLine
24
{
25
    static constexpr auto name = "firstLine";
26
};
27

28
using FunctionFirstLine = FunctionStringToString<ExtractSubstringImpl<FirstLine>, NameFirstLine>;
29

30
REGISTER_FUNCTION(FirstLine)
31
{
32
    factory.registerFunction<FunctionFirstLine>(FunctionDocumentation{
33
        .description = "Returns first line of a multi-line string.",
34
        .syntax = "firstLine(string)",
35
        .arguments = {{.name = "string", .description = "The string to process."}},
36
        .returned_value = {"The first line of the string or the whole string if there is no line separators."},
37
        .examples = {
38
            {.name = "Return first line", .query = "firstLine('Hello\\nWorld')", .result = "'Hello'"},
39
            {.name = "Return whole string", .query = "firstLine('Hello World')", .result = "'Hello World'"},
40
        }});
41
}
42
}
43

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

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

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

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