File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ class Top:
7171 """
7272
7373 limit : Union [int , None ] = 1
74- order_by : Union [str , List [str ]] = "KEY"
74+ order_by : Union [str , List [str ]] = [ "KEY" ]
7575 offset : int = 0
7676
7777 def __post_init__ (self ):
Original file line number Diff line number Diff line change @@ -17,8 +17,9 @@ DataJoint implements a complete algebra of operators on tables:
1717| [ aggr] ( #aggr ) | A.aggr(B, ...) | Same as projection with computations based on matching information in B |
1818| [ union] ( #union ) | A + B | All unique entities from both A and B |
1919| [ universal set] ( #universal-set ) \* | dj.U() | All unique entities from both A and B |
20+ | [ top] ( #top ) \* | dj.Top() | The top rows of A
2021
21- \* While not technically a query operator , it is useful to discuss Universal Set in the
22+ \* While not technically query operators , it is useful to discuss Universal Set and Top in the
2223same context.
2324
2425??? note "Notes on relational algebra"
@@ -218,6 +219,20 @@ The examples below will use the table definitions in [table tiers](../reproduce/
218219
219220<!-- ## Join appears here in the general docs -->
220221
222+ ## Top
223+
224+ Similar to the univeral set operator, the top operator uses ` dj.top ` notation. It is used to
225+ restrict a query by the given ` limit ` , ` order_by ` , and ` offset ` parameters:
226+
227+ ``` python
228+ Session & dj.top(limit = 10 , order_by = ' session_date' )
229+ ```
230+
231+ The result of this expression returns the first 10 rows of ` Session ` and sorts them
232+ by their ` session_date ` in ascending order. If the ` order_by ` argument was instead: ` session_date DESC ` , then it would be sorted in descending order.
233+
234+ The default values for ` dj.top ` parameters are ` limit=1 ` , ` order_by=["KEY"] ` , and ` offset=0 ` .
235+
221236## Restriction
222237
223238` & ` and ` - ` operators permit restriction.
You can’t perform that action at this time.
0 commit comments