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

feat(ibis): Implement Snowflake Metadata APIs #895

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ongdisheng
Copy link

Implement Snowflake Metadata APIs #709

(POST) /v2/connector/snowflake/metadata/tables

Request payload example

{
  "connectionInfo": {
    "user": "my-user",
    "password": "my-pwd",
    "account": "my-account",
    "database": "my-db",
    "schema": "my-schema"
  }
}

Response example

  • name: unique table name
  • columns
    • name: column name in the datasource
    • type: column data type
    • notNull: boolean, nullable or not
    • description: column description(comment) if any
    • properties: column properties if any
  • description: table description if any
  • properties
    • schema: schema name to build tableReference
    • catalog: catalog name to build tableReference
    • table: table name to build tableReference
  • primaryKey: the column name which is bind with primary constraint
[
    {
        "name": "db.REGION",
        "columns": [
            {
                "name": "R_COMMENT",
                "type": "VARCHAR",
                "notNull": false,
                "description": "",
                "properties": null
            }
        ],
        "description": "",
        "properties": {
            "schema": "db",
            "catalog": "def",
            "table": "REGION"
        },
        "primaryKey": ""
    },
]

(POST) /v2/connector/snowflake/metadata/constraints

Request payload example

{
  "connectionInfo": {
    "user": "my-user",
    "password": "my-pwd",
    "account": "my-account",
    "database": "my-db",
    "schema": "my-schema"
  }
}

Response example

  • constraints
    • constraintName: unique constraint name
      ({constraint_table}_{constraint_column}_{constrainted_table}_{constrainted_column})
    • constraintType: “FOREIGN KEY”
    • constraintTable
    • constraintColumn
    • constraintedTable
    • constraintedColumn
[
    {
        "constraintName": "ORDERS_O_CUSTKEY_CUSTOMER_C_CUSTKEY",
        "constraintType": "FOREIGN KEY",
        "constraintTable": "db.ORDERS",
        "constraintColumn": "O_CUSTKEY",
        "constraintedTable": "db.CUSTOMER",
        "constraintedColumn": "C_CUSTKEY"
    },
]

@github-actions github-actions bot added ibis python Pull requests that update Python code labels Nov 10, 2024
@ongdisheng ongdisheng marked this pull request as draft November 10, 2024 06:56
@ongdisheng ongdisheng marked this pull request as ready for review November 10, 2024 08:18
@ongdisheng
Copy link
Author

ongdisheng commented Nov 10, 2024

Hi @grieve54706 @goldmedal, could you take a look at my PR when you have some free time? I'd really appreciate your feedback, thanks in advance!

Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

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

Thanks @ongdisheng. Overall looks good to me 👍 . Let's wait for @grieve54706 to review it.

ibis-server/app/model/metadata/snowflake.py Outdated Show resolved Hide resolved
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.

Well done. Thanks for your contribution. Welcome @ongdisheng.

url=f"{base_url}/metadata/tables",
json={"connectionInfo": connection_info},
)
assert response.status_code == 200
Copy link
Contributor

@grieve54706 grieve54706 Nov 11, 2024

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I’ve updated the test. Could you please take a look when you have time and let me know if I’ve done it correctly? Thanks @grieve54706!

@ongdisheng
Copy link
Author

@goldmedal @grieve54706, thanks for the quick feedback! I’ll have the fixes ready later today.

Comment on lines 292 to +297
def test_metadata_list_constraints():
pass
response = client.post(
url=f"{base_url}/metadata/constraints",
json={"connectionInfo": connection_info},
)
assert response.status_code == 200
Copy link
Contributor

@grieve54706 grieve54706 Nov 12, 2024

Choose a reason for hiding this comment

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

Hi @ongdisheng,
Could you add expected like test_metadata_list_tables too?
You did a good job. Thanks for your help.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @grieve54706, I've noticed that the TPCH_SF1 schema doesn’t seem to enforce foreign key constraints, which causes the SHOW IMPORTED KEYS command to return an empty list.

Here are the results I found when querying the TABLE_CONSTRAINTS:
image

Given this, would it be appropriate to add an assertion to check that the result returns an empty list? I’d be glad to hear any other suggestions you may have. Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, asserting it is an empty list is a good choice.

@grieve54706 grieve54706 added this to the 0.11.3 milestone Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ibis python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants