Search in sources :

Example 16 with Aggregation

use of io.prestosql.spi.plan.AggregationNode.Aggregation in project hetu-core by openlookeng.

the class TestTypeValidator method testInvalidAggregationFunctionCall.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
public void testInvalidAggregationFunctionCall() {
    Symbol aggregationSymbol = planSymbolAllocator.newSymbol("sum", DOUBLE);
    PlanNode node = new AggregationNode(newId(), baseTableScan, ImmutableMap.of(aggregationSymbol, new Aggregation(new CallExpression("sum", SUM, DOUBLE, ImmutableList.of(castToRowExpression(toSymbolReference(columnA)))), ImmutableList.of(castToRowExpression(toSymbolReference(columnA))), false, Optional.empty(), Optional.empty(), Optional.empty())), singleGroupingSet(ImmutableList.of(columnA, columnB)), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty(), AggregationNode.AggregationType.HASH, Optional.empty());
    assertTypesValid(node);
}
Also used : Aggregation(io.prestosql.spi.plan.AggregationNode.Aggregation) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) AggregationNode(io.prestosql.spi.plan.AggregationNode) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 17 with Aggregation

use of io.prestosql.spi.plan.AggregationNode.Aggregation in project hetu-core by openlookeng.

the class AggregationFunctionMatcher method getAssignedSymbol.

@Override
public Optional<Symbol> getAssignedSymbol(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    Optional<Symbol> result = Optional.empty();
    if (!(node instanceof AggregationNode)) {
        return result;
    }
    AggregationNode aggregationNode = (AggregationNode) node;
    FunctionCall expectedCall = callMaker.getExpectedValue(symbolAliases);
    for (Map.Entry<Symbol, Aggregation> assignment : aggregationNode.getAggregations().entrySet()) {
        Aggregation aggregation = assignment.getValue();
        if (aggregationMatches(aggregation, expectedCall, metadata)) {
            checkState(!result.isPresent(), "Ambiguous function calls in %s", aggregationNode);
            result = Optional.of(assignment.getKey());
        }
    }
    return result;
}
Also used : Aggregation(io.prestosql.spi.plan.AggregationNode.Aggregation) Symbol(io.prestosql.spi.plan.Symbol) AggregationNode(io.prestosql.spi.plan.AggregationNode) FunctionCall(io.prestosql.sql.tree.FunctionCall) Map(java.util.Map)

Aggregations

Aggregation (io.prestosql.spi.plan.AggregationNode.Aggregation)17 AggregationNode (io.prestosql.spi.plan.AggregationNode)16 Symbol (io.prestosql.spi.plan.Symbol)16 Map (java.util.Map)12 CallExpression (io.prestosql.spi.relation.CallExpression)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 PlanNode (io.prestosql.spi.plan.PlanNode)8 ProjectNode (io.prestosql.spi.plan.ProjectNode)6 ImmutableList (com.google.common.collect.ImmutableList)5 RowExpression (io.prestosql.spi.relation.RowExpression)5 Optional (java.util.Optional)5 Set (java.util.Set)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Session (io.prestosql.Session)4 Assignments (io.prestosql.spi.plan.Assignments)4 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)4 Expression (io.prestosql.sql.tree.Expression)4 List (java.util.List)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 ImmutableSet (com.google.common.collect.ImmutableSet)3