/** * extracts the format plugin options based on the scanned implementations of {@link FormatPluginConfig} * @param scanResult */ FormatPluginOptionExtractor(ScanResult scanResult) { Map<String, FormatPluginOptionsDescriptor> result = new HashMap<>(); Set<Class<? extends FormatPluginConfig>> pluginConfigClasses = FormatPluginConfigBase.getSubTypes(scanResult); for (Class<? extends FormatPluginConfig> pluginConfigClass : pluginConfigClasses) { FormatPluginOptionsDescriptor optionsDescriptor = new FormatPluginOptionsDescriptor(pluginConfigClass); result.put(optionsDescriptor.typeName.toLowerCase(), optionsDescriptor); } this.optionsByTypeName = unmodifiableMap(result); }
/** * give a table name, returns function signatures to configure the FormatPlugin * @param tableName the name of the table (or table function in this context) * @return the available signatures */ private List<TableSignature> getTableSignatures(String tableName) { List<TableSignature> result = new ArrayList<>(); for (FormatPluginOptionsDescriptor optionsDescriptor : optionsByTypeName.values()) { TableSignature sig = optionsDescriptor.getTableSignature(tableName); result.add(sig); } return unmodifiableList(result); }
/** * returns the table function signature for this format plugin config class * @param tableName the table for which we want a table function signature * @return the signature */ TableSignature getTableSignature(String tableName) { return new TableSignature(tableName, params()); }
"comment: String, skipFirstLine: boolean, extractHeader: boolean, " + "autoGenerateColumnNames: boolean, trimHeader: boolean, outputExtension: String)", d.presentParams() ); break; case "named": assertEquals(NamedFormatPluginConfig.class, d.pluginConfigClass); assertEquals("(type: String, name: String)", d.presentParams()); break; case "json": assertEquals(d.typeName, "(type: String, outputExtension: String, prettyPrint: boolean)", d.presentParams()); break; case "parquet": assertEquals(d.typeName, "(type: String, autoCorrectCorruptDates: boolean, outputExtension: String)", d.presentParams()); break; case "arrow": assertEquals(d.typeName, "(type: String, outputExtension: String)", d.presentParams()); break; case "sequencefile": case "avro": assertEquals(d.typeName, "(type: String)", d.presentParams()); break; case "excel": assertEquals(d.typeName, "(type: String, sheet: String, extractHeader: boolean, hasMergedCells: boolean, xls: boolean)", d.presentParams()); break; default:
.build(logger); return optionsDescriptor.createConfigForTable(t);
"This function signature is not supported: %s\n" + "expecting %s", t.presentParams(), this.presentParams()) .addContext("table", t.getSig().getName()) .build(logger); "The parameters provided are not applicable to the type specified:\n" + "provided: %s\nexpected: %s", t.presentParams(), this.presentParams()) .addContext("table", t.getSig().getName()) .build(logger);
/** * @return a readable String of the parameters and their names */ 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.getName()).append(": ").append(paramDef.getType().getSimpleName()); } sb.append(")"); return sb.toString(); }
final TableSignature tableSignature = optionsDescriptor.getTableSignature(tableName);