[
https://issues.apache.org/jira/browse/DRILL-4047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15004537#comment-15004537
]
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_r44821481
--- 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);
+ }
+ try {
+ Field field = pluginConfigClass.getField(paramDef.name);
+ field.setAccessible(true);
+ if (field.getType() == char.class && param instanceof String) {
+ String stringParam = (String) param;
+ if (stringParam.length() != 1) {
+ throw UserException.parseError()
+ .message("Expected character but was String: %s",
stringParam)
+ .addContext("table", t.sig.name)
+ .addContext("parameter", paramDef.name)
+ .build(logger);
+ }
+ param = stringParam.charAt(0);
+ }
+ 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)
+ .addContext("table", t.sig.name)
+ .addContext("parameter", paramDef.name)
+ .build(logger);
+ }
+ }
+ return config;
+ }
+
+ private void badInput(TableInstance t) {
+ throw new IllegalArgumentException("The parameters provided are not
applicable to the type specified:\n"
--- End diff --
UserException?
> 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)