Search in sources :

Example 6 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class TestDatabaseShardManager method testShardPruningNoStats.

@Test
public void testShardPruningNoStats() throws Exception {
    ShardInfo shard = shardInfo(UUID.randomUUID(), "node");
    List<ShardInfo> shards = ImmutableList.of(shard);
    long tableId = createTable("test");
    List<ColumnInfo> columns = ImmutableList.of(new ColumnInfo(1, BIGINT));
    RaptorColumnHandle c1 = new RaptorColumnHandle("raptor", "c1", 1, BIGINT);
    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, BIGINT, 3L).expected(shards);
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) Test(org.testng.annotations.Test)

Example 7 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class ShardPredicate method create.

public static ShardPredicate create(TupleDomain<RaptorColumnHandle> tupleDomain, boolean bucketed) {
    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;
        }
        Ranges ranges = domain.getValues().getRanges();
        // TODO: support multiple ranges
        if (ranges.getRangeCount() != 1) {
            continue;
        }
        Range range = getOnlyElement(ranges.getOrderedRanges());
        Object minValue = null;
        Object maxValue = null;
        if (range.isSingleValue()) {
            minValue = range.getSingleValue();
            maxValue = range.getSingleValue();
        } else {
            if (!range.getLow().isLowerUnbounded()) {
                minValue = range.getLow().getValue();
            }
            if (!range.getHigh().isUpperUnbounded()) {
                maxValue = range.getHigh().getValue();
            }
        }
        String min;
        String max;
        if (handle.isBucketNumber()) {
            if (!bucketed) {
                predicate.add("false");
                continue;
            }
            min = "bucket_number";
            max = "bucket_number";
        } else {
            min = minColumn(handle.getColumnId());
            max = maxColumn(handle.getColumnId());
        }
        if (minValue != null) {
            predicate.add(format("(%s >= ? OR %s IS NULL)", max, max));
            types.add(jdbcType);
            values.add(minValue);
        }
        if (maxValue != null) {
            predicate.add(format("(%s <= ? OR %s IS NULL)", min, min));
            types.add(jdbcType);
            values.add(maxValue);
        }
    }
    return new ShardPredicate(predicate.toString(), types.build(), values.build());
}
Also used : Ranges(com.facebook.presto.spi.predicate.Ranges) JDBCType(java.sql.JDBCType) RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) Range(com.facebook.presto.spi.predicate.Range) JDBCType(java.sql.JDBCType) Type(com.facebook.presto.spi.type.Type) ColumnIndexStatsUtils.jdbcType(com.facebook.presto.raptor.storage.ColumnIndexStatsUtils.jdbcType) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) StringJoiner(java.util.StringJoiner)

Example 8 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class TestShardPredicate method testDiscreteShardUuidPredicate.

@Test
public void testDiscreteShardUuidPredicate() throws Exception {
    Slice uuid0 = utf8Slice(randomUUID().toString());
    Slice uuid1 = utf8Slice(randomUUID().toString());
    TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(shardUuidColumnHandle("test"), create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of(equal(VARCHAR, uuid0), equal(VARCHAR, uuid1))), false)));
    ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain, bucketed);
    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(com.facebook.presto.raptor.RaptorColumnHandle) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Test(org.testng.annotations.Test)

Example 9 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class TestRaptorMetadata method testCreateTable.

@Test
public void testCreateTable() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    metadata.createTable(SESSION, getOrdersTable());
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    assertEquals(((RaptorTableHandle) tableHandle).getTableId(), 1);
    ConnectorTableMetadata table = metadata.getTableMetadata(SESSION, tableHandle);
    assertTableEqual(table, getOrdersTable());
    ColumnHandle columnHandle = metadata.getColumnHandles(SESSION, tableHandle).get("orderkey");
    assertInstanceOf(columnHandle, RaptorColumnHandle.class);
    assertEquals(((RaptorColumnHandle) columnHandle).getColumnId(), 1);
    ColumnMetadata columnMetadata = metadata.getColumnMetadata(SESSION, tableHandle, columnHandle);
    assertNotNull(columnMetadata);
    assertEquals(columnMetadata.getName(), "orderkey");
    assertEquals(columnMetadata.getType(), BIGINT);
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

RaptorColumnHandle (com.facebook.presto.raptor.RaptorColumnHandle)9 Test (org.testng.annotations.Test)8 Slice (io.airlift.slice.Slice)4 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)4 Type (com.facebook.presto.spi.type.Type)2 ShardInfo (com.facebook.presto.raptor.metadata.ShardInfo)1 ColumnIndexStatsUtils.jdbcType (com.facebook.presto.raptor.storage.ColumnIndexStatsUtils.jdbcType)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)1 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)1 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)1 Page (com.facebook.presto.spi.Page)1 Domain (com.facebook.presto.spi.predicate.Domain)1 NullableValue (com.facebook.presto.spi.predicate.NullableValue)1 Range (com.facebook.presto.spi.predicate.Range)1 Ranges (com.facebook.presto.spi.predicate.Ranges)1 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)1 VarcharType.createVarcharType (com.facebook.presto.spi.type.VarcharType.createVarcharType)1 MaterializedResult (com.facebook.presto.testing.MaterializedResult)1