From 1ce8a9a751a9fd541d71b09ebb5b5044becf1b7d Mon Sep 17 00:00:00 2001
From: Aliaksandr Valialkin <valyala@victoriametrics.com>
Date: Tue, 4 Jun 2024 02:29:10 +0200
Subject: [PATCH] lib/logstorage: allow typing `asc` in `sort` pipe for the
 sake of consistency with `desc`

---
 lib/logstorage/pipe_sort.go      | 10 ++++++++--
 lib/logstorage/pipe_sort_test.go |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/logstorage/pipe_sort.go b/lib/logstorage/pipe_sort.go
index 1bcee3670f..a1c9b00441 100644
--- a/lib/logstorage/pipe_sort.go
+++ b/lib/logstorage/pipe_sort.go
@@ -725,9 +725,12 @@ func parsePipeSort(lex *lexer) (*pipeSort, error) {
 		ps.byFields = bfs
 	}
 
-	if lex.isKeyword("desc") {
+	switch {
+	case lex.isKeyword("desc"):
 		lex.nextToken()
 		ps.isDesc = true
+	case lex.isKeyword("asc"):
+		lex.nextToken()
 	}
 
 	for {
@@ -797,9 +800,12 @@ func parseBySortFields(lex *lexer) ([]*bySortField, error) {
 		bf := &bySortField{
 			name: fieldName,
 		}
-		if lex.isKeyword("desc") {
+		switch {
+		case lex.isKeyword("desc"):
 			lex.nextToken()
 			bf.isDesc = true
+		case lex.isKeyword("asc"):
+			lex.nextToken()
 		}
 		bfs = append(bfs, bf)
 		switch {
diff --git a/lib/logstorage/pipe_sort_test.go b/lib/logstorage/pipe_sort_test.go
index 10b6564fbd..f14a0d2aa4 100644
--- a/lib/logstorage/pipe_sort_test.go
+++ b/lib/logstorage/pipe_sort_test.go
@@ -60,7 +60,7 @@ func TestPipeSort(t *testing.T) {
 	})
 
 	// Sort by a single field
-	f("sort by (a)", [][]Field{
+	f("sort by (a asc) asc", [][]Field{
 		{
 			{"_msg", `abc`},
 			{"a", `2`},