aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-06-08 10:06:18 +0200
committerGitHub <noreply@github.com>2022-06-08 10:06:18 +0200
commitbba749743bc02b396298579fdf4e076bc8f8c196 (patch)
tree87930bd20856675bee151cc81d49755f5ee19237
parent47b0532fc97aebda3ac42aff3fce70fe88d18717 (diff)
parent762a514a2498bdc30db424a4dd712f2c409b33b1 (diff)
Merge pull request #22982 from vespa-engine/mpolden/bare-query-equals7
Handle bare query containing equals
-rw-r--r--client/go/cmd/query.go11
-rw-r--r--client/go/cmd/query_test.go16
2 files changed, 21 insertions, 6 deletions
diff --git a/client/go/cmd/query.go b/client/go/cmd/query.go
index 7abf17d5358..82ff5185cbd 100644
--- a/client/go/cmd/query.go
+++ b/client/go/cmd/query.go
@@ -105,10 +105,13 @@ func query(cli *CLI, arguments []string, timeoutSecs int, curl bool) error {
}
func splitArg(argument string) (string, string) {
- equalsIndex := strings.Index(argument, "=")
- if equalsIndex < 1 {
+ parts := strings.SplitN(argument, "=", 2)
+ if len(parts) < 2 {
+ return "yql", parts[0]
+ }
+ if strings.HasPrefix(strings.ToLower(parts[0]), "select ") {
+ // A query containing '='
return "yql", argument
- } else {
- return argument[0:equalsIndex], argument[equalsIndex+1:]
}
+ return parts[0], parts[1]
}
diff --git a/client/go/cmd/query_test.go b/client/go/cmd/query_test.go
index ab03058d079..d024ca5189e 100644
--- a/client/go/cmd/query_test.go
+++ b/client/go/cmd/query_test.go
@@ -39,8 +39,20 @@ func TestQueryNonJsonResult(t *testing.T) {
func TestQueryWithMultipleParameters(t *testing.T) {
assertQuery(t,
- "?hits=5&timeout=20s&yql=select+from+sources+%2A+where+title+contains+%27foo%27",
- "select from sources * where title contains 'foo'", "hits=5", "timeout=20s")
+ "?hits=5&timeout=20s&yql=select+from+sources+%2A+where+title+contains+%27foo%27+and+year+%3D+2000",
+ "select from sources * where title contains 'foo' and year = 2000", "hits=5", "timeout=20s")
+}
+
+func TestQueryWithEquals(t *testing.T) {
+ assertQuery(t,
+ "?timeout=10s&yql=SELECT+from+sources+%2A+where+title+contains+%27foo%27+and+year+%3D+2000",
+ "SELECT from sources * where title contains 'foo' and year = 2000")
+}
+
+func TestQuerySelect(t *testing.T) {
+ assertQuery(t,
+ "?hits=5&select=%7B%22select%22%3A%7B%22where%22%3A%7B%22contains%22%3A%5B%22title%22%2C%22a%22%5D%7D%7D%7D&timeout=10s",
+ `select={"select":{"where":{"contains":["title","a"]}}}`, "hits=5")
}
func TestQueryWithExplicitYqlParameter(t *testing.T) {