Java Code Examples for io.prestosql.spi.predicate.TupleDomain#getDomains()

The following examples show how to use io.prestosql.spi.predicate.TupleDomain#getDomains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalFileRecordCursor.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Optional<Domain> getDomain(OptionalInt timestampOrdinalPosition, TupleDomain<LocalFileColumnHandle> predicate)
{
    Optional<Map<LocalFileColumnHandle, Domain>> domains = predicate.getDomains();
    Domain domain = null;
    if (domains.isPresent() && timestampOrdinalPosition.isPresent()) {
        Map<LocalFileColumnHandle, Domain> domainMap = domains.get();
        Set<Domain> timestampDomain = domainMap.entrySet().stream()
                .filter(entry -> entry.getKey().getOrdinalPosition() == timestampOrdinalPosition.getAsInt())
                .map(Map.Entry::getValue)
                .collect(toSet());

        if (!timestampDomain.isEmpty()) {
            domain = Iterables.getOnlyElement(timestampDomain);
        }
    }
    return Optional.ofNullable(domain);
}
 
Example 2
Source File: Util.java    From presto with Apache License 2.0 5 votes vote down vote up
static boolean domainsMatch(TupleDomain<Predicate<ColumnHandle>> expected, TupleDomain<ColumnHandle> actual)
{
    Optional<Map<Predicate<ColumnHandle>, Domain>> expectedDomains = expected.getDomains();
    Optional<Map<ColumnHandle, Domain>> actualDomains = actual.getDomains();

    if (expectedDomains.isPresent() != actualDomains.isPresent()) {
        return false;
    }

    if (expectedDomains.isPresent()) {
        if (expectedDomains.get().size() != actualDomains.get().size()) {
            return false;
        }

        for (Map.Entry<Predicate<ColumnHandle>, Domain> entry : expectedDomains.get().entrySet()) {
            // There should be exactly one column matching the expected column matcher
            ColumnHandle actualColumn = Iterables.getOnlyElement(actualDomains.get().keySet().stream()
                    .filter(x -> entry.getKey().test(x))
                    .collect(toImmutableList()));

            if (!actualDomains.get().get(actualColumn).contains(entry.getValue())) {
                return false;
            }
        }
    }
    return true;
}
 
Example 3
Source File: Util.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * @param expectedDomains if empty, the actualConstraint's domains must also be empty.
 */
static boolean domainsMatch(
        Optional<Map<String, Domain>> expectedDomains,
        TupleDomain<ColumnHandle> actualConstraint,
        TableHandle tableHandle,
        Session session,
        Metadata metadata)
{
    Optional<Map<ColumnHandle, Domain>> actualDomains = actualConstraint.getDomains();

    if (expectedDomains.isPresent() != actualDomains.isPresent()) {
        return false;
    }

    if (expectedDomains.isEmpty()) {
        return true;
    }

    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
    for (Map.Entry<String, Domain> expectedColumnConstraint : expectedDomains.get().entrySet()) {
        if (!columnHandles.containsKey(expectedColumnConstraint.getKey())) {
            return false;
        }
        ColumnHandle columnHandle = columnHandles.get(expectedColumnConstraint.getKey());
        if (!actualDomains.get().containsKey(columnHandle)) {
            return false;
        }
        if (!expectedColumnConstraint.getValue().contains(actualDomains.get().get(columnHandle))) {
            return false;
        }
    }

    return true;
}
 
Example 4
Source File: LocalFileRecordCursor.java    From presto with Apache License 2.0 5 votes vote down vote up
private static boolean isThisServerIncluded(HostAddress address, TupleDomain<LocalFileColumnHandle> predicate, LocalFileTableHandle table)
{
    if (table.getServerAddressColumn().isEmpty()) {
        return true;
    }

    Optional<Map<LocalFileColumnHandle, Domain>> domains = predicate.getDomains();
    if (domains.isEmpty()) {
        return true;
    }

    Set<Domain> serverAddressDomain = domains.get().entrySet().stream()
            .filter(entry -> entry.getKey().getOrdinalPosition() == table.getServerAddressColumn().getAsInt())
            .map(Map.Entry::getValue)
            .collect(toSet());

    if (serverAddressDomain.isEmpty()) {
        return true;
    }

    for (Domain domain : serverAddressDomain) {
        if (domain.includesNullableValue(Slices.utf8Slice(address.toString()))) {
            return true;
        }
    }
    return false;
}