Skip to content

Commit

Permalink
Fix NPE on sorting by index with an empty result (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanahmily authored Feb 6, 2025
1 parent 24c06b8 commit f484391
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 13 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/dead-link-checker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
- run: |
for file in $(find . -name "*.md"); do
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion .github/workflows/e2e.storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion banyand/measure/topn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion banyand/stream/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions pkg/query/logical/measure/topn_plan_localscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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],
}
Expand Down
35 changes: 35 additions & 0 deletions test/cases/stream/data/input/sort_empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: "sw"
groups: ["default"]
projection:
tagFamilies:
- name: "searchable"
tags: ["service_instance_id", "duration"]
- name: "data"
tags: ["data_binary"]
criteria:
condition:
name: "service_instance_id"
op: "BINARY_OP_EQ"
value:
str:
value: "foo"
orderBy:
indexRuleName: "duration"
sort: "SORT_DESC"
1 change: 1 addition & 0 deletions test/cases/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
Expand Down

0 comments on commit f484391

Please sign in to comment.