Search in sources :

Example 51 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class ListSelectiveStreamReader method getTopLevelFilter.

private static Optional<TupleDomainFilter> getTopLevelFilter(Map<Subfield, TupleDomainFilter> filters) {
    Map<Subfield, TupleDomainFilter> topLevelFilters = Maps.filterEntries(filters, entry -> entry.getKey().getPath().isEmpty());
    if (topLevelFilters.isEmpty()) {
        return Optional.empty();
    }
    checkArgument(topLevelFilters.size() == 1, "ARRAY column may have at most one top-level range filter");
    TupleDomainFilter filter = Iterables.getOnlyElement(topLevelFilters.values());
    checkArgument(filter == IS_NULL || filter == IS_NOT_NULL, "Top-level range filter on ARRAY column must be IS NULL or IS NOT NULL");
    return Optional.of(filter);
}
Also used : Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Example 52 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class MapDirectSelectiveStreamReader method getTopLevelFilter.

private static Optional<TupleDomainFilter> getTopLevelFilter(Map<Subfield, TupleDomainFilter> filters) {
    Map<Subfield, TupleDomainFilter> topLevelFilters = Maps.filterEntries(filters, entry -> entry.getKey().getPath().isEmpty());
    if (topLevelFilters.isEmpty()) {
        return Optional.empty();
    }
    checkArgument(topLevelFilters.size() == 1, "MAP column may have at most one top-level range filter");
    TupleDomainFilter filter = Iterables.getOnlyElement(topLevelFilters.values());
    checkArgument(filter == IS_NULL || filter == IS_NOT_NULL, "Top-level range filter on MAP column must be IS NULL or IS NOT NULL");
    return Optional.of(filter);
}
Also used : Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Example 53 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class MapFlatSelectiveStreamReader method getTopLevelFilter.

private static Optional<TupleDomainFilter> getTopLevelFilter(Map<Subfield, TupleDomainFilter> filters) {
    Map<Subfield, TupleDomainFilter> topLevelFilters = Maps.filterEntries(filters, entry -> entry.getKey().getPath().isEmpty());
    if (topLevelFilters.isEmpty()) {
        return Optional.empty();
    }
    checkArgument(topLevelFilters.size() == 1, "MAP column may have at most one top-level range filter");
    TupleDomainFilter filter = Iterables.getOnlyElement(topLevelFilters.values());
    checkArgument(filter == IS_NULL || filter == IS_NOT_NULL, "Top-level range filter on MAP column must be IS NULL or IS NOT NULL");
    return Optional.of(filter);
}
Also used : Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Example 54 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class TestHiveLogicalPlanner method testPushdownFilterOnSubfields.

@Test
public void testPushdownFilterOnSubfields() {
    assertUpdate("CREATE TABLE test_pushdown_filter_on_subfields(" + "id bigint, " + "a array(bigint), " + "b map(varchar, bigint), " + "c row(" + "a bigint, " + "b row(x bigint), " + "c array(bigint), " + "d map(bigint, bigint), " + "e map(varchar, bigint)))");
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE a[1] = 1", ImmutableMap.of(new Subfield("a[1]"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields where a[1 + 1] = 1", ImmutableMap.of(new Subfield("a[2]"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT *  FROM test_pushdown_filter_on_subfields WHERE b['foo'] = 1", ImmutableMap.of(new Subfield("b[\"foo\"]"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE b[concat('f','o', 'o')] = 1", ImmutableMap.of(new Subfield("b[\"foo\"]"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE c.a = 1", ImmutableMap.of(new Subfield("c.a"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE c.b.x = 1", ImmutableMap.of(new Subfield("c.b.x"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE c.c[5] = 1", ImmutableMap.of(new Subfield("c.c[5]"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE c.d[5] = 1", ImmutableMap.of(new Subfield("c.d[5]"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE c.e[concat('f', 'o', 'o')] = 1", ImmutableMap.of(new Subfield("c.e[\"foo\"]"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE c.e['foo'] = 1", ImmutableMap.of(new Subfield("c.e[\"foo\"]"), singleValue(BIGINT, 1L)));
    assertPushdownFilterOnSubfields("SELECT * FROM test_pushdown_filter_on_subfields WHERE c.a IS NOT NULL AND c.c IS NOT NULL", ImmutableMap.of(new Subfield("c.a"), notNull(BIGINT), new Subfield("c.c"), notNull(new ArrayType(BIGINT))));
    // TupleDomain predicate is always FALSE
    assertPlan(pushdownFilterEnabled(), "SELECT id FROM test_pushdown_filter_on_subfields WHERE c.a = 1 AND c.a = 2", output(values("id")));
    assertUpdate("DROP TABLE test_pushdown_filter_on_subfields");
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) ParquetTypeUtils.pushdownColumnNameForSubfield(com.facebook.presto.parquet.ParquetTypeUtils.pushdownColumnNameForSubfield) HiveColumnHandle.isPushedDownSubfield(com.facebook.presto.hive.HiveColumnHandle.isPushedDownSubfield) Subfield(com.facebook.presto.common.Subfield) Test(org.testng.annotations.Test)

Aggregations

Subfield (com.facebook.presto.common.Subfield)54 ImmutableMap (com.google.common.collect.ImmutableMap)27 Map (java.util.Map)27 ImmutableList (com.google.common.collect.ImmutableList)25 List (java.util.List)24 TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)22 Type (com.facebook.presto.common.type.Type)21 ArrayList (java.util.ArrayList)21 Optional (java.util.Optional)20 Test (org.testng.annotations.Test)19 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)18 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)18 Collectors.toList (java.util.stream.Collectors.toList)12 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)11 ColumnHandle (com.facebook.presto.spi.ColumnHandle)11 String.format (java.lang.String.format)11 Set (java.util.Set)11 Domain (com.facebook.presto.common.predicate.Domain)10 CharType (com.facebook.presto.common.type.CharType)10 DecimalType (com.facebook.presto.common.type.DecimalType)10