Skip to content

Commit e574024

Browse files
authored
Chore: Migrate geo_st_geogpoint_op operator to SQLGlot (#2266)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes b/447388852 🦕
1 parent d85eee3 commit e574024

File tree

3 files changed

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

3 files changed

+29
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def _(expr: TypedExpr) -> sge.Expression:
6060
return sge.func("ST_CONVEXHULL", expr.expr)
6161

6262

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+
6368
@register_unary_op(ops.geo_st_geogfromtext_op)
6469
def _(expr: TypedExpr) -> sge.Expression:
6570
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`,
4+
`rowindex_2`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
ST_GEOGPOINT(`rowindex`, `rowindex_2`) 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
@@ -99,6 +99,16 @@ def test_geo_st_geogfromtext(scalar_types_df: bpd.DataFrame, snapshot):
9999
snapshot.assert_match(sql, "out.sql")
100100

101101

102+
def test_geo_st_geogpoint(scalar_types_df: bpd.DataFrame, snapshot):
103+
col_names = ["rowindex", "rowindex_2"]
104+
bf_df = scalar_types_df[col_names]
105+
sql = utils._apply_binary_op(
106+
bf_df, ops.geo_st_geogpoint_op, col_names[0], col_names[1]
107+
)
108+
109+
snapshot.assert_match(sql, "out.sql")
110+
111+
102112
def test_geo_st_intersection(scalar_types_df: bpd.DataFrame, snapshot):
103113
col_name = "geography_col"
104114
bf_df = scalar_types_df[[col_name]]

0 commit comments

Comments
 (0)