Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(warehouse_sources): add sigma computing report child tables (#113894)

Tom Owersf6fd2ba0cda3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index dce7e03f33c1..6baab6625536 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -7828,11 +7828,14 @@ Note: Coverage is solid for the images and videos verticals (categories, collect
## SigmaComputing — gaps
-Today (10): `Connections`, `DataModels`, `Members`, `Reports`, `Teams`, `WorkbookElements`, `WorkbookPages`, `WorkbookQueries`, `Workbooks`, `Workspaces`
+Today (13): `Connections`, `DataModels`, `Members`, `ReportElements`, `ReportPages`, `ReportQueries`, `Reports`, `Teams`, `WorkbookElements`, `WorkbookPages`, `WorkbookQueries`, `Workbooks`, `Workspaces`
Diffed against: <https://help.sigmacomputing.com/reference/get-started-sigma-api>
- [x] `reports (GET /v2/reports)` — org-level catalog of saved reports, the same top-level content shape as workbooks and data models, added here
+- [x] `report elements (GET /v2/reports/{reportId}/elements)` — per-report charts, tables, and controls, fanned out from reports like the workbook elements table, added here
+- [x] `report pages (GET /v2/reports/{reportId}/pages)` — per-report page list, fanned out from reports, added here
+- [x] `report queries (GET /v2/reports/{reportId}/queries)` — SQL behind each report element for query auditing, fanned out from reports, added here
## SigNoz — gaps
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/canonical_descriptions.py
index e39d2588b8ed..b2c4373583d6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/canonical_descriptions.py
@@ -161,4 +161,38 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"error": "Error message if the query failed to generate, otherwise empty.",
},
},
+ "ReportElements": {
+ "description": "An element (chart, table, or control) placed on a page within a Sigma report.",
+ "docs_url": "https://help.sigmacomputing.com/reference/list-report-elements",
+ "columns": {
+ "reportId": "Identifier of the report this element belongs to.",
+ "elementId": "Unique identifier for the element, within its report.",
+ "name": "Name of the element.",
+ "type": "The element's type (e.g. chart, table, control).",
+ "columns": "Column names the element pulls from its underlying data source.",
+ "vizualizationType": "The visualization type rendered by the element, when applicable.",
+ "error": "Error message if the element failed to compute, otherwise empty.",
+ },
+ },
+ "ReportPages": {
+ "description": "A page within a Sigma report.",
+ "docs_url": "https://help.sigmacomputing.com/reference/list-report-pages",
+ "columns": {
+ "reportId": "Identifier of the report this page belongs to.",
+ "pageId": "Unique identifier for the page, within its report.",
+ "name": "Display name of the page.",
+ "hidden": "Whether the page is hidden from end users.",
+ },
+ },
+ "ReportQueries": {
+ "description": "The SQL query behind one element of a Sigma report, used to audit what a report runs against its data source.",
+ "docs_url": "https://help.sigmacomputing.com/reference/list-report-queries",
+ "columns": {
+ "reportId": "Identifier of the report this query belongs to.",
+ "elementId": "Identifier of the element the query was generated for, within its report.",
+ "name": "Name of the element the query was generated for.",
+ "sql": "The SQL text Sigma runs for this element.",
+ "error": "Error message if the query failed to generate, otherwise empty.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/settings.py
index 65bc5341b7ca..4f7b1b2a9c2d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/settings.py
@@ -1,4 +1,5 @@
from dataclasses import field
+from typing import Literal
from posthog.dataclasses import frozen
@@ -51,13 +52,30 @@ WORKBOOK_FANOUT = DependentEndpointConfig(
parent_field_renames={"workbookId": "workbookId"},
)
+# Report-scoped child endpoints page with `pageToken`/`pageSize` instead of the `page`/`limit` the
+# parent Reports list takes, so each side's page size is passed as an explicit param rather than
+# through the fan-out helper's shared `page_size_param`.
+REPORT_FANOUT = DependentEndpointConfig(
+ parent_name="Reports",
+ resolve_param="reportId",
+ resolve_field="reportId",
+ include_from_parent=["reportId"],
+ parent_field_renames={"reportId": "reportId"},
+ parent_params={"limit": PAGE_SIZE},
+ child_params={"pageSize": PAGE_SIZE},
+)
+
+# "page" is `page`/`limit` in, `nextPage` out; "page_token" is `pageToken`/`pageSize` in,
+# `nextPageToken` out.
+Pagination = Literal["page", "page_token"]
+
@frozen
class SigmaComputingEndpointConfig:
name: str
path: str
primary_key: str | list[str]
- # Elements/pages/queries are workbook-scoped sub-resources with no created/updated
+ # Elements/pages/queries are workbook- and report-scoped sub-resources with no created/updated
# timestamp of their own, so they carry no partition key.
partition_key: str | None = "createdAt"
page_size: int = PAGE_SIZE
@@ -66,6 +84,7 @@ class SigmaComputingEndpointConfig:
incremental_fields: list[IncrementalField] = field(default_factory=list)
default_incremental_field: str | None = None
fanout: DependentEndpointConfig | None = None
+ pagination: Pagination = "page"
SIGMA_ENDPOINTS: dict[str, SigmaComputingEndpointConfig] = {
@@ -130,6 +149,32 @@ SIGMA_ENDPOINTS: dict[str, SigmaComputingEndpointConfig] = {
partition_key=None,
fanout=WORKBOOK_FANOUT,
),
+ "ReportElements": SigmaComputingEndpointConfig(
+ name="ReportElements",
+ path="/v2/reports/{reportId}/elements",
+ # elementId is only documented unique within its report.
+ primary_key=["reportId", "elementId"],
+ partition_key=None,
+ fanout=REPORT_FANOUT,
+ pagination="page_token",
+ ),
+ "ReportPages": SigmaComputingEndpointConfig(
+ name="ReportPages",
+ path="/v2/reports/{reportId}/pages",
+ primary_key=["reportId", "pageId"],
+ partition_key=None,
+ fanout=REPORT_FANOUT,
+ pagination="page_token",
+ ),
+ "ReportQueries": SigmaComputingEndpointConfig(
+ name="ReportQueries",
+ path="/v2/reports/{reportId}/queries",
+ # Entries carry no dedicated query id; elementId is unique per report.
+ primary_key=["reportId", "elementId"],
+ partition_key=None,
+ fanout=REPORT_FANOUT,
+ pagination="page_token",
+ ),
}
ENDPOINTS = tuple(SIGMA_ENDPOINTS)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/sigma_computing.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/sigma_computing.py
index 8bb418343832..2d20afce12b2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/sigma_computing.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/sigma_computing.py
@@ -23,6 +23,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sou
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.sigma_computing.settings import (
SIGMA_ENDPOINTS,
+ Pagination,
SigmaComputingEndpointConfig,
resolve_base_url,
)
@@ -38,13 +39,15 @@ class SigmaAuthError(Exception):
@frozen
class SigmaComputingResumeConfig:
# Opaque framework checkpoint: `{"cursor": ...}` for a top-level endpoint's
- # JSONResponseCursorPaginator, or the fan-out manager's combined state for a workbook-scoped
- # child endpoint - round-tripped into `initial_paginator_state` on resume. Frozen since it's
+ # JSONResponseCursorPaginator, or the fan-out manager's combined state for a workbook- or
+ # report-scoped child endpoint - round-tripped into `initial_paginator_state` on resume. Frozen since it's
# only ever constructed fresh and handed to `resumable_source_manager.save_state`.
paginator_state: dict[str, Any]
-def _paginator_config() -> PaginatorConfig:
+def _paginator_config(pagination: Pagination = "page") -> PaginatorConfig:
+ if pagination == "page_token":
+ return {"type": "cursor", "cursor_path": "nextPageToken", "cursor_param": "pageToken"}
return {"type": "cursor", "cursor_path": "nextPage", "cursor_param": "page"}
@@ -187,6 +190,7 @@ def sigma_computing_source(
resumable_source_manager.save_state(SigmaComputingResumeConfig(paginator_state=dict(state)))
if endpoint_config.fanout:
+ parent_config = SIGMA_ENDPOINTS[endpoint_config.fanout.parent_name]
dependent_resource = build_dependent_resource(
endpoint_configs=cast(Any, SIGMA_ENDPOINTS),
child_endpoint=endpoint,
@@ -196,9 +200,17 @@ def sigma_computing_source(
team_id=team_id,
job_id=job_id,
db_incremental_field_last_value=None,
- page_size_param="limit",
- parent_endpoint_extra={"paginator": _paginator_config(), "data_selector": "entries"},
- child_endpoint_extra={"paginator": _paginator_config(), "data_selector": "entries"},
+ # The two pagination styles name the page size differently, so a mixed fan-out sets it
+ # through the fanout's parent/child params instead.
+ page_size_param="limit" if endpoint_config.pagination == parent_config.pagination else None,
+ parent_endpoint_extra={
+ "paginator": _paginator_config(parent_config.pagination),
+ "data_selector": "entries",
+ },
+ child_endpoint_extra={
+ "paginator": _paginator_config(endpoint_config.pagination),
+ "data_selector": "entries",
+ },
resume_hook=save_checkpoint,
initial_paginator_state=initial_paginator_state,
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/tests/test_sigma_computing.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/tests/test_sigma_computing.py
index f36a177dd227..0206ebb8dc66 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/tests/test_sigma_computing.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sigma_computing/tests/test_sigma_computing.py
@@ -1,6 +1,6 @@
from collections.abc import Iterable
from typing import Any, Optional, cast
-from urllib.parse import parse_qs
+from urllib.parse import parse_qs, urlparse
import pytest
@@ -337,3 +337,51 @@ class TestSigmaComputingSourceFanout:
assert rows == [{**child_row, "workbookId": "wb1"}]
assert response.primary_keys == expected_primary_keys
+
+ @pytest.mark.parametrize(
+ "endpoint, child_path_suffix, first_row, second_row, expected_primary_keys",
+ [
+ ("ReportElements", "elements", {"elementId": "e1"}, {"elementId": "e2"}, ["reportId", "elementId"]),
+ ("ReportPages", "pages", {"pageId": "p1"}, {"pageId": "p2"}, ["reportId", "pageId"]),
+ ("ReportQueries", "queries", {"elementId": "e1"}, {"elementId": "e2"}, ["reportId", "elementId"]),
+ ],
+ )
+ def test_report_scoped_children_walk_page_token_pagination(
+ self,
+ requests_mock: Any,
+ endpoint: str,
+ child_path_suffix: str,
+ first_row: dict[str, Any],
+ second_row: dict[str, Any],
+ expected_primary_keys: list[str],
+ ) -> None:
+ _mock_token(requests_mock)
+ requests_mock.get(f"{BASE_URL}/v2/reports", json={"entries": [{"reportId": "rp1"}], "nextPage": None})
+ child_path = f"/v2/reports/rp1/{child_path_suffix}"
+ requests_mock.get(
+ f"{BASE_URL}{child_path}",
+ [
+ {"json": {"entries": [first_row], "nextPageToken": "TOKEN1"}},
+ {"json": {"entries": [second_row]}},
+ ],
+ )
+
+ response = sigma_computing_source(
+ region="gcp_us",
+ client_id="client",
+ client_secret="secret",
+ endpoint=endpoint,
+ team_id=1,
+ job_id="job-1",
+ resumable_source_manager=_FakeResumeManager(),
+ )
+ rows = _collect_rows(response)
+
+ assert rows == [{**first_row, "reportId": "rp1"}, {**second_row, "reportId": "rp1"}]
+ assert response.primary_keys == expected_primary_keys
+
+ def query(path: str) -> list[dict[str, list[str]]]:
+ return [parse_qs(urlparse(r.url).query) for r in requests_mock.request_history if r.path == path]
+
+ assert query("/v2/reports") == [{"limit": ["1000"]}]
+ assert query(child_path) == [{"pageSize": ["1000"]}, {"pageSize": ["1000"], "pageToken": ["TOKEN1"]}]