Search in sources :

Example 86 with TupleDomain

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

the class HivePageSourceProvider method shouldSkipSplit.

private static boolean shouldSkipSplit(List<ColumnMapping> columnMappings, DynamicFilter dynamicFilter) {
    TupleDomain<ColumnHandle> predicate = dynamicFilter.getCurrentPredicate();
    if (predicate.isNone()) {
        return true;
    }
    Map<ColumnHandle, Domain> domains = predicate.getDomains().get();
    for (ColumnMapping columnMapping : columnMappings) {
        if (columnMapping.getKind() != PREFILLED) {
            continue;
        }
        Object value = columnMapping.getPrefilledValue().getValue();
        Domain allowedDomain = domains.get(columnMapping.getHiveColumnHandle());
        if (allowedDomain != null && !allowedDomain.includesNullableValue(value)) {
            return true;
        }
    }
    return false;
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) HiveColumnHandle.isRowIdColumnHandle(io.trino.plugin.hive.HiveColumnHandle.isRowIdColumnHandle) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain)

Example 87 with TupleDomain

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

the class HivePartitionManager method partitionMatches.

public static boolean partitionMatches(List<HiveColumnHandle> partitionColumns, TupleDomain<ColumnHandle> constraintSummary, HivePartition partition) {
    if (constraintSummary.isNone()) {
        return false;
    }
    Map<ColumnHandle, Domain> domains = constraintSummary.getDomains().get();
    for (HiveColumnHandle column : partitionColumns) {
        NullableValue value = partition.getKeys().get(column);
        Domain allowedDomain = domains.get(column);
        if (allowedDomain != null && !allowedDomain.includesNullableValue(value.getValue())) {
            return false;
        }
    }
    return true;
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) NullableValue(io.trino.spi.predicate.NullableValue) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain)

Example 88 with TupleDomain

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

the class JmxSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy, DynamicFilter dynamicFilter) {
    JmxTableHandle tableHandle = (JmxTableHandle) table;
    // TODO is there a better way to get the node column?
    Optional<JmxColumnHandle> nodeColumnHandle = tableHandle.getColumnHandles().stream().filter(jmxColumnHandle -> jmxColumnHandle.getColumnName().equals(NODE_COLUMN_NAME)).findFirst();
    checkState(nodeColumnHandle.isPresent(), "Failed to find %s column", NODE_COLUMN_NAME);
    TupleDomain<ColumnHandle> nodeFilter = tableHandle.getNodeFilter();
    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream().filter(node -> {
        NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
        return nodeFilter.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
    }).map(node -> new JmxSplit(ImmutableList.of(node.getHostAndPort()))).collect(toList());
    return new FixedSplitSource(splits);
}
Also used : ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) ImmutableMap(com.google.common.collect.ImmutableMap) NullableValue(io.trino.spi.predicate.NullableValue) NodeManager(io.trino.spi.NodeManager) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) ConnectorSplitSource(io.trino.spi.connector.ConnectorSplitSource) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Inject(javax.inject.Inject) TupleDomain.fromFixedValues(io.trino.spi.predicate.TupleDomain.fromFixedValues) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) NODE_COLUMN_NAME(io.trino.plugin.jmx.JmxMetadata.NODE_COLUMN_NAME) DynamicFilter(io.trino.spi.connector.DynamicFilter) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) Optional(java.util.Optional) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) NullableValue(io.trino.spi.predicate.NullableValue) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Example 89 with TupleDomain

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

the class TestShardMetadataRecordCursor method testSimple.

@Test
public void testSimple() {
    ShardManager shardManager = createShardManager(dbi);
    // Add shards to the table
    long tableId = 1;
    OptionalInt bucketNumber = OptionalInt.empty();
    UUID uuid1 = UUID.randomUUID();
    UUID uuid2 = UUID.randomUUID();
    UUID uuid3 = UUID.randomUUID();
    ShardInfo shardInfo1 = new ShardInfo(uuid1, bucketNumber, ImmutableSet.of("node1"), ImmutableList.of(), 1, 10, 100, 0x1234);
    ShardInfo shardInfo2 = new ShardInfo(uuid2, bucketNumber, ImmutableSet.of("node2"), ImmutableList.of(), 2, 20, 200, 0xCAFEBABEDEADBEEFL);
    ShardInfo shardInfo3 = new ShardInfo(uuid3, bucketNumber, ImmutableSet.of("node3"), ImmutableList.of(), 3, 30, 300, 0xFEDCBA0987654321L);
    List<ShardInfo> shards = ImmutableList.of(shardInfo1, shardInfo2, shardInfo3);
    long transactionId = shardManager.beginTransaction();
    shardManager.commitShards(transactionId, tableId, ImmutableList.of(new ColumnInfo(1, BIGINT), new ColumnInfo(2, DATE)), shards, Optional.empty(), 0);
    Slice schema = utf8Slice(DEFAULT_TEST_ORDERS.getSchemaName());
    Slice table = utf8Slice(DEFAULT_TEST_ORDERS.getTableName());
    DateTime date1 = DateTime.parse("2015-01-01T00:00");
    DateTime date2 = DateTime.parse("2015-01-02T00:00");
    TupleDomain<Integer> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.<Integer, Domain>builder().put(0, Domain.singleValue(createVarcharType(10), schema)).put(1, Domain.create(ValueSet.ofRanges(lessThanOrEqual(createVarcharType(10), table)), true)).put(8, Domain.create(ValueSet.ofRanges(lessThanOrEqual(BIGINT, date1.getMillis()), greaterThan(BIGINT, date2.getMillis())), true)).put(9, Domain.create(ValueSet.ofRanges(lessThanOrEqual(BIGINT, date1.getMillis()), greaterThan(BIGINT, date2.getMillis())), true)).buildOrThrow());
    List<MaterializedRow> actual;
    try (RecordCursor cursor = new ShardMetadataSystemTable(dbi).cursor(null, SESSION, tupleDomain)) {
        actual = getMaterializedResults(cursor, SHARD_METADATA.getColumns());
    }
    assertEquals(actual.size(), 3);
    List<MaterializedRow> expected = ImmutableList.of(new MaterializedRow(DEFAULT_PRECISION, schema, table, utf8Slice(uuid1.toString()), null, 100L, 10L, 1L, utf8Slice("0000000000001234"), null, null, null, null), new MaterializedRow(DEFAULT_PRECISION, schema, table, utf8Slice(uuid2.toString()), null, 200L, 20L, 2L, utf8Slice("cafebabedeadbeef"), null, null, null, null), new MaterializedRow(DEFAULT_PRECISION, schema, table, utf8Slice(uuid3.toString()), null, 300L, 30L, 3L, utf8Slice("fedcba0987654321"), null, null, null, null));
    assertEquals(actual, expected);
}
Also used : RecordCursor(io.trino.spi.connector.RecordCursor) ColumnInfo(io.trino.plugin.raptor.legacy.metadata.ColumnInfo) ShardManager(io.trino.plugin.raptor.legacy.metadata.ShardManager) TestDatabaseShardManager.createShardManager(io.trino.plugin.raptor.legacy.metadata.TestDatabaseShardManager.createShardManager) OptionalInt(java.util.OptionalInt) DateTime(org.joda.time.DateTime) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) UUID(java.util.UUID) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) MaterializedRow(io.trino.testing.MaterializedRow) ShardInfo(io.trino.plugin.raptor.legacy.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 90 with TupleDomain

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

the class PreparedStatementBuilder method getWhereClause.

@SuppressWarnings("OptionalGetWithoutIsPresent")
private static String getWhereClause(TupleDomain<Integer> tupleDomain, List<String> columnNames, List<Type> types, Set<Integer> uuidColumnIndexes, List<ValueBuffer> bindValues) {
    if (tupleDomain.isNone()) {
        return "";
    }
    ImmutableList.Builder<String> conjunctsBuilder = ImmutableList.builder();
    Map<Integer, Domain> domainMap = tupleDomain.getDomains().get();
    for (Map.Entry<Integer, Domain> entry : domainMap.entrySet()) {
        int index = entry.getKey();
        String columnName = columnNames.get(index);
        Type type = types.get(index);
        conjunctsBuilder.add(toPredicate(index, columnName, type, entry.getValue(), uuidColumnIndexes, bindValues));
    }
    List<String> conjuncts = conjunctsBuilder.build();
    if (conjuncts.isEmpty()) {
        return "";
    }
    StringBuilder where = new StringBuilder("WHERE ");
    return Joiner.on(" AND\n").appendTo(where, conjuncts).toString();
}
Also used : Type(io.trino.spi.type.Type) VarcharType(io.trino.spi.type.VarcharType) ImmutableList(com.google.common.collect.ImmutableList) UUID.fromString(java.util.UUID.fromString) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) Map(java.util.Map)

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