Skip to content

Commit a817c80

Browse files
committed
feat: add support UUID type
1 parent 596afc1 commit a817c80

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,5 +379,9 @@ ALTER TABLE mytable SET OPTIONS (locality_group='lg2')
379379

380380
ALTER TABLE mytable SET OPTIONS (droppedKey=NULL,newKey='value2')
381381

382+
== test 75 add UUID column
383+
384+
ALTER TABLE test1 ADD COLUMN col3 UUID
385+
382386
==
383387

src/test/resources/newDdl.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,4 +592,12 @@ create table mytable (keycol int64) primary key(keycol), OPTIONS(locality_group
592592

593593
create table mytable (keycol int64) primary key(keycol), OPTIONS(existingKey='value', newKey='value2')
594594

595+
== test 75 add UUID column
596+
597+
create table test1 (
598+
col1 int64,
599+
col2 string(max),
600+
col3 uuid
601+
) primary key (col1);
602+
595603
==

src/test/resources/originalDdl.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,5 +591,12 @@ create table mytable (keycol int64) primary key(keycol), OPTIONS(locality_group
591591

592592
create table mytable (keycol int64) primary key(keycol), OPTIONS(existingKey='value', droppedKey='value1')
593593

594+
== test 75 add UUID column
595+
596+
create table test1 (
597+
col1 int64,
598+
col2 string(max)
599+
) primary key (col1);
600+
594601
==
595602

0 commit comments

Comments
 (0)