use of org.apache.calcite.rel.RelNode in project drill by apache.
the class DrillFilterRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final LogicalFilter filter = (LogicalFilter) call.rel(0);
final RelNode input = filter.getInput();
//final RelTraitSet traits = filter.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
final RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.DRILL_LOGICAL));
call.transformTo(new DrillFilterRel(filter.getCluster(), convertedInput.getTraitSet(), convertedInput, filter.getCondition()));
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class DrillAggregateRelBase method computeHashAggCost.
/**
* Estimate cost of hash agg. Called by DrillAggregateRel.computeSelfCost() and HashAggPrel.computeSelfCost()
*/
protected RelOptCost computeHashAggCost(RelOptPlanner planner, RelMetadataQuery mq) {
if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
return super.computeSelfCost(planner, mq).multiplyBy(.1);
}
RelNode child = this.getInput();
double inputRows = mq.getRowCount(child);
int numGroupByFields = this.getGroupCount();
int numAggrFields = this.aggCalls.size();
// cpu cost of hashing each grouping key
double cpuCost = DrillCostBase.HASH_CPU_COST * numGroupByFields * inputRows;
// add cpu cost for computing the aggregate functions
cpuCost += DrillCostBase.FUNC_CPU_COST * numAggrFields * inputRows;
// assume in-memory for now until we enforce operator-level memory constraints
double diskIOCost = 0;
// TODO: use distinct row count
// + hash table template stuff
double factor = PrelUtil.getPlannerSettings(planner).getOptions().getOption(ExecConstants.HASH_AGG_TABLE_FACTOR_KEY).float_val;
long fieldWidth = PrelUtil.getPlannerSettings(planner).getOptions().getOption(ExecConstants.AVERAGE_FIELD_WIDTH_KEY).num_val;
// table + hashValues + links
double memCost = ((fieldWidth * numGroupByFields) + IntHolder.WIDTH + IntHolder.WIDTH) * inputRows * factor;
DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
return costFactory.makeCost(inputRows, cpuCost, diskIOCost, 0, /* network cost */
memCost);
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class DrillFilterRelBase method estimateCpuCost.
/* Given the condition (C1 and C2 and C3 and ... C_n), here is how to estimate cpu cost of FILTER :
* Let's say child's rowcount is n. We assume short circuit evaluation will be applied to the boolean expression evaluation.
* #_of_comparison = n + n * Selectivity(C1) + n * Selectivity(C1 and C2) + ... + n * Selecitivity(C1 and C2 ... and C_n)
* cpu_cost = #_of_comparison * DrillCostBase_COMPARE_CPU_COST;
*/
private double estimateCpuCost(RelMetadataQuery mq) {
RelNode child = this.getInput();
double compNum = mq.getRowCount(child);
for (int i = 0; i < numConjuncts; i++) {
RexNode conjFilter = RexUtil.composeConjunction(this.getCluster().getRexBuilder(), conjunctions.subList(0, i + 1), false);
compNum += Filter.estimateFilteredRows(child, conjFilter);
}
return compNum * DrillCostBase.COMPARE_CPU_COST;
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class DrillLimitRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final Sort incomingSort = call.rel(0);
final RelTraitSet incomingTraits = incomingSort.getTraitSet();
RelNode input = incomingSort.getInput();
// limit information.
if (!incomingSort.getCollation().getFieldCollations().isEmpty()) {
input = incomingSort.copy(incomingTraits, input, incomingSort.getCollation(), null, null);
}
RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.DRILL_LOGICAL));
call.transformTo(new DrillLimitRel(incomingSort.getCluster(), convertedInput.getTraitSet().plus(DrillRel.DRILL_LOGICAL), convertedInput, incomingSort.offset, incomingSort.fetch));
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class HashAggPrule method createTransformRequest.
private void createTransformRequest(RelOptRuleCall call, DrillAggregateRel aggregate, RelNode input, RelTraitSet traits) throws InvalidRelException {
final RelNode convertedInput = convert(input, PrelUtil.fixTraits(call, traits));
HashAggPrel newAgg = new HashAggPrel(aggregate.getCluster(), traits, convertedInput, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList(), OperatorPhase.PHASE_1of1);
call.transformTo(newAgg);
}
Aggregations