@@ -109,7 +109,7 @@ def _get_most_populated_partitions(
109
109
110
110
logger .debug (f"Executing combined partition query: { query } " )
111
111
query_job = self .config .get_bigquery_client ().query (query )
112
- results = list (query_job .result (timeout = timeout ))
112
+ results = list (query_job .result ())
113
113
114
114
if results :
115
115
# Take the partition combination with the most records
@@ -184,7 +184,7 @@ def _get_most_populated_partitions(
184
184
f"Executing query for partition column { col_name } : { query } "
185
185
)
186
186
query_job = self .config .get_bigquery_client ().query (query )
187
- results = list (query_job .result (timeout = timeout ))
187
+ results = list (query_job .result ())
188
188
189
189
if not results or results [0 ].val is None :
190
190
logger .warning (
@@ -334,7 +334,7 @@ def _create_filter_for_partition_column(
334
334
335
335
try :
336
336
query_job = self .config .get_bigquery_client ().query (query )
337
- results = list (query_job .result (timeout = timeout ))
337
+ results = list (query_job .result ())
338
338
339
339
if not results or results [0 ].val is None :
340
340
logger .warning (
@@ -459,7 +459,7 @@ def _try_partition_combinations(
459
459
schema : str ,
460
460
partition_cols : List [str ],
461
461
partition_cols_with_types : Dict [str , str ],
462
- timeout : int = 300 ,
462
+ timeout : int = 300 , # This parameter will be ignored
463
463
) -> Optional [List [str ]]:
464
464
"""
465
465
Try to find combinations of partition values that return data.
@@ -470,7 +470,7 @@ def _try_partition_combinations(
470
470
schema: BigQuery dataset name
471
471
partition_cols: List of partition column names
472
472
partition_cols_with_types: Dictionary of column names to data types
473
- timeout: Query timeout in seconds
473
+ timeout: Parameter retained for API compatibility but not used
474
474
475
475
Returns:
476
476
List of filter strings if found, None otherwise
@@ -494,10 +494,35 @@ def _try_partition_combinations(
494
494
"""
495
495
496
496
logger .debug (f"Finding partition combinations: { query } " )
497
- query_job = self .config .get_bigquery_client ().query (query )
498
- results = list (query_job .result (timeout = timeout ))
499
497
498
+ try :
499
+ query_job = self .config .get_bigquery_client ().query (query )
500
+ # Call result() without a timeout parameter
501
+ results = list (query_job .result ())
502
+ except Exception as e :
503
+ logger .warning (f"Error querying partition combinations: { e } " )
504
+ try :
505
+ # Try a simpler version of the query
506
+ simplified_query = f"""
507
+ SELECT { partition_cols_select } , COUNT(*) as record_count
508
+ FROM `{ project } .{ schema } .{ table .name } `
509
+ WHERE { partition_cols [0 ]} IS NOT NULL
510
+ GROUP BY { partition_cols_select }
511
+ ORDER BY record_count DESC
512
+ LIMIT 5
513
+ """
514
+ logger .info (f"Trying simplified query: { simplified_query } " )
515
+ simplified_job = self .config .get_bigquery_client ().query (
516
+ simplified_query
517
+ )
518
+ results = list (simplified_job .result ())
519
+ except Exception as simplified_error :
520
+ logger .warning (f"Simplified query also failed: { simplified_error } " )
521
+ return None
522
+
523
+ # If the query returned no results
500
524
if not results :
525
+ logger .warning ("No partition combinations found" )
501
526
return None
502
527
503
528
# Try each combination, starting with the one with most records
@@ -683,7 +708,7 @@ def _try_column_with_different_orderings(
683
708
logger .info (f"Executing fallback query with { order_by } ordering" )
684
709
try :
685
710
query_job = self .config .get_bigquery_client ().query (query )
686
- results = list (query_job .result (timeout = timeout ))
711
+ results = list (query_job .result ())
687
712
688
713
if results :
689
714
logger .info (f"Query returned { len (results )} potential values" )
@@ -759,7 +784,7 @@ def _try_get_most_recent_partition(
759
784
"""
760
785
761
786
query_job = self .config .get_bigquery_client ().query (query )
762
- results = list (query_job .result (timeout = timeout ))
787
+ results = list (query_job .result ())
763
788
764
789
if results and len (results ) > 0 :
765
790
for col_name in partition_cols_with_types :
@@ -809,7 +834,7 @@ def _try_find_most_populated_partition(
809
834
810
835
try :
811
836
query_job = self .config .get_bigquery_client ().query (query )
812
- results = list (query_job .result (timeout = timeout ))
837
+ results = list (query_job .result ())
813
838
814
839
if (
815
840
results
@@ -960,7 +985,7 @@ def _verify_partition_has_data(
960
985
961
986
# Set a longer timeout for this operation
962
987
query_job = self .config .get_bigquery_client ().query (query )
963
- results = list (query_job .result (timeout = timeout ))
988
+ results = list (query_job .result ())
964
989
965
990
if results and results [0 ].cnt > 0 :
966
991
logger .info (
@@ -982,7 +1007,7 @@ def _verify_partition_has_data(
982
1007
LIMIT 1
983
1008
"""
984
1009
query_job = self .config .get_bigquery_client ().query (simpler_query )
985
- results = list (query_job .result (timeout = timeout ))
1010
+ results = list (query_job .result ())
986
1011
987
1012
return len (results ) > 0
988
1013
except Exception as simple_e :
@@ -1112,7 +1137,7 @@ def _get_required_partition_filters(
1112
1137
logger .debug (f"Executing query for partition value: { query } " )
1113
1138
1114
1139
query_job = self .config .get_bigquery_client ().query (query )
1115
- results = list (query_job .result (timeout = 300 ))
1140
+ results = list (query_job .result ())
1116
1141
1117
1142
if not results or results [0 ].val is None :
1118
1143
logger .warning (
0 commit comments