From 69a65436098860d8dbee284223a106c3585bc007 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 13 May 2024 22:12:18 +0200 Subject: [PATCH] wip --- docs/VictoriaLogs/CHANGELOG.md | 1 + lib/logstorage/block_result.go | 15 +++++++-------- lib/logstorage/parser_test.go | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index f3c0b8745..468bf09a7 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -22,6 +22,7 @@ according to [these docs](https://docs.victoriametrics.com/VictoriaLogs/QuickSta * FEATURE: use [natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order) when sorting logs via [`sort` pipe](https://docs.victoriametrics.com/victorialogs/logsql/#sort-pipe). * BUGFIX: properly return matching logs in [streams](https://docs.victoriametrics.com/victorialogs/keyconcepts/#stream-fields) with small number of entries. Previously they could be skipped. The issue has been introduced in [the release v0.6.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.6.0-victorialogs). +* BUGFIX: fix `runtime error: index out of range` panic when using [`sort` pipe](https://docs.victoriametrics.com/victorialogs/logsql/#sort-pipe) like `_time:1h | sort by (_time)`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6258). ## [v0.6.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.6.0-victorialogs) diff --git a/lib/logstorage/block_result.go b/lib/logstorage/block_result.go index 980b3136e..b5ac62dfb 100644 --- a/lib/logstorage/block_result.go +++ b/lib/logstorage/block_result.go @@ -109,7 +109,7 @@ func (br *blockResult) cloneValues(values []string) []string { for _, v := range values { if len(valuesBuf) > 0 && v == valuesBuf[len(valuesBuf)-1] { - valuesBuf = append(valuesBuf, v) + valuesBuf = append(valuesBuf, valuesBuf[len(valuesBuf)-1]) } else { bufLen := len(buf) buf = append(buf, v...) @@ -287,7 +287,7 @@ func (br *blockResult) addColumn(bs *blockSearch, ch *columnHeader, bm *bitmap) appendValue := func(v string) { if len(valuesBuf) > 0 && v == valuesBuf[len(valuesBuf)-1] { - valuesBuf = append(valuesBuf, v) + valuesBuf = append(valuesBuf, valuesBuf[len(valuesBuf)-1]) } else { bufLen := len(buf) buf = append(buf, v...) @@ -1853,13 +1853,12 @@ func (rc *resultColumn) resetKeepName() { func (rc *resultColumn) addValue(v string) { values := rc.values if len(values) > 0 && string(v) == values[len(values)-1] { - rc.values = append(rc.values, values[len(values)-1]) - return + rc.values = append(values, values[len(values)-1]) + } else { + bufLen := len(rc.buf) + rc.buf = append(rc.buf, v...) + rc.values = append(values, bytesutil.ToUnsafeString(rc.buf[bufLen:])) } - - bufLen := len(rc.buf) - rc.buf = append(rc.buf, v...) - rc.values = append(values, bytesutil.ToUnsafeString(rc.buf[bufLen:])) } func truncateTimestampToMonth(timestamp int64) int64 { diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index 97a06ee1d..ee9498a0b 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -1395,6 +1395,7 @@ func TestQueryGetNeededColumns(t *testing.T) { f(`* | sort by (f1)`, `*`, ``) f(`* | sort by (f1) | fields f2`, `f1,f2`, ``) + f(`_time:5m | sort by (_time) | fields foo`, `_time,foo`, ``) f(`* | sort by (f1) | fields *`, `*`, ``) f(`* | sort by (f1) | sort by (f2,f3 desc) desc`, `*`, ``) f(`* | sort by (f1) | sort by (f2,f3 desc) desc | fields f4`, `f1,f2,f3,f4`, ``)