Search in sources :

Example 36 with Constraint

use of io.trino.spi.connector.Constraint in project trino by trinodb.

the class AbstractTestHive method readTable.

protected MaterializedResult readTable(Transaction transaction, ConnectorTableHandle tableHandle, List<ColumnHandle> columnHandles, ConnectorSession session, TupleDomain<ColumnHandle> tupleDomain, OptionalInt expectedSplitCount, Optional<HiveStorageFormat> expectedStorageFormat) throws Exception {
    tableHandle = applyFilter(transaction.getMetadata(), tableHandle, new Constraint(tupleDomain));
    List<ConnectorSplit> splits = getAllSplits(getSplits(splitManager, transaction, session, tableHandle));
    if (expectedSplitCount.isPresent()) {
        assertEquals(splits.size(), expectedSplitCount.getAsInt());
    }
    ImmutableList.Builder<MaterializedRow> allRows = ImmutableList.builder();
    for (ConnectorSplit split : splits) {
        try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, tableHandle, columnHandles, DynamicFilter.EMPTY)) {
            expectedStorageFormat.ifPresent(format -> assertPageSourceType(pageSource, format));
            MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
            allRows.addAll(result.getMaterializedRows());
        }
    }
    return new MaterializedResult(allRows.build(), getTypes(columnHandles));
}
Also used : Constraint(io.trino.spi.connector.Constraint) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource) MaterializedResult(io.trino.testing.MaterializedResult) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) MaterializedRow(io.trino.testing.MaterializedRow)

Example 37 with Constraint

use of io.trino.spi.connector.Constraint in project trino by trinodb.

the class TestDefaultJdbcMetadata method testApplyFilterAfterAggregationPushdown.

@Test
public void testApplyFilterAfterAggregationPushdown() {
    ConnectorSession session = TestingConnectorSession.builder().setPropertyMetadata(new JdbcMetadataSessionProperties(new JdbcMetadataConfig().setAggregationPushdownEnabled(true), Optional.empty()).getSessionProperties()).build();
    ColumnHandle groupByColumn = metadata.getColumnHandles(session, tableHandle).get("text");
    ConnectorTableHandle baseTableHandle = metadata.getTableHandle(session, new SchemaTableName("example", "numbers"));
    ConnectorTableHandle aggregatedTable = applyCountAggregation(session, baseTableHandle, ImmutableList.of(ImmutableList.of(groupByColumn)));
    Domain domain = Domain.singleValue(VARCHAR, utf8Slice("one"));
    JdbcTableHandle tableHandleWithFilter = applyFilter(session, aggregatedTable, new Constraint(TupleDomain.withColumnDomains(ImmutableMap.of(groupByColumn, domain))));
    assertEquals(tableHandleWithFilter.getConstraint().getDomains(), Optional.of(ImmutableMap.of(groupByColumn, domain)));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Constraint(io.trino.spi.connector.Constraint) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 38 with Constraint

use of io.trino.spi.connector.Constraint in project trino by trinodb.

the class TestJmxMetadata method testApplyFilterWithConstraint.

@Test
public void testApplyFilterWithConstraint() {
    JmxTableHandle handle = metadata.getTableHandle(SESSION, new SchemaTableName(JMX_SCHEMA_NAME, "java.lang:*"));
    JmxColumnHandle nodeColumnHandle = new JmxColumnHandle("node", createUnboundedVarcharType());
    NullableValue nodeColumnValue = NullableValue.of(createUnboundedVarcharType(), utf8Slice(localNode.getNodeIdentifier()));
    JmxColumnHandle objectNameColumnHandle = new JmxColumnHandle("object_name", createUnboundedVarcharType());
    NullableValue objectNameColumnValue = NullableValue.of(createUnboundedVarcharType(), utf8Slice("trino.memory:type=MemoryPool,name=reserved"));
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(nodeColumnHandle, nodeColumnValue, objectNameColumnHandle, objectNameColumnValue));
    Optional<ConstraintApplicationResult<ConnectorTableHandle>> result = metadata.applyFilter(SESSION, handle, new Constraint(tupleDomain));
    assertTrue(result.isPresent());
    assertEquals(result.get().getRemainingFilter(), TupleDomain.fromFixedValues(ImmutableMap.of(objectNameColumnHandle, objectNameColumnValue)));
    assertEquals(((JmxTableHandle) result.get().getHandle()).getNodeFilter(), TupleDomain.fromFixedValues(ImmutableMap.of(nodeColumnHandle, nodeColumnValue)));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Constraint(io.trino.spi.connector.Constraint) NullableValue(io.trino.spi.predicate.NullableValue) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 39 with Constraint

use of io.trino.spi.connector.Constraint in project trino by trinodb.

the class TestJmxMetadata method testApplyFilterWithSameConstraint.

@Test
public void testApplyFilterWithSameConstraint() {
    JmxTableHandle handle = metadata.getTableHandle(SESSION, new SchemaTableName(JMX_SCHEMA_NAME, "java.lang:*"));
    JmxColumnHandle columnHandle = new JmxColumnHandle("node", createUnboundedVarcharType());
    TupleDomain<ColumnHandle> nodeTupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(columnHandle, NullableValue.of(createUnboundedVarcharType(), utf8Slice(localNode.getNodeIdentifier()))));
    JmxTableHandle newTableHandle = new JmxTableHandle(handle.getTableName(), handle.getObjectNames(), handle.getColumnHandles(), handle.isLiveData(), nodeTupleDomain);
    Optional<ConstraintApplicationResult<ConnectorTableHandle>> result = metadata.applyFilter(SESSION, newTableHandle, new Constraint(nodeTupleDomain));
    assertFalse(result.isPresent());
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Constraint(io.trino.spi.connector.Constraint) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 40 with Constraint

use of io.trino.spi.connector.Constraint in project trino by trinodb.

the class TestJmxMetadata method testApplyFilterWithoutConstraint.

@Test
public void testApplyFilterWithoutConstraint() {
    JmxTableHandle handle = metadata.getTableHandle(SESSION, new SchemaTableName(JMX_SCHEMA_NAME, "java.lang:*"));
    Optional<ConstraintApplicationResult<ConnectorTableHandle>> result = metadata.applyFilter(SESSION, handle, new Constraint(TupleDomain.all()));
    assertFalse(result.isPresent());
}
Also used : Constraint(io.trino.spi.connector.Constraint) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Aggregations

Constraint (io.trino.spi.connector.Constraint)41 ColumnHandle (io.trino.spi.connector.ColumnHandle)32 SchemaTableName (io.trino.spi.connector.SchemaTableName)28 TupleDomain (io.trino.spi.predicate.TupleDomain)27 ConnectorSession (io.trino.spi.connector.ConnectorSession)26 Domain (io.trino.spi.predicate.Domain)23 Test (org.testng.annotations.Test)23 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)20 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)18 ConstraintApplicationResult (io.trino.spi.connector.ConstraintApplicationResult)18 Map (java.util.Map)18 Objects.requireNonNull (java.util.Objects.requireNonNull)18 Optional (java.util.Optional)18 ImmutableMap (com.google.common.collect.ImmutableMap)17 List (java.util.List)17 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)16 ImmutableList (com.google.common.collect.ImmutableList)15 Set (java.util.Set)15 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)14 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)13