Apache Airflow: print query success on logging info, query failure on logging.error
up vote
0
down vote
favorite
My question is regarding the logging of query successes or failure, done by the BigQueryOperator of Apache Airflow 1.10.0 I am wondering if it is possible to print query success on logging.info
, and if it is a failure to print on logging.error
?
from airflow.contrib.operators import bigquery_operator
# Query recent StackOverflow questions.
bq_recent_questions_query = bigquery_operator.BigQueryOperator(
task_id='bq_recent_questions_query',
bql="""
SELECT owner_display_name, title, view_count
FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE creation_date < CAST('{max_date}' AS TIMESTAMP)
AND creation_date >= CAST('{min_date}' AS TIMESTAMP)
ORDER BY view_count DESC
LIMIT 100
""".format(max_date=max_query_date, min_date=min_query_date),
use_legacy_sql=False,
destination_dataset_table=bq_recent_questions_table_id)
https://cloud.google.com/composer/docs/how-to/using/writing-dags
python google-bigquery airflow
add a comment |
up vote
0
down vote
favorite
My question is regarding the logging of query successes or failure, done by the BigQueryOperator of Apache Airflow 1.10.0 I am wondering if it is possible to print query success on logging.info
, and if it is a failure to print on logging.error
?
from airflow.contrib.operators import bigquery_operator
# Query recent StackOverflow questions.
bq_recent_questions_query = bigquery_operator.BigQueryOperator(
task_id='bq_recent_questions_query',
bql="""
SELECT owner_display_name, title, view_count
FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE creation_date < CAST('{max_date}' AS TIMESTAMP)
AND creation_date >= CAST('{min_date}' AS TIMESTAMP)
ORDER BY view_count DESC
LIMIT 100
""".format(max_date=max_query_date, min_date=min_query_date),
use_legacy_sql=False,
destination_dataset_table=bq_recent_questions_table_id)
https://cloud.google.com/composer/docs/how-to/using/writing-dags
python google-bigquery airflow
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My question is regarding the logging of query successes or failure, done by the BigQueryOperator of Apache Airflow 1.10.0 I am wondering if it is possible to print query success on logging.info
, and if it is a failure to print on logging.error
?
from airflow.contrib.operators import bigquery_operator
# Query recent StackOverflow questions.
bq_recent_questions_query = bigquery_operator.BigQueryOperator(
task_id='bq_recent_questions_query',
bql="""
SELECT owner_display_name, title, view_count
FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE creation_date < CAST('{max_date}' AS TIMESTAMP)
AND creation_date >= CAST('{min_date}' AS TIMESTAMP)
ORDER BY view_count DESC
LIMIT 100
""".format(max_date=max_query_date, min_date=min_query_date),
use_legacy_sql=False,
destination_dataset_table=bq_recent_questions_table_id)
https://cloud.google.com/composer/docs/how-to/using/writing-dags
python google-bigquery airflow
My question is regarding the logging of query successes or failure, done by the BigQueryOperator of Apache Airflow 1.10.0 I am wondering if it is possible to print query success on logging.info
, and if it is a failure to print on logging.error
?
from airflow.contrib.operators import bigquery_operator
# Query recent StackOverflow questions.
bq_recent_questions_query = bigquery_operator.BigQueryOperator(
task_id='bq_recent_questions_query',
bql="""
SELECT owner_display_name, title, view_count
FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE creation_date < CAST('{max_date}' AS TIMESTAMP)
AND creation_date >= CAST('{min_date}' AS TIMESTAMP)
ORDER BY view_count DESC
LIMIT 100
""".format(max_date=max_query_date, min_date=min_query_date),
use_legacy_sql=False,
destination_dataset_table=bq_recent_questions_table_id)
https://cloud.google.com/composer/docs/how-to/using/writing-dags
python google-bigquery airflow
python google-bigquery airflow
edited Nov 21 at 8:32
Meghdeep Ray
2,50321738
2,50321738
asked Nov 20 at 10:20
Paul Velthuis
130112
130112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
You could make your own Operator by just copying the BigQueryOperator and making the following changes to the execute
and on_kill
functions inside it, or you could override the existing BigQueryOperator
as well.
def execute(self, context):
if self.bq_cursor is None:
self.log.info( "Beginnging Execution." )
hook = BigQueryHook(
bigquery_conn_id=self.bigquery_conn_id,
use_legacy_sql=self.use_legacy_sql,
delegate_to=self.delegate_to)
conn = hook.get_conn()
self.bq_cursor = conn.cursor()
self.bq_cursor.run_query(
self.sql,
destination_dataset_table=self.destination_dataset_table,
write_disposition=self.write_disposition,
allow_large_results=self.allow_large_results,
flatten_results=self.flatten_results,
udf_config=self.udf_config,
maximum_billing_tier=self.maximum_billing_tier,
maximum_bytes_billed=self.maximum_bytes_billed,
create_disposition=self.create_disposition,
query_params=self.query_params,
labels=self.labels,
schema_update_options=self.schema_update_options,
priority=self.priority,
time_partitioning=self.time_partitioning
)
self.log.info( "Executed: %s" % self.sql )
def on_kill(self):
super(BigQueryOperator, self).on_kill()
self.log.error( "Failed to Execute: %s" % self.sql )
if self.bq_cursor is not None:
self.log.info('Canceling running query due to execution timeout')
self.bq_cursor.cancel_query()
You have to put in custom operators into the plugins directory.
add a comment |
up vote
1
down vote
Looks like the code logs the query prior to execution, so the outcome is not known at the time the log is written.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390834%2fapache-airflow-print-query-success-on-logging-info-query-failure-on-logging-er%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You could make your own Operator by just copying the BigQueryOperator and making the following changes to the execute
and on_kill
functions inside it, or you could override the existing BigQueryOperator
as well.
def execute(self, context):
if self.bq_cursor is None:
self.log.info( "Beginnging Execution." )
hook = BigQueryHook(
bigquery_conn_id=self.bigquery_conn_id,
use_legacy_sql=self.use_legacy_sql,
delegate_to=self.delegate_to)
conn = hook.get_conn()
self.bq_cursor = conn.cursor()
self.bq_cursor.run_query(
self.sql,
destination_dataset_table=self.destination_dataset_table,
write_disposition=self.write_disposition,
allow_large_results=self.allow_large_results,
flatten_results=self.flatten_results,
udf_config=self.udf_config,
maximum_billing_tier=self.maximum_billing_tier,
maximum_bytes_billed=self.maximum_bytes_billed,
create_disposition=self.create_disposition,
query_params=self.query_params,
labels=self.labels,
schema_update_options=self.schema_update_options,
priority=self.priority,
time_partitioning=self.time_partitioning
)
self.log.info( "Executed: %s" % self.sql )
def on_kill(self):
super(BigQueryOperator, self).on_kill()
self.log.error( "Failed to Execute: %s" % self.sql )
if self.bq_cursor is not None:
self.log.info('Canceling running query due to execution timeout')
self.bq_cursor.cancel_query()
You have to put in custom operators into the plugins directory.
add a comment |
up vote
0
down vote
accepted
You could make your own Operator by just copying the BigQueryOperator and making the following changes to the execute
and on_kill
functions inside it, or you could override the existing BigQueryOperator
as well.
def execute(self, context):
if self.bq_cursor is None:
self.log.info( "Beginnging Execution." )
hook = BigQueryHook(
bigquery_conn_id=self.bigquery_conn_id,
use_legacy_sql=self.use_legacy_sql,
delegate_to=self.delegate_to)
conn = hook.get_conn()
self.bq_cursor = conn.cursor()
self.bq_cursor.run_query(
self.sql,
destination_dataset_table=self.destination_dataset_table,
write_disposition=self.write_disposition,
allow_large_results=self.allow_large_results,
flatten_results=self.flatten_results,
udf_config=self.udf_config,
maximum_billing_tier=self.maximum_billing_tier,
maximum_bytes_billed=self.maximum_bytes_billed,
create_disposition=self.create_disposition,
query_params=self.query_params,
labels=self.labels,
schema_update_options=self.schema_update_options,
priority=self.priority,
time_partitioning=self.time_partitioning
)
self.log.info( "Executed: %s" % self.sql )
def on_kill(self):
super(BigQueryOperator, self).on_kill()
self.log.error( "Failed to Execute: %s" % self.sql )
if self.bq_cursor is not None:
self.log.info('Canceling running query due to execution timeout')
self.bq_cursor.cancel_query()
You have to put in custom operators into the plugins directory.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You could make your own Operator by just copying the BigQueryOperator and making the following changes to the execute
and on_kill
functions inside it, or you could override the existing BigQueryOperator
as well.
def execute(self, context):
if self.bq_cursor is None:
self.log.info( "Beginnging Execution." )
hook = BigQueryHook(
bigquery_conn_id=self.bigquery_conn_id,
use_legacy_sql=self.use_legacy_sql,
delegate_to=self.delegate_to)
conn = hook.get_conn()
self.bq_cursor = conn.cursor()
self.bq_cursor.run_query(
self.sql,
destination_dataset_table=self.destination_dataset_table,
write_disposition=self.write_disposition,
allow_large_results=self.allow_large_results,
flatten_results=self.flatten_results,
udf_config=self.udf_config,
maximum_billing_tier=self.maximum_billing_tier,
maximum_bytes_billed=self.maximum_bytes_billed,
create_disposition=self.create_disposition,
query_params=self.query_params,
labels=self.labels,
schema_update_options=self.schema_update_options,
priority=self.priority,
time_partitioning=self.time_partitioning
)
self.log.info( "Executed: %s" % self.sql )
def on_kill(self):
super(BigQueryOperator, self).on_kill()
self.log.error( "Failed to Execute: %s" % self.sql )
if self.bq_cursor is not None:
self.log.info('Canceling running query due to execution timeout')
self.bq_cursor.cancel_query()
You have to put in custom operators into the plugins directory.
You could make your own Operator by just copying the BigQueryOperator and making the following changes to the execute
and on_kill
functions inside it, or you could override the existing BigQueryOperator
as well.
def execute(self, context):
if self.bq_cursor is None:
self.log.info( "Beginnging Execution." )
hook = BigQueryHook(
bigquery_conn_id=self.bigquery_conn_id,
use_legacy_sql=self.use_legacy_sql,
delegate_to=self.delegate_to)
conn = hook.get_conn()
self.bq_cursor = conn.cursor()
self.bq_cursor.run_query(
self.sql,
destination_dataset_table=self.destination_dataset_table,
write_disposition=self.write_disposition,
allow_large_results=self.allow_large_results,
flatten_results=self.flatten_results,
udf_config=self.udf_config,
maximum_billing_tier=self.maximum_billing_tier,
maximum_bytes_billed=self.maximum_bytes_billed,
create_disposition=self.create_disposition,
query_params=self.query_params,
labels=self.labels,
schema_update_options=self.schema_update_options,
priority=self.priority,
time_partitioning=self.time_partitioning
)
self.log.info( "Executed: %s" % self.sql )
def on_kill(self):
super(BigQueryOperator, self).on_kill()
self.log.error( "Failed to Execute: %s" % self.sql )
if self.bq_cursor is not None:
self.log.info('Canceling running query due to execution timeout')
self.bq_cursor.cancel_query()
You have to put in custom operators into the plugins directory.
answered Nov 21 at 8:27
Meghdeep Ray
2,50321738
2,50321738
add a comment |
add a comment |
up vote
1
down vote
Looks like the code logs the query prior to execution, so the outcome is not known at the time the log is written.
add a comment |
up vote
1
down vote
Looks like the code logs the query prior to execution, so the outcome is not known at the time the log is written.
add a comment |
up vote
1
down vote
up vote
1
down vote
Looks like the code logs the query prior to execution, so the outcome is not known at the time the log is written.
Looks like the code logs the query prior to execution, so the outcome is not known at the time the log is written.
answered Nov 20 at 14:32
joeb
2,08611519
2,08611519
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390834%2fapache-airflow-print-query-success-on-logging-info-query-failure-on-logging-er%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown