Skip to content

Commit

Permalink
fix: request samples with default row limit (#19456)
Browse files Browse the repository at this point in the history
* fix: request samples with default row limit

* lodashLint

* fix cypress test
  • Loading branch information
villebro committed Apr 1, 2022
1 parent 2a75e4c commit d684ad0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Test datatable', () => {
it('Datapane loads view samples', () => {
cy.get('[data-test="data-tab"]').click();
cy.contains('View samples').click();
cy.get('[data-test="row-count-label"]').contains('10k rows retrieved');
cy.get('[data-test="row-count-label"]').contains('1k rows retrieved');
cy.get('.ant-empty-description').should('not.exist');
});
});
Expand Down
10 changes: 9 additions & 1 deletion superset-frontend/src/explore/exploreUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getChartBuildQueryRegistry,
getChartMetadataRegistry,
} from '@superset-ui/core';
import { omit } from 'lodash';
import { availableDomains } from 'src/utils/hostNamesConfig';
import { safeStringify } from 'src/utils/safeStringify';
import { URL_PARAMS } from 'src/constants';
Expand Down Expand Up @@ -215,7 +216,7 @@ export const buildV1ChartDataPayload = ({
...baseQueryObject,
},
]));
return buildQuery(
const payload = buildQuery(
{
...formData,
force,
Expand All @@ -229,6 +230,13 @@ export const buildV1ChartDataPayload = ({
},
},
);
if (resultType === 'samples') {
// remove row limit and offset to fall back to defaults
payload.queries = payload.queries.map(query =>
omit(query, ['row_limit', 'row_offset']),
);
}
return payload;
};

export const getLegacyEndpointType = ({ resultType, resultFormat }) =>
Expand Down
26 changes: 14 additions & 12 deletions superset/common/query_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

import copy
from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING

Expand Down Expand Up @@ -41,13 +43,13 @@


def _get_datasource(
query_context: "QueryContext", query_obj: "QueryObject"
query_context: QueryContext, query_obj: QueryObject
) -> BaseDatasource:
return query_obj.datasource or query_context.datasource


def _get_columns(
query_context: "QueryContext", query_obj: "QueryObject", _: bool
query_context: QueryContext, query_obj: QueryObject, _: bool
) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj)
return {
Expand All @@ -63,7 +65,7 @@ def _get_columns(


def _get_timegrains(
query_context: "QueryContext", query_obj: "QueryObject", _: bool
query_context: QueryContext, query_obj: QueryObject, _: bool
) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj)
return {
Expand All @@ -79,8 +81,8 @@ def _get_timegrains(


def _get_query(
query_context: "QueryContext",
query_obj: "QueryObject",
query_context: QueryContext,
query_obj: QueryObject,
_: bool,
) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj)
Expand All @@ -93,8 +95,8 @@ def _get_query(


def _get_full(
query_context: "QueryContext",
query_obj: "QueryObject",
query_context: QueryContext,
query_obj: QueryObject,
force_cached: Optional[bool] = False,
) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj)
Expand Down Expand Up @@ -140,7 +142,7 @@ def _get_full(


def _get_samples(
query_context: "QueryContext", query_obj: "QueryObject", force_cached: bool = False
query_context: QueryContext, query_obj: QueryObject, force_cached: bool = False
) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj)
query_obj = copy.copy(query_obj)
Expand All @@ -155,14 +157,14 @@ def _get_samples(


def _get_results(
query_context: "QueryContext", query_obj: "QueryObject", force_cached: bool = False
query_context: QueryContext, query_obj: QueryObject, force_cached: bool = False
) -> Dict[str, Any]:
payload = _get_full(query_context, query_obj, force_cached)
return payload


_result_type_functions: Dict[
ChartDataResultType, Callable[["QueryContext", "QueryObject", bool], Dict[str, Any]]
ChartDataResultType, Callable[[QueryContext, QueryObject, bool], Dict[str, Any]]
] = {
ChartDataResultType.COLUMNS: _get_columns,
ChartDataResultType.TIMEGRAINS: _get_timegrains,
Expand All @@ -179,8 +181,8 @@ def _get_results(

def get_query_results(
result_type: ChartDataResultType,
query_context: "QueryContext",
query_obj: "QueryObject",
query_context: QueryContext,
query_obj: QueryObject,
force_cached: bool,
) -> Dict[str, Any]:
"""
Expand Down
4 changes: 2 additions & 2 deletions superset/common/query_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
orderby: List[OrderBy]
post_processing: List[Dict[str, Any]]
result_type: Optional[ChartDataResultType]
row_limit: int
row_limit: Optional[int]
row_offset: int
series_columns: List[Column]
series_limit: int
Expand All @@ -127,7 +127,7 @@ def __init__( # pylint: disable=too-many-locals
order_desc: bool = True,
orderby: Optional[List[OrderBy]] = None,
post_processing: Optional[List[Optional[Dict[str, Any]]]] = None,
row_limit: int,
row_limit: Optional[int],
row_offset: Optional[int] = None,
series_columns: Optional[List[Column]] = None,
series_limit: int = 0,
Expand Down

0 comments on commit d684ad0

Please sign in to comment.