| 42 | import io.crate.planner.operators.SubQueryResults; |
| 43 | |
| 44 | public class CreateServerPlan implements Plan { |
| 45 | |
| 46 | private final ForeignDataWrappers foreignDataWrappers; |
| 47 | private final AnalyzedCreateServer createServer; |
| 48 | |
| 49 | public CreateServerPlan(ForeignDataWrappers foreignDataWrappers, |
| 50 | AnalyzedCreateServer createServer) { |
| 51 | this.foreignDataWrappers = foreignDataWrappers; |
| 52 | this.createServer = createServer; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public StatementType type() { |
| 57 | return StatementType.DDL; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void executeOrFail(DependencyCarrier dependencies, |
| 62 | PlannerContext plannerContext, |
| 63 | RowConsumer consumer, |
| 64 | Row params, |
| 65 | SubQueryResults subQueryResults) throws Exception { |
| 66 | |
| 67 | CoordinatorTxnCtx transactionContext = plannerContext.transactionContext(); |
| 68 | Function<Symbol, Object> convert = new SymbolEvaluator( |
| 69 | transactionContext, |
| 70 | plannerContext.nodeContext(), |
| 71 | subQueryResults |
| 72 | ).bind(params); |
| 73 | |
| 74 | Settings.Builder optionsBuilder = Settings.builder(); |
| 75 | Map<String, Symbol> options = new HashMap<>(createServer.options()); |
| 76 | var foreignDataWrapper = foreignDataWrappers.get(createServer.fdw()); |
| 77 | for (var option : foreignDataWrapper.mandatoryServerOptions()) { |
| 78 | String optionName = option.getKey(); |
| 79 | Symbol symbol = options.remove(optionName); |
| 80 | if (symbol == null) { |
| 81 | throw new IllegalArgumentException(String.format( |
| 82 | Locale.ENGLISH, |
| 83 | "Mandatory server option `%s` for foreign data wrapper `%s` is missing", |
| 84 | optionName, |
| 85 | createServer.fdw() |
| 86 | )); |
| 87 | } |
| 88 | optionsBuilder.put(optionName, convert.apply(symbol)); |
| 89 | } |
| 90 | if (!options.isEmpty()) { |
| 91 | throw new IllegalArgumentException(String.format( |
| 92 | Locale.ENGLISH, |
| 93 | "Unsupported server options for foreign data wrapper `%s`: %s. Valid options are: %s", |
| 94 | createServer.fdw(), |
| 95 | String.join(", ", options.keySet()), |
| 96 | foreignDataWrapper.mandatoryServerOptions().stream() |
| 97 | .map(x -> x.getKey()) |
| 98 | .collect(Collectors.joining(", ")) |
| 99 | )); |
| 100 | } |
| 101 | CreateServerRequest request = new CreateServerRequest( |
nothing calls this directly
no outgoing calls
no test coverage detected