Changeset: a15f26cd4745 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a15f26cd4745
Added Files:
monetdb5/modules/atoms/Tests/json04.mal
monetdb5/modules/atoms/Tests/json04.stable.err
monetdb5/modules/atoms/Tests/json04.stable.out
Modified Files:
monetdb5/modules/atoms/json_atom.c
Branch: default
Log Message:
Support JSON string quote trimming
diffs (212 lines):
diff --git a/monetdb5/modules/atoms/Tests/json04.mal
b/monetdb5/modules/atoms/Tests/json04.mal
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/Tests/json04.mal
@@ -0,0 +1,19 @@
+js:= calc.json("[{ \"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 }, { \"color\": \"red\", \"price\": 19.95 }]");
+
+
+io.print(js);
+
+(k,v):= json.unnest(js);
+io.print(k,v);
+jsn:= json.nest(k,v);
+io.print(jsn);
+
+(o,l,w):= json.unnest(js);
+io.print(o,l,w);
+
+barrier (i,j):= iterator.new(w);
+s:= json.str(j);
+io.print(j);
+io.print(s);
+redo (i,j) := iterator.next(w);
+exit (i,j);
diff --git a/monetdb5/modules/atoms/Tests/json04.stable.err
b/monetdb5/modules/atoms/Tests/json04.stable.err
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/Tests/json04.stable.err
@@ -0,0 +1,29 @@
+stderr of test 'json04` in directory 'monetdb5/modules/atoms` itself:
+
+
+# 22:43:20 >
+# 22:43:20 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=37577" "--set"
"mapi_usock=/var/tmp/mtest-19132/.s.monetdb.37577" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/export/scratch1/mk/current//Linux/var/MonetDB/mTests_monetdb5_modules_atoms"
"json04.mal"
+# 22:43:20 >
+
+# builtin opt gdk_dbpath =
/export/scratch1/mk/current//Linux/var/monetdb5/dbfarm/demo
+# builtin opt gdk_debug = 0
+# builtin opt gdk_vmtrim = yes
+# builtin opt monet_prompt = >
+# builtin opt monet_daemon = no
+# builtin opt mapi_port = 50000
+# builtin opt mapi_open = false
+# builtin opt mapi_autosense = false
+# builtin opt sql_optimizer = default_pipe
+# builtin opt sql_debug = 0
+# cmdline opt gdk_nr_threads = 0
+# cmdline opt mapi_open = true
+# cmdline opt mapi_port = 37577
+# cmdline opt mapi_usock = /var/tmp/mtest-19132/.s.monetdb.37577
+# cmdline opt monet_prompt =
+# cmdline opt mal_listing = 2
+# cmdline opt gdk_dbpath =
/export/scratch1/mk/current//Linux/var/MonetDB/mTests_monetdb5_modules_atoms
+
+# 22:43:20 >
+# 22:43:20 > "Done."
+# 22:43:20 >
+
diff --git a/monetdb5/modules/atoms/Tests/json04.stable.out
b/monetdb5/modules/atoms/Tests/json04.stable.out
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/Tests/json04.stable.out
@@ -0,0 +1,131 @@
+stdout of test 'json04` in directory 'monetdb5/modules/atoms` itself:
+
+
+# 22:43:20 >
+# 22:43:20 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=37577" "--set"
"mapi_usock=/var/tmp/mtest-19132/.s.monetdb.37577" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/export/scratch1/mk/current//Linux/var/MonetDB/mTests_monetdb5_modules_atoms"
"json04.mal"
+# 22:43:20 >
+
+# MonetDB 5 server v11.16.0
+# This is an unreleased version
+# Serving database 'mTests_monetdb5_modules_atoms', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically
linked
+# Found 15.629 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2013 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://vienna.ins.cwi.nl:37577/
+# Listening for UNIX domain connection requests on
mapi:monetdb:///var/tmp/mtest-19132/.s.monetdb.37577
+# MonetDB/GIS module loaded
+# MonetDB/JAQL module loaded
+# MonetDB/SQL module loaded
+function user.main():void;
+ js := calc.json("[{ \"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 }, { \"color\": \"red\", \"price\": 19.95 }]");
+ io.print(js);
+ (k,v) := json.unnest(js);
+ io.print(k,v);
+ jsn := json.nest(k,v);
+ io.print(jsn);
+ (o,l,w) := json.unnest(js);
+ io.print(o,l,w);
+barrier (i,j) := iterator.new(w);
+ s := json.str(j);
+ io.print(j);
+ io.print(s);
+ redo (i,j) := iterator.next(w);
+exit (i,j);
+end main;
+[ "[{ \"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 }, { \"color\": \"red\",
\"price\": 19.95 }]" ]
+#---------------------------------------------------------#
+# h t t # name
+# void str json # type
+#---------------------------------------------------------#
+[ 0@0, "category", "\"reference\"" ]
+[ 1@0, "author", "\"Nigel Rees\"" ]
+[ 2@0, "title", "\"Sayings of the Century\"" ]
+[ 3@0, "price", "8.95 " ]
+[ 4@0, "category", "\"fiction\"" ]
+[ 5@0, "author", "\"Evelyn Waugh\"" ]
+[ 6@0, "title", "\"Sword of Honour\"" ]
+[ 7@0, "price", "12.99 " ]
+[ 8@0, "category", "\"fiction\"" ]
+[ 9@0, "author", "\"Herman Melville\"" ]
+[ 10@0, "title", "\"Moby Dick\"" ]
+[ 11@0, "isbn", "\"0-553-21311-3\"" ]
+[ 12@0, "price", "8.99 " ]
+[ 13@0, "category", "\"fiction\"" ]
+[ 14@0, "author", "\"J. R. R. Tolkien\"" ]
+[ 15@0, "title", "\"The Lord of the Rings\"" ]
+[ 16@0, "isbn", "\"0-395-19395-8\"" ]
+[ 17@0, "price", "22.99 " ]
+[ 18@0, "color", "\"red\"" ]
+[ 19@0, "price", "19.95 " ]
+[ "[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings
of the Century\",\"price\":.9\",\"category\":\"fiction\",\"author\":\"Evelyn
Waugh\",\"title\":\"Sword of
Honour\",\"price\":2.9\",\"category\":\"fiction\",\"author\":\"Herman
Melville\",\"title\":\"Moby
Dick\",\"isbn\":\"0-553-21311-3\",\"price\":.9\",\"category\":\"fiction\",\"author\":\"J.
R. R. Tolkien\",\"title\":\"The Lord of the
Rings\",\"isbn\":\"0-395-19395-8\",\"price\":2.9\",\"color\":\"red\",\"price\":9.9\"}]"
]
+#-----------------------------------------------------------------#
+# h t t t # name
+# void oid str json # type
+#-----------------------------------------------------------------#
+[ 0@0, 0@0, "category", "\"reference\"" ]
+[ 1@0, 0@0, "author", "\"Nigel Rees\"" ]
+[ 2@0, 0@0, "title", "\"Sayings of the Century\"" ]
+[ 3@0, 0@0, "price", "8.95 " ]
+[ 4@0, 1@0, "category", "\"fiction\"" ]
+[ 5@0, 1@0, "author", "\"Evelyn Waugh\"" ]
+[ 6@0, 1@0, "title", "\"Sword of Honour\"" ]
+[ 7@0, 1@0, "price", "12.99 " ]
+[ 8@0, 2@0, "category", "\"fiction\"" ]
+[ 9@0, 2@0, "author", "\"Herman Melville\"" ]
+[ 10@0, 2@0, "title", "\"Moby Dick\"" ]
+[ 11@0, 2@0, "isbn", "\"0-553-21311-3\"" ]
+[ 12@0, 2@0, "price", "8.99 " ]
+[ 13@0, 3@0, "category", "\"fiction\"" ]
+[ 14@0, 3@0, "author", "\"J. R. R. Tolkien\"" ]
+[ 15@0, 3@0, "title", "\"The Lord of the Rings\"" ]
+[ 16@0, 3@0, "isbn", "\"0-395-19395-8\"" ]
+[ 17@0, 3@0, "price", "22.99 " ]
+[ 18@0, 4@0, "color", "\"red\"" ]
+[ 19@0, 4@0, "price", "19.95 " ]
+[ "\"reference\"" ]
+[ "reference" ]
+[ "\"Nigel Rees\"" ]
+[ "Nigel Rees" ]
+[ "\"Sayings of the Century\"" ]
+[ "Sayings of the Century" ]
+[ "8.95 " ]
+[ "8.95 " ]
+[ "\"fiction\"" ]
+[ "fiction" ]
+[ "\"Evelyn Waugh\"" ]
+[ "Evelyn Waugh" ]
+[ "\"Sword of Honour\"" ]
+[ "Sword of Honour" ]
+[ "12.99 " ]
+[ "12.99 " ]
+[ "\"fiction\"" ]
+[ "fiction" ]
+[ "\"Herman Melville\"" ]
+[ "Herman Melville" ]
+[ "\"Moby Dick\"" ]
+[ "Moby Dick" ]
+[ "\"0-553-21311-3\"" ]
+[ "0-553-21311-3" ]
+[ "8.99 " ]
+[ "8.99 " ]
+[ "\"fiction\"" ]
+[ "fiction" ]
+[ "\"J. R. R. Tolkien\"" ]
+[ "J. R. R. Tolkien" ]
+[ "\"The Lord of the Rings\"" ]
+[ "The Lord of the Rings" ]
+[ "\"0-395-19395-8\"" ]
+[ "0-395-19395-8" ]
+[ "22.99 " ]
+[ "22.99 " ]
+[ "\"red\"" ]
+[ "red" ]
+[ "19.95 " ]
+[ "19.95 " ]
+
+# 22:43:20 >
+# 22:43:20 > "Done."
+# 22:43:20 >
+
diff --git a/monetdb5/modules/atoms/json_atom.c
b/monetdb5/modules/atoms/json_atom.c
--- a/monetdb5/modules/atoms/json_atom.c
+++ b/monetdb5/modules/atoms/json_atom.c
@@ -96,7 +96,13 @@ int JSONtoString(str *s, int *len, json
str JSONjson2str(str *ret, json *j)
{
- *ret = GDKstrdup(*j);
+ char *s = *j;
+ if (*s == '"')
+ s++;
+ s = GDKstrdup(s);
+ if ( s[strlen(s)-1] == '"')
+ s[strlen(s)-1] =0;
+ *ret = s;
return MAL_SUCCEED;
}
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list