Managing Persistent Queries
Persistent Queries (PQs) in Deephaven are designed to run continuously, maintaining state and updating as new data arrives. For queries whose scripts refer to specific dates (often because functions like today()
are evaluated at script initialization), daily restarts are typically necessary. This applies to nearly all queries, since data tables are almost always partitioned by date. The appropriate time to restart a query depends on the region it serves and the schedules of the data imports it relies on. It is possible to use different times and time zones for each query (typically configured via Persistent Query Controller tools or scheduling settings).
In most cases, a single query can serve multiple regions as long as there are overlapping periods of inactivity (e.g., when data feeds are paused or user activity is minimal across those regions). Otherwise, separate queries should be used for each region.
For example, a query script might contain the following code:
// 'today()' is evaluated at script start; 'calendar("USNYSE")' provides NYSE trading day logic.
myDate = calendar("USNYSE").minusBusinessDays(today(), 1)
// 'db.historicalTable' accesses a date-partitioned table.
t = db.historicalTable("MyNamespace", "MyTable").where("Date=myDate")
When running this script, the minusBusinessDays
function is executed. Its value is stored as the myDate
variable, and a table is accessed and filtered for the date stored in this variable. This happens exactly once, and the results will not change, even if the query worker is kept running for days. As a result, if a PQ using this script is intended to always show data for "yesterday" from the user's perspective, it must be restarted each day in order to re-execute the code.