Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/cubejs-client-core/src/ResultSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ export default class ResultSet<T extends Record<string, any> = any> {

const pivotImpl = (resultIndex = 0) => {
let groupByXAxis = groupByToPairs<{ xValues: string[], row: Record<string, any> }, string>(({ xValues }) => this.axisValuesString(xValues));

const measureValue = (row: Record<string, any>, measure: string) => row[measure] || normalizedPivotConfig.fillWithValue || 0;
const measureValue = (row: Record<string, any>, measure: string) => row[measure] ?? normalizedPivotConfig.fillWithValue ?? 0;

if (
normalizedPivotConfig.fillMissingDates &&
Expand Down
73 changes: 73 additions & 0 deletions packages/cubejs-client-core/test/ResultSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,79 @@ describe('ResultSet', () => {
]);
});

test('fillWithValue should preserve actual zero values (issue #10225)', () => {
const resultSet = new ResultSet({
query: {
measures: ['TestCube.value'],
dimensions: ['TestCube.category', 'TestCube.type'],
filters: [],
timezone: 'UTC'
},
data: [
{
'TestCube.category': 'A',
'TestCube.type': 'X',
'TestCube.value': 10
},
{
'TestCube.category': 'A',
'TestCube.type': 'Y',
'TestCube.value': 0
},
{
'TestCube.category': 'B',
'TestCube.type': 'X',
'TestCube.value': 30
}
],
annotation: {
measures: {
'TestCube.value': {
title: 'Value',
shortTitle: 'Value',
type: 'number'
}
},
dimensions: {
'TestCube.category': {
title: 'Category',
shortTitle: 'Category',
type: 'string'
},
'TestCube.type': {
title: 'Type',
shortTitle: 'Type',
type: 'string'
}
},
segments: {},
timeDimensions: {}
}
} as any);

const pivotConfig = {
x: ['TestCube.category'],
y: ['TestCube.type', 'measures'],
fillWithValue: '-'
};

const result = resultSet.tablePivot(pivotConfig);

// Actual zero values should be preserved, not replaced by fillWithValue
expect(result).toEqual([
{
'TestCube.category': 'A',
'X,TestCube.value': 10,
'Y,TestCube.value': 0 // Zero should be preserved, not replaced with '-'
},
{
'TestCube.category': 'B',
'X,TestCube.value': 30,
'Y,TestCube.value': '-' // Missing value should be replaced with '-'
}
]);
});

test('same dimension and time dimension without granularity', () => {
const resultSet = new ResultSet({
query: {
Expand Down