aboutsummaryrefslogtreecommitdiff
path: root/weed/query
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2019-10-02 12:06:03 -0700
committerChris Lu <chris.lu@gmail.com>2019-10-06 22:35:08 -0700
commitcf47f657af55e3c94b357f4c6519f0204aaae9f2 (patch)
tree30fd7b8c7b5a1c29a96286c3988d659f99914511 /weed/query
parent37e3da5e9c86509a47763aa43f2b66a11e902499 (diff)
downloadseaweedfs-cf47f657af55e3c94b357f4c6519f0204aaae9f2.tar.xz
seaweedfs-cf47f657af55e3c94b357f4c6519f0204aaae9f2.zip
scaffold for volume server query feature
Diffstat (limited to 'weed/query')
-rw-r--r--weed/query/json/query_json.go5
-rw-r--r--weed/query/json/query_json_test.go73
2 files changed, 78 insertions, 0 deletions
diff --git a/weed/query/json/query_json.go b/weed/query/json/query_json.go
new file mode 100644
index 000000000..779aa96e9
--- /dev/null
+++ b/weed/query/json/query_json.go
@@ -0,0 +1,5 @@
+package json
+
+func QueryJson(jsonLine string, query string) (jsonOutput string) {
+ return jsonLine
+}
diff --git a/weed/query/json/query_json_test.go b/weed/query/json/query_json_test.go
new file mode 100644
index 000000000..7ad837360
--- /dev/null
+++ b/weed/query/json/query_json_test.go
@@ -0,0 +1,73 @@
+package json
+
+import (
+ "testing"
+
+ "github.com/tidwall/gjson"
+)
+
+func TestGjson(t *testing.T) {
+ data := `
+ {
+ "quiz": {
+ "sport": {
+ "q1": {
+ "question": "Which one is correct team name in NBA?",
+ "options": [
+ "New York Bulls",
+ "Los Angeles Kings",
+ "Golden State Warriros",
+ "Huston Rocket"
+ ],
+ "answer": "Huston Rocket"
+ }
+ },
+ "maths": {
+ "q1": {
+ "question": "5 + 7 = ?",
+ "options": [
+ "10",
+ "11",
+ "12",
+ "13"
+ ],
+ "answer": "12"
+ },
+ "q2": {
+ "question": "12 - 8 = ?",
+ "options": [
+ "1",
+ "2",
+ "3",
+ "4"
+ ],
+ "answer": "4"
+ }
+ }
+ }
+ }
+
+ {
+ "fruit": "Apple",
+ "size": "Large",
+ "quiz": "Red"
+ }
+
+`
+
+ projections := []string{"quiz","fruit"}
+
+ gjson.ForEachLine(data, func(line gjson.Result) bool{
+ println(line.String())
+ println("+++++++++++")
+ results := gjson.GetMany(line.Raw, projections...)
+ for _, result := range results {
+ println(result.Index, result.Type, result.String())
+ }
+ println("-----------")
+ return true
+ })
+
+
+
+}