Search in sources :

Example 11 with NodeStats

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

the class BeamSortRel method beamComputeSelfCost.

@Override
public BeamCostModel beamComputeSelfCost(RelOptPlanner planner, BeamRelMetadataQuery mq) {
    NodeStats inputEstimates = BeamSqlRelUtils.getNodeStats(this.input, mq);
    final double rowSize = getRowType().getFieldCount();
    final double cpu = inputEstimates.getRowCount() * inputEstimates.getRowCount() * rowSize;
    final double cpuRate = inputEstimates.getRate() * inputEstimates.getWindow() * rowSize;
    return BeamCostModel.FACTORY.makeCost(cpu, cpuRate);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 12 with NodeStats

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

the class BeamTableFunctionScanRel method beamComputeSelfCost.

@Override
public BeamCostModel beamComputeSelfCost(RelOptPlanner planner, BeamRelMetadataQuery mq) {
    NodeStats inputEstimates = BeamSqlRelUtils.getNodeStats(getInput(0), mq);
    final double rowSize = getRowType().getFieldCount();
    final double cpu = inputEstimates.getRowCount() * rowSize;
    final double cpuRate = inputEstimates.getRate() * inputEstimates.getWindow() * rowSize;
    return BeamCostModel.FACTORY.makeCost(cpu, cpuRate);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 13 with NodeStats

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

the class BeamUnionRel method estimateNodeStats.

@Override
public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) {
    // The summation of the input stats
    NodeStats summationOfEstimates = inputs.stream().map(input -> BeamSqlRelUtils.getNodeStats(input, mq)).reduce(NodeStats.create(0, 0, 0), NodeStats::plus);
    // If all is set then we propagate duplicated values. Otherwise we assume a constant factor of
    // them are duplicate.
    summationOfEstimates = all ? summationOfEstimates : summationOfEstimates.multiply(0.5);
    return summationOfEstimates;
}
Also used : SetOp(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.SetOp) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamCostModel(org.apache.beam.sdk.extensions.sql.impl.planner.BeamCostModel) WindowFn(org.apache.beam.sdk.transforms.windowing.WindowFn) Union(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union) PCollection(org.apache.beam.sdk.values.PCollection) PTransform(org.apache.beam.sdk.transforms.PTransform) RelOptCluster(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster) List(java.util.List) PCollectionList(org.apache.beam.sdk.values.PCollectionList) RelTraitSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) Row(org.apache.beam.sdk.values.Row) RelOptPlanner(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptPlanner) NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 14 with NodeStats

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

the class BeamJoinRel method estimateNodeStats.

@Override
public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) {
    double selectivity = Preconditions.checkArgumentNotNull(mq.getSelectivity(this, getCondition()), "Attempted to estimate node stats for BeamJoinRel '%s', but selectivity is null.", this);
    NodeStats leftEstimates = BeamSqlRelUtils.getNodeStats(this.left, mq);
    NodeStats rightEstimates = BeamSqlRelUtils.getNodeStats(this.right, mq);
    if (leftEstimates.isUnknown() || rightEstimates.isUnknown()) {
        return NodeStats.UNKNOWN;
    }
    // other.
    return NodeStats.create(leftEstimates.getRowCount() * rightEstimates.getRowCount() * selectivity, (leftEstimates.getRate() * rightEstimates.getWindow() + rightEstimates.getRate() * leftEstimates.getWindow()) * selectivity, leftEstimates.getWindow() * rightEstimates.getWindow() * selectivity);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 15 with NodeStats

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

the class BeamJoinRel method beamComputeSelfCost.

@Override
public BeamCostModel beamComputeSelfCost(RelOptPlanner planner, BeamRelMetadataQuery mq) {
    NodeStats leftEstimates = BeamSqlRelUtils.getNodeStats(this.left, mq);
    NodeStats rightEstimates = BeamSqlRelUtils.getNodeStats(this.right, mq);
    NodeStats selfEstimates = BeamSqlRelUtils.getNodeStats(this, mq);
    NodeStats summation = selfEstimates.plus(leftEstimates).plus(rightEstimates);
    return BeamCostModel.FACTORY.makeCost(summation.getRowCount(), summation.getRate());
}
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