Exemplo n.º 1
0
  /** Unit test for Tuple.resetTupleDesc() */
  @Test
  public void resetTupleDesc() {
    // create a tuple with the original tuple desc
    TupleDesc origTd = Utility.getTupleDesc(2, "orig");
    Tuple tup = new Tuple(origTd);
    assertEquals("orig0", tup.getTupleDesc().getFieldName(0));

    // rename the fields by changing the tuple desc to a new one
    TupleDesc newTd = Utility.getTupleDesc(2, "new");
    tup.resetTupleDesc(newTd);
    assertEquals("new0", tup.getTupleDesc().getFieldName(0));
  }
Exemplo n.º 2
0
  /**
   * Merge a new tuple into the aggregate, grouping as indicated in the constructor
   *
   * @param tup the Tuple containing an aggregate field and a group-by field
   */
  public void mergeTupleIntoGroup(Tuple tup) {
    if (this.groupByFieldName == null && this.groupByField != NO_GROUPING) {
      this.groupByFieldName = tup.getTupleDesc().getFieldName(this.groupByField);
    }

    Field key;
    if (this.groupByField != NO_GROUPING) {
      key = tup.getField(this.groupByField);
    } else {
      key = new IntField(-1);
    }

    // TODO: clean up average logic
    int aggregationValue = ((IntField) tup.getField(this.aggregateField)).getValue();
    if (this.groups.containsKey(key)) {
      this.groups.put(key, this.performOperation(key, this.groups.get(key), aggregationValue));
      if (this.op == Op.AVG) {
        this.counts.put(key, this.counts.get(key) + 1);
      }
    } else {
      this.groups.put(key, this.initValue(aggregationValue));
      if (this.op == Op.AVG) {
        this.counts.put(key, 1);
      }
    }
  }
Exemplo n.º 3
0
 /**
  * Adds the specified tuple to the page; the tuple should be updated to reflect that it is now
  * stored on this page.
  *
  * @throws DbException if the page is full (no empty slots) or tupledesc is mismatch.
  * @param t The tuple to add.
  */
 public void insertTuple(Tuple t) throws DbException {
   // some code goes here
   // not necessary for lab1
   RecordId targetrid = t.getRecordId();
   if (getNumEmptySlots() == 0 || !td.equals(t.getTupleDesc())) {
     throw new DbException("Either page is full or tuple desc doesn't match");
   }
   for (int i = 0; i < getNumTuples(); i++) {
     if (!isSlotUsed(i)) {
       markSlotUsed(i, true);
       RecordId rid = new RecordId(pid, i);
       t.setRecordId(rid);
       tuples[i] = t;
       return;
     }
   }
 }
Exemplo n.º 4
0
 /** Unit test for Tuple.getTupleDesc() */
 @Test
 public void getTupleDesc() {
   TupleDesc td = Utility.getTupleDesc(5);
   Tuple tup = new Tuple(td);
   assertEquals(td, tup.getTupleDesc());
 }