Changeset: d94504c0eae4 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/d94504c0eae4 Modified Files: monetdb5/modules/atoms/Tests/json01.maltest monetdb5/modules/atoms/Tests/json05.maltest monetdb5/modules/atoms/Tests/json08.maltest monetdb5/modules/atoms/Tests/json09.maltest monetdb5/modules/atoms/Tests/json12.maltest monetdb5/modules/atoms/Tests/json13.maltest monetdb5/modules/atoms/json.c sql/test/json/Tests/bulkjson.test sql/test/json/Tests/pathexpr.test sql/test/json/Tests/pgexample.test sql/test/json/Tests/shop.test Branch: default Log Message:
Change JSON path to return scalars when appropriate Before these changes the json.filter function would always wrap the result in square brackets, i.e. it would always return a JSON array. These changes make it so that when the result is a scalar or a single JSON object it gets returned on its own. diffs (truncated from 781 to 300 lines): diff --git a/monetdb5/modules/atoms/Tests/json01.maltest b/monetdb5/modules/atoms/Tests/json01.maltest --- a/monetdb5/modules/atoms/Tests/json01.maltest +++ b/monetdb5/modules/atoms/Tests/json01.maltest @@ -18,7 +18,7 @@ f:= json.filter(b,"f1") query T rowsort io.print(f) ---- -"[1]" +"1" statement ok b:= json.new("{\"f1\":1,\"f2\":2}") @@ -29,7 +29,7 @@ f:= json.filter(b,"f2") query T rowsort io.print(f) ---- -"[2]" +"2" statement ok f:= json.filter(b,"f1,f2") @@ -48,7 +48,7 @@ f:= json.filter(b,"f1[0]") query T rowsort io.print(f) ---- -"[1]" +"3" statement ok f:= json.filter(b,"f1[1]") @@ -56,7 +56,7 @@ f:= json.filter(b,"f1[1]") query T rowsort io.print(f) ---- -"[3]" +"3" statement ok f:= json.filter(b,"f1[2]") @@ -91,7 +91,7 @@ f:= json.filter(b,"f1") query T rowsort io.print(f) ---- -"[{\"f12\":3}]" +"{\"f12\":3}" statement ok f:= json.filter(b,"f1.f12") @@ -99,7 +99,7 @@ f:= json.filter(b,"f1.f12") query T rowsort io.print(f) ---- -"[3]" +"3" statement ok f:= json.filter(b,"$.f1.f12") @@ -107,7 +107,7 @@ f:= json.filter(b,"$.f1.f12") query T rowsort io.print(f) ---- -"[3]" +"3" statement ok f:= json.filter(b,"..f12") @@ -126,7 +126,7 @@ f:= json.filter(b,"[0]") query T rowsort io.print(f) ---- -"[1]" +"1" statement ok f:= json.filter(b,"[1]") @@ -134,7 +134,7 @@ f:= json.filter(b,"[1]") query T rowsort io.print(f) ---- -"[\"f2\"]" +"\"f2\"" statement ok f:= json.filter(b,"[2]") @@ -142,7 +142,7 @@ f:= json.filter(b,"[2]") query T rowsort io.print(f) ---- -"[2]" +"2" statement ok f:= json.filter(b,"[3]") @@ -169,7 +169,7 @@ f:= json.filter(b,"[0]") query T rowsort io.print(f) ---- -"[{\"boter\":1}]" +"{\"boter\":1}" statement ok f:= json.filter(b,"[0].boter") @@ -177,7 +177,7 @@ f:= json.filter(b,"[0].boter") query T rowsort io.print(f) ---- -"[1]" +"1" statement ok f:= json.filter(b,"[1]") @@ -185,7 +185,7 @@ f:= json.filter(b,"[1]") query T rowsort io.print(f) ---- -"[{\"kaas\":2}]" +"{\"kaas\":2}" statement ok f:= json.filter(b,"[1].kaas") @@ -193,7 +193,7 @@ f:= json.filter(b,"[1].kaas") query T rowsort io.print(f) ---- -"[2]" +"2" statement ok f:= json.filter(b,"[2]") @@ -201,7 +201,7 @@ f:= json.filter(b,"[2]") query T rowsort io.print(f) ---- -"[{\"eieren\":3}]" +"{\"eieren\":3}" statement ok f:= json.filter(b,"[2].eieren") @@ -209,7 +209,7 @@ f:= json.filter(b,"[2].eieren") query T rowsort io.print(f) ---- -"[3]" +"3" statement ok f:= json.filter(b,"[3]") diff --git a/monetdb5/modules/atoms/Tests/json05.maltest b/monetdb5/modules/atoms/Tests/json05.maltest --- a/monetdb5/modules/atoms/Tests/json05.maltest +++ b/monetdb5/modules/atoms/Tests/json05.maltest @@ -12,7 +12,7 @@ p:= json.filter(js,"[0].book") query T rowsort io.print(p) ---- -"[{ \"category\": \"reference\", \"author\": \"Nigel Rees\", \"title\": \"Sayings of the Century\", \"price\": 8.95 },{ \"category\": \"fiction\", \"author\": \"Evelyn Waugh\", \"title\": \"Sword of Honour\", \"price\": 12.99 },{ \"category\": \"fiction\", \"author\": \"Herman Melville\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99 },{ \"category\": \"fiction\", \"author\": \"J. R. R. Tolkien\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99 }]" +"{ \"category\": \"fiction\", \"author\": \"J. R. R. Tolkien\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99 }" statement ok p:= json.filter(js,"[1].pencil") @@ -20,7 +20,7 @@ p:= json.filter(js,"[1].pencil") query T rowsort io.print(p) ---- -"[{ \"color\": \"red\", \"price\": 19.95 }]" +"{ \"color\": \"red\", \"price\": 19.95 }" statement ok p:= json.filter(js,"..author") @@ -44,7 +44,7 @@ p:= json.filter(js,"[0].book[0]") query T rowsort io.print(p) ---- -"[{ \"category\": \"reference\", \"author\": \"Nigel Rees\", \"title\": \"Sayings of the Century\", \"price\": 8.95 }]" +"{ \"category\": \"reference\", \"author\": \"Nigel Rees\", \"title\": \"Sayings of the Century\", \"price\": 8.95 }" statement ok p:= json.filter(js,"[0].book[1]") @@ -52,7 +52,7 @@ p:= json.filter(js,"[0].book[1]") query T rowsort io.print(p) ---- -"[{ \"category\": \"fiction\", \"author\": \"Evelyn Waugh\", \"title\": \"Sword of Honour\", \"price\": 12.99 }]" +"{ \"category\": \"fiction\", \"author\": \"Evelyn Waugh\", \"title\": \"Sword of Honour\", \"price\": 12.99 }" statement ok p:= json.filter(js,"[0].book[2]") @@ -60,7 +60,7 @@ p:= json.filter(js,"[0].book[2]") query T rowsort io.print(p) ---- -"[{ \"category\": \"fiction\", \"author\": \"Herman Melville\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99 }]" +"{ \"category\": \"fiction\", \"author\": \"Herman Melville\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99 }" statement ok p:= json.filter(js,"[0].book[3]") @@ -68,7 +68,7 @@ p:= json.filter(js,"[0].book[3]") query T rowsort io.print(p) ---- -"[{ \"category\": \"fiction\", \"author\": \"J. R. R. Tolkien\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99 }]" +"{ \"category\": \"fiction\", \"author\": \"J. R. R. Tolkien\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99 }" statement ok p:= json.filter(js,"[0].book..category") @@ -76,7 +76,7 @@ p:= json.filter(js,"[0].book..category") query T rowsort io.print(p) ---- -"[\"reference\",\"fiction\",\"fiction\",\"fiction\"]" +"[\"fiction\"]" statement ok js := calc.json("[[{\"name\":\"john\"}], {\"name\":\"mary\"}]") diff --git a/monetdb5/modules/atoms/Tests/json08.maltest b/monetdb5/modules/atoms/Tests/json08.maltest --- a/monetdb5/modules/atoms/Tests/json08.maltest +++ b/monetdb5/modules/atoms/Tests/json08.maltest @@ -40,13 +40,13 @@ io.print(f) 0 [] 1 -[1] +1 2 -[1] +1 3 -[1,3] +3 4 -[{"f12":3}] +{"f12":3} statement ok f:bat[:json]:= mal.manifold("json","filter",j,"f2") @@ -59,11 +59,11 @@ 0 1 [] 2 -[2] +2 3 -[2] +2 4 -[[2,3,4]] +[2,3,4] statement ok f:bat[:json]:= mal.manifold("json","filter",j,"f1[0]") @@ -74,13 +74,13 @@ io.print(f) 0 [] 1 -[1] +1 2 -[1] +1 3 -[1] +1 4 -[{"f12":3}] +{"f12":3} statement ok f:bat[:json]:= mal.manifold("json","filter",j,"..f12") @@ -120,7 +120,7 @@ query IT rowsort io.print(f) ---- 0 -[1] +1 statement ok f:bat[:json]:= mal.manifold("json","filter",i,1) @@ -129,7 +129,7 @@ query IT rowsort io.print(f) ---- 0 -["f2"] +"f2" statement ok f:bat[:json]:= mal.manifold("json","filter",i,2) @@ -138,7 +138,7 @@ query IT rowsort io.print(f) ---- 0 -[2] +2 statement ok f:bat[:json]:= mal.manifold("json","filter",i,3) diff --git a/monetdb5/modules/atoms/Tests/json09.maltest b/monetdb5/modules/atoms/Tests/json09.maltest --- a/monetdb5/modules/atoms/Tests/json09.maltest +++ b/monetdb5/modules/atoms/Tests/json09.maltest @@ -26,11 +26,11 @@ query IT rowsort io.print(f) ---- _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org