Fix NPE when using IndexedTable and all left rows are filtered out (#9490)

* Fix NPE when using IndexedTable and all left rows are filtered out

* Fix compile

* Add constant for uninitialized current row

* Fix checkstyle
This commit is contained in:
Jonathan Wei 2020-03-11 19:23:05 -07:00 committed by GitHub
parent 2ef5c17441
commit 3082b9289a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -59,6 +59,8 @@ import java.util.stream.Collectors;
public class IndexedTableJoinMatcher implements JoinMatcher
{
private static final int UNINITIALIZED_CURRENT_ROW = -1;
private final IndexedTable table;
private final List<Supplier<IntIterator>> conditionMatchers;
private final IntIterator[] currentMatchedRows;
@ -81,6 +83,7 @@ public class IndexedTableJoinMatcher implements JoinMatcher
)
{
this.table = table;
this.currentRow = UNINITIALIZED_CURRENT_ROW;
if (condition.isAlwaysTrue()) {
this.conditionMatchers = Collections.singletonList(() -> IntIterators.fromTo(0, table.numRows()));
@ -231,7 +234,7 @@ public class IndexedTableJoinMatcher implements JoinMatcher
// Do not reset matchedRows; we want to remember it across reset() calls so the 'remainder' is anything
// that was unmatched across _all_ cursor walks.
currentIterator = null;
currentRow = -1;
currentRow = UNINITIALIZED_CURRENT_ROW;
matchingRemainder = false;
}
@ -241,7 +244,7 @@ public class IndexedTableJoinMatcher implements JoinMatcher
currentRow = currentIterator.nextInt();
} else {
currentIterator = null;
currentRow = -1;
currentRow = UNINITIALIZED_CURRENT_ROW;
}
}

View File

@ -33,6 +33,7 @@ import org.apache.druid.query.filter.SelectorDimFilter;
import org.apache.druid.segment.VirtualColumns;
import org.apache.druid.segment.column.ColumnCapabilities;
import org.apache.druid.segment.column.ValueType;
import org.apache.druid.segment.filter.SelectorFilter;
import org.apache.druid.segment.join.lookup.LookupJoinable;
import org.apache.druid.segment.join.table.IndexedTableJoinable;
import org.apache.druid.segment.virtual.ExpressionVirtualColumn;
@ -1258,4 +1259,30 @@ public class HashJoinSegmentStorageAdapterTest extends BaseHashJoinSegmentStorag
ImmutableList.of()
);
}
@Test
public void test_makeCursors_factToCountryLeft_filterExcludesAllLeftRows()
{
JoinTestHelper.verifyCursors(
new HashJoinSegmentStorageAdapter(
factSegment.asStorageAdapter(),
ImmutableList.of(factToCountryOnIsoCode(JoinType.LEFT))
).makeCursors(
new SelectorFilter("page", "this matches nothing"),
Intervals.ETERNITY,
VirtualColumns.EMPTY,
Granularities.ALL,
false,
null
),
ImmutableList.of(
"page",
"countryIsoCode",
FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryIsoCode",
FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryName",
FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryNumber"
),
ImmutableList.of()
);
}
}