@Test public void testGiveUpOnCrossJoin() { assertPlan("SELECT o.orderkey FROM part p, orders o, lineitem l WHERE l.orderkey = o.orderkey", anyTree( join(INNER, ImmutableList.of(equiJoinClause("O_ORDERKEY", "L_ORDERKEY")), anyTree( join(INNER, ImmutableList.of(), tableScan("part"), anyTree(tableScan("orders", ImmutableMap.of("O_ORDERKEY", "orderkey"))))), anyTree(tableScan("lineitem", ImmutableMap.of("L_ORDERKEY", "orderkey")))))); }
@Test public void testSimpleScan() { // don't force gather assertPlanWithSession("SELECT * FROM orders", singleNodeOutput(false), false, output( tableScan("orders"))); // force gather assertPlanWithSession("SELECT * FROM orders", singleNodeOutput(true), false, output( exchange(ExchangeNode.Scope.REMOTE, ExchangeNode.Type.GATHER, tableScan("orders")))); }
@Test public void testInnerInequalityJoinNoEquiJoinConjuncts() { assertPlan("SELECT 1 FROM orders o JOIN lineitem l ON o.orderkey < l.orderkey", anyTree( filter("O_ORDERKEY < L_ORDERKEY", join(INNER, ImmutableList.of(), Optional.empty(), tableScan("orders", ImmutableMap.of("O_ORDERKEY", "orderkey")), any(tableScan("lineitem", ImmutableMap.of("L_ORDERKEY", "orderkey"))))))); }
@Test public void testGroupBy() { // don't force gather assertPlanWithSession("SELECT orderkey, count(*) FROM orders GROUP BY orderkey", singleNodeOutput(false), false, output( node(AggregationNode.class, tableScan("orders")))); // force gather assertPlanWithSession("SELECT orderkey, count(*) FROM orders GROUP BY orderkey", singleNodeOutput(true), false, output( exchange(ExchangeNode.Scope.REMOTE, ExchangeNode.Type.GATHER, node(AggregationNode.class, tableScan("orders"))))); }
@Test public void testJoin() { assertPlan("SELECT o.orderkey FROM orders o, lineitem l WHERE l.orderkey = o.orderkey", anyTree( join(INNER, ImmutableList.of(equiJoinClause("ORDERS_OK", "LINEITEM_OK")), any( tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey"))), anyTree( tableScan("lineitem", ImmutableMap.of("LINEITEM_OK", "orderkey")))))); }
@Test public void testJoinWithOrderBySameKey() { assertPlan("SELECT o.orderkey FROM orders o, lineitem l WHERE l.orderkey = o.orderkey ORDER BY l.orderkey ASC, o.orderkey ASC", anyTree( join(INNER, ImmutableList.of(equiJoinClause("ORDERS_OK", "LINEITEM_OK")), any( tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey"))), anyTree( tableScan("lineitem", ImmutableMap.of("LINEITEM_OK", "orderkey")))))); }
@Test public void testFlattensUnionAndUnionAllWhenAllowed() { assertPlan( "SELECT * FROM nation " + "UNION ALL (SELECT * FROM nation " + "UNION (SELECT * FROM nation UNION ALL select * FROM nation))", anyTree( union( tableScan("nation"), anyTree( union( tableScan("nation"), tableScan("nation"), tableScan("nation")))))); }
@Test public void testDoesNotFlattenDifferentSetOperations() { assertPlan( "(SELECT * FROM nation EXCEPT SELECT * FROM nation)" + "UNION (SELECT * FROM nation INTERSECT SELECT * FROM nation)", anyTree( union( except( tableScan("nation"), tableScan("nation")), intersect( tableScan("nation"), tableScan("nation"))))); }
@Test public void testOrderBy() { // don't force gather assertPlanWithSession("SELECT orderkey FROM orders ORDER BY orderkey", singleNodeOutput(false), false, output( exchange(ExchangeNode.Scope.REMOTE, ExchangeNode.Type.GATHER, anyTree( tableScan("orders"))))); // force gather, same result assertPlanWithSession("SELECT orderkey FROM orders ORDER BY orderkey", singleNodeOutput(true), false, output( exchange(ExchangeNode.Scope.REMOTE, ExchangeNode.Type.GATHER, anyTree( tableScan("orders"))))); }
@Test public void rewriteAddFilterWithMultipleFilters() { assertPlan( "SELECT sum(totalprice) FILTER(WHERE totalprice > 0), sum(custkey) FILTER(WHERE custkey > 0) FROM orders", anyTree( filter( "(\"totalprice\" > 0E0 OR \"custkey\" > BIGINT '0')", tableScan( "orders", ImmutableMap.of("totalprice", "totalprice", "custkey", "custkey"))))); }