use of io.trino.sql.tree.Expression in project trino by trinodb.
the class TestDynamicFilterService method testShortCircuitOnAllTupleDomain.
@Test
public void testShortCircuitOnAllTupleDomain() {
DynamicFilterService dynamicFilterService = createDynamicFilterService();
DynamicFilterId filterId1 = new DynamicFilterId("df1");
SymbolAllocator symbolAllocator = new SymbolAllocator();
Symbol symbol1 = symbolAllocator.newSymbol("DF_SYMBOL1", INTEGER);
Expression df1 = symbol1.toSymbolReference();
QueryId queryId = new QueryId("query");
StageId stageId1 = new StageId(queryId, 1);
dynamicFilterService.registerQuery(queryId, session, ImmutableSet.of(filterId1), ImmutableSet.of(filterId1), ImmutableSet.of());
dynamicFilterService.stageCannotScheduleMoreTasks(stageId1, 0, 2);
DynamicFilter dynamicFilter = dynamicFilterService.createDynamicFilter(queryId, ImmutableList.of(new DynamicFilters.Descriptor(filterId1, df1)), ImmutableMap.of(symbol1, new TestingColumnHandle("probeColumnA")), symbolAllocator.getTypes());
// dynamic filter is initially blocked
assertTrue(dynamicFilter.getCurrentPredicate().isAll());
assertFalse(dynamicFilter.isComplete());
assertFalse(dynamicFilter.isBlocked().isDone());
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId1, 1, 0), ImmutableMap.of(filterId1, Domain.all(INTEGER)));
// dynamic filter should be unblocked and completed
assertTrue(dynamicFilter.getCurrentPredicate().isAll());
assertTrue(dynamicFilter.isComplete());
assertTrue(dynamicFilter.isBlocked().isDone());
}
use of io.trino.sql.tree.Expression in project trino by trinodb.
the class ExpressionVerifier method visitInPredicate.
@Override
protected Boolean visitInPredicate(InPredicate actual, Node expectedExpression) {
if (!(expectedExpression instanceof InPredicate)) {
return false;
}
InPredicate expected = (InPredicate) expectedExpression;
if (actual.getValueList() instanceof InListExpression || !(expected.getValueList() instanceof InListExpression)) {
return process(actual.getValue(), expected.getValue()) && process(actual.getValueList(), expected.getValueList());
}
/*
* In some cases, actual.getValueList() and expected.getValueList() might be of different types,
* although they originated from identical single-element InListExpression.
*
* This happens because actual passes through the analyzer, planner, and possibly optimizers,
* one of which sometimes takes the liberty of unpacking the InListExpression.
*
* Since the expected value doesn't go through all of that, we have to deal with the case
* of the actual value being unpacked, but the expected value being an InListExpression.
*
* If the expected value is a value list, but the actual is e.g. a SymbolReference,
* we need to unpack the value from the list to enable comparison: so that when we hit
* visitSymbolReference, the expected.toString() call returns something that the symbolAliases
* actually contains.
* For example, InListExpression.toString returns "(onlyitem)" rather than "onlyitem".
*/
List<Expression> values = ((InListExpression) expected.getValueList()).getValues();
checkState(values.size() == 1, "Multiple expressions in expected value list %s, but actual value is not a list", values, actual.getValue());
Expression onlyExpectedExpression = values.get(0);
return process(actual.getValue(), expected.getValue()) && process(actual.getValueList(), onlyExpectedExpression);
}
use of io.trino.sql.tree.Expression in project trino by trinodb.
the class FilterMatcher 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());
FilterNode filterNode = (FilterNode) node;
Expression filterPredicate = filterNode.getPredicate();
ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
if (dynamicFilter.isPresent()) {
return new MatchResult(verifier.process(filterPredicate, combineConjuncts(metadata, predicate, dynamicFilter.get())));
}
DynamicFilters.ExtractResult extractResult = extractDynamicFilters(filterPredicate);
return new MatchResult(verifier.process(combineConjuncts(metadata, extractResult.getStaticConjuncts()), predicate));
}
use of io.trino.sql.tree.Expression in project trino by trinodb.
the class FunctionCallProvider method getExpectedValue.
@Override
public FunctionCall getExpectedValue(SymbolAliases aliases) {
List<Expression> symbolReferences = toSymbolReferences(args, aliases);
if (isWindowFunction) {
verify(!distinct, "window does not support distinct");
verify(orderBy.isEmpty(), "window does not support order by");
return new ExpectedWindowFunctionCall(symbolReferences);
}
Optional<OrderBy> orderByClause = Optional.empty();
if (!orderBy.isEmpty()) {
orderByClause = Optional.of(new OrderBy(orderBy.stream().map(item -> new SortItem(Symbol.from(aliases.get(item.getField())).toSymbolReference(), item.getOrdering(), item.getNullOrdering())).collect(Collectors.toList())));
}
return new FunctionCall(Optional.empty(), name, Optional.empty(), filter.map(symbol -> symbol.toSymbol(aliases).toSymbolReference()), orderByClause, distinct, Optional.empty(), Optional.empty(), symbolReferences);
}
use of io.trino.sql.tree.Expression in project trino by trinodb.
the class PatternRecognitionExpressionRewriter method rewrite.
public static ExpressionAndValuePointers rewrite(Expression definition, Map<IrLabel, Set<IrLabel>> subsets) {
Expression expression = rewriteIdentifiers(definition);
Map<Symbol, Type> types = extractExpressions(ImmutableList.of(expression), SymbolReference.class).stream().collect(toImmutableMap(Symbol::from, reference -> BIGINT));
return LogicalIndexExtractor.rewrite(expression, subsets, new SymbolAllocator(types), createTestMetadataManager());
}
Aggregations