Skip to content

Conversation

@mystichronicle
Copy link

fix(client-core): preserve zero values with fillWithValue in pivot (#10225)

The fillWithValue pivot config option was using the || (logical OR) operator, which treats 0 as falsy. This caused actual zero values in the data to be incorrectly replaced by fillWithValue, not just missing/undefined values.

Changed the implementation to use the ?? (nullish coalescing) operator instead, which only falls through for null and undefined values, preserving actual 0 values in the data.

Impact: Users can now use fillWithValue to display "no data" indicators (like - or N/A) without also replacing legitimate zeros in their data.

Fixes #10225


Check List

  • Tests have been run in packages where changes have been made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Issue Reference this PR resolves

#10225

Description of Changes Made

Problem

The measureValue function in ResultSet.ts was using the || operator to provide fallback values:

const measureValue = (row, measure) => row[measure] || normalizedPivotConfig.fillWithValue || 0;

…ube-js#10225)

The fillWithValue pivot config option was using the || (logical OR) operator,
which treats 0 as falsy. This caused actual zero values in the data to be
incorrectly replaced by fillWithValue, not just missing/undefined values.

Changed the implementation to use the ?? (nullish coalescing) operator instead,
which only falls through for null and undefined values, preserving actual 0
values in the data.

Impact: Users can now use fillWithValue to display 'no data' indicators (like
'-' or 'N/A') without also replacing legitimate zeros in their data.

Fixes cube-js#10225
Copilot AI review requested due to automatic review settings December 6, 2025 20:19
@mystichronicle mystichronicle requested a review from a team as a code owner December 6, 2025 20:19
@github-actions github-actions bot added client:core Issues relating to the JavaScript client SDK javascript Pull requests that update Javascript code pr:community Contribution from Cube.js community members. labels Dec 6, 2025
Copy link

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

This PR fixes a bug where the fillWithValue pivot configuration option incorrectly replaced legitimate zero values in data. The fix changes the logical OR operator (||) to the nullish coalescing operator (??), which only treats null and undefined as missing values, not 0.

Key Changes:

  • Updated measureValue function to use ?? instead of || to preserve zero values
  • Added comprehensive test case to verify zeros are preserved while missing values are still filled

Reviewed changes

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

File Description
packages/cubejs-client-core/src/ResultSet.ts Changed measureValue function to use nullish coalescing operator (??) instead of logical OR (`
packages/cubejs-client-core/test/ResultSet.test.ts Added test case to verify that actual zero values are preserved while missing values are correctly replaced with fillWithValue

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client:core Issues relating to the JavaScript client SDK javascript Pull requests that update Javascript code pr:community Contribution from Cube.js community members.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pivot fillWithValue incorrectly replaces legitimate zero measure values

1 participant