nicob3y commented on code in PR #35662:
URL: https://github.com/apache/superset/pull/35662#discussion_r4222402994


##########
superset/jinja_context.py:
##########
@@ -1281,22 +1291,81 @@ def get_template_processor(
 
 
 def dataset_macro(
-    dataset_id: int,
+    dataset_id: int | str,
     include_metrics: bool = False,
     columns: list[str] | None = None,
+    schema: str | _Unset | None = _UNSET,
+    catalog: str | _Unset | None = _UNSET,
+    database_id: int | str | _Unset | None = _UNSET,
+    alias: str | None = None,
 ) -> str:
     """
-    Given a dataset ID, return the SQL that represents it.
+    Given a dataset ID or name, return the SQL that represents it.
+
+    If ``dataset_id`` is an integer, it is treated as the unique dataset ID and
+    the optional ``schema``, ``catalog`` and ``database_id`` parameters are
+    ignored.
+
+    If ``dataset_id`` is a string, it is treated as a dataset name. The 
optional
+    ``schema``, ``catalog`` and ``database_id`` parameters are used to narrow
+    down the search when provided. If multiple datasets match the provided
+    criteria, an error is raised because the dataset name is ambiguous.
 
     The generated SQL includes all columns (including computed) by default. 
Optionally
     the user can also request metrics to be included, and columns to group by.
+
+    The ``alias`` parameter allows the user to specify an explicit alias for 
the
+    returned subquery.
     """
     # pylint: disable=import-outside-toplevel
+    from sqlalchemy.orm.exc import MultipleResultsFound
+
     from superset.daos.dataset import DatasetDAO
 
-    dataset = DatasetDAO.find_by_id(dataset_id)
+    filters: dict[str, Any] = {}
+
+    if database_id not in (_UNSET, None):
+        filters["database_id"] = database_id
+    if catalog is not _UNSET:
+        filters["catalog"] = catalog
+    if schema is not _UNSET:
+        filters["schema"] = schema
+
+    if isinstance(dataset_id, str):

Review Comment:
   I chose to introduce two explicit named parameters to cleanly separate the 
intent: dataset_name and database_name



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