File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ class Top:
71
71
"""
72
72
73
73
limit : Union [int , None ] = 1
74
- order_by : Union [str , List [str ]] = "KEY"
74
+ order_by : Union [str , List [str ]] = [ "KEY" ]
75
75
offset : int = 0
76
76
77
77
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:
17
17
| [ aggr] ( #aggr ) | A.aggr(B, ...) | Same as projection with computations based on matching information in B |
18
18
| [ union] ( #union ) | A + B | All unique entities from both A and B |
19
19
| [ universal set] ( #universal-set ) \* | dj.U() | All unique entities from both A and B |
20
+ | [ top] ( #top ) \* | dj.Top() | The top rows of A
20
21
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
22
23
same context.
23
24
24
25
??? note "Notes on relational algebra"
@@ -218,6 +219,20 @@ The examples below will use the table definitions in [table tiers](../reproduce/
218
219
219
220
<!-- ## Join appears here in the general docs -->
220
221
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
+
221
236
## Restriction
222
237
223
238
` & ` and ` - ` operators permit restriction.
You can’t perform that action at this time.
0 commit comments