You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/10/05 21:45:51 UTC
[GitHub] [superset] xingyc15 opened a new issue #16984: JINJA Template does not work with calculated time column
xingyc15 opened a new issue #16984:
URL: https://github.com/apache/superset/issues/16984
Seems that there is a bug in using Jinja template in calculated columns. The scenario is that I set a Jinja template in a **Calculated Columns** and I use this column as the **Time Column** of a time series bar chart (I tried both time series bar chart v1 and v2), in the query, the template is not replaced. But the Jinja template set in calculated columns that are not used as time columns works fine.
Here is the case, my calculated column is:
```
CASE
WHEN '{{time_zone}}' = 'America/Los_Angeles' THEN date_pst
WHEN '{{time_zone}}' = 'Asia/Shanghai' THEN date_cst
END
```
but the query generated from time series chart is that:
```
SELECT {CASE
WHEN '{{time_zone}}' = 'America/Los_Angeles' THEN date_pst
WHEN '{{time_zone}}' = 'Asia/Shanghai' THEN date_cst
END}, DISTINCTCOUNT(username)
FROM logs
WHERE CASE
WHEN 'America/Los_Angeles' = 'America/Los_Angeles' THEN date_pst
WHEN 'America/Los_Angeles' = 'Asia/Shanghai' THEN date_cst
END >= '2021-07-05'
AND CASE
WHEN 'America/Los_Angeles' = 'America/Los_Angeles' THEN date_pst
WHEN 'America/Los_Angeles' = 'Asia/Shanghai' THEN date_cst
END < '2021-10-05'
GROUP BY {CASE
WHEN '{{time_zone}}' = 'America/Los_Angeles' THEN date_pst
WHEN '{{time_zone}}' = 'Asia/Shanghai' THEN date_cst
END}
ORDER BY DISTINCTCOUNT(username) DESC
LIMIT 10000;
```
#### How to reproduce the bug
1. Create a dataset. Setup a calculated column with Jinja template.
2. Create a new chart, set the TIME COLUMN using that calculated column.
3. Run the chart and the Jinja template is not applied.
### Expected results
The Jinja template should have applied.
### Actual results
The template clause is still there.
#### Screenshots
<img width="308" alt="Screen Shot 2021-10-05 at 2 44 18 PM" src="https://user-images.githubusercontent.com/33602700/136107082-da517cc6-7a9e-4d5a-8890-0891621073bb.png">
### Environment
- superset version: `1.3.0`
### Checklist
- [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.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org