Fix hasBuiltInFilters for joins (#12894)

This commit is contained in:
Rohan Garg 2022-08-13 16:26:24 +05:30 committed by GitHub
parent 836430019a
commit af700bba0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -212,8 +212,11 @@ public class HashJoinSegmentStorageAdapter implements StorageAdapter
@Override
public boolean hasBuiltInFilters()
{
return clauses.stream()
.anyMatch(clause -> clause.getJoinType() == JoinType.INNER && !clause.getCondition().isAlwaysTrue());
// if the baseFilter is not null, then rows from underlying storage adapter can be potentially filtered.
// otherwise, a filtering inner join can also filter rows.
return baseFilter != null || clauses.stream().anyMatch(
clause -> clause.getJoinType() == JoinType.INNER && !clause.getCondition().isAlwaysTrue()
);
}
@Override

View File

@ -20,6 +20,7 @@
package org.apache.druid.segment.join;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import org.apache.druid.common.config.NullHandling;
import org.apache.druid.java.util.common.DateTimes;
@ -29,6 +30,7 @@ import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.math.expr.ExprMacroTable;
import org.apache.druid.query.filter.ExpressionDimFilter;
import org.apache.druid.query.filter.Filter;
import org.apache.druid.query.filter.InDimFilter;
import org.apache.druid.query.filter.OrDimFilter;
import org.apache.druid.query.filter.SelectorDimFilter;
import org.apache.druid.segment.VirtualColumn;
@ -2305,6 +2307,19 @@ public class HashJoinSegmentStorageAdapterTest extends BaseHashJoinSegmentStorag
);
}
@Test
public void test_hasBuiltInFiltersForConvertedJoin()
{
Assert.assertTrue(
new HashJoinSegmentStorageAdapter(
factSegment.asStorageAdapter(),
new InDimFilter("dim", ImmutableSet.of("foo", "bar")),
ImmutableList.of(),
null
).hasBuiltInFilters()
);
}
@Test
public void test_hasBuiltInFiltersForMultipleJoinableClausesWithVariousJoinTypes()
{