This is an automated email from the ASF dual-hosted git repository. lyndsi pushed a commit to branch lyndsi/sql-lab-new-explore-button-functionality-and-move-save-dataset-to-split-save-button in repository https://gitbox.apache.org/repos/asf/superset.git
commit 994fc3fda03025f7bd94ac84aff3f12e784dcbeb Author: Hugh A. Miles II <[email protected]> AuthorDate: Wed Jun 22 16:37:20 2022 +0000 down to 26 now --- superset/models/helpers.py | 38 ++++++++++++++++++++++++++++---------- superset/models/sql_lab.py | 23 +++++++++++++---------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/superset/models/helpers.py b/superset/models/helpers.py index 6e501291f2..73f10741fb 100644 --- a/superset/models/helpers.py +++ b/superset/models/helpers.py @@ -34,6 +34,7 @@ from typing import ( Set, Tuple, Type, + TYPE_CHECKING, Union, ) @@ -50,6 +51,7 @@ from flask_appbuilder.models.decorators import renders from flask_appbuilder.models.mixins import AuditMixin from flask_appbuilder.security.sqla.models import User from flask_babel import lazy_gettext as _ +from jinja2.exceptions import TemplateError from sqlalchemy import and_, or_, UniqueConstraint from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.orm import Mapper, Session @@ -61,15 +63,15 @@ from sqlalchemy_utils import UUIDType from superset import app, db, is_feature_enabled, security_manager from superset.common.db_query_status import QueryStatus -# from superset.connectors.sqla import SqlMetric -# from superset.errors import ErrorLevel, SupersetError, SupersetErrorType -# from superset.exceptions import SupersetSecurityException +from superset.constants import EMPTY_STRING, NULL_STRING +from superset.errors import ErrorLevel, SupersetError, SupersetErrorType +from superset.exceptions import SupersetSecurityException +from superset.extensions import feature_flag_manager from superset.jinja_context import ( BaseTemplateProcessor, ExtraCache, get_template_processor, ) -# from superset.models.core import Database from superset.sql_parse import ( extract_table_references, has_table_query, @@ -78,9 +80,13 @@ from superset.sql_parse import ( sanitize_clause, Table as TableName, ) +from superset.superset_typing import AdhocColumn from superset.utils import core as utils -VIRTUAL_TABLE_ALIAS = "virtual_table" +if TYPE_CHECKING: + from superset.connectors.sqla.models import SqlMetric, TableColumn + from superset.db_engine_specs import BaseEngineSpec + from superset.models.core import Database config = app.config logger = logging.getLogger(__name__) @@ -673,6 +679,14 @@ class ExploreMixin: "MAX": sa.func.MAX, } + @property + def query(self) -> str: + raise NotImplementedError() + + @property + def database_id(self) -> int: + raise NotImplementedError() + @property def owners_data(self) -> List[Any]: raise NotImplementedError() @@ -729,6 +743,10 @@ class ExploreMixin: def columns(self) -> List[Any]: raise NotImplementedError() + @property + def get_fetch_values_predicate(self) -> List[Any]: + raise NotImplementedError() + @staticmethod def get_extra_cache_keys(query_obj: Dict[str, Any]) -> List[str]: raise NotImplementedError() @@ -970,7 +988,7 @@ class ExploreMixin: cte = self.db_engine_spec.get_cte_query(from_sql) from_clause = ( - table(CTE_ALIAS) + sa.table(CTE_ALIAS) if cte else TextAsFrom(self.text(from_sql), []).alias(VIRTUAL_TABLE_ALIAS) ) @@ -980,7 +998,7 @@ class ExploreMixin: def adhoc_metric_to_sqla( self, metric: AdhocMetric, - columns_by_name: Dict[str, Dict], + columns_by_name: Dict[str, Dict[str, Any]], template_processor: Optional[BaseTemplateProcessor] = None, ) -> ColumnElement: """ @@ -1406,7 +1424,7 @@ class ExploreMixin: col=granularity, ) ) - time_filters = [] + time_filters: List[Any] = [] if is_timeseries: timestamp = dttm_col.get_timestamp_expression( @@ -1474,7 +1492,7 @@ class ExploreMixin: filter_grain = flt.get("grain") if is_feature_enabled("ENABLE_TEMPLATE_REMOVE_FILTERS"): - if get_column_name(flt_col) in removed_filters: + if utils.get_column_name(flt_col) in removed_filters: # Skip generating SQLA filter when the jinja template handles it. continue @@ -1737,7 +1755,7 @@ class ExploreMixin: "order_desc": True, } - result = self.query(prequery_obj) + result = self.query(prequery_obj) # ignore: typing prequeries.append(result.query) dimensions = [ c diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py index 9440d7a093..6c6e10b514 100644 --- a/superset/models/sql_lab.py +++ b/superset/models/sql_lab.py @@ -17,7 +17,7 @@ """A collection of ORM sqlalchemy models for SQL Lab""" import re from datetime import datetime -from typing import Any, Dict, List, Type +from typing import Any, Dict, List, Optional, Type, TYPE_CHECKING import simplejson as json import sqlalchemy as sqla @@ -52,6 +52,9 @@ from superset.sqllab.limiting_factor import LimitingFactor from superset.superset_typing import ResultSetColumnType from superset.utils.core import QueryStatus, user_label +if TYPE_CHECKING: + from superset.db_engine_specs import BaseEngineSpec + class Query(Model, ExtraJSONMixin, ExploreMixin): """ORM model for SQL query @@ -248,35 +251,35 @@ class Query(Model, ExtraJSONMixin, ExploreMixin): return self.database.db_engine_spec @property - def owners_data(self): + def owners_data(self) -> List[Dict[str, Any]]: return [] @property - def metrics(self): + def metrics(self) -> List[Any]: return [] @property - def uid(self): + def uid(self) -> str: return "foo" @property - def is_rls_supported(self): + def is_rls_supported(self) -> bool: return False @property - def cache_timeout(self): - return None + def cache_timeout(self) -> int: + return 0 @property - def column_names(self): + def column_names(self) -> List[Any]: return [col.get("column_name") for col in self.columns] @property - def offset(self): + def offset(self) -> int: return 0 @property - def main_dttm_col(self) -> str: + def main_dttm_col(self) -> Optional[str]: for col in self.columns: if col.get("is_dttm"): return col.get("column_name")
