rohangarg commented on code in PR #12225:
URL: https://github.com/apache/druid/pull/12225#discussion_r878898786
##########
processing/src/main/java/org/apache/druid/segment/join/JoinableFactoryWrapper.java:
##########
@@ -276,28 +272,31 @@ static Optional<Filter> convertJoinToFilter(
&& clause.getCondition().getEquiConditions().size() > 0) {
final List<Filter> filters = new ArrayList<>();
int numValues = maxNumFilterValues;
+ boolean dropClause = true;
for (final Equality condition :
clause.getCondition().getEquiConditions()) {
final String leftColumn =
condition.getLeftExpr().getBindingIfIdentifier();
if (leftColumn == null) {
- return Optional.empty();
+ return new NonnullPair<>(Optional.empty(), false);
}
- final Optional<Set<String>> columnValuesForFilter =
-
clause.getJoinable().getNonNullColumnValuesIfAllUnique(condition.getRightColumn(),
numValues);
+ Joinable.ColumnValuesWithUniqueFlag columnValuesWithUniqueFlag =
clause.getJoinable().getNonNullColumnValues(condition.getRightColumn(),
numValues);
+ if (columnValuesWithUniqueFlag.getColumnValues().isEmpty()) {
+ dropClause = false;
+ continue;
+ }
- if (columnValuesForFilter.isPresent()) {
- numValues -= columnValuesForFilter.get().size();
- filters.add(Filters.toFilter(new InDimFilter(leftColumn,
columnValuesForFilter.get())));
- } else {
- return Optional.empty();
+ numValues -= columnValuesWithUniqueFlag.getColumnValues().size();
+ filters.add(Filters.toFilter(new InDimFilter(leftColumn,
columnValuesWithUniqueFlag.getColumnValues())));
+ if (!columnValuesWithUniqueFlag.isAllUnique()) {
+ dropClause = false;
}
}
- return Optional.of(Filters.and(filters));
+ return new NonnullPair<>(filters.isEmpty() ? Optional.empty() :
Optional.of(Filters.and(filters)), dropClause);
Review Comment:
> Will we ever get filters = Optional.empty() and dropClause = true? If so
what is the expectation in that case?
Yes, that can happen if the joinableClause has conditions on columns which
only have nulls in it. Currently, in such a case I add a `FalseFilter` in place
of the joinable clause - does that seem ok?
> IMO, the NonnullPair is tough to think about here, so a special class
would be better. That way it could have some javadocs about the expectations.
Its constructor should also do any relevant invariant checks.
Yes, completely agree. 👍 Thanks for the suggestion - I've made a holder
instead of a pair and added documentation regarding its semantics.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]