use of org.knime.core.data.append.AppendedColumnRow in project knime-core by knime.
the class NewToOldTimeNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public StreamableOperatorInternals saveInternals() {
return null;
}
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
final RowInput in = (RowInput) inputs[0];
final RowOutput out = (RowOutput) outputs[0];
final DataTableSpec inSpec = in.getDataTableSpec();
String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndeces = Arrays.stream(includeList).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
DataRow row;
while ((row = in.poll()) != null) {
exec.checkCanceled();
DataCell[] datacells = new DataCell[includeIndeces.length];
for (int i = 0; i < includeIndeces.length; i++) {
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includeList[i], DateAndTimeCell.TYPE);
final ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i]);
datacells[i] = cellFac.getCells(row)[0];
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includeList[i] + m_suffix.getStringValue(), DateAndTimeCell.TYPE);
final ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(dataColSpec, includeIndeces[i]);
datacells[i] = cellFac.getCells(row)[0];
}
}
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
out.push(new ReplacedColumnsDataRow(row, datacells, includeIndeces));
} else {
out.push(new AppendedColumnRow(row, datacells));
}
}
in.close();
out.close();
}
};
}
use of org.knime.core.data.append.AppendedColumnRow in project knime-core by knime.
the class DateTimeToStringNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
final RowInput in = (RowInput) inputs[0];
final RowOutput out = (RowOutput) outputs[0];
final DataTableSpec inSpec = in.getDataTableSpec();
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndeces = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
final boolean isReplace = m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE);
DataRow row;
while ((row = in.poll()) != null) {
exec.checkCanceled();
DataCell[] datacells = new DataCell[includeIndeces.length];
for (int i = 0; i < includeIndeces.length; i++) {
if (isReplace) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includeList[i], StringCell.TYPE);
final TimeToStringCellFactory cellFac = new TimeToStringCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i]);
datacells[i] = cellFac.getCell(row);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includeList[i] + m_suffix.getStringValue(), StringCell.TYPE);
final TimeToStringCellFactory cellFac = new TimeToStringCellFactory(dataColSpec, includeIndeces[i]);
datacells[i] = cellFac.getCell(row);
}
}
if (isReplace) {
out.push(new ReplacedColumnsDataRow(row, datacells, includeIndeces));
} else {
out.push(new AppendedColumnRow(row, datacells));
}
}
in.close();
out.close();
}
};
}
use of org.knime.core.data.append.AppendedColumnRow in project knime-core by knime.
the class ExtractMissingValueCauseNodeModel method execute.
/**
* helper method to compute output
*/
private void execute(final RowInput inData, final RowOutput output, final ExecutionContext exec, final long rowCount) throws Exception {
final AppendErrorMessageCellFactory cellFactory = createCellFactory(inData.getDataTableSpec());
DataRow row;
long currentRowIndex = 0;
while ((row = inData.poll()) != null) {
exec.checkCanceled();
// set progress if not streaming
if (rowCount >= 0) {
exec.setProgress(currentRowIndex / (double) rowCount);
}
final long currentRowIndexFinal = currentRowIndex;
exec.setMessage(() -> "Row " + currentRowIndexFinal + "/" + rowCount);
// compute new cells
Optional<DataCell[]> newCellsOptional = cellFactory.getCellsOptional(row);
if (newCellsOptional.isPresent()) {
DataCell[] newCells = newCellsOptional.get();
output.push(new AppendedColumnRow(row, newCells));
}
currentRowIndex += 1;
}
inData.close();
output.close();
}
use of org.knime.core.data.append.AppendedColumnRow in project knime-core by knime.
the class StringToDurationPeriodNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
private SimpleStreamableOperatorInternals m_internals = new SimpleStreamableOperatorInternals();
/**
* {@inheritDoc}
*/
@Override
public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
final RowInput rowInput = (RowInput) inputs[0];
final DataRow row = rowInput.poll();
if (row != null) {
final DataTableSpec inSpec = rowInput.getDataTableSpec();
final int[] includeIndexes = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
final Config config = m_internals.getConfig();
// detect types
detectTypes(new OneRowAdditionalRowInput(rowInput, row));
for (int i = 0; i < m_detectedTypes.length; i++) {
config.addDataType("detected_type" + i, m_detectedTypes[i]);
}
// write detected types and column names into config
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
for (int i = 0; i < rowInput.getDataTableSpec().getNumColumns(); i++) {
final int searchIdx = Arrays.binarySearch(includeIndexes, i);
config.addString("colname" + i, inSpec.getColumnNames()[i]);
if (searchIdx < 0) {
config.addDataType("type" + i, inSpec.getColumnSpec(i).getType());
} else {
config.addDataType("type" + i, m_detectedTypes[searchIdx] != null ? m_detectedTypes[searchIdx] : null);
}
}
config.addInt("sizeRow", rowInput.getDataTableSpec().getNumColumns());
} else {
for (int i = 0; i < inSpec.getNumColumns(); i++) {
config.addString("colname" + i, inSpec.getColumnNames()[i]);
config.addDataType("type" + i, inSpec.getColumnSpec(i).getType());
}
for (int i = 0; i < m_detectedTypes.length; i++) {
config.addString("colname" + (i + inSpec.getNumColumns()), new UniqueNameGenerator(inSpec).newName(inSpec.getColumnSpec(includeIndexes[i]).getName() + m_suffix.getStringValue()));
config.addDataType("type" + (i + inSpec.getNumColumns()), m_detectedTypes[i]);
}
config.addInt("sizeRow", inSpec.getNumColumns() + m_detectedTypes.length);
}
config.addBoolean("needsIteration", false);
} else {
m_internals.getConfig().addInt("sizeRow", 0);
}
rowInput.close();
}
/**
* {@inheritDoc}
*/
@Override
public StreamableOperatorInternals saveInternals() {
return m_internals;
}
/**
* {@inheritDoc}
*/
@Override
public void loadInternals(final StreamableOperatorInternals internals) {
m_internals = (SimpleStreamableOperatorInternals) internals;
}
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
final RowInput in = (RowInput) inputs[0];
final RowOutput out = (RowOutput) outputs[0];
final DataTableSpec inSpec = in.getDataTableSpec();
final int[] includeIndexes = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
// read detected types from config
final DataType[] detectedTypes = new DataType[includeIndexes.length];
final Config config = m_internals.getConfig();
for (int i = 0; i < includeIndexes.length; i++) {
detectedTypes[i] = config.getDataType("detected_type" + i, null);
}
// compute every row
DataRow row;
while ((row = in.poll()) != null) {
exec.checkCanceled();
DataCell[] datacells = new DataCell[includeIndexes.length];
for (int i = 0; i < includeIndexes.length; i++) {
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final StringToDurationPeriodCellFactory cellFac = new StringToDurationPeriodCellFactory(new DataColumnSpecCreator(inSpec.getColumnNames()[includeIndexes[i]], detectedTypes[i]).createSpec(), includeIndexes[i]);
datacells[i] = cellFac.getCells(row)[0];
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(inSpec.getColumnNames()[includeIndexes[i]] + m_suffix.getStringValue(), detectedTypes[i]);
final StringToDurationPeriodCellFactory cellFac = new StringToDurationPeriodCellFactory(dataColSpec, includeIndexes[i]);
datacells[i] = cellFac.getCells(row)[0];
}
}
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
out.push(new ReplacedColumnsDataRow(row, datacells, includeIndexes));
} else {
out.push(new AppendedColumnRow(row, datacells));
}
}
in.close();
out.close();
}
};
}
use of org.knime.core.data.append.AppendedColumnRow in project knime-core by knime.
the class DateTimeDifferenceNodeModel method execute.
/**
* helper method to compute output
*/
private void execute(final RowInput inData, final RowOutput output, final ExecutionContext exec, final long rowCount) throws Exception {
DataRow row;
DataRow previousRow = inData.poll();
final int colIdx1 = inData.getDataTableSpec().findColumnIndex(m_col1stSelectModel.getStringValue());
final DataType type = inData.getDataTableSpec().getColumnSpec(colIdx1).getType();
long currentRowIndex = 0;
output.push(new AppendedColumnRow(previousRow, new MissingCell("No previous row for calculating difference available.")));
while ((row = inData.poll()) != null) {
exec.checkCanceled();
// set progress if not streaming
if (rowCount >= 0) {
exec.setProgress(currentRowIndex / (double) rowCount);
}
final long currentRowIndexFinal = currentRowIndex;
exec.setMessage(() -> "Row " + currentRowIndexFinal + "/" + rowCount);
// compute new cells
DataCell newCell;
if (type.isCompatible(LocalDateValue.class)) {
newCell = calculateDate(previousRow.getCell(colIdx1), row.getCell(colIdx1), null);
} else {
newCell = calculateTime(previousRow.getCell(colIdx1), row.getCell(colIdx1), null);
}
output.push(new AppendedColumnRow(row, newCell));
previousRow = row;
currentRowIndex++;
}
inData.close();
output.close();
}
Aggregations