ktmud commented on code in PR #19421:
URL: https://github.com/apache/superset/pull/19421#discussion_r853265185
##########
superset/connectors/sqla/models.py:
##########
@@ -479,6 +541,58 @@ def data(self) -> Dict[str, Any]:
attr_dict.update(super().data)
return attr_dict
+ def to_sl_column(
+ self, known_columns: Optional[Dict[str, NewColumn]] = None
+ ) -> NewColumn:
+ """Convert a SqlMetric to NewColumn. Find and update existing or
+ create a new one."""
+ column = known_columns.get(self.uuid) if known_columns else None
+ if not column:
+ column = NewColumn()
+
+ extra_json = self.get_extra_dict()
+ for attr in {"verbose_name", "metric_type", "d3format"}:
+ value = getattr(self, attr)
+ if value is not None:
+ extra_json[attr] = value
+ is_additive = (
+ self.metric_type and self.metric_type.lower() in
ADDITIVE_METRIC_TYPES_LOWER
+ )
+
+ column.uuid = self.uuid
+ column.name = self.metric_name
+ column.created_on = self.created_on
+ column.changed_on = self.changed_on
+ column.created_by = self.created_by
+ column.changed_by = self.changed_by
+ column.type = "Unknown"
+ column.expression = self.expression
+ column.warning_text = self.warning_text
+ column.description = self.description
+ column.is_aggregation = True
+ column.is_additive = is_additive
+ column.is_filterable = False
+ column.is_increase_desired = True
+ column.is_managed_externally = self.table.is_managed_externally
+ column.is_partition = False
+ column.is_physical = False
+ column.is_spatial = False
+ column.extra_json = json.dumps(extra_json) if extra_json else None
+ column.external_url = self.table.external_url
+
+ return column
+
+ @staticmethod
+ def after_delete( # pylint: disable=unused-argument
+ mapper: Mapper,
+ connection: Connection,
+ target: "SqlMetric",
+ ) -> None:
+ session = inspect(target).session
+ dataset =
session.query(NewColumn).filter_by(uuid=target.uuid).one_or_none()
+ if dataset:
+ session.delete(dataset)
Review Comment:
Thanks for catching this!
##########
superset/connectors/sqla/models.py:
##########
@@ -479,6 +541,58 @@ def data(self) -> Dict[str, Any]:
attr_dict.update(super().data)
return attr_dict
+ def to_sl_column(
+ self, known_columns: Optional[Dict[str, NewColumn]] = None
+ ) -> NewColumn:
+ """Convert a SqlMetric to NewColumn. Find and update existing or
+ create a new one."""
+ column = known_columns.get(self.uuid) if known_columns else None
+ if not column:
+ column = NewColumn()
+
+ extra_json = self.get_extra_dict()
+ for attr in {"verbose_name", "metric_type", "d3format"}:
+ value = getattr(self, attr)
+ if value is not None:
+ extra_json[attr] = value
+ is_additive = (
+ self.metric_type and self.metric_type.lower() in
ADDITIVE_METRIC_TYPES_LOWER
+ )
+
+ column.uuid = self.uuid
+ column.name = self.metric_name
+ column.created_on = self.created_on
+ column.changed_on = self.changed_on
+ column.created_by = self.created_by
+ column.changed_by = self.changed_by
+ column.type = "Unknown"
Review Comment:
I created a constant.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]