From e4fba98c6b7f8ec229c9025891912212ff11cbbb Mon Sep 17 00:00:00 2001 From: davidby-influx <72418212+davidby-influx@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:57:39 -0700 Subject: [PATCH] fix: do not panic when empty tags are queried (#24784) (#24787) Do not panic if a cursor array is nil and the number of timestamps is retrieved. closes https://github.com/influxdata/influxdb/issues/24536 (cherry picked from commit bc80e881fa34aef4145007aa510ffe3e78d3e7ab) --- tsdb/cursors/arrayvalues.gen.go | 36 +++++++++++++++++++++++----- tsdb/cursors/arrayvalues.gen.go.tmpl | 6 ++++- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tsdb/cursors/arrayvalues.gen.go b/tsdb/cursors/arrayvalues.gen.go index 9eaffa8e40d..36a80792101 100644 --- a/tsdb/cursors/arrayvalues.gen.go +++ b/tsdb/cursors/arrayvalues.gen.go @@ -27,7 +27,11 @@ func (a *FloatArray) MaxTime() int64 { } func (a *FloatArray) Len() int { - return len(a.Timestamps) + if a != nil { + return len(a.Timestamps) + } else { + return 0 + } } // search performs a binary search for UnixNano() v in a @@ -224,7 +228,11 @@ func (a *IntegerArray) MaxTime() int64 { } func (a *IntegerArray) Len() int { - return len(a.Timestamps) + if a != nil { + return len(a.Timestamps) + } else { + return 0 + } } // search performs a binary search for UnixNano() v in a @@ -421,7 +429,11 @@ func (a *UnsignedArray) MaxTime() int64 { } func (a *UnsignedArray) Len() int { - return len(a.Timestamps) + if a != nil { + return len(a.Timestamps) + } else { + return 0 + } } // search performs a binary search for UnixNano() v in a @@ -618,7 +630,11 @@ func (a *StringArray) MaxTime() int64 { } func (a *StringArray) Len() int { - return len(a.Timestamps) + if a != nil { + return len(a.Timestamps) + } else { + return 0 + } } // search performs a binary search for UnixNano() v in a @@ -815,7 +831,11 @@ func (a *BooleanArray) MaxTime() int64 { } func (a *BooleanArray) Len() int { - return len(a.Timestamps) + if a != nil { + return len(a.Timestamps) + } else { + return 0 + } } // search performs a binary search for UnixNano() v in a @@ -1010,7 +1030,11 @@ func (a *TimestampArray) MaxTime() int64 { } func (a *TimestampArray) Len() int { - return len(a.Timestamps) + if a != nil { + return len(a.Timestamps) + } else { + return 0 + } } // search performs a binary search for UnixNano() v in a diff --git a/tsdb/cursors/arrayvalues.gen.go.tmpl b/tsdb/cursors/arrayvalues.gen.go.tmpl index 3e7632aeeb9..217cebd2cc7 100644 --- a/tsdb/cursors/arrayvalues.gen.go.tmpl +++ b/tsdb/cursors/arrayvalues.gen.go.tmpl @@ -29,7 +29,11 @@ func (a *{{ $typename }}) MaxTime() int64 { } func (a *{{ $typename}}) Len() int { - return len(a.Timestamps) + if a != nil { + return len(a.Timestamps) + } else { + return 0 + } } // search performs a binary search for UnixNano() v in a