|
18 | 18 | import pytest |
19 | 19 | import sqlglot.expressions as sge |
20 | 20 |
|
| 21 | +from bigframes import dtypes |
21 | 22 | from bigframes.core import window_spec |
22 | 23 | from bigframes.core.compile.sqlglot.aggregations.windows import ( |
23 | 24 | apply_window_if_present, |
24 | 25 | get_window_order_by, |
25 | 26 | ) |
26 | 27 | import bigframes.core.expression as ex |
| 28 | +import bigframes.core.identifiers as ids |
27 | 29 | import bigframes.core.ordering as ordering |
28 | 30 |
|
29 | 31 |
|
@@ -82,16 +84,37 @@ def test_apply_window_if_present_row_bounded_no_ordering_raises(self): |
82 | 84 | ), |
83 | 85 | ) |
84 | 86 |
|
85 | | - def test_apply_window_if_present_unbounded_grouping_no_ordering(self): |
| 87 | + def test_apply_window_if_present_grouping_no_ordering(self): |
86 | 88 | result = apply_window_if_present( |
87 | 89 | sge.Var(this="value"), |
88 | 90 | window_spec.WindowSpec( |
89 | | - grouping_keys=(ex.deref("col1"),), |
| 91 | + grouping_keys=( |
| 92 | + ex.ResolvedDerefOp( |
| 93 | + ids.ColumnId("col1"), |
| 94 | + dtype=dtypes.STRING_DTYPE, |
| 95 | + is_nullable=True, |
| 96 | + ), |
| 97 | + ex.ResolvedDerefOp( |
| 98 | + ids.ColumnId("col2"), |
| 99 | + dtype=dtypes.FLOAT_DTYPE, |
| 100 | + is_nullable=True, |
| 101 | + ), |
| 102 | + ex.ResolvedDerefOp( |
| 103 | + ids.ColumnId("col3"), |
| 104 | + dtype=dtypes.JSON_DTYPE, |
| 105 | + is_nullable=True, |
| 106 | + ), |
| 107 | + ex.ResolvedDerefOp( |
| 108 | + ids.ColumnId("col4"), |
| 109 | + dtype=dtypes.GEO_DTYPE, |
| 110 | + is_nullable=True, |
| 111 | + ), |
| 112 | + ), |
90 | 113 | ), |
91 | 114 | ) |
92 | 115 | self.assertEqual( |
93 | 116 | result.sql(dialect="bigquery"), |
94 | | - "value OVER (PARTITION BY `col1`)", |
| 117 | + "value OVER (PARTITION BY `col1`, CAST(`col2` AS STRING), TO_JSON_STRING(`col3`), CAST(`col4` AS BYTES))", |
95 | 118 | ) |
96 | 119 |
|
97 | 120 | def test_apply_window_if_present_range_bounded(self): |
@@ -126,8 +149,22 @@ def test_apply_window_if_present_all_params(self): |
126 | 149 | result = apply_window_if_present( |
127 | 150 | sge.Var(this="value"), |
128 | 151 | window_spec.WindowSpec( |
129 | | - grouping_keys=(ex.deref("col1"),), |
130 | | - ordering=(ordering.OrderingExpression(ex.deref("col2")),), |
| 152 | + grouping_keys=( |
| 153 | + ex.ResolvedDerefOp( |
| 154 | + ids.ColumnId("col1"), |
| 155 | + dtype=dtypes.STRING_DTYPE, |
| 156 | + is_nullable=True, |
| 157 | + ), |
| 158 | + ), |
| 159 | + ordering=( |
| 160 | + ordering.OrderingExpression( |
| 161 | + ex.ResolvedDerefOp( |
| 162 | + ids.ColumnId("col2"), |
| 163 | + dtype=dtypes.STRING_DTYPE, |
| 164 | + is_nullable=True, |
| 165 | + ) |
| 166 | + ), |
| 167 | + ), |
131 | 168 | bounds=window_spec.RowsWindowBounds(start=-1, end=0), |
132 | 169 | ), |
133 | 170 | ) |
|
0 commit comments