Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for empty data for add/delete/+async on InputTable #5242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ public TableDefinition getTableDefinition() {
public void add(@NotNull final Table newData) throws IOException {
checkBlockingEditSafety();
PendingChange pendingChange = enqueueAddition(newData);
blockingContinuation(pendingChange);
if (pendingChange != null) {
blockingContinuation(pendingChange);
}
}

@Override
Expand All @@ -207,14 +209,21 @@ public void addAsync(
@NotNull final InputTableStatusListener listener) {
checkAsyncEditSafety(newData);
final PendingChange pendingChange = enqueueAddition(newData);
asynchronousContinuation(pendingChange, listener);
if (pendingChange != null) {
asynchronousContinuation(pendingChange, listener);
} else {
listener.onSuccess();
}
}

private PendingChange enqueueAddition(@NotNull final Table newData) {
validateAddOrModify(newData);
// we want to get a clean copy of the table; that can not change out from under us or result in long reads
// during our UGP run
final Table newDataSnapshot = snapshotData(newData);
if (newDataSnapshot.size() == 0) {
return null;
}
final PendingChange pendingChange;
synchronized (pendingChanges) {
pendingChange = new PendingChange(newDataSnapshot, false);
Expand All @@ -228,7 +237,9 @@ private PendingChange enqueueAddition(@NotNull final Table newData) {
public void delete(@NotNull final Table table) throws IOException {
checkBlockingEditSafety();
final PendingChange pendingChange = enqueueDeletion(table);
blockingContinuation(pendingChange);
if (pendingChange != null) {
blockingContinuation(pendingChange);
}
}

@Override
Expand All @@ -237,12 +248,19 @@ public void deleteAsync(
@NotNull final InputTableStatusListener listener) {
checkAsyncEditSafety(table);
final PendingChange pendingChange = enqueueDeletion(table);
asynchronousContinuation(pendingChange, listener);
if (pendingChange != null) {
asynchronousContinuation(pendingChange, listener);
} else {
listener.onSuccess();
}
}

private PendingChange enqueueDeletion(@NotNull final Table table) {
validateDelete(table);
final Table oldDataSnapshot = snapshotData(table);
if (oldDataSnapshot.size() == 0) {
return null;
}
final PendingChange pendingChange;
synchronized (pendingChanges) {
pendingChange = new PendingChange(oldDataSnapshot, true);
Expand Down
20 changes: 20 additions & 0 deletions py/server/tests/test_table_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,26 @@ def test_instant_array(self):
self.wait_ticking_table_update(t5, row_count=1, timeout=5)
self.assertEqual(t5.size, 1)

def test_input_table_empty_data(self):
from deephaven import update_graph as ugp
from deephaven import execution_context as ec

ug = ec.get_exec_ctx().update_graph
cm = ugp.exclusive_lock(ug)

with cm:
t = time_table("PT1s", blink_table=True)
it = input_table({c.name: c.data_type for c in t.columns}, key_cols="Timestamp")
it.add(t)
self.assertEqual(it.size, 0)
it.delete(t)
self.assertEqual(it.size, 0)

t = empty_table(0).update("Timestamp=nowSystem()")
it.add(t)
self.assertEqual(it.size, 0)
it.delete(t)
self.assertEqual(it.size, 0)

if __name__ == '__main__':
unittest.main()
Loading