mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
adds filter support to MinRow and MaxRow
This commit is contained in:
parent
3e738e9760
commit
b64a3e0c68
2 changed files with 62 additions and 10 deletions
32
executor.go
32
executor.go
|
|
@ -762,6 +762,15 @@ func (e *executor) executeMaxShard(ctx context.Context, index string, c *pql.Cal
|
|||
|
||||
// executeMinRowShard returns the minimum row ID for a shard.
|
||||
func (e *executor) executeMinRowShard(ctx context.Context, index string, c *pql.Call, shard uint64) (Pair, error) {
|
||||
var filter *Row
|
||||
if len(c.Children) == 1 {
|
||||
row, err := e.executeBitmapCallShard(ctx, index, c.Children[0], shard)
|
||||
if err != nil {
|
||||
return Pair{}, err
|
||||
}
|
||||
filter = row
|
||||
}
|
||||
|
||||
fieldName, _ := c.Args["field"].(string)
|
||||
field := e.Holder.Field(index, fieldName)
|
||||
if field == nil {
|
||||
|
|
@ -773,18 +782,24 @@ func (e *executor) executeMinRowShard(ctx context.Context, index string, c *pql.
|
|||
return Pair{}, nil
|
||||
}
|
||||
|
||||
count := uint64(1)
|
||||
if !fragment.hasRowID {
|
||||
count = 0
|
||||
}
|
||||
minRowID, count := fragment.minRow(filter)
|
||||
return Pair{
|
||||
ID: fragment.minRowID,
|
||||
ID: minRowID,
|
||||
Count: count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// executeMaxRowShard returns the minimum row ID for a shard.
|
||||
func (e *executor) executeMaxRowShard(ctx context.Context, index string, c *pql.Call, shard uint64) (Pair, error) {
|
||||
var filter *Row
|
||||
if len(c.Children) == 1 {
|
||||
row, err := e.executeBitmapCallShard(ctx, index, c.Children[0], shard)
|
||||
if err != nil {
|
||||
return Pair{}, err
|
||||
}
|
||||
filter = row
|
||||
}
|
||||
|
||||
fieldName, _ := c.Args["field"].(string)
|
||||
field := e.Holder.Field(index, fieldName)
|
||||
if field == nil {
|
||||
|
|
@ -796,12 +811,9 @@ func (e *executor) executeMaxRowShard(ctx context.Context, index string, c *pql.
|
|||
return Pair{}, nil
|
||||
}
|
||||
|
||||
count := uint64(1)
|
||||
if !fragment.hasRowID {
|
||||
count = 0
|
||||
}
|
||||
maxRowID, count := fragment.maxRow(filter)
|
||||
return Pair{
|
||||
ID: fragment.maxRowID,
|
||||
ID: maxRowID,
|
||||
Count: count,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
40
fragment.go
40
fragment.go
|
|
@ -1036,6 +1036,46 @@ func (f *fragment) maxUnsigned(filter *Row, bitDepth uint) (max int64, count uin
|
|||
return max, count
|
||||
}
|
||||
|
||||
// minRow returns minRowID of the rows in the filter and its count.
|
||||
// if filter is nil, it returns fragment.minRowID, 1
|
||||
// if fragment has no rows, it returns 0, 0
|
||||
func (f *fragment) minRow(filter *Row) (uint64, uint64) {
|
||||
if f.hasRowID {
|
||||
if filter == nil {
|
||||
return f.minRowID, 1
|
||||
}
|
||||
// iterate from min row ID and return the first that intersects with filter.
|
||||
for i := f.minRowID; i <= f.maxRowID; i++ {
|
||||
row := f.row(i).Intersect(filter)
|
||||
count := row.Count()
|
||||
if count > 0 {
|
||||
return i, count
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
// maxRow returns maxRowID of the rows in the filter and its count.
|
||||
// if filter is nil, it returns fragment.maxRowID, 1
|
||||
// if fragment has no rows, it returns 0, 0
|
||||
func (f *fragment) maxRow(filter *Row) (uint64, uint64) {
|
||||
if f.hasRowID {
|
||||
if filter == nil {
|
||||
return f.maxRowID, 1
|
||||
}
|
||||
// iterate back from max row ID and return the first that intersects with filter.
|
||||
for i := f.maxRowID; i >= f.minRowID; i-- {
|
||||
row := f.row(i).Intersect(filter)
|
||||
count := row.Count()
|
||||
if count > 0 {
|
||||
return i, count
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
// rangeOp returns bitmaps with a bsiGroup value encoding matching the predicate.
|
||||
func (f *fragment) rangeOp(op pql.Token, bitDepth uint, predicate int64) (*Row, error) {
|
||||
switch op {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue