Search in sources :

Example 26 with NodeStats

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

the class BeamAggregationRel method beamComputeSelfCost.

@Override
public BeamCostModel beamComputeSelfCost(RelOptPlanner planner, BeamRelMetadataQuery mq) {
    NodeStats inputStat = BeamSqlRelUtils.getNodeStats(this.input, mq);
    inputStat = computeWindowingCostEffect(inputStat);
    // Aggregates with more aggregate functions cost a bit more
    float multiplier = 1f + (float) aggCalls.size() * 0.125f;
    for (AggregateCall aggCall : aggCalls) {
        if (aggCall.getAggregation().getName().equals("SUM")) {
            // Pretend that SUM costs a little bit more than $SUM0,
            // to make things deterministic.
            multiplier += 0.0125f;
        }
    }
    return BeamCostModel.FACTORY.makeCost(inputStat.getRowCount() * multiplier, inputStat.getRate() * multiplier);
}
Also used : AggregateCall(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.AggregateCall) NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 27 with NodeStats

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

the class BeamMinusRel method estimateNodeStats.

@Override
public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) {
    NodeStats firstInputEstimates = BeamSqlRelUtils.getNodeStats(inputs.get(0), mq);
    // The first input minus half of the others. (We are assuming half of them have intersection)
    for (int i = 1; i < inputs.size(); i++) {
        NodeStats inputEstimate = BeamSqlRelUtils.getNodeStats(inputs.get(i), mq);
        firstInputEstimates = firstInputEstimates.minus(inputEstimate.multiply(0.5));
    }
    return firstInputEstimates;
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 28 with NodeStats

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

the class BeamUncollectRelTest method testNodeStats.

@Test
public void testNodeStats() {
    NodeStats estimate = getEstimateOf("SELECT * FROM UNNEST (SELECT * FROM (VALUES (ARRAY ['a', 'b', 'c']),(ARRAY ['a', 'b', 'c']))) t1");
    Assert.assertEquals(4d, estimate.getRowCount(), 0.001);
    Assert.assertEquals(4d, 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 29 with NodeStats

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

the class BeamSortRelTest method testNodeStatsEstimation.

@Test
public void testNodeStatsEstimation() {
    String sql = "SELECT order_id, site_id, price, order_time " + "FROM ORDER_DETAILS " + "ORDER BY order_time asc limit 11";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamSortRel)) {
        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(10., estimate.getRowCount(), 0.01);
    Assert.assertEquals(10., 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 30 with NodeStats

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

the class BeamUnionRelTest method testNodeStatsEstimationUnionAll.

@Test
public void testNodeStatsEstimationUnionAll() {
    String sql = "SELECT " + " order_id, site_id, price " + "FROM ORDER_DETAILS " + " UNION ALL SELECT " + " order_id, site_id, price " + "FROM ORDER_DETAILS ";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamUnionRel)) {
        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(4., estimate.getRowCount(), 0.01);
    Assert.assertEquals(4., 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)

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