Search in sources :

Example 1 with BigintRange

use of com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange in project presto by prestodb.

the class OrcSelectiveRecordReader method scoreFilter.

private static int scoreFilter(Map<Subfield, TupleDomainFilter> filters) {
    checkArgument(!filters.isEmpty());
    if (filters.size() > 1) {
        // Complex type column. Complex types are expensive!
        return 1000;
    }
    Map.Entry<Subfield, TupleDomainFilter> filterEntry = Iterables.getOnlyElement(filters.entrySet());
    if (!filterEntry.getKey().getPath().isEmpty()) {
        // Complex type column. Complex types are expensive!
        return 1000;
    }
    TupleDomainFilter filter = filterEntry.getValue();
    if (filter instanceof BigintRange) {
        if (((BigintRange) filter).isSingleValue()) {
            // Integer equality. Generally cheap.
            return 10;
        }
        return 50;
    }
    if (filter instanceof BigintValuesUsingHashTable || filter instanceof BigintValuesUsingBitmask || filter instanceof BigintMultiRange) {
        return 50;
    }
    return 100;
}
Also used : BigintValuesUsingHashTable(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) BigintMultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange) BigintValuesUsingBitmask(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingBitmask) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) HashMap(java.util.HashMap) Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Example 2 with BigintRange

use of com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange in project presto by prestodb.

the class TupleDomainFilterUtils method toFilter.

public static TupleDomainFilter toFilter(Domain domain) {
    ValueSet values = domain.getValues();
    boolean nullAllowed = domain.isNullAllowed();
    if (values.isAll()) {
        checkArgument(!nullAllowed, "Unexpected allways-true filter");
        return IS_NOT_NULL;
    }
    if (values.isNone()) {
        checkArgument(nullAllowed, "Unexpected allways-false filter");
        return IS_NULL;
    }
    checkArgument(values instanceof SortedRangeSet, "Unexpected domain type: " + values.getClass().getSimpleName());
    List<Range> ranges = ((SortedRangeSet) values).getOrderedRanges();
    if (ranges.isEmpty() && nullAllowed) {
        return IS_NULL;
    }
    Type type = domain.getType();
    if (ranges.size() == 1) {
        return createRangeFilter(type, ranges.get(0), nullAllowed);
    }
    if (type == BOOLEAN) {
        return createBooleanFilter(ranges, nullAllowed);
    }
    List<TupleDomainFilter> rangeFilters = ranges.stream().map(range -> createRangeFilter(type, range, false)).filter(rangeFilter -> !rangeFilter.equals(ALWAYS_FALSE)).collect(toList());
    if (rangeFilters.isEmpty()) {
        return nullAllowed ? IS_NULL : ALWAYS_FALSE;
    }
    TupleDomainFilter firstRangeFilter = rangeFilters.get(0);
    if (firstRangeFilter instanceof BigintRange) {
        List<BigintRange> bigintRanges = rangeFilters.stream().map(BigintRange.class::cast).collect(toList());
        if (bigintRanges.stream().allMatch(BigintRange::isSingleValue)) {
            return toBigintValues(bigintRanges.stream().mapToLong(BigintRange::getLower).toArray(), nullAllowed);
        }
        return BigintMultiRange.of(bigintRanges, nullAllowed);
    }
    if (firstRangeFilter instanceof BytesRange) {
        List<BytesRange> bytesRanges = rangeFilters.stream().map(BytesRange.class::cast).collect(toList());
        if (bytesRanges.stream().allMatch(BytesRange::isSingleValue)) {
            return BytesValues.of(bytesRanges.stream().map(BytesRange::getLower).toArray(byte[][]::new), nullAllowed);
        }
        if (isNotIn(ranges)) {
            return BytesValuesExclusive.of(bytesRanges.stream().map(BytesRange::getLower).filter(Objects::nonNull).toArray(byte[][]::new), nullAllowed);
        }
    }
    if (firstRangeFilter instanceof DoubleRange || firstRangeFilter instanceof FloatRange) {
        // != and NOT IN filters should return true when applied to NaN
        // E.g. NaN != 1.0 as well as NaN NOT IN (1.0, 2.5, 3.6) should return true; otherwise false.
        boolean nanAllowed = isNotIn(ranges);
        return MultiRange.of(rangeFilters, nullAllowed, nanAllowed);
    }
    return MultiRange.of(rangeFilters, nullAllowed, false);
}
Also used : DecimalType(com.facebook.presto.common.type.DecimalType) Slice(io.airlift.slice.Slice) LongDecimalRange(com.facebook.presto.common.predicate.TupleDomainFilter.LongDecimalRange) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) Float.intBitsToFloat(java.lang.Float.intBitsToFloat) DATE(com.facebook.presto.common.type.DateType.DATE) REAL(com.facebook.presto.common.type.RealType.REAL) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) CharType(com.facebook.presto.common.type.CharType) BigInteger(java.math.BigInteger) Math.toIntExact(java.lang.Math.toIntExact) Type(com.facebook.presto.common.type.Type) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) BigintValuesUsingHashTable(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) BigintMultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange) ALWAYS_FALSE(com.facebook.presto.common.predicate.TupleDomainFilter.ALWAYS_FALSE) BooleanValue(com.facebook.presto.common.predicate.TupleDomainFilter.BooleanValue) BigintValuesUsingBitmask(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingBitmask) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) IS_NOT_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) SIZE_OF_LONG(io.airlift.slice.SizeOf.SIZE_OF_LONG) MultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.MultiRange) IS_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL) BytesValues(com.facebook.presto.common.predicate.TupleDomainFilter.BytesValues) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) BytesValuesExclusive(com.facebook.presto.common.predicate.TupleDomainFilter.BytesValuesExclusive) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) LongDecimalRange(com.facebook.presto.common.predicate.TupleDomainFilter.LongDecimalRange) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) BigintMultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange) MultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.MultiRange) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) DecimalType(com.facebook.presto.common.type.DecimalType) Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) Objects(java.util.Objects)

Example 3 with BigintRange

use of com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange in project presto by prestodb.

the class TestSelectiveOrcReader method testArrays.

@Test
public void testArrays() throws Exception {
    Random random = new Random(0);
    // non-null arrays of varying sizes; some arrays may be empty
    tester.testRoundTrip(arrayType(INTEGER), createList(NUM_ROWS, i -> randomIntegers(random.nextInt(10), random)), IS_NULL, IS_NOT_NULL);
    BigintRange negative = BigintRange.of(Integer.MIN_VALUE, 0, false);
    BigintRange nonNegative = BigintRange.of(0, Integer.MAX_VALUE, false);
    // arrays of strings
    tester.testRoundTrip(arrayType(VARCHAR), createList(1000, i -> randomStrings(5 + random.nextInt(5), random)), ImmutableList.of(toSubfieldFilter("c[1]", IS_NULL), toSubfieldFilter("c[1]", stringIn(true, "a", "b", "c", "d"))));
    tester.testRoundTrip(arrayType(VARCHAR), createList(10, i -> randomStringsWithNulls(5 + random.nextInt(5), random)), ImmutableList.of(toSubfieldFilter("c[1]", IS_NULL), toSubfieldFilter("c[1]", stringIn(true, "a", "b", "c", "d"))));
    // non-empty non-null arrays of varying sizes
    tester.testRoundTrip(arrayType(INTEGER), createList(NUM_ROWS, i -> randomIntegers(5 + random.nextInt(5), random)), ImmutableList.of(toSubfieldFilter(IS_NULL), toSubfieldFilter(IS_NOT_NULL), // c[1] >= 0
    toSubfieldFilter("c[1]", nonNegative), // c[2] >= 0 AND c[4] >= 0
    ImmutableMap.of(new Subfield("c[2]"), nonNegative, new Subfield("c[4]"), nonNegative)));
    // non-null arrays of varying sizes; some arrays may be empty
    tester.testRoundTripTypes(ImmutableList.of(INTEGER, arrayType(INTEGER)), ImmutableList.of(randomIntegers(NUM_ROWS, random), createList(NUM_ROWS, i -> randomIntegers(random.nextInt(10), random))), toSubfieldFilters(ImmutableMap.of(0, nonNegative), ImmutableMap.of(0, nonNegative, 1, IS_NULL), ImmutableMap.of(0, nonNegative, 1, IS_NOT_NULL)));
    // non-empty non-null arrays of varying sizes
    tester.testRoundTripTypes(ImmutableList.of(INTEGER, arrayType(INTEGER)), ImmutableList.of(randomIntegers(NUM_ROWS, random), createList(NUM_ROWS, i -> randomIntegers(5 + random.nextInt(5), random))), ImmutableList.of(// c[1] >= 0
    ImmutableMap.of(0, toSubfieldFilter(nonNegative), 1, toSubfieldFilter("c[1]", nonNegative)), // c[3] >= 0
    ImmutableMap.of(0, toSubfieldFilter(nonNegative), 1, toSubfieldFilter("c[3]", nonNegative)), // c[2] >= 0 AND c[4] <= 0
    ImmutableMap.of(0, toSubfieldFilter(nonNegative), 1, ImmutableMap.of(new Subfield("c[2]"), nonNegative, new Subfield("c[4]"), negative))));
    // nested arrays
    tester.testRoundTripTypes(ImmutableList.of(INTEGER, arrayType(arrayType(INTEGER))), ImmutableList.of(randomIntegers(NUM_ROWS, random), createList(NUM_ROWS, i -> createList(random.nextInt(10), index -> randomIntegers(random.nextInt(5), random)))), toSubfieldFilters(ImmutableMap.of(0, nonNegative), ImmutableMap.of(1, IS_NULL), ImmutableMap.of(1, IS_NOT_NULL), ImmutableMap.of(0, nonNegative, 1, IS_NULL)));
    tester.testRoundTripTypes(ImmutableList.of(INTEGER, arrayType(arrayType(INTEGER))), ImmutableList.of(randomIntegers(NUM_ROWS, random), createList(NUM_ROWS, i -> createList(3 + random.nextInt(10), index -> randomIntegers(3 + random.nextInt(5), random)))), ImmutableList.of(// c[1] IS NULL
    ImmutableMap.of(1, ImmutableMap.of(new Subfield("c[1]"), IS_NULL)), // c[2] IS NOT NULL AND c[2][3] >= 0
    ImmutableMap.of(1, ImmutableMap.of(new Subfield("c[2]"), IS_NOT_NULL, new Subfield("c[2][3]"), nonNegative)), ImmutableMap.of(0, toSubfieldFilter(nonNegative), 1, ImmutableMap.of(new Subfield("c[1]"), IS_NULL))));
}
Also used : CharType.createCharType(com.facebook.presto.common.type.CharType.createCharType) Page(com.facebook.presto.common.Page) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) OrcTester.createCustomOrcSelectiveRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) Test(org.testng.annotations.Test) Random(java.util.Random) OrcTester.quickSelectiveOrcTester(com.facebook.presto.orc.OrcTester.quickSelectiveOrcTester) SESSION(com.facebook.presto.testing.TestingConnectorSession.SESSION) Iterables.concat(com.google.common.collect.Iterables.concat) Iterables.cycle(com.google.common.collect.Iterables.cycle) Slices(io.airlift.slice.Slices) Map(java.util.Map) HIVE_STORAGE_TIME_ZONE(com.facebook.presto.orc.OrcTester.HIVE_STORAGE_TIME_ZONE) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) BigInteger(java.math.BigInteger) SqlDecimal(com.facebook.presto.common.type.SqlDecimal) BigintValuesUsingHashTable(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) NONE(com.facebook.presto.orc.metadata.CompressionKind.NONE) Collections.nCopies(java.util.Collections.nCopies) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Range(com.google.common.collect.Range) BooleanValue(com.facebook.presto.common.predicate.TupleDomainFilter.BooleanValue) Iterables.limit(com.google.common.collect.Iterables.limit) Assert.assertNotNull(org.testng.Assert.assertNotNull) Streams(com.google.common.collect.Streams) Assertions.assertBetweenInclusive(com.facebook.airlift.testing.Assertions.assertBetweenInclusive) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SqlTimestamp(com.facebook.presto.common.type.SqlTimestamp) IS_NOT_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) CompressionKind(com.facebook.presto.orc.metadata.CompressionKind) Optional(java.util.Optional) IS_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL) IntStream(java.util.stream.IntStream) MAX_BLOCK_SIZE(com.facebook.presto.orc.OrcTester.MAX_BLOCK_SIZE) DecimalType(com.facebook.presto.common.type.DecimalType) ContiguousSet(com.google.common.collect.ContiguousSet) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) DateTimeTestingUtils.sqlTimestampOf(com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf) Assert.assertEquals(org.testng.Assert.assertEquals) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) Function(java.util.function.Function) DATE(com.facebook.presto.common.type.DateType.DATE) REAL(com.facebook.presto.common.type.RealType.REAL) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ZLIB(com.facebook.presto.orc.metadata.CompressionKind.ZLIB) SqlDate(com.facebook.presto.common.type.SqlDate) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) DiscreteDomain(com.google.common.collect.DiscreteDomain) OrcTester.writeOrcColumnsPresto(com.facebook.presto.orc.OrcTester.writeOrcColumnsPresto) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) MAX_BATCH_SIZE(com.facebook.presto.orc.OrcReader.MAX_BATCH_SIZE) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) InvalidFunctionArgumentException(com.facebook.presto.common.InvalidFunctionArgumentException) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.fail(org.testng.Assert.fail) AbstractIterator(com.google.common.collect.AbstractIterator) TupleDomainFilterUtils.toBigintValues(com.facebook.presto.common.predicate.TupleDomainFilterUtils.toBigintValues) VARBINARY(com.facebook.presto.common.type.VarbinaryType.VARBINARY) Maps(com.google.common.collect.Maps) Ints(com.google.common.primitives.Ints) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) DWRF(com.facebook.presto.orc.OrcTester.Format.DWRF) OrcReaderSettings(com.facebook.presto.orc.OrcTester.OrcReaderSettings) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) OrcTester.rowType(com.facebook.presto.orc.OrcTester.rowType) TestingOrcPredicate.createOrcPredicate(com.facebook.presto.orc.TestingOrcPredicate.createOrcPredicate) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) BytesValues(com.facebook.presto.common.predicate.TupleDomainFilter.BytesValues) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) Collections(java.util.Collections) ZSTD(com.facebook.presto.orc.metadata.CompressionKind.ZSTD) Random(java.util.Random) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) Subfield(com.facebook.presto.common.Subfield) Test(org.testng.annotations.Test)

Aggregations

BigintRange (com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange)3 BigintValuesUsingHashTable (com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable)3 Subfield (com.facebook.presto.common.Subfield)2 TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)2 BigintMultiRange (com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange)2 BigintValuesUsingBitmask (com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingBitmask)2 BooleanValue (com.facebook.presto.common.predicate.TupleDomainFilter.BooleanValue)2 BytesRange (com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange)2 BytesValues (com.facebook.presto.common.predicate.TupleDomainFilter.BytesValues)2 DoubleRange (com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange)2 FloatRange (com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange)2 IS_NOT_NULL (com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL)2 IS_NULL (com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL)2 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)2 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)2 CharType (com.facebook.presto.common.type.CharType)2 DATE (com.facebook.presto.common.type.DateType.DATE)2 DecimalType (com.facebook.presto.common.type.DecimalType)2 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)2 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)2