Skip to content

fix: send measures as string array in aggregate() to match backend analytics API#1161

Merged
hotlong merged 3 commits intomainfrom
copilot/fix-measures-parameter-format
Apr 1, 2026
Merged

fix: send measures as string array in aggregate() to match backend analytics API#1161
hotlong merged 3 commits intomainfrom
copilot/fix-measures-parameter-format

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

ObjectStackAdapter.aggregate() sends measures as [{ field, function }] but MemoryAnalyticsService.resolveMeasure() calls .split('.') on each element, expecting strings. This causes TypeError: t.split is not a function on every analytics query.

Changes

  • Measure format — Convert to backend's ${field}_${function} convention (e.g. 'amount_sum'), with 'count' as special case
  • Dimensions — Send [] when groupBy === '_all' instead of ['_all'] for single-bucket aggregation
  • Response mapping — Rename measure keys in response (amount_sumamount) to match aggregateClientSide() output format that consumers expect
// Before
measures: [{ field: params.field, function: params.function }],
dimensions: [params.groupBy],

// After
const measureName = params.function === 'count'
  ? 'count'
  : `${params.field}_${params.function}`;

measures: [measureName],
dimensions: params.groupBy && params.groupBy !== '_all' ? [params.groupBy] : [],

Tests

10 new tests in aggregate.test.ts covering payload format, response key mapping, all response envelope variants, and client-side fallback.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectui-demo Ready Ready Preview, Comment Apr 1, 2026 1:55am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectui Ignored Ignored Apr 1, 2026 1:55am

Request Review

…alytics API format

The backend MemoryAnalyticsService.resolveMeasure() expects measure names as
strings (e.g. 'amount_sum', 'count') and calls .split('.') on them. Sending
object arrays ({field, function}) caused TypeError: t.split is not a function.

Changes:
- Convert measures from [{field, function}] to string format: 'count' for
  count aggregation, '${field}_${function}' for others (e.g. 'amount_sum')
- Send empty dimensions array when groupBy is '_all' (single-bucket)
- Map response measure keys back to original field names for consumers
- Add 10 unit tests covering payload format, response mapping, and fallback

Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/7e803790-d91b-4542-886e-743490f0dfc6

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix measures parameter format in analytics API call fix: send measures as string array in aggregate() to match backend analytics API Apr 1, 2026
Copilot AI requested a review from hotlong April 1, 2026 01:59
@hotlong hotlong marked this pull request as ready for review April 1, 2026 02:03
Copilot AI review requested due to automatic review settings April 1, 2026 02:03
@hotlong hotlong merged commit 4e87b80 into main Apr 1, 2026
4 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes ObjectStackAdapter.aggregate() to match the backend analytics API’s expected request/response shape, preventing runtime failures on analytics queries and keeping aggregate results consistent for consumers (charts/dashboard widgets).

Changes:

  • Send measures as a string array (['count'] or ${field}_${function} like amount_sum) instead of { field, function } objects.
  • Treat groupBy === '_all' as a single-bucket aggregation by sending dimensions: [].
  • Normalize analytics responses by remapping measure keys (e.g. amount_sum) back to the requested field key (e.g. amount), plus add Vitest coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/data-objectstack/src/index.ts Updates analytics payload formatting and remaps returned measure keys for consumer compatibility.
packages/data-objectstack/src/aggregate.test.ts Adds unit tests validating payload format, response normalization, envelope variants, and fallback behavior.
CHANGELOG.md Documents the analytics aggregate compatibility fix and related behavior changes.

Comment on lines +842 to 845
measures: [measureName],
// When groupBy is '_all' no dimensions are needed (single-bucket).
dimensions: params.groupBy && params.groupBy !== '_all' ? [params.groupBy] : [],
};
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

groupBy === '_all' is now treated as “no dimensions” for the server-side analytics query, but the fallback aggregateClientSide() (used in the catch path) still groups on the literal '_all' field and will return rows containing an _all key (e.g. { _all: 'Unknown', amount: ... }). This makes the output shape differ depending on whether the analytics endpoint is available. Consider aligning the fallback behavior for '_all' (single-bucket result) so both code paths return the same row shape, and add a test for the fallback path with groupBy: '_all'.

Copilot uses AI. Check for mistakes.
* query payload uses the correct string-based measure/dimension format
* expected by the backend analytics service (MemoryAnalyticsService).
*
* See: https://github.com/objectstack-ai/objectui/issues (measures format bug)
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test header comment references https://github.com/objectstack-ai/objectui/issues which points to the generic issues list, not the specific bug/issue being validated. Linking to a specific issue (or removing the link) would make it easier to trace why these tests exist.

Suggested change
* See: https://github.com/objectstack-ai/objectui/issues (measures format bug)
* Related to prior measures format bug in analytics payloads.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【Bug】前端聚合分析 API 调用 measures 参数格式错误,导致后端 t.split 报错

3 participants