Skip to content

Commit 05cb6f9

Browse files
committed
bqnotify cleanup
1 parent 0d821aa commit 05cb6f9

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

composer/workflows/bq_notify.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,11 @@
4949
bq_dataset_name = 'airflow_bq_notify_dataset_{{ ds_nodash }}'
5050
bq_recent_questions_table_id = 'recent_questions'
5151
bq_most_popular_table_id = 'most_popular'
52-
output_file = '{gcs_bucket}/recent_questionsS.csv'.format(
53-
gcs_bucket=models.Variable.get('gcs_bucket'))
52+
gcs_bucket = models.Variable.get('gcs_bucket')
53+
output_file = f'{gcs_bucket}/recent_questionsS.csv'
5454
location = 'US'
5555
project_id = models.Variable.get('gcp_project')
5656

57-
# TODO: Update query dates
58-
# TODO: fix string formatting
59-
6057
# Data from the month of January 2018
6158
# You may change the query dates to get data from a different time range. You
6259
# may also dynamically pick a date range based on DAG schedule date. Airflow
@@ -66,27 +63,26 @@
6663
max_query_date = '2018-02-01'
6764
min_query_date = '2018-01-01'
6865

69-
RECENT_QUESTIONS_QUERY = """
66+
RECENT_QUESTIONS_QUERY = f"""
7067
SELECT owner_display_name, title, view_count
7168
FROM `bigquery-public-data.stackoverflow.posts_questions`
72-
WHERE creation_date < CAST('{max_date}' AS TIMESTAMP)
73-
AND creation_date >= CAST('{min_date}' AS TIMESTAMP)
69+
WHERE creation_date < CAST('{max_query_date}' AS TIMESTAMP)
70+
AND creation_date >= CAST('{min_query_date}' AS TIMESTAMP)
7471
ORDER BY view_count DESC
7572
LIMIT 100
76-
""".format(max_date=max_query_date, min_date=min_query_date)
73+
"""
7774

78-
MOST_POPULAR_QUERY = """
75+
MOST_POPULAR_QUERY = f"""
7976
SELECT title, view_count
80-
FROM `{table}`
77+
FROM `{project_id}.{bq_dataset_name}.{bq_recent_questions_table_id}`
8178
ORDER BY view_count DESC
8279
LIMIT 1
83-
""".format(table=project_id + "." + bq_dataset_name + "." + bq_recent_questions_table_id)
80+
"""
8481

8582
yesterday = datetime.datetime.combine(
8683
datetime.datetime.today() - datetime.timedelta(1),
8784
datetime.datetime.min.time())
8885

89-
# TODO: Add info about sendgrid operator config
9086
# [START composer_notify_failure]
9187
default_dag_args = {
9288
'start_date': yesterday,
@@ -111,8 +107,7 @@
111107
task_id='make_bq_dataset',
112108
# Executing 'bq' command requires Google Cloud SDK which comes
113109
# preinstalled in Cloud Composer.
114-
bash_command='bq ls {} || bq mk {}'.format(
115-
bq_dataset_name, bq_dataset_name))
110+
bash_command=f'bq ls {bq_dataset_name} || bq mk {bq_dataset_name}')
116111
# [END composer_bash_bq]
117112

118113
# [START composer_bigquery]
@@ -168,7 +163,7 @@
168163
table_id=bq_most_popular_table_id)
169164

170165
# [START composer_email]
171-
# Send email confirmation
166+
# Send email confirmation (you will need to set up the email operator)
172167
email_summary = email.EmailOperator(
173168
task_id='email_summary',
174169
to=models.Variable.get('email'),

0 commit comments

Comments
 (0)