Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JINJA Template does not work with calculated time column #16984

Closed
3 tasks done
xingyc15 opened this issue Oct 5, 2021 · 2 comments
Closed
3 tasks done

JINJA Template does not work with calculated time column #16984

xingyc15 opened this issue Oct 5, 2021 · 2 comments
Labels
#bug Bug report global:jinja Related to Jinja templating inactive Inactive for >= 30 days need:community-volunteer Requires a community volunteer

Comments

@xingyc15
Copy link
Contributor

xingyc15 commented Oct 5, 2021

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

Screen Shot 2021-10-05 at 2 44 18 PM

Environment

  • superset version: 1.3.0

Checklist

  • I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • I have reproduced the issue with at least the latest released version of superset.
  • I have checked the issue tracker for the same issue and I haven't found one similar.
@xingyc15 xingyc15 added the #bug Bug report label Oct 5, 2021
@junlincc junlincc added need:community-volunteer Requires a community volunteer global:jinja Related to Jinja templating labels Oct 6, 2021
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

@stale stale bot added the inactive Inactive for >= 30 days label Apr 17, 2022
@rusackas
Copy link
Member

rusackas commented Feb 2, 2023

I believe this was closed by #17237

If I'm mistaken, holler, and we can revisit the discussion!

@rusackas rusackas closed this as completed Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#bug Bug report global:jinja Related to Jinja templating inactive Inactive for >= 30 days need:community-volunteer Requires a community volunteer
Projects
None yet
Development

No branches or pull requests

3 participants