Add 'Table.row_from_mapping' helper.#3425
Add 'Table.row_from_mapping' helper.#3425lukesneeringer merged 2 commits intogoogleapis:masterfrom tseaver:3396-bigquery-row_from_mapping
Conversation
dhermes
left a comment
There was a problem hiding this comment.
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.