Skip to content

Commit

Permalink
fix: Query execution time is displayed as invalid date (apache#19605)
Browse files Browse the repository at this point in the history
* fix: Query execution time is displayed as invalid date

* PR comment

* Fix test

* unify response

* lint
  • Loading branch information
diegomedina248 committed May 11, 2022
1 parent f0d3f91 commit c1010e9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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

0 comments on commit c1010e9

Please sign in to comment.