-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add 'Table.row_from_mapping' helper. #3425
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
Add 'Table.row_from_mapping' helper. #3425
Conversation
dhermes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say this "closes #3396". That asks us to accept dictionaries in insert_data.
We should either:
- Explicitly not support it (i.e. either a blacklist or whitelist of types)
- Accept a polymorphic input (I am not really into that)
- Offer a sibling
insert_data_from_mappings(or a better / shorter name)
| :rtype: tuple | ||
| :returns: Tuple matching the table's schema | ||
| :raises: ValueError if table's schema is not set |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :param mapping: Mapping of row data. | ||
| :rtype: tuple | ||
| :returns: Tuple matching the table's schema |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| row.append(mapping[field.name]) | ||
| elif field.mode == 'REPEATED': | ||
| row.append(mapping.get(field.name, ())) | ||
| else: # NULLABLE |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| row.append(mapping.get(field.name, ())) | ||
| else: # NULLABLE | ||
| row.append(mapping.get(field.name)) | ||
| return tuple(row) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| with self.assertRaises(ValueError) as exc: | ||
| table.row_from_mapping(MAPPING) | ||
|
|
||
| self.assertEqual(exc.exception.args, (_TABLE_HAS_NO_SCHEMA,)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Given a table.insert_data([table.row_from_mapping(mapping) for mapping in mapping_list])I'm proposing closing #3396 with a note to that effect. |
|
If LGTY @lukesneeringer then I'm OK with it |
Closes #3396.