Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Not A Problem
-
1.13.0
-
None
-
None
-
None
Description
Consider an example format plugin, such as the regex one used in the Drill book. (GitHub reference needed.) We can define the plugin using getters and setters like this:
public class RegexFormatConfig implements FormatPluginConfig { private String regex; private String fields; private String extension; public void setRegex(String regex) { this.regex = regex; } public void setFields(String fields) { this.fields = fields; } public void setExtension(String extension) { this.extension = extension; }
We can then create a plugin configuration using the Drill Web console, the bootstrap-storage-plugins.json and so on. All work fine.
Suppose we try to define a configuration using a Drill table function:
final String sql = "SELECT * FROM table(cp.`regex/simple.log2`\n" + "(type => 'regex',\n" + " extension => 'log2',\n" + " regex => '(\\\\d\\\\d\\\\d\\\\d)-(\\\\d\\\\d)-(\\\\d\\\\d) .*',\n" + " fields => 'a, b, c, d'))";
We get this error:
org.apache.drill.common.exceptions.UserRemoteException: PARSE ERROR: can not set value (\d\d\d\d)-(\d\d)-(\d\d) .* to parameter regex: class java.lang.String table regex/simple.log2 parameter regex
The reason is that the code that handles table functions only knows how to set public fields, it does not know about the Java Bean getter/setter conventions used by Jackson:
package org.apache.drill.exec.store.dfs; ... final class FormatPluginOptionsDescriptor { ... FormatPluginConfig createConfigForTable(TableInstance t) { ... Field field = pluginConfigClass.getField(paramDef.name); ... } field.set(config, param); } catch (IllegalAccessException | NoSuchFieldException | SecurityException e) { throw UserException.parseError(e) .message("can not set value %s to parameter %s: %s", param, paramDef.name, paramDef.type) ...
The only workaround is to make all fields public:
public class RegexFormatConfig implements FormatPluginConfig { public String regex; public String fields; public String extension;
Since public fields are not good practice, please modify the table function mechanism to follow Jackson conventions and allow Java Bean style setters. (Or better, fix DRILL-6673 to allow immutable format objects via the use of a constructor.)
Attachments
Issue Links
- Is contained by
-
DRILL-6986 Table function improvements / issues (UMBRELLA JIRA)
- Open
- is related to
-
DRILL-7612 Modify the Text, Excel format config, etc. immutable
- Open