From a817c800e90d3b8c56f2d5c294e8cc567779fe19 Mon Sep 17 00:00:00 2001 From: matsnow Date: Thu, 19 Mar 2026 03:39:30 +0000 Subject: [PATCH] feat: add support UUID type --- .../spannerddl/parser/ASTcolumn_type.java | 1 + .../solutions/spannerddl/diff/DdlDiffTest.java | 14 ++++++++++++++ .../solutions/spannerddl/parser/DDLParserTest.java | 3 ++- src/test/resources/ddlParserValidation.txt | 1 + src/test/resources/expectedDdlDiff.txt | 4 ++++ src/test/resources/newDdl.txt | 8 ++++++++ src/test/resources/originalDdl.txt | 7 +++++++ 7 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcolumn_type.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcolumn_type.java index 7b8fb9e..4386e13 100644 --- a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcolumn_type.java +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcolumn_type.java @@ -55,6 +55,7 @@ public String toString() { case "DATE": case "NUMERIC": case "JSON": + case "UUID": case "TOKENLIST": return typeName; case "STRING": diff --git a/src/test/java/com/google/cloud/solutions/spannerddl/diff/DdlDiffTest.java b/src/test/java/com/google/cloud/solutions/spannerddl/diff/DdlDiffTest.java index 803ab86..1daa4b0 100644 --- a/src/test/java/com/google/cloud/solutions/spannerddl/diff/DdlDiffTest.java +++ b/src/test/java/com/google/cloud/solutions/spannerddl/diff/DdlDiffTest.java @@ -267,6 +267,20 @@ public void generateAlterTable_incompatibleTypeChange() { "create table test1 (col1 float64) primary key (col1);", true, "Cannot change type of table test1 column col1"); + + // change type to UUID + getDiffCheckDdlDiffException( + "create table test1 (col1 int64, col2 int64) primary key (col1);", + "create table test1 (col1 int64, col2 uuid) primary key (col1);", + true, + "Cannot change type of table test1 column col2"); + + // change STRING(36) to UUID + getDiffCheckDdlDiffException( + "create table test1 (col1 int64, col2 string(36)) primary key (col1);", + "create table test1 (col1 int64, col2 uuid) primary key (col1);", + true, + "Cannot change type of table test1 column col2"); } @Test diff --git a/src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java b/src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java index b64539f..be1e845 100644 --- a/src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java +++ b/src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java @@ -36,7 +36,7 @@ public void parseCreateTable() throws ParseException { + " (\"prefix\" || sizedstring || \"suffix\"), sizedbytes bytes(55)," + " maxbytes bytes(max), datecol date, timestampcol timestamp options" + " (allow_commit_timestamp = true), intarray array, numericcol" - + " numeric,jsoncol json, pgcolumn pg.something, generatedcol string(max)" + + " numeric,jsoncol json, uuidcol uuid, pgcolumn pg.something, generatedcol string(max)" + " as (sizedstring+" + " strstr(maxstring,strpos(maxstring,'xxx'),length(maxstring)) +2.0)" + " STORED, constraint fk_col_remote FOREIGN KEY(col1, col2) REFERENCES" @@ -68,6 +68,7 @@ public void parseCreateTable() throws ParseException { + " intarray ARRAY, \n" + " numericcol NUMERIC, \n" + " jsoncol JSON, \n" + + " uuidcol UUID, \n" + " pgcolumn PG.SOMETHING, \n" + " generatedcol STRING(MAX) AS ( sizedstring + strstr ( maxstring, strpos (\n" + " maxstring, 'xxx' ), length ( maxstring ) ) + 2.0 ) STORED, \n" diff --git a/src/test/resources/ddlParserValidation.txt b/src/test/resources/ddlParserValidation.txt index 3461bd1..43ddfd9 100644 --- a/src/test/resources/ddlParserValidation.txt +++ b/src/test/resources/ddlParserValidation.txt @@ -63,6 +63,7 @@ CREATE TABLE test.test ( intarray ARRAY, numericcol NUMERIC, jsoncol JSON, + uuidcol UUID, pgcolumn PG.SOMETHING, generatedcol STRING(MAX) AS ( sizedstring + strstr ( maxstring, strpos ( maxstring, 'xxx' ), length ( maxstring ) ) + 2.0 ) STORED, tokenlistCol TOKENLIST AS ( TOKENIZE_FULLTEXT ( maxstring ) ) HIDDEN, diff --git a/src/test/resources/expectedDdlDiff.txt b/src/test/resources/expectedDdlDiff.txt index 7027453..4772187 100644 --- a/src/test/resources/expectedDdlDiff.txt +++ b/src/test/resources/expectedDdlDiff.txt @@ -379,5 +379,9 @@ ALTER TABLE mytable SET OPTIONS (locality_group='lg2') ALTER TABLE mytable SET OPTIONS (droppedKey=NULL,newKey='value2') +== test 75 add UUID column + +ALTER TABLE test1 ADD COLUMN col3 UUID + == diff --git a/src/test/resources/newDdl.txt b/src/test/resources/newDdl.txt index 907fb82..43d3c7e 100644 --- a/src/test/resources/newDdl.txt +++ b/src/test/resources/newDdl.txt @@ -592,4 +592,12 @@ create table mytable (keycol int64) primary key(keycol), OPTIONS(locality_group create table mytable (keycol int64) primary key(keycol), OPTIONS(existingKey='value', newKey='value2') +== test 75 add UUID column + +create table test1 ( + col1 int64, + col2 string(max), + col3 uuid +) primary key (col1); + == diff --git a/src/test/resources/originalDdl.txt b/src/test/resources/originalDdl.txt index caf0af7..fd7af8f 100644 --- a/src/test/resources/originalDdl.txt +++ b/src/test/resources/originalDdl.txt @@ -591,5 +591,12 @@ create table mytable (keycol int64) primary key(keycol), OPTIONS(locality_group create table mytable (keycol int64) primary key(keycol), OPTIONS(existingKey='value', droppedKey='value1') +== test 75 add UUID column + +create table test1 ( + col1 int64, + col2 string(max) +) primary key (col1); + ==