Search in sources :

Example 16 with DataTableSpecCreator

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();
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Random(java.util.Random) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 17 with DataTableSpecCreator

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;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator)

Example 18 with DataTableSpecCreator

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();
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 19 with DataTableSpecCreator

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() };
}
Also used : LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) DataType(org.knime.core.data.DataType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue)

Example 20 with DataTableSpecCreator

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 };
    }
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) BufferedDataTable(org.knime.core.node.BufferedDataTable) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Aggregations

DataTableSpecCreator (org.knime.core.data.DataTableSpecCreator)20 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)12 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 DataTableSpec (org.knime.core.data.DataTableSpec)6 DataCell (org.knime.core.data.DataCell)4 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)4 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)4 ArrayList (java.util.ArrayList)3 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)3 HashSet (java.util.HashSet)2 Random (java.util.Random)2 DefaultRow (org.knime.core.data.def.DefaultRow)2 DoubleCell (org.knime.core.data.def.DoubleCell)2 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 FilterResult (org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 HistogramColumn (org.knime.base.data.statistics.HistogramColumn)1 BooleanValue (org.knime.core.data.BooleanValue)1