Skip to content

fix(sql): proper error message when timestamp used along another join key in ASOF/LT join#6698

Merged
bluestreak01 merged 5 commits intomasterfrom
mt_asof-timestamp
Jan 23, 2026
Merged

fix(sql): proper error message when timestamp used along another join key in ASOF/LT join#6698
bluestreak01 merged 5 commits intomasterfrom
mt_asof-timestamp

Conversation

@mtopolnik
Copy link
Copy Markdown
Contributor

Fixes #6637

@mtopolnik mtopolnik requested a review from jerrinot January 23, 2026 14:07
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 23, 2026

Walkthrough

This PR adds validation to prevent designated timestamp columns from being used as join keys in ASOF/LT joins. It introduces a new validation method that raises a proper SqlException instead of allowing an AssertionError to occur when a timestamp is incorrectly specified in multi-key join conditions.

Changes

Cohort / File(s) Summary
Timestamp Join Key Validation
core/src/main/java/io/questdb/griffin/SqlCodeGenerator.java
Adds private method validateTimestampNotInJoinKeys that scans join keys to enforce that designated timestamps are not used as join keys in ASOF/LT joins with multiple keys. Method is invoked during ASOF/LT join construction.
ASOF Join Test Updates
core/src/test/java/io/questdb/test/griffin/engine/join/AsOfJoinTest.java
Replaces testAsOfJoinWithSymbolAndTimestampInOnClause with new test testJoinOnTimestampAndSomethingElseNotAllowed that verifies SqlException is raised when timestamp is used as join key in both ASOF and LT join scenarios.
Join Model Assertion Guard
core/src/test/java/io/questdb/test/griffin/engine/join/JoinTest.java
Adds conditional guard around assertion in testJoinColumnPropagationIntoJoinModel0 to skip validation when join type is LT or ASOF. Minor clause reordering for readability.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

Bug, SQL

Suggested reviewers

  • bluestreak01
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely describes the main change: adding proper error validation for timestamp columns used in ASOF/LT join keys.
Description check ✅ Passed The PR description references the linked issue #6637, which is directly related to the changeset addressing the timestamp-in-join-key validation.
Linked Issues check ✅ Passed The code changes implement validation to prevent timestamps from being used as join keys in ASOF/LT joins, directly addressing issue #6637's requirement to prevent AssertionError and return proper SQLException.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the timestamp-in-join-key issue: new validation method, updated tests, and adjusted join test assertions remain within scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.40.5)
core/src/main/java/io/questdb/griffin/SqlCodeGenerator.java
core/src/test/java/io/questdb/test/griffin/engine/join/JoinTest.java

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.

@mtopolnik
Copy link
Copy Markdown
Contributor Author

@CodeRabbit Please review this.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 23, 2026

@mtopolnik: I'll review the changes in this PR.


🧠 Learnings used
Learnt from: bluestreak01
Repo: questdb/questdb PR: 6673
File: core/src/test/java/io/questdb/test/griffin/WindowJoinTest.java:2616-2618
Timestamp: 2026-01-19T21:43:19.228Z
Learning: In test `testWindowJoinFailsWhenSlaveDoesNotSupportTimeFrames` in `core/src/test/java/io/questdb/test/griffin/WindowJoinTest.java`, the use of `AND` between timestamp equality conditions (e.g., `ts = 'X' AND ts = 'Y'`) is intentional to prevent intrinsic interval creation. This ensures the window join fails as expected when the slave doesn't support time frames, which is necessary after PR `#6673` added OR timestamp intrinsics recognition.
✅ 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.

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 502 / 579 (86.70%)

file detail

path covered line new line coverage
🔵 io/questdb/cutlass/http/processors/SqlValidationProcessor.java 0 1 00.00%
🔵 io/questdb/cairo/wal/ApplyWal2TableJob.java 0 1 00.00%
🔵 io/questdb/cairo/DefaultCairoConfiguration.java 6 8 75.00%
🔵 io/questdb/cairo/DatabaseCheckpointAgent.java 192 228 84.21%
🔵 io/questdb/griffin/SqlCompilerImpl.java 218 251 86.85%
🔵 io/questdb/cairo/DataID.java 27 31 87.10%
🔵 io/questdb/cutlass/http/processors/JsonQueryProcessor.java 1 1 100.00%
🔵 io/questdb/DynamicPropServerConfiguration.java 1 1 100.00%
🔵 io/questdb/PropertyKey.java 5 5 100.00%
🔵 io/questdb/griffin/SqlCodeGenerator.java 11 11 100.00%
🔵 io/questdb/cairo/CairoConfigurationWrapper.java 8 8 100.00%
🔵 io/questdb/Bootstrap.java 1 1 100.00%
🔵 io/questdb/PropServerConfiguration.java 13 13 100.00%
🔵 io/questdb/cairo/wal/seq/SequencerMetadata.java 1 1 100.00%
🔵 io/questdb/cairo/mv/MatViewRefreshJob.java 4 4 100.00%
🔵 io/questdb/cairo/security/ReadOnlySecurityContext.java 1 1 100.00%
🔵 io/questdb/cairo/CairoEngine.java 7 7 100.00%
🔵 io/questdb/griffin/CompiledQueryImpl.java 3 3 100.00%
🔵 io/questdb/cutlass/text/ParallelCsvFileImporter.java 2 2 100.00%
🔵 io/questdb/cairo/SymbolMapUtil.java 1 1 100.00%

@bluestreak01 bluestreak01 merged commit 891ecdc into master Jan 23, 2026
43 checks passed
@bluestreak01 bluestreak01 deleted the mt_asof-timestamp branch January 23, 2026 18:55
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.

LT/ASOF JOIN with timestamp in ON clause crashes with AssertionError instead of returning proper error

3 participants