SLIMIT/SOFFSET
parent
cde973f409
commit
036382ee20
|
@ -1657,22 +1657,22 @@ func (s *SelectStatement) NamesInDimension() []string {
|
|||
}
|
||||
|
||||
// LimitTagSets returns a tag set list with SLIMIT and SOFFSET applied.
|
||||
func (s *SelectStatement) LimitTagSets(a []*TagSet) []*TagSet {
|
||||
func LimitTagSets(a []*TagSet, slimit, soffset int) []*TagSet {
|
||||
// Ignore if no limit or offset is specified.
|
||||
if s.SLimit == 0 && s.SOffset == 0 {
|
||||
if slimit == 0 && soffset == 0 {
|
||||
return a
|
||||
}
|
||||
|
||||
// If offset is beyond the number of tag sets then return nil.
|
||||
if s.SOffset > len(a) {
|
||||
if soffset > len(a) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Clamp limit to the max number of tag sets.
|
||||
if s.SOffset+s.SLimit > len(a) {
|
||||
s.SLimit = len(a) - s.SOffset
|
||||
if soffset+slimit > len(a) {
|
||||
slimit = len(a) - soffset
|
||||
}
|
||||
return a[s.SOffset : s.SOffset+s.SLimit]
|
||||
return a[soffset : soffset+slimit]
|
||||
}
|
||||
|
||||
// walkNames will walk the Expr and return the database fields
|
||||
|
|
|
@ -475,6 +475,12 @@ type IteratorOptions struct {
|
|||
|
||||
// Sorted in time ascending order if true.
|
||||
Ascending bool
|
||||
|
||||
// Limits the number of points per series.
|
||||
Limit, Offset int
|
||||
|
||||
// Limits the number of series.
|
||||
SLimit, SOffset int
|
||||
}
|
||||
|
||||
// newIteratorOptionsStmt creates the iterator options from stmt.
|
||||
|
@ -510,6 +516,9 @@ func newIteratorOptionsStmt(stmt *SelectStatement) (opt IteratorOptions, err err
|
|||
opt.Condition = stmt.Condition
|
||||
opt.Ascending = stmt.TimeAscending()
|
||||
|
||||
opt.Limit, opt.Offset = stmt.Limit, stmt.Offset
|
||||
opt.SLimit, opt.SOffset = stmt.SLimit, stmt.SOffset
|
||||
|
||||
return opt, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -170,8 +170,8 @@ func newTxVarRefIterator(tx Tx, sh *Shard, opt influxql.IteratorOptions, dimensi
|
|||
return err
|
||||
}
|
||||
|
||||
// FIXME(benbjohnson): Calculate tag sets and apply SLIMIT/SOFFSET.
|
||||
// tagSets = m.stmt.LimitTagSets(tagSets)
|
||||
// Calculate tag sets and apply SLIMIT/SOFFSET.
|
||||
tagSets = influxql.LimitTagSets(tagSets, opt.SLimit, opt.SOffset)
|
||||
|
||||
for _, t := range tagSets {
|
||||
for i, seriesKey := range t.SeriesKeys {
|
||||
|
|
Loading…
Reference in New Issue