@@ -4,7 +4,7 @@ description: "End-to-end tutorial parsing PGN chess data to find tie-break games
44layout : default
55nav_order : 2
66parent : Tutorials
7- superdb_version : " 0.1 .0"
7+ superdb_version : " 0.2 .0"
88last_updated : " 2026-02-15"
99---
1010
@@ -34,10 +34,9 @@ super -i line -s -c "
3434 --
3535 -- pair up each player in each game
3636 --
37- -- future super versions will support window functions, but we can make do with this
38- --
39- | put row_num:=count(this)
40- | put game_id:=((row_num - 1) / 2)::int64
37+ | count
38+ | put game_id:=((count - 1) / 2)::int64
39+ | values {...that, game_id}
4140 | aggregate
4241 last_name_white:=max(last_name_white),
4342 last_name_black:=max(last_name_black)
@@ -66,12 +65,12 @@ super -i line -s -c "
6665```
6766
6867``` mdtest-output
69- {player:"Abdusattorov",opponent:"Wei",count:3::uint64 }
70- {player:"Giri",opponent:"Gukesh",count:4::uint64 }
71- {player:"Gukesh",opponent:"Giri",count:4::uint64 }
72- {player:"Gukesh",opponent:"Wei",count:3::uint64 }
73- {player:"Wei",opponent:"Abdusattorov",count:3::uint64 }
74- {player:"Wei",opponent:"Gukesh",count:3::uint64 }
68+ {player:"Abdusattorov",opponent:"Wei",count:3}
69+ {player:"Giri",opponent:"Gukesh",count:4}
70+ {player:"Gukesh",opponent:"Giri",count:4}
71+ {player:"Gukesh",opponent:"Wei",count:3}
72+ {player:"Wei",opponent:"Abdusattorov",count:3}
73+ {player:"Wei",opponent:"Gukesh",count:3}
7574```
7675
7776## Walkthrough
@@ -96,9 +95,11 @@ which we filter with `where not is_error(this)`.
9695PGN files list White and Black players on consecutive lines for each game. We
9796need to combine them into single records.
9897
99- The trick is using expression-context ` count(this) ` which produces a running
100- count (1, 2, 3, ...). Integer division ` (row_num - 1) / 2 ` maps pairs of rows to
101- the same game_id: rows 1,2 get game_id 0; rows 3,4 get game_id 1, etc.
98+ The ` count ` operator adds a sequential ` count ` field to each record (1, 2, 3, ...).
99+ Integer division ` (count - 1) / 2 ` maps pairs of rows to the same game_id:
100+ rows 1,2 get game_id 0; rows 3,4 get game_id 1, etc. The ` count ` operator wraps
101+ the input in a ` that ` field, so ` {...that, game_id} ` spreads the original fields
102+ back out alongside the game_id.
102103
103104Then ` aggregate ... by game_id ` with ` max() ` picks up the non-null value from
104105each field within each pair.
@@ -213,8 +214,8 @@ super -s -c "
213214```
214215
215216``` mdtest-output
216- {player:"Gukesh",opponent:"Wei",count:2::uint64 }
217- {player:"Wei",opponent:"Gukesh",count:2::uint64 }
217+ {player:"Gukesh",opponent:"Wei",count:2}
218+ {player:"Wei",opponent:"Gukesh",count:2}
218219```
219220
220221## as of versions
@@ -223,5 +224,5 @@ super -s -c "
223224super --version
224225```
225226``` mdtest-output
226- Version: v0.1 .0
227+ Version: v0.2 .0
227228```
0 commit comments