You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by "Paul Rogers (JIRA)" <ji...@apache.org> on 2018/08/08 00:23:00 UTC

[jira] [Created] (DRILL-6672) Drill table functions cannot handle "setFoo" accessors

Paul Rogers created DRILL-6672:
----------------------------------

             Summary: Drill table functions cannot handle "setFoo" accessors
                 Key: DRILL-6672
                 URL: https://issues.apache.org/jira/browse/DRILL-6672
             Project: Apache Drill
          Issue Type: Bug
    Affects Versions: 1.13.0
            Reporter: Paul Rogers


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:

{code}
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; }
{code}

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:

{code}
      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'))";
{code}

We get this error:

{noformat}
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
{noformat}

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:

{code}
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)
            ...
{code}

The only workaround is to make all fields public:

{code}
public class RegexFormatConfig implements FormatPluginConfig {

  public String regex;
  public String fields;
  public String extension;
{code}

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-xxxx to allow immutable format objects via the use of a constructor.)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)