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

Add column relationship validation to single table metadata #1698

Closed
amontanez24 opened this issue Nov 29, 2023 · 0 comments · Fixed by #1710
Closed

Add column relationship validation to single table metadata #1698

amontanez24 opened this issue Nov 29, 2023 · 0 comments · Fixed by #1710
Assignees
Labels
feature request Request for a new feature
Milestone

Comments

@amontanez24
Copy link
Contributor

amontanez24 commented Nov 29, 2023

Problem Description

As a user, I'd like to know if I formatted the column relationships in my metadata incorrectly so that I don't run methods that will take longer only to have them crash.

The SingleTableMetadata object is being upgraded to accept a new field called column_relationships. The format is as follows:

{
  "columns": {
    "user_lat": { "sdtype": "latitude" },
    "user_lon": { "sdtype": "longitude" },
  },
  "column_relationships": [{
    "type": "gps_coordinate",
    "column_names": ["user_lat", "user_lon" ],
  }]
}

Expected behavior

When running metadata.validate() on SingleTableMetadata, we should perform the following checks:

  • type must be a supported relationship type (only "address" for now)
  • column_names must all be listed in the "columns" section of the metadata
  • The column_names cannot already be involved in any other column relationship
  • The column_names cannot be a primary key or a foreign key (listed in the relationships)
  • The columns' sdtypes must be compatible with the relationship type. Each type will have different rules for this.
    • Eg. address supports sdtypes: postcode, state, city, …
      If any of the above are invalid, we should raise an InvalidMetadataError.

Additional context

  • We should put all of this validation into its own function since it will be reused by the add_column_relationship function in Add add_column_relationship method to single table metadata #1699 .
  • We should follow the same validation style as below:
    def validate(self):
    """Validate the metadata.
    Raises:
    - ``InvalidMetadataError`` if the metadata is invalid.
    """
    errors = []
    # Validate keys
    self._append_error(errors, self._validate_key, self.primary_key, 'primary')
    self._append_error(errors, self._validate_key, self.sequence_key, 'sequence')
    if self.sequence_index:
    self._append_error(errors, self._validate_sequence_index, self.sequence_index)
    self._append_error(errors, self._validate_sequence_index_not_in_sequence_key)
    self._append_error(errors, self._validate_alternate_keys, self.alternate_keys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants