use of org.apache.calcite.rel.RelNode in project drill by apache.
the class HashJoinPrule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
PlannerSettings settings = PrelUtil.getPlannerSettings(call.getPlanner());
if (!settings.isHashJoinEnabled()) {
return;
}
final DrillJoinRel join = (DrillJoinRel) call.rel(0);
final RelNode left = join.getLeft();
final RelNode right = join.getRight();
if (!checkPreconditions(join, left, right, settings)) {
return;
}
boolean hashSingleKey = PrelUtil.getPlannerSettings(call.getPlanner()).isHashSingleKey();
try {
if (isDist) {
createDistBothPlan(call, join, PhysicalJoinType.HASH_JOIN, left, right, null, /* left collation */
null, /* right collation */
hashSingleKey);
} else {
if (checkBroadcastConditions(call.getPlanner(), join, left, right)) {
createBroadcastPlan(call, join, join.getCondition(), PhysicalJoinType.HASH_JOIN, left, right, null, /* left collation */
null);
}
}
} catch (InvalidRelException e) {
tracer.warning(e.toString());
}
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class HashToMergeExchangePrel method computeSelfCost.
@Override
public RelOptCost computeSelfCost(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 rowWidth = child.getRowType().getFieldCount() * DrillCostBase.AVG_FIELD_WIDTH;
double hashCpuCost = DrillCostBase.HASH_CPU_COST * inputRows * distFields.size();
double svrCpuCost = DrillCostBase.SVR_CPU_COST * inputRows;
double mergeCpuCost = DrillCostBase.COMPARE_CPU_COST * inputRows * (Math.log(numEndPoints) / Math.log(2));
double networkCost = DrillCostBase.BYTE_NETWORK_COST * inputRows * rowWidth;
DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
return costFactory.makeCost(inputRows, hashCpuCost + svrCpuCost + mergeCpuCost, 0, networkCost);
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class OrderedPartitionExchangePrel method computeSelfCost.
@Override
public RelOptCost computeSelfCost(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 rowWidth = child.getRowType().getFieldCount() * DrillCostBase.AVG_FIELD_WIDTH;
double rangePartitionCpuCost = DrillCostBase.RANGE_PARTITION_CPU_COST * inputRows;
double svrCpuCost = DrillCostBase.SVR_CPU_COST * inputRows;
double networkCost = DrillCostBase.BYTE_NETWORK_COST * inputRows * rowWidth;
DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
return costFactory.makeCost(inputRows, rangePartitionCpuCost + svrCpuCost, 0, networkCost);
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class HashToRandomExchangePrel method computeSelfCost.
/**
* HashToRandomExchange processes M input rows and hash partitions them
* based on computing a hash value on the distribution fields.
* If there are N nodes (endpoints), we can assume for costing purposes
* on average each sender will send M/N rows to 1 destination endpoint.
* (See DrillCostBase for symbol notations)
* Include impact of skewness of distribution : the more keys used, the less likely the distribution will be skewed.
* The hash cpu cost will be proportional to 1 / #_keys.
* C = CPU cost of hashing k fields of M/N rows
* + CPU cost of SV remover for M/N rows
* + Network cost of sending M/N rows to 1 destination.
* So, C = (h * 1/k * M/N) + (s * M/N) + (w * M/N)
* Total cost = N * C
*/
@Override
public RelOptCost computeSelfCost(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 rowWidth = child.getRowType().getFieldCount() * DrillCostBase.AVG_FIELD_WIDTH;
double hashCpuCost = DrillCostBase.HASH_CPU_COST * inputRows / fields.size();
double svrCpuCost = DrillCostBase.SVR_CPU_COST * inputRows;
double networkCost = DrillCostBase.BYTE_NETWORK_COST * inputRows * rowWidth;
DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
return costFactory.makeCost(inputRows, hashCpuCost + svrCpuCost, 0, networkCost);
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class JoinPruleBase method createDistBothPlan.
// Create join plan with both left and right children hash distributed. If the physical join type
// is MergeJoin, a collation must be provided for both left and right child and the plan will contain
// sort converter if necessary to provide the collation.
private void createDistBothPlan(RelOptRuleCall call, DrillJoinRel join, PhysicalJoinType physicalJoinType, RelNode left, RelNode right, RelCollation collationLeft, RelCollation collationRight, DrillDistributionTrait hashLeftPartition, DrillDistributionTrait hashRightPartition) throws InvalidRelException {
//DrillDistributionTrait hashLeftPartition = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(join.getLeftKeys())));
//DrillDistributionTrait hashRightPartition = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(join.getRightKeys())));
RelTraitSet traitsLeft = null;
RelTraitSet traitsRight = null;
if (physicalJoinType == PhysicalJoinType.MERGE_JOIN) {
assert collationLeft != null && collationRight != null;
traitsLeft = left.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collationLeft).plus(hashLeftPartition);
traitsRight = right.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collationRight).plus(hashRightPartition);
} else if (physicalJoinType == PhysicalJoinType.HASH_JOIN) {
traitsLeft = left.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(hashLeftPartition);
traitsRight = right.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(hashRightPartition);
}
final RelNode convertedLeft = convert(left, traitsLeft);
final RelNode convertedRight = convert(right, traitsRight);
DrillJoinRelBase newJoin = null;
if (physicalJoinType == PhysicalJoinType.HASH_JOIN) {
newJoin = new HashJoinPrel(join.getCluster(), traitsLeft, convertedLeft, convertedRight, join.getCondition(), join.getJoinType());
} else if (physicalJoinType == PhysicalJoinType.MERGE_JOIN) {
newJoin = new MergeJoinPrel(join.getCluster(), traitsLeft, convertedLeft, convertedRight, join.getCondition(), join.getJoinType());
}
call.transformTo(newJoin);
}
Aggregations