Reverse Table Order
Overview
Users may want to reverse the order of the rows in an entire table, where the last row becomes the first row and vice versa. Deephaven offer two ways to accomplish this: by using the reverse
method in a query, or through the Deephaven console. The following details how to use Reverse Table in the Deephaven Console. See: Table Operations > Reversing Table Order for more about using query methods.
Reverse Table
To reverse a table while working in the Deephaven console, right-click on any column header in the table and select Reverse Table from the drop-down menu, as shown below.
The following three options are presented:
- Reverse Before Sorting: Selecting this option reverses the table order immediately. This reversed table can then be manually sorted as many times as needed.
- Reverse After Sorting: Selecting this option reverses the order of rows after manual sorting methods are applied. When more than one manual sorting operation is applied to the table, all sort operations are sequentially applied to the unaltered table before returning the rows in reverse order.
- No Reversal: Selecting this option restores the order of the original table. If manual sorting has been applied to the table before this option is chosen, those sorting results remain visible in the table.
Examples

The following examples show how table data behaves for each of the settings above, starting with a small table named t1
, which contains data for Syms
and Bid Size
.
t1
Date |
Sym |
BidSize |
2018-05-01 |
AAPL |
36 |
2018-05-01 |
GOOG |
10 |
2018-05-02 |
AAPL |
20 |
2018-05-02 |
GOOG |
20 |
2018-05-03 |
AAPL |
20 |
2018-05-03 |
GOOG |
15 |
Table t2
(below) shows the original table reversed without any sorting operations applied. Note: The column header background in Deephaven will turn green to indicate that Reverse Table has been applied. This is the equivalent to using the following query: t2=t1.reverse()
t2
Date |
Sym |
BidSize |
2018-05-03 |
GOOG |
15 |
2018-05-03 |
AAPL |
20 |
2018-05-02 |
GOOG |
20 |
2018-05-02 |
AAPL |
20 |
2018-05-01 |
GOOG |
10 |
2018-05-01 |
AAPL |
36 |
If you choose the Reverse Before Sorting option, your sorting operation(s) will always be applied to the reversed table. Table t3 shows the original table reversed then sorted by Sym. This is the equivalent to using the following query: t3=t1.reverse().sort("Sym")
t3
Date |
Sym |
BidSize |
2018-05-03 |
AAPL |
20 |
2018-05-02 |
AAPL |
20 |
2018-05-01 |
AAPL |
36 |
2018-05-03 |
GOOG |
15 |
2018-05-02 |
GOOG |
20 |
2018-05-01 |
GOOG |
10 |
However, if you choose the Reverse After Sorting option, your sorting operation(s) will always be applied to the original table. Table t4 shows the original table sorted by Sym, which is the equivalent to using the following query: t4=t1.sort("Sym")
t4
Date |
Sym |
BidSize |
2018-05-01 |
AAPL |
36 |
2018-05-02 |
AAPL |
20 |
2018-05-03 |
AAPL |
20 |
2018-05-01 |
GOOG |
10 |
2018-05-02 |
GOOG |
20 |
2018-05-03 |
GOOG |
15 |
Table t5
then shows the result after the table is sorted and then reversed, which is the equivalent to using the following query: t5=t1.sort("Sym").reverse()
. Again, the column header background in Deephaven turns green to indicate that Reverse Table has been applied.
t5
Date |
Sym |
BidSize |
2018-05-03 |
GOOG |
15 |
2018-05-02 |
GOOG |
20 |
2018-05-01 |
GOOG |
10 |
2018-05-03 |
AAPL |
20 |
2018-05-02 |
AAPL |
20 |
2018-05-01 |
AAPL |
36 |
Clicking a column header can only be used to sort one column at a time. To sort a table using multiple columns, right-click in the header of the additional column you want to sort, and select Add Sort By <ColumnName>. (See: Add Sort By section above for more information.) When multiple sorts are applied, Deephaven applies the sorts in sequential order to the original table, and then reverses the cumulative result at the end.
Table t6
(below) shows the original table sorted by both Sym
and then BidSize
, and table t7 shows the table that results after selecting Reverse After Sorting. This is equivalent to using the following query: t7.sort("Sym").sort("BidSize").reverse(
)
|
|
Last Updated: 24 February 2020 17:09 -05:00 UTC Deephaven v.1.20200121 (See other versions)
Deephaven Documentation Copyright 2016-2020 Deephaven Data Labs, LLC All Rights Reserved