GitHub user dosubot[bot] added a comment to the discussion: Get dataset description and columns description
<!-- Answer --> To retrieve the `dataset_id` for exporting to Excel, you can follow these steps: 1. **Access the Dataset ID**: The dataset ID is typically passed as part of the export operation. In the Superset codebase, the dataset ID is accessed through the `requested_ids` parameter in the `export` method of the `DatasetRestApi` class. This method uses the `ExportDatasetsCommand` to handle the export operation, which takes `requested_ids` as an argument to specify which datasets to export <sup>[[1]](https://github.com/apache/superset/blob/master/superset/datasets/api.py)</sup>. 2. **Modify `excel.py`**: To use the dataset ID in `excel.py`, you need to ensure that the ID is passed to the functions responsible for exporting data. You can modify the function that initiates the export process to accept a `dataset_id` parameter and use it to fetch the dataset object and its metadata. Here's an example of how you might modify the `excel.py` file to include the dataset ID in the export process: ```python from superset.daos.dataset import DatasetDAO def export_to_excel(dataset_id: int, df: pd.DataFrame, **kwargs: Any) -> Any: # Retrieve the dataset object using the dataset ID dataset = DatasetDAO.find_by_id(dataset_id) if not dataset: raise ValueError("Dataset not found") # Access dataset description and column descriptions dataset_description = dataset.description column_descriptions = {column.column_name: column.description for column in dataset.columns} # Export to Excel with descriptions return df_to_excel_with_descriptions(df, dataset_description, column_descriptions, **kwargs) ``` 3. **Integrate with the Export Process**: Ensure that the function responsible for handling the export operation (e.g., `handleBulkDatasetExport`) passes the dataset ID to the `export_to_excel` function. This way, you can retrieve the dataset object and its metadata for inclusion in the Excel export. By following these steps, you can effectively retrieve and use the `dataset_id` during the Excel export process in Superset. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=other)</sup> GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186356 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
