msyavuz opened a new pull request, #44141:
URL: https://github.com/apache/superset/pull/44141

   ### SUMMARY
   SQL Lab's Data Preview returns "The query returned no data" for every 
MongoDB collection. PyMongoSQL takes the whole `FROM` reference as the 
collection name and always queries the database in the connection URI, so the 
preview query `SELECT * FROM testdb.orders` looks for a collection literally 
named `testdb.orders` and matches nothing. The schema picked in SQL Lab was 
also ignored for the same reason: `adjust_engine_params` was the base no-op, so 
`SELECT * FROM items` with `otherdb` selected still ran against the URI's 
database.
   
   The fix treats a Mongo database as the SQLAlchemy schema, the same way the 
MySQL spec does:
   - `supports_dynamic_schema = True` and `adjust_engine_params` swaps the URI 
database to the selected schema.
   - `get_schema_from_engine_params` / `get_default_schema` read the database 
from the URI instead of returning `None`.
   - `quote_table` emits the bare collection name, so `select_star` generates 
`FROM orders` and relies on the connection for the database.
   
   Charts on a Mongo dataset with `schema` set hit the same `schema.table` 
rendering through PyMongoSQL's compiler; that is not covered here.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   ### TESTING INSTRUCTIONS
   1. `docker run -d --rm -p 27017:27017 mongo:7`, seed a few documents into 
`testdb.orders` and `otherdb.items`.
   2. Add a database with `mongodb://localhost:27017/testdb?mode=superset`.
   3. In SQL Lab, pin `orders` and `items` to the result panel and open their 
Data preview tabs: both return rows (before: no data for either).
   4. Select the `otherdb` schema and run `SELECT * FROM items`: returns rows 
(before: no data).
   
   Unit tests in `tests/unit_tests/db_engine_specs/test_mongodb.py` cover the 
URI swap, default schema, and unqualified `select_star` SQL.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue: No
   - [ ] Required feature flags: None
   - [ ] Changes UI: No, backend only
   - [ ] Includes DB Migration: No
   - [ ] Introduces new feature or API: No
   - [ ] Removes existing feature or API: No


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