Search in sources :

Example 26 with TypeProvider

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;
    });
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) PlanAssert.assertPlan(com.facebook.presto.sql.planner.assertions.PlanAssert.assertPlan) PlanPrinter.textLogicalPlan(com.facebook.presto.sql.planner.planPrinter.PlanPrinter.textLogicalPlan) Plan(com.facebook.presto.sql.planner.Plan)

Example 27 with TypeProvider

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));
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) Expression(com.facebook.presto.sql.tree.Expression) Symbol(com.facebook.presto.sql.planner.Symbol) TypeProvider(com.facebook.presto.sql.planner.TypeProvider)

Example 28 with TypeProvider

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));
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) Expression(com.facebook.presto.sql.tree.Expression) Symbol(com.facebook.presto.sql.planner.Symbol) TypeProvider(com.facebook.presto.sql.planner.TypeProvider)

Aggregations

TypeProvider (com.facebook.presto.sql.planner.TypeProvider)28 RowExpression (com.facebook.presto.spi.relation.RowExpression)17 PlanNode (com.facebook.presto.spi.plan.PlanNode)12 Test (org.testng.annotations.Test)12 ColumnHandle (com.facebook.presto.spi.ColumnHandle)7 Session (com.facebook.presto.Session)6 TranslatedExpression (com.facebook.presto.expressions.translator.TranslatedExpression)6 ConnectorSession (com.facebook.presto.spi.ConnectorSession)6 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)6 List (java.util.List)6 JdbcColumnHandle (com.facebook.presto.plugin.jdbc.JdbcColumnHandle)5 JdbcTableHandle (com.facebook.presto.plugin.jdbc.JdbcTableHandle)5 JdbcTableLayoutHandle (com.facebook.presto.plugin.jdbc.JdbcTableLayoutHandle)5 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 Expression (com.facebook.presto.sql.tree.Expression)5 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)5 Map (java.util.Map)5 CallExpression (com.facebook.presto.spi.relation.CallExpression)4 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)3 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)3