Search in sources :

Example 6 with RelationType

use of com.facebook.presto.sql.analyzer.RelationType in project presto by prestodb.

the class QueryPlanner method plan.

public DeleteNode plan(Delete node) {
    RelationType descriptor = analysis.getOutputDescriptor(node.getTable());
    TableHandle handle = analysis.getTableHandle(node.getTable());
    ColumnHandle rowIdHandle = metadata.getUpdateRowIdColumnHandle(session, handle);
    Type rowIdType = metadata.getColumnMetadata(session, handle, rowIdHandle).getType();
    // add table columns
    ImmutableList.Builder<Symbol> outputSymbols = ImmutableList.builder();
    ImmutableMap.Builder<Symbol, ColumnHandle> columns = ImmutableMap.builder();
    ImmutableList.Builder<Field> fields = ImmutableList.builder();
    for (Field field : descriptor.getAllFields()) {
        Symbol symbol = symbolAllocator.newSymbol(field.getName().get(), field.getType());
        outputSymbols.add(symbol);
        columns.put(symbol, analysis.getColumn(field));
        fields.add(field);
    }
    // add rowId column
    Field rowIdField = Field.newUnqualified(Optional.empty(), rowIdType);
    Symbol rowIdSymbol = symbolAllocator.newSymbol("$rowId", rowIdField.getType());
    outputSymbols.add(rowIdSymbol);
    columns.put(rowIdSymbol, rowIdHandle);
    fields.add(rowIdField);
    // create table scan
    PlanNode tableScan = new TableScanNode(idAllocator.getNextId(), handle, outputSymbols.build(), columns.build(), Optional.empty(), TupleDomain.all(), null);
    Scope scope = Scope.builder().withRelationType(new RelationType(fields.build())).build();
    RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputSymbols.build());
    TranslationMap translations = new TranslationMap(relationPlan, analysis, lambdaDeclarationToSymbolMap);
    translations.setFieldMappings(relationPlan.getFieldMappings());
    PlanBuilder builder = new PlanBuilder(translations, relationPlan.getRoot(), analysis.getParameters());
    if (node.getWhere().isPresent()) {
        builder = filter(builder, node.getWhere().get(), node);
    }
    // create delete node
    Symbol rowId = builder.translate(new FieldReference(relationPlan.getDescriptor().indexOf(rowIdField)));
    List<Symbol> outputs = ImmutableList.of(symbolAllocator.newSymbol("partialrows", BIGINT), symbolAllocator.newSymbol("fragment", VARBINARY));
    return new DeleteNode(idAllocator.getNextId(), builder.getRoot(), new DeleteHandle(handle, metadata.getTableMetadata(session, handle).getTable()), rowId, outputs);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) FieldReference(com.facebook.presto.sql.tree.FieldReference) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Field(com.facebook.presto.sql.analyzer.Field) DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) Type(com.facebook.presto.spi.type.Type) RelationType(com.facebook.presto.sql.analyzer.RelationType) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) Scope(com.facebook.presto.sql.analyzer.Scope) RelationType(com.facebook.presto.sql.analyzer.RelationType) DeleteHandle(com.facebook.presto.sql.planner.plan.TableWriterNode.DeleteHandle) TableHandle(com.facebook.presto.metadata.TableHandle)

Example 7 with RelationType

use of com.facebook.presto.sql.analyzer.RelationType in project presto by prestodb.

the class LogicalPlanner method createOutputPlan.

private PlanNode createOutputPlan(RelationPlan plan, Analysis analysis) {
    ImmutableList.Builder<Symbol> outputs = ImmutableList.builder();
    ImmutableList.Builder<String> names = ImmutableList.builder();
    int columnNumber = 0;
    RelationType outputDescriptor = analysis.getOutputDescriptor();
    for (Field field : outputDescriptor.getVisibleFields()) {
        String name = field.getName().orElse("_col" + columnNumber);
        names.add(name);
        int fieldIndex = outputDescriptor.indexOf(field);
        Symbol symbol = plan.getSymbol(fieldIndex);
        outputs.add(symbol);
        columnNumber++;
    }
    return new OutputNode(idAllocator.getNextId(), plan.getRoot(), names.build(), outputs.build());
}
Also used : Field(com.facebook.presto.sql.analyzer.Field) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RelationType(com.facebook.presto.sql.analyzer.RelationType)

Aggregations

RelationType (com.facebook.presto.sql.analyzer.RelationType)7 ImmutableList (com.google.common.collect.ImmutableList)7 Field (com.facebook.presto.sql.analyzer.Field)6 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)6 Type (com.facebook.presto.spi.type.Type)5 Expression (com.facebook.presto.sql.tree.Expression)5 ExpressionInterpreter.evaluateConstantExpression (com.facebook.presto.sql.planner.ExpressionInterpreter.evaluateConstantExpression)4 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)4 ProjectNode (com.facebook.presto.sql.planner.plan.ProjectNode)4 CoalesceExpression (com.facebook.presto.sql.tree.CoalesceExpression)4 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)4 ComparisonExpressionType (com.facebook.presto.sql.tree.ComparisonExpressionType)4 ArrayList (java.util.ArrayList)4 ColumnHandle (com.facebook.presto.spi.ColumnHandle)3 Scope (com.facebook.presto.sql.analyzer.Scope)3 Assignments (com.facebook.presto.sql.planner.plan.Assignments)3 Session (com.facebook.presto.Session)2 Metadata (com.facebook.presto.metadata.Metadata)2 TableHandle (com.facebook.presto.metadata.TableHandle)2 Analysis (com.facebook.presto.sql.analyzer.Analysis)2