Skip to content

fix(sql): fix a bug that made some ASOF JOIN queries fail with an internal error#6433

Merged
bluestreak01 merged 2 commits intomasterfrom
mt_fix-symbol-table
Nov 24, 2025
Merged

fix(sql): fix a bug that made some ASOF JOIN queries fail with an internal error#6433
bluestreak01 merged 2 commits intomasterfrom
mt_fix-symbol-table

Conversation

@mtopolnik
Copy link
Copy Markdown
Contributor

Fixes #6430

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 23, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This PR fixes a ClassCastException occurring during ASOF JOIN queries with aggregated symbol columns. It adds a helper method to properly extract StaticSymbolTable from wrapped symbol tables (including SymbolFunction wrappers), ensuring join key mapping handles grouped symbol columns correctly. Includes a test case to verify the fix.

Changes

Cohort / File(s) Summary
ASOF Join Symbol Table Extraction
core/src/main/java/io/questdb/griffin/engine/join/SymbolToSymbolJoinKeyMapping.java
Adds private helper method getStaticSymbolTable(SymbolTable) to extract StaticSymbolTable from wrapped symbol tables (handles direct StaticSymbolTable, SymbolFunction wrappers, and throws assertion for unexpected cases). Updates of(RecordCursor) to use this helper when assigning slave symbol table. Adds import for SymbolFunction.
ASOF Join Test Coverage
core/src/test/java/io/questdb/test/griffin/engine/join/AsOfJoinTest.java
Adds new test method testGetStaticSymbolTable() that exercises ASOF JOIN with symbol columns from aggregated CTEs, validating correct handling of wrapped symbol tables and verifying result set precision.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Targeted single-method fix in core join logic requires understanding symbol table wrapping mechanics
  • New test validates the specific ClassCastException scenario from the linked issue
  • Logic density is low but context-dependent on symbol table abstraction hierarchy

Possibly related PRs

Suggested labels

Bug, SQL

Suggested reviewers

  • RaphDal

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing a bug in ASOF JOIN queries that caused internal errors.
Description check ✅ Passed The description references the linked issue #6430, which directly relates to the changeset addressing the ASOF JOIN bug.
Linked Issues check ✅ Passed The PR introduces a helper method getStaticSymbolTable() and adds a test case that directly addresses the ClassCastException reported in issue #6430 when joining symbol tables.
Out of Scope Changes check ✅ Passed All changes are within scope: the helper method supports static symbol table extraction for ASOF JOINs, and the test validates the fix for the reported bug.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bluestreak01
Copy link
Copy Markdown
Member

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 23, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e831633 and 64f01f2.

📒 Files selected for processing (2)
  • core/src/main/java/io/questdb/griffin/engine/join/SymbolToSymbolJoinKeyMapping.java (2 hunks)
  • core/src/test/java/io/questdb/test/griffin/engine/join/AsOfJoinTest.java (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-10T14:28:48.329Z
Learnt from: mtopolnik
Repo: questdb/questdb PR: 0
File: :0-0
Timestamp: 2025-11-10T14:28:48.329Z
Learning: In AsOfJoinDenseRecordCursorFactoryBase.java, the `backwardScanExhausted` flag is intentionally NOT reset in `toTop()` because backward scan results are reusable across cursor rewinds. The backward scan caches historical matches that remain valid when the cursor is rewound.

Applied to files:

  • core/src/main/java/io/questdb/griffin/engine/join/SymbolToSymbolJoinKeyMapping.java
🧬 Code graph analysis (1)
core/src/main/java/io/questdb/griffin/engine/join/SymbolToSymbolJoinKeyMapping.java (1)
core/src/main/java/io/questdb/griffin/engine/functions/SymbolFunction.java (1)
  • SymbolFunction (52-276)
⏰ 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). (34)
  • GitHub Check: New pull request (Coverage Report Coverage Report)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-other)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-pgwire)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-sub)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-root)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz2)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz1)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-sub)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-root)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x86-graal)
  • GitHub Check: New pull request (Hosted Running tests on windows-other-2)
  • GitHub Check: New pull request (Hosted Running tests on windows-other-1)
  • GitHub Check: New pull request (Hosted Running tests on windows-pgwire)
  • GitHub Check: New pull request (Hosted Running tests on windows-cairo-2)
  • GitHub Check: New pull request (Hosted Running tests on windows-cairo-1)
  • 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-sub)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-base)
  • GitHub Check: New pull request (Hosted Running tests on mac-other)
  • 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 on mac-cairo)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x64-zfs)
  • GitHub Check: New pull request (Hosted Running tests on mac-griffin)
  • GitHub Check: New pull request (Rust Test and Lint on linux-jdk17)
  • 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 (Check Changes Check changes)
🔇 Additional comments (3)
core/src/test/java/io/questdb/test/griffin/engine/join/AsOfJoinTest.java (1)

1837-1871: Test properly covers the bug scenario.

The test correctly exercises the ClassCastException fix by using ASOF JOIN with aggregated symbol columns (via SAMPLE BY in the asks CTE). This creates a wrapped symbol table (MapSymbolColumn) that previously caused the cast failure, now properly handled by the new getStaticSymbolTable helper.

core/src/main/java/io/questdb/griffin/engine/join/SymbolToSymbolJoinKeyMapping.java (2)

33-33: LGTM - necessary import for the fix.


99-99: Fix correctly addresses the ClassCastException.

The change from direct cast to using the helper method properly handles symbol tables wrapped by SymbolFunction (e.g., MapSymbolColumn from group by operations).

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 5 / 6 (83.33%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/engine/join/SymbolToSymbolJoinKeyMapping.java 5 6 83.33%

@bluestreak01 bluestreak01 merged commit b4a147e into master Nov 24, 2025
41 checks passed
@bluestreak01 bluestreak01 deleted the mt_fix-symbol-table branch November 24, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal error in ASOF join

3 participants