Commit bb5c1040 authored by Quentin Smith's avatar Quentin Smith

analysis/app: parse prefix separately

Change-Id: I185b853a2580ee16741cbf1581ba465400a5b28b
Reviewed-on: https://go-review.googlesource.com/35947Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 68248f17
......@@ -167,7 +167,7 @@ type compareData struct {
func (a *App) compareQuery(q string) *compareData {
// Parse query
queries := parseQueryString(q)
prefix, queries := parseQueryString(q)
// Send requests
// TODO(quentin): Issue requests in parallel?
......@@ -175,6 +175,9 @@ func (a *App) compareQuery(q string) *compareData {
var found int
for _, qPart := range queries {
group := &resultGroup{}
if prefix != "" {
qPart = prefix + " " + qPart
}
res := a.StorageClient.Query(qPart)
for res.Next() {
group.add(res.Result())
......
......@@ -8,11 +8,11 @@ import "strings"
// parseQueryString splits a user-entered query into one or more storage server queries.
// The supported query formats are:
// prefix | one vs two - parsed as {"prefix one", "prefix two"}
// prefix one vs two - parsed as {"prefix one", "two"}
// anything else - parsed as {"anything else"}
// prefix | one vs two - parsed as "prefix", {"one", "two"}
// prefix one vs two - parsed as "", {"prefix one", "two"}
// anything else - parsed as "", {"anything else"}
// The vs and | separators must not be quoted.
func parseQueryString(q string) []string {
func parseQueryString(q string) (string, []string) {
var queries []string
var parts []string
var prefix string
......@@ -33,10 +33,10 @@ func parseQueryString(q string) []string {
case c == ' ', c == '\t':
switch part := q[:r]; {
case part == "|" && prefix == "":
prefix = strings.Join(parts, " ") + " "
prefix = strings.Join(parts, " ")
parts = nil
case part == "vs":
queries = append(queries, prefix+strings.Join(parts, " "))
queries = append(queries, strings.Join(parts, " "))
parts = nil
default:
parts = append(parts, part)
......@@ -54,7 +54,7 @@ func parseQueryString(q string) []string {
parts = append(parts, q)
}
if len(parts) > 0 {
queries = append(queries, prefix+strings.Join(parts, " "))
queries = append(queries, strings.Join(parts, " "))
}
return queries
return prefix, queries
}
......@@ -11,20 +11,24 @@ import (
func TestParseQueryString(t *testing.T) {
tests := []struct {
q string
want []string
q string
wantPrefix string
wantParts []string
}{
{"prefix | one vs two", []string{"prefix one", "prefix two"}},
{"prefix one vs two", []string{"prefix one", "two"}},
{"anything else", []string{"anything else"}},
{`one vs "two vs three"`, []string{"one", `"two vs three"`}},
{"mixed\ttabs \"and\tspaces\"", []string{"mixed tabs \"and\tspaces\""}},
{"prefix | one vs two", "prefix", []string{"one", "two"}},
{"prefix one vs two", "", []string{"prefix one", "two"}},
{"anything else", "", []string{"anything else"}},
{`one vs "two vs three"`, "", []string{"one", `"two vs three"`}},
{"mixed\ttabs \"and\tspaces\"", "", []string{"mixed tabs \"and\tspaces\""}},
}
for _, test := range tests {
t.Run(test.q, func(t *testing.T) {
have := parseQueryString(test.q)
if !reflect.DeepEqual(have, test.want) {
t.Fatalf("parseQueryString = %#v, want %#v", have, test.want)
havePrefix, haveParts := parseQueryString(test.q)
if havePrefix != test.wantPrefix {
t.Errorf("parseQueryString returned prefix %q, want %q", havePrefix, test.wantPrefix)
}
if !reflect.DeepEqual(haveParts, test.wantParts) {
t.Errorf("parseQueryString returned parts %#v, want %#v", haveParts, test.wantParts)
}
})
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment