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/07/05 07:49:14 UTC
[GitHub] [superset] zhaoyongjie commented on a change in pull request #15502: feat: supporting jinja templating in saved metrics
zhaoyongjie commented on a change in pull request #15502:
URL: https://github.com/apache/superset/pull/15502#discussion_r663712394
##########
File path: superset/connectors/sqla/models.py
##########
@@ -404,9 +404,14 @@ class SqlMetric(Model, BaseMetric):
)
export_parent = "table"
+ def get_template_processor(self, **kwargs: Any) -> BaseTemplateProcessor:
+ return self.table.get_template_processor()
+
def get_sqla_col(self, label: Optional[str] = None) -> Column:
label = label or self.metric_name
- sqla_col: ColumnClause = literal_column(self.expression)
+ sqla_col: ColumnClause = literal_column(
+ self.get_template_processor().process_template(self.expression)
+ )
Review comment:
It is not recommended to add the new instance method(get_template_processor) here.
```suggestion
def get_sqla_col(self, label: Optional[str] = None) -> Column:
label = label or self.metric_name
tp = self.table.get_template_processor()
sqla_col = literal_column(tp.process_template(self.expression))
return self.table.make_sqla_column_compatible(sqla_col, label)
```
--
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