Repository navigation
fix(eval): replace fragile str.replace chain with robust regex in fix_table_name - #133
MilindLate wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Hi @MilindLate, thank you for your contribution!
One thing is still worth adding: the lookahead (?=\s|$|,|\)) no longer matches a placeholder followed directly by ; or a keyword, which the old str.replace code did handle:
fix_table_name('SELECT a FROM "Table";', "t") # -> unchanged: 'SELECT a FROM "Table";'
fix_table_name('SELECT a FROM "Table"WHERE b=1', "t") # -> unchangedIn the evaluation pipeline the extractor strips the trailing ; first, so we saw no impact on the leaderboard outputs, but fix_table_name is a public helper and should not regress. For the quoted forms no lookahead is needed at all (the closing quote already ends the name); only the bare table form needs a boundary. For example:
r"""(?i)\bFROM\s+(?:"table"|'table'|`table`|table\b)"""Please add tests for the two cases above (and keep the Table1 / "Tables" cases unchanged).
If you find LLMSQL useful, we'd be grateful if you could give the project a ⭐ on GitHub, it really helps us!
…_table_name Fixes LLMSQL#125 Use regex pattern `\bFROM\s+(?:"table"|'table'|`table`|table\b)` to correctly replace quoted and bare table placeholders without regressing on trailing semicolons or unspaced following keywords, while preserving prefixes like Table1 and "Tables". Add comprehensive test coverage in tests/utils/test_evaluation_utils.py.
597ec74 to
dd07713
Compare
|
Hi @DzmitryPihulski, thank you for the feedback and helpful suggestion! I've updated the regex to I've also rebased onto latest
(And starred the repo! ⭐) |
Fixes #125
Problem
fix_table_name()inllmsql/utils/evaluation_utils.pyused three exactstr.replacecalls to swap theTableplaceholder:FROM 'Table'→ handledFROM "Table"→ handledFROM Table→ handledAll other common spellings silently failed, causing correct model queries to be counted as SQL errors:
from "Table"(lowercase FROM keyword)FROM "table"(lowercase placeholder)FROMTable`` (backtick quotes)FROM "Table"(extra whitespace)FROM\n"Table"(newline between FROM and table)Fix
Replaced the three
str.replacecalls with a single case-insensitive regex:This handles all quoting styles and any whitespace (spaces or newlines) between
FROMand the placeholder.Tests Added
Added 6 new test cases in
tests/utils/test_evaluation_utils.pycovering all the failing variants from the issue, plus a safety check that a value/column containing the wordTableis not altered.