Skip to content

Commit 08158a5

Browse files
committed
address comments
1 parent fb5e036 commit 08158a5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
187187

188188
@UNARY_OP_REGISTRATION.register(ops.dayofweek_op)
189189
def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
190-
return sge.Extract(this=sge.Identifier(this="DAYOFWEEK"), expression=expr.expr)
190+
# Adjust the 1-based day-of-week index (from SQL) to a 0-based index.
191+
return sge.Extract(
192+
this=sge.Identifier(this="DAYOFWEEK"), expression=expr.expr
193+
) - sge.convert(1)
191194

192195

193196
@UNARY_OP_REGISTRATION.register(ops.dayofyear_op)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
EXTRACT(DAYOFWEEK FROM `bfcol_0`) AS `bfcol_1`
8+
EXTRACT(DAYOFWEEK FROM `bfcol_0`) + 1 AS `bfcol_1`
99
FROM `bfcte_0`
1010
)
1111
SELECT

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def _apply_unary_op(obj: bpd.DataFrame, op: ops.UnaryOp, arg: str) -> str:
3737
def test_arccosh(scalar_types_df: bpd.DataFrame, snapshot):
3838
bf_df = scalar_types_df[["float64_col"]]
3939
sql = _apply_unary_op(bf_df, ops.arccosh_op, "float64_col")
40+
4041
snapshot.assert_match(sql, "out.sql")
4142

4243

@@ -57,6 +58,7 @@ def test_arcsin(scalar_types_df: bpd.DataFrame, snapshot):
5758
def test_arcsinh(scalar_types_df: bpd.DataFrame, snapshot):
5859
bf_df = scalar_types_df[["float64_col"]]
5960
sql = _apply_unary_op(bf_df, ops.arcsinh_op, "float64_col")
61+
6062
snapshot.assert_match(sql, "out.sql")
6163

6264

@@ -70,18 +72,21 @@ def test_arctan(scalar_types_df: bpd.DataFrame, snapshot):
7072
def test_arctanh(scalar_types_df: bpd.DataFrame, snapshot):
7173
bf_df = scalar_types_df[["float64_col"]]
7274
sql = _apply_unary_op(bf_df, ops.arctanh_op, "float64_col")
75+
7376
snapshot.assert_match(sql, "out.sql")
7477

7578

7679
def test_abs(scalar_types_df: bpd.DataFrame, snapshot):
7780
bf_df = scalar_types_df[["float64_col"]]
7881
sql = _apply_unary_op(bf_df, ops.abs_op, "float64_col")
82+
7983
snapshot.assert_match(sql, "out.sql")
8084

8185

8286
def test_capitalize(scalar_types_df: bpd.DataFrame, snapshot):
8387
bf_df = scalar_types_df[["string_col"]]
8488
sql = _apply_unary_op(bf_df, ops.capitalize_op, "string_col")
89+
8590
snapshot.assert_match(sql, "out.sql")
8691

8792

@@ -94,42 +99,49 @@ def test_ceil(scalar_types_df: bpd.DataFrame, snapshot):
9499
def test_date(scalar_types_df: bpd.DataFrame, snapshot):
95100
bf_df = scalar_types_df[["timestamp_col"]]
96101
sql = _apply_unary_op(bf_df, ops.date_op, "timestamp_col")
102+
97103
snapshot.assert_match(sql, "out.sql")
98104

99105

100106
def test_day(scalar_types_df: bpd.DataFrame, snapshot):
101107
bf_df = scalar_types_df[["timestamp_col"]]
102108
sql = _apply_unary_op(bf_df, ops.day_op, "timestamp_col")
109+
103110
snapshot.assert_match(sql, "out.sql")
104111

105112

106113
def test_dayofweek(scalar_types_df: bpd.DataFrame, snapshot):
107114
bf_df = scalar_types_df[["timestamp_col"]]
108115
sql = _apply_unary_op(bf_df, ops.dayofweek_op, "timestamp_col")
116+
109117
snapshot.assert_match(sql, "out.sql")
110118

111119

112120
def test_dayofyear(scalar_types_df: bpd.DataFrame, snapshot):
113121
bf_df = scalar_types_df[["timestamp_col"]]
114122
sql = _apply_unary_op(bf_df, ops.dayofyear_op, "timestamp_col")
123+
115124
snapshot.assert_match(sql, "out.sql")
116125

117126

118127
def test_exp(scalar_types_df: bpd.DataFrame, snapshot):
119128
bf_df = scalar_types_df[["float64_col"]]
120129
sql = _apply_unary_op(bf_df, ops.exp_op, "float64_col")
130+
121131
snapshot.assert_match(sql, "out.sql")
122132

123133

124134
def test_expm1(scalar_types_df: bpd.DataFrame, snapshot):
125135
bf_df = scalar_types_df[["float64_col"]]
126136
sql = _apply_unary_op(bf_df, ops.expm1_op, "float64_col")
137+
127138
snapshot.assert_match(sql, "out.sql")
128139

129140

130141
def test_floor(scalar_types_df: bpd.DataFrame, snapshot):
131142
bf_df = scalar_types_df[["float64_col"]]
132143
sql = _apply_unary_op(bf_df, ops.floor_op, "float64_col")
144+
133145
snapshot.assert_match(sql, "out.sql")
134146

135147

@@ -171,6 +183,7 @@ def test_cos(scalar_types_df: bpd.DataFrame, snapshot):
171183
def test_cosh(scalar_types_df: bpd.DataFrame, snapshot):
172184
bf_df = scalar_types_df[["float64_col"]]
173185
sql = _apply_unary_op(bf_df, ops.cosh_op, "float64_col")
186+
174187
snapshot.assert_match(sql, "out.sql")
175188

176189

@@ -219,6 +232,7 @@ def test_tan(scalar_types_df: bpd.DataFrame, snapshot):
219232
def test_tanh(scalar_types_df: bpd.DataFrame, snapshot):
220233
bf_df = scalar_types_df[["float64_col"]]
221234
sql = _apply_unary_op(bf_df, ops.tanh_op, "float64_col")
235+
222236
snapshot.assert_match(sql, "out.sql")
223237

224238

0 commit comments

Comments
 (0)