Repository: ibis-project/ibis

Issue:
bug: bigquery geography dtype misses the srid (spatial reference identifier) configuration
### What happened?

BigQuery Geography column maps to `ibis_dtypes.GeoSpatial(geotype="geography")` with a None `srid` configuration. However, BigQuery uses points on the WGS84 reference ellipsoid according to [doc](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types?hl=en#geography_type ).


### What version of ibis are you using?

0.14.0

### What backend(s) are you using, if any?

BigQuery

### Relevant log output

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
bug: bigquery geography dtype misses the srid (spatial reference identifier) configuration
### What happened?

BigQuery Geography column maps to `ibis_dtypes.GeoSpatial(geotype="geography")` with a None `srid` configuration. However, BigQuery uses points on the WGS84 reference ellipsoid according to [doc](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types?hl=en#geography_type ).


### What version of ibis are you using?

0.14.0

### What backend(s) are you using, if any?

BigQuery

### Relevant log output

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct


Discussion:
thanks for @tswast to point out the issue.
thanks for @tswast to point out the issue.

Resolving patch:
diff --git a/ibis/backends/bigquery/client.py b/ibis/backends/bigquery/client.py
--- a/ibis/backends/bigquery/client.py
+++ b/ibis/backends/bigquery/client.py
@@ -29,6 +29,7 @@
     "TIMESTAMP": dt.timestamp,
     "BYTES": dt.binary,
     "NUMERIC": dt.Decimal(38, 9),
+    "GEOGRAPHY": dt.GeoSpatial(geotype="geography", srid=4326),
 }
 
 
diff --git a/ibis/backends/bigquery/datatypes.py b/ibis/backends/bigquery/datatypes.py
--- a/ibis/backends/bigquery/datatypes.py
+++ b/ibis/backends/bigquery/datatypes.py
@@ -82,6 +82,16 @@ def trans_json(t):
     return "JSON"
 
 
+@ibis_type_to_bigquery_type.register(dt.GeoSpatial)
+def trans_geography(t):
+    if (t.geotype, t.srid) == ("geography", 4326):
+        return "GEOGRAPHY"
+    raise TypeError(
+        "BigQuery geography uses points on WGS84 reference ellipsoid."
+        f"Current geotype: {t.geotype}, Current srid: {t.srid}"
+    )
+
+
 def spread_type(dt: dt.DataType):
     """Returns a generator that contains all the types in the given type.
 


Test patch:
diff --git a/ibis/backends/bigquery/tests/system/test_client.py b/ibis/backends/bigquery/tests/system/test_client.py
--- a/ibis/backends/bigquery/tests/system/test_client.py
+++ b/ibis/backends/bigquery/tests/system/test_client.py
@@ -350,3 +350,21 @@ def test_create_table_bignumeric(client):
         assert df.shape == (1, 1)
     finally:
         client.drop_table(temp_table_name)
+
+
+def test_geography_table(client):
+    temp_table_name = f"temp_to_table_{guid()[:6]}"
+    schema = ibis.schema({'col1': dt.GeoSpatial(geotype="geography", srid=4326)})
+    temporary_table = client.create_table(temp_table_name, schema=schema)
+    try:
+        client.raw_sql(
+            f"INSERT {client.current_database}.{temp_table_name} (col1) VALUES (ST_GEOGPOINT(1,3))"
+        )
+        df = temporary_table.execute()
+        assert df.shape == (1, 1)
+
+        assert temporary_table.schema() == ibis.schema(
+            [("col1", dt.GeoSpatial(geotype="geography", srid=4326))]
+        )
+    finally:
+        client.drop_table(temp_table_name)
diff --git a/ibis/backends/bigquery/tests/unit/test_datatypes.py b/ibis/backends/bigquery/tests/unit/test_datatypes.py
--- a/ibis/backends/bigquery/tests/unit/test_datatypes.py
+++ b/ibis/backends/bigquery/tests/unit/test_datatypes.py
@@ -51,6 +51,17 @@ def test_no_ambiguities():
         ),
         param(dt.Decimal(38, 9), "NUMERIC", id="decimal-numeric"),
         param(dt.Decimal(76, 38), "BIGNUMERIC", id="decimal-bignumeric"),
+        param(
+            dt.GeoSpatial(geotype="geography", srid=4326), "GEOGRAPHY", id="geography"
+        ),
+        param(
+            dt.GeoSpatial(geotype="geography"),
+            "GEOGRAPHY",
+            marks=pytest.mark.xfail(
+                raises=TypeError, reason="Should use the WGS84 reference ellipsoid."
+            ),
+            id="geography",
+        ),
     ],
 )
 def test_simple(datatype, expected):