Commit 22fbaa7a by Torkel Ödegaard Committed by GitHub

Singlestat: Fixed issue with mapping null to text (#19689)

parent b858a5f4
...@@ -116,11 +116,11 @@ describe('Stats Calculators', () => { ...@@ -116,11 +116,11 @@ describe('Stats Calculators', () => {
}, },
{ {
data: [null, null, null], // All null data: [null, null, null], // All null
result: undefined, result: null,
}, },
{ {
data: [undefined, undefined, undefined], // Empty row data: [undefined, undefined, undefined], // Empty row
result: undefined, result: null,
}, },
]; ];
......
...@@ -236,8 +236,8 @@ function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean ...@@ -236,8 +236,8 @@ function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean
mean: null, mean: null,
last: null, last: null,
first: null, first: null,
lastNotNull: undefined, lastNotNull: null,
firstNotNull: undefined, firstNotNull: null,
count: 0, count: 0,
nonNullCount: 0, nonNullCount: 0,
allIsNull: true, allIsNull: true,
...@@ -272,8 +272,8 @@ function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean ...@@ -272,8 +272,8 @@ function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean
} }
} }
if (currentValue !== null) { if (currentValue !== null && currentValue !== undefined) {
const isFirst = calcs.firstNotNull === undefined; const isFirst = calcs.firstNotNull === null;
if (isFirst) { if (isFirst) {
calcs.firstNotNull = currentValue; calcs.firstNotNull = currentValue;
} }
...@@ -366,11 +366,11 @@ function calculateFirstNotNull(field: Field, ignoreNulls: boolean, nullAsZero: b ...@@ -366,11 +366,11 @@ function calculateFirstNotNull(field: Field, ignoreNulls: boolean, nullAsZero: b
const data = field.values; const data = field.values;
for (let idx = 0; idx < data.length; idx++) { for (let idx = 0; idx < data.length; idx++) {
const v = data.get(idx); const v = data.get(idx);
if (v != null) { if (v != null && v !== undefined) {
return { firstNotNull: v }; return { firstNotNull: v };
} }
} }
return { firstNotNull: undefined }; return { firstNotNull: null };
} }
function calculateLast(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs { function calculateLast(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
...@@ -383,11 +383,11 @@ function calculateLastNotNull(field: Field, ignoreNulls: boolean, nullAsZero: bo ...@@ -383,11 +383,11 @@ function calculateLastNotNull(field: Field, ignoreNulls: boolean, nullAsZero: bo
let idx = data.length - 1; let idx = data.length - 1;
while (idx >= 0) { while (idx >= 0) {
const v = data.get(idx--); const v = data.get(idx--);
if (v != null) { if (v != null && v !== undefined) {
return { lastNotNull: v }; return { lastNotNull: v };
} }
} }
return { lastNotNull: undefined }; return { lastNotNull: null };
} }
function calculateChangeCount(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs { function calculateChangeCount(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment