Skip to content

Commit e734e5e

Browse files
committed
fix ops.invert_op in engine tests
1 parent 8c0ede2 commit e734e5e

File tree

7 files changed

+42
-30
lines changed

7 files changed

+42
-30
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ def _(expr: TypedExpr) -> sge.Expression:
7373
return sge.func("FARM_FINGERPRINT", expr.expr)
7474

7575

76+
@register_unary_op(ops.invert_op)
77+
def _(expr: TypedExpr) -> sge.Expression:
78+
if expr.dtype == dtypes.BOOL_DTYPE:
79+
return sge.Not(this=expr.expr)
80+
return sge.BitwiseNot(this=expr.expr)
81+
82+
7683
@register_unary_op(ops.isnull_op)
7784
def _(expr: TypedExpr) -> sge.Expression:
7885
return sge.Is(this=expr.expr, expression=sge.Null())

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ def _(expr: TypedExpr) -> sge.Expression:
148148
return sge.Floor(this=expr.expr)
149149

150150

151-
@register_unary_op(ops.invert_op)
152-
def _(expr: TypedExpr) -> sge.Expression:
153-
return sge.BitwiseNot(this=expr.expr)
154-
155-
156151
@register_unary_op(ops.ln_op)
157152
def _(expr: TypedExpr) -> sge.Expression:
158153
return sge.Case(

tests/system/small/engines/test_generic_ops.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def test_engines_casewhen_op_double_case(
391391
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
392392

393393

394-
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
394+
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
395395
def test_engines_isnull_op(scalars_array_value: array_value.ArrayValue, engine):
396396
arr, _ = scalars_array_value.compute_values(
397397
[ops.isnull_op.as_expr(expression.deref("string_col"))]
@@ -400,7 +400,7 @@ def test_engines_isnull_op(scalars_array_value: array_value.ArrayValue, engine):
400400
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
401401

402402

403-
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
403+
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
404404
def test_engines_notnull_op(scalars_array_value: array_value.ArrayValue, engine):
405405
arr, _ = scalars_array_value.compute_values(
406406
[ops.notnull_op.as_expr(expression.deref("string_col"))]
@@ -409,7 +409,7 @@ def test_engines_notnull_op(scalars_array_value: array_value.ArrayValue, engine)
409409
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
410410

411411

412-
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
412+
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
413413
def test_engines_invert_op(scalars_array_value: array_value.ArrayValue, engine):
414414
arr, _ = scalars_array_value.compute_values(
415415
[
@@ -454,7 +454,7 @@ def test_engines_isin_op(scalars_array_value: array_value.ArrayValue, engine):
454454
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
455455

456456

457-
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
457+
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
458458
def test_engines_isin_op_nested_filter(
459459
scalars_array_value: array_value.ArrayValue, engine
460460
):
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`bool_col` AS `bfcol_0`,
4+
`bytes_col` AS `bfcol_1`,
5+
`int64_col` AS `bfcol_2`
6+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
7+
), `bfcte_1` AS (
8+
SELECT
9+
*,
10+
~`bfcol_2` AS `bfcol_6`,
11+
~`bfcol_1` AS `bfcol_7`,
12+
NOT `bfcol_0` AS `bfcol_8`
13+
FROM `bfcte_0`
14+
)
15+
SELECT
16+
`bfcol_6` AS `int64_col`,
17+
`bfcol_7` AS `bytes_col`,
18+
`bfcol_8` AS `bool_col`
19+
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_invert/out.sql

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/unit/core/compile/sqlglot/expressions/test_generic_ops.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ def test_hash(scalar_types_df: bpd.DataFrame, snapshot):
233233
snapshot.assert_match(sql, "out.sql")
234234

235235

236+
def test_invert(scalar_types_df: bpd.DataFrame, snapshot):
237+
bf_df = scalar_types_df[["int64_col", "bytes_col", "bool_col"]]
238+
ops_map = {
239+
"int64_col": ops.invert_op.as_expr("int64_col"),
240+
"bytes_col": ops.invert_op.as_expr("bytes_col"),
241+
"bool_col": ops.invert_op.as_expr("bool_col"),
242+
}
243+
sql = utils._apply_unary_ops(bf_df, list(ops_map.values()), list(ops_map.keys()))
244+
245+
snapshot.assert_match(sql, "out.sql")
246+
247+
236248
def test_isnull(scalar_types_df: bpd.DataFrame, snapshot):
237249
col_name = "float64_col"
238250
bf_df = scalar_types_df[[col_name]]

tests/unit/core/compile/sqlglot/expressions/test_numeric_ops.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,6 @@ def test_floor(scalar_types_df: bpd.DataFrame, snapshot):
126126
snapshot.assert_match(sql, "out.sql")
127127

128128

129-
def test_invert(scalar_types_df: bpd.DataFrame, snapshot):
130-
col_name = "int64_col"
131-
bf_df = scalar_types_df[[col_name]]
132-
sql = utils._apply_unary_ops(bf_df, [ops.invert_op.as_expr(col_name)], [col_name])
133-
134-
snapshot.assert_match(sql, "out.sql")
135-
136-
137129
def test_ln(scalar_types_df: bpd.DataFrame, snapshot):
138130
col_name = "float64_col"
139131
bf_df = scalar_types_df[[col_name]]

0 commit comments

Comments
 (0)