EBoisseauSierra opened a new issue #15060:
URL: https://github.com/apache/superset/issues/15060


   When creating a “calculated column” `foo` (defined, e.g. as `col1 + col2`), 
I can't reuse it in the “custom metric” `bar`, as the generated SQL query uses 
`foo` literally (rather than expanding into its `col1 + col2` definition).
   
   This fails as `foo` doesn't actually exist as a column in the table I query.
   
   ## Expected results
   
   1. I define a **calculated column** (here, as the difference of 2 columns of 
my PostgreSQL table): 
   ![Screenshot from 2021-06-09 
10-36-40_shadow](https://user-images.githubusercontent.com/37387755/121333687-edba4780-c910-11eb-9795-fedab6e3989a.png)
   2. I define a **custom metrics** that notably **reuses my previously defined 
calculated column**: 
   ![Screenshot from 2021-06-09 
10-42-21_shadow](https://user-images.githubusercontent.com/37387755/121333886-1a6e5f00-c911-11eb-92da-fda7d8f24165.png)
   
   I want to be able to now build charts using that custom metrics: 
   ![Screenshot from 2021-06-09 
10-52-04_shadow](https://user-images.githubusercontent.com/37387755/121334303-72a56100-c911-11eb-921c-ebd25132d070.png)
   
   This means, running the following query:
   
   ```sql
   SELECT DATE_TRUNC('hour', timestamp) AS __timestamp,
          AVG(ABS(temperature_feelslike - temperature))::numeric(10, 
2)/AVG(temperature) AS avg_temp_offset
   FROM public.weather_forecast
   GROUP BY DATE_TRUNC('hour', timestamp)
   LIMIT 50000;
   ```
   
   ### Actual results
   
   However, trying to use the custom metrics in Explore fails:
   ![Screenshot from 2021-06-09 
10-59-37_shadow](https://user-images.githubusercontent.com/37387755/121334717-d3cd3480-c911-11eb-854b-0ba17b00670b.png)
   
   Indeed, the following query is executed:
   ```sql
   SELECT DATE_TRUNC('hour', timestamp) AS __timestamp,
          AVG(ABS(feelslike_offset))::numeric(10, 2)/AVG(temperature) AS 
avg_temp_offset
   FROM public.weather_forecast
   GROUP BY DATE_TRUNC('hour', timestamp)
   LIMIT 50000;
   ```
   (I.e. the `feelslike_offset` calculated column is not expanded to its 
definition: `temperature_feelslike - temperature`.)
   
   ## Environment
   
   (please complete the following information):
   
   - superset version: `1.1.0`
   - python version: `3.8.9`
   - node.js version: `node -v`
   
   ## Checklist
   
   Make sure to follow these steps before submitting your issue - thank you!
   
   - [ ] 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.

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