create new column - best practice question

Hi,

I have a very basic question. I have a (java based) node which will create a new column. The user can provide the name of the new column via TextInputWidget. I added the column name validation pattern which will show a red “warning” if the input field is empty.

@TextInputWidget(patternValidation = ColumnNameValidationUtils.ColumnNameValidation.class )

Still, the user can apply and execute the node.

When creating the column rearranger, I provided the setup for the new column like this:

final var uniqueNameGenerator = new UniqueNameGenerator(spec);
DataColumnSpec cspec = uniqueNameGenerator.newColumn(outputColumnName, outType);

If the new column name is an empty string, I will get a new column named <empty_1>.

First, I am confused that the number within that column name varies when changing/applying the settings several times. (looks like a bug to me)

Second, I was wondering whether it would be good practice to avoid these cases (by checking for an empty string and throwing an InvalidSettingsException) or if there is any scenario when these names are valid.

I can provide the full code of this node if that helps.

Antje

Hi @niederle - Good question!

Let me ask internally to see if I can find the right person to help.

Hi @niederle,

It’s expected that the number changes, and it’s good practice to prevent users from running into automatic column name generation.
Therefore, such cases should be avoided — as you mentioned — by throwing an InvalidSettingsException.
The ColumnNameValidationUtils class provides a method, validateColumnName, which checks for various invalid column name conditions (the same ones checked by ColumnNameValidationUtils.ColumnNameValidation).

Best regards,
Robin

1 Like

@robin_gerling

Thanks a lot for the clarification and the hint with the ColumnNameValidationUtils.validateColumnName. That helps a lot.

Best,
Antje

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.