Skip to content

Commit

Permalink
fix(trino): fix sql for querying metadata (#834)
Browse files Browse the repository at this point in the history
* fix(trino): fix sql for querying metadata

* test(trino): adjust test case to prove it is fixed
  • Loading branch information
grieve54706 authored Oct 18, 2024
1 parent 4499fe1 commit 8ef49d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ibis-server/app/model/metadata/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_table_list(self) -> list[Table]:
AND t.table_name = c.table_name
INNER JOIN
system.metadata.table_comments AS tc
ON t.table_catalog = c.table_catalog
ON t.table_catalog = tc.catalog_name
AND t.table_schema = tc.schema_name
AND t.table_name = tc.table_name
WHERE t.table_schema = '{schema}'
Expand Down
44 changes: 24 additions & 20 deletions ibis-server/tests/routers/v2/connector/test_trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,17 @@ def test_validate_rule_column_is_valid_without_one_parameter(
assert response.text == "Missing required parameter: `modelName`"

def test_metadata_list_tables(trino: TrinoContainer):
connection_info = _to_connection_info(trino)
response = client.post(
url=f"{base_url}/metadata/tables",
json={"connectionInfo": connection_info},
)
assert response.status_code == 200
tables = response.json()
assert len(tables) == 8
table = next(filter(lambda t: t["name"] == "tpch.tiny.customer", tables))
assert len(table["columns"]) == 8

connection_info = {
"host": trino.get_container_host_ip(),
"port": trino.get_exposed_port(trino.port),
Expand All @@ -355,28 +366,23 @@ def test_metadata_list_tables(trino: TrinoContainer):
}
response = client.post(
url=f"{base_url}/metadata/tables",
json={
"connectionInfo": connection_info,
},
json={"connectionInfo": connection_info},
)
assert response.status_code == 200

result = next(
filter(lambda x: x["name"] == "memory.default.orders", response.json())
)
assert result["name"] == "memory.default.orders"
assert result["primaryKey"] is not None
assert result["description"] == "This is a table comment"
assert result["properties"] == {
tables = response.json()
assert len(tables) == 1
table = next(filter(lambda t: t["name"] == "memory.default.orders", tables))
assert table["name"] == "memory.default.orders"
assert table["primaryKey"] is not None
assert table["description"] == "This is a table comment"
assert table["properties"] == {
"catalog": "memory",
"schema": "default",
"table": "orders",
}
assert len(result["columns"]) == 9
comment_column = next(
filter(lambda x: x["name"] == "comment", result["columns"])
)
assert comment_column == {
assert len(table["columns"]) == 9
column = next(filter(lambda c: c["name"] == "comment", table["columns"]))
assert column == {
"name": "comment",
"nestedColumns": None,
"type": "UNKNOWN",
Expand All @@ -389,9 +395,7 @@ def test_metadata_list_constraints(trino: TrinoContainer):
connection_info = _to_connection_info(trino)
response = client.post(
url=f"{base_url}/metadata/constraints",
json={
"connectionInfo": connection_info,
},
json={"connectionInfo": connection_info},
)
assert response.status_code == 200

Expand All @@ -403,7 +407,7 @@ def _to_connection_info(trino: TrinoContainer):
"host": trino.get_container_host_ip(),
"port": trino.get_exposed_port(trino.port),
"catalog": "tpch",
"schema": "sf1",
"schema": "tiny",
"user": "test",
}

Expand Down

0 comments on commit 8ef49d8

Please sign in to comment.