Browse Source

Lower-case some package-internal names.

pull/536/head
Julius Volz 10 years ago
parent
commit
67e20acc6c
  1. 26
      rules/ast/query_analyzer.go
  2. 14
      rules/ast/walk.go

26
rules/ast/query_analyzer.go

@ -36,10 +36,10 @@ type preloadTimes struct {
ranges map[clientmodel.Fingerprint]time.Duration ranges map[clientmodel.Fingerprint]time.Duration
} }
// A QueryAnalyzer recursively traverses the AST to look for any nodes // A queryAnalyzer recursively traverses the AST to look for any nodes
// which will need data from the datastore. Instantiate with // which will need data from the datastore. Instantiate with
// NewQueryAnalyzer. // newQueryAnalyzer.
type QueryAnalyzer struct { type queryAnalyzer struct {
// Tracks one set of times to preload per offset that occurs in the query // Tracks one set of times to preload per offset that occurs in the query
// expression. // expression.
offsetPreloadTimes map[time.Duration]preloadTimes offsetPreloadTimes map[time.Duration]preloadTimes
@ -48,17 +48,17 @@ type QueryAnalyzer struct {
storage local.Storage storage local.Storage
} }
// NewQueryAnalyzer returns a pointer to a newly instantiated // newQueryAnalyzer returns a pointer to a newly instantiated
// QueryAnalyzer. The storage is needed to extract timeseries // queryAnalyzer. The storage is needed to extract timeseries
// fingerprint information during query analysis. // fingerprint information during query analysis.
func NewQueryAnalyzer(storage local.Storage) *QueryAnalyzer { func newQueryAnalyzer(storage local.Storage) *queryAnalyzer {
return &QueryAnalyzer{ return &queryAnalyzer{
offsetPreloadTimes: map[time.Duration]preloadTimes{}, offsetPreloadTimes: map[time.Duration]preloadTimes{},
storage: storage, storage: storage,
} }
} }
func (analyzer *QueryAnalyzer) getPreloadTimes(offset time.Duration) preloadTimes { func (analyzer *queryAnalyzer) getPreloadTimes(offset time.Duration) preloadTimes {
if _, ok := analyzer.offsetPreloadTimes[offset]; !ok { if _, ok := analyzer.offsetPreloadTimes[offset]; !ok {
analyzer.offsetPreloadTimes[offset] = preloadTimes{ analyzer.offsetPreloadTimes[offset] = preloadTimes{
instants: map[clientmodel.Fingerprint]struct{}{}, instants: map[clientmodel.Fingerprint]struct{}{},
@ -68,8 +68,8 @@ func (analyzer *QueryAnalyzer) getPreloadTimes(offset time.Duration) preloadTime
return analyzer.offsetPreloadTimes[offset] return analyzer.offsetPreloadTimes[offset]
} }
// Visit implements the Visitor interface. // visit implements the visitor interface.
func (analyzer *QueryAnalyzer) Visit(node Node) { func (analyzer *queryAnalyzer) visit(node Node) {
switch n := node.(type) { switch n := node.(type) {
case *VectorSelector: case *VectorSelector:
pt := analyzer.getPreloadTimes(n.offset) pt := analyzer.getPreloadTimes(n.offset)
@ -107,7 +107,7 @@ type iteratorInitializer struct {
storage local.Storage storage local.Storage
} }
func (i *iteratorInitializer) Visit(node Node) { func (i *iteratorInitializer) visit(node Node) {
switch n := node.(type) { switch n := node.(type) {
case *VectorSelector: case *VectorSelector:
for _, fp := range n.fingerprints { for _, fp := range n.fingerprints {
@ -124,7 +124,7 @@ func prepareInstantQuery(node Node, timestamp clientmodel.Timestamp, storage loc
totalTimer := queryStats.GetTimer(stats.TotalEvalTime) totalTimer := queryStats.GetTimer(stats.TotalEvalTime)
analyzeTimer := queryStats.GetTimer(stats.QueryAnalysisTime).Start() analyzeTimer := queryStats.GetTimer(stats.QueryAnalysisTime).Start()
analyzer := NewQueryAnalyzer(storage) analyzer := newQueryAnalyzer(storage)
Walk(analyzer, node) Walk(analyzer, node)
analyzeTimer.Stop() analyzeTimer.Stop()
@ -171,7 +171,7 @@ func prepareRangeQuery(node Node, start clientmodel.Timestamp, end clientmodel.T
totalTimer := queryStats.GetTimer(stats.TotalEvalTime) totalTimer := queryStats.GetTimer(stats.TotalEvalTime)
analyzeTimer := queryStats.GetTimer(stats.QueryAnalysisTime).Start() analyzeTimer := queryStats.GetTimer(stats.QueryAnalysisTime).Start()
analyzer := NewQueryAnalyzer(storage) analyzer := newQueryAnalyzer(storage)
Walk(analyzer, node) Walk(analyzer, node)
analyzeTimer.Stop() analyzeTimer.Stop()

14
rules/ast/walk.go

@ -13,16 +13,16 @@
package ast package ast
// Visitor is the interface for a Node visitor. // visitor is the interface for a Node visitor.
type Visitor interface { type visitor interface {
Visit(node Node) visit(node Node)
} }
// Walk does a depth-first traversal of the AST, starting at node, // Walk does a depth-first traversal of the AST, starting at node,
// calling visitor.Visit for each encountered Node in the tree. // calling visitor.visit for each encountered Node in the tree.
func Walk(visitor Visitor, node Node) { func Walk(v visitor, node Node) {
visitor.Visit(node) v.visit(node)
for _, childNode := range node.Children() { for _, childNode := range node.Children() {
Walk(visitor, childNode) Walk(v, childNode)
} }
} }

Loading…
Cancel
Save