Computes the sum of absolute values of each column within each group.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, computes the absolute sum across all rows
a new table with the absolute sums
Applies a single aggregation to all columns.
the aggregation to apply
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by
a new table with these aggregations applied to the data in this table
Aggregates the contents of this table into a new table. Each aggregation adds columns computed over each group,
and can be made with a dh.agg.Aggregation factory or written as an object literal:
const summary = await table.aggBy({
aggregations: [
dh.agg.Aggregation.AggWAvg("W", ["WAvgX = X"]),
dh.agg.Aggregation.AggAvg(["AvgX = X"]),
{ type: "Count", col: "N" },
],
groupByColumns: ["Key"],
});
the aggregations, and optionally the columns to group by and the groups to start with
a table with one row per group, and a column for each aggregation
Performs an as-of join of this table with the right table: each row takes the right table's row with the closest as-of value at or before its own.
the table to join with
the columns to match on. All but the last are exact matches ("LeftCol=RightCol" or
a name in both tables). The last is the as-of match: "LeftCol>=RightCol",
"LeftCol>RightCol", or a name in both tables, which means >=.
OptionalcolumnsToAdd: readonly (string | Column)[]
the columns to add from the right table. If omitted, adds all non-match columns
a new table with the joined columns
Computes the arithmetic mean of each column within each group.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, computes the average across all rows
a new table with the averages
Counts the number of rows in each group, storing the result in a new column.
the name of the new column to hold the row counts
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, counts all rows into a single result
a new table with a count column and optional group-by columns
Creates a table with fewer rows than this one that draws the same as a line plot at the given width, for plotting large time series. Each pixel of the width keeps the rows that set its first, last, minimum and maximum values. If the table has fewer rows than that, the result is the table unchanged.
the columns to plot, the plot width, and optionally the visible X range
the downsampled table
Creates a new table without the specified columns.
the columns to drop. Should not be empty.
a new table without those columns
Performs an exact join of this table with the right table. Each row in this table must have exactly one matching row in the right table based on the match columns. If a row has no match, the operation fails.
the table to join with
the columns to match on, in "LeftCol=RightCol" format
OptionalcolumnsToAdd: readonly (string | Column)[]
the columns to add from the right table. If omitted, adds all non-match columns
a new table with the joined columns
Returns the first row of each group.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, returns the first row of the table
a new table with the first row from each group
Creates a version of this table with a flat rowset.
a new table with a flat rowset
Groups the table by the specified columns, accumulating the other columns into arrays. If no columns are provided, the resulting table has a single row.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group
a table with one row per group
Creates a table with the given number of rows from the beginning of this table.
the number of rows to keep from the beginning of this table
a new table with at most that many rows
Performs a cross join (Cartesian product) of this table with the right table, filtered to matching rows. Each row in this table is paired with every matching row in the right table.
the table to join with
the columns to match on, in "LeftCol=RightCol" format
OptionalcolumnsToAdd: readonly (string | Column)[]
the columns to add from the right table. If omitted, adds all non-match columns
OptionalreserveBits: number
the number of bits of key-space to initially reserve per group. The default is 10
a new table with the joined columns
Returns the last row of each group.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, returns the last row of the table
a new table with the last row from each group
Returns the maximum value of each column within each group.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, computes the maximum across all rows
a new table with the maximum values
Computes the median of each column within each group. When the group size is even, averages the two middle values
of int, long, float and double columns, and uses the larger value for other
types.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, computes the median across all rows
a new table with the medians
Returns the minimum value of each column within each group.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, computes the minimum across all rows
a new table with the minimum values
Perform a natural-join with the rightTable.
the right side table on the join
the match pair conditions
OptionalcolumnsToAdd: readonly (string | Column)[]
the columns from the right table to add to the result. If omitted, adds all non-match columns
OptionaljoinType: NaturalJoinType
the type of join to perform
the natural-joined table
Performs a reverse as-of join of this table with the right table: each row takes the right table's row with the closest as-of value at or after its own.
the table to join with
the columns to match on. All but the last are exact matches ("LeftCol=RightCol" or
a name in both tables). The last is the as-of match: "LeftCol<=RightCol",
"LeftCol<RightCol", or a name in both tables, which means <=.
OptionalcolumnsToAdd: readonly (string | Column)[]
the columns to add from the right table. If omitted, adds all non-match columns
a new table with the joined columns
Joins each row of this table to the rows of rightTable that match it exactly on exactMatches and
fall in its range, and aggregates those right rows into columns of the result. The result has one row per row of
this table.
At this time, the server supports only static (not refreshing) tables and Group aggregations. This operation remains under active development.
the table to join to
columns that must be equal in both tables, as "Col" or "LeftCol=RightCol"
the columns and rules of the range match
the aggregations to apply to each row's matching right rows
a table with one row per row of this table, and a column for each aggregation
Creates a table with all the rows of this table in reverse order.
a new table with the rows in reverse order
Creates a new table with only the specified columns. Computes all formulas eagerly and stores their values in memory.
the columns or expressions to have in the new table
a new table with only those columns.
Creates a new table with only the distinct values of the specified columns. If no columns are specified, uses all columns.
OptionalcolumnNames: readonly (string | Column)[]
the column names to distinct on. If empty/null, uses all columns
a new table with only the distinct values of the specified columns
Extracts a subset of a table by row position.
If both firstPositionInclusive and lastPositionExclusive are positive, both count from the
beginning of the table. The firstPositionInclusive is inclusive, and the lastPositionExclusive is
exclusive. The head(N) call is equivalent to slice(0, N). The
firstPositionInclusive must be less than or equal to the lastPositionExclusive.
If firstPositionInclusive is positive and lastPositionExclusive is negative, the
firstPositionInclusive counts from the beginning of the table, inclusively. The
lastPositionExclusive counts from the end of the table. For example, slice(1, -1) includes all
rows but the first and last. If the lastPositionExclusive would be before the
firstPositionInclusive, the result is an empty table.
If firstPositionInclusive is negative and lastPositionExclusive is zero, the
firstPositionInclusive counts from the end of the table, and the slice ends at the end of the table.
Calling slice(-N, 0) is equivalent to tail(N).
If the firstPositionInclusive is negative and the lastPositionExclusive is negative, both count
from the end of the table. For example, slice(-2, -1) returns the second to last row of the table.
If firstPositionInclusive is negative and lastPositionExclusive is positive, the
firstPositionInclusive counts from the end of the table, inclusively. The lastPositionExclusive
counts from the beginning of the table, exclusively. For example, slice(-3, 5) returns all rows starting
from the third-last row to the fifth row of the table. If there are no rows between these positions, the result
is an empty table.
the first position to include in the result
the position after the last one to include in the result
a new table with the subset of rows from the original table
A server-side snapshot of the entire table as of the time the request is processed. The result does not update. This is what Table.freeze() does. The name here follows the other Deephaven clients.
a new, non-ticking table with the same contents as this table at that moment
Creates a table that captures a snapshot of this table whenever the trigger table updates.
the table to use as a trigger for when to take a snapshot of this table
Optionaloptions: SnapshotWhenOptions
options controlling when and how the result table updates. If omitted, every option takes its default.
the snapshot table
Sorts the table by the given columns.
the sorts to apply, in order of precedence
a sorted table
Computes the sample standard deviation of each column within each group, using Bessel's correction.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, computes the standard deviation across all rows
a new table with the standard deviations
Computes the sum of each column within each group.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, computes the sum across all rows
a new table with the sums
Creates a table with the given number of rows from the end of this table.
the number of rows to keep from the end of this table
a new table with at most that many rows
Ungroups a table by expanding columns of arrays or vectors into columns of singular values, creating one row in the output table for each value in the columns being ungrouped. Each output row repeats the values of the other columns from its input row.
Optionaloptions: UngroupOptions
options to specify the behavior of the ungroup operation
an ungrouped table
Creates a new table, appending or replacing the specified columns. Computes all formulas eagerly and stores their values in memory.
the columns or expressions to have in the new table
a new table with those columns appended
Adds or replaces columns whose value in each row depends on the rows around it in its group: cumulative operations, rolling windows, exponential moving statistics, fills and deltas. Without UpdateByOptions.groupByColumns, the whole table is one group. For example, a weighted average over each row and the two before it in its group:
const rolling = await table.updateBy({
operations: [{
spec: {
type: "UpdateByRollingWAvg",
weightColumn: "W",
reverseWindowScale: { type: "ticks", ticks: 3 },
},
matchPairs: ["RollWAvgX = X"],
}],
groupByColumns: ["Key"],
});
the operations to apply, and optionally the columns to group by and control settings
a table with the same rows as this table, and each operation's output columns added or replacing the columns of the same name
Creates a new table, appending or replacing the specified columns. Computes each formula every time a value is read, and stores nothing.
the columns or expressions to have in the new table
a new table with those columns appended
Computes the sample variance of each column within each group, using Bessel's correction.
OptionalgroupByColumns: readonly (string | Column)[]
columns to group by. If omitted, computes the variance across all rows
a new table with the variances
Creates a new table with only the specified columns. Computes each formula every time a value is read, and stores nothing.
the columns or expressions to have in the new table
a new table with only those columns.
Computes the weighted average of each column within each group: the sum of each value multiplied by its weight,
divided by the sum of the weights. It averages every column other than the weight and the group-by columns, so
each must be numeric. To choose and rename columns, or to combine with other aggregations, use
TableOperations.aggBy() with dh.agg.Aggregation.AggWAvg.
const byKey = await table.wavgBy("W", ["Key"]);
a new table with the weighted averages
Creates a table that filters the contents of this table based on the provided conditions.
the conditions to filter on. FilterValue.ofColumn() names a column without a resolved table
a filtered table
Filters the contents of this table based on the set of values that match the provided right table.
When the right table ticks, all the rows in this table are re-evaluated.
the table with the filter criteria
the column matches between the two tables
a new filtered table
Filters the contents of this table based on the set of values that do not match the provided right table.
When the right table ticks, all the rows in this table are re-evaluated.
the table with the filter criteria
the column matches between the two tables
a new filtered table
Computes the weighted sum of each column within each group: the sum of each value multiplied by its weight.
a new table with the weighted sums
Operations on a table that need none of its data or metadata, so they can be chained without waiting on a promise.
Every instance represents one server-side table, with its definition fixed when created. Compared with a Table, it is "immutable", and has no methods to change its columns, filters, sort, etc. A ticking table's rows still change as the server's update graph adds, removes, and modifies them. Each operation returns a new pending table, so the caller decides the order of operations by how they chain them.
Each table holds server resources until it is closed, by whoever owns it:
- Awaiting a PendingTable gives the table it produces, and PendingTable.resolve() gives
it as a ResolvedTable. Use one or the other, not both; repeating the same one gives the same instance, as
awaiting a promise twice does. A pending table has no owner: whoever awaits or resolves it owns that instance, and is
responsible for closing it.
- A ResolvedTable is already the table: it cannot be awaited, since awaiting a thenable would also await
what it resolves to, and needs no resolving.
- Code that receives a table and its caller agree on whether that code may close it. Code given a
To hand one table to several owners, resolve it once, give each owner a copy, and close the original:TableOperationscan only chain on it, so it never retains a table its caller cannot reach to close. Code that reads a table should take a ResolvedTable, which the sender resolves before handing it over, and code that keeps one it was lent can call ResolvedTable.copy() for a new instance with its own lifetime.No method throws: as from an async function, every failure rejects the pending table it returns. That includes invalid arguments, an operand from another connection and a closed table, which reject with the error and send nothing to the server, as well as a failure on the server or of a table the operation uses, if it was canceled, failed, or used too late. PendingTable describes how long a pending table may be used.
async function process(table: dh.TableOperations) { const result = await table .where([dh.FilterValue.ofColumn("A").greaterThan(dh.FilterValue.ofNumber(5))]) .sort([{column: "B", direction: "DESC"}]) .head(10); // From here on, `table` may already be closed. This function did not retain it, and cannot tell whether the // caller did. try { const a = result.findColumn("A"); const data = await result.createSnapshot({ rows: {first: 0, last: 9}, columns: [a, "B"] }); return data.getData(0, a); } finally { result.close(); } }The
processexample only chains on the table it is given, so it works whether the caller passes a pending or a resolved table, and closes only what its own chain produced. To keep a table for later, take aResolvedTableand copy it: below, SwapFilters owns its copy and each filtered table it makes, and closes each when replaced or when it is closed.class SwapFilters { private readonly table: dh.ResolvedTable; private filteredTable: Promise<dh.ResolvedTable> | null = null; constructor(table: dh.ResolvedTable) { // The caller keeps its own table; this class owns the copy this.table = table.copy(); } changeFilters(filters: ReadonlyArray<dh.FilterCondition>) { if (this.filteredTable) { // A table that failed has nothing to close this.filteredTable.then(t => t.close(), () => {}); } this.filteredTable = Promise.resolve(this.table.where(filters)); } async loadData(): Promise<dh.TableData> { if (!this.filteredTable) { throw new Error("no filters set"); } const t = await this.filteredTable; return t.createSnapshot({ rows: {first:0, last:1_000_000}, columns: t.columns }) } close() { this.table.close(); if (this.filteredTable) { this.filteredTable.then(t => t.close(), () => {}); } } }See