You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2025/12/11 15:58:33 UTC

(superset) branch semantic-layer-implementation updated (2833b69ca0 -> e253bd2fb3)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a change to branch semantic-layer-implementation
in repository https://gitbox.apache.org/repos/asf/superset.git


    from 2833b69ca0 WIP
     new bfb7048e42 Frontend
     new e253bd2fb3 Fix mapping

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../superset-ui-core/src/query/DatasourceKey.ts        | 18 ++++++++++++++----
 .../superset-ui-core/src/query/types/Datasource.ts     |  3 ++-
 .../packages/superset-ui-core/src/query/types/Query.ts |  2 +-
 .../src/components/Chart/DrillBy/DrillByModal.tsx      |  9 +++++++--
 superset-frontend/src/dashboard/types.ts               |  2 +-
 .../src/explore/actions/saveModalActions.ts            |  6 ++++--
 superset-frontend/src/explore/exploreUtils/formData.ts |  8 ++++----
 superset/semantic_layers/mapper.py                     |  2 +-
 superset/semantic_layers/snowflake/semantic_layer.py   |  5 -----
 superset/semantic_layers/snowflake/semantic_view.py    | 17 ++++++++++++++---
 10 files changed, 48 insertions(+), 24 deletions(-)


(superset) 01/02: Frontend

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch semantic-layer-implementation
in repository https://gitbox.apache.org/repos/asf/superset.git

commit bfb7048e427aa5786070a7b8d2e4968073e78164
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Thu Dec 11 10:32:06 2025 -0500

    Frontend
---
 .../superset-ui-core/src/query/DatasourceKey.ts        | 18 ++++++++++++++----
 .../superset-ui-core/src/query/types/Datasource.ts     |  3 ++-
 .../packages/superset-ui-core/src/query/types/Query.ts |  2 +-
 .../src/components/Chart/DrillBy/DrillByModal.tsx      |  9 +++++++--
 superset-frontend/src/dashboard/types.ts               |  2 +-
 .../src/explore/actions/saveModalActions.ts            |  6 ++++--
 superset-frontend/src/explore/exploreUtils/formData.ts |  8 ++++----
 superset/semantic_layers/mapper.py                     |  2 +-
 superset/semantic_layers/snowflake/semantic_layer.py   |  5 -----
 superset/semantic_layers/snowflake/semantic_view.py    |  5 ++---
 10 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/superset-frontend/packages/superset-ui-core/src/query/DatasourceKey.ts b/superset-frontend/packages/superset-ui-core/src/query/DatasourceKey.ts
index 38a38e10b1..07b296c6d0 100644
--- a/superset-frontend/packages/superset-ui-core/src/query/DatasourceKey.ts
+++ b/superset-frontend/packages/superset-ui-core/src/query/DatasourceKey.ts
@@ -19,16 +19,26 @@
 
 import { DatasourceType } from './types/Datasource';
 
+const DATASOURCE_TYPE_MAP: Record<string, DatasourceType> = {
+  table: DatasourceType.Table,
+  query: DatasourceType.Query,
+  dataset: DatasourceType.Dataset,
+  sl_table: DatasourceType.SlTable,
+  saved_query: DatasourceType.SavedQuery,
+  semantic_view: DatasourceType.SemanticView,
+};
+
 export default class DatasourceKey {
-  readonly id: number;
+  readonly id: number | string;
 
   readonly type: DatasourceType;
 
   constructor(key: string) {
     const [idStr, typeStr] = key.split('__');
-    this.id = parseInt(idStr, 10);
-    this.type = DatasourceType.Table; // default to SqlaTable model
-    this.type = typeStr === 'query' ? DatasourceType.Query : this.type;
+    // Try to parse as integer, fall back to string (UUID) if NaN
+    const parsedId = parseInt(idStr, 10);
+    this.id = Number.isNaN(parsedId) ? idStr : parsedId;
+    this.type = DATASOURCE_TYPE_MAP[typeStr] ?? DatasourceType.Table;
   }
 
   public toString() {
diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts b/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts
index c5ce93c1e9..b93e99e4c3 100644
--- a/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts
+++ b/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts
@@ -26,6 +26,7 @@ export enum DatasourceType {
   Dataset = 'dataset',
   SlTable = 'sl_table',
   SavedQuery = 'saved_query',
+  SemanticView = 'semantic_view',
 }
 
 export interface Currency {
@@ -37,7 +38,7 @@ export interface Currency {
  * Datasource metadata.
  */
 export interface Datasource {
-  id: number;
+  id: number | string;
   name: string;
   type: DatasourceType;
   columns: Column[];
diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/Query.ts b/superset-frontend/packages/superset-ui-core/src/query/types/Query.ts
index 65c9ba253c..c8ee11086e 100644
--- a/superset-frontend/packages/superset-ui-core/src/query/types/Query.ts
+++ b/superset-frontend/packages/superset-ui-core/src/query/types/Query.ts
@@ -156,7 +156,7 @@ export interface QueryObject
 
 export interface QueryContext {
   datasource: {
-    id: number;
+    id: number | string;
     type: DatasourceType;
   };
   /** Force refresh of all queries */
diff --git a/superset-frontend/src/components/Chart/DrillBy/DrillByModal.tsx b/superset-frontend/src/components/Chart/DrillBy/DrillByModal.tsx
index eec8fd8ce5..cc939a0661 100644
--- a/superset-frontend/src/components/Chart/DrillBy/DrillByModal.tsx
+++ b/superset-frontend/src/components/Chart/DrillBy/DrillByModal.tsx
@@ -90,11 +90,16 @@ const ModalFooter = ({ formData, closeModal }: ModalFooterProps) => {
     findPermission('can_explore', 'Superset', state.user?.roles),
   );
 
-  const [datasource_id, datasource_type] = formData.datasource.split('__');
+  const [datasourceIdStr, datasource_type] = formData.datasource.split('__');
+  // Try to parse as integer, fall back to string (UUID) if NaN
+  const parsedDatasourceId = parseInt(datasourceIdStr, 10);
+  const datasource_id = Number.isNaN(parsedDatasourceId)
+    ? datasourceIdStr
+    : parsedDatasourceId;
   useEffect(() => {
     // short circuit if the user is embedded as explore is not available
     if (isEmbedded()) return;
-    postFormData(Number(datasource_id), datasource_type, formData, 0)
+    postFormData(datasource_id, datasource_type, formData, 0)
       .then(key => {
         setUrl(
           `/explore/?form_data_key=${key}&dashboard_page_id=${dashboardPageId}`,
diff --git a/superset-frontend/src/dashboard/types.ts b/superset-frontend/src/dashboard/types.ts
index e1a589acdb..0989241d2d 100644
--- a/superset-frontend/src/dashboard/types.ts
+++ b/superset-frontend/src/dashboard/types.ts
@@ -272,7 +272,7 @@ export type Slice = {
   changed_on: number;
   changed_on_humanized: string;
   modified: string;
-  datasource_id: number;
+  datasource_id: number | string;
   datasource_type: DatasourceType;
   datasource_url: string;
   datasource_name: string;
diff --git a/superset-frontend/src/explore/actions/saveModalActions.ts b/superset-frontend/src/explore/actions/saveModalActions.ts
index 2e1e48431c..0caf87cb9b 100644
--- a/superset-frontend/src/explore/actions/saveModalActions.ts
+++ b/superset-frontend/src/explore/actions/saveModalActions.ts
@@ -144,12 +144,14 @@ export const getSlicePayload = async (
     ...adhocFilters,
     dashboards,
   };
-  let datasourceId = 0;
+  let datasourceId: number | string = 0;
   let datasourceType: DatasourceType = DatasourceType.Table;
 
   if (formData.datasource) {
     const [id, typeString] = formData.datasource.split('__');
-    datasourceId = parseInt(id, 10);
+    // Try to parse as integer, fall back to string (UUID) if NaN
+    const parsedId = parseInt(id, 10);
+    datasourceId = Number.isNaN(parsedId) ? id : parsedId;
 
     const formattedTypeString =
       typeString.charAt(0).toUpperCase() + typeString.slice(1);
diff --git a/superset-frontend/src/explore/exploreUtils/formData.ts b/superset-frontend/src/explore/exploreUtils/formData.ts
index 9a83d8fd8d..994b7f0b4c 100644
--- a/superset-frontend/src/explore/exploreUtils/formData.ts
+++ b/superset-frontend/src/explore/exploreUtils/formData.ts
@@ -20,7 +20,7 @@ import { SupersetClient, JsonObject, JsonResponse } from '@superset-ui/core';
 import { sanitizeFormData } from 'src/utils/sanitizeFormData';
 
 type Payload = {
-  datasource_id: number;
+  datasource_id: number | string;
   datasource_type: string;
   form_data: string;
   chart_id?: number;
@@ -36,7 +36,7 @@ const assembleEndpoint = (key?: string, tabId?: string) => {
 };
 
 const assemblePayload = (
-  datasourceId: number,
+  datasourceId: number | string,
   datasourceType: string,
   formData: JsonObject,
   chartId?: number,
@@ -53,7 +53,7 @@ const assemblePayload = (
 };
 
 export const postFormData = (
-  datasourceId: number,
+  datasourceId: number | string,
   datasourceType: string,
   formData: JsonObject,
   chartId?: number,
@@ -70,7 +70,7 @@ export const postFormData = (
   }).then((r: JsonResponse) => r.json.key);
 
 export const putFormData = (
-  datasourceId: number,
+  datasourceId: number | string,
   datasourceType: string,
   key: string,
   formData: JsonObject,
diff --git a/superset/semantic_layers/mapper.py b/superset/semantic_layers/mapper.py
index 6fe6ffc16e..5c4896d395 100644
--- a/superset/semantic_layers/mapper.py
+++ b/superset/semantic_layers/mapper.py
@@ -877,7 +877,7 @@ def _validate_orderby(query_object: ValidatedQueryObject) -> None:
             "Adhoc expressions in order by are not supported in this Semantic View."
         )
 
-    elements = set(query_object.orderby)
+    elements = {orderby[0] for orderby in query_object.orderby}
     metric_names = {metric.name for metric in semantic_view.metrics}
     dimension_names = {dimension.name for dimension in semantic_view.dimensions}
     if not elements <= metric_names | dimension_names:
diff --git a/superset/semantic_layers/snowflake/semantic_layer.py b/superset/semantic_layers/snowflake/semantic_layer.py
index 185f57a2d4..f9d4e1a148 100644
--- a/superset/semantic_layers/snowflake/semantic_layer.py
+++ b/superset/semantic_layers/snowflake/semantic_layer.py
@@ -253,8 +253,6 @@ class SnowflakeSemanticLayer(
 
         # check that the semantic view exists
         connection_parameters = get_connection_parameters(configuration)
-        print("PARAMS")
-        print(connection_parameters)
         with connect(**connection_parameters) as connection:
             cursor = connection.cursor()
             query = dedent(
@@ -263,9 +261,6 @@ class SnowflakeSemanticLayer(
                     ->> SELECT "name" FROM $1 WHERE "name" = ?;
                 """
             ).strip()
-            print("BETO Q")
-            print(repr(query))
-            print(repr(name))
             cursor.execute(query, (name,))
             rows = cursor.fetchall()
             if not rows:
diff --git a/superset/semantic_layers/snowflake/semantic_view.py b/superset/semantic_layers/snowflake/semantic_view.py
index e40635ab5d..7bc609fe24 100644
--- a/superset/semantic_layers/snowflake/semantic_view.py
+++ b/superset/semantic_layers/snowflake/semantic_view.py
@@ -396,9 +396,8 @@ class SnowflakeSemanticView(SemanticViewImplementation):
 
         filters = filters or set()
         where_clause, where_parameters = self._build_predicates(
-            sorted(
-                filter_ for filter_ in filters if filter_.type == PredicateType.WHERE
-            )
+            # XXX sort to ensure deterministic order for parameters
+            [filter_ for filter_ in filters if filter_.type == PredicateType.WHERE]
         )
         # having clauses are not supported, since there's no GROUP BY
         if any(filter_.type == PredicateType.HAVING for filter_ in filters):


(superset) 02/02: Fix mapping

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch semantic-layer-implementation
in repository https://gitbox.apache.org/repos/asf/superset.git

commit e253bd2fb3f8d2dbb7398b955d71e3ca11ecfe83
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Thu Dec 11 10:58:17 2025 -0500

    Fix mapping
---
 superset/semantic_layers/snowflake/semantic_view.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/superset/semantic_layers/snowflake/semantic_view.py b/superset/semantic_layers/snowflake/semantic_view.py
index 7bc609fe24..8ce849af2f 100644
--- a/superset/semantic_layers/snowflake/semantic_view.py
+++ b/superset/semantic_layers/snowflake/semantic_view.py
@@ -305,6 +305,7 @@ class SnowflakeSemanticView(SemanticViewImplementation):
         """
         Execute a query and return the results as a Pandas DataFrame.
         """
+        print("AM HERE")
         if not metrics and not dimensions:
             return DataFrame()
 
@@ -321,6 +322,17 @@ class SnowflakeSemanticView(SemanticViewImplementation):
         with connect(**connection_parameters) as connection:
             df = connection.cursor().execute(query, parameters).fetch_pandas_all()
 
+        # map column names to dimension/metric names instead of IDs
+        mapping = {
+            **{dimension.id: dimension.name for dimension in dimensions},
+            **{metric.id: metric.name for metric in metrics},
+        }
+        print("BETO")
+        print(df.columns)
+        print(mapping)
+        df.rename(columns=mapping, inplace=True)
+        print(df.columns)
+
         return SemanticResult(
             requests=[
                 SemanticRequest(