-
Notifications
You must be signed in to change notification settings - Fork 9k
Expand file tree
/
Copy pathhasAny.cpp
More file actions
54 lines (46 loc) · 2.25 KB
/
Copy pathhasAny.cpp
File metadata and controls
54 lines (46 loc) · 2.25 KB
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
#include <Functions/array/hasAllAny.h>
#include <Functions/FunctionFactory.h>
#include <Functions/GatherUtils/GatherUtils.h>
namespace DB
{
class FunctionArrayHasAny final : public FunctionArrayHasAllAny
{
public:
static constexpr auto name = "hasAny";
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionArrayHasAny>(); }
FunctionArrayHasAny() : FunctionArrayHasAllAny(GatherUtils::ArraySearchType::Any, name) {}
};
REGISTER_FUNCTION(HasAny)
{
FunctionDocumentation::Description description = R"(
Checks whether two arrays have intersection by some elements.
- `Null` is processed as a value.
- The order of the values in both of the arrays does not matter.
)";
FunctionDocumentation::Syntax syntax = "hasAny(arr_x, arr_y)";
FunctionDocumentation::Arguments arguments = {
{"arr_x", "Array of any type with a set of elements.", {"Array(T)"}},
{"arr_y", "Array of any type that shares a common supertype with array `arr_x`.", {"Array(T)"}},
};
FunctionDocumentation::ReturnedValue returned_value = {R"(
- `1`, if `arr_x` and `arr_y` have one similar element at least.
- `0`, otherwise.
Raises a `NO_COMMON_TYPE` exception if any of the elements of the two arrays do not share a common supertype.
)"};
FunctionDocumentation::Examples examples = {
{"One array is empty", "SELECT hasAny([1], [])", "0"},
{"Arrays containing NULL values", "SELECT hasAny([Null], [Null, 1])", "1"},
{"Arrays containing values of a different type", "SELECT hasAny([-128, 1., 512], [1])", "1"},
{"Arrays without a common type", "SELECT hasAny([[1, 2], [3, 4]], ['a', 'c'])",
R"(
Received exception:
Code: 386. DB::Exception: There is no supertype for types Array(UInt8), String because some of them are Array and some of them are not. (NO_COMMON_TYPE)
)"},
{"Array of arrays", "SELECT hasAll([[1, 2], [3, 4]], [[1, 2], [1, 2]])", "1"},
};
FunctionDocumentation::IntroducedIn introduced_in = {1, 1};
FunctionDocumentation::Category category = FunctionDocumentation::Category::Array;
FunctionDocumentation documentation = {description, syntax, arguments, {}, returned_value, examples, introduced_in, category};
factory.registerFunction<FunctionArrayHasAny>(documentation);
}
}