Aggregating Column Values in Tables
At this time, Table Totals are only available in Deephaven Classic.
For users who want to see aggregated column values in a table, such as the total sum of values in a column, or an average value of a particular column, Deephaven offers two options. Data aggregation can be accomplished through the Deephaven console using the Show Totals option in the right-click context menu, or it can be accomplished through the query language in a persistent query. To learn more about using Show Totals in the Deephaven console, see: Working With Tables > Show Totals.
The following section details how to configure totals using query methods.
Configuring Table Totals through a Query
A Grand Totals section can be added to the top of any table using the setTotalsTable
method in a persistent query.
To build a table that presents aggregated values for one or more columns (filtered or not), users must first import the com.illumon.iris.db.v2.TotalsTableBuilder class
. The TotalsTableBuilder
class is used to define the default aggregations to be displayed in the Grand Totals and Totals section(s) of a particular table.
Example
The following example creates a table using data from the StockQuotes
table in the LearnDeephaven
namespace. The final generated table will include the Grand Totals section at the top of the table:
from deephaven import *
t1 = db.t("LearnDeephaven", "StockQuotes").where("Date=`2017-08-25`")
t2 = t1.setTotalsTable(TotalsTableBuilder()
.setOperation("Bid", "Avg")
.setOperation("Ask", "Avg"))
import com.illumon.iris.db.v2.TotalsTableBuilder
t1 = db.t("LearnDeephaven" , "StockQuotes").where("Date=`2017-08-25`")
t2 = t1.setTotalsTable(new TotalsTableBuilder()
.setOperation("Bid", "Avg")
.setOperation("Ask", "Avg"))
- The first line tells Deephaven where to import the class needed for the query to run properly.
- The second line of the query generates the
t1
table using data from theStockQuotes
table. - The third line of the query creates the
t2
table by creating a new instance of theTotalsTableBuilder
, chains together a series of operations to fully define the desired aggregation, and, finally, passes the result of the chaining to thesetTotalsTable()
method of the table.
In this example, the Grand Totals section (and Totals section if present) will display the average size of the Bid
column and the average size of the Ask
column. See below:
The query used for the example did not configure the setShowGrandTotalsByDefault
argument to true (see the list of available methods below), so the Grand Totals section will appear in its collapsed state when the table is shown. The Totals section will only appear if the table is manually filtered.
The parameters set in the query become the Table Default However, they do not prevent individual users from customizing the aggregations in their workspace using the Edit Totals dialog. For more information about manually configuring the options available and restoring the default settings, please refer to Show Totals.
Available Methods
The following methods are included within TotalsTableBuilder
:
Method |
Description |
---|---|
|
Creates a new instance of a |
|
Creates a new instance of a |
|
Adds a column operation to the set of aggregations. You can select multiple aggregations on the same column by including distinct |
addOperation("ColName", "Operation", "Format") |
Adds a column operation to the set of aggregations, and also a format by which to display the total value; e.g., |
|
Sets the aggregation for the specified column. Note that this will replace any other aggregations specified by |
setOperation("ColName", "Operation", "Format") |
Sets the aggregation for the specified column, and also a format by which to display the total value; e.g, |
|
Sets the default aggregation to apply to columns that have not been explicitly set. If the query writer does not choose an alternative, the default aggregation is |
setFormat("ColName","Operation","Format")
|
Sets the format for the designated column and operation. If "Operation" is set to an asterisk (" |
|
Instructs Deephaven to expand ( |
|
Instructs Deephaven to expand ( |
|
Passes the result of the specified operations to the table.
|
Available Aggregation Operations
The following aggregation operations may be used:
Aggregation |
Description |
---|---|
|
Display the first value of the column |
|
Display the last value of the column |
|
Display the minimum of the column |
|
Display the maximum of the column |
|
Display the total sum of the column |
|
Display the total average of the column |
|
Display the standard deviation of the column |
|
Display the variance of the column |
|
Display the number of non-null items present |
|
Do not display any aggregation information for this column |
Available Formatting Options
Only Date and Decimal are supported as arguments within the in TotalsTableBuilder
methods. The expressions are the same those used to format columns in a table.
See: Formatting Tables.
Last Updated: 16 February 2021 18:07 -04:00 UTC Deephaven v.1.20200928 (See other versions)
Deephaven Documentation Copyright 2016-2020 Deephaven Data Labs, LLC All Rights Reserved