Converting Legacy scripts to Core+ Scripts Cheat Sheet
Data access methods (both Groovy and Python)
Deephaven method in DHE | Python method in DHC | Groovy method in DHC |
---|---|---|
db.i | db.live_table | db.liveTable |
db.t | db.historical_table | db.historicalTable |
Empty .where()
clauses
In an Enterprise Legacy worker, a .where()
method applied to an uncoalesced table (e.g., the return from db.t
before filtering
by a partitioning column) would coalesce the table. Alternatively, the table could explicitly be realized with the
.coalsece()
method. In Community, you must use the .coalesce()
method instead of .where()
.
Time handling
The Deephaven Community time library is very different from the Enterprise Library, having been thoroughly modernized as described in this blog post.
In particular, Enterprise queries that used currentDateNy()
must use today()
, business calendars are entirely re-written, and the syntax of periods as input to time_table
have changed.
To get the current date, you must use the today()
function, which takes an optional time zone. You can use a full time zone name like America/New_York
or the shortcut ET
for Eastern time. The equivalent function to currentDateNy()
is either today(timeZone(`America/New_York`))
or today(timeZone(`ET`))
, as in the following example:
quotes = db.liveTable("Market", "EqQuote").where("Date=today(timeZone(`ET`))")
quotes = db.live_table("Market", "EqQuote").where("Date=today(timeZone(`ET`))")
When the time zone is omitted, the today()
function uses the value of the user.timezone
property.
The common Legacy idiom lastBusinessDateNy()
to get yesterday's data has been replaced by functions on the BusinessCalendar class. First, you must retrieve the calendar with the calendar()
function, which on a default Core+ installation returns the USNYSE
business calendar. To verify your default business calendar, you can run the following command:
println(io.deephaven.time.calendar.Calendars.calendar().name())
import deephaven.calendar
print(deephaven.calendar.calendar().name())
You can specify an alternative business calendar name as an argument to the calendar()
function. For filtering Date partitions, you may either use the minusBusinessDays
method and pass today()
as a String argument or use the pastBusinessDate
method and convert the resulting java.time.LocalDate
to a String.
As a shortcut, you can elide calendar()
for the default calendar.
The following six examples all retrieve yesterday's data:
quotes = db.historicalTable("Market", "EqQuote").where("Date=minusBusinessDays(today(), 1)")
quotes2 = db.historicalTable("Market", "EqQuote").where("Date=pastBusinessDate(1).toString()")
quotes3 = db.historicalTable("Market", "EqQuote").where("Date=calendar().minusBusinessDays(today(), 1)")
quotes4 = db.historicalTable("Market", "EqQuote").where("Date=calendar().pastBusinessDate(1).toString()")
quotes5 = db.historicalTable("Market", "EqQuote").where("Date=calendar(`USNYSE`).minusBusinessDays(today(), 1)")
quotes6 = db.historicalTable("Market", "EqQuote").where("Date=calendar(`USNYSE`).pastBusinessDate(1).toString()")
quotes = db.historical_table("Market", "EqQuote").where("Date=minusBusinessDays(today(), 1)")
quotes2 = db.historical_table("Market", "EqQuote").where("Date=pastBusinessDate(1).toString()")
quotes3 = db.historical_table("Market", "EqQuote").where("Date=calendar().minusBusinessDays(today(), 1)")
quotes4 = db.historical_table("Market", "EqQuote").where("Date=calendar().pastBusinessDate(1).toString()")
quotes5 = db.historical_table("Market", "EqQuote").where("Date=calendar(`USNYSE`).minusBusinessDays(today(), 1)")
quotes6 = db.historical_table("Market", "EqQuote").where("Date=calendar(`USNYSE`).pastBusinessDate(1).toString()")
Caution
If you use the pastBusinessDate
function, then you must convert the result from a LocalDate
to a String
. If you compare a LocalDate
to your partitioning column, a match is impossible and the result is an empty table.
For time tables, you must use the new Period syntax. For example:
fiveSeconds = timeTable("PT5s")
oneHour = timeTable("PT1h")
from deephaven import time_table
five_seconds = time_table("PT5s")
one_hour = time_table("PT1h")
Python-only summary of changes
-
Method names are now
snake_case
. For example,lastBy
becomeslast_by
. -
Aggregation names (previously
ComboAggregateFactory
) have changed, as detailed below. For example,AggLast
becomesagg.last
. -
In instances of more than one parameter, arguments may take array lists instead of multiple strings; e.g.,
t.update(["Update Statement 1", "Update Statement 2", ...])
. These are marked in the "Python method renames" table below. For comparison:-
In an Enterprise script,
AggTypes
will be comma-separated:source.by(AggCombo(AggType("Col1"), AggType("Col2 = NewCol1")), "Key1" , "Key2")
. -
In Core, this becomes an
agg_list
within arrays:agg_list=[ agg.first(cols=["Col1 = NewCol1"]), agg.last(cols=["Col2 = NewCol2"]), ] source.agg_by(agg_list, by=["GroupingColumns..."])
-
Important
This is not a comprehensive listing of all Python commands -- only those where the syntax has changed.
Python import translation
Enterprise method | Community method |
---|---|
import com.illumon.iris.db.Plot.* | from deephaven.plot import * |
import com.illumon.iris.db.Plot.colors.* | from deephaven.plot.color import * |
import deephaven.Calendars | import deephaven.calendar |
import deephaven.Plot | import deephaven.plot |
jpy.get_type("com.illumon.iris.db.v2.by.ComboAggregateFactory").* | from deephaven import agg |
from deephaven.Calendars import | from deephaven.calendar import |
from deephaven import Plot | from deephaven import plot |
from deephaven import TableTools |
|
from deephaven.Plot import | from deephaven.plot import |
from deephaven.TableTools import emptyTable | from deephaven import empty_table |
from iris.plot import | from deephaven.plot import |
Python method renames
Enterprise method | Community method | Parameters in array [] ? |
---|---|---|
AggArray | agg.group | ✅ |
AggCombo(<original params>) | agg_list = [<original params>] | |
AggCount | agg.count_ | ✅ |
AggFirst | agg.first | ✅ |
AggLast | agg.last | ✅ |
AggMax | agg.max_ | ✅ |
AggMed | agg.median | ✅ |
AggMin | agg.min_ | ✅ |
AggPct | agg.pct | ✅ |
AggStd | agg.std | ✅ |
AggSum | agg.sum_ | ✅ |
AggVar | agg.var | ✅ |
avgBy | avg_by | |
catHistPlot | cat_hist_plot | |
catPlot | cat_plot | |
chartTitle | chart_title | |
colSpan | col_span | |
convertDateTime |
| |
countBy | count_by | |
db.timeTable | from deephaven import time_table | |
dropColumns | drop_columns | |
exactJoin | exact_join | |
figureTitle | figure_title | |
firstBy | first_by | |
formatColumnWhere | format_column_where | |
formatColumns | format_columns | ✅ |
formatRowWhere | format_row_where | |
getMeta() | meta_table | |
headBy | head_by | |
headPct | head_pct | |
histPlot | hist_plot | |
lastBy | last_by | |
leftJoin | left_join | |
lineStyle | line_style | |
maxBy | max_by | |
medianBy | median_by | |
merge | merge | ✅ |
minBy | min_by | |
moveColumns | move_columns | |
moveUpColumns | move_columns_up | |
naturalJoin | natural_join | |
newChart | new_chart | |
ohlcPlot | ohlc_plot | |
piePlot | pie_plot | |
renameColumns | rename_columns | ✅ |
select | select | ✅ |
size() | size | |
sortDescending | sort_descending | |
stdBy | std_by | |
sumBy | sum_by | |
tailBy | tail_by | |
tailPct | tail_pct | |
ttools.emptyTable |
| |
twinX | twin_x | |
updateView | update_view | ✅ |
update | update | ✅ |
varBy | var_by | |
view | view | ✅ |
whereIn | where_in | |
whereNotIn | where_not_in | |
where | where | ✅ |
Internal tooling
Enterprise method | Community method |
---|---|
com.fishlib.base.verify.Assert | io.deephaven.base.verify.Assert |