Skip to content

Commit dcb99ae

Browse files
committed
Migrate geo_st_geogpoint_op operator to SQLGlot
1 parent 9b86dcf commit dcb99ae

File tree

3 files changed

+30
-0
lines changed
  • bigframes/core/compile/sqlglot/expressions
  • tests/unit/core/compile/sqlglot/expressions

3 files changed

+30
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import bigframes.core.compile.sqlglot.scalar_compiler as scalar_compiler
2222

2323
register_unary_op = scalar_compiler.scalar_op_compiler.register_unary_op
24+
register_binary_op = scalar_compiler.scalar_op_compiler.register_binary_op
2425

2526

2627
@register_unary_op(ops.geo_area_op)
@@ -59,6 +60,11 @@ def _(expr: TypedExpr) -> sge.Expression:
5960
return sge.func("ST_CONVEXHULL", expr.expr)
6061

6162

63+
@register_binary_op(ops.geo_st_geogpoint_op)
64+
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
65+
return sge.func("ST_GEOGPOINT", left.expr, right.expr)
66+
67+
6268
@register_unary_op(ops.geo_st_geogfromtext_op)
6369
def _(expr: TypedExpr) -> sge.Expression:
6470
return sge.func("SAFE.ST_GEOGFROMTEXT", expr.expr)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`rowindex` AS `bfcol_0`,
4+
`rowindex_2` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
ST_GEOGPOINT(`bfcol_0`, `bfcol_1`) AS `bfcol_2`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_2` AS `rowindex`
14+
FROM `bfcte_1`

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ def test_geo_st_geogfromtext(scalar_types_df: bpd.DataFrame, snapshot):
9191
snapshot.assert_match(sql, "out.sql")
9292

9393

94+
def test_geo_st_geogpoint(scalar_types_df: bpd.DataFrame, snapshot):
95+
col_names = ["rowindex", "rowindex_2"]
96+
bf_df = scalar_types_df[col_names]
97+
sql = utils._apply_binary_op(
98+
bf_df, ops.geo_st_geogpoint_op, col_names[0], col_names[1]
99+
)
100+
101+
snapshot.assert_match(sql, "out.sql")
102+
103+
94104
def test_geo_st_isclosed(scalar_types_df: bpd.DataFrame, snapshot):
95105
col_name = "geography_col"
96106
bf_df = scalar_types_df[[col_name]]

0 commit comments

Comments
 (0)