Skip to main content
Version: Python

How does the console determine what objects tables and charts to display?

When you run a query, Deephaven automatically displays any tables or charts added to your binding by the query. If you do not add a chart/table to your Groovy binding, the chart/table will not be displayed. If you have intermediate tables that you do not want or need to display, then assign them a type so that they are not added to the binding.

Let's take a look at a query that generates three tables:

import static io.deephaven.csv.CsvTools.readCsv

cryptoTrades = readCsv("/data/examples/CryptoCurrencyHistory/CSV/CryptoTrades_20210922.csv")
lastTrades = cryptoTrades.lastBy("Instrument")
lastTradesWithPriceTimesSize = lastTrades.updateView("PriceTimesSize = Price * Size")

When this query runs, tabs for cryptoTrades, lastTrades, and lastTradesWithPriceTimesSize will appear in the console. However, if you do not want to display lastTrades, you can change it to:

import static io.deephaven.csv.CsvTools.readCsv

cryptoTrades = readCsv("/data/examples/CryptoCurrencyHistory/CSV/CryptoTrades_20210922.csv")
def lastTrades = cryptoTrades.lastBy("Instrument")
lastTradesWithPriceTimesSize = lastTrades.updateView("PriceTimesSize = Price * Size")

In this case, lastTrades is not in the binding, and it will not be visible when the script returns. "def" is Groovy's 'type' for dynamic typing outside of the binding.

Here is another version of the query:

import static io.deephaven.csv.CsvTools.readCsv

cryptoTrades = readCsv("/data/examples/CryptoCurrencyHistory/CSV/CryptoTrades_20210922.csv")
Table lastTrades = cryptoTrades.lastBy("Instrument")
lastTradesWithPriceTimesSize = lastTrades.updateView("PriceTimesSize = Price * Size")

lastTrades is no longer in the binding, but there are still references to that table itself, as it is still feeding the lastTradesWithPriceTimesSize table. lastTrades falls between cryptoTrades and lastTradesWithPriceTimesSize in your query graph. However, generally speaking, this does not improve memory usage or performance, since you will still have a reference to the table.

Here is the query all in one line:

lastTradesWithPriceTimesSize = readCsv("/data/examples/CryptoCurrencyHistory/CSV/CryptoTrades_20210922.csv").lastBy("Instrument").updateView("PriceTimesSize = Price * Size")

You may have fewer intermediate table objects that are visible to you at the end of the script, but the query still creates the same number of tables and does the same amount of work:

  1. get a table,
  2. filter it,
  3. look at last rows by Instrument, and
  4. calculate a weighted mid.

However, choosing not to display tables can make a meaningful difference if you are performing an operation in a loop. For example:

// note: this example is pseudocode

dates = //get an array of dates
for(String date : dates) {
t = readCsv("/data/examples/TechStockPortfolio/csv/tech_stock_portfolio_slim.csv")
result = //run a regression, join in positions, etc.
publishVariable("result_$date", result) //put the result in the binding as, for example,"result_2018-04-10"
}

Here, t and result are in the binding, but because they are replaced on each iteration, the tables created by previous iterations can be cleaned up. However, putting the results for each individual date in the binding with publishVariable prevents this cleanup because a brand new variable is being added to the binding on every iteration.