Search in sources :

Example 81 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestDomainTranslator method testToPredicateAllIgnored.

@Test
public void testToPredicateAllIgnored() {
    TupleDomain<Symbol> tupleDomain = tupleDomain(ImmutableMap.<Symbol, Domain>builder().put(C_BIGINT, Domain.singleValue(BIGINT, 1L)).put(C_DOUBLE, Domain.onlyNull(DOUBLE)).put(C_VARCHAR, Domain.notNull(VARCHAR)).put(C_BOOLEAN, Domain.all(BOOLEAN)).buildOrThrow());
    ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    assertEquals(result.getTupleDomain(), tupleDomain(ImmutableMap.<Symbol, Domain>builder().put(C_BIGINT, Domain.singleValue(BIGINT, 1L)).put(C_DOUBLE, Domain.onlyNull(DOUBLE)).put(C_VARCHAR, Domain.notNull(VARCHAR)).buildOrThrow()));
}
Also used : ExtractionResult(io.trino.sql.planner.DomainTranslator.ExtractionResult) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) Test(org.testng.annotations.Test)

Example 82 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestTupleDomainParquetPredicate method getEffectivePredicate.

private TupleDomain<ColumnDescriptor> getEffectivePredicate(RichColumnDescriptor column, VarcharType type, Slice value) {
    ColumnDescriptor predicateColumn = new ColumnDescriptor(column.getPath(), column.getPrimitiveType().getPrimitiveTypeName(), 0, 0);
    Domain predicateDomain = singleValue(type, value);
    Map<ColumnDescriptor, Domain> predicateColumns = singletonMap(predicateColumn, predicateDomain);
    return withColumnDomains(predicateColumns);
}
Also used : ColumnDescriptor(org.apache.parquet.column.ColumnDescriptor) TupleDomainParquetPredicate.getDomain(io.trino.parquet.predicate.TupleDomainParquetPredicate.getDomain) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain)

Example 83 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestDefaultJdbcQueryBuilder method testNormalBuildSql.

@Test
public void testNormalBuildSql() throws SQLException {
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.<ColumnHandle, Domain>builder().put(columns.get(0), Domain.create(SortedRangeSet.copyOf(BIGINT, ImmutableList.of(Range.equal(BIGINT, 128L), Range.equal(BIGINT, 180L), Range.equal(BIGINT, 233L), Range.lessThan(BIGINT, 25L), Range.range(BIGINT, 66L, true, 96L, true), Range.greaterThan(BIGINT, 192L))), false)).put(columns.get(1), Domain.create(SortedRangeSet.copyOf(DOUBLE, ImmutableList.of(Range.equal(DOUBLE, 200011.0), Range.equal(DOUBLE, 200014.0), Range.equal(DOUBLE, 200017.0), Range.equal(DOUBLE, 200116.5), Range.range(DOUBLE, 200030.0, true, 200036.0, true), Range.range(DOUBLE, 200048.0, true, 200099.0, true))), false)).put(columns.get(7), Domain.create(SortedRangeSet.copyOf(TINYINT, ImmutableList.of(Range.range(TINYINT, 60L, true, 70L, false), Range.range(TINYINT, 52L, true, 55L, false))), false)).put(columns.get(8), Domain.create(SortedRangeSet.copyOf(SMALLINT, ImmutableList.of(Range.range(SMALLINT, -75L, true, -68L, true), Range.range(SMALLINT, -200L, true, -100L, false))), false)).put(columns.get(9), Domain.create(SortedRangeSet.copyOf(INTEGER, ImmutableList.of(Range.equal(INTEGER, 80L), Range.equal(INTEGER, 96L), Range.lessThan(INTEGER, 0L))), false)).put(columns.get(2), Domain.create(SortedRangeSet.copyOf(BOOLEAN, ImmutableList.of(Range.equal(BOOLEAN, true))), false)).buildOrThrow());
    Connection connection = database.getConnection();
    PreparedQuery preparedQuery = queryBuilder.prepareSelectQuery(jdbcClient, SESSION, connection, TEST_TABLE, Optional.empty(), columns, Map.of(), tupleDomain, Optional.empty());
    try (PreparedStatement preparedStatement = queryBuilder.prepareStatement(jdbcClient, SESSION, connection, preparedQuery)) {
        assertThat(preparedQuery.getQuery()).isEqualTo("" + "SELECT \"col_0\", \"col_1\", \"col_2\", \"col_3\", \"col_4\", \"col_5\", " + "\"col_6\", \"col_7\", \"col_8\", \"col_9\", \"col_10\", \"col_11\" " + "FROM \"test_table\" " + "WHERE (\"col_0\" < ? OR (\"col_0\" >= ? AND \"col_0\" <= ?) OR \"col_0\" > ? OR \"col_0\" IN (?,?)) " + "AND ((\"col_1\" >= ? AND \"col_1\" <= ?) OR (\"col_1\" >= ? AND \"col_1\" <= ?) OR \"col_1\" IN (?,?,?,?)) " + "AND ((\"col_7\" >= ? AND \"col_7\" < ?) OR (\"col_7\" >= ? AND \"col_7\" < ?)) " + "AND ((\"col_8\" >= ? AND \"col_8\" < ?) OR (\"col_8\" >= ? AND \"col_8\" <= ?)) " + "AND (\"col_9\" < ? OR \"col_9\" IN (?,?)) " + "AND \"col_2\" = ?");
        ImmutableSet.Builder<Long> builder = ImmutableSet.builder();
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                builder.add((Long) resultSet.getObject("col_0"));
            }
        }
        assertEquals(builder.build(), ImmutableSet.of(68L, 180L, 196L));
    }
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableSet(com.google.common.collect.ImmutableSet) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) Test(org.testng.annotations.Test)

Example 84 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class GenericHiveRecordCursorProvider method createRecordCursor.

@Override
public Optional<ReaderRecordCursorWithProjections> createRecordCursor(Configuration configuration, ConnectorSession session, Path path, long start, long length, long fileSize, Properties schema, List<HiveColumnHandle> columns, TupleDomain<HiveColumnHandle> effectivePredicate, TypeManager typeManager, boolean s3SelectPushdownEnabled) {
    configuration.setInt(LineRecordReader.MAX_LINE_LENGTH, textMaxLineLengthBytes);
    // make sure the FileSystem is created with the proper Configuration object
    try {
        this.hdfsEnvironment.getFileSystem(session.getIdentity(), path, configuration);
    } catch (IOException e) {
        throw new TrinoException(HIVE_FILESYSTEM_ERROR, "Failed getting FileSystem: " + path, e);
    }
    Optional<ReaderColumns> projections = projectBaseColumns(columns);
    List<HiveColumnHandle> readerColumns = projections.map(ReaderColumns::get).map(columnHandles -> columnHandles.stream().map(HiveColumnHandle.class::cast).collect(toUnmodifiableList())).orElse(columns);
    RecordCursor cursor = hdfsEnvironment.doAs(session.getIdentity(), () -> {
        RecordReader<?, ?> recordReader = HiveUtil.createRecordReader(configuration, path, start, length, schema, readerColumns);
        try {
            return new GenericHiveRecordCursor<>(configuration, path, genericRecordReader(recordReader), length, schema, readerColumns);
        } catch (Exception e) {
            try {
                recordReader.close();
            } catch (IOException closeException) {
                if (e != closeException) {
                    e.addSuppressed(closeException);
                }
            }
            throw e;
        }
    });
    return Optional.of(new ReaderRecordCursorWithProjections(cursor, projections));
}
Also used : HiveUtil(io.trino.plugin.hive.util.HiveUtil) RecordCursor(io.trino.spi.connector.RecordCursor) Properties(java.util.Properties) LineRecordReader(org.apache.hadoop.mapreduce.lib.input.LineRecordReader) TrinoException(io.trino.spi.TrinoException) Writable(org.apache.hadoop.io.Writable) IOException(java.io.IOException) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) Inject(javax.inject.Inject) DataSize(io.airlift.units.DataSize) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HivePageSourceProvider.projectBaseColumns(io.trino.plugin.hive.HivePageSourceProvider.projectBaseColumns) Configuration(org.apache.hadoop.conf.Configuration) Objects.requireNonNull(java.util.Objects.requireNonNull) Path(org.apache.hadoop.fs.Path) RecordReader(org.apache.hadoop.mapred.RecordReader) Optional(java.util.Optional) HIVE_FILESYSTEM_ERROR(io.trino.plugin.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR) Math.toIntExact(java.lang.Math.toIntExact) TypeManager(io.trino.spi.type.TypeManager) RecordCursor(io.trino.spi.connector.RecordCursor) TrinoException(io.trino.spi.TrinoException) IOException(java.io.IOException) TrinoException(io.trino.spi.TrinoException) IOException(java.io.IOException)

Example 85 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestDynamicFilterSourceOperator method testMultipleColumnsCollectMinMaxRangeWhenTooManyBytes.

@Test
public void testMultipleColumnsCollectMinMaxRangeWhenTooManyBytes() {
    DataSize maxSize = DataSize.of(10, KILOBYTE);
    long maxByteSize = maxSize.toBytes();
    String largeTextA = "A".repeat((int) (maxByteSize / 2) + 1);
    String largeTextB = "B".repeat((int) (maxByteSize / 2) + 1);
    Page largePage = new Page(createStringsBlock(largeTextA), createStringsBlock(largeTextB));
    List<TupleDomain<DynamicFilterId>> expectedTupleDomains = ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("0"), Domain.create(ValueSet.ofRanges(range(VARCHAR, utf8Slice(largeTextA), true, utf8Slice(largeTextA), true)), false), new DynamicFilterId("1"), Domain.create(ValueSet.ofRanges(range(VARCHAR, utf8Slice(largeTextB), true, utf8Slice(largeTextB), true)), false))));
    assertDynamicFilters(100, maxSize, 100, ImmutableList.of(VARCHAR, VARCHAR), ImmutableList.of(largePage), expectedTupleDomains);
}
Also used : TupleDomain(io.trino.spi.predicate.TupleDomain) DataSize(io.airlift.units.DataSize) Page(io.trino.spi.Page) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test)

Aggregations

TupleDomain (io.trino.spi.predicate.TupleDomain)97 Domain (io.trino.spi.predicate.Domain)77 Map (java.util.Map)50 ColumnHandle (io.trino.spi.connector.ColumnHandle)48 ImmutableMap (com.google.common.collect.ImmutableMap)43 ImmutableList (com.google.common.collect.ImmutableList)41 List (java.util.List)40 Optional (java.util.Optional)36 Set (java.util.Set)33 Test (org.testng.annotations.Test)33 Objects.requireNonNull (java.util.Objects.requireNonNull)32 ConnectorSession (io.trino.spi.connector.ConnectorSession)29 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)28 ImmutableSet (com.google.common.collect.ImmutableSet)26 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)23 Range (io.trino.spi.predicate.Range)22 String.format (java.lang.String.format)22 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)20 TrinoException (io.trino.spi.TrinoException)20 Type (io.trino.spi.type.Type)19