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/12/26 00:59:56 UTC

[GitHub] [airflow] potiuk commented on a change in pull request #12677: Refactor SQL/BigQuery/Qubole Check operators

potiuk commented on a change in pull request #12677:
URL: https://github.com/apache/airflow/pull/12677#discussion_r548927815



##########
File path: airflow/operators/sql.py
##########
@@ -38,7 +41,53 @@
 }
 
 
-class SQLCheckOperator(BaseOperator):
+class BaseSQLOperator(BaseOperator):
+    """
+    This is a base class for generic SQL Operator to get a DB Hook
+
+    The provided method is .get_db_hook(). The default behavior will try to
+    retrieve the DB hook based on connection type.
+    You can custom the behavior by overriding the .get_db_hook() method.
+    """
+
+    @apply_defaults
+    def __init__(self, *, conn_id: Optional[str] = None, database: Optional[str] = None, **kwargs):
+        super().__init__(**kwargs)
+        self.conn_id = conn_id
+        self.database = database
+
+    @cached_property
+    def _hook(self):
+        """Get DB Hook based on connection type"""
+        self.log.debug("Get connection for %s", self.conn_id)
+        conn = BaseHook.get_connection(self.conn_id)
+
+        if conn.conn_type not in ALLOWED_CONN_TYPE:

Review comment:
       Hmm. I think we should rather check the povider's manager hook property for that. We've added automated discovery of providers so that they can register their own connection -> Hook mapping so maybe we should utilise that? https://github.com/apache/airflow/blob/6f246b0d54ccaf733b7c5951a8955adda6719acb/airflow/providers_manager.py#L387 
   




----------------------------------------------------------------
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