[ 
https://issues.apache.org/jira/browse/DRILL-4047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15004540#comment-15004540
 ] 

ASF GitHub Bot commented on DRILL-4047:
---------------------------------------

Github user jacques-n commented on a diff in the pull request:

    https://github.com/apache/drill/pull/246#discussion_r44822308
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
 ---
    @@ -148,12 +175,427 @@ private Path getViewPath(String name) {
         return DotDrillType.VIEW.getPath(config.getLocation(), name);
       }
     
    -  public WorkspaceSchema createSchema(List<String> parentSchemaPath, 
SchemaConfig schemaConfig) throws  IOException {
    +  public WorkspaceSchema createSchema(List<String> parentSchemaPath, 
SchemaConfig schemaConfig) throws IOException {
         return new WorkspaceSchema(parentSchemaPath, schemaName, schemaConfig);
       }
     
    -  public class WorkspaceSchema extends AbstractSchema implements 
ExpandingConcurrentMap.MapValueFactory<String, DrillTable> {
    -    private final ExpandingConcurrentMap<String, DrillTable> tables = new 
ExpandingConcurrentMap<>(this);
    +  /**
    +   * Describes the options for a format plugin
    +   * extracted from the FormatPluginConfig subclass
    +   */
    +  static final class OptionsDescriptor {
    +    final Class<? extends FormatPluginConfig> pluginConfigClass;
    +    final String typeName;
    +    private final Map<String, TableParamDef> functionParamsByName;
    +
    +    OptionsDescriptor(Class<? extends FormatPluginConfig> 
pluginConfigClass) {
    +      this.pluginConfigClass = pluginConfigClass;
    +      Map<String, TableParamDef> paramsByName = new LinkedHashMap<>();
    +      Field[] fields = pluginConfigClass.getDeclaredFields();
    +      // @JsonTypeName("text")
    +      JsonTypeName annotation = 
pluginConfigClass.getAnnotation(JsonTypeName.class);
    +      this.typeName = annotation != null ? annotation.value() : null;
    +      if (this.typeName != null) {
    +        paramsByName.put("type", new TableParamDef("type", String.class));
    +      }
    +      for (Field field : fields) {
    +        if (Modifier.isStatic(field.getModifiers())
    +            // we want to deprecate this field
    +            || (field.getName().equals("extensions") && field.getType() == 
List.class)) {
    +          continue;
    +        }
    +        Class<?> fieldType = field.getType();
    +        if (fieldType == char.class) {
    +          // calcite does not like char type. Just use String and enforce 
later that length == 1
    +          fieldType = String.class;
    +        }
    +        paramsByName.put(field.getName(), new 
TableParamDef(field.getName(), fieldType).optional());
    +      }
    +      this.functionParamsByName = unmodifiableMap(paramsByName);
    +    }
    +
    +    TableSignature getTableSignature(String tableName) {
    +      return new TableSignature(tableName, params());
    +    }
    +
    +    private List<TableParamDef> params() {
    +      return new ArrayList<>(functionParamsByName.values());
    +    }
    +
    +    String presentParams() {
    +      StringBuilder sb = new StringBuilder("(");
    +      List<TableParamDef> params = params();
    +      for (int i = 0; i < params.size(); i++) {
    +        TableParamDef paramDef = params.get(i);
    +        if (i != 0) {
    +          sb.append(", ");
    +        }
    +        sb.append(paramDef.name).append(": 
").append(paramDef.type.getSimpleName());
    +      }
    +      sb.append(")");
    +      return sb.toString();
    +    }
    +
    +    FormatPluginConfig eval(TableInstance t) {
    +      // Per the constructor, the first param is always "type"
    +      TableParamDef typeParamDef = t.sig.params.get(0);
    +      Object typeParam = t.params.get(0);
    +      if (!typeParamDef.name.equals("type") || typeParamDef.type != 
String.class || !(typeParam instanceof String)
    +          || !typeName.equalsIgnoreCase((String) typeParam)) {
    +        badInput(t);
    +      }
    +      FormatPluginConfig config;
    +      try {
    +        config = pluginConfigClass.newInstance();
    +      } catch (InstantiationException | IllegalAccessException e) {
    +        throw UserException.parseError(e)
    +            .message(
    +                "configuration for format of type %s can not be created 
(class: %s)",
    +                this.typeName, pluginConfigClass.getName())
    +            .addContext("table", t.sig.name)
    +            .build(logger);
    +      }
    +      for (int i = 1; i < t.params.size(); i++) {
    +        Object param = t.params.get(i);
    +        if (param == null)
    +          continue;
    +        TableParamDef paramDef = t.sig.params.get(i);
    +        TableParamDef expectedParamDef = 
this.functionParamsByName.get(paramDef.name);
    +        if (expectedParamDef == null || expectedParamDef.type != 
paramDef.type) {
    +          badInput(t);
    --- End diff --
    
    I think you should make these errors much more specific (e.g. param 'name' 
was of type 'blah' but was actually of type 'blah'. Expected parameters are: ...


> Select with options
> -------------------
>
>                 Key: DRILL-4047
>                 URL: https://issues.apache.org/jira/browse/DRILL-4047
>             Project: Apache Drill
>          Issue Type: Improvement
>          Components: Execution - Relational Operators
>            Reporter: Julien Le Dem
>            Assignee: Julien Le Dem
>
> Add a mechanism to pass parameters down to the StoragePlugin when writing a 
> Select statement.
> Some discussion here:
> http://mail-archives.apache.org/mod_mbox/drill-dev/201510.mbox/%3CCAO%2Bvc4AcGK3%2B3QYvQV1-xPPdpG3Tc%2BfG%3D0xDGEUPrhd6ktHv5Q%40mail.gmail.com%3E
> http://mail-archives.apache.org/mod_mbox/drill-dev/201511.mbox/%3ccao+vc4clzylvjevisfjqtcyxb-zsmfy4bqrm-jhbidwzgqf...@mail.gmail.com%3E



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to