You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2022/04/04 08:12:18 UTC
[superset] 18/23: fix: request samples with default row limit (#19456)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to tag 1.5.0rc1
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 3c627bdc618a736304606ff5f6bb6d532a7254f2
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Fri Apr 1 11:32:36 2022 +0300
fix: request samples with default row limit (#19456)
* fix: request samples with default row limit
* lodashLint
* fix cypress test
(cherry picked from commit d684ad073d63953d803cf05b4b208484f1fe7e51)
---
.../cypress/integration/explore/control.test.ts | 2 +-
.../src/explore/exploreUtils/index.js | 10 ++++++++-
superset/common/query_actions.py | 26 ++++++++++++----------
superset/common/query_object.py | 4 ++--
4 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts
index 804fffafa2..f8254ac9bb 100644
--- a/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts
@@ -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');
});
});
diff --git a/superset-frontend/src/explore/exploreUtils/index.js b/superset-frontend/src/explore/exploreUtils/index.js
index 679902243b..79bcb1a362 100644
--- a/superset-frontend/src/explore/exploreUtils/index.js
+++ b/superset-frontend/src/explore/exploreUtils/index.js
@@ -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';
@@ -215,7 +216,7 @@ export const buildV1ChartDataPayload = ({
...baseQueryObject,
},
]));
- return buildQuery(
+ const payload = buildQuery(
{
...formData,
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 }) =>
diff --git a/superset/common/query_actions.py b/superset/common/query_actions.py
index 2b85125b0e..5899757d52 100644
--- a/superset/common/query_actions.py
+++ b/superset/common/query_actions.py
@@ -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
@@ -41,13 +43,13 @@ config = app.config
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 {
@@ -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 {
@@ -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)
@@ -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)
@@ -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)
@@ -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,
@@ -179,8 +181,8 @@ _result_type_functions: Dict[
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]:
"""
diff --git a/superset/common/query_object.py b/superset/common/query_object.py
index 78a76fc3cd..40d37041b9 100644
--- a/superset/common/query_object.py
+++ b/superset/common/query_object.py
@@ -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
@@ -127,7 +127,7 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
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,