Skip to content

Commit

Permalink
fix IndexedStringDruidPredicateIndexes to not needlessly lookup index…
Browse files Browse the repository at this point in the history
… of values (apache#16860)
  • Loading branch information
clintropolis authored Aug 8, 2024
1 parent 7f67d26 commit 6cd8c6b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public Iterable<ImmutableBitmap> getBitmapIterable(boolean includeUnknown)
return () -> new Iterator<ImmutableBitmap>()
{
final Iterator<String> iterator = dictionary.iterator();
@Nullable
String next = null;
boolean nextSet = false;
int index = -1;

@Override
public boolean hasNext()
Expand All @@ -85,23 +84,17 @@ public ImmutableBitmap next()
}
}
nextSet = false;
final int idx = dictionary.indexOf(next);
if (idx < 0) {
return bitmapFactory.makeEmptyImmutableBitmap();
}

final ImmutableBitmap bitmap = bitmaps.get(idx);
final ImmutableBitmap bitmap = bitmaps.get(index);
return bitmap == null ? bitmapFactory.makeEmptyImmutableBitmap() : bitmap;
}

private void findNext()
{
while (!nextSet && iterator.hasNext()) {
String nextValue = iterator.next();
final String nextValue = iterator.next();
index++;
nextSet = stringPredicate.apply(nextValue).matches(includeUnknown);
if (nextSet) {
next = nextValue;
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,7 @@ public Iterable<ImmutableBitmap> getBitmapIterable(boolean includeUnknown)

// in the future, this could use an int iterator
final Iterator<Integer> iterator = localDictionary.iterator();
int next;
int index = 0;
int index = -1;
boolean nextSet = false;

@Override
Expand All @@ -635,19 +634,16 @@ public ImmutableBitmap next()
}
}
nextSet = false;
return getBitmap(next);
return getBitmap(index);
}

private void findNext()
{
while (!nextSet && iterator.hasNext()) {
Integer nextValue = iterator.next();
index++;
nextSet = stringPredicate.apply(StringUtils.fromUtf8Nullable(stringDictionary.get(nextValue)))
.matches(includeUnknown);
if (nextSet) {
next = index;
}
index++;
}
}
};
Expand Down Expand Up @@ -892,8 +888,7 @@ public Iterable<ImmutableBitmap> getBitmapIterable(boolean includeUnknown)

// in the future, this could use an int iterator
final Iterator<Integer> iterator = localDictionary.iterator();
int next;
int index = 0;
int index = -1;
boolean nextSet = false;

@Override
Expand All @@ -916,22 +911,19 @@ public ImmutableBitmap next()
}
nextSet = false;

return getBitmap(next);
return getBitmap(index);
}

private void findNext()
{
while (!nextSet && iterator.hasNext()) {
Integer nextValue = iterator.next();
final Integer nextValue = iterator.next();
index++;
if (nextValue == 0) {
nextSet = longPredicate.applyNull().matches(includeUnknown);
} else {
nextSet = longPredicate.applyLong(longDictionary.get(nextValue - adjustLongId)).matches(includeUnknown);
}
if (nextSet) {
next = index;
}
index++;
}
}
};
Expand Down Expand Up @@ -1158,8 +1150,7 @@ public Iterable<ImmutableBitmap> getBitmapIterable(boolean includeUnknown)

// in the future, this could use an int iterator
final Iterator<Integer> iterator = localDictionary.iterator();
int next;
int index = 0;
int index = -1;
boolean nextSet = false;

@Override
Expand All @@ -1181,23 +1172,20 @@ public ImmutableBitmap next()
}
}
nextSet = false;
return getBitmap(next);
return getBitmap(index);
}

private void findNext()
{
while (!nextSet && iterator.hasNext()) {
Integer nextValue = iterator.next();
final Integer nextValue = iterator.next();
index++;
if (nextValue == 0) {
nextSet = doublePredicate.applyNull().matches(includeUnknown);
} else {
nextSet = doublePredicate.applyDouble(doubleDictionary.get(nextValue - adjustDoubleId))
.matches(includeUnknown);
}
if (nextSet) {
next = index;
}
index++;
}
}
};
Expand Down Expand Up @@ -1384,8 +1372,7 @@ public Iterable<ImmutableBitmap> getBitmapIterable(boolean includeUnknown)

// in the future, this could use an int iterator
final Iterator<Integer> iterator = localDictionary.iterator();
int next;
int index;
int index = -1;
boolean nextSet = false;

@Override
Expand All @@ -1407,13 +1394,14 @@ public ImmutableBitmap next()
}
}
nextSet = false;
return getBitmap(next);
return getBitmap(index);
}

private void findNext()
{
while (!nextSet && iterator.hasNext()) {
Integer nextValue = iterator.next();
final Integer nextValue = iterator.next();
index++;
if (nextValue >= adjustArrayId) {
// this shouldn't be possible since arrayIds will only exist if array dictionary is not null
// v4 columns however have a null array dictionary
Expand Down Expand Up @@ -1442,10 +1430,6 @@ private void findNext()
nextSet = stringPredicate.apply(StringUtils.fromUtf8Nullable(stringDictionary.get(nextValue)))
.matches(includeUnknown);
}
if (nextSet) {
next = index;
}
index++;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,7 @@ public Iterable<ImmutableBitmap> getBitmapIterable(boolean includeUnknown)
final Iterator<Double> iterator = doubleDictionarySupplier.get().iterator();
final DruidDoublePredicate doublePredicate = matcherFactory.makeDoublePredicate();

int next;
int index = 0;
int index = -1;
boolean nextSet = false;

@Override
Expand All @@ -567,13 +566,14 @@ public ImmutableBitmap next()
}
}
nextSet = false;
return getBitmap(next);
return getBitmap(index);
}

private void findNext()
{
while (!nextSet && iterator.hasNext()) {
Double nextValue = iterator.next();
index++;
if (nextValue == null) {
if (NullHandling.sqlCompatible()) {
nextSet = doublePredicate.applyNull().matches(includeUnknown);
Expand All @@ -583,10 +583,6 @@ private void findNext()
} else {
nextSet = doublePredicate.applyDouble(nextValue).matches(includeUnknown);
}
if (nextSet) {
next = index;
}
index++;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ public Iterable<ImmutableBitmap> getBitmapIterable(boolean includeUnknown)
final Iterator<Long> iterator = dictionary.iterator();
final DruidLongPredicate longPredicate = matcherFactory.makeLongPredicate();

int next;
int index = 0;
int index = -1;
boolean nextSet = false;

@Override
Expand All @@ -578,13 +577,14 @@ public ImmutableBitmap next()
}
nextSet = false;

return getBitmap(next);
return getBitmap(index);
}

private void findNext()
{
while (!nextSet && iterator.hasNext()) {
Long nextValue = iterator.next();
index++;
if (nextValue == null) {
if (NullHandling.sqlCompatible()) {
nextSet = longPredicate.applyNull().matches(includeUnknown);
Expand All @@ -594,10 +594,6 @@ private void findNext()
} else {
nextSet = longPredicate.applyLong(nextValue).matches(includeUnknown);
}
if (nextSet) {
next = index;
}
index++;
}
}
};
Expand Down

0 comments on commit 6cd8c6b

Please sign in to comment.