Constructor. Implementation hint: depending on the type of afield, you will want to construct an IntegerAggregator or StringAggregator to help you with your implementation of readNext(). @param child The OpIterator that is feeding us tuples. @param afield The column over which
(OpIterator child, int afield, int gfield, Aggregator.Op aop)
| 40 | * @param aop The aggregation operator to use |
| 41 | */ |
| 42 | public Aggregate(OpIterator child, int afield, int gfield, Aggregator.Op aop) { |
| 43 | // some code goes here |
| 44 | this.child = child; |
| 45 | this.afield = afield; |
| 46 | this.gfield = gfield; |
| 47 | this.aop = aop; |
| 48 | Type fieldType = child.getTupleDesc().getFieldType(afield); |
| 49 | if(gfield!=-1){ |
| 50 | if(fieldType.equals(Type.INT_TYPE)){ |
| 51 | //这里要改一下 |
| 52 | aggregator = new IntegerAggregator(gfield,child.getTupleDesc().getFieldType(gfield),afield,aop); |
| 53 | }else if(fieldType.equals(Type.STRING_TYPE)){ |
| 54 | aggregator = new StringAggregator(gfield,child.getTupleDesc().getFieldType(gfield),afield,aop); |
| 55 | }else{ |
| 56 | aggregator = null; |
| 57 | } |
| 58 | }else{ |
| 59 | if(fieldType.equals(Type.INT_TYPE)){ |
| 60 | aggregator = new IntegerAggregator(gfield,null,afield,aop); |
| 61 | }else if(fieldType.equals(Type.STRING_TYPE)){ |
| 62 | aggregator = new StringAggregator(gfield,null,afield,aop); |
| 63 | }else{ |
| 64 | aggregator = null; |
| 65 | } |
| 66 | } |
| 67 | this.opIterator = aggregator.iterator(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @return If this aggregate is accompanied by a groupby, return the groupby |
nothing calls this directly
no test coverage detected