You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/07/15 13:57:29 UTC
[GitHub] [airflow] cjsekl opened a new issue #9834: Surface cursor.rowcount in PostgresOperator
cjsekl opened a new issue #9834:
URL: https://github.com/apache/airflow/issues/9834
<!--
Welcome to Apache Airflow! For a smooth issue process, try to answer the following questions.
Don't worry if they're not all applicable; just try to include what you can :-)
If you need to include code snippets or logs, please put them in fenced code
blocks. If they're super-long, please use the details tag like
<details><summary>super-long log</summary> lots of stuff </details>
Please delete these comment blocks before submitting the issue.
-->
**Description**
The `Cursor` object in `psycopg2` provides a useful feature of logging how many rows were affected by the last execute.
https://www.psycopg.org/docs/cursor.html#cursor.rowcount
This can be added as a parameter to `PostgresOperator` and passed through to `DbApiHook.run` to log affected row after each query.
The operator parameter could be a `verbose` flag that when enabled logs the SQL statement before running it and the rows affected after.
Example of `conn.cursor` logging:
```
>>> sql_statements = ['select 1;',
... 'insert into jeklund.rowtest (player_id) select 1;',
... 'select now()::date - generate_series(0, 59);']
>>> with closing(conn.cursor()) as cur:
... for sql_statement in sql_statements:
... print('Running {}'.format(sql_statement))
... cur.execute(sql_statement)
... print('Affected rows: {}'.format(cur.rowcount))
...
Running select 1;
Affected rows: 1
Running insert into jeklund.rowtest (player_id) select 1;
Affected rows: 1
Running select now()::date - generate_series(0, 59);
Affected rows: 60
```
**Use case / motivation**
Having rows affected in Airflow task logs is useful for monitoring and debugging multi step ETLs.
Making it easy to spot cases where e.g. an INSERT query unexpectedly inserted 0 rows.
**Related Issues**
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] turbaszek commented on issue #9834: Surface cursor.rowcount in PostgresOperator
Posted by GitBox <gi...@apache.org>.
turbaszek commented on issue #9834:
URL: https://github.com/apache/airflow/issues/9834#issuecomment-658823047
Hi @cjsekl would you like to work on this feature?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] cjsekl edited a comment on issue #9834: Surface cursor.rowcount in PostgresOperator
Posted by GitBox <gi...@apache.org>.
cjsekl edited a comment on issue #9834:
URL: https://github.com/apache/airflow/issues/9834#issuecomment-658844176
> Hi @cjsekl would you like to work on this feature?
Yes, I was planning on using this for the workshop.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] cjsekl commented on issue #9834: Surface cursor.rowcount in PostgresOperator
Posted by GitBox <gi...@apache.org>.
cjsekl commented on issue #9834:
URL: https://github.com/apache/airflow/issues/9834#issuecomment-658844176
Yes, I was planning on using this for the workshop
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] turbaszek closed issue #9834: Surface cursor.rowcount in PostgresOperator
Posted by GitBox <gi...@apache.org>.
turbaszek closed issue #9834:
URL: https://github.com/apache/airflow/issues/9834
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] gamebusterz commented on issue #9834: Surface cursor.rowcount in PostgresOperator
Posted by GitBox <gi...@apache.org>.
gamebusterz commented on issue #9834:
URL: https://github.com/apache/airflow/issues/9834#issuecomment-658843779
I have implemented this in the pipelines I've built to help with logging and debugging. So this looks like a good first issue for me to start with.
@turbaszek @cjsekl Can I pick this up?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] cjsekl edited a comment on issue #9834: Surface cursor.rowcount in PostgresOperator
Posted by GitBox <gi...@apache.org>.
cjsekl edited a comment on issue #9834:
URL: https://github.com/apache/airflow/issues/9834#issuecomment-658844176
> Hi @cjsekl would you like to work on this feature?
Yes, I was planning on using this for the workshop
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on issue #9834: Surface cursor.rowcount in PostgresOperator
Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on issue #9834:
URL: https://github.com/apache/airflow/issues/9834#issuecomment-658783746
Thanks for opening your first issue here! Be sure to follow the issue template!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] turbaszek commented on issue #9834: Surface cursor.rowcount in PostgresOperator
Posted by GitBox <gi...@apache.org>.
turbaszek commented on issue #9834:
URL: https://github.com/apache/airflow/issues/9834#issuecomment-661105948
Closing as this was done in #9841
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org