use of io.prestosql.spi.predicate.ValueSet in project hetu-core by openlookeng.
the class TestBloomIndex method testDomainMatching.
@Test
public void testDomainMatching() throws IOException {
try (TempFolder folder = new TempFolder();
BloomIndex stringBloomIndex = new BloomIndex()) {
folder.create();
File testFile = folder.newFile();
List<Object> testValues = ImmutableList.of("a", "ab", "测试", "\n", "%#!", ":dfs");
stringBloomIndex.setExpectedNumOfEntries(testValues.size());
stringBloomIndex.addValues(Collections.singletonList(new Pair<>("testColumn", testValues)));
try (FileOutputStream fo = new FileOutputStream(testFile)) {
stringBloomIndex.serialize(fo);
}
try (FileInputStream fi = new FileInputStream(testFile)) {
stringBloomIndex.deserialize(fi);
}
ValueSet valueSet = mock(ValueSet.class);
when(valueSet.isSingleValue()).thenReturn(true);
when(valueSet.getType()).thenReturn(VARCHAR);
when(valueSet.getSingleValue()).thenReturn("a");
assertTrue(stringBloomIndex.matches(Domain.create(valueSet, false)));
when(valueSet.getSingleValue()).thenReturn("%#!");
assertTrue(stringBloomIndex.matches(Domain.create(valueSet, false)));
when(valueSet.getSingleValue()).thenReturn("bb");
assertFalse(stringBloomIndex.matches(Domain.create(valueSet, false)));
}
}
use of io.prestosql.spi.predicate.ValueSet in project hetu-core by openlookeng.
the class HivePartitionManager method toCompactTupleDomain.
private static TupleDomain<HiveColumnHandle> toCompactTupleDomain(TupleDomain<ColumnHandle> effectivePredicate, int threshold) {
ImmutableMap.Builder<HiveColumnHandle, Domain> builder = ImmutableMap.builder();
effectivePredicate.getDomains().ifPresent(domains -> {
for (Map.Entry<ColumnHandle, Domain> entry : domains.entrySet()) {
HiveColumnHandle hiveColumnHandle = (HiveColumnHandle) entry.getKey();
ValueSet values = entry.getValue().getValues();
ValueSet compactValueSet = values.getValuesProcessor().<Optional<ValueSet>>transform(ranges -> ranges.getRangeCount() > threshold ? Optional.of(ValueSet.ofRanges(ranges.getSpan())) : Optional.empty(), discreteValues -> discreteValues.getValues().size() > threshold ? Optional.of(ValueSet.all(values.getType())) : Optional.empty(), allOrNone -> Optional.empty()).orElse(values);
builder.put(hiveColumnHandle, Domain.create(compactValueSet, entry.getValue().isNullAllowed()));
}
});
return TupleDomain.withColumnDomains(builder.build());
}
use of io.prestosql.spi.predicate.ValueSet in project hetu-core by openlookeng.
the class HiveBucketing method getHiveBucketFilter.
public static Optional<HiveBucketFilter> getHiveBucketFilter(Table table, TupleDomain<ColumnHandle> effectivePredicate) {
if (!getHiveBucketHandle(table).isPresent()) {
return Optional.empty();
}
if (bucketedOnTimestamp(table.getStorage().getBucketProperty().get(), table)) {
return Optional.empty();
}
Optional<Map<ColumnHandle, NullableValue>> bindings = TupleDomain.extractFixedValues(effectivePredicate);
if (!bindings.isPresent()) {
return Optional.empty();
}
OptionalInt singleBucket = getHiveBucket(table, bindings.get());
if (singleBucket.isPresent()) {
return Optional.of(new HiveBucketFilter(ImmutableSet.of(singleBucket.getAsInt())));
}
if (!effectivePredicate.getDomains().isPresent()) {
return Optional.empty();
}
Optional<Domain> domain = effectivePredicate.getDomains().get().entrySet().stream().filter(entry -> ((HiveColumnHandle) entry.getKey()).getName().equals(BUCKET_COLUMN_NAME)).findFirst().map(Entry::getValue);
if (!domain.isPresent()) {
return Optional.empty();
}
ValueSet values = domain.get().getValues();
ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
int bucketCount = table.getStorage().getBucketProperty().get().getBucketCount();
for (int i = 0; i < bucketCount; i++) {
if (values.containsValue((long) i)) {
builder.add(i);
}
}
return Optional.of(new HiveBucketFilter(builder.build()));
}
use of io.prestosql.spi.predicate.ValueSet in project hetu-core by openlookeng.
the class TupleDomainFilterUtils method toFilter.
public static TupleDomainFilter toFilter(Domain domain) {
ValueSet values = domain.getValues();
checkArgument(values instanceof SortedRangeSet, "Unexpected domain type: " + values.getClass().getSimpleName());
List<Range> ranges = ((SortedRangeSet) values).getOrderedRanges();
boolean nullAllowed = domain.isNullAllowed();
if (ranges.isEmpty() && nullAllowed) {
return IS_NULL;
}
Type type = domain.getType();
if (ranges.size() == 1 && type != BOOLEAN) {
return createRangeFilter(type, ranges.get(0), nullAllowed);
}
if (type == BOOLEAN) {
return createBooleanFilter(ranges, nullAllowed);
}
List<TupleDomainFilter> rangeFilters = ranges.stream().map(range -> createRangeFilter(type, range, false)).filter(not(ALWAYS_FALSE::equals)).collect(toImmutableList());
if (rangeFilters.isEmpty()) {
return nullAllowed ? IS_NULL : ALWAYS_FALSE;
}
if (rangeFilters.get(0) instanceof TupleDomainFilter.BigintRange) {
List<TupleDomainFilter.BigintRange> bigintRanges = rangeFilters.stream().map(TupleDomainFilter.BigintRange.class::cast).collect(toImmutableList());
// will get converted to BigIntValues so that filter will be evaluated on multiple possible values.
if (bigintRanges.stream().allMatch(TupleDomainFilter.BigintRange::isSingleValue)) {
return TupleDomainFilter.BigintValues.of(bigintRanges.stream().mapToLong(TupleDomainFilter.BigintRange::getLower).toArray(), nullAllowed);
}
// in any of these ranges.
return TupleDomainFilter.BigintMultiRange.of(bigintRanges, nullAllowed);
}
return getMultiValuesTDF(rangeFilters, nullAllowed);
}
Aggregations