| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <Common/memcmpSmall.h> |
| 4 | #include <Columns/ColumnString.h> |
| 5 | #include <Functions/FunctionFactory.h> |
| 6 | |
| 7 | |
| 8 | namespace DB |
| 9 | { |
| 10 | |
| 11 | namespace ErrorCodes |
| 12 | { |
| 13 | extern const int LOGICAL_ERROR; |
| 14 | } |
| 15 | |
| 16 | |
| 17 | template <bool negative = false> |
| 18 | struct EmptyImpl |
| 19 | { |
| 20 | /// If the function will return constant value for FixedString data type. |
| 21 | static constexpr auto is_fixed_to_constant = false; |
| 22 | |
| 23 | static void vector(const ColumnString::Chars & /*data*/, const ColumnString::Offsets & offsets, PaddedPODArray<UInt8> & res) |
| 24 | { |
| 25 | size_t size = offsets.size(); |
| 26 | ColumnString::Offset prev_offset = 1; |
| 27 | for (size_t i = 0; i < size; ++i) |
| 28 | { |
| 29 | res[i] = negative ^ (offsets[i] == prev_offset); |
| 30 | prev_offset = offsets[i] + 1; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /// Only make sense if is_fixed_to_constant. |
| 35 | static void vector_fixed_to_constant(const ColumnString::Chars & /*data*/, size_t /*n*/, UInt8 & /*res*/) |
| 36 | { |
| 37 | throw Exception("Logical error: 'vector_fixed_to_constant method' is called", ErrorCodes::LOGICAL_ERROR); |
| 38 | } |
| 39 | |
| 40 | static void vector_fixed_to_vector(const ColumnString::Chars & data, size_t n, PaddedPODArray<UInt8> & res) |
| 41 | { |
| 42 | size_t size = data.size() / n; |
| 43 | for (size_t i = 0; i < size; ++i) |
| 44 | res[i] = negative ^ memoryIsZeroSmallAllowOverflow15(data.data() + i * n, n); |
| 45 | } |
| 46 | |
| 47 | static void array(const ColumnString::Offsets & offsets, PaddedPODArray<UInt8> & res) |
| 48 | { |
| 49 | size_t size = offsets.size(); |
| 50 | ColumnString::Offset prev_offset = 0; |
| 51 | for (size_t i = 0; i < size; ++i) |
| 52 | { |
| 53 | res[i] = negative ^ (offsets[i] == prev_offset); |
| 54 | prev_offset = offsets[i]; |
| 55 | } |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | } |
| 60 |