Skip to content

Commit 3d2a33b

Browse files
committed
geo_st_centroid_op compiler
1 parent 2375c07 commit 3d2a33b

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

bigframes/core/compile/sqlglot/expressions/unary_compiler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ def _(op: ops.GeoStBufferOp, expr: TypedExpr) -> sge.Expression:
273273
)
274274

275275

276+
@UNARY_OP_REGISTRATION.register(ops.geo_st_centroid_op)
277+
def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
278+
return sge.func("ST_CENTROID", expr.expr)
279+
280+
276281
@UNARY_OP_REGISTRATION.register(ops.geo_st_geogfromtext_op)
277282
def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
278283
return sge.func("SAFE.ST_GEOGFROMTEXT", expr.expr)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`geography_col` AS `bfcol_0`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
), `bfcte_1` AS (
6+
SELECT
7+
*,
8+
ST_CENTROID(`bfcol_0`) AS `bfcol_1`
9+
FROM `bfcte_0`
10+
)
11+
SELECT
12+
`bfcol_1` AS `geography_col`
13+
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ def test_geo_st_buffer(scalar_types_df: bpd.DataFrame, snapshot):
181181
snapshot.assert_match(sql, "out.sql")
182182

183183

184+
def test_geo_st_centroid(scalar_types_df: bpd.DataFrame, snapshot):
185+
bf_df = scalar_types_df[["geography_col"]]
186+
sql = _apply_unary_op(bf_df, ops.geo_st_centroid_op, "geography_col")
187+
188+
snapshot.assert_match(sql, "out.sql")
189+
190+
184191
def test_geo_st_geogfromtext(scalar_types_df: bpd.DataFrame, snapshot):
185192
bf_df = scalar_types_df[["string_col"]]
186193
sql = _apply_unary_op(bf_df, ops.geo_st_geogfromtext_op, "string_col")

0 commit comments

Comments
 (0)