|
15 | 15 | """Unit tests for read_gbq_table helper functions.""" |
16 | 16 |
|
17 | 17 | import unittest.mock as mock |
| 18 | +import warnings |
18 | 19 |
|
19 | 20 | import google.cloud.bigquery |
20 | 21 | import pytest |
21 | 22 |
|
| 23 | +import bigframes.enums |
| 24 | +import bigframes.exceptions |
22 | 25 | import bigframes.session._io.bigquery.read_gbq_table as bf_read_gbq_table |
23 | 26 | from bigframes.testing import mocks |
24 | 27 |
|
@@ -143,3 +146,43 @@ def test_check_if_index_columns_are_unique(index_cols, values_distinct, expected |
143 | 146 | ) |
144 | 147 |
|
145 | 148 | assert result == expected |
| 149 | + |
| 150 | + |
| 151 | +def test_get_index_cols_warns_if_clustered_but_sequential_index(): |
| 152 | + table = google.cloud.bigquery.Table.from_api_repr( |
| 153 | + { |
| 154 | + "tableReference": { |
| 155 | + "projectId": "my-project", |
| 156 | + "datasetId": "my_dataset", |
| 157 | + "tableId": "my_table", |
| 158 | + }, |
| 159 | + "clustering": { |
| 160 | + "fields": ["col1", "col2"], |
| 161 | + }, |
| 162 | + }, |
| 163 | + ) |
| 164 | + table.schema = ( |
| 165 | + google.cloud.bigquery.SchemaField("col1", "INT64"), |
| 166 | + google.cloud.bigquery.SchemaField("col2", "INT64"), |
| 167 | + google.cloud.bigquery.SchemaField("col3", "INT64"), |
| 168 | + google.cloud.bigquery.SchemaField("col4", "INT64"), |
| 169 | + ) |
| 170 | + |
| 171 | + with pytest.warns(bigframes.exceptions.DefaultIndexWarning, match="is clustered"): |
| 172 | + bf_read_gbq_table.get_index_cols( |
| 173 | + table, |
| 174 | + index_col=(), |
| 175 | + default_index_type=bigframes.enums.DefaultIndexKind.SEQUENTIAL_INT64, |
| 176 | + ) |
| 177 | + |
| 178 | + # Ensure that we don't raise if using a NULL index by default, such as in |
| 179 | + # partial ordering mode. See: internal issue b/356872356. |
| 180 | + with warnings.catch_warnings(): |
| 181 | + warnings.simplefilter( |
| 182 | + "error", category=bigframes.exceptions.DefaultIndexWarning |
| 183 | + ) |
| 184 | + bf_read_gbq_table.get_index_cols( |
| 185 | + table, |
| 186 | + index_col=(), |
| 187 | + default_index_type=bigframes.enums.DefaultIndexKind.NULL, |
| 188 | + ) |
0 commit comments