sekruse / metanome-cli

Run Metanome algorithms from the command line
http://www.metanome.de/
Apache License 2.0
7 stars 6 forks source link

String config that looks like integer breaks algorithm configuration #1

Closed Parnswir closed 6 years ago

Parnswir commented 6 years ago

If an algorithm implements both IntegerParameterAlgorithm and StringParameterAlgorithm, and a --algorithm-config value is a valid integer, it will not work for a string parameter.

How to reproduce

// MyAlgorithm.java

public class MyAlgorithm implements StringParameterAlgorithm, IntegerParameterAlgorithm {
//...
        @Override
    public void setIntegerConfigurationValue(String identifier, Integer... values) throws AlgorithmConfigurationException {
        if (Identifier.SOME_INTEGER_PARAMETER.name().equals(identifier)) {
            this.someIntegerParameter= values[0];
        } else {
            this.handleUnknownConfiguration(identifier, CollectionUtils.concat(values, ","));
        }
    }

        @Override
    public void setStringConfigurationValue(String identifier, String... values) throws AlgorithmConfigurationException {
        if (Identifier.SOME_STRING_PARAMETER.name().equals(identifier)) {
            this.someStringParameter= values[0];
        } else {
            this.handleUnknownConfiguration(identifier, CollectionUtils.concat(values, ","));
        }
    }
//...
}

metanome-cli: java -cp metanome-cli-0.1-SNAPSHOT.jar;MyAlgorithm-1.1-SNAPSHOT.jar de.metanome.cli.App -a de.metanome.algorithms.MyAlgorithm --file-key INPUT_GENERATOR --separator , --header --null ? --files sample.csv --algorithm-config SOME_STRING_PARAMETER:0

will result in something like

Initializing algorithm.
Could not initialize algorithm.
de.metanome.algorithm_integration.AlgorithmConfigurationException: Unknown configuration: SOME_STRING_PARAMETER -> 0
        at de.metanome.algorithms.MyAlgorithm.handleUnknownConfiguration(MyAlgorithm.java:209)
        at de.metanome.algorithms.MyAlgorithm.setIntegerConfigurationValue(MyAlgorithm.java:196)
        at de.metanome.cli.App.loadMiscConfigurations(App.java:300)
        at de.metanome.cli.App.configureAlgorithm(App.java:267)
        at de.metanome.cli.App.run(App.java:83)
        at de.metanome.cli.App.main(App.java:47)

Workaround

This behavior is caused by https://github.com/sekruse/metanome-cli/blob/master/src/main/java/de/metanome/cli/App.java#L285, which will turn every config that looks like an Integer into an IntegerParameter, even if the algorithm does not accept it. For my use case (float parameter), it was sufficient to add .0 to the algorithm-config, however for many other cases this will not work.

Impact

This impacts BooleanParameterAlgorithms as well. There may be use cases where the algorithm needs a String parameter like searchString -> "true", or someSpecialValue -> 2.

f4lco commented 6 years ago

ListBoxParameterAlgorithm and CheckBoxParameterAlgorithm are also affected in pretty much the same way, since the configuration values are indistinguishable from a "standard" string configuration value.