How to open all the tables within a namespace in your console

When examining new data or monitoring a set of tables, you may want to show all of the tables in a namespace in your console. The following Groovy snippet shows all of the tables for the DbInternal namespace, using variable names equal to the table name.

ns="DbInternal" 
db.getTableNames(ns).sort().each{
     publishVariable(it, db.i(ns, it).where("Date=currentDateNy()"))
}

We will unpack the syntax below and explain how you can modify this script to work with your data.

Syntax

Explanation

ns="DbInternal";

Sets the variable named "ns" to the value "DbInternal" (the namespace)

db.getTableNames(ns)

Gets the list of table names in that namespace

.sort()

Sorts the String names, using the default order (ascending) so that the variables are defined in a predictable order. New tabs in the console are created in that order.

.each{

For each of the string names, this executes the following Groovy closure, which we define inline. The closure is executed once for each name in our list.

publishVariable (it,

Creates a variable with the string contained in "it", which represents table name. For example, "AuditEventLog" is the name of one of the tables in the DbInternal namespace, so one of the created variables will be named "AuditEventLog".

db.i(ns, it)

The second argument to publishVariable is the value to publish db.i(ns, it). This fetches an intraday table. To fetch historical tables, use db.t.

.where("Date=currentDateNy()")

This filters your data to the current day. This .where filter is intended for Deephaven tables that use "Date" as a partitioning column and are centered around the date in New York. If your data is partitioned differently, or uses a different time zone, you should use a different filter. All the tables in the namespace must include this column.

)

Close the publishVariable parentheses.

   )}

The end of the closure each began

The entire command can be written in one line by adding a semi-colon and removing line breaks:

ns="DbInternal";db.getTableNames(ns).sort().each{publishVariable(it, db.i(ns, it).where("Date=currentDateNy()"))}

The following example shows the script as written using Python:

ns="DbInternal"
for tn in db.getTableNames(ns).toArray():
  globals()[tn] = db.i(ns, tn).where("Date=currentDateNy()")


Last Updated: 16 February 2021 18:06 -04:00 UTC    Deephaven v.1.20200928  (See other versions)

Deephaven Documentation     Copyright 2016-2020  Deephaven Data Labs, LLC     All Rights Reserved