Skip to content

Commit

Permalink
test: more failed cases for modify_col.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Apr 14, 2024
1 parent de0dfee commit 21d6d16
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/sql/src/parsers/alter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ mod tests {
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
.unwrap_err();
let err = result.output_msg();
assert!(err.contains("expect keyword ADD or DROP or ALERT COLUMN or RENAME after ALTER TABLE"));
assert!(
err.contains("expect keyword ADD or DROP or ALERT COLUMN or RENAME after ALTER TABLE")
);

let sql = "ALTER TABLE test_table RENAME table_t";
let mut result =
Expand Down
32 changes: 21 additions & 11 deletions tests/cases/standalone/common/alter/modify_col.result
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
CREATE TABLE test(i INTEGER, j TIMESTAMP TIME INDEX);
CREATE TABLE test(id INTEGER PRIMARY KEY, i INTEGER, j TIMESTAMP TIME INDEX, k BOOLEAN);

Affected Rows: 0

INSERT INTO test VALUES (1, 1), (2, 2);
INSERT INTO test VALUES (1, 1, 1, false), (2, 2, 2, true);

Affected Rows: 2

ALTER TABLE test ALTER COLUMN "I" TYPE STRING;

Error: 4002(TableColumnNotFound), Column I not exists in table test

ALTER TABLE test ALTER COLUMN I TYPE STRING;
ALTER TABLE test ALTER COLUMN k TYPE DATE;

Affected Rows: 0
Error: 1004(InvalidArguments), Invalid alter table(test) request: column 'k' cannot be cast automatically to type 'Date'

SELECT * FROM test;
ALTER TABLE test ALTER COLUMN id TYPE STRING;

+---+-------------------------+
| i | j |
+---+-------------------------+
| 1 | 1970-01-01T00:00:00.001 |
| 2 | 1970-01-01T00:00:00.002 |
+---+-------------------------+
Error: 1004(InvalidArguments), Not allowed to modify index column id from table test

ALTER TABLE test ALTER COLUMN j TYPE STRING;

Error: 1004(InvalidArguments), Not allowed to modify index column j from table test

ALTER TABLE test ALTER COLUMN I TYPE STRING;

Affected Rows: 0

SELECT * FROM test;

+----+---+-------------------------+-------+
| id | i | j | k |
+----+---+-------------------------+-------+
| 1 | 1 | 1970-01-01T00:00:00.001 | false |
| 2 | 2 | 1970-01-01T00:00:00.002 | true |
+----+---+-------------------------+-------+

DESCRIBE test;

+--------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+--------+----------------------+-----+------+---------+---------------+
| id | Int32 | PRI | YES | | TAG |
| i | String | | YES | | FIELD |
| j | TimestampMillisecond | PRI | NO | | TIMESTAMP |
| k | Boolean | | YES | | FIELD |
+--------+----------------------+-----+------+---------+---------------+

DROP TABLE test;
Expand Down
14 changes: 9 additions & 5 deletions tests/cases/standalone/common/alter/modify_col.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
CREATE TABLE test(i INTEGER, j TIMESTAMP TIME INDEX);
CREATE TABLE test(id INTEGER PRIMARY KEY, i INTEGER, j TIMESTAMP TIME INDEX, k BOOLEAN);

INSERT INTO test VALUES (1, 1), (2, 2);
INSERT INTO test VALUES (1, 1, 1, false), (2, 2, 2, true);

ALTER TABLE test ALTER COLUMN "I" TYPE STRING;

ALTER TABLE test ALTER COLUMN I TYPE STRING;
ALTER TABLE test ALTER COLUMN k TYPE DATE;

SELECT * FROM test;
ALTER TABLE test ALTER COLUMN id TYPE STRING;

ALTER TABLE test ALTER COLUMN j TYPE STRING;

ALTER TABLE test ALTER COLUMN I TYPE STRING;

SELECT * FROM test;

DESCRIBE test;

DROP TABLE test;
DROP TABLE test;
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ SELECT * FROM test;

DESCRIBE test;

DROP TABLE test;
DROP TABLE test;

0 comments on commit 21d6d16

Please sign in to comment.