Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Object and array JSON types are now handled before primitive types when converting them to SQL types #2727

Merged
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
12 changes: 6 additions & 6 deletions singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,12 @@ def to_sql_type( # noqa: PLR0911, C901
Returns:
The SQL type.
"""
if _jsonschema_type_check(jsonschema_type, ("object",)):
return sa.types.VARCHAR()

if _jsonschema_type_check(jsonschema_type, ("array",)):
return sa.types.VARCHAR()

if _jsonschema_type_check(jsonschema_type, ("string",)):
datelike_type = get_datelike_property_type(jsonschema_type)
if datelike_type:
Expand All @@ -1236,10 +1242,4 @@ def to_sql_type( # noqa: PLR0911, C901
if _jsonschema_type_check(jsonschema_type, ("boolean",)):
return sa.types.BOOLEAN()

if _jsonschema_type_check(jsonschema_type, ("object",)):
return sa.types.VARCHAR()

if _jsonschema_type_check(jsonschema_type, ("array",)):
return sa.types.VARCHAR()

return sa.types.VARCHAR()
4 changes: 4 additions & 0 deletions tests/core/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ def test_conform_primitives():
sa.types.DATETIME,
),
({"anyOf": [{"type": "integer"}, {"type": "null"}]}, sa.types.INTEGER),
(
{"type": ["array", "object", "boolean", "null"]},
sa.types.VARCHAR,
),
],
)
def test_to_sql_type(jsonschema_type, expected):
Expand Down
Loading