Lee-W commented on code in PR #48915:
URL: https://github.com/apache/airflow/pull/48915#discussion_r2041088929


##########
providers/jdbc/src/airflow/providers/jdbc/hooks/jdbc.py:
##########
@@ -220,3 +221,38 @@ def get_autocommit(self, conn: jaydebeapi.Connection) -> 
bool:
         with suppress_and_warn(jaydebeapi.Error, jpype.JException):
             return conn.jconn.getAutoCommit()
         return False
+
+    def get_uri(self) -> str:
+        """Get the connection URI for the JDBC connection."""
+        conn = self.connection
+        extra = conn.extra_dejson
+
+        scheme = extra.get("sqlalchemy_scheme")
+        if not scheme:
+            return conn.host
+
+        driver = extra.get("sqlalchemy_driver")
+        uri_prefix = f"{scheme}+{driver}" if driver else scheme
+
+        auth_part = ""
+        if conn.login:
+            auth_part = quote_plus(conn.login)
+            if conn.password:
+                auth_part += f":{quote_plus(conn.password)}"
+            auth_part += "@"
+
+        host_part = conn.host or "localhost"
+        if conn.port:
+            host_part += f":{conn.port}"
+
+        schema_part = f"/{quote_plus(conn.schema)}" if conn.schema else ""
+
+        uri = f"{uri_prefix}://{auth_part}{host_part}{schema_part}"
+
+        sqlalchemy_query = extra.get("sqlalchemy_query", {})
+        if isinstance(sqlalchemy_query, dict):
+            query_string = urlencode({k: str(v) for k, v in 
sqlalchemy_query.items() if v is not None})
+            if query_string:
+                uri += f"?{query_string}"

Review Comment:
   ```suggestion
                   uri = f"{uri}?{query_string}"
   ```



##########
providers/jdbc/src/airflow/providers/jdbc/hooks/jdbc.py:
##########
@@ -220,3 +221,38 @@ def get_autocommit(self, conn: jaydebeapi.Connection) -> 
bool:
         with suppress_and_warn(jaydebeapi.Error, jpype.JException):
             return conn.jconn.getAutoCommit()
         return False
+
+    def get_uri(self) -> str:
+        """Get the connection URI for the JDBC connection."""
+        conn = self.connection
+        extra = conn.extra_dejson
+
+        scheme = extra.get("sqlalchemy_scheme")
+        if not scheme:
+            return conn.host
+
+        driver = extra.get("sqlalchemy_driver")
+        uri_prefix = f"{scheme}+{driver}" if driver else scheme
+
+        auth_part = ""
+        if conn.login:
+            auth_part = quote_plus(conn.login)
+            if conn.password:
+                auth_part += f":{quote_plus(conn.password)}"
+            auth_part += "@"
+
+        host_part = conn.host or "localhost"
+        if conn.port:
+            host_part += f":{conn.port}"

Review Comment:
   ```suggestion
               host_part = "{host_part}:{conn.port}"
   ```



##########
providers/jdbc/src/airflow/providers/jdbc/hooks/jdbc.py:
##########
@@ -220,3 +221,38 @@ def get_autocommit(self, conn: jaydebeapi.Connection) -> 
bool:
         with suppress_and_warn(jaydebeapi.Error, jpype.JException):
             return conn.jconn.getAutoCommit()
         return False
+
+    def get_uri(self) -> str:
+        """Get the connection URI for the JDBC connection."""
+        conn = self.connection
+        extra = conn.extra_dejson
+
+        scheme = extra.get("sqlalchemy_scheme")
+        if not scheme:
+            return conn.host
+
+        driver = extra.get("sqlalchemy_driver")
+        uri_prefix = f"{scheme}+{driver}" if driver else scheme
+
+        auth_part = ""
+        if conn.login:
+            auth_part = quote_plus(conn.login)
+            if conn.password:
+                auth_part += f":{quote_plus(conn.password)}"
+            auth_part += "@"

Review Comment:
   ```suggestion
                   auth_part = f"{auth_part}:{quote_plus(conn.password)}"
               auth_part = "{auth_part}@"
   ```



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