Search in sources :

Example 21 with NodeStats

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

the class BeamAggregationRelTest method testNodeStats.

@Test
public void testNodeStats() {
    String sql = "SELECT order_id FROM ORDER_DETAILS_BOUNDED " + " GROUP BY order_id ";
    NodeStats estimate = getEstimateOf(sql);
    Assert.assertEquals(5d / 2, estimate.getRowCount(), 0.001);
    Assert.assertEquals(5d / 2, estimate.getWindow(), 0.001);
    Assert.assertEquals(0., estimate.getRate(), 0.001);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) Test(org.junit.Test)

Example 22 with NodeStats

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

the class BeamAggregationRelTest method testNodeStatsSlidingWindow.

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

Example 23 with NodeStats

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

the class BeamCoGBKJoinRelBoundedVsBoundedTest method testNodeStatsEstimation.

@Test
public void testNodeStatsEstimation() {
    String sql = "SELECT *  " + " FROM ORDER_DETAILS1 o1 " + " JOIN ORDER_DETAILS2 o2 " + " on " + " o1.order_id=o2.site_id ";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamCoGBKJoinRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    NodeStats leftEstimate = BeamSqlRelUtils.getNodeStats(((BeamCoGBKJoinRel) root).getLeft(), ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    NodeStats rightEstimate = BeamSqlRelUtils.getNodeStats(((BeamCoGBKJoinRel) root).getRight(), ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertFalse(estimate.isUnknown());
    Assert.assertEquals(0d, estimate.getRate(), 0.01);
    Assert.assertNotEquals(0d, estimate.getRowCount(), 0.001);
    Assert.assertTrue(estimate.getRowCount() < leftEstimate.getRowCount() * rightEstimate.getRowCount());
    Assert.assertNotEquals(0d, estimate.getWindow(), 0.001);
    Assert.assertTrue(estimate.getWindow() < leftEstimate.getWindow() * rightEstimate.getWindow());
}
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 24 with NodeStats

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

the class BeamIntersectRelTest method testNodeStatsEstimation.

@Test
public void testNodeStatsEstimation() {
    String sql = "SELECT order_id, site_id, price " + " FROM ORDER_DETAILS1 " + " INTERSECT " + " SELECT order_id, site_id, price " + " FROM ORDER_DETAILS2 ";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamIntersectRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertFalse(estimate.isUnknown());
    Assert.assertEquals(0d, estimate.getRate(), 0.01);
    Assert.assertEquals(3. / 2., estimate.getRowCount(), 0.01);
    Assert.assertEquals(3. / 2., 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 25 with NodeStats

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

the class AbstractBeamCalcRel method estimateNodeStats.

@Override
public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) {
    NodeStats inputStat = BeamSqlRelUtils.getNodeStats(input, mq);
    double selectivity = estimateFilterSelectivity(getInput(), program, mq);
    return inputStat.multiply(selectivity);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

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