mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 11:57:51 +00:00
Merge pull request #449 from jaddr2line/fixbsioffbyone
Fix BSI comparison match-all-but-one operation
This commit is contained in:
commit
ec9474114a
2 changed files with 42 additions and 8 deletions
16
fragment.go
16
fragment.go
|
|
@ -1270,12 +1270,12 @@ func (f *fragment) rangeLTUnsigned(filter *Row, bitDepth uint, predicate uint64,
|
|||
return filter, nil
|
||||
case predicate == (1<<bitDepth)-1 && !allowEquality:
|
||||
// This query matches everything that is not (1<<bitDepth)-1.
|
||||
remaining := filter
|
||||
for i := uint(0); i < bitDepth && remaining.Any(); i++ {
|
||||
matches := NewRow()
|
||||
for i := uint(0); i < bitDepth; i++ {
|
||||
row := f.row(uint64(bsiOffsetBit + i))
|
||||
remaining = remaining.Intersect(row)
|
||||
matches = matches.Union(filter.Difference(row))
|
||||
}
|
||||
return remaining, nil
|
||||
return matches, nil
|
||||
case allowEquality:
|
||||
predicate++
|
||||
}
|
||||
|
|
@ -1345,12 +1345,12 @@ func (f *fragment) rangeGTUnsigned(filter *Row, bitDepth uint, predicate uint64,
|
|||
return filter, nil
|
||||
case predicate == 0 && !allowEquality:
|
||||
// This query matches everything that is not 0.
|
||||
remaining := filter
|
||||
for i := uint(0); i < bitDepth && remaining.Any(); i++ {
|
||||
matches := NewRow()
|
||||
for i := uint(0); i < bitDepth; i++ {
|
||||
row := f.row(uint64(bsiOffsetBit + i))
|
||||
remaining = remaining.Difference(row)
|
||||
matches = matches.Union(filter.Intersect(row))
|
||||
}
|
||||
return remaining, nil
|
||||
return matches, nil
|
||||
case allowEquality:
|
||||
predicate--
|
||||
}
|
||||
|
|
|
|||
|
|
@ -624,6 +624,23 @@ func TestFragment_Range(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("LTMaxRegression", func(t *testing.T) {
|
||||
f := mustOpenFragment("i", "f", viewStandard, 0, "")
|
||||
defer f.Clean(t)
|
||||
|
||||
if _, err := f.setValue(1, 2, 3); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if _, err := f.setValue(2, 2, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if b, err := f.rangeLTUnsigned(NewRow(1, 2), 2, 3, false); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(b.Columns(), []uint64{2}) {
|
||||
t.Fatalf("unepxected coulmns: %+v", b.Columns())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("GT", func(t *testing.T) {
|
||||
f := mustOpenFragment("i", "f", viewStandard, 0, "")
|
||||
defer f.Clean(t)
|
||||
|
|
@ -672,6 +689,23 @@ func TestFragment_Range(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("GTMinRegression", func(t *testing.T) {
|
||||
f := mustOpenFragment("i", "f", viewStandard, 0, "")
|
||||
defer f.Clean(t)
|
||||
|
||||
if _, err := f.setValue(1, 2, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if _, err := f.setValue(2, 2, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if b, err := f.rangeGTUnsigned(NewRow(1, 2), 2, 0, false); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(b.Columns(), []uint64{2}) {
|
||||
t.Fatalf("unepxected coulmns: %+v", b.Columns())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("BETWEEN", func(t *testing.T) {
|
||||
f := mustOpenFragment("i", "f", viewStandard, 0, "")
|
||||
defer f.Clean(t)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue