use of com.facebook.presto.sql.planner.iterative.rule.test.RuleTester in project presto by prestodb.
the class TestPredicatePushdown method testPredicatePushDownCreatesValidJoin.
@Test
public void testPredicatePushDownCreatesValidJoin() {
RuleTester tester = new RuleTester();
tester.assertThat(new PredicatePushDown(tester.getMetadata(), tester.getSqlParser())).on(p -> p.join(INNER, p.filter(p.comparison(OperatorType.EQUAL, p.variable("a1"), constant(1L, INTEGER)), p.values(p.variable("a1"))), p.values(p.variable("b1")), ImmutableList.of(new EquiJoinClause(p.variable("a1"), p.variable("b1"))), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(PARTITIONED), ImmutableMap.of())).matches(project(join(INNER, ImmutableList.of(), Optional.empty(), Optional.of(REPLICATED), project(filter("a1=1", values("a1"))), project(filter("1=b1", values("b1"))))));
}
use of com.facebook.presto.sql.planner.iterative.rule.test.RuleTester in project presto by prestodb.
the class TestInlineSqlFunctions method setup.
@BeforeTest
public void setup() {
RuleTester tester = new RuleTester();
FunctionAndTypeManager functionAndTypeManager = tester.getMetadata().getFunctionAndTypeManager();
functionAndTypeManager.addFunctionNamespace("unittest", new InMemoryFunctionNamespaceManager("unittest", new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL, JAVA, THRIFT), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setSupportedFunctionLanguages("sql,java")));
functionAndTypeManager.createFunction(SQL_FUNCTION_SQUARE, true);
functionAndTypeManager.createFunction(THRIFT_FUNCTION_FOO, true);
functionAndTypeManager.createFunction(SQL_FUNCTION_ADD_1_TO_INT_ARRAY, true);
functionAndTypeManager.createFunction(SQL_FUNCTION_ADD_1_TO_BIGINT_ARRAY, true);
this.tester = tester;
}
use of com.facebook.presto.sql.planner.iterative.rule.test.RuleTester 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.iterative.rule.test.RuleTester in project presto by prestodb.
the class TestPlanRemoteProjections method setup.
@BeforeClass
public void setup() {
tester = new RuleTester(ImmutableList.of(), ImmutableMap.of("remote_functions_enabled", "true"));
FunctionAndTypeManager functionAndTypeManager = getFunctionAndTypeManager();
functionAndTypeManager.addFunctionNamespace("unittest", new InMemoryFunctionNamespaceManager("unittest", new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL, JAVA, THRIFT), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setSupportedFunctionLanguages("sql,java")));
functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_0, true);
functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_1, true);
functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_2, true);
functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_3, true);
}
use of com.facebook.presto.sql.planner.iterative.rule.test.RuleTester in project presto by prestodb.
the class TestPlanRemoteProjections method testRemoteFunctionDisabled.
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = ".*Remote functions are not enabled")
public void testRemoteFunctionDisabled() {
RuleTester tester = new RuleTester(ImmutableList.of());
FunctionAndTypeManager functionAndTypeManager = tester.getMetadata().getFunctionAndTypeManager();
functionAndTypeManager.addFunctionNamespace("unittest", new InMemoryFunctionNamespaceManager("unittest", new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL, JAVA, THRIFT), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setSupportedFunctionLanguages("sql,java")));
functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_1, true);
tester.assertThat(new PlanRemotePojections(functionAndTypeManager)).on(p -> {
p.variable("x", INTEGER);
return p.project(Assignments.builder().put(p.variable("a"), p.rowExpression("unittest.memory.remote_foo(x)")).build(), p.values(p.variable("x", INTEGER)));
}).matches(anyTree());
}
Aggregations