use of org.knime.base.data.aggregation.GlobalSettings in project knime-core by knime.
the class MovingAggregationNodeModel method createTableFactory.
private MovingAggregationTableFactory createTableFactory(final FileStoreFactory fsf, final DataTableSpec spec) {
final GlobalSettings globalSettings = new GlobalSettings(fsf, Collections.<String>emptyList(), m_maxUniqueVals.getIntValue(), m_valueDelimiter.getJavaUnescapedStringValue(), spec, 0);
final ColumnNamePolicy colNamePolicy = ColumnNamePolicy.getPolicy4Label(m_columnNamePolicy.getStringValue());
final MovingAggregationTableFactory tableFactory = new MovingAggregationTableFactory(spec, globalSettings, colNamePolicy, m_columnAggregators2Use, m_cumulativeComputing.getBooleanValue(), WindowType.getType(m_windowType.getStringValue()), m_winLength.getIntValue(), m_handleMissings.getBooleanValue(), m_removeAggregationCols.getBooleanValue(), m_removeRetainedCols.getBooleanValue());
return tableFactory;
}
use of org.knime.base.data.aggregation.GlobalSettings in project knime-core by knime.
the class CrosstabNodeModel method createGroupByTable.
/**
* Create group-by table.
* @param exec execution context
* @param table input table to group
* @param groupByCols column selected for group-by operation
* @return table with group and aggregation columns
* @throws CanceledExecutionException if the group-by table generation was
* canceled externally
*/
private final GroupByTable createGroupByTable(final ExecutionContext exec, final BufferedDataTable table, final List<String> groupByCols) throws CanceledExecutionException {
final int maxUniqueVals = Integer.MAX_VALUE;
final boolean enableHilite = m_settings.getEnableHiliting();
final boolean retainOrder = false;
final ColumnNamePolicy colNamePolicy = ColumnNamePolicy.AGGREGATION_METHOD_COLUMN_NAME;
final GlobalSettings globalSettings = GlobalSettings.builder().setFileStoreFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec)).setGroupColNames(groupByCols).setMaxUniqueValues(maxUniqueVals).setValueDelimiter(GlobalSettings.STANDARD_DELIMITER).setDataTableSpec(table.getDataTableSpec()).setNoOfRows(table.size()).setAggregationContext(AggregationContext.ROW_AGGREGATION).build();
ColumnAggregator collAggregator = null;
if (null != m_settings.getWeightColumn()) {
final String weightColumn = m_settings.getWeightColumn();
// the column aggregator for the weighting column
final boolean inclMissing = false;
final DataColumnSpec originalColSpec = table.getDataTableSpec().getColumnSpec(weightColumn);
final OperatorColumnSettings opColSettings = new OperatorColumnSettings(inclMissing, originalColSpec);
collAggregator = new ColumnAggregator(originalColSpec, new NonNegativeSumOperator(globalSettings, opColSettings), inclMissing);
} else {
// use any column, does not matter as long as it exists and
// include missing is true;
final boolean inclMissing = true;
final DataColumnSpec originalColSpec = table.getDataTableSpec().getColumnSpec(groupByCols.get(0));
final OperatorColumnSettings opColSettings = new OperatorColumnSettings(inclMissing, originalColSpec);
collAggregator = new ColumnAggregator(originalColSpec, new CountOperator(globalSettings, opColSettings), inclMissing);
}
final GroupByTable resultTable = new BigGroupByTable(exec, table, groupByCols, new ColumnAggregator[] { collAggregator }, globalSettings, enableHilite, colNamePolicy, retainOrder);
if (enableHilite) {
setHiliteMapping(new DefaultHiLiteMapper(resultTable.getHiliteMapping()));
}
// check for skipped columns
final String warningMsg = resultTable.getSkippedGroupsMessage(3, 3);
if (warningMsg != null) {
setWarningMessage(warningMsg);
}
return resultTable;
}
use of org.knime.base.data.aggregation.GlobalSettings in project knime-core by knime.
the class GroupByNodeModel method createGroupByTable.
/**
* Create group-by table.
* @param exec execution context
* @param table input table to group
* @param groupByCols column selected for group-by operation
* @param inMemory keep data in memory
* @param sortInMemory does sorting in memory
* @param retainOrder reconstructs original data order
* @param aggregators column aggregation to use
* @return table with group and aggregation columns
* @throws CanceledExecutionException if the group-by table generation was
* canceled externally
* @deprecated sortInMemory is no longer required
* @see #createGroupByTable(ExecutionContext, BufferedDataTable, List,
* boolean, boolean, List)
*/
@Deprecated
protected final GroupByTable createGroupByTable(final ExecutionContext exec, final BufferedDataTable table, final List<String> groupByCols, final boolean inMemory, final boolean sortInMemory, final boolean retainOrder, final List<ColumnAggregator> aggregators) throws CanceledExecutionException {
final int maxUniqueVals = m_maxUniqueValues.getIntValue();
final boolean enableHilite = m_enableHilite.getBooleanValue();
final ColumnNamePolicy colNamePolicy = ColumnNamePolicy.getPolicy4Label(m_columnNamePolicy.getStringValue());
final GlobalSettings globalSettings = createGlobalSettings(exec, table, groupByCols, maxUniqueVals);
// reset all aggregators in order to use enforce operator creation
for (final ColumnAggregator colAggr : aggregators) {
colAggr.reset();
}
final GroupByTable resultTable;
if (inMemory || groupByCols.isEmpty()) {
resultTable = new MemoryGroupByTable(exec, table, groupByCols, aggregators.toArray(new ColumnAggregator[0]), globalSettings, enableHilite, colNamePolicy, retainOrder);
} else {
resultTable = new BigGroupByTable(exec, table, groupByCols, aggregators.toArray(new ColumnAggregator[0]), globalSettings, enableHilite, colNamePolicy, retainOrder);
}
if (m_enableHilite.getBooleanValue()) {
setHiliteMapping(new DefaultHiLiteMapper(resultTable.getHiliteMapping()));
}
// check for skipped columns
final String warningMsg = resultTable.getSkippedGroupsMessage(3, 3);
if (warningMsg != null) {
setWarningMessage(warningMsg);
LOGGER.info(resultTable.getSkippedGroupsMessage(Integer.MAX_VALUE, Integer.MAX_VALUE));
}
return resultTable;
}
use of org.knime.base.data.aggregation.GlobalSettings in project knime-core by knime.
the class ColumnAggregatorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable table = inData[0];
final DataTableSpec origSpec = table.getSpec();
final FilterResult filterResult = m_aggregationCols.applyTo(origSpec);
final List<String> selectedCols = Arrays.asList(filterResult.getIncludes());
final GlobalSettings globalSettings = GlobalSettings.builder().setFileStoreFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec)).setGroupColNames(selectedCols).setMaxUniqueValues(m_maxUniqueValues.getIntValue()).setValueDelimiter(getDefaultValueDelimiter()).setDataTableSpec(origSpec).setNoOfRows(table.size()).setAggregationContext(AggregationContext.COLUMN_AGGREGATION).build();
final AggregationCellFactory cellFactory = new AggregationCellFactory(origSpec, selectedCols, globalSettings, m_methods);
final ColumnRearranger cr = createRearranger(origSpec, cellFactory);
final BufferedDataTable out = exec.createColumnRearrangeTable(table, cr, exec);
return new BufferedDataTable[] { out };
}
use of org.knime.base.data.aggregation.GlobalSettings in project knime-core by knime.
the class ColumnAggregatorNodeModel method createStreamableOperator.
/* ================= STREAMING ================= */
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
final DataTableSpec origSpec = (DataTableSpec) inSpecs[0];
final FilterResult filterResult = m_aggregationCols.applyTo(origSpec);
final List<String> selectedCols = Arrays.asList(filterResult.getIncludes());
final GlobalSettings globalSettings = GlobalSettings.builder().setFileStoreFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec)).setGroupColNames(selectedCols).setMaxUniqueValues(m_maxUniqueValues.getIntValue()).setValueDelimiter(getDefaultValueDelimiter()).setDataTableSpec(origSpec).setNoOfRows(-1).setAggregationContext(AggregationContext.COLUMN_AGGREGATION).build();
final AggregationCellFactory cellFactory = new AggregationCellFactory(origSpec, selectedCols, globalSettings, m_methods);
final ColumnRearranger cr = createRearranger(origSpec, cellFactory);
cr.createStreamableFunction().runFinal(inputs, outputs, exec);
}
};
}
Aggregations