Skip to content

Commit

Permalink
fix: flash table panic when table has interval column close #3235
Browse files Browse the repository at this point in the history
Signed-off-by: yihong0618 <[email protected]>
  • Loading branch information
yihong0618 committed Jan 22, 2025
1 parent d2f3f2e commit ffc63ef
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/operator/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },

Expand Down Expand Up @@ -807,6 +814,7 @@ impl ErrorExt for Error {
| Error::SchemaNotFound { .. }
| Error::SchemaExists { .. }
| Error::SchemaInUse { .. }
| Error::TableCanNotAlter { .. }
| Error::ColumnNotFound { .. }
| Error::BuildRegex { .. }
| Error::InvalidSchema { .. }
Expand Down
8 changes: 8 additions & 0 deletions src/operator/src/statement/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions tests/cases/standalone/common/alter/alter_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -173,6 +183,10 @@ DROP TABLE t2;

Affected Rows: 0

DROP TABLE t3;

Affected Rows: 0

DROP TABLE phy;

Affected Rows: 0
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/standalone/common/alter/alter_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit ffc63ef

Please sign in to comment.