-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AIRFLOW-3905] Allow using "parameters" in SqlSensor #4723
Conversation
c629ecb
to
1af2afe
Compare
Codecov Report
@@ Coverage Diff @@
## master #4723 +/- ##
==========================================
+ Coverage 74.65% 74.65% +<.01%
==========================================
Files 430 430
Lines 27990 27992 +2
==========================================
+ Hits 20896 20898 +2
Misses 7094 7094
Continue to review full report at Codecov.
|
d607f52
to
472310c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please find my two cents.
472310c
to
c63f008
Compare
self.log.info('Poking: %s', self.sql) | ||
records = hook.get_records(self.sql) | ||
self.log.info('Poking: %s (with parameters %s)', self.sql, self.parameters) | ||
records = hook.get_records(self.sql, self.parameters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all the sql type hooks(druid, mysql, postgres etc) are all inherited from dbapi hook? If that's case, the change LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, we should change that hook to inherit from dbapi hook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, hooks of druid, mysql, mssql, Postgres, oracle etc are all inherited from dbapi hook.
reference:
- https://github.com/apache/airflow/blob/master/airflow/hooks/mssql_hook.py#L25
- https://github.com/apache/airflow/blob/master/airflow/hooks/mysql_hook.py#L28
- https://github.com/apache/airflow/blob/master/airflow/hooks/oracle_hook.py#L29
- https://github.com/apache/airflow/blob/master/airflow/hooks/postgres_hook.py#L28
For SqlSensor
, the get_hook()
in BaseHook.get_connection(self.conn_id).get_hook()
will decide which exact hook to use based on the connection type (reference: https://github.com/apache/airflow/blob/master/airflow/models/connection.py#L184).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I checkCloudSqlDatabaseHook
(
airflow/airflow/contrib/hooks/gcp_sql_hook.py
Line 669 in 6b38649
class CloudSqlDatabaseHook(BaseHook): |
But the I assume the sqlSensor could use CloudSqlDatabasehook? Given there are many connection hooks defined, a safer approach would be check if the hook is an instance of dbapi hook, use the records = hook.get_records(self.sql, self.parameters)
, otherwise fall back to records = hook.get_records(self.sql)
. what you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually SqlSensor
can not support CloudSqlDatabaseHook
.
Eventually SqlSensor
uses get_records
method to retrieve the records from DB, while get_records
method is not available in CloudSqlDatabaseHook
at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but would a check on hook type be safer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get what you mean.
Given the limitation in https://github.com/apache/airflow/blob/master/airflow/models/connection.py#L184 and the implementation of each hook, only the connection types below are supported by SqlSensor
:
- 'google_cloud_platform'
- 'jdbc'
- 'mssql'
- 'mysql'
- 'oracle'
- 'postgres'
- 'presto'
- 'sqlite'
- 'vertica'
I will add a check.
8eb5517
to
de33170
Compare
1509734
to
1d005e6
Compare
Not all SQL-related connections are supported by SqlSensor, due to limitation in Connection model and hook implementation.
1d005e6
to
b1acc55
Compare
LGTM |
Thanks @feng-tao |
* [AIRFLOW-3905] Allow 'parameters' in SqlSensor * Add check on conn_type & add test Not all SQL-related connections are supported by SqlSensor, due to limitation in Connection model and hook implementation.
* [AIRFLOW-3905] Allow 'parameters' in SqlSensor * Add check on conn_type & add test Not all SQL-related connections are supported by SqlSensor, due to limitation in Connection model and hook implementation.
* [AIRFLOW-3905] Allow 'parameters' in SqlSensor * Add check on conn_type & add test Not all SQL-related connections are supported by SqlSensor, due to limitation in Connection model and hook implementation.
@XD-DENG @feng-tao it breaks the
As the |
Shouldn't the Or perhaps |
Jira
Description
In most SQL-related operators/sensors, argument
parameters
is available to help render SQL command conveniently, likeMySqlOperator
(https://github.com/apache/airflow/blob/master/airflow/operators/mysql_operator.py#L25) andPostgresOperator
(https://github.com/apache/airflow/blob/master/airflow/operators/postgres_operator.py#L24).But this is not available in
SqlSensor
yet.Tests
Tests passed.
Commits
Documentation
Code Quality
flake8