use of io.trino.metadata.Metadata in project trino by trinodb.
the class PatternRecognitionMatcher 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());
PatternRecognitionNode patternRecognitionNode = (PatternRecognitionNode) node;
boolean specificationMatches = specification.map(expected -> expected.getExpectedValue(symbolAliases).equals(patternRecognitionNode.getSpecification())).orElse(true);
if (!specificationMatches) {
return NO_MATCH;
}
if (frame.isPresent()) {
if (patternRecognitionNode.getCommonBaseFrame().isEmpty()) {
return NO_MATCH;
}
if (!frame.get().getExpectedValue(symbolAliases).equals(patternRecognitionNode.getCommonBaseFrame().get())) {
return NO_MATCH;
}
}
if (rowsPerMatch != patternRecognitionNode.getRowsPerMatch()) {
return NO_MATCH;
}
if (!skipToLabel.equals(patternRecognitionNode.getSkipToLabel())) {
return NO_MATCH;
}
if (skipToPosition != patternRecognitionNode.getSkipToPosition()) {
return NO_MATCH;
}
if (initial != patternRecognitionNode.isInitial()) {
return NO_MATCH;
}
if (!pattern.equals(patternRecognitionNode.getPattern())) {
return NO_MATCH;
}
if (!subsets.equals(patternRecognitionNode.getSubsets())) {
return NO_MATCH;
}
if (variableDefinitions.size() != patternRecognitionNode.getVariableDefinitions().size()) {
return NO_MATCH;
}
for (Map.Entry<IrLabel, ExpressionAndValuePointers> entry : variableDefinitions.entrySet()) {
IrLabel name = entry.getKey();
ExpressionAndValuePointers actual = patternRecognitionNode.getVariableDefinitions().get(name);
if (actual == null) {
return NO_MATCH;
}
ExpressionAndValuePointers expected = entry.getValue();
ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
if (!ExpressionAndValuePointersEquivalence.equivalent(actual, expected, (actualSymbol, expectedSymbol) -> verifier.process(actualSymbol.toSymbolReference(), expectedSymbol.toSymbolReference()))) {
return NO_MATCH;
}
}
return match();
}
use of io.trino.metadata.Metadata in project trino by trinodb.
the class SemiJoinMatcher 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());
SemiJoinNode semiJoinNode = (SemiJoinNode) node;
if (!(symbolAliases.get(sourceSymbolAlias).equals(semiJoinNode.getSourceJoinSymbol().toSymbolReference()) && symbolAliases.get(filteringSymbolAlias).equals(semiJoinNode.getFilteringSourceJoinSymbol().toSymbolReference()))) {
return NO_MATCH;
}
if (distributionType.isPresent() && !distributionType.equals(semiJoinNode.getDistributionType())) {
return NO_MATCH;
}
if (hasDynamicFilter.isPresent()) {
if (hasDynamicFilter.get()) {
if (semiJoinNode.getDynamicFilterId().isEmpty()) {
return NO_MATCH;
}
DynamicFilterId dynamicFilterId = semiJoinNode.getDynamicFilterId().get();
List<DynamicFilters.Descriptor> matchingDescriptors = searchFrom(semiJoinNode.getSource()).where(FilterNode.class::isInstance).findAll().stream().flatMap(filterNode -> extractExpressions(filterNode).stream()).flatMap(expression -> extractDynamicFilters(expression).getDynamicConjuncts().stream()).filter(descriptor -> descriptor.getId().equals(dynamicFilterId)).collect(toImmutableList());
boolean sourceSymbolsMatch = matchingDescriptors.stream().map(descriptor -> Symbol.from(descriptor.getInput())).allMatch(sourceSymbol -> symbolAliases.get(sourceSymbolAlias).equals(sourceSymbol.toSymbolReference()));
if (!matchingDescriptors.isEmpty() && sourceSymbolsMatch) {
return match(outputAlias, semiJoinNode.getSemiJoinOutput().toSymbolReference());
}
return NO_MATCH;
}
if (semiJoinNode.getDynamicFilterId().isPresent()) {
return NO_MATCH;
}
}
return match(outputAlias, semiJoinNode.getSemiJoinOutput().toSymbolReference());
}
use of io.trino.metadata.Metadata in project trino by trinodb.
the class TableWriterMatcher 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());
TableWriterNode tableWriterNode = (TableWriterNode) node;
if (!tableWriterNode.getColumnNames().equals(columnNames)) {
return NO_MATCH;
}
if (!columns.stream().map(s -> Symbol.from(symbolAliases.get(s))).collect(toImmutableList()).equals(tableWriterNode.getColumns())) {
return NO_MATCH;
}
return match();
}
use of io.trino.metadata.Metadata in project trino by trinodb.
the class TestDeterminismEvaluator method testSanity.
@Test
public void testSanity() {
Metadata metadata = functionResolution.getMetadata();
assertFalse(DeterminismEvaluator.isDeterministic(function("rand"), metadata));
assertFalse(DeterminismEvaluator.isDeterministic(function("random"), metadata));
assertFalse(DeterminismEvaluator.isDeterministic(function("shuffle", ImmutableList.of(new ArrayType(VARCHAR)), ImmutableList.of(new NullLiteral())), metadata));
assertFalse(DeterminismEvaluator.isDeterministic(function("uuid"), metadata));
assertTrue(DeterminismEvaluator.isDeterministic(function("abs", ImmutableList.of(DOUBLE), ImmutableList.of(input("symbol"))), metadata));
assertFalse(DeterminismEvaluator.isDeterministic(function("abs", ImmutableList.of(DOUBLE), ImmutableList.of(function("rand"))), metadata));
assertTrue(DeterminismEvaluator.isDeterministic(function("abs", ImmutableList.of(DOUBLE), ImmutableList.of(function("abs", ImmutableList.of(DOUBLE), ImmutableList.of(input("symbol"))))), metadata));
}
use of io.trino.metadata.Metadata in project trino by trinodb.
the class BaseIcebergConnectorTest method getTableStatistics.
private TableStatistics getTableStatistics(String tableName, Constraint constraint) {
Metadata metadata = getDistributedQueryRunner().getCoordinator().getMetadata();
QualifiedObjectName qualifiedName = QualifiedObjectName.valueOf(tableName);
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(getSession(), session -> {
Optional<TableHandle> optionalHandle = metadata.getTableHandle(session, qualifiedName);
checkArgument(optionalHandle.isPresent(), "Could not create table handle for table %s", tableName);
return metadata.getTableStatistics(session, optionalHandle.get(), constraint);
});
}
Aggregations