Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Add a hashcode implementation to SchemaField#3601
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7c015fc3b5c7ba1974553b6507025a6a4a02f728fa8882df33a0ad42c4f4234File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -26,27 +26,89 @@ class SchemaField(object): | ||
| 'FLOAT', 'BOOLEAN', 'TIMESTAMP' or 'RECORD'). | ||
| :type mode: str | ||
| :param mode: the type of the field (one of 'NULLABLE', 'REQUIRED', | ||
| :param mode: the mode of the field (one of 'NULLABLE', 'REQUIRED', | ||
| or 'REPEATED'). | ||
| :type description: str | ||
| :param description: optional description for the field. | ||
| :type fields: list of :class:`SchemaField`, or None | ||
| :type fields: tuple of :class:`SchemaField` | ||
| :param fields: subfields (requires ``field_type`` of 'RECORD'). | ||
| """ | ||
| def __init__(self, name, field_type, mode='NULLABLE', description=None, | ||
| fields=None): | ||
| self.name = name | ||
| self.field_type = field_type | ||
| self.mode = mode | ||
| self.description = description | ||
| self.fields = fields | ||
| def __init__(self, name, field_type, mode='NULLABLE', | ||
| description=None, fields=()): | ||
| self._name = name | ||
| self._field_type = field_type | ||
| self._mode = mode | ||
| self._description = description | ||
| self._fields = tuple(fields) | ||
| def __eq__(self, other): | ||
| @property | ||
| def name(self): | ||
| """str: The name of the field.""" | ||
| return self._name | ||
| @property | ||
| def field_type(self): | ||
| """str: The type of the field. | ||
| Will be one of 'STRING', 'INTEGER', 'FLOAT', 'BOOLEAN', | ||
| 'TIMESTAMP' or 'RECORD'. | ||
| """ | ||
| return self._field_type | ||
| @property | ||
| def mode(self): | ||
| """str: The mode of the field. | ||
| Will be one of 'NULLABLE', 'REQUIRED', or 'REPEATED'. | ||
| """ | ||
| return self._mode | ||
| @property | ||
| def description(self): | ||
| """Optional[str]: Description for the field.""" | ||
| return self._description | ||
| @property | ||
| def fields(self): | ||
| """tuple: Subfields contained in this field. | ||
| If ``field_type`` is not 'RECORD', this property must be | ||
| empty / unset. | ||
| """ | ||
| return self._fields | ||
| def _key(self): | ||
| """A tuple key that unique-ly describes this field. | ||
| Used to compute this instance's hashcode and evaluate equality. | ||
| Returns: | ||
| tuple: The contents of this :class:`SchemaField`. | ||
| """ | ||
| return ( | ||
| self.name == other.name and | ||
| self.field_type.lower() == other.field_type.lower() and | ||
| self.mode == other.mode and | ||
| self.description == other.description and | ||
| self.fields == other.fields) | ||
| self._name, | ||
| self._field_type.lower(), | ||
| self._mode, | ||
| self._description, | ||
| self._fields, | ||
| ) | ||
| def __eq__(self, other): | ||
| if isinstance(other, SchemaField): | ||
| return self._key() == other._key() | ||
| else: | ||
| return NotImplemented | ||
| def __ne__(self, other): | ||
| if isinstance(other, SchemaField): | ||
| return self._key() != other._key() | ||
| else: | ||
| return NotImplemented | ||
| def __hash__(self): | ||
| return hash(self._key()) | ||
| def __repr__(self): | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| return 'SchemaField{}'.format(self._key()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1079,7 +1079,7 @@ def _parse_schema_resource(info): | ||
| present in ``info``. | ||
| """ | ||
| if 'fields' not in info: | ||
| return None | ||
| return () | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| schema = [] | ||
| for r_field in info['fields']: | ||
| @@ -1109,7 +1109,7 @@ def _build_schema_resource(fields): | ||
| 'mode': field.mode} | ||
| if field.description is not None: | ||
| info['description'] = field.description | ||
| if field.fields is not None: | ||
| if field.fields: | ||
| info['fields'] = _build_schema_resource(field.fields) | ||
| infos.append(info) | ||
| return infos | ||
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.