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

feat: infer timestamp constraint for single-timestamp column #1266

Merged
merged 4 commits into from
Oct 18, 2023

Conversation

Dennis40816
Copy link
Contributor

Rationale

This PR aims to resolve issue #1144 by simplifying the process of table creation with timestamp constraints. Specifically, the system will automatically infer and set the timestamp constraint under the following conditions:

  1. No timestamp constraint has been previously set.
  2. There exists exactly one column with a timestamp data type(DataType::Timestamp).

By introducing this automatic inference, we reduce the complexity for users who otherwise would have to manually set this constraint.

Detailed Changes

  • Automatic Inference of Timestamp Constraint: The system now detects if there is only a single timestamp column during table creation and automatically sets it as the timestamp constraint.

    • Added a function build_and_check_timestamp_key_constraint for checking and inference.
    • Modified the create_table function to call the new function.
  • Updated Test Expectations for create_table:

    • Refactored test cases for create_table in parser.rs to align with the latest timestamp inference changes.
    • Updated the expected statements to include unique constraints for timestamp columns.

Test Plan

Utilized the default CI Action for testing. The result was a pass.

Remarks

  • Made modifications to a particular section of the code. Would appreciate it if experienced team members could review and confirm whether any changes or corrections are needed.

This commit addresses issue apache#1144. It aims to automatically infer the
timestamp column during table creation when possible.

Previously, users had to explicitly set a timestamp constraint, adding
unnecessary complexity.

Now, the system will detect if there is only one timestamp column and
set it as the constraint.

- Added `build_and_check_timestamp_key_constraint` to check and infer.
- Modified `create_table` to call the new function.
- Refactor test cases for `create_table` in `parser.rs` to align with the latest
  timestamp inference changes made in the previous commit.
- Update the expected statements to include unique constraints for timestamp
  columns, as influenced by the modifications in timestamp inference.
@jiacai2050
Copy link
Contributor

The general implementation looks GOOD to me. 👍

I leave a few minor suggestions, do those make sense to you?

- Rename from `build_and_check_timestamp_key_constraint` to
  `build_or_infer_timestamp_key_constraint`
- Modify the function's comment
- Added a test case that includes two timestamp columns and explicitly selects
  the c2 field as the timestamp key. The test passes locally.
@Dennis40816
Copy link
Contributor Author

Dennis40816 commented Oct 17, 2023

Thank you for the review and for your positive feedback! 👍

I've gone ahead and made some additional updates based on our discussion:

  1. Renamed the function for better clarity.
  2. Added a new test case to cover more scenarios.

Your minor suggestions make complete sense to me, and I've taken them into account.

Here's the link to the updated CI results.

Please let me know if there's anything else to improve.

Copy link
Contributor

@jiacai2050 jiacai2050 left a comment

Choose a reason for hiding this comment

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

LGTM

@jiacai2050 jiacai2050 changed the title [WIP]feat: auto-add timestamp constraint for single-timestamp column feat: infer timestamp constraint for single-timestamp column Oct 18, 2023
@jiacai2050 jiacai2050 merged commit fb783f0 into apache:main Oct 18, 2023
7 checks passed
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