Skip to content

Commit

Permalink
fix: Object and array JSON types are now handled before primitive typ…
Browse files Browse the repository at this point in the history
…es when converting them to SQL types (#2727)

* Add failing test

* Prioritize object and array
  • Loading branch information
edgarrmondragon authored Oct 23, 2024
1 parent 3bb3e5f commit fb9ac30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit fb9ac30

Please sign in to comment.