public static TupleDomain<ColumnHandle> computeEnforced(TupleDomain<ColumnHandle> predicate, TupleDomain<ColumnHandle> unenforced)
    {
        if (predicate.isNone()) {
            // If the engine requests that the connector provides a layout with a domain of "none". The connector can have two possible reactions, either:
            // 1. The connector can provide an empty table layout.
            //   * There would be no unenforced predicate, i.e., unenforced predicate is TupleDomain.all().
            //   * The predicate was successfully enforced. Enforced predicate would be same as predicate: TupleDomain.none().
            // 2. The connector can't/won't.
            //   * The connector would tell the engine to put a filter on top of the scan, i.e., unenforced predicate is TupleDomain.none().
            //   * The connector didn't successfully enforce anything. Therefore, enforced predicate would be TupleDomain.all().
            if (unenforced.isNone()) {
                return TupleDomain.all();
            }
            if (unenforced.isAll()) {
                return TupleDomain.none();
            }
            throw new IllegalArgumentException();
        }

        // The engine requested the connector provides a layout with a non-none TupleDomain.
        // A TupleDomain is effectively a list of column-Domain pairs.
        // The connector is expected enforce the respective domain entirely on none, some, or all of the columns.
        // 1. When the connector could enforce none of the domains, the unenforced would be equal to predicate;
        // 2. When the connector could enforce some of the domains, the unenforced would contain a subset of the column-Domain pairs;
        // 3. When the connector could enforce all of the domains, the unenforced would be TupleDomain.all().

        // In all 3 cases shown above, the unenforced is not TupleDomain.none().
        checkArgument(!unenforced.isNone());

        Map<ColumnHandle, Domain> predicateDomains = predicate.getDomains().get();
        Map<ColumnHandle, Domain> unenforcedDomains = unenforced.getDomains().get();
        ImmutableMap.Builder<ColumnHandle, Domain> enforcedDomainsBuilder = ImmutableMap.builder();
        for (Map.Entry<ColumnHandle, Domain> entry : predicateDomains.entrySet()) {
            ColumnHandle predicateColumnHandle = entry.getKey();
            if (unenforcedDomains.containsKey(predicateColumnHandle)) {
                checkArgument(
                        entry.getValue().equals(unenforcedDomains.get(predicateColumnHandle)),
                        "Enforced tuple domain cannot be determined. The connector is expected to enforce the respective domain entirely on none, some, or all of the column.");
            }
            else {
                enforcedDomainsBuilder.put(predicateColumnHandle, entry.getValue());
            }
        }
        Map<ColumnHandle, Domain> enforcedDomains = enforcedDomainsBuilder.build();
        checkArgument(
                enforcedDomains.size() + unenforcedDomains.size() == predicateDomains.size(),
                "Enforced tuple domain cannot be determined. Connector returned an unenforced TupleDomain that contains columns not in predicate.");
        return TupleDomain.withColumnDomains(enforcedDomains);
    }
@Test
    public void testComputeEnforced()
    {
        assertComputeEnforced(TupleDomain.all(), TupleDomain.all(), TupleDomain.all());
        assertComputeEnforcedFails(TupleDomain.all(), TupleDomain.none());
        assertComputeEnforced(TupleDomain.none(), TupleDomain.all(), TupleDomain.none());
        assertComputeEnforced(TupleDomain.none(), TupleDomain.none(), TupleDomain.all());

        assertComputeEnforced(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))),
                TupleDomain.all(),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))));
        assertComputeEnforced(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))),
                TupleDomain.all());
        assertComputeEnforcedFails(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))),
                TupleDomain.none());
        assertComputeEnforcedFails(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 9999L))));
        assertComputeEnforcedFails(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c9999"), Domain.singleValue(BIGINT, 1L))));

        assertComputeEnforced(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L),
                        new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))),
                TupleDomain.all(),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L),
                        new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))));
        assertComputeEnforced(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L),
                        new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))));
        assertComputeEnforced(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L),
                        new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))));
        assertComputeEnforced(
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L),
                        new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))),
                TupleDomain.withColumnDomains(ImmutableMap.of(
                        new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L),
                        new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))),
                TupleDomain.all());
    }