Search in sources :

Example 6 with NodeStats

use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.

the class BeamIOSourceRelTest method testBoundedNodeStats.

@Test
public void testBoundedNodeStats() {
    String sql = "SELECT * FROM ORDER_DETAILS_BOUNDED";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamIOSourceRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertEquals(5d, estimate.getRowCount(), 0.01);
    Assert.assertEquals(0d, estimate.getRate(), 0.01);
    Assert.assertEquals(5d, estimate.getWindow(), 0.01);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 7 with NodeStats

use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.

the class BeamIOSourceRelTest method testUnboundedNodeStats.

@Test
public void testUnboundedNodeStats() {
    String sql = "SELECT * FROM ORDER_DETAILS_UNBOUNDED";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamIOSourceRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertEquals(0d, estimate.getRowCount(), 0.01);
    Assert.assertEquals(2d, estimate.getRate(), 0.01);
    Assert.assertEquals(BeamIOSourceRel.CONSTANT_WINDOW_SIZE, estimate.getWindow(), 0.01);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 8 with NodeStats

use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.

the class BeamMinusRelTest method testNodeStatsEstimationUnbounded.

@Test
public void testNodeStatsEstimationUnbounded() {
    String sql = "SELECT * " + "FROM " + "(select order_id FROM ORDER_DETAILS_UNBOUNDED " + "          GROUP BY order_id, TUMBLE(order_time, INTERVAL '1' HOUR)) o1 " + " EXCEPT ALL " + " select order_id FROM ORDER_DETAILS_UNBOUNDED " + "          GROUP BY order_id, TUMBLE(order_time, INTERVAL '1' HOUR) ";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamMinusRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    // note that we have group by
    Assert.assertEquals(4d / 2 - 4d / 4, estimate.getRate(), 0.01);
    Assert.assertEquals(0d, estimate.getRowCount(), 0.01);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 9 with NodeStats

use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.

the class BeamAggregationRelTest method testNodeStatsUnboundedWindow.

@Test
public void testNodeStatsUnboundedWindow() {
    String sql = "select order_id, sum(site_id) as sum_site_id FROM ORDER_DETAILS_UNBOUNDED " + " GROUP BY order_id, TUMBLE(order_time, INTERVAL '1' HOUR)";
    NodeStats estimate1 = getEstimateOf(sql);
    Assert.assertEquals(1d, estimate1.getRate(), 0.01);
    Assert.assertEquals(BeamIOSourceRel.CONSTANT_WINDOW_SIZE / 2, estimate1.getWindow(), 0.01);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) Test(org.junit.Test)

Example 10 with NodeStats

use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.

the class BeamCoGBKJoinRelBoundedVsBoundedTest method testNodeStatsOfMoreConditions.

@Test
public void testNodeStatsOfMoreConditions() {
    String sql1 = "SELECT *  " + " FROM ORDER_DETAILS1 o1 " + " JOIN ORDER_DETAILS2 o2 " + " on " + " o1.order_id=o2.site_id ";
    String sql2 = "SELECT *  " + " FROM ORDER_DETAILS1 o1 " + " JOIN ORDER_DETAILS2 o2 " + " on " + " o1.order_id=o2.site_id AND o2.price=o1.site_id";
    RelNode root1 = env.parseQuery(sql1);
    while (!(root1 instanceof BeamCoGBKJoinRel)) {
        root1 = root1.getInput(0);
    }
    RelNode root2 = env.parseQuery(sql2);
    while (!(root2 instanceof BeamCoGBKJoinRel)) {
        root2 = root2.getInput(0);
    }
    NodeStats estimate1 = BeamSqlRelUtils.getNodeStats(root1, ((BeamRelMetadataQuery) root1.getCluster().getMetadataQuery()));
    NodeStats estimate2 = BeamSqlRelUtils.getNodeStats(root2, ((BeamRelMetadataQuery) root1.getCluster().getMetadataQuery()));
    Assert.assertNotEquals(0d, estimate2.getRowCount(), 0.001);
    // A join with two conditions should have lower estimate.
    Assert.assertTrue(estimate2.getRowCount() < estimate1.getRowCount());
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Aggregations

NodeStats (org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)34 Test (org.junit.Test)22 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)19 BeamRelMetadataQuery (org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery)17 List (java.util.List)1 BeamCostModel (org.apache.beam.sdk.extensions.sql.impl.planner.BeamCostModel)1 PTransform (org.apache.beam.sdk.transforms.PTransform)1 WindowFn (org.apache.beam.sdk.transforms.windowing.WindowFn)1 PCollection (org.apache.beam.sdk.values.PCollection)1 PCollectionList (org.apache.beam.sdk.values.PCollectionList)1 Row (org.apache.beam.sdk.values.Row)1 RelOptCluster (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster)1 RelOptPlanner (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptPlanner)1 RelTraitSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet)1 AggregateCall (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.AggregateCall)1 SetOp (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.SetOp)1 Union (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union)1