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: ...
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---