Converting Legacy scripts to Core+ Scripts Cheat Sheet

Data access methods (both Groovy and Python)

Deephaven method in DHEPython method in DHCGroovy method in DHC
db.idb.live_tabledb.liveTable
db.tdb.historical_tabledb.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 becomes last_by.

  • Aggregation names (previously ComboAggregateFactory) have changed, as detailed below. For example, AggLast becomes agg.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 methodCommunity 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.Calendarsimport deephaven.calendar
import deephaven.Plotimport deephaven.plot
jpy.get_type("com.illumon.iris.db.v2.by.ComboAggregateFactory").*from deephaven import agg
from deephaven.Calendars importfrom deephaven.calendar import
from deephaven import Plotfrom deephaven import plot
from deephaven import TableTools
  • from deephaven import time_table
  • from deephaven import empty_table
  • from deephaven import new_table
from deephaven.Plot importfrom deephaven.plot import
from deephaven.TableTools import emptyTablefrom deephaven import empty_table
from iris.plot importfrom deephaven.plot import

Python method renames

Enterprise methodCommunity methodParameters in array []?
AggArrayagg.group
AggCombo(<original params>)agg_list = [<original params>]
AggCountagg.count_
AggFirstagg.first
AggLastagg.last
AggMaxagg.max_
AggMedagg.median
AggMinagg.min_
AggPctagg.pct
AggStdagg.std
AggSumagg.sum_
AggVaragg.var
avgByavg_by
catHistPlotcat_hist_plot
catPlotcat_plot
chartTitlechart_title
colSpancol_span
convertDateTime
  • from deephaven.time import to_datetime
  • convert_date_time
countBycount_by
db.timeTablefrom deephaven import time_table
dropColumnsdrop_columns
exactJoinexact_join
figureTitlefigure_title
firstByfirst_by
formatColumnWhereformat_column_where
formatColumnsformat_columns
formatRowWhereformat_row_where
getMeta()meta_table
headByhead_by
headPcthead_pct
histPlothist_plot
lastBylast_by
leftJoinleft_join
lineStyleline_style
maxBymax_by
medianBymedian_by
mergemerge
minBymin_by
moveColumnsmove_columns
moveUpColumnsmove_columns_up
naturalJoinnatural_join
newChartnew_chart
ohlcPlotohlc_plot
piePlotpie_plot
renameColumnsrename_columns
selectselect
size()size
sortDescendingsort_descending
stdBystd_by
sumBysum_by
tailBytail_by
tailPcttail_pct
ttools.emptyTable
  • from deephaven import empty_table
  • empty_table
twinXtwin_x
updateViewupdate_view
updateupdate
varByvar_by
viewview
whereInwhere_in
whereNotInwhere_not_in
wherewhere

Internal tooling

Enterprise methodCommunity method
com.fishlib.base.verify.Assertio.deephaven.base.verify.Assert