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 mapping of MAP types with boolean or integer keys #441

Merged
merged 3 commits into from
Jan 24, 2024

Conversation

hashhar
Copy link
Member

@hashhar hashhar commented Jan 22, 2024

Description

Fix mapping of MAP types with boolean or integer keys.

This is on top of #440 so only last 3 commits need to be reviewed.

Release notes

(x) Release notes are required, with the following suggested text:

* Fix mapping of MAP types with boolean or integer keys.

Copy link
Member

@hovaesco hovaesco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Comment on lines +40 to +43
if str(value).lower() == 'true':
return True
if str(value).lower() == 'false':
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to avoid this and return map keys as boolean instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes, but it's much harder to do on server. There's already some code FixJsonDataUtils which tries to handle some of this but it doesn't work well or is easy to do for structural types.

Comment on lines 873 to 880
# structural types - note that none of these below tests work in the Trino JDBC Driver either.
# Unhashable types like lists and dicts cannot be used as keys so these values cannot be represented as Python
# objects at all.
# .add_field(sql="MAP(ARRAY[ARRAY[1, 2]], ARRAY[null])", python={[1, 2]: None})
# .add_field(sql="MAP(ARRAY[MAP(ARRAY[1], ARRAY[2])], ARRAY[null])", python={{1: 2}: None})

# TODO: fails because server sends [[{"[1, 2]":null}]] as response whereas it sends [[[1,2]]] as response for ROW
# types that are not enclosed in a MAP while the RowValueMapper expects values to be lists.
# .add_field(sql="MAP(ARRAY[ROW(1, 2)], ARRAY[CAST(null AS VARCHAR)])", python={(1, 2): None})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow-up issue for the TODO?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uncovers a few bugs in the handling of map with boolean, integer or
row keys which will be fixed in a future commit.
@hashhar hashhar merged commit ca38d29 into trinodb:master Jan 24, 2024
12 checks passed
@hashhar hashhar deleted the hashhar/fix-type-mappings branch January 24, 2024 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants