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()));
}
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);
}
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));
}
}
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));
}
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);
}
Aggregations