use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class RuleAssert method applyRule.
private RuleApplication applyRule() {
PlanVariableAllocator variableAllocator = new PlanVariableAllocator(types.allVariables());
Memo memo = new Memo(idAllocator, plan);
Lookup lookup = Lookup.from(planNode -> Stream.of(memo.resolve(planNode)));
PlanNode memoRoot = memo.getNode(memo.getRootGroup());
return inTransaction(session -> applyRule(rule, memoRoot, ruleContext(statsCalculator, costCalculator, variableAllocator, memo, lookup, session)));
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestInlineSqlFunctions method assertInlined.
private void assertInlined(RuleTester tester, String inputSql, String expected, Map<String, Type> variableTypes) {
Session session = TestingSession.testSessionBuilder().setSystemProperty("inline_sql_functions", "true").build();
Metadata metadata = tester.getMetadata();
Expression inputSqlExpression = PlanBuilder.expression(inputSql);
Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes(session, metadata, tester.getSqlParser(), viewOf(variableTypes), inputSqlExpression, ImmutableList.of(), WarningCollector.NOOP);
Expression inlinedExpression = InlineSqlFunctions.InlineSqlFunctionsRewriter.rewrite(inputSqlExpression, session, metadata, new PlanVariableAllocator(variableTypes.entrySet().stream().map(entry -> new VariableReferenceExpression(Optional.empty(), entry.getKey(), entry.getValue())).collect(toImmutableList())), expressionTypes);
inlinedExpression = ExpressionUtils.rewriteIdentifiersToSymbolReferences(inlinedExpression);
Expression expectedExpression = PlanBuilder.expression(expected);
assertEquals(inlinedExpression, expectedExpression);
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestPlanRemoteProjections method testRemoteOnly.
@Test
void testRemoteOnly() {
PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), getMetadata());
PlanRemotePojections rule = new PlanRemotePojections(getFunctionAndTypeManager());
List<ProjectionContext> rewritten = rule.planRemoteAssignments(Assignments.builder().put(planBuilder.variable("a"), planBuilder.rowExpression("unittest.memory.remote_foo()")).put(planBuilder.variable("b"), planBuilder.rowExpression("unittest.memory.remote_foo(unittest.memory.remote_foo())")).build(), new PlanVariableAllocator(planBuilder.getTypes().allVariables()));
assertEquals(rewritten.size(), 2);
assertEquals(rewritten.get(1).getProjections().size(), 2);
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestPlanRemoteProjections method testSpecialForm.
@Test
void testSpecialForm() {
PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), getMetadata());
planBuilder.variable("x", INTEGER);
planBuilder.variable("y", INTEGER);
PlanRemotePojections rule = new PlanRemotePojections(getFunctionAndTypeManager());
List<ProjectionContext> rewritten = rule.planRemoteAssignments(Assignments.builder().put(planBuilder.variable("a"), planBuilder.rowExpression("unittest.memory.remote_foo(x, y + unittest.memory.remote_foo(x))")).put(planBuilder.variable("b"), planBuilder.rowExpression("x IS NULL OR y IS NULL")).put(planBuilder.variable("c"), planBuilder.rowExpression("IF(abs(unittest.memory.remote_foo()) > 0, x, y)")).put(planBuilder.variable("d"), planBuilder.rowExpression("unittest.memory.remote_foo(x + y, abs(x))")).put(planBuilder.variable("e"), planBuilder.rowExpression("TRUE OR FALSE")).build(), new PlanVariableAllocator(planBuilder.getTypes().allVariables()));
assertEquals(rewritten.size(), 4);
assertEquals(rewritten.get(3).getProjections().size(), 5);
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestLambdaCaptureDesugaringRewriter method testRewriteBasicLambda.
@Test
public void testRewriteBasicLambda() {
final List<VariableReferenceExpression> variables = ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "a", BIGINT), new VariableReferenceExpression(Optional.empty(), "x", BIGINT));
final PlanVariableAllocator allocator = new PlanVariableAllocator(variables);
assertEquals(rewrite(expression("x -> a + x"), allocator), new BindExpression(ImmutableList.of(expression("a")), new LambdaExpression(Stream.of("a_0", "x").map(Identifier::new).map(LambdaArgumentDeclaration::new).collect(toList()), expression("a_0 + x"))));
}
Aggregations