예제 #1
0
 public Row select(String[] pFieldNames) {
   RowFormat newFormat = mFormat.select(pFieldNames);
   Row newRow = (Row) newFormat.getRowFactory().makeRow();
   for (int i = 0; i < pFieldNames.length; i++) {
     String fieldName = pFieldNames[i];
     newRow.set(fieldName, get(fieldName));
   }
   return newRow;
 }
예제 #2
0
  public Row join(Row pRow, String pField) {
    // dbgMsg("Join!");
    RowFormat newFormat = mFormat.join(pRow.mFormat, pField);
    Row newRow = (Row) newFormat.getRowFactory().makeRow();
    // String[] ourFieldNames = mFormat.getFieldNames();
    // String[] theirFieldNames =pRow.mFormat.getFieldNames();
    // dbgMsg("ourFieldNames="+StringUtils.arrayToString(ourFieldNames, ", "));
    // dbgMsg("theirFieldNames="+StringUtils.arrayToString(theirFieldNames, ", "));

    HashSet ourFields = new HashSet(Arrays.asList(mFormat.getFieldNames()));
    HashSet theirFields = new HashSet(Arrays.asList(pRow.mFormat.getFieldNames()));
    ourFields.remove(pField);
    theirFields.remove(pField);
    HashSet commonFields = new HashSet(ourFields);
    commonFields.retainAll(theirFields);
    ourFields.removeAll(commonFields);
    theirFields.removeAll(commonFields);

    // dbgMsg("join field "+pField);
    // dbgMsg("our fields: "+StringUtils.collectionToString(ourFields, " "));
    // dbgMsg("their fields: "+StringUtils.collectionToString(theirFields, " "));
    // dbgMsg("common fields: "+StringUtils.collectionToString(commonFields, " "));

    // copy join field
    newRow.set(pField, get(pField)); // (copied arbitrarily from...us, as should be same!)

    // copy our fields
    Iterator ourFieldsIter = ourFields.iterator();
    while (ourFieldsIter.hasNext()) {
      String field = (String) ourFieldsIter.next();
      newRow.set(field, (get(field)));
    }

    // copy their fields
    Iterator theirFieldsIter = theirFields.iterator();
    while (theirFieldsIter.hasNext()) {
      String field = (String) theirFieldsIter.next();
      newRow.set(field, (pRow.get(field)));
    }

    // copy common fields (renaming fields becomes necessary)
    Iterator commonFieldsIter = commonFields.iterator();
    while (commonFieldsIter.hasNext()) {
      String field = (String) commonFieldsIter.next();
      newRow.set(field + "1", (get(field)));
      newRow.set(field + "2", (pRow.get(field)));
    }

    return newRow;
  }