private RuleAssert assertRuleApplication() { return tester().assertThat(new RewriteSpatialPartitioningAggregation(tester().getMetadata())); } }
private RuleAssert assertRuleApplication() { RuleTester tester = tester(); return tester.assertThat(new ExtractSpatialInnerJoin(tester.getMetadata(), tester.getSplitManager(), tester.getPageSourceManager(), tester.getSqlParser())); } }
@Test public void doesNotFireOnUncorrelated() { tester().assertThat(new TransformCorrelatedScalarAggregationToJoin(tester().getMetadata().getFunctionRegistry())) .on(p -> p.lateral( ImmutableList.of(), p.values(p.symbol("a")), p.values(p.symbol("b")))) .doesNotFire(); }
@Test public void doesNotFireOnPlanWithoutApplyNode() { tester().assertThat(new TransformCorrelatedScalarAggregationToJoin(tester().getMetadata().getFunctionRegistry())) .on(p -> p.values(p.symbol("a"))) .doesNotFire(); }
@Test public void testRewrite() { tester().assertThat(new TransformExistsApplyToLateralNode(tester().getMetadata().getFunctionRegistry())) .on(p -> p.apply( Assignments.of(p.symbol("b", BOOLEAN), expression("EXISTS(SELECT TRUE)")), ImmutableList.of(), p.values(), p.values())) .matches(lateral( ImmutableList.of(), values(ImmutableMap.of()), project( ImmutableMap.of("b", PlanMatchPattern.expression("(\"count_expr\" > CAST(0 AS bigint))")), aggregation(ImmutableMap.of("count_expr", functionCall("count", ImmutableList.of())), values())))); }
private RuleAssert assertRuleApplication() { RuleTester tester = tester(); return tester().assertThat(new ExtractSpatialLeftJoin(tester.getMetadata(), tester.getSplitManager(), tester.getPageSourceManager(), tester.getSqlParser())); } }
@Test public void doesNotFireOnCorrelatedWithoutAggregation() { tester().assertThat(new TransformCorrelatedScalarAggregationToJoin(tester().getMetadata().getFunctionRegistry())) .on(p -> p.lateral( ImmutableList.of(p.symbol("corr")), p.values(p.symbol("corr")), p.values(p.symbol("a")))) .doesNotFire(); }
@Test public void rewritesOnSubqueryWithoutProjection() { tester().assertThat(new TransformCorrelatedScalarAggregationToJoin(tester().getMetadata().getFunctionRegistry())) .on(p -> p.lateral( ImmutableList.of(p.symbol("corr")), p.values(p.symbol("corr")), p.aggregation(ab -> ab .source(p.values(p.symbol("a"), p.symbol("b"))) .addAggregation(p.symbol("sum"), PlanBuilder.expression("sum(a)"), ImmutableList.of(BIGINT)) .globalGrouping()))) .matches( project(ImmutableMap.of("sum_1", expression("sum_1"), "corr", expression("corr")), aggregation(ImmutableMap.of("sum_1", functionCall("sum", ImmutableList.of("a"))), join(JoinNode.Type.LEFT, ImmutableList.of(), assignUniqueId("unique", values(ImmutableMap.of("corr", 0))), project(ImmutableMap.of("non_null", expression("true")), values(ImmutableMap.of("a", 0, "b", 1))))))); }
@Test public void testDoesNotFire() { tester().assertThat(new TransformExistsApplyToLateralNode(tester().getMetadata().getFunctionRegistry())) .on(p -> p.values(p.symbol("a"))) .doesNotFire(); tester().assertThat(new TransformExistsApplyToLateralNode(tester().getMetadata().getFunctionRegistry())) .on(p -> p.lateral( ImmutableList.of(p.symbol("a")), p.values(p.symbol("a")), p.values(p.symbol("a")))) .doesNotFire(); }
@Test public void rewritesOnSubqueryWithProjection() { tester().assertThat(new TransformCorrelatedScalarAggregationToJoin(tester().getMetadata().getFunctionRegistry())) .on(p -> p.lateral( ImmutableList.of(p.symbol("corr")), p.values(p.symbol("corr")), p.project(Assignments.of(p.symbol("expr"), p.expression("sum + 1")), p.aggregation(ab -> ab .source(p.values(p.symbol("a"), p.symbol("b"))) .addAggregation(p.symbol("sum"), PlanBuilder.expression("sum(a)"), ImmutableList.of(BIGINT)) .globalGrouping())))) .matches( project(ImmutableMap.of("corr", expression("corr"), "expr", expression("(\"sum_1\" + 1)")), aggregation(ImmutableMap.of("sum_1", functionCall("sum", ImmutableList.of("a"))), join(JoinNode.Type.LEFT, ImmutableList.of(), assignUniqueId("unique", values(ImmutableMap.of("corr", 0))), project(ImmutableMap.of("non_null", expression("true")), values(ImmutableMap.of("a", 0, "b", 1))))))); } }
@Test public void doesNotFireOnCorrelatedWithNonScalarAggregation() { tester().assertThat(new TransformCorrelatedScalarAggregationToJoin(tester().getMetadata().getFunctionRegistry())) .on(p -> p.lateral( ImmutableList.of(p.symbol("corr")), p.values(p.symbol("corr")), p.aggregation(ab -> ab .source(p.values(p.symbol("a"), p.symbol("b"))) .addAggregation(p.symbol("sum"), PlanBuilder.expression("sum(a)"), ImmutableList.of(BIGINT)) .singleGroupingSet(p.symbol("b"))))) .doesNotFire(); }
@Test public void testRewritesToLimit() { tester().assertThat(new TransformExistsApplyToLateralNode(tester().getMetadata().getFunctionRegistry())) .on(p -> p.apply( Assignments.of(p.symbol("b", BOOLEAN), expression("EXISTS(SELECT TRUE)")), ImmutableList.of(p.symbol("corr")), p.values(p.symbol("corr")), p.project(Assignments.of(), p.filter( expression("corr = column"), p.values(p.symbol("column")))))) .matches( project(ImmutableMap.of("b", PlanMatchPattern.expression("COALESCE(subquerytrue, false)")), lateral( ImmutableList.of("corr"), values("corr"), project( ImmutableMap.of("subquerytrue", PlanMatchPattern.expression("true")), limit(1, project(ImmutableMap.of(), node(FilterNode.class, values("column")))))))); } }
@BeforeClass public void setUpBeforeClass() { pickTableLayout = new PickTableLayout(tester().getMetadata(), new SqlParser()); connectorId = tester().getCurrentConnectorId(); nationTableHandle = new TableHandle( connectorId, new TpchTableHandle("nation", 1.0)); ordersTableHandle = new TableHandle( connectorId, new TpchTableHandle("orders", 1.0)); nationTableLayoutHandle = new TableLayoutHandle( connectorId, TestingTransactionHandle.create(), new TpchTableLayoutHandle((TpchTableHandle) nationTableHandle.getConnectorHandle(), TupleDomain.all())); ordersTableLayoutHandle = new TableLayoutHandle( connectorId, TestingTransactionHandle.create(), new TpchTableLayoutHandle((TpchTableHandle) ordersTableHandle.getConnectorHandle(), TupleDomain.all())); }
private RuleAssert assertRuleApplication() { return tester().assertThat(new RewriteSpatialPartitioningAggregation(tester().getMetadata())); } }
private RuleAssert assertRuleApplication() { return tester().assertThat(new ExtractSpatialInnerJoin(tester().getMetadata(), tester().getSplitManager(), tester().getPageSourceManager())); } }
private RuleAssert assertRuleApplication() { return tester().assertThat(new ExtractSpatialLeftJoin(tester().getMetadata(), tester().getSplitManager(), tester().getPageSourceManager())); } }