Skip to content

Commit

Permalink
Optimize TupleDomain#contains using Domain#contains
Browse files Browse the repository at this point in the history
  • Loading branch information
raunaqmorarka authored and findepi committed Oct 20, 2021
1 parent 2b8468c commit e149082
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,21 @@ public boolean overlaps(TupleDomain<T> other)
*/
public boolean contains(TupleDomain<T> other)
{
return other.isNone() || columnWiseUnion(this, other).equals(this);
if (other.isNone() || this == other) {
return true;
}
if (isNone()) {
return false;
}
Map<T, Domain> thisDomains = domains.orElseThrow();
Map<T, Domain> otherDomains = other.getDomains().orElseThrow();
for (Map.Entry<T, Domain> entry : thisDomains.entrySet()) {
Domain otherDomain = otherDomains.get(entry.getKey());
if (otherDomain == null || !entry.getValue().contains(otherDomain)) {
return false;
}
}
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,16 @@ private boolean contains(Map<ColumnHandle, Domain> superSet, Map<ColumnHandle, D
{
TupleDomain<ColumnHandle> superSetTupleDomain = TupleDomain.withColumnDomains(superSet);
TupleDomain<ColumnHandle> subSetTupleDomain = TupleDomain.withColumnDomains(subSet);
return superSetTupleDomain.contains(subSetTupleDomain);
boolean contains = superSetTupleDomain.contains(subSetTupleDomain);
// Results from computing contains using union and using the method directly should match
assertThat(contains).isEqualTo(containsFromUnion(superSetTupleDomain, subSetTupleDomain));
return contains;
}

private static boolean containsFromUnion(TupleDomain<ColumnHandle> superSetTupleDomain, TupleDomain<ColumnHandle> subSetTupleDomain)
{
return subSetTupleDomain.isNone()
|| columnWiseUnion(superSetTupleDomain, subSetTupleDomain).equals(superSetTupleDomain);
}

private boolean equals(Map<ColumnHandle, Domain> domains1, Map<ColumnHandle, Domain> domains2)
Expand Down

0 comments on commit e149082

Please sign in to comment.