aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/GatherUtils/ends_with.cpp
blob: 579d903005a668d64130c606930d1eb529ebe2a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "GatherUtils.h"
#include "Selectors.h"
#include "Algorithms.h"

namespace DB::GatherUtils
{

namespace
{

struct ArrayEndsWithSelectArraySourcePair : public ArraySourcePairSelector<ArrayEndsWithSelectArraySourcePair>
{
    template <typename FirstSource, typename SecondSource>
    static void callFunction(FirstSource && first,
                             bool is_second_const, bool is_second_nullable, SecondSource && second,
                             ColumnUInt8 & result)
    {
        using SourceType = typename std::decay<SecondSource>::type;

        if (is_second_nullable)
        {
            using NullableSource = NullableArraySource<SourceType>;

            if (is_second_const)
                arrayAllAny<ArraySearchType::EndsWith>(first, static_cast<ConstSource<NullableSource> &>(second), result);
            else
                arrayAllAny<ArraySearchType::EndsWith>(first, static_cast<NullableSource &>(second), result);
        }
        else
        {
            if (is_second_const)
                arrayAllAny<ArraySearchType::EndsWith>(first, static_cast<ConstSource<SourceType> &>(second), result);
            else
                arrayAllAny<ArraySearchType::EndsWith>(first, second, result);
        }
    }

    template <typename FirstSource, typename SecondSource>
    static void selectSourcePair(bool is_first_const, bool is_first_nullable, FirstSource && first,
                                 bool is_second_const, bool is_second_nullable, SecondSource && second,
                                 ColumnUInt8 & result)
    {
        using SourceType = typename std::decay<FirstSource>::type;

        if (is_first_nullable)
        {
            using NullableSource = NullableArraySource<SourceType>;

            if (is_first_const)
                callFunction(static_cast<ConstSource<NullableSource> &>(first), is_second_const, is_second_nullable, second, result);
            else
                callFunction(static_cast<NullableSource &>(first), is_second_const, is_second_nullable, second, result);
        }
        else
        {
            if (is_first_const)
                callFunction(static_cast<ConstSource<SourceType> &>(first), is_second_const, is_second_nullable, second, result);
            else
                callFunction(first, is_second_const, is_second_nullable, second, result);
        }
    }
};

}

void sliceHasEndsWith(IArraySource & first, IArraySource & second, ColumnUInt8 & result)
{
    ArrayEndsWithSelectArraySourcePair::select(first, second, result);
}

}