use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class ModifyDateNodeModel method createColumnRearranger.
/**
* @param inSpec table input spec
* @return the CR describing the output
*/
@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 = LocalTimeCellFactory.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;
}
}
}
final ZoneId zone = m_timeZone.getZone();
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++], zone);
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includedCol + m_suffix.getStringValue(), dataType);
final SingleCellFactory cellFac = createCellFactory(dataColSpec, includeIndices[i++], zone);
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class MovingAggregationNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
if (inData == null || inData.length != 1) {
throw new InvalidSettingsException("No input table available");
}
final BufferedDataTable table = inData[0];
if (table.getRowCount() == 0) {
setWarningMessage("Empty input table found");
} else if (!m_cumulativeComputing.getBooleanValue() && table.getRowCount() < m_winLength.getIntValue()) {
throw new InvalidSettingsException("Window length is larger than the number of rows of the input table");
}
final DataTableSpec spec = table.getDataTableSpec();
final MovingAggregationTableFactory tableFactory = createTableFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec), spec);
BufferedDataTable resultTable = tableFactory.createTable(exec, table);
return new BufferedDataTable[] { resultTable };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class MovingAggregationNodeModel method configure.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (inSpecs == null || inSpecs.length != 1) {
throw new InvalidSettingsException("No input table specification available");
}
final DataTableSpec inputSpec = inSpecs[0];
m_columnAggregators2Use.clear();
final ArrayList<ColumnAggregator> invalidColAggrs = new ArrayList<>(1);
m_columnAggregators2Use.addAll(GroupByNodeModel.getAggregators(inputSpec, Collections.EMPTY_LIST, m_columnAggregators, m_patternAggregators, m_dataTypeAggregators, invalidColAggrs));
if (m_columnAggregators2Use.isEmpty()) {
setWarningMessage("No aggregation column defined");
}
if (!invalidColAggrs.isEmpty()) {
setWarningMessage(invalidColAggrs.size() + " invalid aggregation column(s) found.");
}
LOGGER.debug(m_columnAggregators2Use);
final MovingAggregationTableFactory tableFactory = createTableFactory(FileStoreFactory.createNotInWorkflowFileStoreFactory(), inputSpec);
return new DataTableSpec[] { tableFactory.createResultSpec() };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class TimeFieldExtractorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = inSpecs[0];
// contains timestamp?
if (!inSpec.containsCompatibleType(DateAndTimeValue.class)) {
throw new InvalidSettingsException("No timestamp found in input table!");
}
// currently selected column still there?
String selectedColName = m_selectedColumn.getStringValue();
if (selectedColName != null && !selectedColName.isEmpty()) {
if (!inSpec.containsName(selectedColName)) {
throw new InvalidSettingsException("Column " + selectedColName + " not found in input spec!");
}
} else {
// no value set: auto-configure -> choose first timeseries
for (DataColumnSpec colSpec : inSpec) {
if (colSpec.getType().isCompatible(DateAndTimeValue.class)) {
String colName = colSpec.getName();
m_selectedColumn.setStringValue(colName);
setWarningMessage("Auto-configure: selected " + colName);
break;
}
}
}
// create outputspec
ColumnRearranger colRearranger = createColumnRearranger(inSpec).getColumnRearranger();
return new DataTableSpec[] { colRearranger.createSpec() };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class DateGeneratorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
validateDates(m_to);
final Calendar from;
if (m_useExecution.getBooleanValue()) {
from = Calendar.getInstance(TimeZone.getDefault());
from.setTimeInMillis(System.currentTimeMillis() + TimeZone.getDefault().getOffset(System.currentTimeMillis()));
// no validation of from date necessary
} else {
from = m_from.getCalendar();
validateDates(m_from);
}
int noRows = m_noOfRows.getIntValue();
long offset = (long) calculateOffset(from, m_to.getCalendar(), noRows);
// if no of row = 1 we simply return the start date
if (Math.abs(offset) <= 0 && noRows > 1) {
setWarningMessage("Number of rows too large for entered time period! " + "All rows will contain the same time stamp.");
}
return new DataTableSpec[] { createOutSpec() };
}
Aggregations