mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-18 09:52:27 +00:00
feat(json2): support ALTER syntax for JSON column settings (#9094)
feat(json2): support alter syntax for JSON2 columns Signed-off-by: fys <fengys1996@gmail.com> This is the commit message #3:
This commit is contained in:
@@ -826,9 +826,16 @@ pub(crate) fn to_alter_table_expr(
|
||||
AlterTableOperation::ModifyColumnType {
|
||||
column_name,
|
||||
target_type,
|
||||
..
|
||||
} => {
|
||||
let target_type =
|
||||
sql_data_type_to_concrete_data_type(&target_type).context(ParseSqlSnafu)?;
|
||||
if target_type.is_json2() {
|
||||
return NotSupportedSnafu {
|
||||
feat: "ALTER TABLE MODIFY COLUMN to JSON2 type",
|
||||
}
|
||||
.fail();
|
||||
}
|
||||
let (target_type, target_type_extension) = ColumnDataTypeWrapper::try_from(target_type)
|
||||
.map(|w| w.to_parts())
|
||||
.context(ColumnDataTypeSnafu)?;
|
||||
@@ -1744,6 +1751,34 @@ SELECT max(c1), min(c2) FROM schema_2.table_2;";
|
||||
assert!(modify_column_type.target_type_extension.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_alter_json2_is_not_supported() {
|
||||
for sql in [
|
||||
"ALTER TABLE monitor MODIFY COLUMN payload JSON2;",
|
||||
"ALTER TABLE monitor MODIFY COLUMN payload JSON2 (service STRING);",
|
||||
] {
|
||||
let stmt = ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default(),
|
||||
)
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap();
|
||||
|
||||
let Statement::AlterTable(alter_table) = stmt else {
|
||||
unreachable!()
|
||||
};
|
||||
let err = to_alter_table_expr(alter_table, &QueryContext::arc()).unwrap_err();
|
||||
|
||||
assert!(matches!(err, crate::error::Error::NotSupported { .. }));
|
||||
assert_eq!(
|
||||
"Not supported: ALTER TABLE MODIFY COLUMN to JSON2 type",
|
||||
err.to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_repartition_request() {
|
||||
let sql = r#"
|
||||
|
||||
Reference in New Issue
Block a user