Search in sources :

Example 16 with NodeStats

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

the class BeamMatchRel method estimateNodeStats.

@Override
public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) {
    // a simple way of getting some estimate data
    // to be examined further
    NodeStats inputEstimate = BeamSqlRelUtils.getNodeStats(input, mq);
    double numRows = inputEstimate.getRowCount();
    double winSize = inputEstimate.getWindow();
    double rate = inputEstimate.getRate();
    return NodeStats.create(numRows, rate, winSize).multiply(0.5);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 17 with NodeStats

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

the class BeamAggregationRel method estimateNodeStats.

@Override
public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) {
    NodeStats inputEstimate = BeamSqlRelUtils.getNodeStats(this.input, mq);
    inputEstimate = computeWindowingCostEffect(inputEstimate);
    // groupCount shows how many columns do we have in group by. One of them might be the windowing.
    int groupCount = groupSet.cardinality() - (windowFn == null ? 0 : 1);
    // preserved.
    return (groupCount == 0) ? NodeStats.create(Math.min(inputEstimate.getRowCount(), 1d), inputEstimate.getRate() / inputEstimate.getWindow(), 1d) : inputEstimate.multiply(1.0 - Math.pow(.5, groupCount));
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 18 with NodeStats

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

the class BeamIntersectRel method estimateNodeStats.

@Override
public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) {
    // This takes the minimum of the inputs for all the estimate factors.
    double minimumRows = Double.POSITIVE_INFINITY;
    double minimumWindowSize = Double.POSITIVE_INFINITY;
    double minimumRate = Double.POSITIVE_INFINITY;
    for (RelNode input : inputs) {
        NodeStats inputEstimates = BeamSqlRelUtils.getNodeStats(input, mq);
        minimumRows = Math.min(minimumRows, inputEstimates.getRowCount());
        minimumRate = Math.min(minimumRate, inputEstimates.getRate());
        minimumWindowSize = Math.min(minimumWindowSize, inputEstimates.getWindow());
    }
    return NodeStats.create(minimumRows, minimumRate, minimumWindowSize).multiply(0.5);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)

Example 19 with NodeStats

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

the class BeamWindowRel method beamComputeSelfCost.

/**
 * A dummy cost computation based on a fixed multiplier.
 *
 * <p>Since, there are not additional LogicalWindow to BeamWindowRel strategies, the result of
 * this cost computation has no impact in the query execution plan.
 */
@Override
public BeamCostModel beamComputeSelfCost(RelOptPlanner planner, BeamRelMetadataQuery mq) {
    NodeStats inputStat = BeamSqlRelUtils.getNodeStats(this.input, mq);
    float multiplier = 1f + 0.125f;
    return BeamCostModel.FACTORY.makeCost(inputStat.getRowCount() * multiplier, inputStat.getRate() * multiplier);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 20 with NodeStats

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

the class BeamAggregationRelTest method testNodeStatsEffectOfGroupSet.

@Test
public void testNodeStatsEffectOfGroupSet() {
    String sql1 = "SELECT order_id FROM ORDER_DETAILS_BOUNDED " + " GROUP BY order_id ";
    String sql2 = "SELECT order_id, site_id FROM ORDER_DETAILS_BOUNDED " + " GROUP BY order_id, site_id ";
    NodeStats estimate1 = getEstimateOf(sql1);
    NodeStats estimate2 = getEstimateOf(sql2);
    Assert.assertTrue(estimate1.getRowCount() < estimate2.getRowCount());
    Assert.assertTrue(estimate1.getWindow() < estimate2.getWindow());
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) 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