From 14274a960ec920bf3769b908b9a1fe930a0c8357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Wed, 21 Jul 2021 10:44:41 +0200 Subject: [PATCH] influxdb: influxql: handle null-cases in timeseries data (#37047) --- public/app/plugins/datasource/influxdb/datasource.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index ac0c1720894..376e62ecbf8 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -34,13 +34,16 @@ import { catchError, map } from 'rxjs/operators'; // we detect the field type based on the value-array function getFieldType(values: unknown[]): FieldType { - if (values.length === 0) { - // if we get called with an empty value-array, - // we will assume the values are numbers + // the values-array may contain a lot of nulls. + // we need the first not-null item + const firstNotNull = values.find((v) => v !== null); + + if (firstNotNull === undefined) { + // we could not find any not-null values return FieldType.number; } - const valueType = typeof values[0]; + const valueType = typeof firstNotNull; switch (valueType) { case 'string':