Skip to content

Commit

Permalink
Apply auto-locking to time_window
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver committed Nov 21, 2024
1 parent 5396c3a commit 715f60c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion py/server/deephaven/experimental/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jpy
from deephaven import DHError
from deephaven.table import Table
from deephaven.update_graph import auto_locking_ctx

_JWindowCheck = jpy.get_type("io.deephaven.engine.util.WindowCheck")

Expand All @@ -31,6 +32,7 @@ def time_window(table: Table, ts_col: str, window: int, bool_col: str) -> Table:
DHError
"""
try:
return Table(j_table=_JWindowCheck.addTimeWindow(table.j_table, ts_col, window, bool_col))
with auto_locking_ctx(table):
return Table(j_table=_JWindowCheck.addTimeWindow(table.j_table, ts_col, window, bool_col))
except Exception as e:
raise DHError(e, "failed to create a time window table.") from e
21 changes: 15 additions & 6 deletions py/server/tests/test_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,24 @@ def test_left_outer_join(self):
self.assertRegex(str(cm.exception), r"Conflicting column names")

def test_time_window(self):
with exclusive_lock(self.test_update_graph):
with self.subTest("user-explicit lock"):
with exclusive_lock(self.test_update_graph):
source_table = time_table("PT00:00:00.01").update(["TS=now()"])
t = time_window(source_table, ts_col="TS", window=10 ** 8, bool_col="InWindow")

self.assertEqual("InWindow", t.columns[-1].name)
self.wait_ticking_table_update(t, row_count=20, timeout=60)
self.assertIn("true", t.to_string(1000))
self.assertIn("false", t.to_string(1000))

with self.subTest("auto-lock"):
source_table = time_table("PT00:00:00.01").update(["TS=now()"])
t = time_window(source_table, ts_col="TS", window=10 ** 8, bool_col="InWindow")

self.assertEqual("InWindow", t.columns[-1].name)
self.wait_ticking_table_update(t, row_count=20, timeout=60)
self.assertIn("true", t.to_string(1000))
self.assertIn("false", t.to_string(1000))

self.assertEqual("InWindow", t.columns[-1].name)
self.wait_ticking_table_update(t, row_count=20, timeout=60)
self.assertIn("true", t.to_string(1000))
self.assertIn("false", t.to_string(1000))

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

0 comments on commit 715f60c

Please sign in to comment.