| 49 | import io.crate.planner.operators.SubQueryResults; |
| 50 | |
| 51 | public class AlterServerPlan implements Plan { |
| 52 | |
| 53 | private final ForeignDataWrappers foreignDataWrappers; |
| 54 | private final AnalyzedAlterServer alterServer; |
| 55 | |
| 56 | public AlterServerPlan(ForeignDataWrappers foreignDataWrappers, |
| 57 | AnalyzedAlterServer alterServer) { |
| 58 | this.foreignDataWrappers = foreignDataWrappers; |
| 59 | this.alterServer = alterServer; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public StatementType type() { |
| 64 | return StatementType.DDL; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void executeOrFail(DependencyCarrier dependencies, |
| 69 | PlannerContext plannerContext, |
| 70 | RowConsumer consumer, |
| 71 | Row params, |
| 72 | SubQueryResults subQueryResults) throws Exception { |
| 73 | |
| 74 | CoordinatorTxnCtx transactionContext = plannerContext.transactionContext(); |
| 75 | Function<Symbol, Object> convert = new SymbolEvaluator( |
| 76 | transactionContext, |
| 77 | plannerContext.nodeContext(), |
| 78 | subQueryResults |
| 79 | ).bind(params); |
| 80 | |
| 81 | Metadata metadata = plannerContext.clusterState().metadata(); |
| 82 | ServersMetadata servers = metadata.custom(ServersMetadata.TYPE); |
| 83 | if (servers == null) { |
| 84 | throw new ResourceNotFoundException( |
| 85 | String.format(Locale.ENGLISH, "Server `%s` not found", alterServer.name())); |
| 86 | } |
| 87 | ServersMetadata.Server server = servers.get(alterServer.name()); |
| 88 | |
| 89 | ForeignDataWrapper fdw = foreignDataWrappers.get(server.fdw()); |
| 90 | |
| 91 | HashSet<String> optionNames = new HashSet<>(); |
| 92 | Settings.Builder optionsAdded = Settings.builder(); |
| 93 | Settings.Builder optionsUpdated = Settings.builder(); |
| 94 | List<String> optionsRemoved = new ArrayList<>(); |
| 95 | |
| 96 | Map<String, Setting<?>> mandatoryOptions = fdw.mandatoryServerOptions().stream() |
| 97 | .collect(Collectors.toMap(Setting::getKey, Function.identity())); |
| 98 | |
| 99 | for (var option : alterServer.options()) { |
| 100 | if (mandatoryOptions.get(option.key()) == null) { |
| 101 | throw new IllegalArgumentException(String.format( |
| 102 | Locale.ENGLISH, |
| 103 | "Unsupported server options for foreign data wrapper `%s`: %s. Valid options are: %s", |
| 104 | server.fdw(), |
| 105 | option.key(), |
| 106 | fdw.mandatoryServerOptions().stream() |
| 107 | .map(Setting::getKey) |
| 108 | .collect(Collectors.joining(", ")) |
nothing calls this directly
no outgoing calls
no test coverage detected