Skip to content

Commit d85eee3

Browse files
authored
Refactor: Use sge.func for ML.DISTANCE (#2270)
Replaced `sge.Anonymous` with `sge.func` for `ML.DISTANCE` calls to improve code clarity and consistency. 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 #<issue_number_goes_here> 🦕
1 parent 597eb55 commit d85eee3

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,7 @@ def _(expr: TypedExpr) -> sge.Expression:
127127

128128
@register_binary_op(ops.cosine_distance_op)
129129
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
130-
return sge.Anonymous(
131-
this="ML.DISTANCE",
132-
expressions=[
133-
left.expr,
134-
right.expr,
135-
sge.Literal.string("COSINE"),
136-
],
137-
)
130+
return sge.func("ML.DISTANCE", left.expr, right.expr, sge.Literal.string("COSINE"))
138131

139132

140133
@register_unary_op(ops.exp_op)
@@ -307,13 +300,8 @@ def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
307300

308301
@register_binary_op(ops.euclidean_distance_op)
309302
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
310-
return sge.Anonymous(
311-
this="ML.DISTANCE",
312-
expressions=[
313-
left.expr,
314-
right.expr,
315-
sge.Literal.string("EUCLIDEAN"),
316-
],
303+
return sge.func(
304+
"ML.DISTANCE", left.expr, right.expr, sge.Literal.string("EUCLIDEAN")
317305
)
318306

319307

0 commit comments

Comments
 (0)