Skip to content

Commit

Permalink
fix the custom datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmedal committed Dec 25, 2024
1 parent af5c332 commit ff2257f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ibis-server/app/model/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any

import ibis
import ibis.backends.bigquery
import ibis.expr.datatypes as dt
import ibis.expr.schema as sch
import ibis.formats
Expand Down Expand Up @@ -117,6 +116,9 @@ def query(self, sql: str, limit: int) -> pd.DataFrame:
try:
return super().query(sql, limit)
except ValueError as e:
# Import here to avoid override the custom datatypes
import ibis.backends.bigquery

# Try to match the error message from the google cloud bigquery library matching Arrow type error.
# If the error message matches, requries to get the schema from the result and generate a empty pandas dataframe with the mapped schema
#
Expand Down
34 changes: 32 additions & 2 deletions ibis-server/tests/routers/v2/connector/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async def test_query_values(client, manifest_str):


async def test_query_empty_json(client, manifest_str):
# Test the empty result with json column
"""Test the empty result with json column."""
response = await client.post(
url=f"{base_url}/query",
json={
Expand All @@ -213,7 +213,7 @@ async def test_query_empty_json(client, manifest_str):
assert len(result["data"]) == 0
assert result["dtypes"] == {"f0_": "object"}

# Test only the json column is null
"""Test only the json column is null."""
response = await client.post(
url=f"{base_url}/query",
json={
Expand Down Expand Up @@ -260,6 +260,36 @@ async def test_avg_interval(client, manifest_str):
assert result["dtypes"] == {"col": "object"}


async def test_custom_datatypes_no_overrides(client, manifest_str):
# Trigger import the official BigQueryType
response = await client.post(
url=f"{base_url}/query",
json={
"manifestStr": manifest_str,
"connectionInfo": connection_info,
"sql": "select json_object('a', 1, 'b', 2) limit 0",
},
)
assert response.status_code == 200
result = response.json()
assert len(result["data"]) == 0
assert result["dtypes"] == {"f0_": "object"}

# Should use back the custom BigQueryType
response = await client.post(
url=f"{base_url}/query",
json={
"connectionInfo": connection_info,
"manifestStr": manifest_str,
"sql": "SELECT INTERVAL '1' YEAR + INTERVAL '100' MONTH + INTERVAL '100' DAY + INTERVAL '1' HOUR AS col",
},
)
assert response.status_code == 200
result = response.json()
assert result["data"][0] == ["112 months 100 days 3600000000 microseconds"]
assert result["dtypes"] == {"col": "object"}


async def test_validate_with_unknown_rule(client, manifest_str):
response = await client.post(
url=f"{base_url}/validate/unknown_rule",
Expand Down

0 comments on commit ff2257f

Please sign in to comment.