julianhyde commented on code in PR #3263:
URL: https://github.com/apache/calcite/pull/3263#discussion_r1232917935
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -3883,6 +3883,59 @@ private static AtomicLong getAtomicLong(String key) {
return atomic;
}
+ /** Support the ARRAYS_OVERLAP function. */
+ public static @Nullable Boolean arraysOverlap(List list1, List list2) {
+ final List bigger = list1.size() > list2.size() ? list1 : list2;
+ final List smaller = list1.size() > list2.size() ? list2 : list1;
+ boolean hasNull = false;
Review Comment:
Yes, your algorithm is probably more efficient.
However, note that `intersects` uses `contains`, which is possibly optimized
using intrinsics, and that's not nothing, especially when one or both inputs
are small.
You could assign smaller and larger using one test rather than two. In fact,
to keep it simple, I'd probably write
```
if (list1.size() > list2.size()) {
return arraysOverlap(list2, list1);
}
```
Can you add a unit test to `SqlFunctionsTest`? There are at least 16
combinations to check: each list can be empty, contain only nulls, contain a
mixture of nulls and non-nulls, and contain only non-nulls, which gives 4 * 4.
That's easier done in a Java unit test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]