Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bugs introduced by alter table options #4953

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

killme2008
Copy link
Contributor

@killme2008 killme2008 commented Nov 6, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

Fixed bugs introduced by #4926 :

  • Wrong display format for ChangeTableOptions
  • The partition number in table metadata disappears after altering table options.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced table structure with the addition of a PRIMARY KEY constraint on the i column in the ato table.
    • Introduced time-to-live (TTL) options for the ato table, allowing for dynamic management of data retention.
  • Bug Fixes

    • Adjusted SQL syntax in test cases for altering tables to ensure alignment with expected formats.
  • Refactor

    • Streamlined methods for altering table metadata to improve code clarity and consistency.
  • Tests

    • Updated test cases to reflect new table definitions and ensure accurate validation of SQL commands.

@killme2008 killme2008 requested a review from a team as a code owner November 6, 2024 13:20
Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

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

The changes in this pull request involve modifications to SQL parsing and table alteration functionalities. Specifically, adjustments were made to the alter_parser.rs file to remove semicolons from test cases and refine error messages. The AlterTableOperation enum in alter.rs was updated to reflect new SQL syntax for altering table options. Additionally, methods in metadata.rs were refactored to streamline the creation of table metadata builders. Finally, SQL scripts and result files were updated to incorporate a primary key constraint and various time-to-live settings for a test table.

Changes

File Path Change Summary
src/sql/src/parsers/alter_parser.rs Removed semicolons from SQL statements in test cases; updated error messages for consistency.
src/sql/src/statements/alter.rs Updated comment and implementation of AlterTableOperation for ChangeTableOptions to use SET.
src/table/src/metadata.rs Refactored builder_with_alter_kind and change_table_options methods to use new_meta_builder; added new_meta_builder method.
tests/cases/standalone/common/alter/alter_table_options.result Added PRIMARY KEY(i) constraint; modified TTL settings with corresponding SELECT and SHOW CREATE TABLE commands.
tests/cases/standalone/common/alter/alter_table_options.sql Added PRIMARY KEY(i) constraint; restructured TTL alterations and added SELECT statements.

Poem

In the land of SQL, where tables grow,
A primary key now steals the show! 🐇
With TTLs dancing, they change like the breeze,
Our queries now sing with newfound ease.
So hop along, let’s celebrate this feat,
With structured tables, our work is complete! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Nov 6, 2024
Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.81%. Comparing base (dfe8cf2) to head (889526b).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4953      +/-   ##
==========================================
- Coverage   84.04%   83.81%   -0.24%     
==========================================
  Files        1142     1142              
  Lines      211473   211474       +1     
==========================================
- Hits       177740   177246     -494     
- Misses      33733    34228     +495     

@killme2008
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

✅ 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
Contributor

@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: 4

🧹 Outside diff range and nitpick comments (4)
tests/cases/standalone/common/alter/alter_table_options.sql (1)

1-3: Consider adding more diverse test data.

While the current test data is sufficient for basic verification, consider adding test cases with:

  • Larger datasets to verify TTL behavior with multiple records
  • Different time intervals between records to better validate TTL expiration
 CREATE TABLE ato(i INTEGER, j TIMESTAMP TIME INDEX, PRIMARY KEY(i));

-INSERT INTO ato VALUES(1, now()), (2, now());
+INSERT INTO ato VALUES
+  (1, now()),
+  (2, now() - INTERVAL '6 hours'),
+  (3, now() - INTERVAL '12 hours'),
+  (4, now() - INTERVAL '23 hours');
src/sql/src/parsers/alter_parser.rs (2)

500-509: LGTM! Comprehensive test coverage for ALTER TABLE SET options.

The test cases effectively cover various scenarios including single/multiple options, NULL values, and error cases. Consider adding a test case for empty string values (e.g., SET 'a'='') to ensure complete coverage of possible input values.


500-509: Consider adding validation for table option keys and values.

While the parsing implementation correctly handles the syntax, consider adding validation for:

  • Maximum length limits for option keys and values
  • Allowed characters in option keys
  • Reserved option keys that might have special meaning
src/table/src/metadata.rs (1)

257-262: Consider automating builder initialization.

While the current implementation is good, it relies on manual updates when new fields are added to TableMeta. Consider using derive macros or code generation to automatically handle new fields and prevent potential bugs.

You could:

  1. Use a derive macro to generate the builder initialization code
  2. Or add compile-time checks to ensure all fields are copied

Example of a potential derive macro approach:

#[derive(BuilderInit)]
struct TableMeta {
    // ... existing fields ...
}

// This would automatically generate new_meta_builder with all fields
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dfe8cf2 and 996167b.

📒 Files selected for processing (5)
  • src/sql/src/parsers/alter_parser.rs (2 hunks)
  • src/sql/src/statements/alter.rs (3 hunks)
  • src/table/src/metadata.rs (3 hunks)
  • tests/cases/standalone/common/alter/alter_table_options.result (7 hunks)
  • tests/cases/standalone/common/alter/alter_table_options.sql (1 hunks)
🔇 Additional comments (12)
tests/cases/standalone/common/alter/alter_table_options.sql (1)

15-16: Validate TTL transition behavior.

The test should verify that changing TTL from '1d' to '2d' properly updates expiration times for existing records.

tests/cases/standalone/common/alter/alter_table_options.result (6)

1-17: LGTM: Table creation and initial data population are correct.

The table structure with PRIMARY KEY constraint and the initial data insertion are properly implemented and verified.


Line range hint 18-47: Verify TTL format consistency between input and output.

The input TTL format '1d' is displayed as '1day' in the SHOW CREATE TABLE output. While this works, it might be worth documenting this behavior to avoid confusion.


Line range hint 48-78: Previous comment about TTL format applies here.


Line range hint 79-108: LGTM: TTL removal is handled correctly.

The NULL TTL setting appropriately removes the WITH clause from the table definition while preserving data.


Line range hint 109-139: Verify the implications of 1-second TTL.

While this might be intentional for testing, a 1-second TTL is extremely short and could lead to immediate data deletion in production. Consider adding a comment or assertion to explicitly indicate this is a test case.


Line range hint 140-143: LGTM: Clean test cleanup.

The table is properly dropped at the end of the test case.

src/sql/src/statements/alter.rs (2)

19-19: LGTM: Good choice using itertools!

Using Itertools for joining strings is a good choice as it provides a more ergonomic and efficient way to handle string concatenation compared to manual string building.


72-72: LGTM: Documentation accurately reflects the new SQL syntax.

The change from MODIFY to SET for table options aligns better with standard SQL syntax conventions.

src/sql/src/parsers/alter_parser.rs (1)

489-490: LGTM! Important assertion added for string representation.

The new assertion ensures that ALTER TABLE statements maintain their correct string representation after parsing, which directly addresses the PR objective of fixing the ChangeTableOptions display format.

src/table/src/metadata.rs (2)

204-204: LGTM: Good refactoring of table rename handling.

The change simplifies the code by using the centralized new_meta_builder method, reducing duplication.


224-226: LGTM: Clean implementation of table options change.

The code follows good practices:

  • Uses the centralized builder creation
  • Maintains immutability
  • Correctly applies the builder pattern

src/table/src/metadata.rs Outdated Show resolved Hide resolved
Co-authored-by: Ruihang Xia <waynestxia@gmail.com>
Copy link
Contributor

@v0y4g3r v0y4g3r left a comment

Choose a reason for hiding this comment

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

LGTM

@v0y4g3r v0y4g3r added this pull request to the merge queue Nov 6, 2024
Merged via the queue into GreptimeTeam:main with commit 305767e Nov 6, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants