Skip to content

Commit ab29b75

Browse files
committed
create a name to id mapping
1 parent b31c667 commit ab29b75

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ WITH `bfcte_0` AS (
66
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
77
), `bfcte_1` AS (
88
SELECT
9-
AVG(`bfcol_1`) AS `bfcol_6`,
10-
AVG(CAST(`bfcol_0` AS INT64)) AS `bfcol_7`,
11-
AVG(`bfcol_2`) AS `bfcol_8`,
12-
FLOOR(AVG(`bfcol_1`)) AS `bfcol_9`
9+
*,
10+
`bfcol_1` AS `bfcol_6`,
11+
`bfcol_0` AS `bfcol_7`,
12+
`bfcol_2` AS `bfcol_8`
1313
FROM `bfcte_0`
14+
), `bfcte_2` AS (
15+
SELECT
16+
AVG(`bfcol_6`) AS `bfcol_12`,
17+
AVG(CAST(`bfcol_7` AS INT64)) AS `bfcol_13`,
18+
FLOOR(AVG(`bfcol_8`)) AS `bfcol_14`,
19+
FLOOR(AVG(`bfcol_6`)) AS `bfcol_15`
20+
FROM `bfcte_1`
1421
)
1522
SELECT
16-
`bfcol_6` AS `int64_col`,
17-
`bfcol_7` AS `bool_col`,
18-
`bfcol_8` AS `duration_col`,
19-
`bfcol_9` AS `int64_col_w_floor`
20-
FROM `bfcte_1`
23+
`bfcol_12` AS `int64_col`,
24+
`bfcol_13` AS `bool_col`,
25+
`bfcol_14` AS `duration_col`,
26+
`bfcol_15` AS `int64_col_w_floor`
27+
FROM `bfcte_2`

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,24 @@ def test_max(scalar_types_df: bpd.DataFrame, snapshot):
5757

5858

5959
def test_mean(scalar_types_df: bpd.DataFrame, snapshot):
60-
# bf_df = scalar_types_df[["int64_col", "bool_col", "duration_col"]]
61-
bf_df = scalar_types_df[["duration_col"]]
60+
col_names = ["int64_col", "bool_col", "duration_col"]
61+
bf_df = scalar_types_df[col_names]
6262
bf_df["duration_col"] = bpd.to_timedelta(bf_df["duration_col"], unit="us")
6363

64+
# to_timedelta creates a new mapping for expression.
65+
col_names.insert(0, "rowindex")
66+
name2id = {
67+
col_name: col_id
68+
for col_name, col_id in zip(col_names, bf_df._block.expr.column_ids)
69+
}
70+
6471
agg_ops_map = {
65-
# "int64_col": agg_ops.MeanOp().as_expr("int64_col"),
66-
# "bool_col": agg_ops.MeanOp().as_expr("bool_col"),
67-
"duration_col": agg_ops.MeanOp().as_expr("duration_col"),
68-
# "int64_col_w_floor": agg_ops.MeanOp(should_floor_result=True).as_expr(
69-
# "int64_col"
70-
# ),
72+
"int64_col": agg_ops.MeanOp().as_expr(name2id["int64_col"]),
73+
"bool_col": agg_ops.MeanOp().as_expr(name2id["bool_col"]),
74+
"duration_col": agg_ops.MeanOp().as_expr(name2id["duration_col"]),
75+
"int64_col_w_floor": agg_ops.MeanOp(should_floor_result=True).as_expr(
76+
name2id["int64_col"]
77+
),
7178
}
7279
sql = _apply_unary_agg_ops(
7380
bf_df, list(agg_ops_map.values()), list(agg_ops_map.keys())

0 commit comments

Comments
 (0)