// Querier returns a new querier over the data partition for the given time range.
// A goroutine must not handle more than one open Querier.
340522
func (db *DB) Querier(mint, maxt int64) (Querier, error) {
	var blocks []BlockReader
	var blockMetas []BlockMeta

	db.mtx.RLock()
	defer db.mtx.RUnlock()

	for _, b := range db.blocks {
		if b.OverlapsClosedInterval(mint, maxt) {
			blocks = append(blocks, b)
			blockMetas = append(blockMetas, b.Meta())
		}
	}
	if maxt >= db.head.MinTime() {
		blocks = append(blocks, &rangeHead{
			head: db.head,
			mint: mint,
			maxt: maxt,
		})
	}

	blockQueriers := make([]Querier, 0, len(blocks))
	for _, b := range blocks {
		q, err := NewBlockQuerier(b, mint, maxt)
		if err == nil {
			blockQueriers = append(blockQueriers, q)
			continue
		}
		// If we fail, all previously opened queriers must be closed.
		for _, q := range blockQueriers {
			q.Close()
		}
		return nil, errors.Wrapf(err, "open querier for block %s", b)
	}

	if len(OverlappingBlocks(blockMetas)) > 0 {
		return &verticalQuerier{
			querier: querier{
				blocks: blockQueriers,
			},
		}, nil
	}

	return &querier{
		blocks: blockQueriers,
	}, nil
}
198823
func (c *CrateDriver) Query(stmt string, args []driver.Value) (driver.Rows, error) {
	res, err := c.query(stmt, args)

	if err != nil {
		return nil, err
	}

	// Rows reader
	rows := &Rows{
		columns:  res.Cols,
		values:   res.Rows,
		rowcount: res.Rowcount,
	}

	return rows, nil
}
301870
func Iter(q *gocql.Query) *Iterx {
	return &Iterx{
		Iter:   q.Iter(),
		Mapper: DefaultMapper,
	}
}
447823
func (r *FastHttpRequest) GetQuery() url.Values {
	if !r.toQuery {
		// Attempt to convert to query
		r.query = url.Values{}
		r.Original.QueryArgs().VisitAll(func(key, value []byte) {
			r.query.Set(string(key), string(value))
		})
		r.toQuery = true
	}
	return r.query
}
794917
func AverageQueueLength() int {
	ql.Lock()
	var s int
	for _, l := range q {
		s += l
	}
	avg := s / len(q) // yes, it's an integer division
	ql.Unlock()
	return avg
}
245647
func (f QueryHandlerFunc) ServeQuery(ctx context.Context, res QueryResponse, req *QueryRequest) error {
	return f(ctx, res, req)
}
596372
func (f *FreqDist) max() (string, error) {
	if len(f.Samples) == 0 {
		return "", fmt.Errorf("No Samples loaded, please add samples before getting max")
	}

	max := maxFreq{}
	for key, val := range f.Samples {
		if val > max.Val {
			max.Key = key
			max.Val = val
		}
	}
	return max.Key, nil
}
1365962
func (tx *Tx) Queryx(query string, args ...interface{}) (*Rows, error) {
	r, err := tx.Tx.Query(query, args...)
	if err != nil {
		return nil, err
	}
	return &Rows{Rows: r, unsafe: tx.unsafe, Mapper: tx.Mapper}, err
}
17218
func (tx *TX) QueryAll(stmt Executable, i interface{}) error {
	result, err := tx.Query(stmt)
	if err != nil {
		return err
	}
	return result.All(i)
}
665946
func (db *DBLogger) QueryRowx(query string, args ...interface{}) *sqlx.Row {
	start := time.Now()
	row := db.DB.QueryRowx(query, args...)
	logQuery(query, time.Since(start), args...)
	return row
}
1243859
func (n *NamedStmt) Queryx(arg interface{}) (*Rows, error) {
	r, err := n.Query(arg)
	if err != nil {
		return nil, err
	}
	return &Rows{Rows: r, Mapper: n.Stmt.Mapper, unsafe: isUnsafe(n)}, err
}
1058942
func (db *DB) QueryRowx(query string, args ...interface{}) *Row {
	rows, err := db.DB.Query(query, args...)
	return &Row{rows: rows, err: err, unsafe: db.unsafe, Mapper: db.Mapper}
}
471597
func (q *QueryStringQuery) TimeZone(timeZone string) *QueryStringQuery {
	q.timeZone = timeZone
	return q
}
425793
func (self *Query) Limit(limit int) *Query {

	self.limit = limit

	return self
}
689925
func (q *RangeQuery) TimeZone(timeZone string) *RangeQuery {
	q.timeZone = timeZone
	return q
}
693791
func (c *Connection) Query(qr *QueryRequest) (*QueryResponse, error) {
	c.dbMu.RLock()
	defer c.dbMu.RUnlock()
	if c.db == nil {
		return nil, ErrConnectionDoesNotExist
	}
	return c.store.query(c, qr)
}
1203715
func (c *Client) Query(ctx context.Context, q chronograf.Query) (chronograf.Response, error) {
	if !c.opened {
		return nil, chronograf.ErrUninitialized
	}
	return c.nextDataNode().Query(ctx, q)
}