|
22 | 22 | import bigframes.core.compile.sqlglot.expressions.constants as constants |
23 | 23 | from bigframes.core.compile.sqlglot.expressions.typed_expr import TypedExpr |
24 | 24 | import bigframes.core.compile.sqlglot.scalar_compiler as scalar_compiler |
| 25 | +from bigframes.operations import numeric_ops |
25 | 26 |
|
26 | 27 | register_unary_op = scalar_compiler.scalar_op_compiler.register_unary_op |
27 | 28 | register_binary_op = scalar_compiler.scalar_op_compiler.register_binary_op |
@@ -189,7 +190,7 @@ def _(expr: TypedExpr) -> sge.Expression: |
189 | 190 |
|
190 | 191 | @register_unary_op(ops.neg_op) |
191 | 192 | def _(expr: TypedExpr) -> sge.Expression: |
192 | | - return sge.Neg(this=expr.expr) |
| 193 | + return sge.Neg(this=sge.paren(expr.expr)) |
193 | 194 |
|
194 | 195 |
|
195 | 196 | @register_unary_op(ops.pos_op) |
@@ -408,6 +409,21 @@ def _(left: TypedExpr, right: TypedExpr) -> sge.Expression: |
408 | 409 | ) |
409 | 410 |
|
410 | 411 |
|
| 412 | +@register_unary_op(numeric_ops.isnan_op) |
| 413 | +def isnan(arg: TypedExpr) -> sge.Expression: |
| 414 | + return sge.IsNan(this=arg.expr) |
| 415 | + |
| 416 | + |
| 417 | +@register_unary_op(numeric_ops.isfinite_op) |
| 418 | +def isfinite(arg: TypedExpr) -> sge.Expression: |
| 419 | + return sge.Not( |
| 420 | + this=sge.Or( |
| 421 | + this=sge.IsInf(this=arg.expr), |
| 422 | + right=sge.IsNan(this=arg.expr), |
| 423 | + ), |
| 424 | + ) |
| 425 | + |
| 426 | + |
411 | 427 | def _coerce_bool_to_int(typed_expr: TypedExpr) -> sge.Expression: |
412 | 428 | """Coerce boolean expression to integer.""" |
413 | 429 | if typed_expr.dtype == dtypes.BOOL_DTYPE: |
|
0 commit comments