Copilot commented on code in PR #786:
URL:
https://github.com/apache/skywalking-banyandb/pull/786#discussion_r2374058732
##########
banyand/stream/tag_filter.go:
##########
@@ -203,6 +203,28 @@ func (tfs *tagFamilyFilters) Range(tagName string,
rangeOpts index.RangeOpts) (b
return true, nil
}
+// Having checks if any of the provided tag values might exist in the bloom
filter.
+// It returns true if at least one value might be contained in any tag family
filter.
+func (tfs *tagFamilyFilters) Having(tagName string, tagValues []string) bool {
+ for _, tff := range tfs.tagFamilyFilters {
+ if tf, ok := (*tff)[tagName]; ok {
+ if tf.filter != nil {
+ for _, tagValue := range tagValues {
+ if
tf.filter.MightContain([]byte(tagValue)) {
+ return true // Return true as
soon as we find a potential match
+ }
+ }
+ // None of the values might exist in this tag
family filter
+ return false
+ }
+ // If no bloom filter, conservatively return true
+ return true
+ }
+ }
Review Comment:
The logic incorrectly returns `false` when no values match in the first tag
family filter, but doesn't check other tag family filters. The method should
continue checking remaining filters when no matches are found, not return
immediately.
```suggestion
foundTag := false
for _, tff := range tfs.tagFamilyFilters {
if tf, ok := (*tff)[tagName]; ok {
foundTag = true
if tf.filter != nil {
for _, tagValue := range tagValues {
if
tf.filter.MightContain([]byte(tagValue)) {
return true // Return true as
soon as we find a potential match
}
}
// None of the values might exist in this tag
family filter, continue checking others
continue
}
// If no bloom filter, conservatively return true
return true
}
}
// If tag was found in at least one tag family filter, but no values
matched, return false
if foundTag {
return false
}
```
##########
pkg/query/logical/trace/index_filter_test.go:
##########
@@ -0,0 +1,281 @@
+// 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.
+
+package trace
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/skywalking-banyandb/pkg/index"
+ "github.com/apache/skywalking-banyandb/pkg/query/logical"
+)
+
+type MockFilterOp struct {
+ eqResults map[string]map[string]bool
+ havingResults map[string]map[string]bool
+}
+
+func NewMockFilterOp() *MockFilterOp {
+ return &MockFilterOp{
+ eqResults: make(map[string]map[string]bool),
+ havingResults: make(map[string]map[string]bool),
+ }
+}
+
+func (m *MockFilterOp) Eq(tagName string, tagValue string) bool {
+ if tagResults, ok := m.eqResults[tagName]; ok {
+ if result, ok := tagResults[tagValue]; ok {
+ return result
+ }
+ }
+ return false
+}
+
+func (m *MockFilterOp) Range(_ string, _ index.RangeOpts) (bool, error) {
+ return false, nil
+}
+
+func (m *MockFilterOp) Having(tagName string, tagValues []string) bool {
+ if tagResults, ok := m.havingResults[tagName]; ok {
+ key := ""
+ for i, val := range tagValues {
+ if i > 0 {
+ key += ","
+ }
+ key += val
+ }
Review Comment:
The key generation logic using string concatenation is duplicated in both
`Having` and `SetHavingResult` methods. Extract this into a helper method like
`generateKey(tagValues []string) string` to eliminate code duplication.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]