use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestIcebergProjectionPushdownPlans method testDereferencePushdown.
@Test
public void testDereferencePushdown() {
String testTable = "test_simple_projection_pushdown" + randomTableSuffix();
QualifiedObjectName completeTableName = new QualifiedObjectName(CATALOG, SCHEMA, testTable);
getQueryRunner().execute(format("CREATE TABLE %s (col0, col1) WITH (partitioning = ARRAY['col1']) AS" + " SELECT CAST(row(5, 6) AS row(x bigint, y bigint)) AS col0, 5 AS col1 WHERE false", testTable));
Session session = getQueryRunner().getDefaultSession();
Optional<TableHandle> tableHandle = getTableHandle(session, completeTableName);
assertTrue(tableHandle.isPresent(), "expected the table handle to be present");
Map<String, ColumnHandle> columns = getColumnHandles(session, completeTableName);
IcebergColumnHandle column0Handle = (IcebergColumnHandle) columns.get("col0");
IcebergColumnHandle column1Handle = (IcebergColumnHandle) columns.get("col1");
IcebergColumnHandle columnX = new IcebergColumnHandle(column0Handle.getColumnIdentity(), column0Handle.getType(), ImmutableList.of(column0Handle.getColumnIdentity().getChildren().get(0).getId()), BIGINT, Optional.empty());
IcebergColumnHandle columnY = new IcebergColumnHandle(column0Handle.getColumnIdentity(), column0Handle.getType(), ImmutableList.of(column0Handle.getColumnIdentity().getChildren().get(1).getId()), BIGINT, Optional.empty());
// Simple Projection pushdown
assertPlan("SELECT col0.x expr_x, col0.y expr_y FROM " + testTable, any(tableScan(equalTo(((IcebergTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(Set.of(columnX, columnY))), TupleDomain.all(), ImmutableMap.of("col0#x", equalTo(columnX), "col0#y", equalTo(columnY)))));
// Projection and predicate pushdown
assertPlan(format("SELECT col0.x FROM %s WHERE col0.x = col1 + 3 and col0.y = 2", testTable), anyTree(filter("y = BIGINT '2' AND (x = CAST((col1 + 3) AS BIGINT))", tableScan(table -> {
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) table;
TupleDomain<IcebergColumnHandle> unenforcedConstraint = icebergTableHandle.getUnenforcedPredicate();
return icebergTableHandle.getProjectedColumns().equals(ImmutableSet.of(column1Handle, columnX, columnY)) && unenforcedConstraint.equals(TupleDomain.withColumnDomains(ImmutableMap.of(columnY, Domain.singleValue(BIGINT, 2L))));
}, TupleDomain.all(), ImmutableMap.of("y", equalTo(columnY), "x", equalTo(columnX), "col1", equalTo(column1Handle))))));
// Projection and predicate pushdown with overlapping columns
assertPlan(format("SELECT col0, col0.y expr_y FROM %s WHERE col0.x = 5", testTable), anyTree(filter("x = BIGINT '5'", tableScan(table -> {
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) table;
TupleDomain<IcebergColumnHandle> unenforcedConstraint = icebergTableHandle.getUnenforcedPredicate();
return icebergTableHandle.getProjectedColumns().equals(ImmutableSet.of(column0Handle, columnX)) && unenforcedConstraint.equals(TupleDomain.withColumnDomains(ImmutableMap.of(columnX, Domain.singleValue(BIGINT, 5L))));
}, TupleDomain.all(), ImmutableMap.of("col0", equalTo(column0Handle), "x", equalTo(columnX))))));
// Projection and predicate pushdown with joins
assertPlan(format("SELECT T.col0.x, T.col0, T.col0.y FROM %s T join %s S on T.col1 = S.col1 WHERE (T.col0.x = 2)", testTable, testTable), anyTree(project(ImmutableMap.of("expr_0_x", expression("expr_0[1]"), "expr_0", expression("expr_0"), "expr_0_y", expression("expr_0[2]")), join(INNER, ImmutableList.of(equiJoinClause("t_expr_1", "s_expr_1")), anyTree(filter("x = BIGINT '2'", tableScan(table -> {
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) table;
TupleDomain<IcebergColumnHandle> unenforcedConstraint = icebergTableHandle.getUnenforcedPredicate();
Set<IcebergColumnHandle> expectedProjections = ImmutableSet.of(column0Handle, column1Handle, columnX);
TupleDomain<IcebergColumnHandle> expectedUnenforcedConstraint = TupleDomain.withColumnDomains(ImmutableMap.of(columnX, Domain.singleValue(BIGINT, 2L)));
return icebergTableHandle.getProjectedColumns().equals(expectedProjections) && unenforcedConstraint.equals(expectedUnenforcedConstraint);
}, TupleDomain.all(), ImmutableMap.of("x", equalTo(columnX), "expr_0", equalTo(column0Handle), "t_expr_1", equalTo(column1Handle))))), anyTree(tableScan(equalTo(((IcebergTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(Set.of(column1Handle))), TupleDomain.all(), ImmutableMap.of("s_expr_1", equalTo(column1Handle))))))));
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestIcebergMetadataListing method getStorageTable.
private SchemaTableName getStorageTable(String catalogName, String schemaName, String objectName) {
TransactionManager transactionManager = getQueryRunner().getTransactionManager();
TransactionId transactionId = transactionManager.beginTransaction(false);
Session session = getSession().beginTransactionId(transactionId, transactionManager, getQueryRunner().getAccessControl());
Optional<MaterializedViewDefinition> materializedView = getQueryRunner().getMetadata().getMaterializedView(session, new QualifiedObjectName(catalogName, schemaName, objectName));
assertThat(materializedView).isPresent();
return materializedView.get().getStorageTable().get().getSchemaTableName();
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestIcebergMaterializedViews method getStorageTable.
private SchemaTableName getStorageTable(String catalogName, String schemaName, String objectName) {
TransactionManager transactionManager = getQueryRunner().getTransactionManager();
TransactionId transactionId = transactionManager.beginTransaction(false);
Session session = getSession().beginTransactionId(transactionId, transactionManager, getQueryRunner().getAccessControl());
Optional<MaterializedViewDefinition> materializedView = getQueryRunner().getMetadata().getMaterializedView(session, new QualifiedObjectName(catalogName, schemaName, objectName));
assertThat(materializedView).isPresent();
return materializedView.get().getStorageTable().get().getSchemaTableName();
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestMinimalFunctionality method testStreamExists.
@Test
public void testStreamExists() {
QualifiedObjectName name = new QualifiedObjectName("kinesis", "default", streamName);
transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()).singleStatement().execute(SESSION, session -> {
Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
assertTrue(handle.isPresent());
});
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestRecordAccess method testStreamExists.
@Test
public void testStreamExists() {
QualifiedObjectName name = new QualifiedObjectName("kinesis", "default", dummyStreamName);
transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()).singleStatement().execute(SESSION, session -> {
Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
assertTrue(handle.isPresent());
});
log.info("Completed first test (access table handle)");
}
Aggregations