aminghadersohi commented on code in PR #43870:
URL: https://github.com/apache/superset/pull/43870#discussion_r4331610830
##########
superset/views/datasource/utils.py:
##########
@@ -217,12 +232,85 @@ def get_samples( # pylint: disable=too-many-arguments
sample_data["page"] = page
sample_data["per_page"] = per_page
- sample_data["total_count"] = count_star_data["data"][0]["COUNT(*)"]
+ if skip_count:
+ _set_lower_bound_total(
+ sample_data, row_offset, row_limit, probed=not via_cursor
+ )
+ else:
+ sample_data["total_count"] = count_star_data["data"][0]["COUNT(*)"]
+ sample_data["total_count_is_lower_bound"] = False
return sample_data
except (IndexError, KeyError) as exc:
raise DatasetSamplesFailedError from exc
+def _count_star_query_context(
+ datasource: Datasource,
+ payload: SamplesPayloadSchema | None,
+ form_data: dict[str, Any] | None,
+ force: bool,
+) -> QueryContext:
+ count_star_metric = {
+ "metrics": [
+ {
+ "expressionType": "SQL",
+ "sqlExpression": "COUNT(*)",
+ "label": "COUNT(*)",
+ }
+ ]
+ }
+ return QueryContextFactory().create(
+ datasource={
+ "type": datasource.type,
+ "id": datasource.id,
+ },
+ queries=[{**payload, **count_star_metric} if payload else
count_star_metric],
+ form_data=form_data,
+ result_type=ChartDataResultType.FULL,
+ force=force,
+ )
+
+
+def _get_count_star_data(
+ count_star_instance: QueryContext | None,
+) -> dict[str, Any]:
+ """Run the count query, or return an empty payload when it was skipped."""
+ if count_star_instance is None:
+ return {}
+
+ count_star_instance.raise_for_access()
+ count_star_data = count_star_instance.get_payload()["queries"][0]
+ if count_star_data.get("status") == QueryStatus.FAILED:
+ raise DatasetSamplesFailedError(count_star_data.get("error"))
+ return count_star_data
+
+
+def _set_lower_bound_total(
+ sample_data: dict[str, Any], row_offset: int, row_limit: int, probed: bool
+) -> None:
+ """
+ Report the total as "the rows up to and including this page".
+
+ The rows query asked for one probe row past the page. If it came back there
+ is at least one more page, so the probe is trimmed and the total flagged as
+ a lower bound; if it did not, this page is the last one and the total is
+ exact. The cursor path pages with an exact page size and has no probe row
+ (``probed=False``), so a full page is taken to mean there may be more.
+ """
+ data = sample_data.get("data") or []
+ page_size = row_limit or app.config["SAMPLES_ROW_LIMIT"]
+ if probed:
+ has_more = len(data) > page_size
Review Comment:
When the page size reaches SQL_MAX_ROW, QueryObjectFactory caps away the
lookahead row. A full page is then reported as an exact total, so Drill Detail
disables Next even when more rows exist.
```suggestion
has_more = len(data) > page_size or (
len(data) == page_size
and page_size >= apply_max_row_limit(page_size + 1)
)
```
--
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]