From dcb99ae681bb3ae4e0d35317afcf0c382be2f006 Mon Sep 17 00:00:00 2001 From: jialuo Date: Thu, 13 Nov 2025 22:43:19 +0000 Subject: [PATCH 1/2] Migrate geo_st_geogpoint_op operator to SQLGlot --- .../core/compile/sqlglot/expressions/geo_ops.py | 6 ++++++ .../test_geo_ops/test_geo_st_geogpoint/out.sql | 14 ++++++++++++++ .../compile/sqlglot/expressions/test_geo_ops.py | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql diff --git a/bigframes/core/compile/sqlglot/expressions/geo_ops.py b/bigframes/core/compile/sqlglot/expressions/geo_ops.py index 4585a7f073..0c0d7bdc2b 100644 --- a/bigframes/core/compile/sqlglot/expressions/geo_ops.py +++ b/bigframes/core/compile/sqlglot/expressions/geo_ops.py @@ -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) @@ -59,6 +60,11 @@ def _(expr: TypedExpr) -> sge.Expression: return sge.func("ST_CONVEXHULL", expr.expr) +@register_binary_op(ops.geo_st_geogpoint_op) +def _(left: TypedExpr, right: TypedExpr) -> sge.Expression: + return sge.func("ST_GEOGPOINT", left.expr, right.expr) + + @register_unary_op(ops.geo_st_geogfromtext_op) def _(expr: TypedExpr) -> sge.Expression: return sge.func("SAFE.ST_GEOGFROMTEXT", expr.expr) diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql new file mode 100644 index 0000000000..5019e7d4e0 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql @@ -0,0 +1,14 @@ +WITH `bfcte_0` AS ( + SELECT + `rowindex` AS `bfcol_0`, + `rowindex_2` AS `bfcol_1` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + ST_GEOGPOINT(`bfcol_0`, `bfcol_1`) AS `bfcol_2` + FROM `bfcte_0` +) +SELECT + `bfcol_2` AS `rowindex` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/test_geo_ops.py b/tests/unit/core/compile/sqlglot/expressions/test_geo_ops.py index 9b99b37fb6..96c57e76f9 100644 --- a/tests/unit/core/compile/sqlglot/expressions/test_geo_ops.py +++ b/tests/unit/core/compile/sqlglot/expressions/test_geo_ops.py @@ -91,6 +91,16 @@ def test_geo_st_geogfromtext(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") +def test_geo_st_geogpoint(scalar_types_df: bpd.DataFrame, snapshot): + col_names = ["rowindex", "rowindex_2"] + bf_df = scalar_types_df[col_names] + sql = utils._apply_binary_op( + bf_df, ops.geo_st_geogpoint_op, col_names[0], col_names[1] + ) + + snapshot.assert_match(sql, "out.sql") + + def test_geo_st_isclosed(scalar_types_df: bpd.DataFrame, snapshot): col_name = "geography_col" bf_df = scalar_types_df[[col_name]] From 8e1fe470958be6d0906d2a7bf868aaca038065e4 Mon Sep 17 00:00:00 2001 From: jialuo Date: Thu, 13 Nov 2025 22:46:14 +0000 Subject: [PATCH 2/2] fix sql --- .../snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql index 5019e7d4e0..f6c953d161 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql @@ -1,12 +1,12 @@ WITH `bfcte_0` AS ( SELECT - `rowindex` AS `bfcol_0`, - `rowindex_2` AS `bfcol_1` + `rowindex`, + `rowindex_2` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` ), `bfcte_1` AS ( SELECT *, - ST_GEOGPOINT(`bfcol_0`, `bfcol_1`) AS `bfcol_2` + ST_GEOGPOINT(`rowindex`, `rowindex_2`) AS `bfcol_2` FROM `bfcte_0` ) SELECT