mirror of
https://github.com/apache/superset.git
synced 2026-05-12 11:25:56 +00:00
fix(query-history): enable sorting by Duration column (#39637)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
(cherry picked from commit c4a8b34b11)
This commit is contained in:
committed by
Michael S. Molina
parent
87e5450cbe
commit
b55bb4e3ce
@@ -44,6 +44,7 @@ from sqlalchemy import (
|
||||
Text,
|
||||
)
|
||||
from sqlalchemy.engine.url import URL
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
from sqlalchemy.sql.elements import ColumnElement, literal_column
|
||||
from superset_core.queries.models import (
|
||||
@@ -159,6 +160,20 @@ class Query(
|
||||
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=True
|
||||
)
|
||||
|
||||
@hybrid_property
|
||||
def duration(self) -> Optional[float]:
|
||||
start = self.start_running_time or self.start_time
|
||||
if self.end_time is not None and start is not None:
|
||||
return float(self.end_time - start)
|
||||
return None
|
||||
|
||||
@duration.expression # type: ignore[no-redef]
|
||||
def duration(cls) -> ColumnElement: # noqa: N805
|
||||
return sqla.func.coalesce(
|
||||
cls.end_time - sqla.func.coalesce(cls.start_running_time, cls.start_time),
|
||||
0,
|
||||
)
|
||||
|
||||
database = relationship(
|
||||
"Database",
|
||||
foreign_keys=[database_id],
|
||||
|
||||
Reference in New Issue
Block a user