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


##########
providers/apache/impala/src/airflow/providers/apache/impala/hooks/impala.py:
##########
@@ -45,3 +46,30 @@ def get_conn(self) -> Connection:
             database=connection.schema,
             **connection.extra_dejson,
         )
+
+    @property
+    def sqlalchemy_url(self) -> URL:
+        """Return a `sqlalchemy.engine.URL` object constructed from the 
connection."""
+        conn = self.get_connection(self.get_conn_id())
+        extra = conn.extra_dejson or {}
+
+        required_attrs = ["host", "login"]
+        for attr in required_attrs:
+            if getattr(conn, attr) is None:
+                raise ValueError(f"Impala Connection Error: '{attr}' is 
missing in the connection")
+
+        query = {k: str(v) for k, v in extra.items() if v is not None and k 
not in ["__extra__"]}

Review Comment:
   ```suggestion
           query = {k: str(v) for k, v in extra.items() if v is not None and k 
!= "__extra__"}
   ```
   
   Cool! Thanks! Didn't know we have this. Then maybe we can try something like 
this



##########
providers/apache/impala/src/airflow/providers/apache/impala/hooks/impala.py:
##########
@@ -45,3 +46,30 @@ def get_conn(self) -> Connection:
             database=connection.schema,
             **connection.extra_dejson,
         )
+
+    @property
+    def sqlalchemy_url(self) -> URL:
+        """Return a `sqlalchemy.engine.URL` object constructed from the 
connection."""
+        conn = self.get_connection(self.get_conn_id())
+        extra = conn.extra_dejson or {}
+
+        required_attrs = ["host", "login"]
+        for attr in required_attrs:
+            if getattr(conn, attr) is None:
+                raise ValueError(f"Impala Connection Error: '{attr}' is 
missing in the connection")
+
+        query = {k: str(v) for k, v in extra.items() if v is not None and k 
not in ["__extra__"]}
+
+        return URL.create(
+            drivername="impala",
+            username=conn.login,
+            password=conn.password or "",
+            host=str(conn.host),
+            port=conn.port or 21050,
+            database=conn.schema,
+            query=query,
+        )
+
+    def get_uri(self) -> str:
+        """Return a SQLAlchemy engine URL as a string."""
+        return self.sqlalchemy_url.render_as_string(hide_password=False)

Review Comment:
   I also feel this is great!



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