on f7fc888 help sign in
project-m36/docs/dataframes.markdown
53 lines 3.0 kB history raw
1# Project:M36 DataFrames
3Users of typical relational algebra engines have come to expect sorting and limiting of query results despite the fact that relations do not support ordering. To that end, Project:M36 supports converting relations to "data frames" to support sorting on attributes and limiting the maximum tuple count in the result set.
5The equivalent feature in SQL is invoked by the `ORDER BY`, `LIMIT`, and `OFFSET` clauses.
7## Usage
9From within the `tutd` console, converting a relation to be sorted as a data frame is invoked using the `:showdataframe` command.
11```
12:showdataframe <relational expression> orderby {<attribute {ascending,descending}>} {offset <num>} {limit <num>}
13```
15The default sort order is `ascending`.
17## Examples
19```
20TutorialD (master/main): :showdataframe s orderby {status}
21┌──┬───────────┬─────────┬────────────┬────────────────┐
22│DF│city::Text↕│s#::Text↕│sname::Text↕│status::Integer⬆│
23├──┼───────────┼─────────┼────────────┼────────────────┤
24│1 │"Paris" │"S2" │"Jones" │10 │
25│2 │"London" │"S1" │"Smith" │20 │
26│3 │"London" │"S4" │"Clark" │20 │
27│4 │"Athens" │"S5" │"Adams" │30 │
28│5 │"Paris" │"S3" │"Blake" │30 │
29└──┴───────────┴─────────┴────────────┴────────────────┘
30TutorialD (master/main): :showdataframe s{status} orderby {status}
31┌──┬────────────────┐
32│DF│status::Integer⬆│
33├──┼────────────────┤
34│1 │10 │
35│2 │20 │
36│3 │30 │
37└──┴────────────────┘
38TutorialD (master/main): :showdataframe s{status} orderby {status descending} limit 1
39┌──┬────────────────┐
40│DF│status::Integer⬇│
41├──┼────────────────┤
42│1 │30 │
43└──┴────────────────┘
44TutorialD (master/main): :showdataframe s{status} orderby {status descending} offset 1 limit 3
45┌──┬────────────────┐
46│DF│status::Integer⬇│
47├──┼────────────────┤
48│1 │20 │
49│2 │10 │
50└──┴────────────────┘
52```
53The arrow in the attributes indicates the sort order while the DF column indicates the row number based on the sort order. Column ordering can also be arbitrary.