/** Marks all unassigned join predicates as well as exprs in aggInfo and sortInfo. */ @Override public void materializeRequiredSlots(Analyzer analyzer) { // Mark unassigned join predicates. Some predicates that must be evaluated by a join // can also be safely evaluated below the join (picked up by getBoundPredicates()). // Such predicates will be marked twice and that is ok. List<Expr> unassigned = analyzer.getUnassignedConjuncts(getTableRefIds(), true); List<Expr> unassignedJoinConjuncts = Lists.newArrayList(); for (Expr e : unassigned) { if (analyzer.evalByJoin(e)) unassignedJoinConjuncts.add(e); } List<Expr> baseTblJoinConjuncts = Expr.cloneList(unassignedJoinConjuncts, baseTblSmap_); materializeSlots(analyzer, baseTblJoinConjuncts); if (sortInfo_ != null) { // mark ordering exprs before marking agg exprs because the ordering exprs // may contain agg exprs that are not referenced anywhere but the ORDER BY clause List<Expr> resolvedExprs = Expr.cloneList(sortInfo_.getOrderingExprs(), baseTblSmap_); materializeSlots(analyzer, resolvedExprs); } if (aggInfo_ != null) { // mark all agg exprs needed for HAVING pred and binding predicates as materialized // before calling AggregateInfo.materializeRequiredSlots(), otherwise they won't // show up in AggregateInfo.getMaterializedAggregateExprs() ArrayList<Expr> havingConjuncts = Lists.newArrayList(); if (havingPred_ != null) havingConjuncts.add(havingPred_); // Ignore predicates bound to a group-by slot because those // are already evaluated below this agg node (e.g., in a scan). Set<SlotId> groupBySlots = Sets.newHashSet(); for (int i = 0; i < aggInfo_.getGroupingExprs().size(); ++i) { groupBySlots.add(aggInfo_.getAggTupleDesc().getSlots().get(i).getId()); } // Binding predicates are assigned to the final output tuple of the aggregation, // which is the tuple of the 2nd phase agg for distinct aggs. ArrayList<Expr> bindingPredicates = analyzer.getBoundPredicates(aggInfo_.getOutputTupleId(), groupBySlots); havingConjuncts.addAll(bindingPredicates); havingConjuncts.addAll( analyzer.getUnassignedConjuncts(aggInfo_.getOutputTupleId().asList(), false)); materializeSlots(analyzer, havingConjuncts); aggInfo_.materializeRequiredSlots(analyzer, baseTblSmap_); } }
@Override public void getMaterializedTupleIds(ArrayList<TupleId> tupleIdList) { // If select statement has an aggregate, then the aggregate tuple id is materialized. // Otherwise, all referenced tables are materialized. if (aggInfo_ != null) { // Return the tuple id produced in the final aggregation step. tupleIdList.add(aggInfo_.getOutputTupleId()); } else { for (TableRef tblRef : tableRefs_) { tupleIdList.addAll(tblRef.getMaterializedTupleIds()); } } }