RehanAhmad25 commented on code in PR #77423:
URL: https://github.com/apache/airflow/pull/77423#discussion_r4655770541


##########
providers/microsoft/mssql/src/airflow/providers/microsoft/mssql/hooks/mssql.py:
##########
@@ -37,6 +37,162 @@
     from airflow.providers.common.sql.dialects.dialect import Dialect
     from airflow.providers.openlineage.sqlparser import DatabaseInfo
 
+# Connection extras that are handled by the hook itself and must never reach 
the DBAPI driver.
+_AIRFLOW_ONLY_EXTRAS = frozenset({"sqlalchemy_scheme", "dbapi_driver"})
+
+
+class _PymssqlDriver:
+    """What ``MsSqlHook`` does differently when ``dbapi_driver`` is 
``pymssql`` (the default)."""
+
+    name = "pymssql"
+    default_sqlalchemy_scheme = "mssql+pymssql"
+    # None means the placeholder of ``DbApiHook``.
+    placeholder: str | None = None
+
+    def connect(self, hook: MsSqlHook) -> PymssqlConnection:
+        conn = hook.connection
+        extra_conn_args = {
+            key: val for key, val in conn.extra_dejson.items() if key.lower() 
not in _AIRFLOW_ONLY_EXTRAS
+        }
+        return pymssql.connect(
+            server=conn.host or "",
+            user=conn.login,
+            password=conn.password,
+            database=hook.schema or conn.schema or "",
+            port=str(conn.port),
+            **extra_conn_args,
+        )
+
+    def sqlalchemy_url(self, hook: MsSqlHook) -> URL | None:
+        # None means the default of ``DbApiHook``, so the engine is built from 
``get_uri()``.
+        return None
+
+    def get_uri(self, hook: MsSqlHook) -> str:
+        from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit

Review Comment:
   Moved to the top of the module.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to