for (Entry<String, String> entry : CloneTableUtils.cloneHTable(ht, newHT, oldws, factory, hnodes, selection).entrySet()) {
outputColumns.add(entry.getValue());
}
List<Row> resultRows = new ArrayList<Row>();
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;
}
}
Map<String, String> keyMapping = new HashMap<String, String>();
Map<String, String> HNodeidMapping = new HashMap<String, String>();
ArrayList<Row> rows = t.getRows(0, t.getNumRows(), selection);
for (Row row : rows) {
Node n = row.getNode(key.getId());
keyMapping.put(HashValueManager.getHashValue(oldws, n.getId(), factory), n.getValue().asString());
}
for (String mapkey : keyMapping.keySet()) {
HNode hn = newHT.getHNodeFromColumnName(keyMapping.get(mapkey).toLowerCase().replace('/', '_'));
if (hn == null) {
HNode n = newHT.addHNode(keyMapping.get(mapkey).toLowerCase().replace('/', '_'), HNodeType.Transformation, oldws, factory);
outputColumns.add(n.getId());
HTable htt = n.addNestedTable("values", oldws, factory);
outputColumns.add(htt.addHNode("Values", HNodeType.Transformation, oldws, factory).getId());
HNodeidMapping.put(keyMapping.get(mapkey), n.getId());
}
else
HNodeidMapping.put(keyMapping.get(mapkey), hn.getId());
}
Map<String, ArrayList<String>> hash = new HashMap<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);
//System.out.println("Hash: " + HashValueManager.getHashValue(row, hnodeIDs));
}
for (String hashKey : hash.keySet()) {
ArrayList<String> r = hash.get(hashKey);
Node node = parentRow.getNeighbor(newNode.getId());
Row lastRow = CloneTableUtils.cloneDataTable(factory.getRow(r.get(0)), node.getNestedTable(),
parentHT, newHT, hnodes, factory, selection);
for (String rowid : r) {
Row cur = factory.getRow(rowid);
String newId = HNodeidMapping.get(cur.getNode(key.getId()).getValue().asString());
Node newnode = lastRow.getNode(newId);
Node oldnode = cur.getNode(value.getId());
Row tmprow = newnode.getNestedTable().addRow(factory);
tmprow.getNeighborByColumnName("Values", factory).setValue(oldnode.getValue().asString(), oldnode.getStatus(), factory);
//newnode.setValue(oldnode.getValue().asString(), oldnode.getStatus(), factory);
}
resultRows.add(lastRow);
}
}
for (Row tmpRow : resultRows) {
for (Node node : tmpRow.getNodes()) {
if (node.hasNestedTable()) {
Table tmpTable = node.getNestedTable();
if (tmpTable.getNumRows() == 0) {
tmpTable.addRow(factory);
}
}
}
}