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
5 changes: 5 additions & 0 deletions bigframes/core/compile/sqlglot/expressions/geo_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def _(expr: TypedExpr) -> sge.Expression:
return sge.func("SAFE.ST_Y", expr.expr)


@register_binary_op(ops.GeoStDistanceOp, pass_op=True)
def _(left: TypedExpr, right: TypedExpr, op: ops.GeoStDistanceOp) -> sge.Expression:
return sge.func("ST_DISTANCE", left.expr, right.expr, sge.convert(op.use_spheroid))


@register_binary_op(ops.geo_st_difference_op)
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
return sge.func("ST_DIFFERENCE", left.expr, right.expr)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
WITH `bfcte_0` AS (
SELECT
`geography_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
ST_DISTANCE(`geography_col`, `geography_col`, TRUE) AS `bfcol_1`,
ST_DISTANCE(`geography_col`, `geography_col`, FALSE) AS `bfcol_2`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `spheroid`,
`bfcol_2` AS `no_spheroid`
FROM `bfcte_1`
15 changes: 15 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,21 @@ def test_geo_st_convexhull(scalar_types_df: bpd.DataFrame, snapshot):
snapshot.assert_match(sql, "out.sql")


def test_geo_st_distance(scalar_types_df: bpd.DataFrame, snapshot):
col_name = "geography_col"
bf_df = scalar_types_df[[col_name]]

sql = utils._apply_ops_to_sql(
bf_df,
[
ops.GeoStDistanceOp(use_spheroid=True).as_expr(col_name, col_name),
ops.GeoStDistanceOp(use_spheroid=False).as_expr(col_name, col_name),
],
["spheroid", "no_spheroid"],
)
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]]
Expand Down