Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/guides/sql-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ You can register new type handlers for the `x-sql-datatype` extension:

```python
from sqlalchemy.types import SMALLINT
from my_sqlalchemy_dialect import VectorType


def vector_to_sql(jsonschema: dict) -> VectorType:
return VectorType(**jsonschema.get("x-sql-datatype-properties", {}))


class MyConnector(SQLConnector):
@functools.cached_property
def jsonschema_to_sql(self):
to_sql = JSONSchemaToSQL()
to_sql.register_sql_datatype_handler("smallint", SMALLINT)
to_sql.register_sql_datatype_handler("vector", custom_vector_to_sql)
return to_sql
```

Expand All @@ -86,6 +92,10 @@ plugins:
addresses:
number:
x-sql-datatype: smallint
values:
x-sql-datatype: vector
x-sql-datatype-properties:
dim: 10
```
````

Expand Down
2 changes: 2 additions & 0 deletions singer_sdk/singerlib/schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Provides an object model for JSON Schema."""

from __future__ import annotations
Expand All @@ -18,7 +18,7 @@

# These are keys defined in the JSON Schema spec that do not themselves contain
# schemas (or lists of schemas)
STANDARD_KEYS = [

Check warning on line 21 in singer_sdk/singerlib/schema.py

View workflow job for this annotation

GitHub Actions / Check API Changes

STANDARD_KEYS

Attribute value was changed: `['title', 'description', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf', 'maxLength', 'minLength', 'format', 'type', 'default', 'required', 'enum', 'pattern', 'contentMediaType', 'contentEncoding', 'deprecated', 'additionalProperties', 'anyOf', 'patternProperties', 'allOf', 'oneOf', 'x-sql-datatype']` -> `['title', 'description', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf', 'maxLength', 'minLength', 'format', 'type', 'default', 'required', 'enum', 'pattern', 'contentMediaType', 'contentEncoding', 'deprecated', 'additionalProperties', 'anyOf', 'patternProperties', 'allOf', 'oneOf', 'x-sql-datatype', 'x-sql-datatype-properties']`
"title",
"description",
"minimum",
Expand Down Expand Up @@ -46,6 +46,7 @@
"oneOf",
# JSON Schema extensions
"x-sql-datatype",
"x-sql-datatype-properties",
]


Expand Down Expand Up @@ -89,6 +90,7 @@
contentEncoding: str | None = None # noqa: N815
# JSON Schema extensions
x_sql_datatype: str | None = None
x_sql_datatype_properties: dict[str, t.Any] | None = None

deprecated: bool | None = None
oneOf: t.Any | None = None # noqa: N815
Expand Down
18 changes: 18 additions & 0 deletions tests/singerlib/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
"additionalProperties": True,
"required": ["a_string"],
}
SCHEMA_WITH_CUSTOM_SQL_DATATYPE = Schema(
x_sql_datatype="vector",
x_sql_datatype_properties={"dimensions": 10},
)
SCHEMA_WITH_CUSTOM_SQL_DATATYPE_DICT = {
"x-sql-datatype": "vector",
"x-sql-datatype-properties": {"dimensions": 10},
}


@pytest.mark.parametrize(
Expand All @@ -53,6 +61,11 @@
OBJECT_DICT,
id="object_to_dict",
),
pytest.param(
SCHEMA_WITH_CUSTOM_SQL_DATATYPE,
SCHEMA_WITH_CUSTOM_SQL_DATATYPE_DICT,
id="schema_with_custom_sql_datatype_to_dict",
),
],
)
def test_schema_to_dict(schema, expected):
Expand Down Expand Up @@ -82,6 +95,11 @@ def test_schema_to_dict(schema, expected):
OBJECT_SCHEMA,
id="schema_from_object_dict",
),
pytest.param(
SCHEMA_WITH_CUSTOM_SQL_DATATYPE_DICT,
SCHEMA_WITH_CUSTOM_SQL_DATATYPE,
id="schema_from_custom_sql_datatype_dict",
),
],
)
def test_schema_from_dict(pydict, expected):
Expand Down
Loading