use of org.apache.calcite.rex.RexNode in project drill by apache.
the class DrillRelOptUtil method containIdentity.
/**
* Returns whether the leading edge of a given array of expressions is
* wholly {@link RexInputRef} objects with types and names corresponding
* to the underlying row type. */
private static boolean containIdentity(List<? extends RexNode> exps, RelDataType rowType, RelDataType childRowType) {
List<RelDataTypeField> fields = rowType.getFieldList();
List<RelDataTypeField> childFields = childRowType.getFieldList();
int fieldCount = childFields.size();
if (exps.size() != fieldCount) {
return false;
}
for (int i = 0; i < exps.size(); i++) {
RexNode exp = exps.get(i);
if (!(exp instanceof RexInputRef)) {
return false;
}
RexInputRef var = (RexInputRef) exp;
if (var.getIndex() != i) {
return false;
}
if (!fields.get(i).getName().equals(childFields.get(i).getName())) {
return false;
}
if (!fields.get(i).getType().equals(childFields.get(i).getType())) {
return false;
}
}
return true;
}
use of org.apache.calcite.rex.RexNode 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.rex.RexNode in project drill by apache.
the class ConvertHiveParquetScanToDrillParquetScan method createProjectRel.
/**
* Create a project that converts the native scan output to expected output of Hive scan.
*/
private DrillProjectRel createProjectRel(final DrillScanRel hiveScanRel, final Map<String, String> partitionColMapping, final DrillScanRel nativeScanRel) {
final List<RexNode> rexNodes = Lists.newArrayList();
final RexBuilder rb = hiveScanRel.getCluster().getRexBuilder();
final RelDataType hiveScanRowType = hiveScanRel.getRowType();
for (String colName : hiveScanRowType.getFieldNames()) {
final String dirColName = partitionColMapping.get(colName);
if (dirColName != null) {
rexNodes.add(createPartitionColumnCast(hiveScanRel, nativeScanRel, colName, dirColName, rb));
} else {
rexNodes.add(createColumnFormatConversion(hiveScanRel, nativeScanRel, colName, rb));
}
}
return DrillProjectRel.create(hiveScanRel.getCluster(), hiveScanRel.getTraitSet(), nativeScanRel, rexNodes, hiveScanRowType);
}
use of org.apache.calcite.rex.RexNode in project drill by apache.
the class ProjectAllowDupPrel method getProjectExpressions.
@Override
protected List<NamedExpression> getProjectExpressions(DrillParseContext context) {
List<NamedExpression> expressions = Lists.newArrayList();
for (Pair<RexNode, String> pair : Pair.zip(exps, getRowType().getFieldNames())) {
LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), pair.left);
expressions.add(new NamedExpression(expr, FieldReference.getWithQuotedRef(pair.right)));
}
return expressions;
}
use of org.apache.calcite.rex.RexNode in project drill by apache.
the class LimitUnionExchangeTransposeRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final LimitPrel limit = (LimitPrel) call.rel(0);
final UnionExchangePrel unionExchangePrel = (UnionExchangePrel) call.rel(1);
RelNode child = unionExchangePrel.getInput();
final int offset = limit.getOffset() != null ? Math.max(0, RexLiteral.intValue(limit.getOffset())) : 0;
final int fetch = Math.max(0, RexLiteral.intValue(limit.getFetch()));
// child Limit uses conservative approach: use offset 0 and fetch = parent limit offset + parent limit fetch.
final RexNode childFetch = limit.getCluster().getRexBuilder().makeExactLiteral(BigDecimal.valueOf(offset + fetch));
final RelNode limitUnderExchange = new LimitPrel(child.getCluster(), child.getTraitSet(), child, null, childFetch);
final RelNode newUnionExch = new UnionExchangePrel(unionExchangePrel.getCluster(), unionExchangePrel.getTraitSet(), limitUnderExchange);
final RelNode limitAboveExchange = new LimitPrel(limit.getCluster(), limit.getTraitSet(), newUnionExch, limit.getOffset(), limit.getFetch(), true);
call.transformTo(limitAboveExchange);
}
Aggregations