Search in sources :

Example 1 with RaptorColumnHandle

use of io.trino.plugin.raptor.legacy.RaptorColumnHandle in project trino by trinodb.

the class ShardPredicate method create.

public static ShardPredicate create(TupleDomain<RaptorColumnHandle> tupleDomain) {
    StringJoiner predicate = new StringJoiner(" AND ").setEmptyValue("true");
    ImmutableList.Builder<JDBCType> types = ImmutableList.builder();
    ImmutableList.Builder<Object> values = ImmutableList.builder();
    for (Entry<RaptorColumnHandle, Domain> entry : tupleDomain.getDomains().get().entrySet()) {
        Domain domain = entry.getValue();
        if (domain.isNullAllowed() || domain.isAll()) {
            continue;
        }
        RaptorColumnHandle handle = entry.getKey();
        Type type = handle.getColumnType();
        JDBCType jdbcType = jdbcType(type);
        if (jdbcType == null) {
            continue;
        }
        if (handle.isShardUuid()) {
            predicate.add(createShardPredicate(types, values, domain, jdbcType));
            continue;
        }
        if (!domain.getType().isOrderable()) {
            continue;
        }
        StringJoiner columnPredicate = new StringJoiner(" OR ", "(", ")").setEmptyValue("true");
        Ranges ranges = domain.getValues().getRanges();
        // prevent generating complicated metadata queries
        if (ranges.getRangeCount() > MAX_RANGE_COUNT) {
            continue;
        }
        for (Range range : ranges.getOrderedRanges()) {
            String min;
            String max;
            if (handle.isBucketNumber()) {
                min = "bucket_number";
                max = "bucket_number";
            } else {
                min = minColumn(handle.getColumnId());
                max = maxColumn(handle.getColumnId());
            }
            StringJoiner rangePredicate = new StringJoiner(" AND ", "(", ")").setEmptyValue("true");
            if (!range.isLowUnbounded()) {
                rangePredicate.add(format("(%s >= ? OR %s IS NULL)", max, max));
                types.add(jdbcType);
                values.add(range.getLowBoundedValue());
            }
            if (!range.isHighUnbounded()) {
                rangePredicate.add(format("(%s <= ? OR %s IS NULL)", min, min));
                types.add(jdbcType);
                values.add(range.getHighBoundedValue());
            }
            columnPredicate.add(rangePredicate.toString());
        }
        predicate.add(columnPredicate.toString());
    }
    return new ShardPredicate(predicate.toString(), types.build(), values.build());
}
Also used : Ranges(io.trino.spi.predicate.Ranges) JDBCType(java.sql.JDBCType) RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) Range(io.trino.spi.predicate.Range) Type(io.trino.spi.type.Type) JDBCType(java.sql.JDBCType) ColumnIndexStatsUtils.jdbcType(io.trino.plugin.raptor.legacy.storage.ColumnIndexStatsUtils.jdbcType) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) StringJoiner(java.util.StringJoiner)

Example 2 with RaptorColumnHandle

use of io.trino.plugin.raptor.legacy.RaptorColumnHandle in project trino by trinodb.

the class TestDatabaseShardManager method testShardPruningTruncatedValues.

@Test
public void testShardPruningTruncatedValues() {
    String prefix = "x".repeat(MAX_BINARY_INDEX_SIZE);
    ColumnStats stats = new ColumnStats(1, prefix + "a", prefix + "z");
    ShardInfo shard = shardInfo(UUID.randomUUID(), "node", ImmutableList.of(stats));
    List<ShardInfo> shards = ImmutableList.of(shard);
    List<ColumnInfo> columns = ImmutableList.of(new ColumnInfo(1, createVarcharType(10)));
    RaptorColumnHandle c1 = new RaptorColumnHandle("c1", 1, createVarcharType(10));
    long tableId = createTable("test");
    shardManager.createTable(tableId, columns, false, OptionalLong.empty());
    long transactionId = shardManager.beginTransaction();
    shardManager.commitShards(transactionId, tableId, columns, shards, Optional.empty(), 0);
    shardAssertion(tableId).expected(shards);
    shardAssertion(tableId).equal(c1, createVarcharType(10), utf8Slice(prefix)).expected(shards);
    shardAssertion(tableId).equal(c1, createVarcharType(10), utf8Slice(prefix + "c")).expected(shards);
    shardAssertion(tableId).range(c1, lessThan(createVarcharType(10), utf8Slice(prefix + "c"))).expected(shards);
    shardAssertion(tableId).range(c1, greaterThan(createVarcharType(10), utf8Slice(prefix + "zzz"))).expected(shards);
    shardAssertion(tableId).between(c1, createVarcharType(10), utf8Slice("w"), utf8Slice("y")).expected(shards);
    shardAssertion(tableId).range(c1, greaterThan(createVarcharType(10), utf8Slice("x"))).expected(shards);
    shardAssertion(tableId).between(c1, createVarcharType(10), utf8Slice("x"), utf8Slice("x")).expected();
    shardAssertion(tableId).range(c1, lessThan(createVarcharType(10), utf8Slice("w"))).expected();
    shardAssertion(tableId).range(c1, lessThan(createVarcharType(10), utf8Slice("x"))).expected();
    shardAssertion(tableId).range(c1, greaterThan(createVarcharType(10), utf8Slice("y"))).expected();
    Slice shorter = utf8Slice(prefix.substring(0, prefix.length() - 1));
    shardAssertion(tableId).equal(c1, createVarcharType(10), shorter).expected();
    shardAssertion(tableId).range(c1, lessThan(createVarcharType(10), shorter)).expected();
    shardAssertion(tableId).range(c1, greaterThan(createVarcharType(10), shorter)).expected(shards);
}
Also used : RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) Test(org.testng.annotations.Test)

Example 3 with RaptorColumnHandle

use of io.trino.plugin.raptor.legacy.RaptorColumnHandle in project trino by trinodb.

the class TestShardPredicate method testDiscreteShardUuidPredicate.

@Test
public void testDiscreteShardUuidPredicate() {
    Slice uuid0 = utf8Slice(randomUUID().toString());
    Slice uuid1 = utf8Slice(randomUUID().toString());
    TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(shardUuidColumnHandle(), create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of(equal(VARCHAR, uuid0), equal(VARCHAR, uuid1))), false)));
    ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain);
    assertEquals(shardPredicate.getPredicate(), "shard_uuid = ? OR shard_uuid = ?");
    assertEquals(shardPredicate.getTypes(), ImmutableList.of(VARBINARY, VARBINARY));
    assertEquals(ImmutableSet.copyOf(shardPredicate.getValues()), ImmutableSet.of(uuidStringToBytes(uuid0), uuidStringToBytes(uuid1)));
}
Also used : RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Test(org.testng.annotations.Test)

Example 4 with RaptorColumnHandle

use of io.trino.plugin.raptor.legacy.RaptorColumnHandle in project trino by trinodb.

the class TestRaptorStorageManager method testReader.

@Test
public void testReader() throws Exception {
    RaptorStorageManager manager = createRaptorStorageManager();
    List<Long> columnIds = ImmutableList.of(2L, 4L, 6L, 7L, 8L, 9L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10), VARBINARY, DATE, BOOLEAN, DOUBLE);
    byte[] bytes1 = octets(0x00, 0xFE, 0xFF);
    byte[] bytes3 = octets(0x01, 0x02, 0x19, 0x80);
    StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
    Object[][] doubles = { { 881L, "-inf", null, null, null, Double.NEGATIVE_INFINITY }, { 882L, "+inf", null, null, null, Double.POSITIVE_INFINITY }, { 883L, "nan", null, null, null, Double.NaN }, { 884L, "min", null, null, null, Double.MIN_VALUE }, { 885L, "max", null, null, null, Double.MAX_VALUE }, { 886L, "pzero", null, null, null, 0.0 }, { 887L, "nzero", null, null, null, -0.0 } };
    List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello", wrappedBuffer(bytes1), sqlDate(2001, 8, 22).getDays(), true, 123.45).row(null, null, null, null, null, null).row(456L, "bye", wrappedBuffer(bytes3), sqlDate(2005, 4, 22).getDays(), false, 987.65).rows(doubles).build();
    sink.appendPages(pages);
    List<ShardInfo> shards = getFutureValue(sink.commit());
    assertEquals(shards.size(), 1);
    UUID uuid = Iterables.getOnlyElement(shards).getShardUuid();
    MaterializedResult expected = resultBuilder(SESSION, columnTypes).row(123L, "hello", sqlBinary(bytes1), sqlDate(2001, 8, 22), true, 123.45).row(null, null, null, null, null, null).row(456L, "bye", sqlBinary(bytes3), sqlDate(2005, 4, 22), false, 987.65).rows(doubles).build();
    // no tuple domain (all)
    TupleDomain<RaptorColumnHandle> tupleDomain = TupleDomain.all();
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), expected.getRowCount());
        assertEquals(result, expected);
    }
    // tuple domain within the column range
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.<RaptorColumnHandle, NullableValue>builder().put(new RaptorColumnHandle("c1", 2, BIGINT), NullableValue.of(BIGINT, 124L)).buildOrThrow());
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), expected.getRowCount());
    }
    // tuple domain outside the column range
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.<RaptorColumnHandle, NullableValue>builder().put(new RaptorColumnHandle("c1", 2, BIGINT), NullableValue.of(BIGINT, 122L)).buildOrThrow());
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), 0);
    }
}
Also used : RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) NullableValue(io.trino.spi.predicate.NullableValue) Page(io.trino.spi.Page) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource) Type(io.trino.spi.type.Type) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) OptionalLong(java.util.OptionalLong) UUID(java.util.UUID) MaterializedResult(io.trino.testing.MaterializedResult) ShardInfo(io.trino.plugin.raptor.legacy.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 5 with RaptorColumnHandle

use of io.trino.plugin.raptor.legacy.RaptorColumnHandle in project trino by trinodb.

the class TestShardPredicate method testInvalidUuid.

@Test
public void testInvalidUuid() {
    Slice uuid0 = utf8Slice("test1");
    Slice uuid1 = utf8Slice("test2");
    TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(shardUuidColumnHandle(), create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of(equal(VARCHAR, uuid0), equal(VARCHAR, uuid1))), false)));
    ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain);
    assertEquals(shardPredicate.getPredicate(), "true");
}
Also used : RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Test(org.testng.annotations.Test)

Aggregations

RaptorColumnHandle (io.trino.plugin.raptor.legacy.RaptorColumnHandle)9 Test (org.testng.annotations.Test)8 Slice (io.airlift.slice.Slice)4 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)4 Type (io.trino.spi.type.Type)2 ImmutableList (com.google.common.collect.ImmutableList)1 ShardInfo (io.trino.plugin.raptor.legacy.metadata.ShardInfo)1 ColumnIndexStatsUtils.jdbcType (io.trino.plugin.raptor.legacy.storage.ColumnIndexStatsUtils.jdbcType)1 Page (io.trino.spi.Page)1 ColumnHandle (io.trino.spi.connector.ColumnHandle)1 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)1 ConnectorPageSource (io.trino.spi.connector.ConnectorPageSource)1 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)1 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)1 Domain (io.trino.spi.predicate.Domain)1 NullableValue (io.trino.spi.predicate.NullableValue)1 Range (io.trino.spi.predicate.Range)1 Ranges (io.trino.spi.predicate.Ranges)1 TupleDomain (io.trino.spi.predicate.TupleDomain)1 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)1