GeezerVison is showing github.com — fix: do not warn with DefaultIndexWarning in partial ordering mode (#… · google/bigframes@cc2dbae
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bigframes/session/_io/bigquery/read_gbq_table.py +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -402,6 +402,7 @@ def get_index_cols( | 402 | 402 | | bigframes.enums.DefaultIndexKind, | 403 | 403 | *, | 404 | 404 | rename_to_schema: Optional[Dict[str, str]] = None, | | 405 | + default_index_type: bigframes.enums.DefaultIndexKind = bigframes.enums.DefaultIndexKind.SEQUENTIAL_INT64, | 405 | 406 | ) -> List[str]: | 406 | 407 | """ | 407 | 408 | If we can get a total ordering from the table, such as via primary key | @@ -471,7 +472,11 @@ def get_index_cols( | 471 | 472 | # find index_cols to use. This is to avoid unexpected performance and | 472 | 473 | # resource utilization because of the default sequential index. See | 473 | 474 | # internal issue 335727141. | 474 | | - if _is_table_clustered_or_partitioned(table) and not primary_keys: | | 475 | + if ( | | 476 | + _is_table_clustered_or_partitioned(table) | | 477 | + and not primary_keys | | 478 | + and default_index_type == bigframes.enums.DefaultIndexKind.SEQUENTIAL_INT64 | | 479 | + ): | 475 | 480 | msg = bfe.format_message( | 476 | 481 | f"Table '{str(table.reference)}' is clustered and/or " | 477 | 482 | "partitioned, but BigQuery DataFrames was not able to find a " | |
Collapse file Copy file name to clipboardExpand all lines: bigframes/session/loader.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -696,6 +696,7 @@ def read_gbq_table( | 696 | 696 | table=table, | 697 | 697 | index_col=index_col, | 698 | 698 | rename_to_schema=rename_to_schema, | | 699 | + default_index_type=self._default_index_type, | 699 | 700 | ) | 700 | 701 | _check_index_col_param( | 701 | 702 | index_cols, | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/session/test_read_gbq_table.py +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 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 | + ) |
|