From 2d900ed2b7c7edb632c174c13ed52687aaae6dc3 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:43:12 +0100 Subject: [PATCH] Export errors for time series processing (#1134) * Export errors for time series processing * Add more * Update data/time_series_errors.go * Fix lint * Keep errors in same format * Update * Fix lint --- data/time_series.go | 6 +++--- data/time_series_errors.go | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 data/time_series_errors.go diff --git a/data/time_series.go b/data/time_series.go index 5cfb2857c..0156b3f79 100644 --- a/data/time_series.go +++ b/data/time_series.go @@ -308,7 +308,7 @@ func (p *longRowProcessor) process(longRowIdx int) error { } if currentTime.Before(p.lastTime) { - return fmt.Errorf("long series must be sorted ascending by time to be converted") + return ErrorSeriesUnsorted } sliceKey := make(tupleLabels, len(p.tsSchema.FactorIndices)) // factor columns idx:value tuples (used for lookup) @@ -386,7 +386,7 @@ func (p *longRowProcessor) process(longRowIdx int) error { func timeAt(idx int, longFrame *Frame, tsSchema TimeSeriesSchema) (time.Time, error) { // get time.Time regardless if pointer val, ok := longFrame.ConcreteAt(tsSchema.TimeIndex, idx) if !ok { - return time.Time{}, fmt.Errorf("can not convert to wide series, input has null time values") + return time.Time{}, ErrorNullTimeValues } return val.(time.Time), nil } @@ -420,7 +420,7 @@ func WideToLong(wideFrame *Frame) (*Frame, error) { if err != nil { return nil, err } else if wideLen == 0 { - return nil, fmt.Errorf("can not convert to long series, input fields have no rows") + return nil, ErrorInputFieldsWithoutRows } var uniqueValueNames []string // unique names of Fields that are value types diff --git a/data/time_series_errors.go b/data/time_series_errors.go new file mode 100644 index 000000000..e223ea93a --- /dev/null +++ b/data/time_series_errors.go @@ -0,0 +1,9 @@ +package data + +import "errors" + +var ( + ErrorNullTimeValues = errors.New("unable to process the data to wide series because input has null time values, make sure all time values are not null") + ErrorSeriesUnsorted = errors.New("unable to process the data because it is not sorted in ascending order by time, please updated your query to sort the data by time if possible") + ErrorInputFieldsWithoutRows = errors.New("can not convert to long series, input fields have no rows") +)