Re: [PR] Fix sidx tag filter range check issue [skywalking-banyandb]

2026-03-06 Thread via GitHub


wu-sheng merged PR #991:
URL: https://github.com/apache/skywalking-banyandb/pull/991


-- 
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]



Re: [PR] Fix sidx tag filter range check issue [skywalking-banyandb]

2026-03-05 Thread via GitHub


codecov-commenter commented on PR #991:
URL: 
https://github.com/apache/skywalking-banyandb/pull/991#issuecomment-4009017148

   ## 
[Codecov](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/991?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 37.92%. Comparing base 
([`3530dd9`](https://app.codecov.io/gh/apache/skywalking-banyandb/commit/3530dd9b5cefaa4fef60eec91ecbfbdfcaf243c5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`d7a823f`](https://app.codecov.io/gh/apache/skywalking-banyandb/commit/d7a823f3c6fc2e3589e9aa42efe6e8e4d528f659?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 144 commits behind head on main.
   > :exclamation:  There is a different number of reports uploaded between 
BASE (3530dd9) and HEAD (d7a823f). Click for more details.
   > 
   > HEAD has 1 upload less than BASE
   >
   >| Flag | BASE (3530dd9) | HEAD (d7a823f) |
   >|--|--|--|
   >||1|0|
   >
   
   Additional details and impacted files
   
   
   
   ```diff
   @@Coverage Diff @@
   ## main #991  +/-   ##
   ==
   - Coverage   45.97%   37.92%   -8.06% 
   ==
 Files 328  139 -189 
 Lines   5550515817   -39688 
   ==
   - Hits25520 5998   -19522 
   + Misses  27909 9331   -18578 
   + Partials 2076  488-1588 
   ```
   
   | 
[Flag](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/991/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[fodc](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/991/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | `72.02% <ø> (?)` | |
   | 
[pkg](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/991/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | `30.03% <ø> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click 
here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment)
 to find out more.
   
   
   [:umbrella: View full report in Codecov by 
Sentry](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/991?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   :loudspeaker: Have feedback on the report? [Share it 
here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:rocket: New features to boost your workflow: 
   
   - :snowflake: [Test 
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, 
report on failures, and find test suite problems.
   - :package: [JS Bundle 
Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save 
yourself from yourself by tracking and limiting bundle sizes in JS merges.
   


-- 
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]



Re: [PR] Fix sidx tag filter range check issue [skywalking-banyandb]

2026-03-05 Thread via GitHub


Copilot commented on code in PR #991:
URL: 
https://github.com/apache/skywalking-banyandb/pull/991#discussion_r2893328218


##
banyand/cmd/dump/sidx.go:
##
@@ -1077,3 +1089,81 @@ func outputScanResultsAsCSV(results 
[]*sidx.QueryResponse, seriesMap map[common.
 
return nil
 }
+
+func discoverProjectionTagTypes(sidxPath string, projectionTagNames []string) 
(map[string]pbv1.ValueType, error) {
+   if len(projectionTagNames) == 0 {
+   return nil, nil
+   }
+   partEntries, err := os.ReadDir(sidxPath)
+   if err != nil {
+   return nil, fmt.Errorf("failed to read sidx path %s: %w", 
sidxPath, err)
+   }
+   partPaths := make([]string, 0, len(partEntries))
+   for _, entry := range partEntries {
+   if !entry.IsDir() {
+   continue
+   }
+   partPaths = append(partPaths, filepath.Join(sidxPath, 
entry.Name()))
+   }
+   sort.Strings(partPaths)
+
+   result := make(map[string]pbv1.ValueType, len(projectionTagNames))
+   for _, tagName := range projectionTagNames {
+   for _, partPath := range partPaths {
+   tmPath := filepath.Join(partPath, tagName+".tm")
+   data, readErr := os.ReadFile(tmPath)
+   if readErr != nil {
+   continue
+   }
+   valueType, parseErr := parseSidxTagValueType(data)
+   if parseErr != nil {
+   fmt.Fprintf(os.Stderr, "Warning: failed to 
parse %s: %v\n", tmPath, parseErr)
+   break
+   }
+   result[tagName] = valueType
+   break
+   }
+   }
+   return result, nil
+}
+
+func parseSidxTagValueType(data []byte) (pbv1.ValueType, error) {
+   src, _, err := encoding.DecodeBytes(data)
+   if err != nil {
+   return pbv1.ValueTypeUnknown, fmt.Errorf("cannot decode tag 
name: %w", err)
+   }
+   if len(src) < 1 {
+   return pbv1.ValueTypeUnknown, fmt.Errorf("invalid tag metadata: 
missing value type")
+   }
+   return pbv1.ValueType(src[0]), nil
+}
+
+func decodeProjectedTagValue(raw string, valueType pbv1.ValueType) string {
+   if raw == "" {
+   return raw
+   }
+   rawBytes := []byte(raw)
+
+   switch valueType {
+   case pbv1.ValueTypeInt64:
+   if len(rawBytes) < 8 {
+   return raw
+   }
+   return strconv.FormatInt(convert.BytesToInt64(rawBytes), 10)
+   case pbv1.ValueTypeFloat64:
+   if len(rawBytes) < 8 {
+   return raw
+   }
+   return strconv.FormatFloat(convert.BytesToFloat64(rawBytes), 
'f', -1, 64)
+   case pbv1.ValueTypeTimestamp:
+   if len(rawBytes) < 8 {

Review Comment:
   `decodeProjectedTagValue` checks `len(rawBytes) < 8` before decoding int64. 
If the projected value is unexpectedly longer than 8 bytes, 
`convert.BytesToInt64` will decode only the first 8 bytes and silently produce 
a wrong value. Safer is to require an exact length (e.g., `len(rawBytes) == 8`) 
for numeric/timestamp types and fall back to returning `raw` otherwise.
   ```suggestion
if len(rawBytes) != 8 {
return raw
}
return strconv.FormatInt(convert.BytesToInt64(rawBytes), 10)
case pbv1.ValueTypeFloat64:
if len(rawBytes) != 8 {
return raw
}
return strconv.FormatFloat(convert.BytesToFloat64(rawBytes), 
'f', -1, 64)
case pbv1.ValueTypeTimestamp:
if len(rawBytes) != 8 {
   ```



##
banyand/internal/sidx/block_scanner.go:
##
@@ -96,10 +119,35 @@ func (bsn *blockScanner) scan(ctx context.Context, blockCh 
chan *blockScanResult
return
}
 
+   var (
+   totalBlockBytes uint64
+   scannedBlocks   int
+   )
+
+   if tracer := query.GetTracer(ctx); tracer != nil {
+   span, spanCtx := tracer.StartSpan(ctx, "sidx.scan-blocks")
+   bsn.span = span
+   ctx = spanCtx
+   span.Tagf("part_count", "%d", len(bsn.parts))
+   span.Tagf("series_id_count", "%d", len(bsn.seriesIDs))
+   span.Tagf("min_key", "%d", bsn.minKey)
+   span.Tagf("max_key", "%d", bsn.maxKey)
+   span.Tagf("ascending", "%t", bsn.asc)
+   span.Tagf("batch_size", "%d", bsn.batchSize)
+   defer func() {
+   if span != nil {
+   span.Tagf("scanned_blocks", "%d", scannedBlocks)
+   span.Tagf("total_block_bytes", "%d", 
totalBlockBytes)
+