Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bigframes/core/compile/sqlglot/expressions/geo_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bigframes.core.compile.sqlglot.scalar_compiler as scalar_compiler

register_unary_op = scalar_compiler.scalar_op_compiler.register_unary_op
register_binary_op = scalar_compiler.scalar_op_compiler.register_binary_op


@register_unary_op(ops.geo_area_op)
Expand Down Expand Up @@ -108,3 +109,8 @@ def _(expr: TypedExpr) -> sge.Expression:
@register_unary_op(ops.geo_y_op)
def _(expr: TypedExpr) -> sge.Expression:
return sge.func("SAFE.ST_Y", expr.expr)


@register_binary_op(ops.geo_st_difference_op)
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
return sge.func("ST_DIFFERENCE", left.expr, right.expr)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
WITH `bfcte_0` AS (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ibis sql

SELECT
  st_difference(`t0`.`geography_col`, `t0`.`geography_col`) AS `geography_col`
FROM (
  SELECT
    `geography_col`
  FROM `bigframes-dev.sqlglot_test.scalar_types`
) AS `t0`

SELECT
`geography_col` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
ST_DIFFERENCE(`bfcol_0`, `bfcol_0`) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `geography_col`
FROM `bfcte_1`
8 changes: 8 additions & 0 deletions tests/unit/core/compile/sqlglot/expressions/test_geo_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def test_geo_st_convexhull(scalar_types_df: bpd.DataFrame, snapshot):
snapshot.assert_match(sql, "out.sql")


def test_geo_st_difference(scalar_types_df: bpd.DataFrame, snapshot):
col_name = "geography_col"
bf_df = scalar_types_df[[col_name]]
sql = utils._apply_binary_op(bf_df, ops.geo_st_difference_op, col_name, col_name)

snapshot.assert_match(sql, "out.sql")


def test_geo_st_geogfromtext(scalar_types_df: bpd.DataFrame, snapshot):
col_name = "string_col"
bf_df = scalar_types_df[[col_name]]
Expand Down