Search in sources :

Example 1 with ValuesNode

use of com.facebook.presto.spi.plan.ValuesNode in project presto by prestodb.

the class TestWindowNode method setUp.

@BeforeClass
public void setUp() {
    variableAllocator = new PlanVariableAllocator();
    columnA = variableAllocator.newVariable("a", BIGINT);
    columnB = variableAllocator.newVariable("b", BIGINT);
    columnC = variableAllocator.newVariable("c", BIGINT);
    sourceNode = new ValuesNode(Optional.empty(), newId(), ImmutableList.of(columnA, columnB, columnC), ImmutableList.of());
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with ValuesNode

use of com.facebook.presto.spi.plan.ValuesNode in project presto by prestodb.

the class TestVerifyOnlyOneOutputNode method testValidateFailed.

@Test(expectedExceptions = IllegalStateException.class)
public void testValidateFailed() {
    // random plan with 2 output nodes
    PlanNode root = new OutputNode(Optional.empty(), idAllocator.getNextId(), new ExplainAnalyzeNode(Optional.empty(), idAllocator.getNextId(), new OutputNode(Optional.empty(), idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(Optional.empty(), idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of()), new VariableReferenceExpression(Optional.empty(), "a", BIGINT), false), ImmutableList.of(), ImmutableList.of());
    new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP);
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) ExplainAnalyzeNode(com.facebook.presto.sql.planner.plan.ExplainAnalyzeNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 3 with ValuesNode

use of com.facebook.presto.spi.plan.ValuesNode in project presto by prestodb.

the class PruneValuesColumns method pushDownProjectOff.

@Override
protected Optional<PlanNode> pushDownProjectOff(PlanNodeIdAllocator idAllocator, PlanVariableAllocator variableAllocator, ValuesNode valuesNode, Set<VariableReferenceExpression> referencedOutputs) {
    List<VariableReferenceExpression> newOutputs = filteredCopy(valuesNode.getOutputVariables(), referencedOutputs::contains);
    List<VariableReferenceExpression> newOutputVariables = filteredCopy(valuesNode.getOutputVariables(), referencedOutputs::contains);
    // for each output of project, the corresponding column in the values node
    int[] mapping = new int[newOutputs.size()];
    for (int i = 0; i < mapping.length; i++) {
        mapping[i] = valuesNode.getOutputVariables().indexOf(newOutputs.get(i));
    }
    ImmutableList.Builder<List<RowExpression>> rowsBuilder = ImmutableList.builder();
    for (List<RowExpression> row : valuesNode.getRows()) {
        rowsBuilder.add(Arrays.stream(mapping).mapToObj(row::get).collect(Collectors.toList()));
    }
    return Optional.of(new ValuesNode(valuesNode.getSourceLocation(), valuesNode.getId(), newOutputVariables, rowsBuilder.build()));
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ImmutableList(com.google.common.collect.ImmutableList) RowExpression(com.facebook.presto.spi.relation.RowExpression) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 4 with ValuesNode

use of com.facebook.presto.spi.plan.ValuesNode in project presto by prestodb.

the class RelationPlanner method visitValues.

@Override
protected RelationPlan visitValues(Values node, Void context) {
    Scope scope = analysis.getScope(node);
    ImmutableList.Builder<VariableReferenceExpression> outputVariablesBuilder = ImmutableList.builder();
    for (Field field : scope.getRelationType().getVisibleFields()) {
        outputVariablesBuilder.add(variableAllocator.newVariable(field));
    }
    ImmutableList.Builder<List<RowExpression>> rowsBuilder = ImmutableList.builder();
    for (Expression row : node.getRows()) {
        ImmutableList.Builder<RowExpression> values = ImmutableList.builder();
        if (row instanceof Row) {
            for (Expression item : ((Row) row).getItems()) {
                values.add(rewriteRow(item));
            }
        } else {
            values.add(rewriteRow(row));
        }
        rowsBuilder.add(values.build());
    }
    ValuesNode valuesNode = new ValuesNode(getSourceLocation(node), idAllocator.getNextId(), outputVariablesBuilder.build(), rowsBuilder.build());
    return new RelationPlan(valuesNode, scope, outputVariablesBuilder.build());
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) Field(com.facebook.presto.sql.analyzer.Field) Scope(com.facebook.presto.sql.analyzer.Scope) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) ExpressionTreeUtils.isEqualComparisonExpression(com.facebook.presto.sql.analyzer.ExpressionTreeUtils.isEqualComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Row(com.facebook.presto.sql.tree.Row)

Example 5 with ValuesNode

use of com.facebook.presto.spi.plan.ValuesNode in project presto by prestodb.

the class ValuesMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    ValuesNode valuesNode = (ValuesNode) node;
    if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows().stream().map(rowExpressions -> rowExpressions.stream().map(rowExpression -> {
        if (isExpression(rowExpression)) {
            return castToExpression(rowExpression);
        }
        ConstantExpression expression = (ConstantExpression) rowExpression;
        if (expression.getType().getJavaType() == boolean.class) {
            return new BooleanLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == long.class) {
            return new LongLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == double.class) {
            return new DoubleLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == Slice.class) {
            return new StringLiteral(((Slice) expression.getValue()).toStringUtf8());
        }
        return new GenericLiteral(expression.getType().toString(), String.valueOf(expression.getValue()));
    }).collect(toImmutableList())).collect(toImmutableSet()))).orElse(true)) {
        return NO_MATCH;
    }
    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> createSymbolReference(valuesNode.getOutputVariables().get(index)))).build());
}
Also used : Slice(io.airlift.slice.Slice) OriginalExpressionUtils.isExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.isExpression) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) OriginalExpressionUtils.castToExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression) DoubleLiteral(com.facebook.presto.sql.tree.DoubleLiteral) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StatsProvider(com.facebook.presto.cost.StatsProvider) Set(java.util.Set) Maps(com.google.common.collect.Maps) Preconditions.checkState(com.google.common.base.Preconditions.checkState) BooleanLiteral(com.facebook.presto.sql.tree.BooleanLiteral) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) GenericLiteral(com.facebook.presto.sql.tree.GenericLiteral) Expression(com.facebook.presto.sql.tree.Expression) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) Metadata(com.facebook.presto.metadata.Metadata) ExpressionTreeUtils.createSymbolReference(com.facebook.presto.sql.analyzer.ExpressionTreeUtils.createSymbolReference) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) BooleanLiteral(com.facebook.presto.sql.tree.BooleanLiteral) Slice(io.airlift.slice.Slice) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) DoubleLiteral(com.facebook.presto.sql.tree.DoubleLiteral) GenericLiteral(com.facebook.presto.sql.tree.GenericLiteral)

Aggregations

ValuesNode (com.facebook.presto.spi.plan.ValuesNode)18 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)13 Test (org.testng.annotations.Test)8 PlanNode (com.facebook.presto.spi.plan.PlanNode)7 RowExpression (com.facebook.presto.spi.relation.RowExpression)6 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)6 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)5 MultiJoinNode (com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)5 MultiJoinNode.toMultiJoinNode (com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode)5 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)5 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Map (java.util.Map)4 Session (com.facebook.presto.Session)3 OutputNode (com.facebook.presto.sql.planner.plan.OutputNode)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Capture (com.facebook.presto.matching.Capture)2 Capture.newCapture (com.facebook.presto.matching.Capture.newCapture)2 Captures (com.facebook.presto.matching.Captures)2