Repository navigation
Add PGN (portable game notation) input format - #93067
chhetripradeep wants to merge 15 commits into
Conversation
|
Workflow [PR], commit [3237a44] Summary: ❌
AI ReviewSummaryThis PR adds a new Findings
Final VerdictNeeds changes before merge: the parser's current handling of tagless games is still inconsistent and depends on where the game appears in the file. LLVM Coverage ReportMeasured on commit 3237a44.
Changed lines: Changed C/C++ lines covered: 349/370 (94.32%) · Uncovered code |
ecfabd2 to
926bdfa
Compare
nihalzp
left a comment
There was a problem hiding this comment.
I was trying out simple_games.pgn and printed all the rows and got:
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┓
┃ event ┃ site ┃ date ┃ round ┃ white ┃ black ┃ result ┃ white_elo ┃ black_elo ┃ moves ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━┩
1. │ Test Event │ Test Site │ 2024.01.01 │ 1 │ Player A │ Player B │ 1-0 │ 2500 │ 2400 │ e5 Nc6 │
├──────────────┼─────────────┼────────────┼───────┼──────────┼──────────┼────────┼───────────┼───────────┼──────────┤
2. │ Test Event 2 │ Test Site 2 │ 2024.01.02 │ 2 │ Player C │ Player D │ 0-1 │ 2600 │ 2550 │ d5 dxc4 │
└──────────────┴─────────────┴────────────┴───────┴──────────┴──────────┴────────┴───────────┴───────────┴──────────┘
It only shows black's moves. Also, we do not have any move related queries in tests, let's add them in tests.
If the move contains castling notation move: (0-0 or 0-0-0), we do not seem to able to parse it. For example this,
1. e4 e5 2. Nf3 Nc6 3. 0-0 0-0 4. d4 d6 5. 0-0-0 *If the Result is missing, I think we can try parse the result from moves for a PGN like this:
[Event "Event"]
[Site "Site"]
[Date "2026.01.01"]
[Round "1"]
[White "Alice"]
[Black "Bob"]
1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 1-0
If I try to load this PGN:
[Event "x"]
[WhiteElo "123"]
[BlackElo "456"]
*
using:
SELECT *
FROM file('path_to_pgn', 'PGN',
'event String, white_elo String');it crashes.
I think there are some issues with file segmentation engine. I tried running simple_games.pgn's segmentation path with:
SELECT * FROM file('simple_games.pgn', 'PGN') SETTINGS max_parsing_threads=4, input_format_parallel_parsing=1, min_chunk_bytes_for_parallel_parsing=1, max_block_size=1 FORMAT PRETTY;and it gave me 18 rows.
But with input_format_parallel_parsing=0 it worked fine.
We can either fix it or not support file segmentation engine for PGN for now. We can add support for that later if that's easier.
|
Additionally, let's add a test for each of the issues in the review. It will make sure the same bugs do not reappear in the future if someone else changes the code. |
|
Dear @nihalzp, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
1c3605d to
1e03f40
Compare
9283ee5 to
3d7addb
Compare
3d7addb to
dc8f274
Compare
dc8f274 to
6abf57a
Compare
|
Dear @nihalzp, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Dear @nihalzp, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
🕵 Picked this up: merged
@nihalzp all of your review threads are addressed and resolved; every point of your review summary now has a test: exact moves of both colours and the compact All three tests pass against a local build. |
Build profile diff (arm_release)Comparing commit See the job log for details. |
…rmat A file starting with a byte order mark produced a phantom first row, because `PGNRowInputFormat` never skipped it: it now overrides `readPrefix` and calls `skipBOMIfExists`. The escape mechanism of the standard - a line whose first column is `%` is ignored - was not implemented, so such lines produced a bogus extra row or leaked into `moves`; they are now skipped both between the tags and inside the move text. Regression test `05029_pgn_format_bom_and_escape_lines` covers a BOM-prefixed file and escape lines in all positions. Co-Authored-By: Claude Fable 5 <[email protected]>
… refills `isEscapeLine` peeked at the byte before the current position, which is not in the buffer when a `%` escape line starts exactly at a `ReadBuffer` refill boundary, so such a line was parsed as data. The parser now tracks the previously consumed byte explicitly, and the state survives refills. Regression test `05045_pgn_format_escape_line_at_buffer_boundary` reads a file with escape lines through 1-, 3- and 16-byte read buffers, which forces every `%` onto a refill boundary. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 The |
|
Investigated. Two corrections first, then the answer. Not the PGN format: confirmed. Not #112203. The artifact holds 13 hung queries. Across all 13 processlist rows, What actually hung: one holder plus 12 waiters on a single Holder, Row 1: Rows 2 to 13 are The ask. The holder's frame is already covered by your own #112930: it replaces that exact line ( The other half is unowned: #112930 touches Why it surfaced now: #114502 (merged 2026-08-24) added |
|
The separate PR is up: #116774 It stops |
… marker The `result` of a game is carried both by the `Result` tag and by the game termination marker of the move text, but neither relationship was validated: any tag value was accepted verbatim, and a termination marker was ignored whenever a tag had already filled `result`, so both `[Result "won"]` and `[Result "1-0"] ... 0-1` were ingested silently. Now a `Result` tag outside `1-0`, `0-1`, `1/2-1/2`, `*` and a termination marker that contradicts the game result both raise `INCORRECT_DATA`. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 The |
|
A fix for this one is already in progress: #114058 Route pinned from that run's own artifacts (report):
On master, #114058 keeps that One caveat: |
|
🕵 The sole red on Merged |
…esult Two gaps in the `PGN` parser found by the review of the previous commit: - `skipVariation` did not honour the escape mechanism of the standard, so a `%` line inside a parenthesized variation was read as ordinary text. A `)` written on such a line closed the variation early and leaked the rest of the variation into the mainline `moves`. `isEscapeLine` is now checked there as well, exactly like in `readMoves` and `skipWhitespaceAndComments`. - A game whose movetext has moves but no game termination marker, and which has no `Result` tag, was accepted with an empty `result`. That contradicts the documented contract that `result` is one of `1-0`, `0-1`, `1/2-1/2` or `*`, so it now raises `INCORRECT_DATA`. The documentation sentence about the result is extended accordingly, in both the `setDocumentation` body and `docs/reference/formats/PGN.mdx`. New test `05137_pgn_format_variation_escape_line_and_missing_result` covers an escape line containing `)` inside a variation (also read one byte at a time so that the line starts at a buffer refill boundary), a game without any result, and a `Result` tag without a termination marker.
`readMoves` kept scanning ordinary tokens after it had accepted a game termination marker, so a malformed game such as `1.e4 e5 1-0 2.Nf3 Nc6` was stored with `moves = 'e4 e5 Nf3 Nc6'`. The marker now ends the movetext: any later ordinary token (including a repeated marker) raises `INCORRECT_DATA`, while comments, variations and escape lines after the marker are still skipped. Documented in both the `setDocumentation` body and `docs/reference/formats/PGN.mdx`; regression test `05225_pgn_format_tokens_after_termination_marker`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
| bool terminated = false; | ||
|
|
||
| /// Read move text until end of game (next [ or EOF or blank line followed by [) | ||
| while (!in.eof() && *in.position() != '[') |
There was a problem hiding this comment.
parseGameImpl already treats the tag-pair section as optional, so a tagless game is accepted when it appears first in the file. But readMoves still uses [ as the only row boundary, so after the first game's result this loop keeps scanning until it sees another tag header.
That makes support for missing tags position-dependent. For example, this input parses the first game and then throws on the second one:
1. e4 e5 1-0
1. d4 d5 0-1
The second game's opening 1. reaches the terminated branch below and becomes Invalid PGN: unexpected token ... after the game termination marker. Please either reject tagless games uniformly before readMoves, or recognize a blank-line-separated next game after a termination marker and add a regression for consecutive tagless games.
|
I've asked in Slack, but no one was interested. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add PGN (portable game notation) input format for reading chess datasets
Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/93067]