Access
Finding Data Sources
The data loaded on your installation of Deephaven is managed by your system administrator. To learn about installed data, you can run the following commands in the Deephaven console:
- To review a table listing all the available tables in the database, run:
tables = db.getCatalog()
- To find available namespaces, run:
println db.getNamespaces()
orprint(db.getNamespaces()
- To find available tables within a namespace, run:
println db.getTableNames("<namespace")
orprint(db.getTableNames("<namespace"))
; e.g.,print(db.getTableNames("LearnDeephaven"))
- To see all of the column names and data types within a specific table, run:
t = db.t("<namespace>","<tablename>").getMeta()
Tip
The "autocomplete" feature can also be used to discover and insert namespaces and table names into your queries. Move to one of the suggested values and click or press Return/Enter on the highlighted item
Data Table Types
Deephaven supports two types of tables: live tables and static tables.
- Static tables (sometimes called "historical" tables) are regular data tables: they have fixed numbers of rows and columns, and contain fixed data.
- Live tables (also known as "real-time" or "intraday") tables have a fixed number of columns, but new rows of data can be appended to the table over time.
The syntax is nearly identical when accessing both static and live data, but working with live data introduces additional performance concerns.
Note
See also: Working with Live vs. Static Data
Accessing Static Data
To retrieve static data, use the db.t()
method, and pass the table's namespace and table name as arguments. The example below retrieves the table called "exampleTable" from a namespace called "exampleNamespace", and stores the result under the variable t
.
Note
exampleNamespace
and exampleTable
are not actual datasets available within Deephaven.
t = db.t("exampleNamespace", "exampleTable")
In many cases, the table to access is partitioned. When accessing a partitioned table, it is highly recommended to immediately filter the table by partition. The example below demonstrates how to filter exampleTable
to the partition for March 15, 2017. (This example assumes that exampleTable
is partitioned by the Date column.)
t = db.t("exampleNamespace", "exampleTable").where("Date=`2017-03-15`")
Many tables are partitioned by date. In these cases, using a function to provide the date can produce a more robust query. The following example demonstrates how to access a table and filter to the previous business date (using New York time):
t = db.t("exampleNamespace", "exampleTable").where("Date=lastBusinessDateNy()")
Accessing Live Data
To retrieve live data, use the db.i()
method instead of db.t()
. The method parameters are the same. (The "i" in db.i
stands for "intraday".)
Note
All live tables are partitioned tables, so any access to a live table should be immediately followed by a filter on the partitioning column.
The following line of code is an example of how to access live data for exampleTable
from March 15, 2017.
t = db.i("exampleNamespace", "exampleTable").where("Date=`2017-03-15`")
As with static data, it may be desirable to filter the data to a date determined by a function:
t = db.i("exampleNamespace", "exampleTable").where("Date=currentDateNy()")
Non-Updating Live Data
In some cases, a query requires the most recent data at the time of its initialization, but no subsequent updates. To disable updates when accessing live data, pass "false
" as the third argument to db.i()
. This will direct the query engine to not enable live updates for this table, which means new rows will never be appended to it.
t = db.i("exampleNamespace", "exampleTable", false).where("Date=currentDateNy()")
from deephaven import *
t = db.i("exampleNamespace", "exampleTable", False).where("Date=currentDateNy()")
Predefined Variables
Deephaven predefines certain variables as follows.
You can refer to a particular query with these constants:
PERSISTENT_QUERY_OWNER
- e.g.,demoUser
PERSISTENT_QUERY_NAME
- e.g.,OrderTable
,MyMergeQuery
PERSISTENT_QUERY_SERIAL_NUMBER
- e.g.,1234568256427000000
There are two variables available for database in either a Groovy or Python session:
db
- variable for databasedatabase
- variable database
Upon Groovy shell initialization:
DB_SCRIPT_PATH
- defines the location from where you can source scripts that exist on the server._groovySession
- allows you to work with the Groovy session directly (for example, to add variables directly to the binding).