aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/cmd
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2022-06-08 09:53:24 +0200
committerMartin Polden <mpolden@mpolden.no>2022-06-08 09:59:39 +0200
commit762a514a2498bdc30db424a4dd712f2c409b33b1 (patch)
tree9a2a7ee57a8d611d682fef8911bb9627d83ba65b /client/go/cmd
parent3c11b757e61d022832de4c48fae6f0a44030f4bd (diff)
Handle bare query containing equals
Diffstat (limited to 'client/go/cmd')
-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) {