Skip to content

Commit de46d2f

Browse files
fix: Fix read_gbq with ORDER BY query and index_col set (#963)
* fix: Fix read_gbq with ORDER BY query and index_col set * add integration test --------- Co-authored-by: Tim Sweña (Swast) <[email protected]>
1 parent 2b5a44e commit de46d2f

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

bigframes/core/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,7 @@ def _get_rows_as_json_values(self) -> Block:
26162616
# The only ways this code is used is through df.apply(axis=1) cope path
26172617
# TODO: Stop using internal API
26182618
destination, query_job = self.session._loader._query_to_destination(
2619-
json_sql, index_cols=[ordering_column_name], api_name="apply"
2619+
json_sql, cluster_candidates=[ordering_column_name], api_name="apply"
26202620
)
26212621
if not destination:
26222622
raise ValueError(f"Query job {query_job} did not produce result table")

bigframes/session/loader.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,10 @@ def read_gbq_query(
606606
time_travel_timestamp=None,
607607
)
608608

609+
# No cluster candidates as user query might not be clusterable (eg because of ORDER BY clause)
609610
destination, query_job = self._query_to_destination(
610611
query,
611-
index_cols,
612+
cluster_candidates=[],
612613
api_name=api_name,
613614
configuration=configuration,
614615
)
@@ -645,7 +646,7 @@ def read_gbq_query(
645646
def _query_to_destination(
646647
self,
647648
query: str,
648-
index_cols: List[str],
649+
cluster_candidates: List[str],
649650
api_name: str,
650651
configuration: dict = {"query": {"useQueryCache": True}},
651652
do_clustering=True,
@@ -668,7 +669,7 @@ def _query_to_destination(
668669
assert schema is not None
669670
if do_clustering:
670671
cluster_cols = bf_io_bigquery.select_cluster_cols(
671-
schema, cluster_candidates=index_cols
672+
schema, cluster_candidates=cluster_candidates
672673
)
673674
else:
674675
cluster_cols = []

tests/system/small/test_session.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ def test_read_gbq_w_unknown_index_col(
132132
CONCAT(t.string_col, "_2") AS my_strings,
133133
t.int64_col > 0 AS my_bools,
134134
FROM `{scalars_table_id}` AS t
135+
ORDER BY my_strings
135136
""",
136137
["my_strings"],
137-
id="string_index",
138+
id="string_index_w_order_by",
138139
),
139140
pytest.param(
140141
"SELECT GENERATE_UUID() AS uuid, 0 AS my_value FROM UNNEST(GENERATE_ARRAY(1, 20))",

0 commit comments

Comments
 (0)