Skip to content

Commit d8bd2b5

Browse files
committed
chore: fix ops.ToTimedeltaOp and ops.IsInOp sqlglot compiler
1 parent 209d0d4 commit d8bd2b5

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
420420

421421
@UNARY_OP_REGISTRATION.register(ops.IsInOp)
422422
def _(op: ops.IsInOp, expr: TypedExpr) -> sge.Expression:
423+
if op.values is None or len(op.values) == 0:
424+
return sge.convert(False)
423425
return sge.In(this=expr.expr, expressions=[sge.convert(v) for v in op.values])
424426

425427

@@ -767,7 +769,7 @@ def _(op: ops.ToTimedeltaOp, expr: TypedExpr) -> sge.Expression:
767769
factor = UNIT_TO_US_CONVERSION_FACTORS[op.unit]
768770
if factor != 1:
769771
value = sge.Mul(this=value, expression=sge.convert(factor))
770-
return sge.Interval(this=value, unit=sge.Identifier(this="MICROSECOND"))
772+
return value
771773

772774

773775
@UNARY_OP_REGISTRATION.register(ops.UnixMicros)

tests/system/small/engines/test_generic_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def test_engines_invert_op(scalars_array_value: array_value.ArrayValue, engine):
392392
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
393393

394394

395-
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
395+
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
396396
def test_engines_isin_op(scalars_array_value: array_value.ArrayValue, engine):
397397
arr, col_ids = scalars_array_value.compute_values(
398398
[
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col` AS `bfcol_0`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
), `bfcte_1` AS (
6+
SELECT
7+
*,
8+
FALSE AS `bfcol_1`
9+
FROM `bfcte_0`
10+
)
11+
SELECT
12+
`bfcol_1` AS `int64_col`
13+
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_to_timedelta/out.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ WITH `bfcte_0` AS (
88
*,
99
`bfcol_1` AS `bfcol_4`,
1010
`bfcol_0` AS `bfcol_5`,
11-
INTERVAL `bfcol_0` MICROSECOND AS `bfcol_6`
11+
`bfcol_0` AS `bfcol_6`
1212
FROM `bfcte_0`
1313
), `bfcte_2` AS (
1414
SELECT
1515
*,
1616
`bfcol_4` AS `bfcol_10`,
1717
`bfcol_5` AS `bfcol_11`,
1818
`bfcol_6` AS `bfcol_12`,
19-
INTERVAL (`bfcol_5` * 1000000) MICROSECOND AS `bfcol_13`
19+
`bfcol_5` * 1000000 AS `bfcol_13`
2020
FROM `bfcte_1`
2121
), `bfcte_3` AS (
2222
SELECT
@@ -25,7 +25,7 @@ WITH `bfcte_0` AS (
2525
`bfcol_11` AS `bfcol_19`,
2626
`bfcol_12` AS `bfcol_20`,
2727
`bfcol_13` AS `bfcol_21`,
28-
INTERVAL (`bfcol_11` * 604800000000) MICROSECOND AS `bfcol_22`
28+
`bfcol_11` * 604800000000 AS `bfcol_22`
2929
FROM `bfcte_2`
3030
)
3131
SELECT

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,13 @@ def test_invert(scalar_types_df: bpd.DataFrame, snapshot):
307307

308308
def test_is_in(scalar_types_df: bpd.DataFrame, snapshot):
309309
bf_df = scalar_types_df[["int64_col"]]
310-
sql = _apply_unary_op(bf_df, ops.IsInOp(values=(1, 2, 3)), "int64_col")
311310

311+
sql = _apply_unary_op(bf_df, ops.IsInOp(values=(1, 2, 3)), "int64_col")
312312
snapshot.assert_match(sql, "out.sql")
313313

314+
sql = _apply_unary_op(bf_df, ops.IsInOp(values=()), "int64_col")
315+
snapshot.assert_match(sql, "empty.sql")
316+
314317

315318
def test_isalnum(scalar_types_df: bpd.DataFrame, snapshot):
316319
bf_df = scalar_types_df[["string_col"]]

0 commit comments

Comments
 (0)