Search in sources :

Example 56 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class StringManipulationNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    DataTableSpec spec;
    if (m_isOnlyVariables) {
        spec = new DataTableSpec();
    } else {
        spec = (DataTableSpec) specs[0];
    }
    StringManipulationSettings s = new StringManipulationSettings();
    s.loadSettingsInDialog(settings, spec);
    String exp = s.getExpression();
    String defaultNewName = "new " + m_columnOrVariable;
    String newName = s.getColName();
    boolean isReplace = s.isReplace();
    boolean isTestCompilation = s.isTestCompilationOnDialogClose();
    boolean isInsertMissingAsNull = s.isInsertMissingAsNull();
    m_newNameField.setText("");
    final Map<String, FlowVariable> availableFlowVariables = getAvailableFlowVariables();
    if (m_isOnlyVariables) {
        DefaultComboBoxModel<FlowVariable> cmbModel = (DefaultComboBoxModel<FlowVariable>) m_replaceVariableCombo.getModel();
        cmbModel.removeAllElements();
        for (FlowVariable v : availableFlowVariables.values()) {
            switch(v.getScope()) {
                case Flow:
                    cmbModel.addElement(v);
                    break;
                default:
            }
        }
        if (availableFlowVariables.containsValue(newName)) {
            m_replaceVariableCombo.setSelectedItem(availableFlowVariables.get(newName));
        }
    } else {
        // will select newColName only if it is in the spec list
        try {
            m_replaceColumnCombo.update(spec, newName);
        } catch (NotConfigurableException e1) {
            NodeLogger.getLogger(getClass()).coding("Combo box throws exception although content is not required", e1);
        }
    }
    m_currentSpec = spec;
    // whether there are variables or columns available
    // -- which of two depends on the customizer
    boolean fieldsAvailable;
    if (m_isOnlyVariables) {
        fieldsAvailable = m_replaceVariableCombo.getItemCount() > 0;
    } else {
        fieldsAvailable = m_replaceColumnCombo.getNrItemsInList() > 0;
    }
    m_replaceRadio.setEnabled(fieldsAvailable);
    if (isReplace && fieldsAvailable) {
        m_replaceRadio.doClick();
    } else {
        m_appendRadio.doClick();
        String newNameString = (newName != null ? newName : defaultNewName);
        m_newNameField.setText(newNameString);
    }
    m_snippetPanel.update(exp, spec, availableFlowVariables);
    m_compileOnCloseChecker.setSelected(isTestCompilation);
    m_insertMissingAsNullChecker.setSelected(isInsertMissingAsNull);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 57 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class StringManipulationNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    DataTableSpec inSpec = inData[0].getDataTableSpec();
    ColumnRearranger c = createColumnRearranger(inSpec);
    m_rowCount = inData[0].size();
    try {
        BufferedDataTable o = exec.createColumnRearrangeTable(inData[0], c, exec);
        return new BufferedDataTable[] { o };
    } finally {
        m_rowCount = -1L;
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 58 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class ModifyTimeNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) {
    final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
    final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
    final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
    // determine the data type of output
    DataType dataType;
    if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_REMOVE)) {
        dataType = LocalDateCellFactory.TYPE;
    } else {
        if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
            dataType = LocalDateTimeCellFactory.TYPE;
        } else {
            if (m_timeZone.useZone()) {
                dataType = ZonedDateTimeCellFactory.TYPE;
            } else {
                dataType = LocalDateTimeCellFactory.TYPE;
            }
        }
    }
    int i = 0;
    for (final String includedCol : includeList) {
        if (inSpec.getColumnSpec(includedCol).getType().equals(ZonedDateTimeCellFactory.TYPE) && m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
            dataType = ZonedDateTimeCellFactory.TYPE;
        }
        if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
            final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, dataType);
            final SingleCellFactory cellFac = createCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++], m_timeZone.getZone());
            rearranger.replace(cellFac, includedCol);
        } else {
            final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includedCol + m_suffix.getStringValue(), dataType);
            final SingleCellFactory cellFac = createCellFactory(dataColSpec, includeIndices[i++], m_timeZone.getZone());
            rearranger.append(cellFac);
        }
    }
    return rearranger;
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataTypeColumnFilter(org.knime.core.node.util.filter.column.DataTypeColumnFilter) ZonedDateTime(java.time.ZonedDateTime) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTime(java.time.LocalDateTime) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) ZonedDateTimeCellFactory(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCellFactory) SimpleStreamableFunctionNodeModel(org.knime.core.node.streamable.simple.SimpleStreamableFunctionNodeModel) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LocalTime(java.time.LocalTime) DataCell(org.knime.core.data.DataCell) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) ZoneId(java.time.ZoneId) DataRow(org.knime.core.data.DataRow) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) SettingsModelDateTime(org.knime.time.util.SettingsModelDateTime) DataType(org.knime.core.data.DataType) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataType(org.knime.core.data.DataType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 59 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class ModifyTimeNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    if (!m_hasValidatedConfiguration) {
        throw new InvalidSettingsException("Node must be configured!");
    }
    DataTableSpec in = inSpecs[0];
    ColumnRearranger r = createColumnRearranger(in);
    DataTableSpec out = r.createSpec();
    return new DataTableSpec[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 60 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class ModifyDateNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    if (!m_hasValidatedConfiguration) {
        throw new InvalidSettingsException("Node must be configured!");
    }
    DataTableSpec in = inSpecs[0];
    ColumnRearranger r = createColumnRearranger(in);
    DataTableSpec out = r.createSpec();
    return new DataTableSpec[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Aggregations

DataTableSpec (org.knime.core.data.DataTableSpec)938 DataColumnSpec (org.knime.core.data.DataColumnSpec)340 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)306 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)228 BufferedDataTable (org.knime.core.node.BufferedDataTable)226 DataCell (org.knime.core.data.DataCell)186 DataRow (org.knime.core.data.DataRow)170 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)136 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)129 DataType (org.knime.core.data.DataType)109 ArrayList (java.util.ArrayList)106 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)98 DoubleValue (org.knime.core.data.DoubleValue)94 DefaultRow (org.knime.core.data.def.DefaultRow)92 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)90 ExecutionContext (org.knime.core.node.ExecutionContext)68 PortObject (org.knime.core.node.port.PortObject)66 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)62 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)61 RowKey (org.knime.core.data.RowKey)59