Skip to content

fix(core): fix incorrect designated timestamp column displayed by tables() after column type changes#6570

Merged
bluestreak01 merged 3 commits intomasterfrom
ia_metadata_cache_timestamp
Dec 20, 2025
Merged

fix(core): fix incorrect designated timestamp column displayed by tables() after column type changes#6570
bluestreak01 merged 3 commits intomasterfrom
ia_metadata_cache_timestamp

Conversation

@glasstiger
Copy link
Copy Markdown
Contributor

The tables() function displayed incorrect designated timestamp column when a column type change occurred on any column positioned before the designated timestamp column in the table schema.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 20, 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

MetadataCache.MetadataCacheWriterImpl.hydrateTable method now stores sorted columns in a local variable, calls setPosition(i) on each, and updates the table's timestamp index when processing timestamp-designated columns. Two new test cases were added to verify timestamp index behavior after column type changes and column drops.

Changes

Cohort / File(s) Summary
Core Implementation
core/src/main/java/io/questdb/cairo/MetadataCache.java
Modified hydrateTable method to update table's timestamp index within the column sorting loop when a column is designated as timestamp, alongside position updates
Tests
core/src/test/java/io/questdb/test/cairo/MetadataCacheTest.java
Added testMetadataAfterColumnTypeChange and testMetadataAfterDropColumn test methods to verify timestamp index behavior during column modifications; added assertTimestamp helper method to validate timestamp index and name from metadata cache

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • The timestamp index update logic in hydrateTable requires verification that position updates and timestamp index updates are correctly coordinated
  • Test cases should be validated to ensure they comprehensively cover the intended behavior, including edge cases around timestamp column modifications
  • The interaction between column position changes and timestamp index state consistency should be carefully reviewed

Suggested reviewers

  • bluestreak01

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the bug fix related to the tables() function displaying incorrect timestamp columns after type changes, which directly relates to the code changes in MetadataCache and the new tests.
Title check ✅ Passed The title accurately describes the main fix: correcting an incorrect designated timestamp column displayed by tables() after column type changes, which aligns with the code changes in MetadataCache.java that now properly update the timestamp index.

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.

@glasstiger
Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 20, 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: 0

🧹 Nitpick comments (1)
core/src/test/java/io/questdb/test/cairo/MetadataCacheTest.java (1)

840-848: Useful helper method for test assertions.

The assertTimestamp helper simplifies timestamp index verification in the new tests. The hardcoded timestamp column name "timestamp" is acceptable since it matches the schema of table 'x' used in the current tests.

💡 Optional: Make the helper more flexible for future use

If this helper is used with tables having different timestamp column names in the future, consider adding the timestamp name as a parameter:

-private static void assertTimestamp(TableToken tt, int timestampIndex) {
+private static void assertTimestamp(TableToken tt, int timestampIndex, String expectedTimestampName) {
     try (MetadataCacheReader reader = engine.getMetadataCache().readLock()) {
         final CairoTable table = reader.getTable(tt);
         Assert.assertNotNull(table);
         final int tsIndex = table.getTimestampIndex();
         Assert.assertEquals(timestampIndex, tsIndex);
-        Assert.assertEquals("timestamp", table.getTimestampName());
+        Assert.assertEquals(expectedTimestampName, table.getTimestampName());
     }
 }

Then update the calls:

-assertTimestamp(tt, 3);
+assertTimestamp(tt, 3, "timestamp");
📜 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 cf8c145 and dc9ae21.

📒 Files selected for processing (2)
  • core/src/main/java/io/questdb/cairo/MetadataCache.java (1 hunks)
  • core/src/test/java/io/questdb/test/cairo/MetadataCacheTest.java (2 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). (36)
  • 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 (SelfHosted Running tests with cover on linux-other)
  • GitHub Check: New pull request (Hosted Running tests on windows-fuzz1)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-pgwire)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-sub)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-sub)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-base)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-root)
  • GitHub Check: New pull request (Hosted Running tests on mac-other)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz2)
  • GitHub Check: New pull request (Hosted Running tests on mac-pgwire)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz1)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo-fuzz)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-sub)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo)
  • GitHub Check: New pull request (Hosted Running tests on mac-griffin)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-root)
  • GitHub Check: New pull request (Trigger Enterprise CI Trigger Enterprise Pipeline)
  • GitHub Check: New pull request (Rust Test and Lint on linux-jdk17)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x86-graal)
  • GitHub Check: New pull request (Check Changes Check changes)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (3)
core/src/main/java/io/questdb/cairo/MetadataCache.java (1)

599-607: LGTM! Critical fix correctly implemented.

The addition of the timestamp index update after column sorting correctly addresses the bug described in the PR. When columns are sorted (line 597), the designated timestamp column's logical position may change, especially after column type changes that affect columns positioned before it. The fix ensures the table's timestamp index reflects the post-sort position by updating it during the iteration over sorted columns.

The use of a local variable column improves readability and performance by avoiding repeated getQuick(i) calls.

core/src/test/java/io/questdb/test/cairo/MetadataCacheTest.java (2)

721-732: Good test coverage for the column type change scenario.

This test correctly validates that the designated timestamp index remains stable when a column positioned before it undergoes a type change. The test directly addresses the bug described in the PR objectives.

Since table 'x' is a non-WAL table, the absence of drainWalQueue() is appropriate—metadata updates are synchronous for non-WAL tables.


734-745: Good complementary test for the column drop scenario.

This test validates that the designated timestamp index correctly adjusts when a column positioned before it is dropped. After dropping column 'i' at position 0, the timestamp index correctly decrements from 3 to 2, verifying the post-sort timestamp index update logic in the fix.

@bluestreak01 bluestreak01 changed the title fix(core): Fix incorrect designated timestamp column displayed by tables() after column type changes fix(core): fix incorrect designated timestamp column displayed by tables() after column type changes Dec 20, 2025
@glasstiger
Copy link
Copy Markdown
Contributor Author

[PR Coverage check]

😍 pass : 4 / 4 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/cairo/MetadataCache.java 4 4 100.00%

@bluestreak01 bluestreak01 merged commit 5ea35f5 into master Dec 20, 2025
43 checks passed
@bluestreak01 bluestreak01 deleted the ia_metadata_cache_timestamp branch December 20, 2025 23:59
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.

2 participants