diff --git a/ibis-server/app/util.py b/ibis-server/app/util.py index f05f61e2e..9cbed3b77 100644 --- a/ibis-server/app/util.py +++ b/ibis-server/app/util.py @@ -29,9 +29,18 @@ def _to_datetime_and_format(series: pd.Series) -> pd.Series: def _to_json_obj(df: pd.DataFrame) -> dict: - data = df.map(lambda x: f"{x:.9g}" if isinstance(x, float) else x).to_dict( - orient="split", index=False - ) + def format_value(x): + if isinstance(x, float): + return f"{x:.9g}" + elif isinstance(x, decimal.Decimal): + if x == 0: + return "0" + else: + return x + else: + return x + + data = df.map(format_value).to_dict(orient="split", index=False) def default(obj): if pd.isna(obj): diff --git a/ibis-server/tests/routers/v2/connector/test_bigquery.py b/ibis-server/tests/routers/v2/connector/test_bigquery.py index a5be020c7..764fbd5d8 100644 --- a/ibis-server/tests/routers/v2/connector/test_bigquery.py +++ b/ibis-server/tests/routers/v2/connector/test_bigquery.py @@ -198,6 +198,20 @@ async def test_query_values(client, manifest_str): assert response.status_code == 204 +async def test_scientific_notation(client, manifest_str): + response = await client.post( + url=f"{base_url}/query", + json={ + "connectionInfo": connection_info, + "manifestStr": manifest_str, + "sql": "SELECT cast(0 as numeric) as col", + }, + ) + assert response.status_code == 200 + result = response.json() + assert result["data"][0] == ["0"] + + async def test_query_empty_json(client, manifest_str): """Test the empty result with json column.""" response = await client.post( diff --git a/ibis-server/tests/routers/v2/connector/test_local_file.py b/ibis-server/tests/routers/v2/connector/test_local_file.py index e882307e2..0f0b6c99c 100644 --- a/ibis-server/tests/routers/v2/connector/test_local_file.py +++ b/ibis-server/tests/routers/v2/connector/test_local_file.py @@ -331,7 +331,7 @@ async def test_list_csv_files(client): assert "type-test" in table_names # `invalid` will be considered as a one column csv file assert "invalid" in table_names - columns = result[0]["columns"] + columns = next(filter(lambda x: x["name"] == "type-test-csv", result))["columns"] assert columns[0]["name"] == "c_bigint" assert columns[0]["type"] == "INT64" assert columns[1]["name"] == "c_bit"