in pinot-core/src/main/java/org/apache/pinot/core/operator/filter/predicate/PredicateUtils.java [78:192]
public static IntSet getDictIdSet(BaseInPredicate inPredicate, Dictionary dictionary, DataType dataType,
@Nullable QueryContext queryContext) {
List<String> values = inPredicate.getValues();
int hashSetSize = Integer.min(HashUtil.getMinHashSetSize(values.size()), MAX_INITIAL_DICT_ID_SET_SIZE);
IntSet dictIdSet = new IntOpenHashSet(hashSetSize);
switch (dataType) {
case INT:
int[] intValues = inPredicate.getIntValues();
for (int value : intValues) {
int dictId = dictionary.indexOf(value);
if (dictId >= 0) {
dictIdSet.add(dictId);
}
}
break;
case LONG:
long[] longValues = inPredicate.getLongValues();
for (long value : longValues) {
int dictId = dictionary.indexOf(value);
if (dictId >= 0) {
dictIdSet.add(dictId);
}
}
break;
case FLOAT:
float[] floatValues = inPredicate.getFloatValues();
for (float value : floatValues) {
int dictId = dictionary.indexOf(value);
if (dictId >= 0) {
dictIdSet.add(dictId);
}
}
break;
case DOUBLE:
double[] doubleValues = inPredicate.getDoubleValues();
for (double value : doubleValues) {
int dictId = dictionary.indexOf(value);
if (dictId >= 0) {
dictIdSet.add(dictId);
}
}
break;
case BIG_DECIMAL:
BigDecimal[] bigDecimalValues = inPredicate.getBigDecimalValues();
for (BigDecimal value : bigDecimalValues) {
int dictId = dictionary.indexOf(value);
if (dictId >= 0) {
dictIdSet.add(dictId);
}
}
break;
case BOOLEAN:
int[] booleanValues = inPredicate.getBooleanValues();
for (int value : booleanValues) {
int dictId = dictionary.indexOf(value);
if (dictId >= 0) {
dictIdSet.add(dictId);
}
}
break;
case TIMESTAMP:
long[] timestampValues = inPredicate.getTimestampValues();
for (long value : timestampValues) {
int dictId = dictionary.indexOf(value);
if (dictId >= 0) {
dictIdSet.add(dictId);
}
}
break;
case STRING:
if (queryContext == null || values.size() <= 1) {
dictionary.getDictIds(values, dictIdSet);
break;
}
Dictionary.SortedBatchLookupAlgorithm lookupAlgorithm =
Dictionary.SortedBatchLookupAlgorithm.DIVIDE_BINARY_SEARCH;
String inPredicateLookupAlgorithm =
queryContext.getQueryOptions().get(QueryOptionKey.IN_PREDICATE_LOOKUP_ALGORITHM);
if (inPredicateLookupAlgorithm != null) {
try {
lookupAlgorithm = Dictionary.SortedBatchLookupAlgorithm.valueOf(inPredicateLookupAlgorithm.toUpperCase());
} catch (Exception e) {
throw new IllegalArgumentException("Illegal IN predicate lookup algorithm: " + inPredicateLookupAlgorithm);
}
}
if (lookupAlgorithm == Dictionary.SortedBatchLookupAlgorithm.PLAIN_BINARY_SEARCH) {
dictionary.getDictIds(values, dictIdSet);
break;
}
if (Boolean.parseBoolean(queryContext.getQueryOptions().get(QueryOptionKey.IN_PREDICATE_PRE_SORTED))) {
dictionary.getDictIds(values, dictIdSet, lookupAlgorithm);
} else {
//noinspection unchecked
dictionary.getDictIds(
queryContext.getOrComputeSharedValue(List.class, Equivalence.identity().wrap(inPredicate), k -> {
List<String> sortedValues = new ArrayList<>(values);
sortedValues.sort(null);
return sortedValues;
}), dictIdSet, lookupAlgorithm);
}
break;
case BYTES:
ByteArray[] bytesValues = inPredicate.getBytesValues();
for (ByteArray value : bytesValues) {
int dictId = dictionary.indexOf(value);
if (dictId >= 0) {
dictIdSet.add(dictId);
}
}
break;
default:
throw new IllegalStateException("Unsupported data type: " + dataType);
}
return dictIdSet;
}