Comments (7)
To resolve the issue of special characters appearing when exporting Arabic data as a CSV from SQL Lab after upgrading to Superset version 4.0.1, you need to ensure that the CSV export is using the correct encoding. The df_to_escaped_csv
function should specify the encoding as 'utf-8'.
Here is the relevant part of the code with the necessary modification:
csv_data = df_to_escaped_csv(df, index=False, encoding='utf-8', **config["CSV_EXPORT"])
This ensures that the CSV file is encoded in UTF-8, which should handle Arabic characters correctly. The df_to_escaped_csv
function is defined in the superset/utils/csv.py
file and is responsible for escaping special characters and exporting the DataFrame to a CSV format [1][2].
To continue talking to Dosu, mention @dosu.
from superset.
You should add the given code snippet inside the SqlResultExportCommand
class, specifically in the run
method, after the DataFrame df
is created and before any further processing is done on it. Here is the modified method:
class SqlResultExportCommand(BaseCommand):
# ... other methods ...
def run(
self,
) -> SqlExportResult:
self.validate()
blob = None
if results_backend and self._query.results_key:
logger.info(
"Fetching CSV from results backend [%s]", self._query.results_key
)
blob = results_backend.get(self._query.results_key)
if blob:
logger.info("Decompressing")
payload = utils.zlib_decompress(
blob, decode=not results_backend_use_msgpack
)
obj = _deserialize_results_payload(
payload, self._query, cast(bool, results_backend_use_msgpack)
)
df = pd.DataFrame(
data=obj["data"],
dtype=object,
columns=[c["name"] for c in obj["columns"]],
)
logger.info("Using pandas to convert to CSV")
else:
logger.info("Running a query to turn into CSV")
if self._query.select_sql:
sql = self._query.select_sql
limit = None
else:
sql = self._query.executed_sql
limit = ParsedQuery(
sql,
engine=self._query.database.db_engine_spec.engine,
).limit
if limit is not None and self._query.limiting_factor in {
LimitingFactor.QUERY,
LimitingFactor.DROPDOWN,
LimitingFactor.QUERY_AND_DROPDOWN,
}:
# remove extra row from `increased_limit`
limit -= 1
df = self._query.database.get_df(
sql,
self._query.catalog,
self._query.schema,
)[:limit]
# Add the given code snippet here
csv_data = csv.df_to_escaped_csv(df, index=False, encoding='utf-8', **config["CSV_EXPORT"])
return {
"query": self._query,
"count": len(df.index),
"data": csv_data,
}
This ensures that the DataFrame df
is converted to an escaped CSV format right after it is created [1].
To continue talking to Dosu, mention @dosu.
from superset.
The SqlResultExportCommand
class is located in the superset/commands/sql_lab/export.py
file. You can find and modify the run
method in this file to include the necessary code snippet for handling the CSV export with the correct encoding.
To continue talking to Dosu, mention @dosu.
from superset.
The issue has been resolved by downgrading the package with the following command: pip install Werkzeug==2.3.8
.
from superset.
Where I should add this part of the code?
csv_data = df_to_escaped_csv(df, index=False, encoding='utf-8', **config["CSV_EXPORT"])
from superset.
Where is this class file path?
from superset.
This did not solve the problem. I am still facing the same issue with version 4.0.1
, while version 2.1.3
did not have this problem. I am unsure if it is related to the Python version or something else.
from superset.
Related Issues (20)
- SQL Lab Error 'str' object has no attribute 'set' HOT 4
- No module named 'superset.translations.utils' HOT 3
- subquery calculated columns not supported as dimensions with sql_mode=only_full_group_by HOT 4
- SECRET KEY ERROR HOT 7
- When a user wants to delete a dataset , the confirmation message could be more shaped HOT 2
- A report not yet executed is marked like a success HOT 1
- On Country Map, Cross-Filtering is not operational as a source HOT 2
- ModuleNotFoundError: No module named 'pkg_resources' HOT 1
- Report fails to generate if dashboard doesn't contain a chart HOT 1
- Mixed chart doesn't support forced categorical x-axis HOT 1
- Error: `prophet` package not installed HOT 3
- Very very slow Apache Superset dashboard HOT 8
- Superset 4.0.2 : Table Chart - Column Based Total Calculation HOT 2
- Handlebars chart - pagination support HOT 2
- superset_node build failure @nx/nx-linux-x64-gnu missing module HOT 6
- Mixed chart x-axes overlap for time period of last quarter HOT 1
- Cannot get back asyncquery result HOT 3
- Dev-server page isn't rendered HOT 14
- Garbled characters on the agent page in the development environment HOT 4
- Labels of Advanced analytics stats in the chart legend can't be changed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superset.