mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: add global max row limit (#16683)
* feat: add global max limit * fix lint and tests * leave SAMPLES_ROW_LIMIT unchanged * fix sample rowcount test * replace max global limit with existing sql max row limit * fix test * make max_limit optional in util * improve comments
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
# under the License.
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Dict, List, NamedTuple, Optional
|
||||
from typing import Any, Dict, List, NamedTuple, Optional, TYPE_CHECKING
|
||||
|
||||
from flask_babel import gettext as _
|
||||
from pandas import DataFrame
|
||||
@@ -28,6 +28,7 @@ from superset.exceptions import QueryObjectValidationError
|
||||
from superset.typing import Metric, OrderBy
|
||||
from superset.utils import pandas_postprocessing
|
||||
from superset.utils.core import (
|
||||
apply_max_row_limit,
|
||||
ChartDataResultType,
|
||||
DatasourceDict,
|
||||
DTTM_ALIAS,
|
||||
@@ -41,6 +42,10 @@ from superset.utils.date_parser import get_since_until, parse_human_timedelta
|
||||
from superset.utils.hashing import md5_sha_from_dict
|
||||
from superset.views.utils import get_time_range_endpoints
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from superset.common.query_context import QueryContext # pragma: no cover
|
||||
|
||||
|
||||
config = app.config
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -103,6 +108,7 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
|
||||
|
||||
def __init__( # pylint: disable=too-many-arguments,too-many-locals
|
||||
self,
|
||||
query_context: "QueryContext",
|
||||
annotation_layers: Optional[List[Dict[str, Any]]] = None,
|
||||
applied_time_extras: Optional[Dict[str, str]] = None,
|
||||
apply_fetch_values_predicate: bool = False,
|
||||
@@ -146,7 +152,7 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
|
||||
self.datasource = ConnectorRegistry.get_datasource(
|
||||
str(datasource["type"]), int(datasource["id"]), db.session
|
||||
)
|
||||
self.result_type = result_type
|
||||
self.result_type = result_type or query_context.result_type
|
||||
self.apply_fetch_values_predicate = apply_fetch_values_predicate or False
|
||||
self.annotation_layers = [
|
||||
layer
|
||||
@@ -186,7 +192,12 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
|
||||
for x in metrics
|
||||
]
|
||||
|
||||
self.row_limit = config["ROW_LIMIT"] if row_limit is None else row_limit
|
||||
default_row_limit = (
|
||||
config["SAMPLES_ROW_LIMIT"]
|
||||
if self.result_type == ChartDataResultType.SAMPLES
|
||||
else config["ROW_LIMIT"]
|
||||
)
|
||||
self.row_limit = apply_max_row_limit(row_limit or default_row_limit)
|
||||
self.row_offset = row_offset or 0
|
||||
self.filter = filters or []
|
||||
self.series_limit = series_limit
|
||||
|
||||
Reference in New Issue
Block a user