orion222 commented on code in PR #45991:
URL: https://github.com/apache/superset/pull/45991#discussion_r4470357298


##########
superset/charts/data/run_query_context.py:
##########
@@ -0,0 +1,177 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Host implementations of the `superset_core.exports` chart-query 
functions."""
+
+from __future__ import annotations
+
+from typing import Any
+
+import pandas as pd
+from marshmallow import ValidationError
+from superset_core.exports.types import ChartQueryResult, GenericDataType
+
+from superset import is_feature_enabled, security_manager
+from superset.charts.client_processing import apply_client_processing
+from superset.charts.schemas import ChartDataQueryContextSchema
+from superset.commands.chart.data.get_data_command import ChartDataCommand
+from superset.common.chart_data import ChartDataResultFormat, 
ChartDataResultType
+from superset.common.query_context_factory import QueryContextFactory
+from superset.daos.dashboard import DashboardDAO
+from superset.exceptions import SupersetSecurityException
+from superset.utils.core import extract_dataframe_dtypes
+
+# Result types whose queries return rows; the rest return SQL or metadata.
+ROW_RESULT_TYPES = frozenset(
+    {
+        ChartDataResultType.FULL,
+        ChartDataResultType.RESULTS,
+        ChartDataResultType.POST_PROCESSED,
+        ChartDataResultType.SAMPLES,
+        ChartDataResultType.DRILL_DETAIL,
+    }
+)
+
+# Header of the row-label column; blank, like the unnamed index in a CSV 
export.
+ROW_LABEL_COLUMN = ""
+
+
+def _requested_result_types(payload: dict[str, Any]) -> set[str]:
+    """Collect the context-level and per-query result types a payload asks 
for."""
+    requested = {str(payload.get("result_type") or ChartDataResultType.FULL)}
+    for query in payload.get("queries") or []:
+        if isinstance(query, dict) and query.get("result_type"):
+            requested.add(str(query["result_type"]))
+    return requested
+
+
+def _coltype(value: Any) -> GenericDataType:
+    """Map a host column type to the core enum; unknown types read as 
strings."""
+    try:
+        return GenericDataType(value)
+    except ValueError:
+        return GenericDataType.STRING
+
+
+def _flatten_label(label: Any) -> str:
+    """Join a hierarchical label the way client processing flattens tuples."""
+    if isinstance(label, tuple):
+        return " ".join(str(part) for part in label).strip()
+    return str(label)
+
+
+def post_processed_rows(query: dict[str, Any]) -> dict[str, Any]:
+    """
+    Return ``query`` with post-processed JSON data rebuilt as row records.
+
+    Client processing serializes its frame as ``{column: {row label: value}}``
+    and drops the index names, so the row labels become a leading
+    ``ROW_LABEL_COLUMN`` unless they are the default ``0..n-1`` positions.
+    ``colnames`` and ``coltypes`` are recomputed to describe the rows.
+    """
+    data = query.get("data")
+    if not isinstance(data, dict):
+        return query
+
+    df = pd.DataFrame.from_dict(data)
+    df.columns = [_flatten_label(column) for column in df.columns]
+    if df.index.tolist() == list(range(len(df))):
+        df = df.reset_index(drop=True)

Review Comment:
   valid issue, fixed in `5b1a8e19a5` for every chart type now (except table, 
the only one without row numbers). 



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

  • [PR] feat(c... orion222 (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... orion222 (via GitHub) via notifications
    • Re: [P... orion222 (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... orion222 (via GitHub) via notifications
    • Re: [P... codecov[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... orion222 (via GitHub) via notifications
    • Re: [P... orion222 (via GitHub) via notifications
    • Re: [P... netlify[bot] (via GitHub) via notifications

Reply via email to