From c75845c570ab3c7ddd34704cea84d575707bbd15 Mon Sep 17 00:00:00 2001 From: Zheming Li Date: Sun, 23 Apr 2023 11:25:38 +0800 Subject: [PATCH] fix: wrong next column in manifest (#1440) Signed-off-by: Zheming Li --- src/mito/src/table.rs | 6 +-- .../distributed/alter/alter_table.result | 46 ++++++++++++++++++ tests/cases/distributed/alter/alter_table.sql | 13 +++++ .../cases/standalone/alter/alter_table.result | 47 +++++++++++++++++++ tests/cases/standalone/alter/alter_table.sql | 14 ++++++ 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 tests/cases/distributed/alter/alter_table.result create mode 100644 tests/cases/distributed/alter/alter_table.sql create mode 100644 tests/cases/standalone/alter/alter_table.result create mode 100644 tests/cases/standalone/alter/alter_table.sql diff --git a/src/mito/src/table.rs b/src/mito/src/table.rs index eecb74ac08..ae4a99f6ae 100644 --- a/src/mito/src/table.rs +++ b/src/mito/src/table.rs @@ -241,6 +241,8 @@ impl Table for MitoTable { new_info.meta = new_meta; } } + // Do create_alter_operation first to bump next_column_id in meta. + let alter_op = create_alter_operation(table_name, &req.alter_kind, &mut new_info.meta)?; // Increase version of the table. new_info.ident.version = table_info.ident.version + 1; @@ -263,9 +265,7 @@ impl Table for MitoTable { .map_err(BoxedError::new) .context(table_error::TableOperationSnafu)?; - if let Some(alter_op) = - create_alter_operation(table_name, &req.alter_kind, &mut new_info.meta)? - { + if let Some(alter_op) = alter_op { // TODO(yingwen): Error handling. Maybe the region need to provide a method to // validate the request first. let regions = self.regions(); diff --git a/tests/cases/distributed/alter/alter_table.result b/tests/cases/distributed/alter/alter_table.result new file mode 100644 index 0000000000..36269aad5c --- /dev/null +++ b/tests/cases/distributed/alter/alter_table.result @@ -0,0 +1,46 @@ +CREATE TABLE t(i INTEGER, j BIGINT TIME INDEX); + +Affected Rows: 0 + +DESC TABLE t; + ++-------+-------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-------+-------+------+---------+---------------+ +| i | Int32 | YES | | FIELD | +| j | Int64 | NO | | TIME INDEX | ++-------+-------+------+---------+---------------+ + +ALTER TABLE t ADD COLUMN k INTEGER; + +Affected Rows: 0 + +DESC TABLE t; + ++-------+-------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-------+-------+------+---------+---------------+ +| i | Int32 | YES | | FIELD | +| j | Int64 | NO | | TIME INDEX | +| k | Int32 | YES | | FIELD | ++-------+-------+------+---------+---------------+ + +ALTER TABLE t ADD COLUMN m INTEGER; + +Affected Rows: 0 + +DESC TABLE t; + ++-------+-------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-------+-------+------+---------+---------------+ +| i | Int32 | YES | | FIELD | +| j | Int64 | NO | | TIME INDEX | +| k | Int32 | YES | | FIELD | +| m | Int32 | YES | | FIELD | ++-------+-------+------+---------+---------------+ + +DROP TABLE t; + +Affected Rows: 1 + diff --git a/tests/cases/distributed/alter/alter_table.sql b/tests/cases/distributed/alter/alter_table.sql new file mode 100644 index 0000000000..66c217743d --- /dev/null +++ b/tests/cases/distributed/alter/alter_table.sql @@ -0,0 +1,13 @@ +CREATE TABLE t(i INTEGER, j BIGINT TIME INDEX); + +DESC TABLE t; + +ALTER TABLE t ADD COLUMN k INTEGER; + +DESC TABLE t; + +ALTER TABLE t ADD COLUMN m INTEGER; + +DESC TABLE t; + +DROP TABLE t; diff --git a/tests/cases/standalone/alter/alter_table.result b/tests/cases/standalone/alter/alter_table.result new file mode 100644 index 0000000000..d213ab8a56 --- /dev/null +++ b/tests/cases/standalone/alter/alter_table.result @@ -0,0 +1,47 @@ +CREATE TABLE t(i INTEGER, j BIGINT TIME INDEX); + +Affected Rows: 0 + +DESC TABLE t; + ++-------+-------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-------+-------+------+---------+---------------+ +| i | Int32 | YES | | FIELD | +| j | Int64 | NO | | TIME INDEX | ++-------+-------+------+---------+---------------+ + +ALTER TABLE t ADD COLUMN k INTEGER; + +Affected Rows: 0 + +DESC TABLE t; + ++-------+-------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-------+-------+------+---------+---------------+ +| i | Int32 | YES | | FIELD | +| j | Int64 | NO | | TIME INDEX | +| k | Int32 | YES | | FIELD | ++-------+-------+------+---------+---------------+ + +-- SQLNESS ARG restart=true +ALTER TABLE t ADD COLUMN m INTEGER; + +Affected Rows: 0 + +DESC TABLE t; + ++-------+-------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-------+-------+------+---------+---------------+ +| i | Int32 | YES | | FIELD | +| j | Int64 | NO | | TIME INDEX | +| k | Int32 | YES | | FIELD | +| m | Int32 | YES | | FIELD | ++-------+-------+------+---------+---------------+ + +DROP TABLE t; + +Affected Rows: 1 + diff --git a/tests/cases/standalone/alter/alter_table.sql b/tests/cases/standalone/alter/alter_table.sql new file mode 100644 index 0000000000..46165625dc --- /dev/null +++ b/tests/cases/standalone/alter/alter_table.sql @@ -0,0 +1,14 @@ +CREATE TABLE t(i INTEGER, j BIGINT TIME INDEX); + +DESC TABLE t; + +ALTER TABLE t ADD COLUMN k INTEGER; + +DESC TABLE t; + +-- SQLNESS ARG restart=true +ALTER TABLE t ADD COLUMN m INTEGER; + +DESC TABLE t; + +DROP TABLE t;