Skip to content

Commit 86f9e5f

Browse files
authored
feat: add support UUID type (#239)
fixes #238
1 parent cd1dabf commit 86f9e5f

7 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcolumn_type.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public String toString() {
5555
case "DATE":
5656
case "NUMERIC":
5757
case "JSON":
58+
case "UUID":
5859
case "TOKENLIST":
5960
return typeName;
6061
case "STRING":

src/test/java/com/google/cloud/solutions/spannerddl/diff/DdlDiffTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ public void generateAlterTable_incompatibleTypeChange() {
267267
"create table test1 (col1 float64) primary key (col1);",
268268
true,
269269
"Cannot change type of table test1 column col1");
270+
271+
// change type to UUID
272+
getDiffCheckDdlDiffException(
273+
"create table test1 (col1 int64, col2 int64) primary key (col1);",
274+
"create table test1 (col1 int64, col2 uuid) primary key (col1);",
275+
true,
276+
"Cannot change type of table test1 column col2");
277+
278+
// change STRING(36) to UUID
279+
getDiffCheckDdlDiffException(
280+
"create table test1 (col1 int64, col2 string(36)) primary key (col1);",
281+
"create table test1 (col1 int64, col2 uuid) primary key (col1);",
282+
true,
283+
"Cannot change type of table test1 column col2");
270284
}
271285

272286
@Test

src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void parseCreateTable() throws ParseException {
3636
+ " (\"prefix\" || sizedstring || \"suffix\"), sizedbytes bytes(55),"
3737
+ " maxbytes bytes(max), datecol date, timestampcol timestamp options"
3838
+ " (allow_commit_timestamp = true), intarray array<int64>, numericcol"
39-
+ " numeric,jsoncol json, pgcolumn pg.something, generatedcol string(max)"
39+
+ " numeric,jsoncol json, uuidcol uuid, pgcolumn pg.something, generatedcol string(max)"
4040
+ " as (sizedstring+"
4141
+ " strstr(maxstring,strpos(maxstring,'xxx'),length(maxstring)) +2.0)"
4242
+ " STORED, constraint fk_col_remote FOREIGN KEY(col1, col2) REFERENCES"
@@ -68,6 +68,7 @@ public void parseCreateTable() throws ParseException {
6868
+ " intarray ARRAY<INT64>, \n"
6969
+ " numericcol NUMERIC, \n"
7070
+ " jsoncol JSON, \n"
71+
+ " uuidcol UUID, \n"
7172
+ " pgcolumn PG.SOMETHING, \n"
7273
+ " generatedcol STRING(MAX) AS ( sizedstring + strstr ( maxstring, strpos (\n"
7374
+ " maxstring, 'xxx' ), length ( maxstring ) ) + 2.0 ) STORED, \n"

src/test/resources/ddlParserValidation.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ CREATE TABLE test.test (
6363
intarray ARRAY<INT64>,
6464
numericcol NUMERIC,
6565
jsoncol JSON,
66+
uuidcol UUID,
6667
pgcolumn PG.SOMETHING,
6768
generatedcol STRING(MAX) AS ( sizedstring + strstr ( maxstring, strpos ( maxstring, 'xxx' ), length ( maxstring ) ) + 2.0 ) STORED,
6869
tokenlistCol TOKENLIST AS ( TOKENIZE_FULLTEXT ( maxstring ) ) HIDDEN,

src/test/resources/expectedDdlDiff.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ ALTER TABLE mytable SET OPTIONS (locality_group='lg2')
380380
ALTER TABLE mytable SET OPTIONS (droppedKey=NULL,newKey='value2')
381381

382382
== test 75 column changing not null with default value
383+
383384
ALTER TABLE test ALTER COLUMN add_nn BOOL NOT NULL DEFAULT (FALSE)
384385
ALTER TABLE test ALTER COLUMN add_both BOOL NOT NULL DEFAULT (FALSE)
385386
ALTER TABLE test ALTER COLUMN remove_NN BOOL DEFAULT (FALSE)
@@ -388,5 +389,9 @@ ALTER TABLE test ALTER COLUMN remove_both BOOL
388389
ALTER TABLE test ALTER COLUMN change_both BOOL NOT NULL DEFAULT (TRUE)
389390
ALTER TABLE test ALTER COLUMN change_def SET DEFAULT (TRUE)
390391

392+
== test 76 add UUID column
393+
394+
ALTER TABLE test1 ADD COLUMN col3 UUID
395+
391396
==
392397

src/test/resources/newDdl.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,5 +605,12 @@ CREATE TABLE test (
605605
change_both BOOL NOT NULL DEFAULT (TRUE),
606606
) PRIMARY KEY (id)
607607

608+
== test 76 add UUID column
609+
610+
create table test1 (
611+
col1 int64,
612+
col2 string(max),
613+
col3 uuid
614+
) primary key (col1);
608615

609616
==

src/test/resources/originalDdl.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,5 +604,12 @@ CREATE TABLE test (
604604
change_def BOOL NOT NULL DEFAULT (FALSE),
605605
) PRIMARY KEY (id)
606606

607+
== test 76 add UUID column
608+
609+
create table test1 (
610+
col1 int64,
611+
col2 string(max)
612+
) primary key (col1);
613+
607614
==
608615

0 commit comments

Comments
 (0)