Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]Support array_contains_seq functions like trino contains_sequence and ck hasSubstr function #33929

Merged
merged 19 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
aa015a8
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Oct 30, 2023
950bd8f
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Oct 30, 2023
e894887
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Oct 30, 2023
7bce46a
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Oct 31, 2023
4e564b3
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Oct 31, 2023
6fc6a75
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Oct 31, 2023
972e8ed
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 1, 2023
c574a79
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 2, 2023
5046ff4
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 2, 2023
37bcfa6
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 2, 2023
478c2de
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 2, 2023
1f73ee6
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 2, 2023
3bdd409
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 3, 2023
16d3f0c
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 3, 2023
efead1a
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 3, 2023
d7b8ace
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 7, 2023
a3724c8
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 8, 2023
6ed5253
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 8, 2023
2bbaa0d
support array_contains_seq functions like trino contains_sequence and…
leoyy0316 Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support array_contains_seq functions like trino contains_sequence and…
… ck hasSubstr

Signed-off-by: leoyy0316 <571684903@qq.com>
  • Loading branch information
leoyy0316 committed Nov 2, 2023
commit c574a79b7d0a400599bbd235562b87abd9196f93
19 changes: 18 additions & 1 deletion be/src/exprs/array_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ class ArrayHasImpl {
std::is_same_v<MapColumn, ElementColumn> ||
std::is_same_v<StructColumn, ElementColumn>,
uint8_t, typename ElementColumn::ValueType>;
[[maybe_unused]] auto is_null = [](const NullColumn::Container* null_map, size_t idx) -> bool {
return (*null_map)[idx] != 0;
};
if (element_end < target_end) {
return false;
}
Expand All @@ -775,7 +778,21 @@ class ArrayHasImpl {
} else {
auto elements_ptr = (const ValueType*)(elements.raw_data());
auto targets_ptr = (const ValueType*)(targets.raw_data());
found = (elements_ptr[j] == targets_ptr[i]);
bool null_target = false;
if constexpr (NullableTarget) {
null_target = is_null(null_map_targets, i);
}
bool null_element = false;
if constexpr (NullableElement) {
null_element = is_null(null_map_elements, j);
}
if (null_target && null_element) {
found = true;
} else if (null_target || null_element) {
found = false;
} else {
found = (elements_ptr[j] == targets_ptr[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            if constexpr (std::is_same_v<ArrayColumn, ElementColumn> || std::is_same_v<MapColumn, ElementColumn> ||
                          std::is_same_v<StructColumn, ElementColumn> || std::is_same_v<JsonColumn, ElementColumn>) {
                found = (elements.equals(j, targets, i) == 1);
            } else

should move here

}
}
if (found) {
i++;
Expand Down
28 changes: 28 additions & 0 deletions test/sql/test_array_fn/R/test_array_fn
Original file line number Diff line number Diff line change
Expand Up @@ -4454,4 +4454,32 @@ select array_contains_seq([map([1,2,5],[2,4,5])], [map([1,2,5],[2,4,5])]);
select array_contains_seq([map([1,2,5],[2,4,5])], [map([1,2],[2,4])]);
-- result:
0
-- !result
select array_contains_seq([1, 2, NULL, 3, 4], ['a']);
-- result:
0
-- !result
SELECT array_contains_seq([1, 2, NULL, 3, 4], [2,3]);
-- result:
0
-- !result
SELECT array_contains_seq([1, 2, NULL, 3, 4], null);
-- result:
NULL
-- !result
SELECT array_contains_seq(null, [2,3])
-- result:
NULL
-- !result
SELECT array_contains_seq([1, 2, NULL, 3, 4], [null,null])
-- result:
0
-- !result
SELECT array_contains_seq([1, 2, NULL], [null,2])
-- result:
0
-- !result
SELECT array_contains_seq(null, null)
-- result:
NULL
-- !result
7 changes: 7 additions & 0 deletions test/sql/test_array_fn/T/test_array_fn
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,10 @@ select array_contains_seq([json_keys('{"a":1,"b":2}')], [json_keys('{"a":1}')]);
select array_contains_seq([json_keys('{"a":1,"b":2}')], [json_keys('{"a":1,"b":2}')]);
select array_contains_seq([map([1,2,5],[2,4,5])], [map([1,2,5],[2,4,5])]);
select array_contains_seq([map([1,2,5],[2,4,5])], [map([1,2],[2,4])]);
select array_contains_seq([1, 2, NULL, 3, 4], ['a']);
SELECT array_contains_seq([1, 2, NULL, 3, 4], [2,3]);
SELECT array_contains_seq([1, 2, NULL, 3, 4], null);
SELECT array_contains_seq(null, [2,3])
SELECT array_contains_seq([1, 2, NULL, 3, 4], [null,null])
SELECT array_contains_seq([1, 2, NULL], [null,2])
SELECT array_contains_seq(null, null)