Search in sources :

Example 1 with BeamCostModel

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

the class BeamPushDownIOSourceRel method beamComputeSelfCost.

@Override
public BeamCostModel beamComputeSelfCost(RelOptPlanner planner, BeamRelMetadataQuery mq) {
    BeamCostModel parentCost = super.beamComputeSelfCost(planner, mq);
    Preconditions.checkArgument(parentCost.getCpu() >= 0, "Cpu cost must be zero or positive.");
    // Table schema will always contain all fields, while usedFields may contain less fields due to
    // push-down. Difference between the two will be the number of fields pushed-down. Bigger
    // difference - better.
    double projectBenefit = getBeamSqlTable().getSchema().getFieldCount() - usedFields.size();
    // Number of filters pushed-down should have a smaller impact.
    double filterBenefit = tableFilters.numSupported();
    // Normalize filterBenefit to be between 0.00 and (10% of projectBenefit).
    filterBenefit = (1.0 - (1.0 / (filterBenefit + 1))) * ((projectBenefit + 1) * 0.1);
    // Total totalBenefit of having push-down.
    double totalBenefit = projectBenefit + filterBenefit;
    // Normalize totalBenefit to be between 0.00 and 1.00.
    double normalizedBenefit = totalBenefit / (Math.max(totalBenefit, parentCost.getCpu()) + 1);
    BeamCostModel minus = BeamCostModel.FACTORY.makeTinyCost().multiplyBy(normalizedBenefit);
    return parentCost.minus(minus);
}
Also used : BeamCostModel(org.apache.beam.sdk.extensions.sql.impl.planner.BeamCostModel)

Aggregations

BeamCostModel (org.apache.beam.sdk.extensions.sql.impl.planner.BeamCostModel)1