@Override public boolean matches(RelOptRuleCall call) { // Currently we do not support merging windowing functions with other // windowing functions i.e. embedding windowing functions within each // other final Project topProject = call.rel(0); final Project bottomProject = call.rel(1); for (RexNode expr : topProject.getChildExps()) { if (expr instanceof RexOver) { Set<Integer> positions = HiveCalciteUtil.getInputRefs(expr); for (int pos : positions) { if (bottomProject.getChildExps().get(pos) instanceof RexOver) { return false; } } } } return super.matches(call); }
/** * Translate a field access, possibly through a projection, to an underlying Druid dataSource. * * @param rowSignature row signature of underlying Druid dataSource * @param project projection, or null * @param fieldNumber number of the field to access * * @return row expression */ public static RexNode fromFieldAccess( final RowSignature rowSignature, final Project project, final int fieldNumber ) { if (project == null) { // I don't think the factory impl matters here. return RexInputRef.of(fieldNumber, rowSignature.getRelDataType(new JavaTypeFactoryImpl())); } else { return project.getChildExps().get(fieldNumber); } }
@Override public boolean matches(RelOptRuleCall call) { // Currently we do not support merging windowing functions with other // windowing functions i.e. embedding windowing functions within each // other final Project topProject = call.rel(0); final Project bottomProject = call.rel(1); for (RexNode expr : topProject.getChildExps()) { if (expr instanceof RexOver) { Set<Integer> positions = HiveCalciteUtil.getInputRefs(expr); for (int pos : positions) { if (bottomProject.getChildExps().get(pos) instanceof RexOver) { return false; } } } } return super.matches(call); }
protected static String generateInvalidSchemaMessage(Project topLevelProj, List<FieldSchema> resultSchema, int fieldsForOB) { String errorDesc = "Result Schema didn't match Calcite Optimized Op Tree; schema: "; for (FieldSchema fs : resultSchema) { errorDesc += "[" + fs.getName() + ":" + fs.getType() + "], "; } errorDesc += " projection fields: "; for (RexNode exp : topLevelProj.getChildExps()) { errorDesc += "[" + exp.toString() + ":" + exp.getType() + "], "; } if (fieldsForOB != 0) { errorDesc += fieldsForOB + " fields removed due to ORDER BY "; } return errorDesc.substring(0, errorDesc.length() - 2); }
@Override public boolean matches(final RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final Project project = call.rel(1); if (aggregate.indicator || aggregate.getGroupSets().size() != 1) { return false; } for (AggregateCall aggregateCall : aggregate.getAggCallList()) { if (isOneArgAggregateCall(aggregateCall) && isThreeArgCase(project.getChildExps().get(Iterables.getOnlyElement(aggregateCall.getArgList())))) { return true; } } return false; }
public RelNode align(Project rel, List<RelFieldCollation> collations) { // 1) We extract the collations indices boolean containsWindowing = false; for (RexNode childExp : rel.getChildExps()) { if (childExp instanceof RexOver) { // TODO: support propagation for partitioning/ordering in windowing containsWindowing = true; break; } } ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder(); if (!containsWindowing) { for (RelFieldCollation c : collations) { RexNode rexNode = rel.getChildExps().get(c.getFieldIndex()); if (rexNode instanceof RexInputRef) { int newIdx = ((RexInputRef) rexNode).getIndex(); propagateCollations.add(c.copy((newIdx))); } } } // 2) We propagate final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build()); // 3) Return new Project return rel.copy(rel.getTraitSet(), ImmutableList.of(child)); }
protected static String generateInvalidSchemaMessage(Project topLevelProj, List<FieldSchema> resultSchema, int fieldsForOB) { String errorDesc = "Result Schema didn't match Calcite Optimized Op Tree; schema: "; for (FieldSchema fs : resultSchema) { errorDesc += "[" + fs.getName() + ":" + fs.getType() + "], "; } errorDesc += " projection fields: "; for (RexNode exp : topLevelProj.getChildExps()) { errorDesc += "[" + exp.toString() + ":" + exp.getType() + "], "; } if (fieldsForOB != 0) { errorDesc += fieldsForOB + " fields removed due to ORDER BY "; } return errorDesc.substring(0, errorDesc.length() - 2); }
for (final RexNode rexNode : project.getChildExps()) { final DruidExpression expression = Expressions.toDruidExpression( plannerContext, expression.toVirtualColumn( virtualColumnName, Calcites.getValueTypeForSqlTypeName(project.getChildExps().get(i).getType().getSqlTypeName()), plannerContext.getExprMacroTable()
private static RexCall adjustOBSchema(RexCall obyExpr, Project obChild, List<FieldSchema> resultSchema) { int a = -1; List<RexNode> operands = new ArrayList<>(); for (int k = 0; k < obyExpr.operands.size(); k++) { RexNode rn = obyExpr.operands.get(k); for (int j = 0; j < resultSchema.size(); j++) { if( obChild.getChildExps().get(j).toString().equals(rn.toString())) { a = j; break; } } if (a != -1) { operands.add(new RexInputRef(a, rn.getType())); } else { if (rn instanceof RexCall) { operands.add(adjustOBSchema((RexCall)rn, obChild, resultSchema)); } else { operands.add(rn); } } a = -1; } return (RexCall) obChild.getCluster().getRexBuilder().makeCall( obyExpr.getType(), obyExpr.getOperator(), operands); }
cost += COST_PER_COLUMN * partialQuery.getSelectProject().getChildExps().size(); cost += COST_PER_COLUMN * partialQuery.getAggregateProject().getChildExps().size(); cost += COST_PER_COLUMN * partialQuery.getSortProject().getChildExps().size();
for (final RexNode postAggregatorRexNode : project.getChildExps()) {
@Override public RelOptMaterialization apply(RelOptMaterialization materialization) { final RelNode viewScan = materialization.tableRel; final RelNode newViewScan; if (viewScan instanceof Project) { // There is a Project on top (due to nullability) final Project pq = (Project) viewScan; newViewScan = HiveProject.create(optCluster, copyNodeScan(pq.getInput()), pq.getChildExps(), pq.getRowType(), Collections.<RelCollation> emptyList()); } else { newViewScan = copyNodeScan(viewScan); } return new RelOptMaterialization(newViewScan, materialization.queryRel, null, materialization.qualifiedTableName); }
private void fetchColStats(RelNode key, TableScan tableAccessRel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) { final List<Integer> iRefSet = Lists.newArrayList(); if (key instanceof Project) { final Project project = (Project) key; for (RexNode rx : project.getChildExps()) { iRefSet.addAll(HiveCalciteUtil.getInputRefs(rx)); } } else { final int fieldCount = tableAccessRel.getRowType().getFieldCount(); if (fieldsUsed.equals(ImmutableBitSet.range(fieldCount)) && extraFields.isEmpty()) { // get all cols iRefSet.addAll(ImmutableBitSet.range(fieldCount).asList()); } } //Remove any virtual cols if (tableAccessRel instanceof HiveTableScan) { iRefSet.removeAll(((HiveTableScan)tableAccessRel).getVirtualCols()); } if (!iRefSet.isEmpty()) { final RelOptTable table = tableAccessRel.getTable(); if (table instanceof RelOptHiveTable) { ((RelOptHiveTable) table).getColStat(iRefSet, true); LOG.debug("Got col stats for {} in {}", iRefSet, tableAccessRel.getTable().getQualifiedName()); } } }
listBuilder.add(leftPartialQuery.getSelectProject().getChildExps().get(key));
@Override public void onMatch(RelOptRuleCall call) { final Project project = call.rel(0); final Join join = call.rel(1); final RelNode left = call.rel(2); final Aggregate aggregate = call.rel(3); final ImmutableBitSet topRefs = RelOptUtil.InputFinder.bits(project.getChildExps(), null); perform(call, topRefs, project, join, left, aggregate); } }
public void onMatch(RelOptRuleCall call) { final Project topProject = call.rel(0); final Project bottomProject = call.rel(1); // If top project does not reference any column at the bottom project, // we can just remove botton project final ImmutableBitSet topRefs = RelOptUtil.InputFinder.bits(topProject.getChildExps(), null); if (topRefs.isEmpty()) { RelBuilder relBuilder = call.builder(); relBuilder.push(bottomProject.getInput()); relBuilder.project(topProject.getChildExps()); call.transformTo(relBuilder.build()); return; } super.onMatch(call); }
public Result translate(Project e) { // This variant is for the top project as we want to keep // the column aliases instead of producing STAR Result x = visitChild(0, e.getInput()); parseCorrelTable(e, x); final Builder builder = x.builder(e, Clause.SELECT); final List<SqlNode> selectList = new ArrayList<>(); for (RexNode ref : e.getChildExps()) { SqlNode sqlExpr = builder.context.toSql(null, ref); addSelect(selectList, sqlExpr, e.getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); return builder.result(); }
final Aggregate aggregate = call.rel(1); final ImmutableBitSet projectBits = RelOptUtil.InputFinder.bits(project.getChildExps(), null); .push(newAggregate) .project(fixUpProjects) .project(project.getChildExps()) .build() );
public void onMatch(RelOptRuleCall call) { final Project project = call.rel(0); final Filter filter = call.rel(1); final RelBuilder builder = call.builder(); List<RexNode> projects = project.getChildExps(); List<RexNode> newProjects = rewriteProjects(projects, filter.getCondition(), builder); if (newProjects == null) { return; } RelNode newProjRel = builder.push(filter) .project(newProjects, project.getRowType().getFieldNames()).build(); call.transformTo(newProjRel); }
public void onMatch(RelOptRuleCall call) { final Project project = call.rel(0); final Filter filter = call.rel(1); final RelBuilder builder = call.builder(); List<RexNode> projects = project.getChildExps(); List<RexNode> newProjects = rewriteProjects(projects, filter.getCondition(), builder); if (newProjects == null) { return; } RelNode newProjRel = builder.push(filter) .project(newProjects, project.getRowType().getFieldNames()).build(); call.transformTo(newProjRel); }