MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / open

Method open

src/java/simpledb/execution/AggregateIter.java:41–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39
40
41 @Override
42 public void open() throws DbException, TransactionAbortedException {
43 this.resultSet = new ArrayList<>();
44 if(what == Aggregator.Op.COUNT){
45 for(Field field:group.keySet()){
46 Tuple tuple = new Tuple(this.tupleDesc);
47 if(field!=null){
48 tuple.setField(0,field);
49 tuple.setField(1,new IntField(group.get(field).size()));
50 }else{
51 tuple.setField(1,new IntField(group.get(field).size()));
52 }
53 this.resultSet.add(tuple);
54 }
55 }else if(what == Aggregator.Op.MIN){
56 for(Field field:group.keySet()){
57 int min = Integer.MAX_VALUE;
58 Tuple tuple = new Tuple(tupleDesc);
59 for(int i=0;i<this.group.get(field).size();i++){
60 IntField field1 = (IntField)group.get(field).get(i);
61 if(field1.getValue()<min){
62 min = field1.getValue();
63 }
64 }
65 if(field!=null){
66 tuple.setField(0,field);
67 tuple.setField(1,new IntField(min));
68 }else{
69 tuple.setField(0,new IntField(min));
70 }
71 resultSet.add(tuple);
72 }
73 }else if(what == Aggregator.Op.MAX){
74 for(Field field:group.keySet()){
75 int max = Integer.MIN_VALUE;
76 Tuple tuple = new Tuple(tupleDesc);
77 for(int i=0;i<this.group.get(field).size();i++){
78 IntField field1 = (IntField)group.get(field).get(i);
79 if(field1.getValue()>max){
80 max = field1.getValue();
81 }
82 }
83 if(field!=null){
84 tuple.setField(0,field);
85 tuple.setField(1,new IntField(max));
86 }else{
87 tuple.setField(0,new IntField(max));
88 }
89 resultSet.add(tuple);
90 }
91 }else if(what == Aggregator.Op.AVG){
92 for(Field field: this.group.keySet()){
93 int sum = 0;
94 int size = this.group.get(field).size();
95 Tuple tuple = new Tuple(tupleDesc);
96 for(int i=0;i<size;i++){
97 IntField field1 = (IntField) group.get(field).get(i);
98 sum += field1.getValue();

Callers

nothing calls this directly

Calls 4

setFieldMethod · 0.95
getValueMethod · 0.95
getMethod · 0.80
iteratorMethod · 0.65

Tested by

no test coverage detected