fix(sql): optimize error msg when invalid column references in JOIN queries#6332
fix(sql): optimize error msg when invalid column references in JOIN queries#6332bluestreak01 merged 3 commits intomasterfrom
Conversation
WalkthroughAdds validation during top-down column processing in query generation to check if columns exist in table metadata before accessing them, preventing index-out-of-bounds exceptions. Includes a corresponding test validating error handling when joining with non-existent columns. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested labels
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.39.6)core/src/main/java/io/questdb/griffin/SqlCodeGenerator.javaThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
core/src/main/java/io/questdb/griffin/SqlCodeGenerator.java (1)
5913-5924: Minor: cache column metadata to avoid repeated lookups.Optional micro‑refactor: store metadata.getColumnMetadata(columnIndex) once and reuse for flags/capacity reads.
- queryMeta.add(new TableColumnMetadata( - Chars.toString(column.getName()), - type, - metadata.isColumnIndexed(columnIndex), - metadata.getIndexValueBlockCapacity(columnIndex), - metadata.isSymbolTableStatic(columnIndex), - metadata.getMetadata(columnIndex), - -1, - false, - 0, - metadata.getColumnMetadata(columnIndex).isSymbolCacheFlag(), - metadata.getColumnMetadata(columnIndex).getSymbolCapacity() - )); + final TableColumnMetadata baseMeta = metadata.getColumnMetadata(columnIndex); + queryMeta.add(new TableColumnMetadata( + Chars.toString(column.getName()), + type, + baseMeta.isSymbolIndexFlag(), + baseMeta.getIndexValueBlockCapacity(), + baseMeta.isSymbolTableStatic(), + metadata.getMetadata(columnIndex), + -1, + false, + 0, + baseMeta.isSymbolCacheFlag(), + baseMeta.getSymbolCapacity() + ));core/src/test/java/io/questdb/test/griffin/SqlCodeGeneratorTest.java (1)
2514-2526: Solid regression test; tiny nits for robustness and naming
Approves: the test cleanly reproduces the join+agg invalid-column case and verifies the improved error message under leak checking. Good coverage.
Optional: the hard-coded position 136 can be fragile if the SQL is reformatted. Consider computing it from the token location to keep the test stable:
- assertExceptionNoLeakCheck( - "SELECT o.*, avg(p.bid) avg_big, avg(p.ask) avg_ask FROM orders o LEFT OUTER JOIN prices p ON p.sym = o.sym and p.ts >= dateadd('s', -1, o.ts) and p.ts <= dateadd('s', 1, o.ts);", - 136, - "Invalid column: ts", - sqlExecutionContext - ); + final String sql = + "SELECT o.*, avg(p.bid) avg_big, avg(p.ask) avg_ask FROM orders o LEFT OUTER JOIN prices p " + + "ON p.sym = o.sym and p.ts >= dateadd('s', -1, o.ts) and p.ts <= dateadd('s', 1, o.ts);"; + final int pos = sql.indexOf("o.ts") + "o.".length(); // point at 'ts' + assertExceptionNoLeakCheck(sql, pos, "Invalid column: ts", sqlExecutionContext);
- Optional: rename to testJoinUsesNonexistentColumn for clarity.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
core/src/main/java/io/questdb/griffin/SqlCodeGenerator.java(1 hunks)core/src/test/java/io/questdb/test/griffin/SqlCodeGeneratorTest.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (26)
- GitHub Check: New pull request (SelfHosted Griffin And Fuzz tests on linux-arm64)
- GitHub Check: New pull request (SelfHosted Other tests on linux-x64-zfs)
- GitHub Check: New pull request (SelfHosted Other tests on linux-arm64)
- GitHub Check: New pull request (SelfHosted Griffin And Fuzz tests on linux-x64-zfs)
- GitHub Check: New pull request (SelfHosted Other tests Start X64Zfs Agent)
- GitHub Check: New pull request (Rust Test and Lint on linux-jdk17)
- GitHub Check: New pull request (Hosted Running tests on windows-other)
- GitHub Check: New pull request (Hosted Running tests on windows-pgwire)
- GitHub Check: New pull request (Hosted Running tests on windows-cairo)
- GitHub Check: New pull request (Hosted Running tests on windows-fuzz2)
- GitHub Check: New pull request (Hosted Running tests on windows-fuzz1)
- GitHub Check: New pull request (Hosted Running tests on windows-griffin)
- GitHub Check: New pull request (Hosted Running tests with cover on linux-other)
- GitHub Check: New pull request (Hosted Running tests on mac-other)
- GitHub Check: New pull request (Hosted Running tests with cover on linux-pgwire)
- GitHub Check: New pull request (Hosted Running tests on mac-pgwire)
- GitHub Check: New pull request (Hosted Running tests on mac-cairo-fuzz)
- GitHub Check: New pull request (Hosted Running tests with cover on linux-cairo)
- GitHub Check: New pull request (Hosted Running tests on mac-cairo)
- GitHub Check: New pull request (Hosted Running tests with cover on linux-fuzz)
- GitHub Check: New pull request (SelfHosted Griffin And Fuzz tests Start ARM Agent)
- GitHub Check: New pull request (SelfHosted Other tests Start ARM Agent)
- GitHub Check: New pull request (Hosted Running tests with cover on linux-griffin)
- GitHub Check: New pull request (Hosted Running tests on mac-griffin)
- GitHub Check: New pull request (SelfHosted Griffin And Fuzz tests Start X64Zfs Agent)
- GitHub Check: New pull request (Check Changes Check changes)
🔇 Additional comments (1)
core/src/main/java/io/questdb/griffin/SqlCodeGenerator.java (1)
5901-5905: Fail-fast check prevents AIOOBE; verified and approved.The fix correctly calls
getColumnIndexQuiet()and throwsSqlException.invalidColumn()on -1 return, preventing index-out-of-bounds access. Test coverage is in place:testJoinUseNonExistColumnvalidates the scenario by referencing a non-existent column in a JOIN, confirming the error is surfaced with proper position and column name context.
[PR Coverage check]😍 pass : 5 / 5 (100.00%) file detail
|
close #6329