fix: request samples with default row limit (#19456)

* fix: request samples with default row limit

* lodashLint

* fix cypress test
This commit is contained in:
Ville Brofeldt 2022-04-01 11:32:36 +03:00 committed by GitHub
parent 2a75e4c3c3
commit d684ad073d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 16 deletions

View File

@ -129,7 +129,7 @@ describe('Test datatable', () => {
it('Datapane loads view samples', () => { it('Datapane loads view samples', () => {
cy.get('[data-test="data-tab"]').click(); cy.get('[data-test="data-tab"]').click();
cy.contains('View samples').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'); cy.get('.ant-empty-description').should('not.exist');
}); });
}); });

View File

@ -26,6 +26,7 @@ import {
getChartBuildQueryRegistry, getChartBuildQueryRegistry,
getChartMetadataRegistry, getChartMetadataRegistry,
} from '@superset-ui/core'; } from '@superset-ui/core';
import { omit } from 'lodash';
import { availableDomains } from 'src/utils/hostNamesConfig'; import { availableDomains } from 'src/utils/hostNamesConfig';
import { safeStringify } from 'src/utils/safeStringify'; import { safeStringify } from 'src/utils/safeStringify';
import { URL_PARAMS } from 'src/constants'; import { URL_PARAMS } from 'src/constants';
@ -215,7 +216,7 @@ export const buildV1ChartDataPayload = ({
...baseQueryObject, ...baseQueryObject,
}, },
])); ]));
return buildQuery( const payload = buildQuery(
{ {
...formData, ...formData,
force, force,
@ -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 }) => export const getLegacyEndpointType = ({ resultType, resultFormat }) =>

View File

@ -14,6 +14,8 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
from __future__ import annotations
import copy import copy
from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING
@ -41,13 +43,13 @@ config = app.config
def _get_datasource( def _get_datasource(
query_context: "QueryContext", query_obj: "QueryObject" query_context: QueryContext, query_obj: QueryObject
) -> BaseDatasource: ) -> BaseDatasource:
return query_obj.datasource or query_context.datasource return query_obj.datasource or query_context.datasource
def _get_columns( def _get_columns(
query_context: "QueryContext", query_obj: "QueryObject", _: bool query_context: QueryContext, query_obj: QueryObject, _: bool
) -> Dict[str, Any]: ) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj) datasource = _get_datasource(query_context, query_obj)
return { return {
@ -63,7 +65,7 @@ def _get_columns(
def _get_timegrains( def _get_timegrains(
query_context: "QueryContext", query_obj: "QueryObject", _: bool query_context: QueryContext, query_obj: QueryObject, _: bool
) -> Dict[str, Any]: ) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj) datasource = _get_datasource(query_context, query_obj)
return { return {
@ -79,8 +81,8 @@ def _get_timegrains(
def _get_query( def _get_query(
query_context: "QueryContext", query_context: QueryContext,
query_obj: "QueryObject", query_obj: QueryObject,
_: bool, _: bool,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj) datasource = _get_datasource(query_context, query_obj)
@ -93,8 +95,8 @@ def _get_query(
def _get_full( def _get_full(
query_context: "QueryContext", query_context: QueryContext,
query_obj: "QueryObject", query_obj: QueryObject,
force_cached: Optional[bool] = False, force_cached: Optional[bool] = False,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj) datasource = _get_datasource(query_context, query_obj)
@ -140,7 +142,7 @@ def _get_full(
def _get_samples( 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]: ) -> Dict[str, Any]:
datasource = _get_datasource(query_context, query_obj) datasource = _get_datasource(query_context, query_obj)
query_obj = copy.copy(query_obj) query_obj = copy.copy(query_obj)
@ -155,14 +157,14 @@ def _get_samples(
def _get_results( 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]: ) -> Dict[str, Any]:
payload = _get_full(query_context, query_obj, force_cached) payload = _get_full(query_context, query_obj, force_cached)
return payload return payload
_result_type_functions: Dict[ _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.COLUMNS: _get_columns,
ChartDataResultType.TIMEGRAINS: _get_timegrains, ChartDataResultType.TIMEGRAINS: _get_timegrains,
@ -179,8 +181,8 @@ _result_type_functions: Dict[
def get_query_results( def get_query_results(
result_type: ChartDataResultType, result_type: ChartDataResultType,
query_context: "QueryContext", query_context: QueryContext,
query_obj: "QueryObject", query_obj: QueryObject,
force_cached: bool, force_cached: bool,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
""" """

View File

@ -100,7 +100,7 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
orderby: List[OrderBy] orderby: List[OrderBy]
post_processing: List[Dict[str, Any]] post_processing: List[Dict[str, Any]]
result_type: Optional[ChartDataResultType] result_type: Optional[ChartDataResultType]
row_limit: int row_limit: Optional[int]
row_offset: int row_offset: int
series_columns: List[Column] series_columns: List[Column]
series_limit: int series_limit: int
@ -127,7 +127,7 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
order_desc: bool = True, order_desc: bool = True,
orderby: Optional[List[OrderBy]] = None, orderby: Optional[List[OrderBy]] = None,
post_processing: Optional[List[Optional[Dict[str, Any]]]] = None, post_processing: Optional[List[Optional[Dict[str, Any]]]] = None,
row_limit: int, row_limit: Optional[int],
row_offset: Optional[int] = None, row_offset: Optional[int] = None,
series_columns: Optional[List[Column]] = None, series_columns: Optional[List[Column]] = None,
series_limit: int = 0, series_limit: int = 0,