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


##########
providers/mysql/src/airflow/providers/mysql/hooks/mysql.py:
##########
@@ -363,3 +364,44 @@ def get_openlineage_database_dialect(self, _):
     def get_openlineage_default_schema(self):
         """MySQL has no concept of schema."""
         return None
+
+    def get_uri(self) -> str:
+        """Get URI for MySQL connection."""
+        conn = self.connection or self.get_connection(self.get_conn_id())
+        conn_schema = self.schema or conn.schema or ""
+        client_name = conn.extra_dejson.get("client", "mysqlclient")
+
+        # Determine URI prefix based on client
+        if client_name == "mysql-connector-python":
+            uri_prefix = "mysql+mysqlconnector://"
+        else:  # default: mysqlclient
+            uri_prefix = "mysql://"
+
+        auth_part = ""
+        if conn.login:
+            auth_part += quote_plus(conn.login)
+            if conn.password:
+                auth_part += ":" + quote_plus(conn.password)
+            auth_part += "@"

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



##########
providers/mysql/src/airflow/providers/mysql/hooks/mysql.py:
##########
@@ -363,3 +364,44 @@ def get_openlineage_database_dialect(self, _):
     def get_openlineage_default_schema(self):
         """MySQL has no concept of schema."""
         return None
+
+    def get_uri(self) -> str:
+        """Get URI for MySQL connection."""
+        conn = self.connection or self.get_connection(self.get_conn_id())
+        conn_schema = self.schema or conn.schema or ""
+        client_name = conn.extra_dejson.get("client", "mysqlclient")
+
+        # Determine URI prefix based on client
+        if client_name == "mysql-connector-python":
+            uri_prefix = "mysql+mysqlconnector://"
+        else:  # default: mysqlclient
+            uri_prefix = "mysql://"
+
+        auth_part = ""
+        if conn.login:
+            auth_part += quote_plus(conn.login)
+            if conn.password:
+                auth_part += ":" + 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 = conn.host or "localhost"
           if conn.port:
               host_part = f"{host_part}:{conn.port}"
   ```



##########
providers/mysql/src/airflow/providers/mysql/hooks/mysql.py:
##########
@@ -363,3 +364,44 @@ def get_openlineage_database_dialect(self, _):
     def get_openlineage_default_schema(self):
         """MySQL has no concept of schema."""
         return None
+
+    def get_uri(self) -> str:
+        """Get URI for MySQL connection."""
+        conn = self.connection or self.get_connection(self.get_conn_id())
+        conn_schema = self.schema or conn.schema or ""
+        client_name = conn.extra_dejson.get("client", "mysqlclient")
+
+        # Determine URI prefix based on client
+        if client_name == "mysql-connector-python":
+            uri_prefix = "mysql+mysqlconnector://"
+        else:  # default: mysqlclient
+            uri_prefix = "mysql://"
+
+        auth_part = ""
+        if conn.login:
+            auth_part += quote_plus(conn.login)
+            if conn.password:
+                auth_part += ":" + 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}"
+
+        # Add extra connection parameters
+        extra = conn.extra_dejson.copy()
+        if "client" in extra:
+            extra.pop("client")
+
+        params = []
+        for k, v in extra.items():
+            if v:
+                params.append(f"{k}={quote_plus(str(v))}")
+        if params:
+            uri += "?" + "&".join(params)

Review Comment:
   we can use 
https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode for 
this whole section



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