aminghadersohi commented on code in PR #37865:
URL: https://github.com/apache/superset/pull/37865#discussion_r2790737079


##########
superset/daos/dataset.py:
##########
@@ -49,6 +52,37 @@ class DatasetDAO(BaseDAO[SqlaTable]):
 
     base_filter = DatasourceFilter
 
+    @classmethod
+    def apply_column_operators(
+        cls,
+        query: Query,
+        column_operators: list[ColumnOperator] | None = None,
+    ) -> Query:
+        """Override to handle database_name filter via join to Database table.
+
+        database_name lives on Database, not SqlaTable, so we intercept it
+        here, join to the Database table, and apply the filter there.
+        """
+        if not column_operators:
+            return query
+
+        remaining_operators: list[ColumnOperator] = []
+        for c in column_operators:
+            if not isinstance(c, ColumnOperator):
+                c = ColumnOperator.model_validate(c)
+            if c.col == "database_name":
+                query = query.join(Database, SqlaTable.database_id == 
Database.id)
+                operator_enum = ColumnOperatorEnum(c.opr)
+                query = query.filter(
+                    operator_enum.apply(Database.database_name, c.value)
+                )
+            else:
+                remaining_operators.append(c)
+
+        if remaining_operators:
+            query = super().apply_column_operators(query, remaining_operators)
+        return query

Review Comment:
   Fixed - moved the JOIN outside the loop. Now collects all database_name 
operators first, performs a single JOIN to Database, then applies the filters. 
Pushed in cfd49fc.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to