public boolean overlaps(Domain other) { checkCompatibility(other); return !this.intersect(other).isNone(); }
/** * Returns the strict intersection of the TupleDomains. * The resulting TupleDomain represents the set of tuples that would be valid * in both TupleDomains. */ public TupleDomain<T> intersect(TupleDomain<T> other) { if (this.isNone() || other.isNone()) { return none(); } Map<T, Domain> intersected = new HashMap<>(this.getDomains().get()); for (Map.Entry<T, Domain> entry : other.getDomains().get().entrySet()) { Domain intersectionDomain = intersected.get(entry.getKey()); if (intersectionDomain == null) { intersected.put(entry.getKey(), entry.getValue()); } else { intersected.put(entry.getKey(), intersectionDomain.intersect(entry.getValue())); } } return withColumnDomains(intersected); }
@Override public boolean matches(Map<ColumnDescriptor, DictionaryDescriptor> dictionaries) { if (effectivePredicate.isNone()) { return false; } Map<ColumnDescriptor, Domain> effectivePredicateDomains = effectivePredicate.getDomains() .orElseThrow(() -> new IllegalStateException("Effective predicate other than none should have domains")); for (RichColumnDescriptor column : columns) { Domain effectivePredicateDomain = effectivePredicateDomains.get(column); if (effectivePredicateDomain == null) { continue; } DictionaryDescriptor dictionaryDescriptor = dictionaries.get(column); Domain domain = getDomain(effectivePredicateDomain.getType(), dictionaryDescriptor); if (effectivePredicateDomain.intersect(domain).isNone()) { return false; } } return true; }
@Override public boolean matches(long numberOfRows, Map<ColumnDescriptor, Statistics<?>> statistics, ParquetDataSourceId id, boolean failOnCorruptedParquetStatistics) throws ParquetCorruptionException { if (numberOfRows == 0) { return false; } if (effectivePredicate.isNone()) { return false; } Map<ColumnDescriptor, Domain> effectivePredicateDomains = effectivePredicate.getDomains() .orElseThrow(() -> new IllegalStateException("Effective predicate other than none should have domains")); for (RichColumnDescriptor column : columns) { Domain effectivePredicateDomain = effectivePredicateDomains.get(column); if (effectivePredicateDomain == null) { continue; } Statistics<?> columnStatistics = statistics.get(column); if (columnStatistics == null || columnStatistics.isEmpty()) { // no stats for column } else { Domain domain = getDomain(effectivePredicateDomain.getType(), numberOfRows, columnStatistics, id, column.toString(), failOnCorruptedParquetStatistics); if (effectivePredicateDomain.intersect(domain).isNone()) { return false; } } } return true; }
@Test public void testIntersect() { assertEquals( Domain.all(BIGINT).intersect(Domain.all(BIGINT)), Domain.all(BIGINT)); assertEquals( Domain.none(BIGINT).intersect(Domain.none(BIGINT)), Domain.none(BIGINT)); assertEquals( Domain.all(BIGINT).intersect(Domain.none(BIGINT)), Domain.none(BIGINT)); assertEquals( Domain.notNull(BIGINT).intersect(Domain.onlyNull(BIGINT)), Domain.none(BIGINT)); assertEquals( Domain.singleValue(BIGINT, 0L).intersect(Domain.all(BIGINT)), Domain.singleValue(BIGINT, 0L)); assertEquals( Domain.singleValue(BIGINT, 0L).intersect(Domain.onlyNull(BIGINT)), Domain.none(BIGINT)); assertEquals( Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L)), true).intersect(Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 2L)), true)), Domain.onlyNull(BIGINT)); assertEquals( Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L)), true).intersect(Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L)), false)), Domain.singleValue(BIGINT, 1L)); }
@Test public void testIntersect() { assertEquals( Domain.all(BIGINT).intersect(Domain.all(BIGINT)), Domain.all(BIGINT)); assertEquals( Domain.none(BIGINT).intersect(Domain.none(BIGINT)), Domain.none(BIGINT)); assertEquals( Domain.all(BIGINT).intersect(Domain.none(BIGINT)), Domain.none(BIGINT)); assertEquals( Domain.notNull(BIGINT).intersect(Domain.onlyNull(BIGINT)), Domain.none(BIGINT)); assertEquals( Domain.singleValue(BIGINT, 0L).intersect(Domain.all(BIGINT)), Domain.singleValue(BIGINT, 0L)); assertEquals( Domain.singleValue(BIGINT, 0L).intersect(Domain.onlyNull(BIGINT)), Domain.none(BIGINT)); assertEquals( Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L)), true).intersect(Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 2L)), true)), Domain.onlyNull(BIGINT)); assertEquals( Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L)), true).intersect(Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L)), false)), Domain.singleValue(BIGINT, 1L)); }