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:
fys
2026-09-10 10:33:41 +00:00
committed by GitHub
parent 0f625a7e92
commit 536f42e4a2
8 changed files with 210 additions and 6 deletions
+35
View File
@@ -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#"