use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class AbstractColumnTableSorterTest method createRandomTable.
private BufferedDataTable createRandomTable(final int cols, final int rows) {
long currentTimeMillis = System.currentTimeMillis();
System.out.println("Using seed: " + currentTimeMillis);
Random random = new Random(currentTimeMillis);
DataTableSpecCreator creator = new DataTableSpecCreator();
for (int i = 0; i < cols; i++) {
creator.addColumns(new DataColumnSpecCreator("" + i, DoubleCell.TYPE).createSpec());
}
final BufferedDataContainer container = m_exec.createDataContainer(creator.createSpec());
for (int i = 0; i < rows; i++) {
DataCell[] rowVals = new DataCell[cols];
for (int j = 0; j < cols; j++) {
rowVals[j] = new DoubleCell(random.nextDouble());
}
container.addRowToTable(new DefaultRow(Integer.toString(i), rowVals));
if (i % 1000 == 0) {
System.out.println("Added row: " + i);
}
}
container.close();
return container.getTable();
}
use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class HistogramColumn method createNominalHistogramTableSpec.
/**
* @return The {@link DataTableSpec} for the nominal descriptor (column name, number of missings and a histogram).
*/
public DataTableSpec createNominalHistogramTableSpec() {
DataTableSpecCreator tableSpecCreator = new DataTableSpecCreator();
tableSpecCreator.addColumns(new DataColumnSpecCreator("Column", StringCell.TYPE).createSpec());
tableSpecCreator.addColumns(new DataColumnSpecCreator("No. missings", IntCell.TYPE).createSpec());
tableSpecCreator.addColumns(createHistogramColumnSpec());
DataTableSpec tableSpec = tableSpecCreator.createSpec();
return tableSpec;
}
use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class ExtendedStatisticsNodeModel method renamedOccurrencesSpec.
/**
* @param nominalSpec The original spec from {@link Statistics3Table#createOutSpecNominal(DataTableSpec, List)}.
* @return The '{@code ... count}' columns are renamed to '{@code Count (...)}'.
* @deprecated We will not need this once the replacement for Statistics3Table is present and give the correct
* table.
*/
@Deprecated
protected DataTableSpec renamedOccurrencesSpec(final DataTableSpec nominalSpec) {
DataTableSpecCreator tableSpecCreator = new DataTableSpecCreator(nominalSpec);
for (int i = 0; i < nominalSpec.getNumColumns(); i++) {
// columns are grouped: (name1, name1_count, Relative Frequency (name1), name2, name2_Count, ...)
if (i % 3 == 1) {
DataColumnSpec countSpec = nominalSpec.getColumnSpec(i);
String name = countSpec.getName();
CheckUtils.checkState(name.endsWith("_Count"), "Expected column name '<someName>_Count' but got '%s'", name);
String newName = name.replaceAll("(.+)_Count", "Count ($1)");
DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(countSpec);
colSpecCreator.setName(newName);
tableSpecCreator.replaceColumn(i, colSpecCreator.createSpec());
}
}
return tableSpecCreator.createSpec();
}
use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class DateTimeDifferenceNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
final String colName1 = m_col1stSelectModel.getStringValue();
final String colName2 = m_col2ndSelectModel.getStringValue();
if (colName1 == null) {
throw new InvalidSettingsException("Node must be configured!");
}
if (inSpecs[0].findColumnIndex(colName1) < 0) {
throw new InvalidSettingsException("Column '" + colName1 + "' not found in input table!");
}
final DataType type1 = inSpecs[0].getColumnSpec(colName1).getType();
if (!(type1.isCompatible(LocalDateValue.class) || type1.isCompatible(LocalTimeValue.class) || type1.isCompatible(LocalDateTimeValue.class) || type1.isCompatible(ZonedDateTimeValue.class))) {
throw new InvalidSettingsException("Column '" + colName1 + "' is not compatible!");
}
if (m_modusSelectModel.getStringValue().equals(ModusOptions.Use2ndColumn.name())) {
if (inSpecs[0].findColumnIndex(colName2) < 0) {
throw new InvalidSettingsException("Column '" + colName2 + "' not found in input table!");
}
final DataType type2 = inSpecs[0].getColumnSpec(colName2).getType();
if (!(type2.isCompatible(LocalDateValue.class) || type2.isCompatible(LocalTimeValue.class) || type2.isCompatible(LocalDateTimeValue.class) || type2.isCompatible(ZonedDateTimeValue.class))) {
throw new InvalidSettingsException("Column '" + colName1 + "' is not compatible!");
}
if (!type2.isCompatible(type1.getPreferredValueClass())) {
throw new InvalidSettingsException("Column '" + colName1 + "' and column '" + colName2 + "' must be of the same type!");
}
}
return new DataTableSpec[] { new DataTableSpecCreator(inSpecs[0]).addColumns(createColumnSpec(inSpecs[0])).createSpec() };
}
use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class DateTimeDifferenceNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
if (m_modusSelectModel.getStringValue().equals(ModusOptions.UsePreviousRow.name())) {
final BufferedDataTableRowOutput out = new BufferedDataTableRowOutput(exec.createDataContainer(new DataTableSpecCreator(inData[0].getDataTableSpec()).addColumns(createColumnSpec(inData[0].getDataTableSpec())).createSpec()));
execute(new DataTableRowInput(inData[0]), out, exec, inData[0].size());
return new BufferedDataTable[] { out.getDataTable() };
} else {
final ColumnRearranger r = createColumnRearranger(inData[0].getDataTableSpec());
final BufferedDataTable out = exec.createColumnRearrangeTable(inData[0], r, exec);
return new BufferedDataTable[] { out };
}
}
Aggregations