use of com.facebook.presto.sql.tree.SymbolReference in project presto by prestodb.
the class SymbolAliases method get.
public SymbolReference get(String alias) {
alias = toKey(alias);
SymbolReference result = map.get(alias);
/*
* It's still kind of an open question if the right combination of anyTree() and
* a sufficiently complex and/or ambiguous plan might make throwing here a
* theoretically incorrect thing to do.
*
* If you run into a case that you think justifies changing this, please consider
* that it's already pretty hard to determine if a failure is because the test
* is written incorrectly or because the actual plan really doesn't match a
* correctly written test. Having this throw makes it a lot easier to track down
* missing aliases in incorrect plans.
*/
checkState(result != null, format("missing expression for alias %s", alias));
return result;
}
use of com.facebook.presto.sql.tree.SymbolReference in project presto by prestodb.
the class TestExpressionVerifier method test.
@Test
public void test() {
Expression actual = expression("NOT(orderkey = 3 AND custkey = 3 AND orderkey < 10)");
SymbolAliases symbolAliases = SymbolAliases.builder().put("X", new SymbolReference("orderkey")).put("Y", new SymbolReference("custkey")).build();
ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
assertTrue(verifier.process(actual, expression("NOT(X = 3 AND Y = 3 AND X < 10)")));
assertThrows(() -> verifier.process(actual, expression("NOT(X = 3 AND Y = 3 AND Z < 10)")));
assertFalse(verifier.process(actual, expression("NOT(X = 3 AND X = 3 AND X < 10)")));
}
use of com.facebook.presto.sql.tree.SymbolReference in project presto by prestodb.
the class TestCountConstantOptimizer method testCountConstantOptimizer.
@Test
public void testCountConstantOptimizer() throws Exception {
CountConstantOptimizer optimizer = new CountConstantOptimizer();
PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
Symbol countAggregationSymbol = new Symbol("count");
Signature countAggregationSignature = new Signature("count", FunctionKind.AGGREGATE, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT));
ImmutableMap<Symbol, FunctionCall> aggregations = ImmutableMap.of(countAggregationSymbol, new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new SymbolReference("expr"))));
ImmutableMap<Symbol, Signature> functions = ImmutableMap.of(countAggregationSymbol, countAggregationSignature);
ValuesNode valuesNode = new ValuesNode(planNodeIdAllocator.getNextId(), ImmutableList.of(new Symbol("col")), ImmutableList.of(ImmutableList.of()));
AggregationNode eligiblePlan = new AggregationNode(planNodeIdAllocator.getNextId(), new ProjectNode(planNodeIdAllocator.getNextId(), valuesNode, Assignments.of(new Symbol("expr"), new LongLiteral("42"))), aggregations, functions, ImmutableMap.of(), ImmutableList.of(ImmutableList.of()), AggregationNode.Step.INTERMEDIATE, Optional.empty(), Optional.empty());
assertTrue(((AggregationNode) optimizer.optimize(eligiblePlan, TEST_SESSION, ImmutableMap.of(), new SymbolAllocator(), new PlanNodeIdAllocator())).getAggregations().get(countAggregationSymbol).getArguments().isEmpty());
AggregationNode ineligiblePlan = new AggregationNode(planNodeIdAllocator.getNextId(), new ProjectNode(planNodeIdAllocator.getNextId(), valuesNode, Assignments.of(new Symbol("expr"), new FunctionCall(QualifiedName.of("function"), ImmutableList.of(new Identifier("x"))))), aggregations, functions, ImmutableMap.of(), ImmutableList.of(ImmutableList.of()), AggregationNode.Step.INTERMEDIATE, Optional.empty(), Optional.empty());
assertFalse(((AggregationNode) optimizer.optimize(ineligiblePlan, TEST_SESSION, ImmutableMap.of(), new SymbolAllocator(), new PlanNodeIdAllocator())).getAggregations().get(countAggregationSymbol).getArguments().isEmpty());
}
use of com.facebook.presto.sql.tree.SymbolReference in project presto by prestodb.
the class DomainTranslator method extractDisjuncts.
private static List<Expression> extractDisjuncts(Type type, DiscreteValues discreteValues, SymbolReference reference) {
List<Expression> values = discreteValues.getValues().stream().map(object -> toExpression(object, type)).collect(toList());
// If values is empty, then the equatableValues was either ALL or NONE, both of which should already have been checked for
checkState(!values.isEmpty());
Expression predicate;
if (values.size() == 1) {
predicate = new ComparisonExpression(EQUAL, reference, getOnlyElement(values));
} else {
predicate = new InPredicate(reference, new InListExpression(values));
}
if (!discreteValues.isWhiteList()) {
predicate = new NotExpression(predicate);
}
return ImmutableList.of(predicate);
}
use of com.facebook.presto.sql.tree.SymbolReference in project presto by prestodb.
the class DomainTranslator method toPredicate.
public static Expression toPredicate(TupleDomain<Symbol> tupleDomain) {
if (tupleDomain.isNone()) {
return FALSE_LITERAL;
}
ImmutableList.Builder<Expression> conjunctBuilder = ImmutableList.builder();
for (Map.Entry<Symbol, Domain> entry : tupleDomain.getDomains().get().entrySet()) {
Symbol symbol = entry.getKey();
SymbolReference reference = symbol.toSymbolReference();
conjunctBuilder.add(toPredicate(entry.getValue(), reference));
}
return combineConjuncts(conjunctBuilder.build());
}
Aggregations