Skip to content

Commit

Permalink
Change to local variables
Browse files Browse the repository at this point in the history
Signed-off-by: haanhvu <haanh6594@gmail.com>
  • Loading branch information
haanhvu committed Sep 11, 2022
1 parent ed6590f commit 6c7a806
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/querysharding/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (a *QueryAnalyzer) Analyze(query string) (QueryAnalysis, error) {
}

isShardable := true
shardingLabels := make([]string, 0)
var analysis QueryAnalysis
parser.Inspect(expr, func(node parser.Node, nodes []parser.Node) error {
switch n := node.(type) {
Expand All @@ -57,10 +56,11 @@ func (a *QueryAnalyzer) Analyze(query string) (QueryAnalysis, error) {
}
case *parser.BinaryExpr:
if n.VectorMatching != nil {
shardingLabels = without(n.VectorMatching.MatchingLabels, []string{"le"})
shardingLabels := without(n.VectorMatching.MatchingLabels, []string{"le"})
analysis = analysis.scopeToLabels(shardingLabels, n.VectorMatching.On)
}
case *parser.AggregateExpr:
shardingLabels := make([]string, 0)
if len(n.Grouping) > 0 {
shardingLabels = without(n.Grouping, []string{"le"})
}
Expand All @@ -83,11 +83,10 @@ func (a *QueryAnalyzer) Analyze(query string) (QueryAnalysis, error) {
}

func analyzeRootExpression(node parser.Node) QueryAnalysis {
shardingLabels := make([]string, 0)
switch n := node.(type) {
case *parser.BinaryExpr:
if n.VectorMatching != nil && n.VectorMatching.On {
shardingLabels = without(n.VectorMatching.MatchingLabels, []string{"le"})
shardingLabels := without(n.VectorMatching.MatchingLabels, []string{"le"})
return newShardableByLabels(shardingLabels, n.VectorMatching.On)
} else {
return nonShardableQuery()
Expand All @@ -97,7 +96,7 @@ func analyzeRootExpression(node parser.Node) QueryAnalysis {
return nonShardableQuery()
}

shardingLabels = without(n.Grouping, []string{"le"})
shardingLabels := without(n.Grouping, []string{"le"})
return newShardableByLabels(shardingLabels, !n.Without)
}

Expand Down

0 comments on commit 6c7a806

Please sign in to comment.