Skip to content

Commit ba73a5e

Browse files
feat: Support arbitrary properties for x-sql-datatype in x-sql-datatype-properties
Signed-off-by: Edgar Ramírez-Mondragón <[email protected]>
1 parent c0d09dd commit ba73a5e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

docs/guides/sql-target.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,19 @@ You can register new type handlers for the `x-sql-datatype` extension:
6464

6565
```python
6666
from sqlalchemy.types import SMALLINT
67+
from my_sqlalchemy_dialect import VectorType
68+
69+
70+
def vector_to_sql(jsonschema: dict) -> VectorType:
71+
return VectorType(**jsonschema.get("x-sql-datatype-properties", {}))
6772

6873

6974
class MyConnector(SQLConnector):
7075
@functools.cached_property
7176
def jsonschema_to_sql(self):
7277
to_sql = JSONSchemaToSQL()
7378
to_sql.register_sql_datatype_handler("smallint", SMALLINT)
79+
to_sql.register_sql_datatype_handler("vector", custom_vector_to_sql)
7480
return to_sql
7581
```
7682

@@ -86,6 +92,10 @@ plugins:
8692
addresses:
8793
number:
8894
x-sql-datatype: smallint
95+
values:
96+
x-sql-datatype: vector
97+
x-sql-datatype-properties:
98+
dim: 10
8999
```
90100
````
91101

singer_sdk/singerlib/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"oneOf",
4747
# JSON Schema extensions
4848
"x-sql-datatype",
49+
"x-sql-datatype-properties",
4950
]
5051

5152

@@ -89,6 +90,7 @@ class Schema:
8990
contentEncoding: str | None = None # noqa: N815
9091
# JSON Schema extensions
9192
x_sql_datatype: str | None = None
93+
x_sql_datatype_properties: dict[str, t.Any] | None = None
9294

9395
deprecated: bool | None = None
9496
oneOf: t.Any | None = None # noqa: N815

tests/singerlib/test_schema.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
"additionalProperties": True,
2929
"required": ["a_string"],
3030
}
31+
SCHEMA_WITH_CUSTOM_SQL_DATATYPE = Schema(
32+
x_sql_datatype="vector",
33+
x_sql_datatype_properties={"dimensions": 10},
34+
)
35+
SCHEMA_WITH_CUSTOM_SQL_DATATYPE_DICT = {
36+
"x-sql-datatype": "vector",
37+
"x-sql-datatype-properties": {"dimensions": 10},
38+
}
3139

3240

3341
@pytest.mark.parametrize(
@@ -53,6 +61,11 @@
5361
OBJECT_DICT,
5462
id="object_to_dict",
5563
),
64+
pytest.param(
65+
SCHEMA_WITH_CUSTOM_SQL_DATATYPE,
66+
SCHEMA_WITH_CUSTOM_SQL_DATATYPE_DICT,
67+
id="schema_with_custom_sql_datatype_to_dict",
68+
),
5669
],
5770
)
5871
def test_schema_to_dict(schema, expected):
@@ -82,6 +95,11 @@ def test_schema_to_dict(schema, expected):
8295
OBJECT_SCHEMA,
8396
id="schema_from_object_dict",
8497
),
98+
pytest.param(
99+
SCHEMA_WITH_CUSTOM_SQL_DATATYPE_DICT,
100+
SCHEMA_WITH_CUSTOM_SQL_DATATYPE,
101+
id="schema_from_custom_sql_datatype_dict",
102+
),
85103
],
86104
)
87105
def test_schema_from_dict(pydict, expected):

0 commit comments

Comments
 (0)