Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Query execution time is displayed as invalid date #19605

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion superset/queries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from superset.databases.filters import DatabaseFilter
from superset.models.sql_lab import Query
from superset.queries.filters import QueryFilter
from superset.queries.schemas import openapi_spec_methods_override
from superset.queries.schemas import openapi_spec_methods_override, QuerySchema
from superset.views.base_api import BaseSupersetModelRestApi, RelatedFieldFilter
from superset.views.filters import FilterRelatedOwners

Expand Down Expand Up @@ -94,6 +94,7 @@ class QueryRestApi(BaseSupersetModelRestApi):
]
base_filters = [["id", QueryFilter, lambda: []]]
base_order = ("changed_on", "desc")
list_model_schema = QuerySchema()

openapi_spec_tag = "Queries"
openapi_spec_methods = openapi_spec_methods_override
Expand Down
42 changes: 42 additions & 0 deletions superset/queries/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import List

from marshmallow import fields, Schema

from superset.dashboards.schemas import UserSchema
from superset.models.sql_lab import Query
from superset.sql_parse import Table

openapi_spec_methods_override = {
"get": {"get": {"description": "Get query detail information."}},
Expand All @@ -25,3 +32,38 @@
}
},
}


class DatabaseSchema(Schema):
database_name = fields.String()


class QuerySchema(Schema):
"""
Schema for the ``Query`` model.
"""

changed_on = fields.DateTime()
database = fields.Nested(DatabaseSchema)
end_time = fields.Float(attribute="end_time")
executed_sql = fields.String()
id = fields.Int()
rows = fields.Int()
schema = fields.String()
sql = fields.String()
sql_tables = fields.Method("get_sql_tables")
start_time = fields.Float(attribute="start_time")
status = fields.String()
tab_name = fields.String()
tmp_table_name = fields.String()
tracking_url = fields.String()
user = fields.Nested(UserSchema)

class Meta: # pylint: disable=too-few-public-methods
model = Query
load_instance = True
include_relationships = True

# pylint: disable=no-self-use
def get_sql_tables(self, obj: Query) -> List[Table]:
return obj.sql_tables