villebro commented on code in PR #37647:
URL: https://github.com/apache/superset/pull/37647#discussion_r2765215234
##########
superset/explorables/base.py:
##########
@@ -53,6 +53,130 @@ class TimeGrainDict(TypedDict):
duration: str | None
+@runtime_checkable
+class MetricMetadata(Protocol):
Review Comment:
Did we decide that semantic layers will be tabular and have first class
support for SQL-like metrics? I suspect this is the way to go, but it's
something worth deciding on in the SIP before implementation.
##########
superset/explorables/base.py:
##########
@@ -53,6 +53,130 @@ class TimeGrainDict(TypedDict):
duration: str | None
+@runtime_checkable
+class MetricMetadata(Protocol):
+ """
+ Protocol for metric metadata objects.
+
+ Represents a metric that's available on an explorable data source.
+ Metrics contain SQL expressions or references to semantic layer measures.
+
+ Attributes:
+ metric_name: Unique identifier for the metric
+ expression: SQL expression or reference for calculating the metric
+ verbose_name: Human-readable name for display in the UI
+ description: Description of what the metric represents
+ d3format: D3 format string for formatting numeric values
Review Comment:
I think we should be moving away from "d3 formats", and having formatters
being their own abstraction that can be implemented by extensions (the d3
formatter would be a built-in formatter, but there would be others, like
currency formatters etc, that all implement the same interface). This has been
discussed at length in the extensions WG, and is planned for implementation
when we take on viz plugin extensions.
##########
superset/explorables/base.py:
##########
@@ -53,6 +53,130 @@ class TimeGrainDict(TypedDict):
duration: str | None
+@runtime_checkable
+class MetricMetadata(Protocol):
+ """
+ Protocol for metric metadata objects.
+
+ Represents a metric that's available on an explorable data source.
+ Metrics contain SQL expressions or references to semantic layer measures.
+
+ Attributes:
+ metric_name: Unique identifier for the metric
+ expression: SQL expression or reference for calculating the metric
+ verbose_name: Human-readable name for display in the UI
+ description: Description of what the metric represents
+ d3format: D3 format string for formatting numeric values
+ currency: Currency configuration for the metric (JSON object)
+ warning_text: Warning message to display when using this metric
+ certified_by: Person or entity that certified this metric
+ certification_details: Details about the certification
+ """
+
+ @property
+ def metric_name(self) -> str:
+ """Unique identifier for the metric."""
+
+ @property
+ def expression(self) -> str:
+ """SQL expression or reference for calculating the metric."""
+
+ @property
+ def verbose_name(self) -> str | None:
+ """Human-readable name for display in the UI."""
+
+ @property
+ def description(self) -> str | None:
+ """Description of what the metric represents."""
+
+ @property
+ def d3format(self) -> str | None:
+ """D3 format string for formatting numeric values."""
+
+ @property
+ def currency(self) -> dict[str, Any] | None:
+ """Currency configuration for the metric (JSON object)."""
+
+ @property
+ def warning_text(self) -> str | None:
+ """Warning message to display when using this metric."""
+
+ @property
+ def certified_by(self) -> str | None:
+ """Person or entity that certified this metric."""
+
+ @property
+ def certification_details(self) -> str | None:
+ """Details about the certification."""
+
+
+@runtime_checkable
+class ColumnMetadata(Protocol):
+ """
+ Protocol for column metadata objects.
+
+ Represents a column/dimension that's available on an explorable data
source.
+ Used for grouping, filtering, and dimension-based analysis.
+
+ Attributes:
+ column_name: Unique identifier for the column
+ type: SQL data type of the column (e.g., 'VARCHAR', 'INTEGER',
'DATETIME')
+ is_dttm: Whether this column represents a date or time value
+ verbose_name: Human-readable name for display in the UI
+ description: Description of what the column represents
+ groupby: Whether this column is allowed for grouping/aggregation
+ filterable: Whether this column can be used in filters
+ expression: SQL expression if this is a calculated column
+ python_date_format: Python datetime format string for temporal columns
+ advanced_data_type: Advanced data type classification
+ extra: Additional metadata stored as JSON
+ """
+
+ @property
+ def column_name(self) -> str:
+ """Unique identifier for the column."""
+
+ @property
+ def type(self) -> str:
+ """SQL data type of the column."""
Review Comment:
I think there was discussion about opening up to non-SQL datasources (e.g.
Prometheus). Is the intention to limit semantic layers to SQL only?
##########
superset/explorables/base.py:
##########
@@ -53,6 +53,130 @@ class TimeGrainDict(TypedDict):
duration: str | None
+@runtime_checkable
+class MetricMetadata(Protocol):
+ """
+ Protocol for metric metadata objects.
+
+ Represents a metric that's available on an explorable data source.
+ Metrics contain SQL expressions or references to semantic layer measures.
+
+ Attributes:
+ metric_name: Unique identifier for the metric
+ expression: SQL expression or reference for calculating the metric
+ verbose_name: Human-readable name for display in the UI
+ description: Description of what the metric represents
+ d3format: D3 format string for formatting numeric values
+ currency: Currency configuration for the metric (JSON object)
+ warning_text: Warning message to display when using this metric
+ certified_by: Person or entity that certified this metric
+ certification_details: Details about the certification
+ """
+
+ @property
+ def metric_name(self) -> str:
+ """Unique identifier for the metric."""
+
+ @property
+ def expression(self) -> str:
+ """SQL expression or reference for calculating the metric."""
+
+ @property
+ def verbose_name(self) -> str | None:
+ """Human-readable name for display in the UI."""
+
+ @property
+ def description(self) -> str | None:
+ """Description of what the metric represents."""
+
+ @property
+ def d3format(self) -> str | None:
+ """D3 format string for formatting numeric values."""
+
+ @property
+ def currency(self) -> dict[str, Any] | None:
+ """Currency configuration for the metric (JSON object)."""
+
+ @property
+ def warning_text(self) -> str | None:
+ """Warning message to display when using this metric."""
+
+ @property
+ def certified_by(self) -> str | None:
+ """Person or entity that certified this metric."""
+
+ @property
+ def certification_details(self) -> str | None:
+ """Details about the certification."""
+
+
+@runtime_checkable
+class ColumnMetadata(Protocol):
Review Comment:
Same comment as for metrics (let's be explicit in the SIP about restricting
to tabular data with SQL-like metrics/columns)
--
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]