dpgaspar commented on a change in pull request #9427: feat: Add post processing
to QueryObject
URL:
https://github.com/apache/incubator-superset/pull/9427#discussion_r405380855
##########
File path: superset/common/query_object.py
##########
@@ -138,9 +145,36 @@ def cache_key(self, **extra: Any) -> str:
if self.time_range:
cache_dict["time_range"] = self.time_range
json_data = self.json_dumps(cache_dict, sort_keys=True)
+ if self.post_processing:
+ cache_dict["post_processing"] = self.post_processing
return hashlib.md5(json_data.encode("utf-8")).hexdigest()
def json_dumps(self, obj: Any, sort_keys: bool = False) -> str:
return json.dumps(
obj, default=utils.json_int_dttm_ser, ignore_nan=True,
sort_keys=sort_keys
)
+
+ def exec_post_processing(self, df: DataFrame) -> DataFrame:
+ """
+ Perform post processing operations on DataFrame.
+
+ :param df: DataFrame returned from database model.
+ :return: new DataFrame to which all post processing operations have
been
+ applied
+ """
+ for post_process in self.post_processing:
+ operation = post_process.get("operation")
+ if not operation:
+ raise SupersetException(
+ _("`operation` property of post processing object
undefined")
+ )
Review comment:
It would be nice to set these exceptions to something bit more specific
`QueryPostProcessingValidationError` for example. This way the API can catch
and send the appropriate HTTP response
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]