I would like ask for your advice in looping and appending new columns. I have three input columns, the column1, column2 and column3. My objective is to manipulate any number of columns, for example I selected them all from the column panel, after manipulation, it should be column1, column2, column3, column1-1, column2-1 and column3-1. Instead of appending the new columns, the seems like it is only appending the last new column of the loop. The output table is column1, column2, column3 and column3-1. Please see codes below for your reference.
NodeStreamableOperator(final NodeConfiguration configuration, final DataTableSpec inSpec)
throws InvalidSettingsException {
m_configuration = configuration;
Collection<String> ColumnName = m_configuration.iterateOverBackwardColumns();
List<String> colName = new ArrayList<String>(ColumnName);
int lag = m_configuration.getLag();
int lagInterval = m_configuration.getLagInterval();
if (m_configuration == null) {
throw new InvalidSettingsException("No configuration available");
}
for (int i = 0; i < colName.size(); i++) {
m_columnIndex = inSpec.findColumnIndex(colName.get(i)); // -1 if row id column or column not present // for index number of the column
if (colName.get(i) != null && m_columnIndex < 0) {
throw new InvalidSettingsException("Selected column \"" + colName.get(i) + "\" does not exist");
}
String baseName = colName.get(i) == null ? "RowID" : colName.get(i);
DataType type = colName.get(i) == null ? StringCell.TYPE : inSpec.getColumnSpec(colName.get(i)).getType();
UniqueNameGenerator gen = new UniqueNameGenerator(inSpec);
DataColumnSpec[] newCols = new DataColumnSpec[lag];
for (int s = 0; s < lag; s++) {
String p = Integer.toString(lagInterval * (s + 1));
newCols[s] = gen.newColumn(baseName + " -" + p, type);
}
m_outSpec = new DataTableSpec(inSpec,new DataTableSpec(newCols));
System.out.println(m_outSpec);
}
}
/**
* @return the outSpecs
*/
DataTableSpec getOutSpec() {
return m_outSpec;
Good day.
I already fixed the looping on the column names. I was able to produce the “column1, column2, column3, column1-1, column2-1 and column3-1”. Currently I am having a problem with the length of arrays in the column name. " Execute failed: Cell count in row “Row0” is not equal to length of column names array: 4 vs. 5". This happens when I selected more than 1 column.
This is what I did on the codes, after creating the DataTableSpec, I put it on a container on the execute method…
ShiftingNodeStreamableOperator(final ShiftingNodeConfiguration configuration,
final DataTableSpec inSpec) throws InvalidSettingsException {
m_configuration = configuration;
Collection<String> ColumnName = m_configuration.iterateColumns();
ArrayList<String> colName = new ArrayList<String>(ColumnName);
int lag = m_configuration.getLag();
int lagInterval = m_configuration.getLagInterval();
if (m_configuration == null) {
throw new InvalidSettingsException("No configuration available");
}
DataColumnSpec[] newCols = new DataColumnSpec[lag * colName.size()];
for (int i = 0; i < colName.size(); i++) {
m_columnIndex = inSpec.findColumnIndex(colName.get(i)); // -1 if row id column or column not present // for
// index number of the column
if (colName.get(i) != null && m_columnIndex < 0) {
throw new InvalidSettingsException("Selected column \"" + colName.get(i) + "\" does not exist");
}
String baseName = colName.get(i) == null ? "RowID" : colName.get(i);
DataType type = colName.get(i) == null ? StringCell.TYPE : inSpec.getColumnSpec(colName.get(i)).getType();
UniqueNameGenerator gen = new UniqueNameGenerator(inSpec);
for (int s = 0; s < lag; s++) {
String p = Integer.toString(lagInterval * (s + 1));
newCols[i * lag + s] = gen.newColumn(baseName + " -" + p, type);
}
}
m_outSpec = new DataTableSpec(inSpec, new DataTableSpec(newCols));
}
DataTableSpec getOutSpec() {
return m_outSpec;
}
Good day.
Thank you for the support. With regards to the DataTableSpec, I was able to do it’s columns, but even if I adapt it using BufferedDataContainer , I am still having a problem with my DataContainer. I thought this thread is closed so I decided to post my concern with another topic, Please see link below.