Skip to content

Commit bd71efb

Browse files
authored
Merge branch 'main' into release-please--branches--main
2 parents d92683e + db21a85 commit bd71efb

File tree

11 files changed

+334
-28
lines changed

11 files changed

+334
-28
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def _(expr: TypedExpr) -> sge.Expression:
7676
@register_unary_op(ops.invert_op)
7777
def _(expr: TypedExpr) -> sge.Expression:
7878
if expr.dtype == dtypes.BOOL_DTYPE:
79-
return sge.Not(this=expr.expr)
80-
return sge.BitwiseNot(this=expr.expr)
79+
return sge.Not(this=sge.paren(expr.expr))
80+
return sge.BitwiseNot(this=sge.paren(expr.expr))
8181

8282

8383
@register_unary_op(ops.isnull_op)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _(expr: TypedExpr) -> sge.Expression:
190190

191191
@register_unary_op(ops.neg_op)
192192
def _(expr: TypedExpr) -> sge.Expression:
193-
return sge.Neg(this=expr.expr)
193+
return sge.Neg(this=sge.paren(expr.expr))
194194

195195

196196
@register_unary_op(ops.pos_op)

tests/system/small/engines/test_generic_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
):

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ WITH `bfcte_0` AS (
77
), `bfcte_1` AS (
88
SELECT
99
*,
10-
~`bfcol_2` AS `bfcol_6`,
11-
~`bfcol_1` AS `bfcol_7`,
12-
NOT `bfcol_0` AS `bfcol_8`
10+
~(
11+
`bfcol_2`
12+
) AS `bfcol_6`,
13+
~(
14+
`bfcol_1`
15+
) AS `bfcol_7`,
16+
NOT (
17+
`bfcol_0`
18+
) AS `bfcol_8`
1319
FROM `bfcte_0`
1420
)
1521
SELECT
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+
`string_col` AS `bfcol_0`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
), `bfcte_1` AS (
6+
SELECT
7+
*,
8+
CONCAT(`bfcol_0`, 'a') AS `bfcol_1`
9+
FROM `bfcte_0`
10+
)
11+
SELECT
12+
`bfcol_1` AS `string_col`
13+
FROM `bfcte_1`
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`date_col` AS `bfcol_0`,
4+
`rowindex` AS `bfcol_1`,
5+
`timestamp_col` AS `bfcol_2`
6+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
7+
), `bfcte_1` AS (
8+
SELECT
9+
*,
10+
`bfcol_1` AS `bfcol_6`,
11+
`bfcol_2` AS `bfcol_7`,
12+
`bfcol_0` AS `bfcol_8`,
13+
TIMESTAMP_ADD(CAST(`bfcol_0` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `bfcol_9`
14+
FROM `bfcte_0`
15+
), `bfcte_2` AS (
16+
SELECT
17+
*,
18+
`bfcol_6` AS `bfcol_14`,
19+
`bfcol_7` AS `bfcol_15`,
20+
`bfcol_8` AS `bfcol_16`,
21+
`bfcol_9` AS `bfcol_17`,
22+
TIMESTAMP_ADD(`bfcol_7`, INTERVAL 86400000000 MICROSECOND) AS `bfcol_18`
23+
FROM `bfcte_1`
24+
), `bfcte_3` AS (
25+
SELECT
26+
*,
27+
`bfcol_14` AS `bfcol_24`,
28+
`bfcol_15` AS `bfcol_25`,
29+
`bfcol_16` AS `bfcol_26`,
30+
`bfcol_17` AS `bfcol_27`,
31+
`bfcol_18` AS `bfcol_28`,
32+
TIMESTAMP_ADD(CAST(`bfcol_16` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `bfcol_29`
33+
FROM `bfcte_2`
34+
), `bfcte_4` AS (
35+
SELECT
36+
*,
37+
`bfcol_24` AS `bfcol_36`,
38+
`bfcol_25` AS `bfcol_37`,
39+
`bfcol_26` AS `bfcol_38`,
40+
`bfcol_27` AS `bfcol_39`,
41+
`bfcol_28` AS `bfcol_40`,
42+
`bfcol_29` AS `bfcol_41`,
43+
TIMESTAMP_ADD(`bfcol_25`, INTERVAL 86400000000 MICROSECOND) AS `bfcol_42`
44+
FROM `bfcte_3`
45+
), `bfcte_5` AS (
46+
SELECT
47+
*,
48+
172800000000 AS `bfcol_50`
49+
FROM `bfcte_4`
50+
)
51+
SELECT
52+
`bfcol_36` AS `rowindex`,
53+
`bfcol_37` AS `timestamp_col`,
54+
`bfcol_38` AS `date_col`,
55+
`bfcol_39` AS `date_add_timedelta`,
56+
`bfcol_40` AS `timestamp_add_timedelta`,
57+
`bfcol_41` AS `timedelta_add_date`,
58+
`bfcol_42` AS `timedelta_add_timestamp`,
59+
`bfcol_50` AS `timedelta_add_timedelta`
60+
FROM `bfcte_5`

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

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,43 @@ WITH `bfcte_0` AS (
3838
`bfcol_8` AS `bfcol_16`,
3939
`bfcol_9` AS `bfcol_17`,
4040
CASE
41-
WHEN -`bfcol_7` = CAST(0 AS INT64)
41+
WHEN -(
42+
`bfcol_7`
43+
) = CAST(0 AS INT64)
4244
THEN CAST(0 AS INT64) * `bfcol_7`
43-
WHEN -`bfcol_7` < CAST(0 AS INT64)
45+
WHEN -(
46+
`bfcol_7`
47+
) < CAST(0 AS INT64)
4448
AND (
45-
MOD(`bfcol_7`, -`bfcol_7`)
49+
MOD(`bfcol_7`, -(
50+
`bfcol_7`
51+
))
4652
) > CAST(0 AS INT64)
47-
THEN -`bfcol_7` + (
48-
MOD(`bfcol_7`, -`bfcol_7`)
53+
THEN -(
54+
`bfcol_7`
55+
) + (
56+
MOD(`bfcol_7`, -(
57+
`bfcol_7`
58+
))
4959
)
50-
WHEN -`bfcol_7` > CAST(0 AS INT64)
60+
WHEN -(
61+
`bfcol_7`
62+
) > CAST(0 AS INT64)
5163
AND (
52-
MOD(`bfcol_7`, -`bfcol_7`)
64+
MOD(`bfcol_7`, -(
65+
`bfcol_7`
66+
))
5367
) < CAST(0 AS INT64)
54-
THEN -`bfcol_7` + (
55-
MOD(`bfcol_7`, -`bfcol_7`)
68+
THEN -(
69+
`bfcol_7`
70+
) + (
71+
MOD(`bfcol_7`, -(
72+
`bfcol_7`
73+
))
5674
)
57-
ELSE MOD(`bfcol_7`, -`bfcol_7`)
75+
ELSE MOD(`bfcol_7`, -(
76+
`bfcol_7`
77+
))
5878
END AS `bfcol_18`
5979
FROM `bfcte_1`
6080
), `bfcte_3` AS (
@@ -152,23 +172,43 @@ WITH `bfcte_0` AS (
152172
`bfcol_56` AS `bfcol_72`,
153173
`bfcol_57` AS `bfcol_73`,
154174
CASE
155-
WHEN CAST(-`bfcol_52` AS BIGNUMERIC) = CAST(0 AS INT64)
175+
WHEN CAST(-(
176+
`bfcol_52`
177+
) AS BIGNUMERIC) = CAST(0 AS INT64)
156178
THEN CAST('NaN' AS FLOAT64) * CAST(`bfcol_52` AS BIGNUMERIC)
157-
WHEN CAST(-`bfcol_52` AS BIGNUMERIC) < CAST(0 AS INT64)
179+
WHEN CAST(-(
180+
`bfcol_52`
181+
) AS BIGNUMERIC) < CAST(0 AS INT64)
158182
AND (
159-
MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-`bfcol_52` AS BIGNUMERIC))
183+
MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-(
184+
`bfcol_52`
185+
) AS BIGNUMERIC))
160186
) > CAST(0 AS INT64)
161-
THEN CAST(-`bfcol_52` AS BIGNUMERIC) + (
162-
MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-`bfcol_52` AS BIGNUMERIC))
187+
THEN CAST(-(
188+
`bfcol_52`
189+
) AS BIGNUMERIC) + (
190+
MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-(
191+
`bfcol_52`
192+
) AS BIGNUMERIC))
163193
)
164-
WHEN CAST(-`bfcol_52` AS BIGNUMERIC) > CAST(0 AS INT64)
194+
WHEN CAST(-(
195+
`bfcol_52`
196+
) AS BIGNUMERIC) > CAST(0 AS INT64)
165197
AND (
166-
MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-`bfcol_52` AS BIGNUMERIC))
198+
MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-(
199+
`bfcol_52`
200+
) AS BIGNUMERIC))
167201
) < CAST(0 AS INT64)
168-
THEN CAST(-`bfcol_52` AS BIGNUMERIC) + (
169-
MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-`bfcol_52` AS BIGNUMERIC))
202+
THEN CAST(-(
203+
`bfcol_52`
204+
) AS BIGNUMERIC) + (
205+
MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-(
206+
`bfcol_52`
207+
) AS BIGNUMERIC))
170208
)
171-
ELSE MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-`bfcol_52` AS BIGNUMERIC))
209+
ELSE MOD(CAST(`bfcol_52` AS BIGNUMERIC), CAST(-(
210+
`bfcol_52`
211+
) AS BIGNUMERIC))
172212
END AS `bfcol_74`
173213
FROM `bfcte_5`
174214
), `bfcte_7` AS (
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col` AS `bfcol_0`,
4+
`rowindex` AS `bfcol_1`,
5+
`timestamp_col` AS `bfcol_2`,
6+
`duration_col` AS `bfcol_3`
7+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
8+
), `bfcte_1` AS (
9+
SELECT
10+
*,
11+
`bfcol_1` AS `bfcol_8`,
12+
`bfcol_2` AS `bfcol_9`,
13+
`bfcol_0` AS `bfcol_10`,
14+
`bfcol_3` AS `bfcol_11`
15+
FROM `bfcte_0`
16+
), `bfcte_2` AS (
17+
SELECT
18+
*,
19+
`bfcol_8` AS `bfcol_16`,
20+
`bfcol_9` AS `bfcol_17`,
21+
`bfcol_10` AS `bfcol_18`,
22+
`bfcol_11` AS `bfcol_19`,
23+
CAST(FLOOR(`bfcol_11` * `bfcol_10`) AS INT64) AS `bfcol_20`
24+
FROM `bfcte_1`
25+
), `bfcte_3` AS (
26+
SELECT
27+
*,
28+
`bfcol_16` AS `bfcol_26`,
29+
`bfcol_17` AS `bfcol_27`,
30+
`bfcol_18` AS `bfcol_28`,
31+
`bfcol_19` AS `bfcol_29`,
32+
`bfcol_20` AS `bfcol_30`,
33+
CAST(FLOOR(`bfcol_18` * `bfcol_19`) AS INT64) AS `bfcol_31`
34+
FROM `bfcte_2`
35+
)
36+
SELECT
37+
`bfcol_26` AS `rowindex`,
38+
`bfcol_27` AS `timestamp_col`,
39+
`bfcol_28` AS `int64_col`,
40+
`bfcol_29` AS `duration_col`,
41+
`bfcol_30` AS `timedelta_mul_numeric`,
42+
`bfcol_31` AS `numeric_mul_timedelta`
43+
FROM `bfcte_3`

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
-`bfcol_0` AS `bfcol_1`
8+
-(
9+
`bfcol_0`
10+
) AS `bfcol_1`
911
FROM `bfcte_0`
1012
)
1113
SELECT
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`date_col` AS `bfcol_0`,
4+
`rowindex` AS `bfcol_1`,
5+
`timestamp_col` AS `bfcol_2`,
6+
`duration_col` AS `bfcol_3`
7+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
8+
), `bfcte_1` AS (
9+
SELECT
10+
*,
11+
`bfcol_1` AS `bfcol_8`,
12+
`bfcol_2` AS `bfcol_9`,
13+
`bfcol_0` AS `bfcol_10`,
14+
`bfcol_3` AS `bfcol_11`
15+
FROM `bfcte_0`
16+
), `bfcte_2` AS (
17+
SELECT
18+
*,
19+
`bfcol_8` AS `bfcol_16`,
20+
`bfcol_9` AS `bfcol_17`,
21+
`bfcol_11` AS `bfcol_18`,
22+
`bfcol_10` AS `bfcol_19`,
23+
TIMESTAMP_SUB(CAST(`bfcol_10` AS DATETIME), INTERVAL `bfcol_11` MICROSECOND) AS `bfcol_20`
24+
FROM `bfcte_1`
25+
), `bfcte_3` AS (
26+
SELECT
27+
*,
28+
`bfcol_16` AS `bfcol_26`,
29+
`bfcol_17` AS `bfcol_27`,
30+
`bfcol_18` AS `bfcol_28`,
31+
`bfcol_19` AS `bfcol_29`,
32+
`bfcol_20` AS `bfcol_30`,
33+
TIMESTAMP_SUB(`bfcol_17`, INTERVAL `bfcol_18` MICROSECOND) AS `bfcol_31`
34+
FROM `bfcte_2`
35+
), `bfcte_4` AS (
36+
SELECT
37+
*,
38+
`bfcol_26` AS `bfcol_38`,
39+
`bfcol_27` AS `bfcol_39`,
40+
`bfcol_28` AS `bfcol_40`,
41+
`bfcol_29` AS `bfcol_41`,
42+
`bfcol_30` AS `bfcol_42`,
43+
`bfcol_31` AS `bfcol_43`,
44+
TIMESTAMP_DIFF(CAST(`bfcol_29` AS DATETIME), CAST(`bfcol_29` AS DATETIME), MICROSECOND) AS `bfcol_44`
45+
FROM `bfcte_3`
46+
), `bfcte_5` AS (
47+
SELECT
48+
*,
49+
`bfcol_38` AS `bfcol_52`,
50+
`bfcol_39` AS `bfcol_53`,
51+
`bfcol_40` AS `bfcol_54`,
52+
`bfcol_41` AS `bfcol_55`,
53+
`bfcol_42` AS `bfcol_56`,
54+
`bfcol_43` AS `bfcol_57`,
55+
`bfcol_44` AS `bfcol_58`,
56+
TIMESTAMP_DIFF(`bfcol_39`, `bfcol_39`, MICROSECOND) AS `bfcol_59`
57+
FROM `bfcte_4`
58+
), `bfcte_6` AS (
59+
SELECT
60+
*,
61+
`bfcol_52` AS `bfcol_68`,
62+
`bfcol_53` AS `bfcol_69`,
63+
`bfcol_54` AS `bfcol_70`,
64+
`bfcol_55` AS `bfcol_71`,
65+
`bfcol_56` AS `bfcol_72`,
66+
`bfcol_57` AS `bfcol_73`,
67+
`bfcol_58` AS `bfcol_74`,
68+
`bfcol_59` AS `bfcol_75`,
69+
`bfcol_54` - `bfcol_54` AS `bfcol_76`
70+
FROM `bfcte_5`
71+
)
72+
SELECT
73+
`bfcol_68` AS `rowindex`,
74+
`bfcol_69` AS `timestamp_col`,
75+
`bfcol_70` AS `duration_col`,
76+
`bfcol_71` AS `date_col`,
77+
`bfcol_72` AS `date_sub_timedelta`,
78+
`bfcol_73` AS `timestamp_sub_timedelta`,
79+
`bfcol_74` AS `timestamp_sub_date`,
80+
`bfcol_75` AS `date_sub_timestamp`,
81+
`bfcol_76` AS `timedelta_sub_timedelta`
82+
FROM `bfcte_6`

0 commit comments

Comments
 (0)