use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class BaseIcebergConnectorTest method getTableStatistics.
private TableStatistics getTableStatistics(String tableName, Constraint constraint) {
Metadata metadata = getDistributedQueryRunner().getCoordinator().getMetadata();
QualifiedObjectName qualifiedName = QualifiedObjectName.valueOf(tableName);
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(getSession(), session -> {
Optional<TableHandle> optionalHandle = metadata.getTableHandle(session, qualifiedName);
checkArgument(optionalHandle.isPresent(), "Could not create table handle for table %s", tableName);
return metadata.getTableStatistics(session, optionalHandle.get(), constraint);
});
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class BaseIcebergConnectorTest method testPredicatePushdown.
@Test
public void testPredicatePushdown() {
QualifiedObjectName tableName = new QualifiedObjectName("iceberg", "tpch", "test_predicate");
assertUpdate(format("CREATE TABLE %s (col1 BIGINT, col2 BIGINT, col3 BIGINT) WITH (partitioning = ARRAY['col2', 'col3'])", tableName));
assertUpdate(format("INSERT INTO %s VALUES (1, 10, 100)", tableName), 1L);
assertUpdate(format("INSERT INTO %s VALUES (2, 20, 200)", tableName), 1L);
assertQuery(format("SELECT * FROM %s WHERE col1 = 1", tableName), "VALUES (1, 10, 100)");
assertFilterPushdown(tableName, ImmutableMap.of("col1", singleValue(BIGINT, 1L)), ImmutableMap.of(), ImmutableMap.of("col1", singleValue(BIGINT, 1L)));
assertQuery(format("SELECT * FROM %s WHERE col2 = 10", tableName), "VALUES (1, 10, 100)");
assertFilterPushdown(tableName, ImmutableMap.of("col2", singleValue(BIGINT, 10L)), ImmutableMap.of("col2", singleValue(BIGINT, 10L)), ImmutableMap.of());
assertQuery(format("SELECT * FROM %s WHERE col1 = 1 AND col2 = 10", tableName), "VALUES (1, 10, 100)");
assertFilterPushdown(tableName, ImmutableMap.of("col1", singleValue(BIGINT, 1L), "col2", singleValue(BIGINT, 10L)), ImmutableMap.of("col2", singleValue(BIGINT, 10L)), ImmutableMap.of("col1", singleValue(BIGINT, 1L)));
// Assert pushdown for an IN predicate with value count above the default compaction threshold
List<Long> values = LongStream.range(1L, 1010L).boxed().filter(index -> index != 20L).collect(toImmutableList());
assertTrue(values.size() > ICEBERG_DOMAIN_COMPACTION_THRESHOLD);
String valuesString = join(",", values.stream().map(Object::toString).collect(toImmutableList()));
String inPredicate = "%s IN (" + valuesString + ")";
assertQuery(format("SELECT * FROM %s WHERE %s AND %s", tableName, format(inPredicate, "col1"), format(inPredicate, "col2")), "VALUES (1, 10, 100)");
assertFilterPushdown(tableName, ImmutableMap.of("col1", multipleValues(BIGINT, values), "col2", multipleValues(BIGINT, values)), ImmutableMap.of("col2", multipleValues(BIGINT, values)), // Unenforced predicate is simplified during split generation, but not reflected here
ImmutableMap.of("col1", multipleValues(BIGINT, values)));
dropTable(tableName.getObjectName());
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class BaseIcebergConnectorTest method testLocalDynamicFilteringWithSelectiveBuildSizeJoin.
@Test
public void testLocalDynamicFilteringWithSelectiveBuildSizeJoin() {
long fullTableScan = (Long) computeActual("SELECT count(*) FROM lineitem").getOnlyValue();
// Pick a value for totalprice where file level stats will not be able to filter out any data
// This assumes the totalprice ranges in every file have some overlap, otherwise this test will fail.
MaterializedRow range = getOnlyElement(computeActual("SELECT max(lower_bounds[4]), min(upper_bounds[4]) FROM \"orders$files\"").getMaterializedRows());
double totalPrice = (Double) computeActual(format("SELECT totalprice FROM orders WHERE totalprice > %s AND totalprice < %s LIMIT 1", range.getField(0), range.getField(1))).getOnlyValue();
Session session = Session.builder(getSession()).setSystemProperty(JOIN_DISTRIBUTION_TYPE, BROADCAST.name()).build();
ResultWithQueryId<MaterializedResult> result = getDistributedQueryRunner().executeWithQueryId(session, "SELECT * FROM lineitem JOIN orders ON lineitem.orderkey = orders.orderkey AND orders.totalprice = " + totalPrice);
OperatorStats probeStats = searchScanFilterAndProjectOperatorStats(result.getQueryId(), new QualifiedObjectName(ICEBERG_CATALOG, "tpch", "lineitem"));
// Assert some lineitem rows were filtered out on file level
assertThat(probeStats.getInputPositions()).isLessThan(fullTableScan);
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class BaseIcebergConnectorTest method assertFilterPushdown.
private void assertFilterPushdown(QualifiedObjectName tableName, Map<String, Domain> filter, Map<String, Domain> expectedEnforcedPredicate, Map<String, Domain> expectedUnenforcedPredicate) {
Metadata metadata = getQueryRunner().getMetadata();
newTransaction().execute(getSession(), session -> {
TableHandle table = metadata.getTableHandle(session, tableName).orElseThrow(() -> new TableNotFoundException(tableName.asSchemaTableName()));
Map<String, ColumnHandle> columns = metadata.getColumnHandles(session, table);
TupleDomain<ColumnHandle> domains = TupleDomain.withColumnDomains(filter.entrySet().stream().collect(toImmutableMap(entry -> columns.get(entry.getKey()), Map.Entry::getValue)));
Optional<ConstraintApplicationResult<TableHandle>> result = metadata.applyFilter(session, table, new Constraint(domains));
assertTrue(result.isEmpty() == (expectedUnenforcedPredicate == null && expectedEnforcedPredicate == null));
if (result.isPresent()) {
IcebergTableHandle newTable = (IcebergTableHandle) result.get().getHandle().getConnectorHandle();
assertEquals(newTable.getEnforcedPredicate(), TupleDomain.withColumnDomains(expectedEnforcedPredicate.entrySet().stream().collect(toImmutableMap(entry -> columns.get(entry.getKey()), Map.Entry::getValue))));
assertEquals(newTable.getUnenforcedPredicate(), TupleDomain.withColumnDomains(expectedUnenforcedPredicate.entrySet().stream().collect(toImmutableMap(entry -> columns.get(entry.getKey()), Map.Entry::getValue))));
}
});
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestKuduIntegrationDynamicFilter method testIncompleteDynamicFilterTimeout.
@Test(timeOut = 30_000)
public void testIncompleteDynamicFilterTimeout() throws Exception {
QueryRunner runner = getQueryRunner();
TransactionManager transactionManager = runner.getTransactionManager();
TransactionId transactionId = transactionManager.beginTransaction(false);
Session session = Session.builder(getSession()).setCatalogSessionProperty("kudu", "dynamic_filtering_wait_timeout", "1s").build().beginTransactionId(transactionId, transactionManager, new AllowAllAccessControl());
QualifiedObjectName tableName = new QualifiedObjectName("kudu", "tpch", "orders");
Optional<TableHandle> tableHandle = runner.getMetadata().getTableHandle(session, tableName);
assertTrue(tableHandle.isPresent());
SplitSource splitSource = runner.getSplitManager().getSplits(session, tableHandle.get(), UNGROUPED_SCHEDULING, new IncompleteDynamicFilter(), alwaysTrue());
List<Split> splits = new ArrayList<>();
while (!splitSource.isFinished()) {
splits.addAll(splitSource.getNextBatch(NOT_PARTITIONED, Lifespan.taskWide(), 1000).get().getSplits());
}
splitSource.close();
assertFalse(splits.isEmpty());
}
Aggregations