use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class LogicalPlanner method createTableCreationPlan.
private RelationPlan createTableCreationPlan(Analysis analysis, Query query) {
Analysis.Create create = analysis.getCreate().orElseThrow();
QualifiedObjectName destination = create.getDestination().orElseThrow();
RelationPlan plan = createRelationPlan(analysis, query);
if (!create.isCreateTableAsSelectWithData()) {
PlanNode root = new LimitNode(idAllocator.getNextId(), plan.getRoot(), 0L, false);
plan = new RelationPlan(root, plan.getScope(), plan.getFieldMappings(), Optional.empty());
}
ConnectorTableMetadata tableMetadata = create.getMetadata().orElseThrow();
Optional<TableLayout> newTableLayout = create.getLayout();
List<String> columnNames = tableMetadata.getColumns().stream().filter(// todo this filter is redundant
column -> !column.isHidden()).map(ColumnMetadata::getName).collect(toImmutableList());
TableStatisticsMetadata statisticsMetadata = metadata.getStatisticsCollectionMetadataForWrite(session, destination.getCatalogName(), tableMetadata);
return createTableWriterPlan(analysis, plan.getRoot(), visibleFields(plan), new CreateReference(destination.getCatalogName(), tableMetadata, newTableLayout), columnNames, tableMetadata.getColumns(), newTableLayout, statisticsMetadata);
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestHiveProjectionPushdownIntoTableScan method testDereferencePushdown.
@Test
public void testDereferencePushdown() {
String testTable = "test_simple_projection_pushdown";
QualifiedObjectName completeTableName = new QualifiedObjectName(HIVE_CATALOG_NAME, SCHEMA_NAME, testTable);
getQueryRunner().execute(format("CREATE TABLE %s (col0, 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);
HiveColumnHandle column0Handle = (HiveColumnHandle) columns.get("col0");
HiveColumnHandle column1Handle = (HiveColumnHandle) columns.get("col1");
HiveColumnHandle columnX = createProjectedColumnHandle(column0Handle, ImmutableList.of(0));
HiveColumnHandle columnY = createProjectedColumnHandle(column0Handle, ImmutableList.of(1));
// Simple Projection pushdown
assertPlan("SELECT col0.x expr_x, col0.y expr_y FROM " + testTable, any(tableScan(((HiveTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(ImmutableSet.of(columnX, columnY))::equals, TupleDomain.all(), ImmutableMap.of("col0#x", columnX::equals, "col0#y", columnY::equals))));
// Projection and predicate pushdown
assertPlan(format("SELECT col0.x FROM %s WHERE col0.x = col1 + 3 and col0.y = 2", testTable), anyTree(filter("col0_y = BIGINT '2' AND (col0_x = cast((col1 + 3) as BIGINT))", tableScan(table -> {
HiveTableHandle hiveTableHandle = (HiveTableHandle) table;
return hiveTableHandle.getCompactEffectivePredicate().equals(TupleDomain.withColumnDomains(ImmutableMap.of(columnY, Domain.singleValue(BIGINT, 2L)))) && hiveTableHandle.getProjectedColumns().equals(ImmutableSet.of(column1Handle, columnX, columnY));
}, TupleDomain.all(), ImmutableMap.of("col0_y", columnY::equals, "col0_x", columnX::equals, "col1", column1Handle::equals)))));
// Projection and predicate pushdown with overlapping columns
assertPlan(format("SELECT col0, col0.y expr_y FROM %s WHERE col0.x = 5", testTable), anyTree(filter("col0_x = BIGINT '5'", tableScan(table -> {
HiveTableHandle hiveTableHandle = (HiveTableHandle) table;
return hiveTableHandle.getCompactEffectivePredicate().equals(TupleDomain.withColumnDomains(ImmutableMap.of(columnX, Domain.singleValue(BIGINT, 5L)))) && hiveTableHandle.getProjectedColumns().equals(ImmutableSet.of(column0Handle, columnX));
}, TupleDomain.all(), ImmutableMap.of("col0", column0Handle::equals, "col0_x", columnX::equals)))));
// 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("expr_0_x = BIGINT '2'", tableScan(table -> ((HiveTableHandle) table).getCompactEffectivePredicate().getDomains().get().equals(ImmutableMap.of(columnX, Domain.singleValue(BIGINT, 2L))), TupleDomain.all(), ImmutableMap.of("expr_0_x", columnX::equals, "expr_0", column0Handle::equals, "t_expr_1", column1Handle::equals)))), anyTree(tableScan(((HiveTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(ImmutableSet.of(column1Handle))::equals, TupleDomain.all(), ImmutableMap.of("s_expr_1", column1Handle::equals)))))));
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestCreateViewTask method setUp.
@Override
@BeforeMethod
public void setUp() {
super.setUp();
parser = new SqlParser();
analyzerFactory = new AnalyzerFactory(createTestingStatementAnalyzerFactory(plannerContext, new AllowAllAccessControl(), new TablePropertyManager(), new AnalyzePropertyManager()), new StatementRewrite(ImmutableSet.of()));
QualifiedObjectName tableName = qualifiedObjectName("mock_table");
metadata.createTable(testSession, CATALOG_NAME, someTable(tableName), false);
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestCreateViewTask method testCreateViewOnMaterializedView.
@Test
public void testCreateViewOnMaterializedView() {
QualifiedObjectName viewName = qualifiedObjectName("existing_materialized_view");
metadata.createMaterializedView(testSession, viewName, someMaterializedView(), false, false);
assertTrinoExceptionThrownBy(() -> getFutureValue(executeCreateView(asQualifiedName(viewName), false))).hasErrorCode(TABLE_ALREADY_EXISTS).hasMessage("Materialized view already exists: '%s'", viewName);
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestCreateViewTask method testCreateViewOnViewIfExists.
@Test
public void testCreateViewOnViewIfExists() {
QualifiedObjectName viewName = qualifiedObjectName("existing_view");
metadata.createView(testSession, viewName, someView(), false);
assertTrinoExceptionThrownBy(() -> getFutureValue(executeCreateView(asQualifiedName(viewName), false))).hasErrorCode(TABLE_ALREADY_EXISTS).hasMessage("View already exists: '%s'", viewName);
}
Aggregations