Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex tweak #2484

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions pkg/parquetquery/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,30 @@ func (p *regexPredicate) keep(v *pq.Value) bool {
return false
}

s := v.String()
if matched, ok := p.matches[s]; ok {
b := v.ByteArray()

// Check uses zero alloc optimization of map[string([]byte)]
if matched, ok := p.matches[string(b)]; ok {
return matched
}

matched := false
for _, r := range p.regs {
if r.MatchString(s) == p.shouldMatch {
if r.Match(b) == p.shouldMatch {
matched = true
break
}
}

p.matches[s] = matched
// Only alloc the string when updating the map
p.matches[string(b)] = matched

return matched
}

func (p *regexPredicate) KeepColumnChunk(cc pq.ColumnChunk) bool {
p.helper.setNewRowGroup()

// Reset match cache on each row group change
p.matches = make(map[string]bool, len(p.matches))

// Can we do any filtering here?
return true
}
Expand All @@ -165,6 +166,20 @@ func (p *regexPredicate) KeepValue(v pq.Value) bool {
}

func (p *regexPredicate) KeepPage(page pq.Page) bool {
if p.helper.newRowGroup {
// Reset match cache on each row group change
// We delay until the first page is received
// so we can get an accurate count of the number
// of distinct values for dictionary columns.
count := len(p.matches)
if d := page.Dictionary(); d != nil {
if d.Len() > count {
count = d.Len()
}
}
p.matches = make(map[string]bool, count)
}

return p.helper.keepPage(page, p.KeepValue)
}

Expand Down
6 changes: 4 additions & 2 deletions tempodb/encoding/vparquet2/block_traceql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ func BenchmarkBackendBlockTraceQL(b *testing.B) {
{"spanAttValMatch", traceql.MustExtractFetchSpansRequest("{ span.bloom > 0 }")},
{"spanAttIntrinsicNoMatch", traceql.MustExtractFetchSpansRequest("{ name = `asdfasdf` }")},
{"spanAttIntrinsicMatch", traceql.MustExtractFetchSpansRequest("{ name = `gcs.ReadRange` }")},
{"spanAttIntrinsicRegexNoMatch", traceql.MustExtractFetchSpansRequest("{ name =~ `asdfasdf` }")},
{"spanAttIntrinsicRegexMatch", traceql.MustExtractFetchSpansRequest("{ name =~ `gcs.ReadRange` }")},

// resource
{"resourceAttNameNoMatch", traceql.MustExtractFetchSpansRequest("{ resource.foo = `bar` }")},
Expand All @@ -474,10 +476,10 @@ func BenchmarkBackendBlockTraceQL(b *testing.B) {

ctx := context.TODO()
tenantID := "1"
blockID := uuid.MustParse("149e41d2-cc4d-4f71-b355-3377eabc94c8")
blockID := uuid.MustParse("2968a567-5873-4e4c-b3cb-21c106c6714b")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

booooooooooooooo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

149e41d2-cc4d-4f71-b355-3377eabc94c8 is joe's fav uuid 😆


r, _, _, err := local.New(&local.Config{
Path: path.Join("/home/joe/testblock/"),
Path: path.Join("/Users/marty/src/tmp/"),
})
require.NoError(b, err)

Expand Down