Skip to content

Commit 7c16c10

Browse files
committed
Drop columns from key table
1 parent c90e574 commit 7c16c10

1 file changed

Lines changed: 48 additions & 38 deletions

File tree

web/client-api/src/main/java/io/deephaven/web/client/api/JsPartitionedTable.java

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.partitionedtable_pb.GetTableRequest;
1111
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.partitionedtable_pb.MergeRequest;
1212
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.partitionedtable_pb.PartitionedTableDescriptor;
13+
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.DropColumnsRequest;
1314
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.TypedTicket;
1415
import io.deephaven.web.client.api.barrage.WebBarrageUtils;
1516
import io.deephaven.web.client.api.barrage.def.ColumnDefinition;
@@ -23,6 +24,7 @@
2324
import io.deephaven.web.shared.data.RangeSet;
2425
import io.deephaven.web.shared.fu.JsConsumer;
2526
import jsinterop.annotations.JsIgnore;
27+
import jsinterop.annotations.JsMethod;
2628
import jsinterop.annotations.JsProperty;
2729
import jsinterop.annotations.JsType;
2830
import jsinterop.base.Js;
@@ -45,10 +47,10 @@ public class JsPartitionedTable extends HasLifecycle implements ServerObject {
4547
public static final String EVENT_KEYADDED = "keyadded",
4648
EVENT_DISCONNECT = JsTable.EVENT_DISCONNECT,
4749
EVENT_RECONNECT = JsTable.EVENT_RECONNECT,
48-
/**
49-
* Indicates that an error has occurred while communicating with the server.
50-
*/
51-
EVENT_RECONNECTFAILED = JsTable.EVENT_RECONNECTFAILED;
50+
/**
51+
* Indicates that an error has occurred while communicating with the server.
52+
*/
53+
EVENT_RECONNECTFAILED = JsTable.EVENT_RECONNECTFAILED;
5254

5355
private final WorkerConnection connection;
5456
private final JsWidget widget;
@@ -167,26 +169,26 @@ private void populateLazyTable(List<Object> key) {
167169
tables.put(key, JsLazy.of(() -> {
168170
// If we've entered this lambda, the JsLazy is being used, so we need to go ahead and get the tablehandle
169171
final ClientTableState entry = connection.newState((c, cts, metadata) -> {
170-
// TODO deephaven-core#2529 parallelize this
171-
connection.newTable(
172-
descriptor.getKeyColumnNamesList().asArray(new String[0]),
173-
keyColumnTypes.toArray(new String[0]),
174-
key.stream().map(item -> new Object[] {item}).toArray(Object[][]::new),
175-
null,
176-
this)
177-
.then(table -> {
178-
GetTableRequest getTableRequest = new GetTableRequest();
179-
getTableRequest.setPartitionedTable(widget.getTicket());
180-
getTableRequest.setKeyTableTicket(table.getHandle().makeTicket());
181-
getTableRequest.setResultId(cts.getHandle().makeTicket());
182-
connection.partitionedTableServiceClient().getTable(getTableRequest, connection.metadata(),
183-
(error, success) -> {
184-
table.close();
185-
c.apply(error, success);
186-
});
187-
return null;
188-
});
189-
},
172+
// TODO deephaven-core#2529 parallelize this
173+
connection.newTable(
174+
descriptor.getKeyColumnNamesList().asArray(new String[0]),
175+
keyColumnTypes.toArray(new String[0]),
176+
key.stream().map(item -> new Object[]{item}).toArray(Object[][]::new),
177+
null,
178+
this)
179+
.then(table -> {
180+
GetTableRequest getTableRequest = new GetTableRequest();
181+
getTableRequest.setPartitionedTable(widget.getTicket());
182+
getTableRequest.setKeyTableTicket(table.getHandle().makeTicket());
183+
getTableRequest.setResultId(cts.getHandle().makeTicket());
184+
connection.partitionedTableServiceClient().getTable(getTableRequest, connection.metadata(),
185+
(error, success) -> {
186+
table.close();
187+
c.apply(error, success);
188+
});
189+
return null;
190+
});
191+
},
190192
"partitioned table key " + key);
191193

192194
// later, when the CTS is released, remove this "table" from the map and replace with an unresolved JsLazy
@@ -202,7 +204,7 @@ private void populateLazyTable(List<Object> key) {
202204

203205
/**
204206
* Fetch the table with the given key.
205-
*
207+
*
206208
* @param key The key to fetch. An array of values for each key column, in the same order as the key columns are.
207209
* @return Promise of dh.Table
208210
*/
@@ -225,24 +227,24 @@ public Promise<JsTable> getTable(Object key) {
225227
/**
226228
* Open a new table that is the result of merging all constituent tables. See
227229
* {@link io.deephaven.engine.table.PartitionedTable#merge()} for details.
228-
*
230+
*
229231
* @return A merged representation of the constituent tables.
230232
*/
231233
public Promise<JsTable> getMergedTable() {
232234
return connection.newState((c, cts, metadata) -> {
233-
MergeRequest requestMessage = new MergeRequest();
234-
requestMessage.setPartitionedTable(widget.getTicket());
235-
requestMessage.setResultId(cts.getHandle().makeTicket());
236-
connection.partitionedTableServiceClient().merge(requestMessage, connection.metadata(), c::apply);
237-
}, "partitioned table merged table")
235+
MergeRequest requestMessage = new MergeRequest();
236+
requestMessage.setPartitionedTable(widget.getTicket());
237+
requestMessage.setResultId(cts.getHandle().makeTicket());
238+
connection.partitionedTableServiceClient().merge(requestMessage, connection.metadata(), c::apply);
239+
}, "partitioned table merged table")
238240
.refetch(this, connection.metadata())
239241
.then(cts -> Promise.resolve(new JsTable(cts.getConnection(), cts)));
240242
}
241243

242244
/**
243245
* The set of all currently known keys. This is kept up to date, so getting the list after adding an event listener
244246
* for <b>keyadded</b> will ensure no keys are missed.
245-
*
247+
*
246248
* @return Set of Object
247249
*/
248250
public JsSet<Object> getKeys() {
@@ -254,7 +256,7 @@ public JsSet<Object> getKeys() {
254256

255257
/**
256258
* The count of known keys.
257-
*
259+
*
258260
* @return int
259261
*/
260262
@JsProperty(name = "size")
@@ -284,13 +286,21 @@ public Column[] getColumns() {
284286
}
285287

286288
/**
287-
* A Table object containing all currently known keys used for this partitioned table.
289+
* Fetch a table containing all the valid keys of the partitioned table.
288290
*
289-
* @return Table
291+
* @return Promise of a Table
290292
*/
291-
@JsProperty
292-
public JsTable getKeyTable() {
293-
return keys;
293+
@JsMethod
294+
public Promise<JsTable> getKeyTable() {
295+
return connection.newState((c, state, metadata) -> {
296+
DropColumnsRequest drop = new DropColumnsRequest();
297+
drop.setColumnNamesList(new String[]{descriptor.getConstituentColumnName()});
298+
drop.setSourceId(keys.state().getHandle().makeTableReference());
299+
drop.setResultId(state.getHandle().makeTicket());
300+
connection.tableServiceClient().dropColumns(drop, metadata, c::apply);
301+
}, "drop constituent column")
302+
.refetch(this, connection.metadata())
303+
.then(state -> Promise.resolve(new JsTable(connection, state)));
294304
}
295305

296306
/**

0 commit comments

Comments
 (0)