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: Alter inverted index #5131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lyang24
Copy link
Collaborator

@lyang24 lyang24 commented Dec 10, 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?

!!! DO NOT LEAVE THIS BLOCK EMPTY !!!

Please explain IN DETAIL what the changes are in this PR and why they are needed:

  • Summarize your change (mandatory)
    This pr enables alter table x modify column set/ unset inverted index syntax.
  1. modify index proto has been refactored.
  2. parse support the new syntax with refactoring.
  3. metadata update with alter inverted index.
  • How does this PR work? Need a brief introduction for the changed logic (optional)
  • Describe clearly one logical change and avoid lazy messages (optional)
  • Describe any limitations of the current code (optional)

Checklist

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

Copy link
Contributor

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


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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 Dec 10, 2024
@lyang24 lyang24 force-pushed the alter_inverted_index branch from 0313c65 to 9772667 Compare December 12, 2024 06:50
@lyang24 lyang24 changed the title feat: (wip) Alter inverted index feat: Alter inverted index Dec 12, 2024
) -> Result<()> {
for column_meta in self.column_metadatas.iter_mut() {
if column_meta.column_schema.name == column_name {
ensure!(
Copy link
Collaborator Author

@lyang24 lyang24 Dec 12, 2024

Choose a reason for hiding this comment

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

discussion: i wonder if String is the only data type that support inverted index? what about json or other datatypes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently we only support string type. Other datatypes like json may be supported in the future, and we can adjust this correspondingly. See #5080

@lyang24 lyang24 force-pushed the alter_inverted_index branch 2 times, most recently from 9fafcd4 to 6bc72b7 Compare December 12, 2024 07:06
@lyang24 lyang24 force-pushed the alter_inverted_index branch from 6bc72b7 to a9f433b Compare December 12, 2024 07:10
@lyang24 lyang24 marked this pull request as ready for review December 12, 2024 07:10
@lyang24 lyang24 requested a review from CookiePieWw December 12, 2024 07:10
Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 68.66267% with 157 lines in your changes missing coverage. Please review.

Project coverage is 83.74%. Comparing base (2137c53) to head (a9f433b).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5131      +/-   ##
==========================================
- Coverage   84.01%   83.74%   -0.28%     
==========================================
  Files        1172     1172              
  Lines      218098   218485     +387     
==========================================
- Hits       183239   182960     -279     
- Misses      34859    35525     +666     

@waynexia waynexia requested review from zhongzc and Copilot December 12, 2024 12:59

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 16 changed files in this pull request and generated no suggestions.

Files not reviewed (10)
  • tests/cases/standalone/common/alter/change_col_inverted_index.result: Language not supported
  • tests/cases/standalone/common/alter/change_col_inverted_index.sql: Language not supported
  • src/store-api/src/metadata.rs: Evaluated as low risk
  • src/common/grpc-expr/src/alter.rs: Evaluated as low risk
  • Cargo.toml: Evaluated as low risk
  • src/table/src/requests.rs: Evaluated as low risk
  • src/table/src/metadata.rs: Evaluated as low risk
  • src/store-api/src/region_request.rs: Evaluated as low risk
  • src/common/meta/src/ddl/alter_table/region_request.rs: Evaluated as low risk
  • src/common/meta/src/ddl/alter_table/update_metadata.rs: Evaluated as low risk
Comments skipped due to low confidence (4)

src/sql/src/parsers/alter_parser.rs:277

  • The error message should clearly indicate that the parser was expecting either FULLTEXT or INVERTED INDEX. Consider changing it to 'Expected FULLTEXT or INVERTED INDEX after ALTER TABLE MODIFY COLUMN'.
self.expected(format!("{:?} OR INVERTED INDEX", Keyword::FULLTEXT).as_str(), self.parser.peek_token(),)

src/sql/src/parsers/alter_parser.rs:304

  • The error message should clearly indicate that the parser was expecting either FULLTEXT or INVERTED INDEX. Consider changing it to 'Expected FULLTEXT or INVERTED INDEX after ALTER TABLE MODIFY COLUMN'.
self.expected(format!("{:?} OR INVERTED INDEX", Keyword::FULLTEXT).as_str(), self.parser.peek_token(),)

src/operator/src/expr_factory.rs:543

  • [nitpick] The name 'SetIndex' is not very descriptive. Consider renaming it to something more specific, like 'SetColumnIndex'.
AlterTableOperation::SetIndex { options } => AlterTableKind::SetIndex(match options {

src/operator/src/expr_factory.rs:564

  • [nitpick] The name 'UnsetIndex' is not very descriptive. Consider renaming it to something more specific, like 'UnsetColumnIndex'.
AlterTableOperation::UnsetIndex { options } => AlterTableKind::UnsetIndex(match options {
Copy link
Collaborator

@CookiePieWw CookiePieWw left a comment

Choose a reason for hiding this comment

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

Thanks for your nice work! Left some nit comments.

I wonder if the behaviour of changing inverted index is the same as fulltext index: disabling it would only stop constructing new indexes, and the previously contructed indexes will still take effect? @zhongzc


use super::create_parser::INVERTED;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
use super::create_parser::INVERTED;
use crate::create_parser::INVERTED;

Analyzer::try_from(c.analyzer).context(InvalidSetFulltextOptionRequestSnafu)?,
),
case_sensitive: c.case_sensitive,
Kind::SetIndex(o) => match o.options.unwrap() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Kind::SetIndex(o) => match o.options.unwrap() {
Kind::SetIndex(o) => match o.options {
Some(..) => { .. }
None => { .. }
}

},
},
Kind::UnsetColumnFulltext(c) => AlterKind::UnsetColumnFulltext {
column_name: c.column_name,
Kind::UnsetIndex(o) => match o.options.unwrap() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto.

| AlterKind::UnsetColumnFulltext { column_name } => {
Self::validate_column_fulltext_option(column_name, metadata)?;
AlterKind::SetIndex { options } => {
Self::validate_column_fulltext_option(options.column_name(), metadata)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the options is used for both kinds of index, we can change the name of the validate fn.

Analyzer::try_from(x.analyzer).context(DecodeProtoSnafu)?,
),
case_sensitive: x.case_sensitive,
alter_request::Kind::SetIndex(o) => match o.options.unwrap() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
alter_request::Kind::SetIndex(o) => match o.options.unwrap() {
alter_request::Kind::SetIndex(o) => match o.options {
Some(..) => { .. }
None => { .. }
}

},
},
alter_request::Kind::UnsetColumnFulltext(x) => AlterKind::UnsetColumnFulltext {
column_name: x.column_name,
alter_request::Kind::UnsetIndex(o) => match o.options.unwrap() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto.

Comment on lines +152 to +163
pub fn update_inverted_index(&mut self, value: bool) {
match value {
true => {
self.metadata
.insert(INVERTED_INDEX_KEY.to_string(), value.to_string());
}

false => {
self.metadata.remove(INVERTED_INDEX_KEY);
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can simply set the value since is_inverted_indexed would check the value.

Suggested change
pub fn update_inverted_index(&mut self, value: bool) {
match value {
true => {
self.metadata
.insert(INVERTED_INDEX_KEY.to_string(), value.to_string());
}
false => {
self.metadata.remove(INVERTED_INDEX_KEY);
}
}
}
pub fn update_inverted_index(&mut self, value: bool) {
self.metadata.insert(INVERTED_INDEX_KEY.to_string(), value.to_string());
}

@waynexia
Copy link
Member

FYI: #5178

This issue is related to the PR, in case anyone might be interested in it.

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