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

bug: JSON schema union types that contain boolean result in casting JSON objects and arrays as boolean values #2726

Closed
1 task
edgarrmondragon opened this issue Oct 18, 2024 · 0 comments · Fixed by #2727
Assignees
Labels
kind/Bug Something isn't working SQL Support for SQL taps and targets
Milestone

Comments

@edgarrmondragon
Copy link
Collaborator

Singer SDK Version

0.41.0

Is this a regression?

  • Yes

Python Version

NA

Bug scope

Targets (data type handling, batching, SQL object generation, etc.)

Operating System

NA

Description

Fields with schemas similar to the one in the Code section below, prioritize the presence all types before object and array. This is wrong, as the presence of either indicates a non-scalar field.

The issue in question is coming from

sdk/singer_sdk/typing.py

Lines 1208 to 1245 in 316282e

def to_sql_type( # noqa: PLR0911, C901
jsonschema_type: dict,
) -> sa.types.TypeEngine:
"""Convert JSON Schema type to a SQL type.
Args:
jsonschema_type: The JSON Schema object.
Returns:
The SQL type.
"""
if _jsonschema_type_check(jsonschema_type, ("string",)):
datelike_type = get_datelike_property_type(jsonschema_type)
if datelike_type:
if datelike_type == "date-time":
return sa.types.DATETIME()
if datelike_type in "time":
return sa.types.TIME()
if datelike_type == "date":
return sa.types.DATE()
maxlength = jsonschema_type.get("maxLength")
return sa.types.VARCHAR(maxlength)
if _jsonschema_type_check(jsonschema_type, ("integer",)):
return sa.types.INTEGER()
if _jsonschema_type_check(jsonschema_type, ("number",)):
return sa.types.DECIMAL()
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()

Related issues:

Code

{
  "type": ["string","number","integer","array","object","boolean","null"]
}

Link to Slack/Linen

No response

@edgarrmondragon edgarrmondragon self-assigned this Oct 18, 2024
@edgarrmondragon edgarrmondragon changed the title bug: JSON schem union types that contain boolean result in casting JSON objects and arrays as boolean values bug: JSON schema union types that contain boolean result in casting JSON objects and arrays as boolean values Oct 18, 2024
@edgarrmondragon edgarrmondragon added the kind/Bug Something isn't working label Oct 18, 2024
@edgarrmondragon edgarrmondragon added this to the v0.42.0 milestone Oct 23, 2024
@edgarrmondragon edgarrmondragon added the SQL Support for SQL taps and targets label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/Bug Something isn't working SQL Support for SQL taps and targets
Projects
None yet
1 participant