Skip to content

feat(ibis): introduce the relationship validation #815

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

Merged
merged 6 commits into from
Oct 8, 2024

Conversation

goldmedal
Copy link
Contributor

@goldmedal goldmedal commented Oct 7, 2024

Description

This PR implements a new validation rule to validate if a relationship is valid. This validation is used to ensure the real data layout matches the definition. We have some rules for different relationship types.

  • ONE_TO_ONE
    • The join column of the left table is unique.
    • The join column of the right table is unique.
    • The count of the join result is greater than 0.
  • ONE_TO_MANY
    • The join column of the left table is unique.
    • The count of the join result is greater than 0.
  • MANY_TO_ONE
    • The join column of the right table is unique.
    • The count of the join result is greater than 0.
  • MANY_TO_MANY
    • The count of the join result is greater than 0.

API Request format

Rule name

relationship_is_valid

POST /v2/connector/{data_source}/validate/relationship_is_valid

Request body

    "connectionInfo": {......},
    "manifestStr": "eyJjYXRhbG9nIjoibXlfY2F0YWxvZyIsInNjaGVtYSI6Im15X3...",
    "parameters": {
        "relationshipName": "CustomerOrders", 
    }

Response

  • Success: HTTP code 204
  • Failed: HTTP code 422
    The validation result will be shown in the error message:
Exception: <class 'app.model.validator.ValidationError'>, message: Relationship invalid_t1_many_t2_id is not valid: {'result': 'False', 'is_related': 'True', 'left_table_unique': 'False', 'right_table_unique': 'True'}
  • is_related: If the count of the join result is greater than 0.
  • left_table_unique: If the join column of the left table is unique.
  • right_table_unique: If the join column of the right table is unique.

@goldmedal goldmedal marked this pull request as ready for review October 7, 2024 06:32
@goldmedal goldmedal requested a review from grieve54706 October 7, 2024 06:55
},
)
assert response.status_code == 422
assert response.text is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you provide the error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, it should be 204 withou text actually. I provided the wrong input SQL. I'll fix it. Thanks

@@ -197,7 +211,7 @@ def test_validate_with_unknown_rule():
assert response.status_code == 422
assert (
response.text
== "The rule `unknown_rule` is not in the rules, rules: ['column_is_valid']"
== "The rule `unknown_rule` is not in the rules, rules: ['column_is_valid', 'relationship_is_valid']"
Copy link
Contributor

Choose a reason for hiding this comment

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

How about importing the rules

from app.model.validator import rules

response.text == f"The rule `unknown_rule` is not in the rules, rules: {rules}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds great!

)

assert response.status_code == 422
assert response.content == b"Relationship not_found not found in manifest"
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use response.text.

Copy link
Contributor

@grieve54706 grieve54706 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @goldmedal.

@grieve54706 grieve54706 merged commit 5be3385 into main Oct 8, 2024
6 checks passed
@grieve54706 grieve54706 deleted the feature/validate-relationship branch October 8, 2024 08:08
grieve54706 pushed a commit that referenced this pull request Dec 13, 2024
* implement relationship validation

* fix tests for other source

* fix the method argument

* fix test

* fix test

* address comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants