CodeCommitsIssuesPull requestsActionsInsightsSecurity
0510911559cf5fd401418c18b7e230f336246d24

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Functions/GatherUtils/GatherUtils.h

64lines · modecode

1#pragma once
2
3#include <type_traits>
4
5#include <Columns/ColumnArray.h>
6#include <Columns/ColumnsNumber.h>
7
8#include "IValueSource.h"
9#include "IArraySource.h"
10#include "IArraySink.h"
11
12/** These methods are intended for implementation of functions, that
13 * copy ranges from one or more columns to another column.
14 *
15 * Example:
16 * - concatenation of strings and arrays (concat);
17 * - extracting slices and elements of strings and arrays (substring, arraySlice, arrayElement);
18 * - creating arrays from several columns ([x, y]);
19 * - conditional selecting from several string or array columns (if, multiIf);
20 * - push and pop elements from array front or back (arrayPushBack, etc);
21 * - splitting strings into arrays and joining arrays back;
22 * - formatting strings (format).
23 *
24 * There are various Sources, Sinks and Slices.
25 * Source - allows to iterate over a column and obtain Slices.
26 * Slice - a reference to elements to copy.
27 * Sink - allows to build result column by copying Slices into it.
28 */
29
30namespace DB::GatherUtils
31{
32
33enum class ArraySearchType
34{
35 Any, // Corresponds to the hasAny array function
36 All, // Corresponds to the hasAll array function
37 Substr // Corresponds to the hasSubstr array function
38};
39
40std::unique_ptr<IArraySource> createArraySource(const ColumnArray & col, bool is_const, size_t total_rows);
41std::unique_ptr<IValueSource> createValueSource(const IColumn & col, bool is_const, size_t total_rows);
42std::unique_ptr<IArraySink> createArraySink(ColumnArray & col, size_t column_size);
43
44void concat(const std::vector<std::unique_ptr<IArraySource>> & sources, IArraySink & sink);
45
46void sliceFromLeftConstantOffsetUnbounded(IArraySource & src, IArraySink & sink, size_t offset);
47void sliceFromLeftConstantOffsetBounded(IArraySource & src, IArraySink & sink, size_t offset, ssize_t length);
48
49void sliceFromRightConstantOffsetUnbounded(IArraySource & src, IArraySink & sink, size_t offset);
50void sliceFromRightConstantOffsetBounded(IArraySource & src, IArraySink & sink, size_t offset, ssize_t length);
51
52void sliceDynamicOffsetUnbounded(IArraySource & src, IArraySink & sink, const IColumn & offset_column);
53void sliceDynamicOffsetBounded(IArraySource & src, IArraySink & sink, const IColumn & offset_column, const IColumn & length_column);
54
55void sliceHas(IArraySource & first, IArraySource & second, ArraySearchType & search_type, ColumnUInt8 & result);
56
57void push(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, bool push_front);
58
59void resizeDynamicSize(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, const IColumn & size_column);
60
61void resizeConstantSize(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, ssize_t size);
62
63}