use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class TableWriteInfo method createDeleteScanInfo.
private static Optional<DeleteScanInfo> createDeleteScanInfo(StreamingSubPlan plan, Optional<ExecutionWriterTarget> writerTarget, Metadata metadata, Session session) {
if (writerTarget.isPresent() && writerTarget.get() instanceof ExecutionWriterTarget.DeleteHandle) {
TableHandle tableHandle = ((ExecutionWriterTarget.DeleteHandle) writerTarget.get()).getHandle();
DeleteNode delete = getOnlyElement(findPlanNodes(plan, DeleteNode.class));
TableScanNode tableScan = getDeleteTableScan(delete);
TupleDomain<ColumnHandle> originalEnforcedConstraint = tableScan.getEnforcedConstraint();
TableLayoutResult layoutResult = metadata.getLayout(session, tableHandle, new Constraint<>(originalEnforcedConstraint), Optional.of(ImmutableSet.copyOf(tableScan.getAssignments().values())));
return Optional.of(new DeleteScanInfo(tableScan.getId(), layoutResult.getLayout().getNewTableHandle()));
}
return Optional.empty();
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class LogicalPlanner method createRefreshMaterializedViewPlan.
private RelationPlan createRefreshMaterializedViewPlan(Analysis analysis, RefreshMaterializedView refreshMaterializedViewStatement) {
Analysis.RefreshMaterializedViewAnalysis viewAnalysis = analysis.getRefreshMaterializedViewAnalysis().get();
TableHandle tableHandle = viewAnalysis.getTarget();
List<ColumnHandle> columnHandles = viewAnalysis.getColumns();
WriterTarget target = new RefreshMaterializedViewReference(tableHandle, metadata.getTableMetadata(session, tableHandle).getTable());
return buildInternalInsertPlan(tableHandle, columnHandles, viewAnalysis.getQuery(), analysis, target);
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class LogicalPlanner method createInsertPlan.
private RelationPlan createInsertPlan(Analysis analysis, Insert insertStatement) {
Analysis.Insert insertAnalysis = analysis.getInsert().get();
TableHandle tableHandle = insertAnalysis.getTarget();
List<ColumnHandle> columnHandles = insertAnalysis.getColumns();
WriterTarget target = new InsertReference(tableHandle, metadata.getTableMetadata(session, tableHandle).getTable());
return buildInternalInsertPlan(tableHandle, columnHandles, insertStatement.getQuery(), analysis, target);
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class LogicalPlanner method buildInternalInsertPlan.
private RelationPlan buildInternalInsertPlan(TableHandle tableHandle, List<ColumnHandle> columnHandles, Query query, Analysis analysis, WriterTarget target) {
TableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
List<ColumnMetadata> visibleTableColumns = tableMetadata.getColumns().stream().filter(column -> !column.isHidden()).collect(toImmutableList());
List<String> visibleTableColumnNames = visibleTableColumns.stream().map(ColumnMetadata::getName).collect(toImmutableList());
RelationPlan plan = createRelationPlan(analysis, query);
Map<String, ColumnHandle> columns = metadata.getColumnHandles(session, tableHandle);
Assignments.Builder assignments = Assignments.builder();
for (ColumnMetadata column : tableMetadata.getColumns()) {
if (column.isHidden()) {
continue;
}
VariableReferenceExpression output = variableAllocator.newVariable(getSourceLocation(query), column.getName(), column.getType());
int index = columnHandles.indexOf(columns.get(column.getName()));
if (index < 0) {
Expression cast = new Cast(new NullLiteral(), column.getType().getTypeSignature().toString());
assignments.put(output, castToRowExpression(cast));
} else {
VariableReferenceExpression input = plan.getVariable(index);
Type tableType = column.getType();
Type queryType = input.getType();
if (queryType.equals(tableType) || metadata.getFunctionAndTypeManager().isTypeOnlyCoercion(queryType, tableType)) {
assignments.put(output, castToRowExpression(createSymbolReference(input)));
} else {
Expression cast = new Cast(createSymbolReference(input), tableType.getTypeSignature().toString());
assignments.put(output, castToRowExpression(cast));
}
}
}
ProjectNode projectNode = new ProjectNode(idAllocator.getNextId(), plan.getRoot(), assignments.build());
List<Field> fields = visibleTableColumns.stream().map(column -> Field.newUnqualified(query.getLocation(), column.getName(), column.getType())).collect(toImmutableList());
Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields)).build();
plan = new RelationPlan(projectNode, scope, projectNode.getOutputVariables());
Optional<NewTableLayout> newTableLayout = metadata.getInsertLayout(session, tableHandle);
Optional<NewTableLayout> preferredShuffleLayout = metadata.getPreferredShuffleLayoutForInsert(session, tableHandle);
String catalogName = tableHandle.getConnectorId().getCatalogName();
TableStatisticsMetadata statisticsMetadata = metadata.getStatisticsCollectionMetadataForWrite(session, catalogName, tableMetadata.getMetadata());
return createTableWriterPlan(analysis, plan, target, visibleTableColumnNames, visibleTableColumns, newTableLayout, preferredShuffleLayout, statisticsMetadata);
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class TestDruidQueryBase method tableScan.
protected TableScanNode tableScan(PlanBuilder planBuilder, DruidTableHandle connectorTableHandle, DruidColumnHandle... columnHandles) {
List<VariableReferenceExpression> variables = Arrays.stream(columnHandles).map(ch -> new VariableReferenceExpression(Optional.empty(), ch.getColumnName().toLowerCase(ENGLISH), ch.getColumnType())).collect(toImmutableList());
ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> assignments = ImmutableMap.builder();
for (int i = 0; i < variables.size(); ++i) {
assignments.put(variables.get(i), columnHandles[i]);
}
TableHandle tableHandle = new TableHandle(druidConnectorId, connectorTableHandle, TestingTransactionHandle.create(), Optional.empty());
return new TableScanNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), tableHandle, variables, assignments.build(), TupleDomain.all(), TupleDomain.all());
}
Aggregations