use of org.knime.core.data.DataRow in project knime-core by knime.
the class MovingAggregationTableFactory method getBackwardTable.
private BufferedDataTable getBackwardTable(final ExecutionMonitor exec, final BufferedDataTable table, final BufferedDataContainer dc) throws CanceledExecutionException {
final int rowCount = table.getRowCount();
final LinkedList<DataRow> window = new LinkedList<>();
int rowIdx = 0;
for (final DataRow row : table) {
exec.setProgress(rowIdx / (double) rowCount, "Processing row " + rowIdx++ + " of " + rowCount);
exec.checkCanceled();
window.add(row);
final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
int idx = 0;
// handle the retained columns
for (final int colIdx : m_cols2KeepIdxs) {
cells[idx++] = row.getCell(colIdx);
}
final boolean windowFull = window.size() >= m_windowLength;
for (int i = 0, length = m_ops.length; i < length; i++) {
if (windowFull || m_handleMissings) {
final int colIdx = m_aggrColIdxs[i];
final AggregationOperator op = m_ops[i];
for (final DataRow windowRow : window) {
op.compute(windowRow, colIdx);
}
cells[idx++] = op.getResult();
op.reset();
} else {
// the window is not yet full return missing cells
cells[idx++] = DataType.getMissingCell();
}
}
if (windowFull) {
// remove the first row only when the window is full
// not during the missing value handling phase!
window.removeFirst();
}
dc.addRowToTable(new DefaultRow(row.getKey(), cells));
}
dc.close();
return dc.getTable();
}
use of org.knime.core.data.DataRow in project knime-core by knime.
the class MovingAggregationTableFactory method getCenterTable.
private BufferedDataTable getCenterTable(final ExecutionMonitor exec, final BufferedDataTable table, final BufferedDataContainer dc) throws CanceledExecutionException {
final int rowCount = table.getRowCount();
final LinkedList<DataRow> window = new LinkedList<>();
int rowIdx = 0;
int centerIdx = -1;
for (final DataRow row : table) {
exec.setProgress(rowIdx / (double) rowCount, "Processing row " + rowIdx++ + " of " + rowCount);
exec.checkCanceled();
window.add(row);
// we have to subtract 1 since the indexing of the array starts with 0
centerIdx = window.size() - m_windowLength / 2 - 1;
if (centerIdx < 0) {
// we have to fill the window first
continue;
}
final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
final DataRow centerRow = window.get(centerIdx);
int idx = 0;
// handle the retained columns
for (final int colIdx : m_cols2KeepIdxs) {
cells[idx++] = centerRow.getCell(colIdx);
}
final boolean windowFull = window.size() >= m_windowLength;
for (int i = 0, length = m_ops.length; i < length; i++) {
if (windowFull || m_handleMissings) {
final int colIdx = m_aggrColIdxs[i];
final AggregationOperator op = m_ops[i];
for (final DataRow windowRow : window) {
op.compute(windowRow, colIdx);
}
cells[idx++] = op.getResult();
op.reset();
} else {
// the window is not yet full return missing cells
cells[idx++] = DataType.getMissingCell();
}
}
dc.addRowToTable(new DefaultRow(centerRow.getKey(), cells));
// not during the missing value handling phase!
if (windowFull) {
window.removeFirst();
}
}
// we have to handle the remaining rows in the window
while (window.size() > centerIdx) {
exec.checkCanceled();
final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
int idx = 0;
final DataRow centerRow = window.get(centerIdx);
// handle the retained columns
for (final int colIdx : m_cols2KeepIdxs) {
cells[idx++] = centerRow.getCell(colIdx);
}
for (int i = 0, length = m_ops.length; i < length; i++) {
if (m_handleMissings) {
final int colIdx = m_aggrColIdxs[i];
final AggregationOperator op = m_ops[i];
for (final DataRow windowRow : window) {
op.compute(windowRow, colIdx);
}
cells[idx++] = op.getResult();
op.reset();
} else {
// the window is not yet full return missing cells
cells[idx++] = DataType.getMissingCell();
}
}
window.removeFirst();
dc.addRowToTable(new DefaultRow(centerRow.getKey(), cells));
}
dc.close();
return dc.getTable();
}
use of org.knime.core.data.DataRow in project knime-core by knime.
the class MovingAggregationTableFactory method getForwardTable.
private BufferedDataTable getForwardTable(final ExecutionMonitor exec, final BufferedDataTable table, final BufferedDataContainer dc) throws CanceledExecutionException {
final int rowCount = table.getRowCount();
final LinkedList<DataRow> window = new LinkedList<>();
int rowIdx = 0;
for (final DataRow row : table) {
exec.setProgress(rowIdx / (double) rowCount, "Processing row " + rowIdx++ + " of " + rowCount);
exec.checkCanceled();
window.add(row);
final boolean windowFull = window.size() >= m_windowLength;
if (!windowFull) {
// we have to fill the window first
continue;
}
final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
final DataRow firstRow = window.getFirst();
int idx = 0;
// handle the retained columns
for (final int colIdx : m_cols2KeepIdxs) {
cells[idx++] = firstRow.getCell(colIdx);
}
for (int i = 0, length = m_ops.length; i < length; i++) {
final int colIdx = m_aggrColIdxs[i];
final AggregationOperator op = m_ops[i];
for (final DataRow windowRow : window) {
op.compute(windowRow, colIdx);
}
cells[idx++] = op.getResult();
op.reset();
}
dc.addRowToTable(new DefaultRow(firstRow.getKey(), cells));
// remove the first row only when the window is full
// not during the missing value handling phase!
window.removeFirst();
}
// we have to handle the remaining rows in the window
while (!window.isEmpty()) {
exec.checkCanceled();
final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
int idx = 0;
final DataRow firstRow = window.getFirst();
// handle the retained columns
for (final int colIdx : m_cols2KeepIdxs) {
cells[idx++] = firstRow.getCell(colIdx);
}
for (int i = 0, length = m_ops.length; i < length; i++) {
if (m_handleMissings) {
final int colIdx = m_aggrColIdxs[i];
final AggregationOperator op = m_ops[i];
for (final DataRow windowRow : window) {
op.compute(windowRow, colIdx);
}
cells[idx++] = op.getResult();
op.reset();
} else {
// the window is not yet full return missing cells
cells[idx++] = DataType.getMissingCell();
}
}
window.removeFirst();
dc.addRowToTable(new DefaultRow(firstRow.getKey(), cells));
}
dc.close();
return dc.getTable();
}
use of org.knime.core.data.DataRow in project knime-core by knime.
the class BaseRuleParser method parseColumnExpression.
/**
* Creates an {@link Expression} to compute a column.
*
* @param state The {@link ParseState}.
* @param fromMissing This {@link Expression} is created within a {@link Operators#MISSING}.
* @return The {@link Expression} parsed representing a column.
* @throws ParseException Problem during parsing.
*/
private Expression parseColumnExpression(final ParseState state, final boolean fromMissing) throws ParseException {
state.skipWS();
int startPos = state.getPosition();
if (state.isColumnRef()) {
String columnRef = state.readColumnRef();
if (!m_checkColumns) {
// Create a dummy expression
return new Expression() {
@Override
public boolean isConstant() {
return false;
}
@Override
public ASTType getTreeType() {
return ASTType.ColRef;
}
@Override
public DataType getOutputType() {
return DataType.getMissingCell().getType();
}
@Override
public List<DataType> getInputArgs() {
return Collections.emptyList();
}
@Override
public List<Expression> getChildren() {
return Collections.emptyList();
}
@Override
public ExpressionValue evaluate(final DataRow row, final VariableProvider provider) {
throw new IllegalStateException("This expression is only for configuration.");
}
};
}
if (m_spec == null) {
throw new ParseException("No columns present.", startPos);
}
try {
Expression expr = m_factoryRef.columnRef(m_spec, columnRef);
if (BooleanCell.TYPE.isASuperTypeOf(expr.getOutputType()) && fromMissing) {
expr = m_factoryRef.columnRefForMissing(m_spec, columnRef);
}
return expr;
} catch (IllegalStateException e) {
throw new ParseException(e.getMessage(), startPos);
}
}
throw new ParseException("Expected a column reference", state.getPosition());
}
use of org.knime.core.data.DataRow in project knime-core by knime.
the class BaseRuleParser method parseFlowVariableExpression.
/**
* Creates an {@link Expression} to compute a {@link FlowVariable}.
*
* @param state The {@link ParseState}.
* @return The {@link Expression} parsed representing a {@link FlowVariable}.
* @throws ParseException Problem during parsing.
*/
private Expression parseFlowVariableExpression(final ParseState state) throws ParseException {
state.skipWS();
int startPos = state.getPosition();
if (state.isFlowVariableRef()) {
String flowVarRef = state.readFlowVariable();
if (!m_checkFlowVars) {
// Create a dummy expression
return new Expression() {
@Override
public boolean isConstant() {
return false;
}
@Override
public ASTType getTreeType() {
return ASTType.FlowVarRef;
}
@Override
public DataType getOutputType() {
return DataType.getMissingCell().getType();
}
@Override
public List<DataType> getInputArgs() {
return Collections.emptyList();
}
@Override
public List<Expression> getChildren() {
return Collections.emptyList();
}
@Override
public ExpressionValue evaluate(final DataRow row, final VariableProvider provider) {
throw new IllegalStateException("This expression is only for configuration.");
}
};
}
try {
return m_factoryRef.flowVarRef(m_flowVariables, flowVarRef);
} catch (IllegalStateException e) {
throw new ParseException(e.getMessage(), startPos);
}
}
throw new ParseException("Expected a flow variable reference", state.getPosition());
}
Aggregations