Skip to content

Commit 1e59be2

Browse files
authored
feat: Add data type mapping for UUID (#365)
I have a custom tap/extractor that outputs UUID identifiers with a schema Property like the following. ```python from singer_sdk import typing as th th.Property( "id", th.UUIDType, ) ``` I want to load the data into a PostgreSQL database with the `id` in a column with the [UUID type](https://www.postgresql.org/docs/current/datatype-uuid.html). This PR maps the [schema string type with format `uuid`](https://sdk.meltano.com/en/latest/classes/typing/singer_sdk.typing.UUIDType.html) to the PostgreSQL `uuid` type.
1 parent 7c53295 commit 1e59be2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ The below table shows how this tap will map between jsonschema datatypes and Pos
209209
| UNSUPPORTED | tsquery |
210210
| UNSUPPORTED | tsvector |
211211
| UNSUPPORTED | txid_snapshot |
212-
| UNSUPPORTED | uuid |
212+
| string with format="uuid" | uuid |
213213
| UNSUPPORTED | xml |
214214

215215
Note that while object types are mapped directly to jsonb, array types are mapped to a jsonb array.

target_postgres/connector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import sqlalchemy as sa
1717
from singer_sdk import SQLConnector
1818
from singer_sdk import typing as th
19-
from sqlalchemy.dialects.postgresql import ARRAY, BIGINT, BYTEA, JSONB
19+
from sqlalchemy.dialects.postgresql import ARRAY, BIGINT, BYTEA, JSONB, UUID
2020
from sqlalchemy.engine import URL
2121
from sqlalchemy.engine.url import make_url
2222
from sqlalchemy.types import (
@@ -287,6 +287,8 @@ def pick_individual_type(self, jsonschema_type: dict):
287287
# string formats
288288
if jsonschema_type.get("format") == "date-time":
289289
return TIMESTAMP()
290+
if jsonschema_type.get("format") == "uuid":
291+
return UUID()
290292
if (
291293
self.interpret_content_encoding
292294
and jsonschema_type.get("contentEncoding") == "base16"
@@ -311,6 +313,7 @@ def pick_best_sql_type(sql_type_array: list):
311313
HexByteString,
312314
ARRAY,
313315
JSONB,
316+
UUID,
314317
TEXT,
315318
TIMESTAMP,
316319
DATETIME,

0 commit comments

Comments
 (0)