use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.
the class RuleAssert method matches.
public void matches(PlanMatchPattern pattern) {
RuleApplication ruleApplication = applyRule();
TypeProvider types = ruleApplication.types;
if (!ruleApplication.wasRuleApplied()) {
fail(String.format("%s did not fire for:\n%s", rule.getClass().getName(), formatPlan(plan, types)));
}
PlanNode actual = ruleApplication.getTransformedPlan();
if (actual == plan) {
// plans are not comparable, so we can only ensure they are not the same instance
fail(String.format("%s: rule fired but return the original plan:\n%s", rule.getClass().getName(), formatPlan(plan, types)));
}
if (!ImmutableSet.copyOf(plan.getOutputVariables()).equals(ImmutableSet.copyOf(actual.getOutputVariables()))) {
fail(String.format("%s: output schema of transformed and original plans are not equivalent\n" + "\texpected: %s\n" + "\tactual: %s", rule.getClass().getName(), plan.getOutputVariables(), actual.getOutputVariables()));
}
inTransaction(session -> {
assertPlan(session, metadata, ruleApplication.statsProvider, new Plan(actual, types, StatsAndCosts.empty()), ruleApplication.lookup, pattern, planNode -> translateExpressions(planNode, types));
return null;
});
}
use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.
the class TestExpressionEquivalence method assertEquivalent.
private static void assertEquivalent(@Language("SQL") String left, @Language("SQL") String right) {
ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE);
Expression leftExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(left, parsingOptions));
Expression rightExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(right, parsingOptions));
Set<Symbol> symbols = extractUnique(ImmutableList.of(leftExpression, rightExpression));
TypeProvider types = TypeProvider.viewOf(symbols.stream().collect(toImmutableMap(Symbol::getName, TestExpressionEquivalence::generateType)));
assertTrue(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, leftExpression, rightExpression, types), String.format("Expected (%s) and (%s) to be equivalent", left, right));
assertTrue(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, rightExpression, leftExpression, types), String.format("Expected (%s) and (%s) to be equivalent", right, left));
}
use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.
the class TestExpressionEquivalence method assertNotEquivalent.
private static void assertNotEquivalent(@Language("SQL") String left, @Language("SQL") String right) {
ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE);
Expression leftExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(left, parsingOptions));
Expression rightExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(right, parsingOptions));
Set<Symbol> symbols = extractUnique(ImmutableList.of(leftExpression, rightExpression));
TypeProvider types = TypeProvider.viewOf(symbols.stream().collect(toImmutableMap(Symbol::getName, TestExpressionEquivalence::generateType)));
assertFalse(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, leftExpression, rightExpression, types), String.format("Expected (%s) and (%s) to not be equivalent", left, right));
assertFalse(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, rightExpression, leftExpression, types), String.format("Expected (%s) and (%s) to not be equivalent", right, left));
}
Aggregations