use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class ExpressionFactory method constant.
/**
* {@inheritDoc}
*/
@Override
public Expression constant(final int integer) {
final IntCell cell = new IntCell(integer);
final ExpressionValue value = new ExpressionValue(cell, EMPTY_MAP);
return new ConstantExpression(value);
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class ExpressionFactory method flowVarRef.
/**
* {@inheritDoc}
*/
@Override
public Expression flowVarRef(final Map<String, FlowVariable> flowVariables, final String flowVarRef) {
if (!flowVariables.containsKey(flowVarRef) || flowVariables.get(flowVarRef) == null) {
throw new IllegalStateException("Not a valid flow variable: " + flowVarRef + " (" + flowVariables + ")");
}
final FlowVariable var = flowVariables.get(flowVarRef);
final boolean isConstant = var.getScope() != Scope.Local;
final ExpressionValue constant = isConstant ? Util.readFlowVarToExpressionValue(var) : null;
return new Expression.Base() {
/**
* {@inheritDoc}
*/
@Override
public List<DataType> getInputArgs() {
return Collections.emptyList();
}
/**
* {@inheritDoc}
*/
@Override
public DataType getOutputType() {
return Util.toDataType(var.getType());
}
/**
* {@inheritDoc}
*/
@Override
public ExpressionValue evaluate(final DataRow row, final VariableProvider provider) {
if (constant != null) {
return constant;
}
Object variable = provider.readVariable(flowVarRef, Util.flowVarTypeToClass(var.getType()));
switch(var.getType()) {
case DOUBLE:
return new ExpressionValue(new DoubleCell(((Double) variable).doubleValue()), EMPTY_MAP);
case INTEGER:
return new ExpressionValue(new IntCell(((Integer) variable).intValue()), EMPTY_MAP);
case STRING:
return new ExpressionValue(new StringCell((String) variable), EMPTY_MAP);
default:
throw new IllegalStateException("Not supported flow variable type: " + var.getType());
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean isConstant() {
return isConstant;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "$$" + flowVarRef + "$$";
}
/**
* {@inheritDoc}
*/
@Override
public ASTType getTreeType() {
return ASTType.FlowVarRef;
}
};
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class MissingValueHandlingTableIterator method handleMissing.
/* Does the missing value handling on a row. */
private DataRow handleMissing(final DataRow row) {
DataCell[] cells = new DataCell[row.getNumCells()];
for (int i = 0; i < row.getNumCells(); i++) {
ColSetting colset = m_table.getColSetting(i);
DataCell oldCell = row.getCell(i);
DataCell newCell;
if (oldCell.isMissing()) {
switch(colset.getMethod()) {
case ColSetting.METHOD_NO_HANDLING:
newCell = oldCell;
break;
case ColSetting.METHOD_FIX_VAL:
newCell = m_table.getColSetting(i).getFixCell();
assert (newCell != null);
break;
case ColSetting.METHOD_MOST_FREQUENT:
newCell = m_table.getMostFrequent(i);
break;
case ColSetting.METHOD_MAX:
newCell = m_table.getMax(i);
break;
case ColSetting.METHOD_MIN:
newCell = m_table.getMin(i);
break;
case ColSetting.METHOD_MEAN:
// in contrast to the above, it will return
// a newly generate value, thus, only a double
double mean = m_table.getMean(i);
if (colset.getType() == ColSetting.TYPE_DOUBLE) {
newCell = new DoubleCell(mean);
} else {
assert colset.getType() == ColSetting.TYPE_INT;
newCell = new IntCell((int) Math.round(mean));
}
break;
case ColSetting.METHOD_IGNORE_ROWS:
assert false : "That should have been filtered.";
newCell = oldCell;
default:
throw new RuntimeException("Invalid method!");
}
} else {
newCell = oldCell;
}
cells[i] = newCell;
}
RowKey key = row.getKey();
return new DefaultRow(key, cells);
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class ExpressionFactoryTest method testConstantInt.
/**
* Test method for {@link ExpressionFactory#constant(int)}.
*/
@Test
public void testConstantInt() {
final Expression one = m_factory.constant(1);
assertTrue(one.isConstant());
assertEquals(new IntCell(1), one.evaluate(null, null).getValue());
assertEquals(Collections.emptyMap(), one.evaluate(null, null).getMatchedObjects());
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class ExpressionFactoryTest method testTableRef.
/**
* Test method for {@link ExpressionFactory#tableRef(Rule.TableReference)} .
*/
@Test
public void testTableRef() {
assertEquals(new LongCell(2), m_factory.tableRef(TableReference.RowCount).evaluate(null, new VariableProvider() {
@Override
public Object readVariable(final String name, final Class<?> type) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getRowCountLong() {
return 2L;
}
@Override
public long getRowIndexLong() {
return 0L;
}
@Deprecated
@Override
public int getRowCount() {
return 0;
}
@Deprecated
@Override
public int getRowIndex() {
return 0;
}
}).getValue());
assertEquals(new LongCell(3), m_factory.tableRef(TableReference.RowIndex).evaluate(null, new VariableProvider() {
@Override
public Object readVariable(final String name, final Class<?> type) {
return null;
}
@Override
public long getRowCountLong() {
return 0L;
}
@Override
public long getRowIndexLong() {
return 3L;
}
@Deprecated
@Override
public int getRowCount() {
return 0;
}
@Deprecated
@Override
public int getRowIndex() {
return 0;
}
}).getValue());
assertEquals(new StringCell("Row0"), m_factory.tableRef(TableReference.RowId).evaluate(new DefaultRow(new RowKey("Row0"), new IntCell(3)), new VariableProvider() {
@Override
public Object readVariable(final String name, final Class<?> type) {
// TODO Auto-generated method stub
return null;
}
@Deprecated
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return 0;
}
@Deprecated
@Override
public int getRowIndex() {
// TODO Auto-generated method stub
return 0;
}
}).getValue());
}
Aggregations