for (Table tmp : parentTables) {
for (Row row : tmp.getRows(0, tmp.getNumRows(), selection)) {
parentRows.add(row);
}
}
HNode newNode = parentHT.addHNode(parentHT.getNewColumnName("GroupBy"), HNodeType.Transformation, oldws, factory);
newHNodeId = newNode.getId();
outputColumns.add(newNode.getId());
HTable newht = newNode.addNestedTable(newNode.getColumnName(), oldws, factory);
for (Entry<String, String> entry : CloneTableUtils.cloneHTable(ht, newht, oldws, factory, keyhnodes, selection).entrySet()) {
outputColumns.add(entry.getValue());
}
outputColumns.add(newht.addHNode("Values", HNodeType.Transformation, oldws, factory).getId());
HTable newValueTable = newht.getHNodeFromColumnName("Values").addNestedTable("Table for values", oldws, factory);
for (Entry<String, String> entry : CloneTableUtils.cloneHTable(ht, newValueTable, oldws, factory, valuehnodes, selection).entrySet()) {
outputColumns.add(entry.getValue());
}
for (Row parentRow : parentRows) {
Table t = null;
for (Node node : parentRow.getNodes()) {
if (node.hasNestedTable() && node.getNestedTable().getHTableId().compareTo(ht.getId()) == 0) {
t = node.getNestedTable();
break;
}
}
ArrayList<Row> rows = t.getRows(0, t.getNumRows(), selection);
Map<String, ArrayList<String>> hash = new TreeMap<String, ArrayList<String>>();
for (Row row : rows) {
String hashValue = HashValueManager.getHashValue(row, hnodeIDs);
ArrayList<String> ids = hash.get(hashValue);
if (ids == null)
ids = new ArrayList<String>();
ids.add(row.getId());
hash.put(hashValue, ids);
}
for (String key : hash.keySet()) {
ArrayList<String> r = hash.get(key);
Node node = parentRow.getNeighbor(newNode.getId());
Row lastRow = CloneTableUtils.cloneDataTable(factory.getRow(r.get(0)), node.getNestedTable(), ht, newht, keyhnodes, factory, selection);
for (String rowid : r) {
Row cur = factory.getRow(rowid);
Table dataTable = lastRow.getNeighborByColumnName("Values", factory).getNestedTable();
CloneTableUtils.cloneDataTable(cur, dataTable, ht, newValueTable, valuehnodes, factory, selection);