use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class TestEffectivePredicateExtractor method testInnerJoin.
@Test
public void testInnerJoin() {
ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
criteriaBuilder.add(new JoinNode.EquiJoinClause(AV, DV));
criteriaBuilder.add(new JoinNode.EquiJoinClause(BV, EV));
List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
Map<VariableReferenceExpression, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(AV, BV, CV)));
TableScanNode leftScan = tableScanNode(leftAssignments);
Map<VariableReferenceExpression, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(DV, EV, FV)));
TableScanNode rightScan = tableScanNode(rightAssignments);
FilterNode left = filter(leftScan, and(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), equals(GV, bigintLiteral(10))));
FilterNode right = filter(rightScan, and(equals(DV, EV), lessThan(FV, bigintLiteral(100))));
PlanNode node = new JoinNode(Optional.empty(), newId(), JoinNode.Type.INNER, left, right, criteria, ImmutableList.<VariableReferenceExpression>builder().addAll(left.getOutputVariables()).addAll(right.getOutputVariables()).build(), Optional.of(lessThanOrEqual(BV, EV)), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// All predicates having output symbol should be carried through
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), equals(DV, EV), lessThan(FV, bigintLiteral(100)), equals(AV, DV), equals(BV, EV), lessThanOrEqual(BV, EV)));
}
use of com.facebook.presto.spi.ColumnHandle 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.ColumnHandle 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.ColumnHandle 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.ColumnHandle 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);
}
Aggregations