mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-29 23:16:57 +00:00
fix(json2): support settings in ALTER TABLE ADD COLUMN (#9472)
* fix(json2): support settings in ALTER TABLE ADD COLUMN Signed-off-by: fys <fengys1996@gmail.com> * refactor(sql): reuse Column for ADD COLUMN definitions Signed-off-by: fys <fengys1996@gmail.com> * chore: better method name * refactor(sql): share column parsing between CREATE TABLE and ADD COLUMN Signed-off-by: fys <fengys1996@gmail.com> * chore: simplify tests Signed-off-by: fys <fengys1996@gmail.com> * fix(sql): accept trailing commas in ALTER TABLE ADD COLUMN Signed-off-by: fys <fengys1996@gmail.com> * fix(sql): preserve ALTER TABLE ADD COLUMN compatibility Signed-off-by: fys <fengys1996@gmail.com> --------- Signed-off-by: fys <fengys1996@gmail.com>
This commit is contained in:
@@ -150,3 +150,90 @@ DROP TABLE application_logs;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
create table json2_alter_add_settings (
|
||||
ts timestamp time index
|
||||
) with (
|
||||
'append_mode' = 'true'
|
||||
);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
-- ADD COLUMN preserves JSON2 settings and type hints, including for existing rows.
|
||||
insert into json2_alter_add_settings values (1);
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
alter table json2_alter_add_settings add column j json2(max_auto_expanded_paths = 100);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
alter table json2_alter_add_settings add column k json2(service string);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
alter table json2_alter_add_settings add column m json2(max_auto_expanded_paths = 0, nested.value bigint);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
show create table json2_alter_add_settings;
|
||||
|
||||
+--------------------------+---------------------------------------------------------+
|
||||
| Table | Create Table |
|
||||
+--------------------------+---------------------------------------------------------+
|
||||
| json2_alter_add_settings | CREATE TABLE IF NOT EXISTS "json2_alter_add_settings" ( |
|
||||
| | "ts" TIMESTAMP(3) NOT NULL, |
|
||||
| | "j" JSON2( |
|
||||
| | max_auto_expanded_paths = 100 |
|
||||
| | ) NULL, |
|
||||
| | "k" JSON2( |
|
||||
| | max_auto_expanded_paths = 100, |
|
||||
| | "service" STRING |
|
||||
| | ) NULL, |
|
||||
| | "m" JSON2( |
|
||||
| | max_auto_expanded_paths = 0, |
|
||||
| | "nested"."value" BIGINT |
|
||||
| | ) NULL, |
|
||||
| | TIME INDEX ("ts") |
|
||||
| | ) |
|
||||
| | |
|
||||
| | ENGINE=mito |
|
||||
| | WITH( |
|
||||
| | append_mode = 'true' |
|
||||
| | ) |
|
||||
+--------------------------+---------------------------------------------------------+
|
||||
|
||||
insert into json2_alter_add_settings values
|
||||
(2, '{"a":1}', '{"service":"api"}', '{"nested":{"value":42},"extra":true}');
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
select ts, j, k.service, m.nested.value, m from json2_alter_add_settings order by ts;
|
||||
|
||||
+-------------------------+---------+-----------------------------------------------------------------------+-------------------------------------------------------------------------+--------------------------------------+
|
||||
| ts | j | json_get(json2_alter_add_settings.k,Utf8("$.service"),Utf8View(NULL)) | json_get(json2_alter_add_settings.m,Utf8("$.nested.value"),Int64(NULL)) | m |
|
||||
+-------------------------+---------+-----------------------------------------------------------------------+-------------------------------------------------------------------------+--------------------------------------+
|
||||
| 1970-01-01T00:00:00.001 | | | | |
|
||||
| 1970-01-01T00:00:00.002 | {"a":1} | api | 42 | {"extra":true,"nested":{"value":42}} |
|
||||
+-------------------------+---------+-----------------------------------------------------------------------+-------------------------------------------------------------------------+--------------------------------------+
|
||||
|
||||
admin flush_table('json2_alter_add_settings');
|
||||
|
||||
+-----------------------------------------------+
|
||||
| ADMIN flush_table('json2_alter_add_settings') |
|
||||
+-----------------------------------------------+
|
||||
| 0 |
|
||||
+-----------------------------------------------+
|
||||
|
||||
select ts, j, k.service, m.nested.value, m from json2_alter_add_settings order by ts;
|
||||
|
||||
+-------------------------+---------+-----------------------------------------------------------------------+-------------------------------------------------------------------------+--------------------------------------+
|
||||
| ts | j | json_get(json2_alter_add_settings.k,Utf8("$.service"),Utf8View(NULL)) | json_get(json2_alter_add_settings.m,Utf8("$.nested.value"),Int64(NULL)) | m |
|
||||
+-------------------------+---------+-----------------------------------------------------------------------+-------------------------------------------------------------------------+--------------------------------------+
|
||||
| 1970-01-01T00:00:00.001 | | | | |
|
||||
| 1970-01-01T00:00:00.002 | {"a":1} | api | 42 | {"extra":true,"nested":{"value":42}} |
|
||||
+-------------------------+---------+-----------------------------------------------------------------------+-------------------------------------------------------------------------+--------------------------------------+
|
||||
|
||||
drop table json2_alter_add_settings;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
|
||||
@@ -74,3 +74,30 @@ ORDER BY ts;
|
||||
ADMIN FLUSH_TABLE('application_logs');
|
||||
|
||||
DROP TABLE application_logs;
|
||||
|
||||
create table json2_alter_add_settings (
|
||||
ts timestamp time index
|
||||
) with (
|
||||
'append_mode' = 'true'
|
||||
);
|
||||
|
||||
-- ADD COLUMN preserves JSON2 settings and type hints, including for existing rows.
|
||||
insert into json2_alter_add_settings values (1);
|
||||
alter table json2_alter_add_settings add column j json2(max_auto_expanded_paths = 100);
|
||||
|
||||
alter table json2_alter_add_settings add column k json2(service string);
|
||||
|
||||
alter table json2_alter_add_settings add column m json2(max_auto_expanded_paths = 0, nested.value bigint);
|
||||
|
||||
show create table json2_alter_add_settings;
|
||||
|
||||
insert into json2_alter_add_settings values
|
||||
(2, '{"a":1}', '{"service":"api"}', '{"nested":{"value":42},"extra":true}');
|
||||
|
||||
select ts, j, k.service, m.nested.value, m from json2_alter_add_settings order by ts;
|
||||
|
||||
admin flush_table('json2_alter_add_settings');
|
||||
|
||||
select ts, j, k.service, m.nested.value, m from json2_alter_add_settings order by ts;
|
||||
|
||||
drop table json2_alter_add_settings;
|
||||
|
||||
@@ -95,27 +95,6 @@ drop table json2_alter_non_append;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
create table json2_alter_add_settings (
|
||||
ts timestamp time index
|
||||
) with (
|
||||
'append_mode' = 'true'
|
||||
);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
-- ALTER TABLE ADD COLUMN does not yet support JSON2 settings or type hints.
|
||||
alter table json2_alter_add_settings add column j json2(max_auto_expanded_paths = 100);
|
||||
|
||||
Error: 2000(InvalidSyntax), Invalid SQL syntax: sql parser error: Expected: type modifiers, found: = at Line: 1, Column: 81
|
||||
|
||||
alter table json2_alter_add_settings add column k json2(service string);
|
||||
|
||||
Error: 2000(InvalidSyntax), SQL data type not supported yet: Custom(ObjectName([Identifier(Ident { value: "json2", quote_style: None, span: Span(Location(1,51)..Location(1,56)) })]), ["service", "string"])
|
||||
|
||||
drop table json2_alter_add_settings;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
create table json2_set_append_mode_false (
|
||||
ts timestamp time index,
|
||||
j json2
|
||||
|
||||
@@ -58,19 +58,6 @@ alter table json2_alter_non_append add column j json2;
|
||||
|
||||
drop table json2_alter_non_append;
|
||||
|
||||
create table json2_alter_add_settings (
|
||||
ts timestamp time index
|
||||
) with (
|
||||
'append_mode' = 'true'
|
||||
);
|
||||
|
||||
-- ALTER TABLE ADD COLUMN does not yet support JSON2 settings or type hints.
|
||||
alter table json2_alter_add_settings add column j json2(max_auto_expanded_paths = 100);
|
||||
|
||||
alter table json2_alter_add_settings add column k json2(service string);
|
||||
|
||||
drop table json2_alter_add_settings;
|
||||
|
||||
create table json2_set_append_mode_false (
|
||||
ts timestamp time index,
|
||||
j json2
|
||||
|
||||
Reference in New Issue
Block a user