use of io.trino.spi.connector.Constraint in project trino by trinodb.
the class AbstractTestHive method testGetPartitionsWithBindings.
@Test
public void testGetPartitionsWithBindings() {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorTableHandle tableHandle = getTableHandle(metadata, tablePartitionFormat);
Constraint constraint = new Constraint(TupleDomain.withColumnDomains(ImmutableMap.of(intColumn, Domain.singleValue(BIGINT, 5L))));
tableHandle = applyFilter(metadata, tableHandle, constraint);
ConnectorTableProperties properties = metadata.getTableProperties(newSession(), tableHandle);
assertExpectedTableProperties(properties, tablePartitionFormatProperties);
assertExpectedPartitions(tableHandle, tablePartitionFormatPartitions);
}
}
use of io.trino.spi.connector.Constraint in project trino by trinodb.
the class TableScanStatsRule method doCalculate.
@Override
protected Optional<PlanNodeStatsEstimate> doCalculate(TableScanNode node, StatsProvider sourceStats, Lookup lookup, Session session, TypeProvider types) {
if (isStatisticsPrecalculationForPushdownEnabled(session) && node.getStatistics().isPresent()) {
return node.getStatistics();
}
// TODO Construct predicate like AddExchanges's LayoutConstraintEvaluator
Constraint constraint = new Constraint(TupleDomain.all());
TableStatistics tableStatistics = metadata.getTableStatistics(session, node.getTable(), constraint);
Map<Symbol, SymbolStatsEstimate> outputSymbolStats = new HashMap<>();
for (Map.Entry<Symbol, ColumnHandle> entry : node.getAssignments().entrySet()) {
Symbol symbol = entry.getKey();
Optional<ColumnStatistics> columnStatistics = Optional.ofNullable(tableStatistics.getColumnStatistics().get(entry.getValue()));
SymbolStatsEstimate symbolStatistics = columnStatistics.map(statistics -> toSymbolStatistics(tableStatistics, statistics, types.get(symbol))).orElse(SymbolStatsEstimate.unknown());
outputSymbolStats.put(symbol, symbolStatistics);
}
return Optional.of(PlanNodeStatsEstimate.builder().setOutputRowCount(tableStatistics.getRowCount().getValue()).addSymbolStatistics(outputSymbolStats).build());
}
use of io.trino.spi.connector.Constraint in project trino by trinodb.
the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdownWithConstraintPredicateOnViewsTable.
@Test
public void testInformationSchemaPredicatePushdownWithConstraintPredicateOnViewsTable() {
TransactionId transactionId = transactionManager.beginTransaction(false);
// predicate on non columns enumerating table should not cause tables to be enumerated
Constraint constraint = new Constraint(TupleDomain.all(), TestInformationSchemaMetadata::testConstraint, testConstraintColumns());
ConnectorSession session = createNewSession(transactionId);
ConnectorMetadata metadata = new InformationSchemaMetadata("test_catalog", this.metadata);
InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle) metadata.getTableHandle(session, new SchemaTableName("information_schema", "views"));
tableHandle = metadata.applyFilter(session, tableHandle, constraint).map(ConstraintApplicationResult::getHandle).map(InformationSchemaTableHandle.class::cast).orElseThrow(AssertionError::new);
assertEquals(tableHandle.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "test_schema")));
}
use of io.trino.spi.connector.Constraint in project trino by trinodb.
the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdown.
/**
* Tests information schema predicate pushdown when both schema and table name are specified.
*/
@Test
public void testInformationSchemaPredicatePushdown() {
TransactionId transactionId = transactionManager.beginTransaction(false);
ImmutableMap.Builder<ColumnHandle, Domain> domains = ImmutableMap.builder();
domains.put(new InformationSchemaColumnHandle("table_schema"), Domain.singleValue(VARCHAR, Slices.utf8Slice("test_schema")));
domains.put(new InformationSchemaColumnHandle("table_name"), Domain.singleValue(VARCHAR, Slices.utf8Slice("test_view")));
Constraint constraint = new Constraint(TupleDomain.withColumnDomains(domains.buildOrThrow()));
ConnectorSession session = createNewSession(transactionId);
ConnectorMetadata metadata = new InformationSchemaMetadata("test_catalog", this.metadata);
InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle) metadata.getTableHandle(session, new SchemaTableName("information_schema", "views"));
tableHandle = metadata.applyFilter(session, tableHandle, constraint).map(ConstraintApplicationResult::getHandle).map(InformationSchemaTableHandle.class::cast).orElseThrow(AssertionError::new);
assertEquals(tableHandle.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "test_schema", "test_view")));
}
use of io.trino.spi.connector.Constraint in project trino by trinodb.
the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdownOnCatalogWiseTables.
@Test
public void testInformationSchemaPredicatePushdownOnCatalogWiseTables() {
TransactionId transactionId = transactionManager.beginTransaction(false);
// Predicate pushdown shouldn't work for catalog-wise tables because the table prefixes for them are always
// ImmutableSet.of(new QualifiedTablePrefix(catalogName));
Constraint constraint = new Constraint(TupleDomain.all());
ConnectorSession session = createNewSession(transactionId);
ConnectorMetadata metadata = new InformationSchemaMetadata("test_catalog", this.metadata);
InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle) metadata.getTableHandle(session, new SchemaTableName("information_schema", "schemata"));
Optional<ConstraintApplicationResult<ConnectorTableHandle>> result = metadata.applyFilter(session, tableHandle, constraint);
assertFalse(result.isPresent());
}
Aggregations