graceguo-supercat opened a new issue #13562:
URL: https://github.com/apache/superset/issues/13562
A clear and concise description of what the bug is.
#### How to reproduce the bug
1. Create a PivotTable chart,
2. Add ROW LIMIT = 200
3. Check generated query by click `VIEW QUERY`
### Actual results
```
SELECT "dim_destination_geo" AS "dim_destination_geo",
date_trunc('week', CAST("night_in_latest_year" AS TIMESTAMP)) AS
"night_in_latest_year",
...
FROM "tmp"."forward_occupancy_forecast_superset_table"
WHERE "night_in_latest_year" >= '2021-03-11 00:00:00.000000'
AND "night_in_latest_year" < '2021-06-15 00:00:00.000000'
ORDER BY "Nights Backlog" DESC
LIMIT 200;
```
Instead of filtering out the top K rows in the superset view, it filters out
the top K rows in the input data; this results in the pivot table having lots
of missing cells.
### Expected results
Superset should generate a sub-query with limit like this:
```
SELECT "dim_destination_geo" AS "dim_destination_geo",
date_trunc('week', CAST("night_in_latest_year" AS TIMESTAMP)) AS
"night_in_latest_year",
...
FROM "tmp"."forward_occupancy_forecast_superset_table"
WHERE "night_in_latest_year" >= '2021-03-11 00:00:00.000000'
AND "night_in_latest_year" < '2021-06-15 00:00:00.000000'
AND ((is_most_recent_view = True)
AND (dim_destination_geo IN
(SELECT dim_destination_geo
FROM
(SELECT dim_destination_geo,
sum(current_forward_nights_occupied)
FROM tmp.forward_occupancy_forecast_superset_table
WHERE is_most_recent_view = True
GROUP BY 1
order by 2 DESC
LIMIT 200))))
ORDER BY "Nights Backlog" DESC
LIMIT 50000;
```
### Environment
latest master branch
### Checklist
Make sure to follow these steps before submitting your issue - thank you!
- [x] I have checked the superset logs for python stacktraces and included
it here as text if there are any.
- [x] I have reproduced the issue with at least the latest released version
of superset.
- [x] I have checked the issue tracker for the same issue and I haven't
found one similar.
### Additional context
Add any other context about the problem here.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]