use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class Joiner method compareDuplicates.
/**
* @param leftTable The left input table
* @param rightTable The right input table
* @param duplicates The list of columns to test for identity
*/
private void compareDuplicates(final BufferedDataTable leftTable, final BufferedDataTable rightTable, final List<String> duplicates) {
int[] leftIndex = getIndicesOf(leftTable, duplicates);
int[] rightIndex = getIndicesOf(rightTable, duplicates);
String[] messages = new String[duplicates.size()];
CloseableRowIterator leftIter = leftTable.iterator();
CloseableRowIterator rightIter = rightTable.iterator();
while (leftIter.hasNext()) {
if (!rightIter.hasNext()) {
// right table has less rows
m_runtimeWarnings.add("Possible problem in configuration " + "found. The \"Duplicate Column Handling\" is " + "configured to filter duplicates, but the " + "duplicate columns are not equal since the " + "top table has more elements than the bottom " + "table.");
break;
}
DataRow left = leftIter.next();
DataRow right = rightIter.next();
for (int i = 0; i < duplicates.size(); i++) {
if (null == messages[i] && !left.getCell(leftIndex[i]).equals(right.getCell(rightIndex[i]))) {
// Two cells do not match
messages[i] = "The column \"" + duplicates.get(i) + "\" can be found in " + "both input tables but the content is not " + "equal. " + "Only the one in the top input table will show " + "up in the output table. Please change the " + "Duplicate Column Handling if both columns " + "should show up in the output table.";
}
}
}
if (rightIter.hasNext()) {
// right table has more rows
m_runtimeWarnings.add("Possible problem in configuration found. " + "The \"Duplicate Column Handling\" is configured to " + "filter duplicates, but the duplicate columns are not " + "equal since the bottom table has more elements than the " + "top table.");
}
for (int i = 0; i < duplicates.size(); i++) {
if (null != messages[i]) {
m_runtimeWarnings.add(messages[i]);
}
}
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class CrossJoinerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
boolean showLeft = m_showLeft.getBooleanValue();
boolean showRight = m_showRight.getBooleanValue();
int chunksize = m_cacheSize.getIntValue();
String sep = m_rkseparator.getStringValue();
DataContainer dc = exec.createDataContainer(createSpec(inData[0].getDataTableSpec(), inData[1].getDataTableSpec(), showLeft, showRight));
long numOutRows = inData[0].size() * inData[1].size();
long rowcounter = 0;
CloseableRowIterator leftit = inData[0].iterator();
// iterate over all possible chunks of left table
for (long chunkcount = 0; chunkcount < Math.ceil(inData[0].size() * 1.0 / chunksize); chunkcount++) {
// read one chunk of left table
List<DataRow> rowsleft = new LinkedList<DataRow>();
for (int i = 0; i < chunksize && leftit.hasNext(); i++) {
rowsleft.add(leftit.next());
exec.checkCanceled();
}
// iterate over all possible chunks of right table
CloseableRowIterator rightit = inData[1].iterator();
for (long chunkcount2 = 0; chunkcount2 < Math.ceil(inData[1].size() * 1.0 / chunksize); chunkcount2++) {
// read one chunk of right table
List<DataRow> rowsright = new LinkedList<DataRow>();
for (int i = 0; i < chunksize && rightit.hasNext(); i++) {
rowsright.add(rightit.next());
}
for (DataRow left : rowsleft) {
for (DataRow right : rowsright) {
DataRow newRow = joinRow(left, right, showLeft, showRight, sep);
dc.addRowToTable(newRow);
exec.checkCanceled();
exec.setProgress(rowcounter++ / (double) numOutRows, "Generating Row " + newRow.getKey().toString());
}
}
}
rightit.close();
}
leftit.close();
dc.close();
return new BufferedDataTable[] { (BufferedDataTable) dc.getTable() };
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class EditNominalDomainDicNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable additionalValues = inData[1];
final DataTableSpec orgSpec = inData[0].getDataTableSpec();
final DataTableSpec valueSpec = additionalValues.getDataTableSpec();
Map<Integer, Set<DataCell>> doCreateSpec = createNewSpec(orgSpec, valueSpec, new NewDomainValuesAdder<CanceledExecutionException>() {
private long m_currentRowIndex = 0;
private final long m_size = additionalValues.size();
@Override
void addNewDomainValues(final Map<Integer, String> orgIndexToColNameMap, final Map<Integer, Set<DataCell>> orgIndexToNewDomainValuesMap) throws CanceledExecutionException {
CloseableRowIterator addValuesIterator = additionalValues.iterator();
try {
Collection<String> values = orgIndexToColNameMap.values();
while (addValuesIterator.hasNext()) {
DataRow currRow = addValuesIterator.next();
//
exec.setProgress(//
m_currentRowIndex++ / (double) m_size, "adding values to domain of row: " + currRow.getKey().getString());
for (String addValRowId : values) {
DataCell cell = currRow.getCell(valueSpec.findColumnIndex(addValRowId));
if (!cell.isMissing()) {
orgIndexToNewDomainValuesMap.get(orgSpec.findColumnIndex(addValRowId)).add(cell);
}
}
exec.checkCanceled();
}
} finally {
addValuesIterator.close();
}
}
});
return new BufferedDataTable[] { exec.createSpecReplacerTable(inData[0], mergeTableSpecs(orgSpec, doCreateSpec).createSpec()) };
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class EditNumericDomainNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
//
final DataTableSpec originalTableSpec = inData[0].getDataTableSpec();
DataTableSpec editedTableSpec = processDomainSettings(inData[0].getDataTableSpec());
FilterResult filterResult = m_configuration.getColumnspecFilterConfig().applyTo(originalTableSpec);
List<String> includedColumnNames = Arrays.asList(filterResult.getIncludes());
long currentRowIndex = 0;
long size = inData[0].size();
String[] tableNames = originalTableSpec.getColumnNames();
Map<Integer, DataColumnSpec> map = new HashMap<Integer, DataColumnSpec>();
for (int i = 0; i < originalTableSpec.getNumColumns(); i++) {
if (includedColumnNames.contains(tableNames[i])) {
map.put(i, editedTableSpec.getColumnSpec(i));
} else {
map.put(i, originalTableSpec.getColumnSpec(i));
}
}
CloseableRowIterator rowIterator = inData[0].iterator();
long rowIndex = 0;
try {
while (rowIterator.hasNext()) {
DataRow currentRow = rowIterator.next();
//
exec.setProgress(//
currentRowIndex++ / (double) size, "checking domains of row: " + currentRow.getKey().getString());
for (String colName : includedColumnNames) {
int currIndex = originalTableSpec.findColumnIndex(colName);
DataCell currCell = currentRow.getCell(currIndex);
if (!currCell.isMissing() && outOfDomain(currCell, map.get(currIndex))) {
switch(m_configuration.getDomainOverflowPolicy()) {
case CALCULATE_BOUNDS:
map.put(currIndex, calculateAndCreateBoundedColumnSpec(currCell, map.get(currIndex)));
break;
case USE_EXISTING_BOUNDS:
map.put(currIndex, originalTableSpec.getColumnSpec(currIndex));
break;
default:
throw new EditNumericDomainOverflowException(tableNames[currIndex], ((DoubleValue) currCell).getDoubleValue(), m_configuration.getLowerBound(), m_configuration.getUpperBound(), rowIndex, currentRow.getKey());
}
}
}
exec.checkCanceled();
rowIndex++;
}
} finally {
rowIterator.close();
}
DataTableSpecCreator newTableSpecCreator = new DataTableSpecCreator().setName(originalTableSpec.getName()).putProperties(originalTableSpec.getProperties());
for (int i = 0; i < originalTableSpec.getNumColumns(); i++) {
newTableSpecCreator.addColumns(map.get(i));
}
return new BufferedDataTable[] { exec.createSpecReplacerTable(inData[0], newTableSpecCreator.createSpec()) };
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class TestSubnodeView method validateReexecutionResult.
private void validateReexecutionResult() throws Exception {
// validate results
Map<String, String> newValueMap = buildValueMap();
String stringInputValue = newValueMap.get(m_stringInputID.toString());
assertNotNull("Value for string input node should exist", stringInputValue);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonValue = mapper.readTree(stringInputValue);
assertNotNull("String input value should contain new string value", jsonValue.get("string"));
assertEquals("String input value should be '" + CHANGED_URL + "'", CHANGED_URL, jsonValue.get("string").asText());
// check one row was selected and filtered
NodeContainer container = getManager().getNodeContainer(m_subnodeID);
BufferedDataTable table = (BufferedDataTable) container.getOutPort(1).getPortObject();
assertEquals("Table should contain one selected row", 1, table.size());
try (CloseableRowIterator it = table.iterator()) {
DataRow row = it.next();
assertEquals("Filtered row should be the previously selected one", "Row1", row.getKey().toString());
}
// check flow variable created from string input
NodeContainer cacheContainer = getManager().getNodeContainer(m_blockID);
FlowVariable var = cacheContainer.getFlowObjectStack().getAvailableFlowVariables().get("string-input");
assertNotNull("Flow variable 'string input' should exist", var);
assertEquals("Flow variable should contain new string value", CHANGED_URL, var.getStringValue());
}
Aggregations