Skip to content

Commit

Permalink
-> None problems
Browse files Browse the repository at this point in the history
  • Loading branch information
s-paquette committed Dec 12, 2024
1 parent 1ae3b5e commit 6b7556d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cohorts/metadata_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,8 @@ def get_bq_metadata(inc_filters, fields, data_versions=None, data_type=None, sou
results = BigQuerySupport.execute_query_and_fetch_results(full_query_str, params, paginated=paginated)

stop = time.time()
results['elapsed_time'] = "{}s".format(str(stop-start))
if results:
results['elapsed_time'] = "{}s".format(str(stop-start))
logger.info("[STATUS] Exiting BQ metadata counter")

except Exception as e:
Expand Down
1 change: 0 additions & 1 deletion cohorts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def get_filters_for_counts(self, no_vals=False):
filters[prog_attr] = {'values': []} if not no_vals else []
vals = filters[prog_attr]['values'] if not no_vals else filters[prog_attr]
vals.extend(fltr.value.split(fltr.value_delimiter))

return filters

# Returns the set of filters defining this cohort as a dict organized by data source
Expand Down
16 changes: 7 additions & 9 deletions google_helpers/bigquery/bq_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,13 @@ def execute_query(self, query, parameters=None, write_disposition='WRITE_EMPTY',
'total_bytes_processed': query_job.total_bytes_processed
}

job_is_done_ = self.await_job_is_done(query_job)
query_job = self.await_job_is_done(query_job)

# Parse the final disposition
if job_is_done_.done():
if query_job.done():
if query_job.errors or query_job.error_result:
print(str(job_is_done_.error_result))
print(str(job_is_done_.errors))
job_is_done_.error_result and logger.error("[ERROR] During query job {}: {}".format(job_id, str(job_is_done_.error_result)))
job_is_done_.errors and logger.error("[ERROR] During query job {}: {}".format(job_id, str(job_is_done_.errors)))
query_job.error_result and logger.error("[ERROR] During query job {}: {}".format(job_id, str(query_job.error_result)))
query_job.errors and logger.error("[ERROR] During query job {}: {}".format(job_id, str(query_job.errors)))
logger.error("[ERROR] Error'd out query: {}".format(query))
else:
logger.info("[STATUS] Query {} done, fetching results...".format(job_id))
Expand All @@ -264,8 +262,8 @@ def execute_query(self, query, parameters=None, write_disposition='WRITE_EMPTY',
"If you check job ID {} manually you can wait for it to finish.".format(job_id))
logger.error("[ERROR] Timed out query: {}".format(query))

if job_is_done_.timeline and len(job_is_done_.timeline):
logger.debug("Elapsed: {}".format(str(job_is_done_.timeline[-1].elapsed_ms)))
if query_job.timeline and len(query_job.timeline):
logger.debug("Elapsed: {}".format(str(query_job.timeline[-1].elapsed_ms)))

return query_results

Expand Down Expand Up @@ -401,7 +399,7 @@ def get_table_preview(cls, projectId, datasetId, tableId, max_rows=8):
else:
raw_rows = bqs.bq_client.list_rows("{}.{}.{}".format(projectId, datasetId, tableId), max_results=max_rows)

if raw_rows.total_rows > 0:
if raw_rows and raw_rows.total_rows > 0:
result = {
'rows': [{key: val for key, val in x.items() } for x in raw_rows],
'status': 200
Expand Down

0 comments on commit 6b7556d

Please sign in to comment.