Skip to content

Commit f73fb98

Browse files
authored
chore: Migrate geo_st_intersection_op operator to SQLGlot (#2262)
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 0e3f2a4 commit f73fb98

File tree

3 files changed

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

3 files changed

+26
-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
@@ -114,3 +114,8 @@ def _(expr: TypedExpr) -> sge.Expression:
114114
@register_binary_op(ops.geo_st_difference_op)
115115
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
116116
return sge.func("ST_DIFFERENCE", left.expr, right.expr)
117+
118+
119+
@register_binary_op(ops.geo_st_intersection_op)
120+
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
121+
return sge.func("ST_INTERSECTION", left.expr, right.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`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
), `bfcte_1` AS (
6+
SELECT
7+
*,
8+
ST_INTERSECTION(`geography_col`, `geography_col`) 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_geo_ops.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ 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_intersection(scalar_types_df: bpd.DataFrame, snapshot):
103+
col_name = "geography_col"
104+
bf_df = scalar_types_df[[col_name]]
105+
sql = utils._apply_binary_op(bf_df, ops.geo_st_intersection_op, col_name, col_name)
106+
107+
snapshot.assert_match(sql, "out.sql")
108+
109+
102110
def test_geo_st_isclosed(scalar_types_df: bpd.DataFrame, snapshot):
103111
col_name = "geography_col"
104112
bf_df = scalar_types_df[[col_name]]

0 commit comments

Comments
 (0)