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

This commit is contained in:
Torkel Ödegaard 2019-10-09 09:00:39 +02:00 committed by GitHub
parent b858a5f496
commit 22fbaa7ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -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,
}, },
]; ];

View File

@ -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
} }
} }
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
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
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 {