Esempio n. 1
0
  @Test
  public void new_getFieldNameTest() {
    int length = 100;
    String name = "td";
    TupleDesc td = Utility.getTupleDesc(length, name);

    // Lower than index bound.
    try {
      td.getFieldName(length + 1);
      fail("expected exception");
    } catch (NoSuchElementException e) {
    }

    // Higher than index bound.
    try {
      td.getFieldName(-1);
      fail("expected exception");
    } catch (NoSuchElementException e) {
    }

    // Check each name.
    for (int i = 0; i < length; i++) {
      assertEquals(name + i, td.getFieldName(i));
    }
  }
Esempio n. 2
0
 /**
  * Returns the TupleDesc with field names from the underlying HeapFile, prefixed with the
  * tableAlias string from the constructor. This prefix becomes useful when joining tables
  * containing a field(s) with the same name.
  *
  * @return the TupleDesc with field names from the underlying HeapFile, prefixed with the
  *     tableAlias string from the constructor.
  */
 public TupleDesc getTupleDesc() {
   TupleDesc tup = Database.getCatalog().getTupleDesc(id);
   int length = tup.numFields();
   String[] field = new String[length];
   Type[] types = new Type[length];
   for (int i = 0; i < length; i++) {
     types[i] = tup.getFieldType(i);
     field[i] = alias + "." + tup.getFieldName(i);
   }
   return new TupleDesc(types, field);
 }
Esempio n. 3
0
  /** Test one prarmeter constructor, it should set the filed name to null. */
  @Test
  public void new_oneParamsConTest() {
    int[] lengths = new int[] {1, 2, 1000};

    for (int len : lengths) {
      TupleDesc td = Utility.getTupleDesc(len);
      for (int i = 0; i < len; i++) {
        assertEquals("", td.getFieldName(i));
      }
    }
  }
Esempio n. 4
0
  /** Ensures that combined's field names = td1's field names + td2's field names */
  private boolean combinedStringArrays(TupleDesc td1, TupleDesc td2, TupleDesc combined) {
    for (int i = 0; i < td1.numFields(); i++) {
      if (!(((td1.getFieldName(i) == null) && (combined.getFieldName(i) == null))
          || td1.getFieldName(i).equals(combined.getFieldName(i)))) {
        return false;
      }
    }

    for (int i = td1.numFields(); i < td1.numFields() + td2.numFields(); i++) {
      if (!(((td2.getFieldName(i - td1.numFields()) == null) && (combined.getFieldName(i) == null))
          || td2.getFieldName(i - td1.numFields()).equals(combined.getFieldName(i)))) {
        return false;
      }
    }

    return true;
  }
Esempio n. 5
0
 private void createAliasedTd() {
   Catalog gc = Database.getCatalog();
   TupleDesc old_td = gc.getTupleDesc(tableid);
   String[] newFieldAr = new String[old_td.numFields()];
   Type[] typeAr = new Type[old_td.numFields()];
   String field = null;
   for (int i = 0; i < newFieldAr.length; i++) {
     field = old_td.getFieldName(i);
     if (alias == null) {
       alias = "null";
     } else if (field == null) {
       field = "null";
     }
     newFieldAr[i] = alias + "." + field;
     typeAr[i] = old_td.getFieldType(i);
   }
   td = new TupleDesc(typeAr, newFieldAr);
 }