You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEA] Share code between left_semi_anti_join, cudf::contains, and set operations #11037
I haven't looked closely, but my suspicion is the semi_join implementation is already closer to the desired implementation I described here: #10656 (comment)
So I'd be more inclined to use that as the basis upon which contains is implemented, but I don't have strong feelings here.
semi-join currently uses static_map which in turn uses the old row comparator that doesn't support both nested data types and strong index types. So basically we can't reuse the code in *-join implementation but have to start from scratch with the solution as you just suggested.
Updating the equality/hashing operators to use the solution you suggested (#10656 (comment)) is almost starting from scratch 😃. In summary, to have *-joins and cudf::contains share their implementation, we need:
Support nested types in cudf::contains (this is what cudf::contains wants), and
Add null_equality parameter in cudf::contains (this is what *-joins need)
We can do these steps in parallel.
Edit: Just realize that *_joins can just work around null equality check during building the gather map. So I'm going to push a PR refactoring semi_anti_join to call cudf::contains. I'll also run benchmarks comparing the performance before and after the transition.
I would like the join implementation to be the source of truth.
The implementation I described is very similar to how inner_join/left_join are also implemented. It would be incongruous to have the implementation for semi_join elsewhere when in it is so similar to the implementations for the other joins.
Is it? This looks awfully close to what I already described:
No, that implementation uses the old row comparator, which doesn't support nested types. If we want nested types, that implementation needs to be modified heavily to something like we just talked in the cudf::contains PR (#10656 (comment)).
It would be incongruous to have the implementation for semi_join elsewhere when in it is so similar to the implementations for the other joins.
The problem is that, *-joins firstly check for existence (using the same result generated from cudf::contains) then build a gather_map from that result. So we can use cudf::contains as a component to implement *-join.
If you want to keep the contains implementation inside *-join, then we will have cudf::contains internally call an external function like detail::semi_anti_join_contains which seems a bit awkward to me.
@ttnghia I see your point. The semi_join implementation is essentially 1) build a hash table on the right table, 2) probe the hash table with the left table entries and generate a boolean array indicating whether each row in left matches anything in right, and 3) perform a stream compaction using the boolean array to generate a gather map, which is returned.
I think there are two conflicting considerations here.
Steps 1+2 from above are essentially contains. That suggests that semi_join should depend on contains.
contains is a single-column search, i.e. the needles are scalars (perhaps of nested types) and the haystack is a column, whereas semi_join needs to support multiple columns. That suggests that contains should depend on semi_join.
Given these two considerations I think the second option that you outlined makes more sense. The function that you call detail::semi_anti_join_contains would need to have the signature
If repeated lookups are valuable to optimize, we could extend the hash_join object to support holding either a static_multimap or a static_map as a way to also incorporate the semi_/anti_join logic into the same framework as the other joins. That would allow us to expose the containment check as a public API of hash_join object. That's probably premature at this stage however; implementing the above contains(table_view, table_view) helper function should be sufficient for now.
Okay then I'll implement contains inside semi_anti_join.
Now I even think of this as an extension of the set-like operations. Semi-join is something like set_intersect and anti-join is set_difference (but all with duplicates?). We may end up in the future to refactor it again, moving the implementation to reduction set-like operations 😃 .
To me that sounds like the last piece that I suggested: we may eventually want to implement something like a static_map version of the current hash_join object (which uses static_multimap for the other types of joins) in order to expose the hash lookup component for querying just the contains check. Using it for a single column would be suitable for contains or the various set-like operations (IIRC those are also all single columns of lists) while using it for multiple columns would be for semi/anti joins. I don't remember enough of @devavret's idea for #10409 to know if that would be consistent with what he had in mind, though.
changed the title [-][FEA] Use `cudf::contains` in `left_semi_anti_join`[/-][+][FEA] Share code between `cudf::contains` and `left_semi_anti_join`[/+]on Jun 10, 2022
changed the title [-][FEA] Share code between `cudf::contains` and `left_semi_anti_join`[/-][+][FEA] Share code between `left_semi_anti_join`, `cudf::contains`, and set operations[/+]on Jun 11, 2022
Activity
jrhemstad commentedon Jun 3, 2022
I haven't looked closely, but my suspicion is the
semi_joinimplementation is already closer to the desired implementation I described here: #10656 (comment)So I'd be more inclined to use that as the basis upon which
containsis implemented, but I don't have strong feelings here.ttnghia commentedon Jun 3, 2022
semi-joincurrently usesstatic_mapwhich in turn uses the old row comparator that doesn't support both nested data types and strong index types. So basically we can't reuse the code in*-joinimplementation but have to start from scratch with the solution as you just suggested.jrhemstad commentedon Jun 3, 2022
I don't think it would need to start from scratch. I think it would just be a matter of updating the equality/hashing operators used.
@vyasr wrote the code that is there today and should be able to help.
ttnghia commentedon Jun 3, 2022
Updating the equality/hashing operators to use the solution you suggested (#10656 (comment)) is almost starting from scratch 😃. In summary, to have *-joins and
cudf::containsshare their implementation, we need:cudf::contains(this is whatcudf::containswants), andAddnull_equalityparameter incudf::contains(this is what *-joins need)We can do these steps in parallel.
Edit: Just realize that *_joins can just work around null equality check during building the gather map. So I'm going to push a PR refactoring
semi_anti_jointo callcudf::contains. I'll also run benchmarks comparing the performance before and after the transition.jrhemstad commentedon Jun 3, 2022
Is it? This looks awfully close to what I already described: https://github.com/rapidsai/cudf/blob/fe9a4f88713f7ee1692738ce0deb5935da362134/cpp/src/join/semi_join.cu#L92-L152
I would like the join implementation to be the source of truth.
The implementation I described is very similar to how
inner_join/left_joinare also implemented. It would be incongruous to have the implementation forsemi_joinelsewhere when in it is so similar to the implementations for the other joins.ttnghia commentedon Jun 3, 2022
No, that implementation uses the old row comparator, which doesn't support nested types. If we want nested types, that implementation needs to be modified heavily to something like we just talked in the
cudf::containsPR (#10656 (comment)).The problem is that, *-joins firstly check for existence (using the same result generated from
cudf::contains) then build a gather_map from that result. So we can usecudf::containsas a component to implement *-join.If you want to keep the
containsimplementation inside *-join, then we will havecudf::containsinternally call an external function likedetail::semi_anti_join_containswhich seems a bit awkward to me.ttnghia commentedon Jun 3, 2022
So, in summary, we have 2 options:
cudf::contains:cudf::containscallsdetail::semi_anti_join_contains(which is extracted fromsemi_anti_join):What do you think? I'm fine with both although I prefer the first one.
vyasr commentedon Jun 7, 2022
@ttnghia I see your point. The
semi_joinimplementation is essentially 1) build a hash table on the right table, 2) probe the hash table with the left table entries and generate a boolean array indicating whether each row in left matches anything in right, and 3) perform a stream compaction using the boolean array to generate a gather map, which is returned.I think there are two conflicting considerations here.
contains. That suggests thatsemi_joinshould depend oncontains.containsis a single-column search, i.e. the needles are scalars (perhaps of nested types) and the haystack is a column, whereassemi_joinneeds to support multiple columns. That suggests thatcontainsshould depend onsemi_join.Given these two considerations I think the second option that you outlined makes more sense. The function that you call
detail::semi_anti_join_containswould need to have the signatureIf repeated lookups are valuable to optimize, we could extend the
hash_joinobject to support holding either astatic_multimapor astatic_mapas a way to also incorporate thesemi_/anti_joinlogic into the same framework as the other joins. That would allow us to expose the containment check as a public API ofhash_joinobject. That's probably premature at this stage however; implementing the abovecontains(table_view, table_view)helper function should be sufficient for now.ttnghia commentedon Jun 7, 2022
Okay then I'll implement
containsinsidesemi_anti_join.Now I even think of this as an extension of the set-like operations. Semi-join is something like
set_intersectandanti-joinisset_difference(but all with duplicates?). We may end up in the future to refactor it again, moving the implementation to reduction set-like operations 😃 .vyasr commentedon Jun 7, 2022
To me that sounds like the last piece that I suggested: we may eventually want to implement something like a
static_mapversion of the currenthash_joinobject (which usesstatic_multimapfor the other types of joins) in order to expose the hash lookup component for querying just thecontainscheck. Using it for a single column would be suitable forcontainsor the various set-like operations (IIRC those are also all single columns of lists) while using it for multiple columns would be for semi/anti joins. I don't remember enough of @devavret's idea for #10409 to know if that would be consistent with what he had in mind, though.[-][FEA] Use `cudf::contains` in `left_semi_anti_join`[/-][+][FEA] Share code between `cudf::contains` and `left_semi_anti_join`[/+][-][FEA] Share code between `cudf::contains` and `left_semi_anti_join`[/-][+][FEA] Share code between `left_semi_anti_join`, `cudf::contains`, and set operations[/+]Refactor `semi_anti_join` (#11100)
Fully support nested types in `cudf::contains` (#10656)
Support nested types in `lists::contains` (#10548)