villebro commented on a change in pull request #13233:
URL: https://github.com/apache/superset/pull/13233#discussion_r579628907



##########
File path: superset/viz.py
##########
@@ -1053,6 +1052,15 @@ def query_obj(self) -> QueryObjectDict:
         d = super().query_obj()
         fd = self.form_data
         d["metrics"] = fd.get("metrics")
+        mapping = {
+            "min": "PT1M",
+            "hour": "PT1H",
+            "day": "P1D",
+            "week": "P1W",
+            "month": "P1M",
+            "year": "P1Y",
+        }
+        d["extras"]["time_grain_sqla"] = 
mapping[fd.get("subdomain_granularity", "min")]

Review comment:
       Minor improvement proposal: To make this work for Legacy Druid, we'd 
need to set the `d["granularity"]` property to time grain. so something like 
this:
   ```python
   time_grain = mapping[fd.get("subdomain_granularity", "min")]
   if self.datasource.type == 'druid':
       d["granularity"] = time_grain
   else:
       d["extras"]["time_grain_sqla"] = time_grain
   ```
   

##########
File path: superset/viz.py
##########
@@ -1031,7 +1030,7 @@ def get_data(self, df: pd.DataFrame) -> VizData:
         diff_secs = (end - start).total_seconds()
 
         if domain == "year":
-            range_ = diff_delta.years + 1
+            range_ = end.year - start.year + 1

Review comment:
       good catch!




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