MCPcopy Create free account
hub / github.com/crate/crate / SwapTablePlan

Class SwapTablePlan

server/src/main/java/io/crate/planner/SwapTablePlan.java:45–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43import io.crate.types.DataTypes;
44
45public class SwapTablePlan implements Plan {
46
47 private final AnalyzedSwapTable swapTable;
48
49 SwapTablePlan(AnalyzedSwapTable swapTable) {
50 this.swapTable = swapTable;
51 }
52
53 @Override
54 public StatementType type() {
55 return StatementType.DDL;
56 }
57
58 @Override
59 public void executeOrFail(DependencyCarrier dependencies,
60 PlannerContext plannerContext,
61 RowConsumer consumer,
62 Row params,
63 SubQueryResults subQueryResults) {
64 boolean dropSource = Objects.requireNonNull(
65 DataTypes.BOOLEAN.sanitizeValue(SymbolEvaluator.evaluate(
66 plannerContext.transactionContext(),
67 dependencies.nodeContext(),
68 swapTable.dropSource(),
69 params,
70 subQueryResults
71 )), SwapTableAnalyzer.DROP_SOURCE + " option must be true or false, not null");
72
73 RelationName source = swapTable.source().ident();
74 SwapRelationsRequest request = new SwapRelationsRequest(
75 Collections.singletonList(new RelationNameSwap(source, swapTable.target().ident())),
76 dropSource ? Collections.singletonList(source) : emptyList()
77 );
78 OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(
79 consumer,
80 r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L)
81 );
82 dependencies.client().execute(TransportSwapRelations.ACTION, request).whenComplete(listener);
83 }
84}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected