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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations