Skip to content

Commit 2481637

Browse files
feat: add support for UUID and PG_UUID types across Spanner migration utilities
1 parent 466301e commit 2481637

6 files changed

Lines changed: 43 additions & 0 deletions

File tree

v2/spanner-common/src/main/java/com/google/cloud/teleport/v2/spanner/ddl/Column.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ private static String typeString(Type type, Integer size) {
164164
return Type.Code.JSON.getName();
165165
case PG_JSONB:
166166
return Type.Code.PG_JSONB.getName();
167+
case UUID:
168+
return Type.Code.UUID.getName();
169+
case PG_UUID:
170+
return Type.Code.PG_UUID.getName();
167171
case TOKENLIST:
168172
return Type.Code.TOKENLIST.getName();
169173
case ARRAY:
@@ -250,6 +254,10 @@ public Builder bytes() {
250254
return type(Type.bytes());
251255
}
252256

257+
public Builder uuid() {
258+
return type(Type.uuid());
259+
}
260+
253261
public Builder timestamp() {
254262
return type(Type.timestamp());
255263
}
@@ -306,6 +314,10 @@ public Builder pgJsonb() {
306314
return type(Type.pgJsonb());
307315
}
308316

317+
public Builder pgUuid() {
318+
return type(Type.pgUuid());
319+
}
320+
309321
public Builder max() {
310322
return size(-1);
311323
}
@@ -377,6 +389,9 @@ private static SizedType parseSpannerType(String spannerType, Dialect dialect) {
377389
if (spannerType.equals(Type.Code.NUMERIC.getName())) {
378390
return t(Type.numeric(), null);
379391
}
392+
if (spannerType.equals(Type.Code.UUID.getName())) {
393+
return t(Type.uuid(), null);
394+
}
380395
if (spannerType.equals(Type.Code.JSON.getName())) {
381396
return t(Type.json(), null);
382397
}
@@ -432,6 +447,9 @@ private static SizedType parseSpannerType(String spannerType, Dialect dialect) {
432447
if (spannerType.equals(Type.Code.PG_NUMERIC.getName())) {
433448
return t(Type.pgNumeric(), null);
434449
}
450+
if (spannerType.equals(Type.Code.PG_UUID.getName())) {
451+
return t(Type.pgUuid(), null);
452+
}
435453
if (spannerType.equals(Type.Code.PG_JSONB.getName())) {
436454
return t(Type.pgJsonb(), null);
437455
}

v2/spanner-common/src/main/java/com/google/cloud/teleport/v2/spanner/migrations/convertors/ChangeEventSpannerConvertor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public static com.google.cloud.spanner.Key changeEventToPrimaryKey(
111111
case STRING:
112112
case PG_VARCHAR:
113113
case PG_TEXT:
114+
case UUID:
115+
case PG_UUID:
114116
pk.append(
115117
ChangeEventTypeConvertor.toString(
116118
changeEvent, keyColName, /* requiredField= */ true));

v2/spanner-common/src/main/java/com/google/cloud/teleport/v2/spanner/migrations/convertors/ChangeEventTypeConvertor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public static Value toValue(
7171
case STRING:
7272
case PG_VARCHAR:
7373
case PG_TEXT:
74+
case UUID:
75+
case PG_UUID:
7476
return Value.string(toString(changeEvent, key, requiredField));
7577
case NUMERIC:
7678
case PG_NUMERIC:

v2/spanner-common/src/main/java/com/google/cloud/teleport/v2/spanner/migrations/spanner/SpannerReadUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private static void bindGoogleSqlValue(
111111
break;
112112
case STRING:
113113
case JSON:
114+
case UUID:
114115
stmtBuilder.bind(bindName).to((String) value);
115116
break;
116117
case NUMERIC:
@@ -153,6 +154,7 @@ private static void bindPgValue(
153154
case PG_VARCHAR:
154155
case PG_TEXT:
155156
case PG_JSONB:
157+
case PG_UUID:
156158
stmtBuilder.bind(bindName).to((String) value);
157159
break;
158160
case PG_NUMERIC:

v2/spanner-common/src/main/java/com/google/cloud/teleport/v2/spanner/type/Type.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public final class Type implements Serializable {
4444
private static final Type TYPE_BYTES = new Type(Type.Code.BYTES, null, null);
4545
private static final Type TYPE_TIMESTAMP = new Type(Type.Code.TIMESTAMP, null, null);
4646
private static final Type TYPE_DATE = new Type(Type.Code.DATE, null, null);
47+
private static final Type TYPE_UUID = new Type(Type.Code.UUID, null, null);
4748
private static final Type TYPE_ARRAY_BOOL = new Type(Type.Code.ARRAY, TYPE_BOOL, null);
4849
private static final Type TYPE_ARRAY_INT64 = new Type(Type.Code.ARRAY, TYPE_INT64, null);
4950
private static final Type TYPE_ARRAY_FLOAT32 = new Type(Type.Code.ARRAY, TYPE_FLOAT32, null);
@@ -66,6 +67,7 @@ public final class Type implements Serializable {
6667
private static final Type TYPE_PG_BYTEA = new Type(Type.Code.PG_BYTEA, null, null);
6768
private static final Type TYPE_PG_TIMESTAMPTZ = new Type(Type.Code.PG_TIMESTAMPTZ, null, null);
6869
private static final Type TYPE_PG_DATE = new Type(Type.Code.PG_DATE, null, null);
70+
private static final Type TYPE_PG_UUID = new Type(Type.Code.PG_UUID, null, null);
6971
private static final Type TYPE_PG_ARRAY_BOOL = new Type(Type.Code.PG_ARRAY, TYPE_PG_BOOL, null);
7072
private static final Type TYPE_PG_ARRAY_INT8 = new Type(Type.Code.PG_ARRAY, TYPE_PG_INT8, null);
7173
private static final Type TYPE_PG_ARRAY_FLOAT4 =
@@ -160,6 +162,11 @@ public static Type date() {
160162
return TYPE_DATE;
161163
}
162164

165+
/** Returns the descriptor for the {@code UUID} type. */
166+
public static Type uuid() {
167+
return TYPE_UUID;
168+
}
169+
163170
public static Type pgBool() {
164171
return TYPE_PG_BOOL;
165172
}
@@ -204,6 +211,10 @@ public static Type pgDate() {
204211
return TYPE_PG_DATE;
205212
}
206213

214+
public static Type pgUuid() {
215+
return TYPE_PG_UUID;
216+
}
217+
207218
public static Type pgCommitTimestamp() {
208219
return TYPE_PG_COMMIT_TIMESTAMP;
209220
}
@@ -317,6 +328,7 @@ public enum Code {
317328
BYTES("BYTES", Dialect.GOOGLE_STANDARD_SQL),
318329
TIMESTAMP("TIMESTAMP", Dialect.GOOGLE_STANDARD_SQL),
319330
DATE("DATE", Dialect.GOOGLE_STANDARD_SQL),
331+
UUID("UUID", Dialect.GOOGLE_STANDARD_SQL),
320332
ARRAY("ARRAY", Dialect.GOOGLE_STANDARD_SQL),
321333
STRUCT("STRUCT", Dialect.GOOGLE_STANDARD_SQL),
322334
PG_BOOL("boolean", Dialect.POSTGRESQL),
@@ -330,6 +342,7 @@ public enum Code {
330342
PG_BYTEA("bytea", Dialect.POSTGRESQL),
331343
PG_TIMESTAMPTZ("timestamp with time zone", Dialect.POSTGRESQL),
332344
PG_DATE("date", Dialect.POSTGRESQL),
345+
PG_UUID("uuid", Dialect.POSTGRESQL),
333346
PG_ARRAY("array", Dialect.POSTGRESQL),
334347
PG_COMMIT_TIMESTAMP("spanner.commit_timestamp", Dialect.POSTGRESQL);
335348

v2/spanner-to-sourcedb/src/main/java/com/google/cloud/teleport/v2/templates/transforms/AssignShardIdFn.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ private com.google.cloud.spanner.Key generateKey(String tableName, JsonNode keys
586586
case STRING:
587587
case PG_VARCHAR:
588588
case PG_TEXT:
589+
case UUID:
590+
case PG_UUID:
589591
pk.append(
590592
DataChangeRecordTypeConvertor.toString(
591593
keysJson, keyColName, /* requiredField= */ true));
@@ -645,6 +647,8 @@ private Object getColumnValueFromJson(Column column, JsonNode valuesJson) throws
645647
case STRING:
646648
case PG_VARCHAR:
647649
case PG_TEXT:
650+
case UUID:
651+
case PG_UUID:
648652
return DataChangeRecordTypeConvertor.toString(valuesJson, colName, false);
649653
case NUMERIC:
650654
case PG_NUMERIC:
@@ -690,6 +694,8 @@ private Object getColumnValueFromRow(Column column, Value value) throws Exceptio
690694
case STRING:
691695
case PG_VARCHAR:
692696
case PG_TEXT:
697+
case UUID:
698+
case PG_UUID:
693699
return value.getString();
694700
case NUMERIC:
695701
case PG_NUMERIC:

0 commit comments

Comments
 (0)