mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-25 09:20:40 +00:00
chore: allow numberic values in alter statements (#6252)
chore/allow-numberic-values-in-alter: ### Commit Message Enhance `alter_parser.rs` to Support Numeric Values - Updated `parse_string_options` function in `alter_parser.rs` to handle numeric literals in addition to string literals and `NULL` for alter table statements. - Added a new test `test_parse_alter_with_numeric_value` in `alter_parser.rs` to verify the parsing of numeric values in alter table options.
This commit is contained in:
@@ -391,13 +391,16 @@ fn parse_string_options(parser: &mut Parser) -> std::result::Result<(String, Str
|
||||
parser.expect_token(&Token::Eq)?;
|
||||
let value = if parser.parse_keyword(Keyword::NULL) {
|
||||
"".to_string()
|
||||
} else if let Ok(v) = parser.parse_literal_string() {
|
||||
v
|
||||
} else {
|
||||
return Err(ParserError::ParserError(format!(
|
||||
"Unexpected option value for alter table statements, expect string literal or NULL, got: `{}`",
|
||||
parser.next_token()
|
||||
)));
|
||||
let next_token = parser.peek_token();
|
||||
if let Token::Number(number_as_string, _) = next_token.token {
|
||||
parser.advance_token();
|
||||
number_as_string
|
||||
} else {
|
||||
parser.parse_literal_string().map_err(|_|{
|
||||
ParserError::ParserError(format!("Unexpected option value for alter table statements, expect string literal, numeric literal or NULL, got: `{}`", next_token))
|
||||
})?
|
||||
}
|
||||
};
|
||||
Ok((name, value))
|
||||
}
|
||||
@@ -1088,4 +1091,38 @@ mod tests {
|
||||
)
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_alter_with_numeric_value() {
|
||||
for sql in [
|
||||
"ALTER TABLE test SET 'compaction.twcs.trigger_file_num'=8;",
|
||||
"ALTER TABLE test SET 'compaction.twcs.trigger_file_num'='8';",
|
||||
] {
|
||||
let mut result = ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(alter_operation, AlterTableOperation::SetTableOptions { .. });
|
||||
match alter_operation {
|
||||
AlterTableOperation::SetTableOptions { options } => {
|
||||
assert_eq!(options.len(), 1);
|
||||
assert_eq!(options[0].key, "compaction.twcs.trigger_file_num");
|
||||
assert_eq!(options[0].value, "8");
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user