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 column fulltext option #4637

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

irenjj
Copy link
Collaborator

@irenjj irenjj commented Aug 28, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

closes: #4395

What's changed and what's your intention?

Supports alter column options like:

ALTER TABLE monitor SET COLUMN load_15 fulltext WITH(analyzer = 'Chinese', case_sensitive = 'false');

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 Aug 28, 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 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 Aug 28, 2024
@irenjj irenjj changed the title feat: Alter column option feat: Alter column fulltext option Sep 7, 2024
@irenjj irenjj marked this pull request as ready for review September 7, 2024 12:07
@WenyXu
Copy link
Member

WenyXu commented Sep 9, 2024

Hi @irenjj there are some conflicts

column_name,
target_type,
if self.parser.parse_keyword(Keyword::SET) {
let _ = self.parser.parse_keyword(Keyword::FULLTEXT);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can check the parse result to avoid receiving unexpected input

Comment on lines 84 to 101
let options = self
.parser
.parse_options(Keyword::WITH)?
.into_iter()
.map(|option: SqlOption| -> Result<(String, String)> {
let (key, value) = (option.name, option.value);
let v = match value {
Expr::Value(sqlparser::ast::Value::SingleQuotedString(v))
| Expr::Value(sqlparser::ast::Value::DoubleQuotedString(v)) => v,
Expr::Identifier(v) => v.value,
Expr::Value(sqlparser::ast::Value::Number(v, _)) => v.to_string(),
_ => return error::InvalidTableOptionValueSnafu { key, value }.fail(),
};
let k = key.value.to_lowercase();
Ok((k, v))
})
.collect::<Result<HashMap<String, String>>>()
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be simplied as

Suggested change
let options = self
.parser
.parse_options(Keyword::WITH)?
.into_iter()
.map(|option: SqlOption| -> Result<(String, String)> {
let (key, value) = (option.name, option.value);
let v = match value {
Expr::Value(sqlparser::ast::Value::SingleQuotedString(v))
| Expr::Value(sqlparser::ast::Value::DoubleQuotedString(v)) => v,
Expr::Identifier(v) => v.value,
Expr::Value(sqlparser::ast::Value::Number(v, _)) => v.to_string(),
_ => return error::InvalidTableOptionValueSnafu { key, value }.fail(),
};
let k = key.value.to_lowercase();
Ok((k, v))
})
.collect::<Result<HashMap<String, String>>>()
.unwrap();
let options = self
.parser
.parse_options(Keyword::WITH)?
.into_iter()
.map(parse_option_string)
.collect::<Result<HashMap<String, String>>>()?;

Comment on lines 609 to 615
let index = table_schema
.column_index_by_name(column_name)
.with_context(|| error::ColumnNotExistsSnafu {
column_name,
table_name,
})?;
let column = &table_schema.column_schemas()[index];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let index = table_schema
.column_index_by_name(column_name)
.with_context(|| error::ColumnNotExistsSnafu {
column_name,
table_name,
})?;
let column = &table_schema.column_schemas()[index];
let column = &table_schema.column_schema_by_name(column_name).with_context(...);

Copy link
Contributor

@zhongzc zhongzc Sep 9, 2024

Choose a reason for hiding this comment

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

I propose that we only allow modify column to create a fulltext index on columns that do not already have one, rather than modifying fulltext options for existing columns.

Copy link
Member

Choose a reason for hiding this comment

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

So we can't disable the full-text index after creation?

@@ -262,6 +262,14 @@ impl ColumnSchema {
);
Ok(self)
}

pub fn set_fulltext_options(&mut self, options: FulltextOptions) -> Result<()> {
self.metadata.insert(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can add a check whether the column type is string: self.data_type == ConcreteDataType::string_datatype(), and also change the with_fulltext_options above

Copy link
Member

@WenyXu WenyXu left a comment

Choose a reason for hiding this comment

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

Nice work!

Some nitpicking:

  1. Add more unit tests
  2. Reduce duplicate code by introducing functions
  3. Avoid unnecessary cloning

@@ -151,7 +151,7 @@ reqwest = { version = "0.12", default-features = false, features = [
"stream",
"multipart",
] }
# SCRAM-SHA-512 requires https://github.com/dequbed/rsasl/pull/48, https://github.com/influxdata/rskafka/pull/247
# SCRAM-SHA-512 requires https://github.com/dequbed/rsasl/pull/48, https://github.com/influxdata/rskafka/pull/247
Copy link
Member

Choose a reason for hiding this comment

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

nit: No need to change this. The comments have been removed in the latest main.

Comment on lines 266 to 272
pub fn set_fulltext_options(&mut self, options: FulltextOptions) -> Result<()> {
self.metadata.insert(
FULLTEXT_KEY.to_string(),
serde_json::to_string(&options).context(error::SerializeSnafu)?,
);
Ok(())
}
Copy link
Member

Choose a reason for hiding this comment

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

Prefer to reduce the duplicated code

Option 1: refactor the with_fulltext_options method

    pub fn with_fulltext_options(mut self, options: FulltextOptions) -> Result<Self> {
        self. set_fulltext_options(options)?;
        Ok(self)
    }

Option 2: use the with_fulltext_options method

column_meta.column_schema = column_meta.column_schema.with_fulltext_options(fulltext)?;

src/sql/src/statements/alter.rs Outdated Show resolved Hide resolved
_ => {}
}
}
column_meta.column_schema.set_fulltext_options(fulltext).expect("set fulltext");
Copy link
Member

Choose a reason for hiding this comment

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

Handle the error

fulltext.enable = true;
fulltext.case_sensitive = false;
}
_ => {}
Copy link
Member

Choose a reason for hiding this comment

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

It's better to throw an error here. What will happen if the user sets the invalid full-text options while creating a table? @zhongzc

Copy link
Contributor

@zhongzc zhongzc Sep 9, 2024

Choose a reason for hiding this comment

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

will return error

return FulltextInvalidOptionSnafu {
    msg: format!("{analyzer}, expected: 'English' | 'Chinese'"),
}
.fail();

Comment on lines 623 to 652
if let Some(analyzer) = options.get(COLUMN_FULLTEXT_OPT_KEY_ANALYZER) {
match analyzer.to_ascii_lowercase().as_str() {
"english" => {
fulltext.enable = true;
fulltext.analyzer = FulltextAnalyzer::English;
}
"chinese" => {
fulltext.enable = true;
fulltext.analyzer = FulltextAnalyzer::Chinese;
}
_ => {
return error::InvalidFulltextOptionsSnafu { column_name }.fail()?;
}
}
}
if let Some(case_sensitive) = options.get(COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE) {
match case_sensitive.to_ascii_lowercase().as_str() {
"true" => {
fulltext.enable = true;
fulltext.case_sensitive = true;
}
"false" => {
fulltext.enable = true;
fulltext.case_sensitive = false;
}
_ => {
return error::InvalidFulltextOptionsSnafu { column_name }.fail()?;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

ditto, repeated code.

src/table/src/metadata.rs Outdated Show resolved Hide resolved
Comment on lines 81 to 113
if self.parser.parse_keyword(Keyword::SET) {
let _ = self.parser.parse_keyword(Keyword::FULLTEXT);

let options = self
.parser
.parse_options(Keyword::WITH)?
.into_iter()
.map(|option: SqlOption| -> Result<(String, String)> {
let (key, value) = (option.name, option.value);
let v = match value {
Expr::Value(sqlparser::ast::Value::SingleQuotedString(v))
| Expr::Value(sqlparser::ast::Value::DoubleQuotedString(v)) => v,
Expr::Identifier(v) => v.value,
Expr::Value(sqlparser::ast::Value::Number(v, _)) => v.to_string(),
_ => return error::InvalidTableOptionValueSnafu { key, value }.fail(),
};
let k = key.value.to_lowercase();
Ok((k, v))
})
.collect::<Result<HashMap<String, String>>>()
.unwrap();

AlterTableOperation::AlterColumnFulltext {
column_name,
options: options.into(),
}
} else {
let target_type = self.parser.parse_data_type()?;

AlterTableOperation::ChangeColumnType {
column_name,
target_type,
}
Copy link
Member

Choose a reason for hiding this comment

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

Add unit tests

@@ -588,6 +597,95 @@ impl TableMeta {
Ok(meta_builder)
}

fn change_column_fulltext(
Copy link
Member

@WenyXu WenyXu Sep 9, 2024

Choose a reason for hiding this comment

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

Do we have a way to add tests to verify it?

irenjj and others added 5 commits September 11, 2024 20:45
Co-authored-by: Weny Xu <wenymedia@gmail.com>
Co-authored-by: Weny Xu <wenymedia@gmail.com>
Copy link
Member

@WenyXu WenyXu left a comment

Choose a reason for hiding this comment

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

Some nitpicking

src/datatypes/src/schema.rs Outdated Show resolved Hide resolved
src/store-api/src/region_request.rs Outdated Show resolved Hide resolved
@WenyXu
Copy link
Member

WenyXu commented Sep 18, 2024

Hi @irenjj There are some conflicts 👀

Co-authored-by: Weny Xu <wenymedia@gmail.com>
Co-authored-by: Weny Xu <wenymedia@gmail.com>
@irenjj
Copy link
Collaborator Author

irenjj commented Sep 18, 2024

Hi @irenjj There are some conflicts 👀

yep, it's greptime.proto that conflicts, i'll merge it first when this pr is ready to merge.

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.

Good job. Left some comments. I'll start the alter table option work soon, feel free to engage if you're interested in that.

src/datatypes/src/schema/column_schema.rs Outdated Show resolved Hide resolved
src/datatypes/src/schema.rs Outdated Show resolved Hide resolved
src/store-api/src/metadata.rs Outdated Show resolved Hide resolved
src/store-api/src/region_request.rs Outdated Show resolved Hide resolved
src/table/src/metadata.rs Outdated Show resolved Hide resolved
column = column
.clone()
.with_fulltext_options(fulltext.clone())
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add the doc for the safety of unwrap here or handle the error

irenjj and others added 2 commits September 19, 2024 20:16
Co-authored-by: Lei, HUANG <6406592+v0y4g3r@users.noreply.github.com>
@github-actions github-actions bot added docs-required This change requires docs update. docs-not-required This change does not impact docs. and removed docs-not-required This change does not impact docs. docs-required This change requires docs update. labels Sep 20, 2024
@WenyXu
Copy link
Member

WenyXu commented Sep 20, 2024

I prefer to use the struct instead of a hashmap, then we don't need to validate the hashmap everywhere. cc @evenyag @zhongzc
GreptimeTeam/greptime-proto#185 (comment)

@evenyag
Copy link
Contributor

evenyag commented Sep 29, 2024

I prefer to use the struct instead of a hashmap, then we don't need to validate the hashmap everywhere. cc @evenyag @zhongzc GreptimeTeam/greptime-proto#185 (comment)

Looks good. We know the options in advance so I'd also suggest using a struct.

@killme2008
Copy link
Contributor

What's the status of this PR? @irenjj @WenyXu

@irenjj
Copy link
Collaborator Author

irenjj commented Oct 8, 2024

What's the status of this PR? @irenjj @WenyXu

I'll finish it this week as @WenyXu mentioned.

@WenyXu
Copy link
Member

WenyXu commented Oct 8, 2024

What's the status of this PR? @irenjj @WenyXu

I'll finish it this week as @WenyXu mentioned.

Many thanks ❤️!


pub fn set_fulltext_options(&mut self, options: &FulltextOptions) -> Result<()> {
if self.data_type != ConcreteDataType::string_datatype() {
return error::InvalidFulltextDataTypeSnafu {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add column name in error

Copy link
Member

Choose a reason for hiding this comment

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

So we can't disable the full-text index after creation?

Comment on lines 100 to 106
}) => AlterKind::ChangeFulltext {
column_name,
options: ChangeFulltextOptions {
enable,
analyzer,
case_sensitive,
},
Copy link
Member

Choose a reason for hiding this comment

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

add a new function under api::v1::column_def

/// Tries to construct a `ChangeFulltextOptions` from the given `ChangeFulltext`.
pub fn try_as_change_fulltext_options(
    ChangeFulltext {
        column_name,
        enable,
        analyzer,
        case_sensitive,
    }: &ChangeFulltext,
) -> Result<ChangeFulltextOptions> {
    let analyer = analyzer
        .map(|a| Analyzer::try_from(a))
        .transpose()
        .context(error::DecodeProto)?;
    Ok(ChangeFulltextOptions {
        enable: *enable,
        analyzer: analyzer,
        case_sensitive: *case_sensitive,
    })
}

and use it like

        }) => AlterKind::ChangeFulltext {
             column_name,
             options: column_def::try_as_change_fulltext_options(&change)?.context(...)

Comment on lines 419 to 471
impl TryFrom<HashMap<String, String>> for ChangeFulltextOptions {
type Error = Error;

fn try_from(options: HashMap<String, String>) -> Result<Self> {
let mut fulltext = ChangeFulltextOptions::default();

// Check and parse the "analyzer" option
if let Some(analyzer) = options.get(COLUMN_FULLTEXT_OPT_KEY_ANALYZER) {
match analyzer.to_ascii_lowercase().as_str() {
"english" => {
fulltext.enable = Some(true);
fulltext.analyzer = Some(0);
}
"chinese" => {
fulltext.enable = Some(true);
fulltext.analyzer = Some(1);
}
_ => {
// If the analyzer is invalid, return None to indicate failure
return error::InvalidFulltextOptionsSnafu {
key: COLUMN_FULLTEXT_OPT_KEY_ANALYZER.to_string(),
value: analyzer.to_string(),
}
.fail();
}
}
}

// Check and parse the "case_sensitive" option
if let Some(case_sensitive) = options.get(COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE) {
match case_sensitive.to_ascii_lowercase().as_str() {
"true" => {
fulltext.enable = Some(true);
fulltext.case_sensitive = Some(true);
}
"false" => {
fulltext.enable = Some(true);
fulltext.case_sensitive = Some(false);
}
_ => {
// If case sensitivity is invalid, return None
return error::InvalidFulltextOptionsSnafu {
key: COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE.to_string(),
value: case_sensitive.to_string(),
}
.fail();
}
}
}

Ok(fulltext)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

unused code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

used by let fulltext_options: ChangeFulltextOptions = match options.try_into() {...} to extract FulltextOptions from map.

Comment on lines 359 to 373
impl TryFrom<i32> for FulltextAnalyzer {
type Error = Error;

fn try_from(value: i32) -> Result<Self> {
match value {
0 => Ok(FulltextAnalyzer::English),
1 => Ok(FulltextAnalyzer::Chinese),
_ => Err(error::InvalidFulltextOptionsSnafu {
key: "analyzer".to_string(),
value: value.to_string(),
}
.build()),
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
impl TryFrom<i32> for FulltextAnalyzer {
type Error = Error;
fn try_from(value: i32) -> Result<Self> {
match value {
0 => Ok(FulltextAnalyzer::English),
1 => Ok(FulltextAnalyzer::Chinese),
_ => Err(error::InvalidFulltextOptionsSnafu {
key: "analyzer".to_string(),
value: value.to_string(),
}
.build()),
}
}
}

Comment on lines 375 to 380
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Visit, VisitMut, Default)]
pub struct ChangeFulltextOptions {
pub enable: Option<bool>,
pub analyzer: Option<i32>,
pub case_sensitive: Option<bool>,
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Visit, VisitMut, Default)]
pub struct ChangeFulltextOptions {
pub enable: Option<bool>,
pub analyzer: Option<i32>,
pub case_sensitive: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Visit, VisitMut, Default)]
pub struct ChangeFulltextOptions {
pub enable: Option<bool>,
pub analyzer: Option<FulltextAnalyzer>,
pub case_sensitive: Option<bool>,
}

Comment on lines 98 to 116
/// Tries to construct a `ChangeFulltextOptions` from the given `ChangeFulltext`.
pub fn try_as_change_fulltext_options(
ChangeFulltext {
enable,
analyzer,
case_sensitive,
..
}: &ChangeFulltext,
) -> Result<ChangeFulltextOptions> {
let _ = analyzer
.map(|a| Analyzer::try_from(a))
.transpose()
.context(error::DecodeProtoSnafu)?;
Ok(ChangeFulltextOptions {
enable: *enable,
analyzer: *analyzer,
case_sensitive: *case_sensitive,
})
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Tries to construct a `ChangeFulltextOptions` from the given `ChangeFulltext`.
pub fn try_as_change_fulltext_options(
ChangeFulltext {
enable,
analyzer,
case_sensitive,
..
}: &ChangeFulltext,
) -> Result<ChangeFulltextOptions> {
let _ = analyzer
.map(|a| Analyzer::try_from(a))
.transpose()
.context(error::DecodeProtoSnafu)?;
Ok(ChangeFulltextOptions {
enable: *enable,
analyzer: *analyzer,
case_sensitive: *case_sensitive,
})
}
/// Tries to construct a `FulltextAnalyzer` from the given `Analyzer`.
pub fn try_as_fulltext_option(analyzer: Option<i32>) -> Result<Option<FulltextAnalyzer>> {
let analyzer = analyzer
.map(Analyzer::try_from)
.transpose()
.context(error::DecodeProtoSnafu)?;
Ok(analyzer.map(|a| match a {
Analyzer::English => FulltextAnalyzer::English,
Analyzer::Chiniese => FulltextAnalyzer::Chinese,
}))
}
/// Tries to construct a `ChangeFulltextOptions` from the given `ChangeFulltext`.
pub fn try_as_change_fulltext_options(
ChangeFulltext {
enable,
analyzer,
case_sensitive,
..
}: &ChangeFulltext,
) -> Result<ChangeFulltextOptions> {
let analyzer = try_as_fulltext_option(*analyzer)?;
Ok(ChangeFulltextOptions {
enable: *enable,
analyzer,
case_sensitive: *case_sensitive,
})
}

Comment on lines 506 to 513
alter_request::Kind::ChangeFulltext(x) => AlterKind::ChangeColumnFulltext {
column_name: x.column_name,
options: ChangeFulltextOptions {
enable: x.enable,
analyzer: x.analyzer,
case_sensitive: x.case_sensitive,
},
},
Copy link
Member

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::ChangeFulltext(x) => AlterKind::ChangeColumnFulltext {
column_name: x.column_name,
options: ChangeFulltextOptions {
enable: x.enable,
analyzer: x.analyzer,
case_sensitive: x.case_sensitive,
},
},
alter_request::Kind::ChangeFulltext(x) => AlterKind::ChangeColumnFulltext {
column_name: x.column_name,
options: ChangeFulltextOptions {
enable: x.enable,
analyzer: column_def::try_as_fulltext_option(x.analyzer).context(..)?,
case_sensitive: x.case_sensitive,
},
},

Comment on lines 382 to 410
impl fmt::Display for ChangeFulltextOptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "fulltext options: ")?;

if let Some(enable) = self.enable {
write!(f, "enable={}", enable)?;
} else {
write!(f, "enable=None")?;
}

if let Some(analyzer) = self.analyzer {
if analyzer == 0 {
write!(f, ", analyzer=English")?;
} else {
write!(f, ", analyzer=Chinese")?;
}
} else {
write!(f, ", analyzer=None")?;
}

if let Some(case_sensitive) = self.case_sensitive {
write!(f, ", case_sensitive={}", case_sensitive)?;
} else {
write!(f, ", case_sensitive=None")?;
}

Ok(())
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
impl fmt::Display for ChangeFulltextOptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "fulltext options: ")?;
if let Some(enable) = self.enable {
write!(f, "enable={}", enable)?;
} else {
write!(f, "enable=None")?;
}
if let Some(analyzer) = self.analyzer {
if analyzer == 0 {
write!(f, ", analyzer=English")?;
} else {
write!(f, ", analyzer=Chinese")?;
}
} else {
write!(f, ", analyzer=None")?;
}
if let Some(case_sensitive) = self.case_sensitive {
write!(f, ", case_sensitive={}", case_sensitive)?;
} else {
write!(f, ", case_sensitive=None")?;
}
Ok(())
}
}
impl fmt::Display for ChangeFulltextOptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "fulltext options: ")?;
if let Some(enable) = self.enable {
write!(f, "enable={}", enable)?;
} else {
write!(f, "enable=None")?;
}
if let Some(analyzer) = &self.analyzer {
match analyzer {
FulltextAnalyzer::English => {
write!(f, ", analyzer=English")?;
}
FulltextAnalyzer::Chinese => {
write!(f, ", analyzer=Chinese")?;
}
}
} else {
write!(f, ", analyzer=None")?;
}
if let Some(case_sensitive) = self.case_sensitive {
write!(f, ", case_sensitive={}", case_sensitive)?;
} else {
write!(f, ", case_sensitive=None")?;
}
Ok(())
}
}

Copy link
Member

Choose a reason for hiding this comment

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

BTW, We can remove this

Comment on lines 486 to 494
AlterTableOperation::AlterColumnFulltext {
column_name,
options,
} => Kind::ChangeFulltext(ChangeFulltext {
column_name: column_name.value.to_string(),
enable: options.enable,
analyzer: options.analyzer,
case_sensitive: options.case_sensitive,
}),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AlterTableOperation::AlterColumnFulltext {
column_name,
options,
} => Kind::ChangeFulltext(ChangeFulltext {
column_name: column_name.value.to_string(),
enable: options.enable,
analyzer: options.analyzer,
case_sensitive: options.case_sensitive,
}),
AlterTableOperation::AlterColumnFulltext {
column_name,
options,
} => Kind::ChangeFulltext(ChangeFulltext {
column_name: column_name.value.to_string(),
enable: options.enable,
analyzer: match options.analyzer {
Some(FulltextAnalyzer::Chinese) => Some(Analyzer::Chiniese as i32),
Some(FulltextAnalyzer::English) => Some(Analyzer::English as i32),
None => None,
},
case_sensitive: options.case_sensitive,
}),

And the found a proto typo: Chiniese

@CookiePieWw
Copy link
Collaborator

Hi @irenjj , I‘ve noticed the pr is almost completed. If you're busy recently, I'd like to help to push forward this based on your great efforts :)

@irenjj
Copy link
Collaborator Author

irenjj commented Nov 4, 2024

Hi @irenjj , I‘ve noticed the pr is almost completed. If you're busy recently, I'd like to help to push forward this based on your great efforts :)

Sure, feel to continue this work, thank you! @CookiePieWw

@CookiePieWw CookiePieWw mentioned this pull request Nov 6, 2024
3 tasks
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.

Alter column option
7 participants