zhaoyongjie commented on code in PR #20683: URL: https://github.com/apache/superset/pull/20683#discussion_r925674725
########## superset/views/datasource/utils.py: ########## @@ -0,0 +1,113 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from typing import Any, Dict, Optional + +from superset import app, db +from superset.common.chart_data import ChartDataResultType +from superset.common.query_context_factory import QueryContextFactory +from superset.common.utils.query_cache_manager import QueryCacheManager +from superset.constants import CacheRegion +from superset.datasets.commands.exceptions import DatasetSamplesFailedError +from superset.datasource.dao import DatasourceDAO +from superset.utils.core import QueryStatus +from superset.views.datasource.schemas import SamplesPayloadSchema + + +def get_limit_clause(page: Optional[int], per_page: Optional[int]) -> Dict[str, int]: + samples_row_limit = app.config.get("SAMPLES_ROW_LIMIT", 1000) + limit = samples_row_limit + offset = 0 + + if isinstance(page, int) and isinstance(per_page, int): + limit = int(per_page) + if limit < 0 or limit > samples_row_limit: + # reset limit value if input is invalid + limit = samples_row_limit + + offset = max((int(page) - 1) * limit, 0) + + return {"row_offset": offset, "row_limit": limit} + + +def get_samples( # pylint: disable=too-many-arguments,too-many-locals + datasource_type: str, + datasource_id: int, + force: bool = False, + page: int = 1, + per_page: int = 1000, Review Comment: the `SAMPLES_ROW_LIMIT` is not a constant, It is an attribute in the flask app config. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
