aboutsummaryrefslogtreecommitdiff
path: root/weed/query/json/query_json_test.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2019-10-06 22:35:05 -0700
committerChris Lu <chris.lu@gmail.com>2019-10-06 22:35:08 -0700
commitf8d4b7d1c01eecb54edc4169d6b8a0d3c39a730c (patch)
treee463982066e42bdabeae7cff5e0569c0874b4c39 /weed/query/json/query_json_test.go
parente26670c67ad27301dcfd597c94f5fce9b5cd6331 (diff)
downloadseaweedfs-f8d4b7d1c01eecb54edc4169d6b8a0d3c39a730c.tar.xz
seaweedfs-f8d4b7d1c01eecb54edc4169d6b8a0d3c39a730c.zip
support basic json filtering and selection
Diffstat (limited to 'weed/query/json/query_json_test.go')
-rw-r--r--weed/query/json/query_json_test.go65
1 files changed, 64 insertions, 1 deletions
diff --git a/weed/query/json/query_json_test.go b/weed/query/json/query_json_test.go
index 7ad837360..621d4f548 100644
--- a/weed/query/json/query_json_test.go
+++ b/weed/query/json/query_json_test.go
@@ -58,7 +58,7 @@ func TestGjson(t *testing.T) {
projections := []string{"quiz","fruit"}
gjson.ForEachLine(data, func(line gjson.Result) bool{
- println(line.String())
+ println(line.Raw)
println("+++++++++++")
results := gjson.GetMany(line.Raw, projections...)
for _, result := range results {
@@ -71,3 +71,66 @@ func TestGjson(t *testing.T) {
}
+
+func TestJsonQueryRow(t *testing.T) {
+
+ data := `
+ {
+ "fruit": "Bl\"ue",
+ "size": 6,
+ "quiz": "green"
+ }
+
+`
+ selections := []string{"fruit", "size"}
+
+ isFiltered, values := QueryJson(data, selections, Query{
+ Field: "quiz",
+ Op: "=",
+ Value: "green",
+ })
+
+ if !isFiltered {
+ t.Errorf("should have been filtered")
+ }
+
+ if values == nil {
+ t.Errorf("values should have been returned")
+ }
+
+ buf := ToJson(nil, selections, values)
+ println(string(buf))
+
+}
+
+func TestJsonQueryNumber(t *testing.T) {
+
+ data := `
+ {
+ "fruit": "Bl\"ue",
+ "size": 6,
+ "quiz": "green"
+ }
+
+`
+ selections := []string{"fruit", "quiz"}
+
+ isFiltered, values := QueryJson(data, selections, Query{
+ Field: "size",
+ Op: ">=",
+ Value: "6",
+ })
+
+ if !isFiltered {
+ t.Errorf("should have been filtered")
+ }
+
+ if values == nil {
+ t.Errorf("values should have been returned")
+ }
+
+ buf := ToJson(nil, selections, values)
+ println(string(buf))
+
+}
+