You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2025/02/06 04:27:04 UTC

(skywalking-banyandb) 01/01: Fix NPE on sorting by index with an empty result

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch patch-stream
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 09b20928d6758c64d6b34ae30ccfebe6d15ae039
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Thu Feb 6 04:24:21 2025 +0000

    Fix NPE on sorting by index with an empty result
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 .github/workflows/ci.yml                         |  8 ++++++--
 .github/workflows/dead-link-checker.yaml         |  4 +++-
 .github/workflows/dependency-review.yml          |  4 +++-
 .github/workflows/e2e.storage.yml                |  4 +++-
 .github/workflows/publish-docker.yml             |  4 +++-
 .github/workflows/test.yml                       |  4 +++-
 banyand/measure/topn_test.go                     |  4 +++-
 banyand/stream/query.go                          |  3 ++-
 pkg/query/logical/measure/topn_plan_localscan.go | 11 +++++++----
 test/cases/stream/stream.go                      |  1 +
 10 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 213a83e0..ecd0269a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -31,7 +31,9 @@ jobs:
     runs-on: ubuntu-20.04
     steps:
       - name: Check out code into the Go module directory
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
+        with:
+          fetch-tags: true
       - name: Cache Go Modules
         uses: actions/cache@v3
         id: cache-go
@@ -94,7 +96,9 @@ jobs:
     runs-on: ubuntu-20.04
     steps:
       - name: Check out code into the Go module directory
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
+        with:
+          fetch-tags: true
       - name: Cache Go Modules
         uses: actions/cache@v3
         id: cache-go
diff --git a/.github/workflows/dead-link-checker.yaml b/.github/workflows/dead-link-checker.yaml
index 8103bc34..fac227b9 100644
--- a/.github/workflows/dead-link-checker.yaml
+++ b/.github/workflows/dead-link-checker.yaml
@@ -33,7 +33,9 @@ jobs:
     runs-on: ubuntu-latest
     timeout-minutes: 30
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
+        with:
+          fetch-tags: true
       - run: sudo npm install -g markdown-link-check@3.10.0
       - run: |
           for file in $(find . -name "*.md"); do
diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml
index 09f5be9c..8bfbb0e5 100644
--- a/.github/workflows/dependency-review.yml
+++ b/.github/workflows/dependency-review.yml
@@ -29,6 +29,8 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: 'Checkout Repository'
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
+        with:
+          fetch-tags: true
       - name: 'Dependency Review'
         uses: actions/dependency-review-action@v2
diff --git a/.github/workflows/e2e.storage.yml b/.github/workflows/e2e.storage.yml
index b815ffac..e09eba27 100644
--- a/.github/workflows/e2e.storage.yml
+++ b/.github/workflows/e2e.storage.yml
@@ -51,7 +51,9 @@ jobs:
       TAG: ${{ github.sha }}
     steps:
       - name: Check out code into the Go module directory
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
+        with:
+          fetch-tags: true
       - name: Cache Go Modules
         uses: actions/cache@v3
         id: cache-go
diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml
index c823da3f..89d9fd25 100644
--- a/.github/workflows/publish-docker.yml
+++ b/.github/workflows/publish-docker.yml
@@ -40,7 +40,9 @@ jobs:
       TAG: ${{ github.sha }}
     steps:
       - name: Check out code into the Go module directory
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
+        with:
+          fetch-tags: true
       - name: Cache Go Modules
         uses: actions/cache@v3
         id: cache-go
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 1ce4f12f..da507ba2 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -39,7 +39,9 @@ jobs:
       - name: Set timezone
         run: sudo timedatectl set-timezone ${{ matrix.tz }}
       - name: Check out code into the Go module directory
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
+        with:
+          fetch-tags: true
       - name: Cache Go Modules
         uses: actions/cache@v3
         id: cache-go
diff --git a/banyand/measure/topn_test.go b/banyand/measure/topn_test.go
index b416ec6b..e449ffe3 100644
--- a/banyand/measure/topn_test.go
+++ b/banyand/measure/topn_test.go
@@ -69,6 +69,8 @@ func TestTopNValue_MarshalUnmarshal(t *testing.T) {
 	}
 	decoder := generateColumnValuesDecoder()
 	defer releaseColumnValuesDecoder(decoder)
+	decodedTopNValue := GenerateTopNValue()
+	defer ReleaseTopNValue(decodedTopNValue)
 
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -77,7 +79,7 @@ func TestTopNValue_MarshalUnmarshal(t *testing.T) {
 			require.NoError(t, err)
 
 			// Unmarshal the topNValue
-			var decodedTopNValue TopNValue
+			decodedTopNValue.Reset()
 			err = decodedTopNValue.Unmarshal(dst, decoder)
 			require.NoError(t, err)
 
diff --git a/banyand/stream/query.go b/banyand/stream/query.go
index 4ed25ab4..049ac17e 100644
--- a/banyand/stream/query.go
+++ b/banyand/stream/query.go
@@ -124,7 +124,8 @@ func (s *stream) Query(ctx context.Context, sqo model.StreamQueryOptions) (sqr m
 	}
 
 	if seriesFilter.IsEmpty() {
-		return &result, nil
+		result.Release()
+		return nil, nil
 	}
 	sids := seriesFilter.ToSlice()
 	if result.qo.elementFilter, err = indexSearch(ctx, sqo, result.tabs, sids); err != nil {
diff --git a/pkg/query/logical/measure/topn_plan_localscan.go b/pkg/query/logical/measure/topn_plan_localscan.go
index 6eb19855..e0e4f645 100644
--- a/pkg/query/logical/measure/topn_plan_localscan.go
+++ b/pkg/query/logical/measure/topn_plan_localscan.go
@@ -24,6 +24,7 @@ import (
 	"time"
 
 	"github.com/pkg/errors"
+	"go.uber.org/multierr"
 	"google.golang.org/protobuf/types/known/timestamppb"
 
 	measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
@@ -200,15 +201,17 @@ func (ei *topNMIterator) Next() bool {
 			ei.err = errors.New("failed to get binary data")
 			return false
 		}
+		ts := timestamppb.New(time.Unix(0, r.Timestamps[i]))
 		ei.topNValue.Reset()
-		ei.err = ei.topNValue.Unmarshal(bd, ei.decoder)
-		if ei.err != nil {
-			return false
+		err := ei.topNValue.Unmarshal(bd, ei.decoder)
+		if err != nil {
+			ei.err = multierr.Append(ei.err, errors.WithMessagef(err, "failed to unmarshal topN values[%d]:[%s]%s", i, ts, fv))
+			continue
 		}
 		fieldName, entityNames, values, entities := ei.topNValue.Values()
 		for j := range entities {
 			dp := &measurev1.DataPoint{
-				Timestamp: timestamppb.New(time.Unix(0, r.Timestamps[i])),
+				Timestamp: ts,
 				Sid:       uint64(r.SID),
 				Version:   r.Versions[i],
 			}
diff --git a/test/cases/stream/stream.go b/test/cases/stream/stream.go
index 4d5509c5..fcb29051 100644
--- a/test/cases/stream/stream.go
+++ b/test/cases/stream/stream.go
@@ -65,6 +65,7 @@ var _ = g.DescribeTable("Scanning Streams", func(args helpers.Args) {
 	}),
 	g.Entry("sort desc", helpers.Args{Input: "sort_desc", Duration: 1 * time.Hour}),
 	g.Entry("sort with filter", helpers.Args{Input: "sort_filter", Duration: 1 * time.Hour}),
+	g.Entry("sort with empty result", helpers.Args{Input: "sort_empty", Duration: 1 * time.Hour, WantEmpty: true}),
 	g.Entry("global index", helpers.Args{Input: "global_index", Duration: 1 * time.Hour}),
 	g.Entry("multi-global index", helpers.Args{Input: "global_indices", Duration: 1 * time.Hour}),
 	g.Entry("filter by non-indexed tag", helpers.Args{Input: "filter_tag", Duration: 1 * time.Hour}),