From ffc63efda39cd6ef525313b60ede061c5ec24b12 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Wed, 22 Jan 2025 14:42:11 +0800 Subject: [PATCH] fix: flash table panic when table has interval column close #3235 Signed-off-by: yihong0618 --- src/operator/src/error.rs | 8 ++++++++ src/operator/src/statement/ddl.rs | 8 ++++++++ .../standalone/common/alter/alter_table.result | 14 ++++++++++++++ .../cases/standalone/common/alter/alter_table.sql | 7 +++++++ 4 files changed, 37 insertions(+) diff --git a/src/operator/src/error.rs b/src/operator/src/error.rs index 3a5aae897399..6f754cc6d92f 100644 --- a/src/operator/src/error.rs +++ b/src/operator/src/error.rs @@ -223,6 +223,13 @@ pub enum Error { #[snafu(display("Table not found: {}", table_name))] TableNotFound { table_name: String }, + #[snafu(display("Table: {} can not alter because it has interval datatype", table_name))] + TableCanNotAlter { + table_name: String, + #[snafu(implicit)] + location: Location, + }, + #[snafu(display("Admin function not found: {}", name))] AdminFunctionNotFound { name: String }, @@ -807,6 +814,7 @@ impl ErrorExt for Error { | Error::SchemaNotFound { .. } | Error::SchemaExists { .. } | Error::SchemaInUse { .. } + | Error::TableCanNotAlter { .. } | Error::ColumnNotFound { .. } | Error::BuildRegex { .. } | Error::InvalidSchema { .. } diff --git a/src/operator/src/statement/ddl.rs b/src/operator/src/statement/ddl.rs index 23cba11de8da..acbed25a875d 100644 --- a/src/operator/src/statement/ddl.rs +++ b/src/operator/src/statement/ddl.rs @@ -990,6 +990,14 @@ impl StatementExecutor { table_name: format_full_table_name(&catalog_name, &schema_name, &table_name), })?; + // for issue #3235 early error if the table has interval column + // FIXME: drop the check when arrow support interval type + for field in table.schema().column_schemas() { + if matches!(field.data_type.clone(), ConcreteDataType::Interval(_)) { + return error::TableCanNotAlterSnafu { table_name }.fail(); + } + } + let table_id = table.table_info().ident.table_id; let need_alter = self.verify_alter(table_id, table.table_info(), expr.clone())?; if !need_alter { diff --git a/tests/cases/standalone/common/alter/alter_table.result b/tests/cases/standalone/common/alter/alter_table.result index 5c1dbfca77a8..78bf5b0a9bf3 100644 --- a/tests/cases/standalone/common/alter/alter_table.result +++ b/tests/cases/standalone/common/alter/alter_table.result @@ -165,6 +165,16 @@ FROM | loc_1 | loc_2 | loc_3 | 2 | job1 | 1970-01-01T00:00:00 | 1.0 | +-------+-------+-------+-----+------+---------------------+-----+ +-- issue #3235 can not alter when table has column with tyep interval +create table t3(val interval, ts timestamp time index); + +Affected Rows: 0 + +-- should fail with error +alter table t3 add column label varchar; + +Error: 1004(InvalidArguments), Table: t3 can not alter because it has interval datatype + DROP TABLE t1; Affected Rows: 0 @@ -173,6 +183,10 @@ DROP TABLE t2; Affected Rows: 0 +DROP TABLE t3; + +Affected Rows: 0 + DROP TABLE phy; Affected Rows: 0 diff --git a/tests/cases/standalone/common/alter/alter_table.sql b/tests/cases/standalone/common/alter/alter_table.sql index c52a2445db42..d7b74477da56 100644 --- a/tests/cases/standalone/common/alter/alter_table.sql +++ b/tests/cases/standalone/common/alter/alter_table.sql @@ -82,8 +82,15 @@ SELECT FROM t2; +-- issue #3235 can not alter when table has column with tyep interval +create table t3(val interval, ts timestamp time index); +-- should fail with error +alter table t3 add column label varchar; + DROP TABLE t1; DROP TABLE t2; +DROP TABLE t3; + DROP TABLE phy;