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 | |
30 | namespace DB::GatherUtils |
31 | { |
32 | |
33 | std::unique_ptr<IArraySource> createArraySource(const ColumnArray & col, bool is_const, size_t total_rows); |
34 | std::unique_ptr<IValueSource> createValueSource(const IColumn & col, bool is_const, size_t total_rows); |
35 | std::unique_ptr<IArraySink> createArraySink(ColumnArray & col, size_t column_size); |
36 | |
37 | void concat(const std::vector<std::unique_ptr<IArraySource>> & sources, IArraySink & sink); |
38 | |
39 | void sliceFromLeftConstantOffsetUnbounded(IArraySource & src, IArraySink & sink, size_t offset); |
40 | void sliceFromLeftConstantOffsetBounded(IArraySource & src, IArraySink & sink, size_t offset, ssize_t length); |
41 | |
42 | void sliceFromRightConstantOffsetUnbounded(IArraySource & src, IArraySink & sink, size_t offset); |
43 | void sliceFromRightConstantOffsetBounded(IArraySource & src, IArraySink & sink, size_t offset, ssize_t length); |
44 | |
45 | void sliceDynamicOffsetUnbounded(IArraySource & src, IArraySink & sink, const IColumn & offset_column); |
46 | void sliceDynamicOffsetBounded(IArraySource & src, IArraySink & sink, const IColumn & offset_column, const IColumn & length_column); |
47 | |
48 | void sliceHas(IArraySource & first, IArraySource & second, bool all, ColumnUInt8 & result); |
49 | |
50 | void push(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, bool push_back); |
51 | |
52 | void resizeDynamicSize(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, const IColumn & size_column); |
53 | |
54 | void resizeConstantSize(IArraySource & array_source, IValueSource & value_source, IArraySink & sink, ssize_t size); |
55 | |
56 | } |
57 | |
58 | |