Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lyang24 committed Dec 1, 2024
1 parent c049ce6 commit 7a59359
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/common/meta/src/ddl/alter_table/update_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ impl AlterTableProcedure {
| AlterKind::SetTableOptions { .. }
| AlterKind::UnsetTableOptions { .. }
| AlterKind::SetColumnFulltext { .. }
| AlterKind::UnsetColumnFulltext { .. } => {}
| AlterKind::UnsetColumnFulltext { .. }
| AlterKind::SetColumnInvertedIndex { .. }
| AlterKind::UnsetColumnInvertedIndex { .. } => {}
}

Ok(new_info)
Expand Down
16 changes: 16 additions & 0 deletions src/operator/src/expr_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,22 @@ pub(crate) fn to_alter_table_expr(
},
case_sensitive: options.case_sensitive,
}),
AlterTableOperation::UnsetColumnFulltext { column_name } => {
AlterTableKind::UnsetColumnFulltext(UnsetColumnFulltext {
column_name: column_name.value,
})
},
AlterTableOperation::SetColumnInvertedIndex {
column_name,
} => AlterTableKind::SetColumnFulltext(SetColumnFulltext {
column_name: column_name.value,
enable: options.enable,
analyzer: match options.analyzer {
FulltextAnalyzer::English => Analyzer::English.into(),
FulltextAnalyzer::Chinese => Analyzer::Chinese.into(),
},
case_sensitive: options.case_sensitive,
}),
AlterTableOperation::UnsetColumnFulltext { column_name } => {
AlterTableKind::UnsetColumnFulltext(UnsetColumnFulltext {
column_name: column_name.value,
Expand Down
30 changes: 22 additions & 8 deletions src/sql/src/parsers/alter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use snafu::{ensure, ResultExt};
use sqlparser::ast::Ident;
use sqlparser::keywords::Keyword;
use sqlparser::parser::{Parser, ParserError};
use sqlparser::tokenizer::Token;
use sqlparser::tokenizer::{Token, TokenWithLocation};

use crate::error::{self, InvalidColumnOptionSnafu, Result, SetFulltextOptionSnafu};
use crate::parser::ParserContext;
Expand All @@ -31,6 +31,8 @@ use crate::statements::alter::{
use crate::statements::statement::Statement;
use crate::util::parse_option_string;

use super::create_parser::INVERTED;

impl ParserContext<'_> {
pub(crate) fn parse_alter(&mut self) -> Result<Statement> {
let _ = self.parser.expect_keyword(Keyword::ALTER);
Expand Down Expand Up @@ -226,13 +228,25 @@ impl ParserContext<'_> {
match self.parser.peek_token().token {
Token::Word(w) => {
if w.value.eq_ignore_ascii_case("UNSET") {
let _ = self.parser.next_token();

self.parser
.expect_keyword(Keyword::FULLTEXT)
.context(error::SyntaxSnafu)?;

Ok(AlterTableOperation::UnsetColumnFulltext { column_name })
match self.parser.next_token() {
TokenWithLocation {
token: Token::Word(w),
..
} if w.keyword == Keyword::FULLTEXT => {
Ok(AlterTableOperation::UnsetColumnFulltext { column_name })
},

TokenWithLocation {
token: Token::Word(w),
..
} if w.value.eq_ignore_ascii_case(INVERTED)=> {
self.parser.expect_keyword(Keyword::INDEX).context(error::SyntaxSnafu)?;
Ok(AlterTableOperation::UnsetColumnInvertedIndex { column_name })
},
_ => {
self.expected(format!("{:?}", Keyword::FULLTEXT).as_str(), self.parser.peek_token())
}
}
} else if w.keyword == Keyword::SET {
self.parse_alter_column_fulltext(column_name)
} else {
Expand Down
17 changes: 17 additions & 0 deletions src/sql/src/statements/alter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ pub enum AlterTableOperation {
UnsetColumnFulltext {
column_name: Ident,
},
/// `MODIFY COLUMN <column_name> SET INVERTED INDEX`
SetColumnInvertedIndex {
column_name: Ident,
},
/// `MODIFY COLUMN <column_name> UNSET INVERTED INDEX`
UnsetColumnInvertedIndex {
column_name: Ident,
},

}

impl Display for AlterTableOperation {
Expand Down Expand Up @@ -147,6 +156,14 @@ impl Display for AlterTableOperation {
AlterTableOperation::UnsetColumnFulltext { column_name } => {
write!(f, "MODIFY COLUMN {column_name} UNSET FULLTEXT")
}
AlterTableOperation::SetColumnInvertedIndex {
column_name,
} => {
write!(f, "MODIFY COLUMN {column_name} SET INVERTED INDEX")
}
AlterTableOperation::UnsetColumnInvertedIndex { column_name } => {
write!(f, "MODIFY COLUMN {column_name} UNSET INVERTED INDEX")
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/table/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ pub enum AlterKind {
UnsetColumnFulltext {
column_name: String,
},
SetColumnInvertedIndex {
column_name: String,
},
UnsetColumnInvertedIndex {
column_name: String,
},
}

#[derive(Debug)]
Expand Down

0 comments on commit 7a59359

Please sign in to comment.