Changeset: 25efe47b61c9 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=25efe47b61c9 Added Files: monetdb5/extras/jaql/json_jaql.c monetdb5/extras/jaql/json_jaql.h monetdb5/extras/jaql/json_jaql.mal monetdb5/modules/atoms/Tests/json09.mal monetdb5/modules/atoms/Tests/json09.stable.err monetdb5/modules/atoms/Tests/json09.stable.out monetdb5/modules/atoms/Tests/json10.mal monetdb5/modules/atoms/Tests/json10.stable.err monetdb5/modules/atoms/Tests/json10.stable.out monetdb5/modules/atoms/Tests/json11.mal monetdb5/modules/atoms/Tests/json11.stable.err monetdb5/modules/atoms/Tests/json11.stable.out monetdb5/modules/atoms/Tests/json12.mal monetdb5/modules/atoms/Tests/json12.stable.err monetdb5/modules/atoms/Tests/json12.stable.out monetdb5/modules/atoms/Tests/json13.mal monetdb5/modules/atoms/Tests/json13.stable.err monetdb5/modules/atoms/Tests/json13.stable.out monetdb5/modules/atoms/Tests/json14.mal monetdb5/modules/atoms/Tests/json14.stable.err monetdb5/modules/atoms/Tests/json14.stable.out monetdb5/modules/atoms/json.c monetdb5/modules/atoms/json.h monetdb5/modules/atoms/json.mal Removed Files: monetdb5/extras/jaql/json.c monetdb5/extras/jaql/json.h monetdb5/extras/jaql/json.mal monetdb5/modules/atoms/Tests/json06.stable.err monetdb5/modules/atoms/Tests/json06.stable.out monetdb5/modules/atoms/json_atom.c monetdb5/modules/atoms/json_atom.h monetdb5/modules/atoms/json_atom.mal Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/exports.stable.out monetdb5/extras/jaql/30_jaql.mal monetdb5/extras/jaql/Makefile.ag monetdb5/extras/jaql/jaql.c monetdb5/modules/atoms/Makefile.ag monetdb5/modules/atoms/Tests/All monetdb5/modules/atoms/Tests/json00.stable.out monetdb5/modules/atoms/Tests/json01.mal monetdb5/modules/atoms/Tests/json01.stable.out monetdb5/modules/atoms/Tests/json03.mal monetdb5/modules/atoms/Tests/json03.stable.out monetdb5/modules/atoms/Tests/json04.mal monetdb5/modules/atoms/Tests/json04.stable.out monetdb5/modules/atoms/Tests/json05.mal monetdb5/modules/atoms/Tests/json05.stable.out monetdb5/modules/atoms/Tests/json07.mal monetdb5/modules/atoms/Tests/json07.stable.out monetdb5/modules/atoms/Tests/json08.mal monetdb5/modules/atoms/Tests/json08.stable.out monetdb5/modules/mal/mal_init.mal sql/test/json/Tests/books.sql sql/test/json/Tests/books.stable.out sql/test/json/Tests/bulkjson.sql sql/test/json/Tests/bulkjson.stable.out sql/test/json/Tests/bulkvalid.sql sql/test/json/Tests/bulkvalid.stable.out sql/test/json/Tests/parsing.sql sql/test/json/Tests/parsing.stable.err sql/test/json/Tests/pathexpr.sql sql/test/json/Tests/pathexpr.stable.err sql/test/json/Tests/pathexpr.stable.out sql/test/json/Tests/pgexample.stable.out Branch: default Log Message:
A new version of the JSON functionality JSON structures are now parsed and represented as a parse tree, before broken into pieces using a JSON path expression modelled after http://goessner.net/articles/JsonPath/ [excluding child range and union sets for now] The functionality is exported to SQL using a limited set of external functions. diffs (truncated from 5023 to 300 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -39684,6 +39684,8 @@ command json.drop(nme:str):void address JSONdrop; comment Drop the JSON object name from the database +command json.dump(j:json):void +address JSONdump; command json.extract(k:bat[:oid,:bte],s:bat[:oid,:str],i:bat[:oid,:lng],d:bat[:oid,:dbl],a:bat[:oid,:oid],o:bat[:oid,:oid],n:bat[:oid,:str],elems:bat[:oid,:oid],start:oid) (kind:bat[:oid,:bte],string:bat[:oid,:str],integer:bat[:oid,:lng],double:bat[:oid,:dbl],array:bat[:oid,:oid],object:bat[:oid,:oid],name:bat[:oid,:str]) address JSONextract; comment Extract the given elems (kind id) from the given JSON object @@ -39692,19 +39694,39 @@ command json.exportResult(o:streams,kind address JSONexportResult; comment Serialise the given JSON pointer into JSON format, respecting the MAPI protocol +pattern json.fold(k:bat[:oid,:any]):json +address JSONfold; +comment Combine the value list into a single json array object. + +pattern json.fold(k:bat[:oid,:str],v:bat[:oid,:any]):json +address JSONfold; +comment Combine the key-value pairs into a single json object list. + +pattern json.fold(o:bat[:oid,:oid],k:bat[:oid,:str],v:bat[:oid,:any]):json +address JSONfold; +comment Combine the key-value pairs into a single json object list. + +command json.filter(name:json,idx:lng,other:str):json +address JSONfilterArrayDefault; +comment Extract a single array element + command json.filter(name:json,idx:lng):json address JSONfilterArray; -comment Extract a single array element - +command json.filter(name:json,idx:int,other:str):json +address JSONfilterArrayDefault; command json.filter(name:json,idx:int):json address JSONfilterArray; +command json.filter(name:json,idx:sht,other:str):json +address JSONfilterArrayDefault; command json.filter(name:json,idx:sht):json address JSONfilterArray; +command json.filter(name:json,idx:bte,other:str):json +address JSONfilterArrayDefault; command json.filter(name:json,idx:bte):json address JSONfilterArray; command json.filter(name:json,pathexpr:str):json address JSONfilter; -comment Filter all members of an object by path expression +comment Filter all members of an object by a path expression, returning an array.Non-matching elements are skipped. command json.#fromstr():json address JSONfromString; @@ -39740,7 +39762,7 @@ comment Expands the outermost JSON objec command json.keyarray(val:json):json address JSONkeyArray; -comment Expands the outermost JSON object keys into a JSON array. +comment Expands the outermost JSON object keys into a JSON value array. command json.load(nme:str) (kind:bat[:oid,:bte],string:bat[:oid,:str],integer:bat[:oid,:lng],double:bat[:oid,:dbl],array:bat[:oid,:oid],object:bat[:oid,:oid],name:bat[:oid,:str]) address JSONload; @@ -39754,28 +39776,6 @@ command json.nextid(kind:bat[:oid,:bte]) address JSONnextid; comment Returns the next free id for the kind BAT -pattern json.nest(k:bat[:oid,:dbl]):json -address JSONnest; -comment Combine the value list into a single json array object. - -pattern json.nest(k:bat[:oid,:flt]):json -address JSONnest; -pattern json.nest(k:bat[:oid,:lng]):json -address JSONnest; -pattern json.nest(k:bat[:oid,:int]):json -address JSONnest; -pattern json.nest(k:bat[:oid,:sht]):json -address JSONnest; -pattern json.nest(k:bat[:oid,:str]):json -address JSONnest; -pattern json.nest(k:bat[:oid,:str],v:bat[:oid,:any]):json -address JSONnest; -comment Combine the key-value pairs into a single json object list. - -pattern json.nest(o:bat[:oid,:oid],k:bat[:oid,:str],v:bat[:oid,:any]):json -address JSONnest; -comment Nest the key-value pairs with object identity into a list of JSON objects - command json.new(j:str):json address JSONstr2json; comment Convert string to its JSON. Dealing with escape characters @@ -39811,9 +39811,13 @@ command json.str(j:json):str address JSONjson2str; comment Convert JSON to its string equivalent. Dealing with escape characters +command json.text(j:json,s:str):str +address JSONjson2textSeparator; +comment Convert JSON values to their plain string equivalent. + command json.text(j:json):str address JSONjson2text; -comment Convert JSON to its plain string equivalent. +comment Convert JSON values to their plain string equivalent. command json.#tostr():str address JSONtoString; @@ -39827,17 +39831,13 @@ pattern json.unwraptype(kind:bat[:oid,:b address JSONunwrap; comment Retrieve the type necessary to unwrap the given JSON array to -command json.unnest(val:json):bat[:oid,:json] -address JSONunnestOne; -comment Expands a JSON list to its elements. - -command json.unnest(val:json) (k:bat[:oid,:str],v:bat[:oid,:json]) -address JSONunnest; +pattern json.unfold(val:json) (o:bat[:oid,:oid],k:bat[:oid,:str],v:bat[:oid,:json]) +address JSONunfold; comment Expands the outermost JSON object into key-value pairs. -command json.unnest(val:json) (o:bat[:oid,:oid],k:bat[:oid,:str],v:bat[:oid,:json]) -address JSONunnestGrouped; -comment Expands the outermost JSON object into key-value pairs with object identity. +pattern json.unfold(val:json) (k:bat[:oid,:str],v:bat[:oid,:json]) +address JSONunfold; +comment Expands the outermost JSON object into key-value pairs. command json.values(val:json):bat[:oid,:json] address JSONvalueTable; @@ -39845,7 +39845,7 @@ comment Expands the outermost JSON value command json.valuearray(val:json):json address JSONvalueArray; -comment Expands the outermost JSON object values into a JSON array. +comment Expands the outermost JSON object values into a JSON value array. command json.wrap(elems:bat[:oid,:any]) (kind:bat[:oid,:bte],string:bat[:oid,:str],integer:bat[:oid,:lng],double:bat[:oid,:dbl],array:bat[:oid,:oid],object:bat[:oid,:oid],name:bat[:oid,:str]) address JSONwrap; diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -1477,27 +1477,28 @@ str ITRnext_int(int *i, int *step, int * str ITRnext_lng(lng *i, lng *step, lng *last); str ITRnext_oid(oid *i, oid *step, oid *last); str ITRnext_sht(sht *i, sht *step, sht *last); +str JSONdump(int *ret, json *val); str JSONfilter(json *ret, json *js, str *expr); str JSONfilterArray(json *ret, json *j, int *index); +str JSONfilterArrayDefault(json *ret, json *j, int *index, str *other); +str JSONfold(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); int JSONfromString(str src, int *len, json *x); str JSONisarray(bit *ret, json *j); str JSONisobject(bit *ret, json *j); str JSONisvalid(bit *ret, json *j); str JSONjson2str(str *ret, json *j); str JSONjson2text(str *ret, json *arg); +str JSONjson2textSeparator(str *ret, json *arg, str *sep); str JSONkeyArray(json *ret, json *arg); str JSONkeyTable(int *ret, json *j); str JSONlength(int *ret, json *j); -str JSONnest(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); str JSONprelude(int *ret); str JSONrenderarray(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); str JSONrenderobject(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); str JSONresultSet(str *res, bat *u, bat *rev, bat *js); str JSONstr2json(json *ret, str *j); int JSONtoString(str *s, int *len, json src); -str JSONunnest(int *key, int *val, json *j); -str JSONunnestGrouped(int *grp, int *key, int *val, json *j); -str JSONunnestOne(int *val, json *j); +str JSONunfold(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); str JSONvalueArray(json *ret, json *arg); str JSONvalueTable(int *ret, json *j); str LCKcreate(monet_lock *l); diff --git a/monetdb5/extras/jaql/30_jaql.mal b/monetdb5/extras/jaql/30_jaql.mal --- a/monetdb5/extras/jaql/30_jaql.mal +++ b/monetdb5/extras/jaql/30_jaql.mal @@ -15,6 +15,6 @@ # Copyright August 2008-2014 MonetDB B.V. # All Rights Reserved. -include json; +include json_jaql; include jaql; include jaqlfunc; diff --git a/monetdb5/extras/jaql/Makefile.ag b/monetdb5/extras/jaql/Makefile.ag --- a/monetdb5/extras/jaql/Makefile.ag +++ b/monetdb5/extras/jaql/Makefile.ag @@ -26,10 +26,10 @@ INCLUDES = ../../mal \ ../../../common/utils \ ../../../gdk -lib__json = { +lib__json_jaql = { MODULE DIR = libdir/monetdb5 - SOURCES = json.c json.h + SOURCES = json_jaql.c json_jaql.h LIBS = ../../tools/libmonetdb5 \ ../../../gdk/libbat \ @@ -52,10 +52,10 @@ lib__jaql = { $(MALLOC_LIBS) } -headers_json_mal = { +headers_json_jaql_mal = { HEADERS = mal DIR = libdir/monetdb5 - SOURCES = json.mal + SOURCES = json_jaql.mal } headers_jaql_mal = { @@ -70,5 +70,5 @@ headers_autoload = { SOURCES = 30_jaql.mal } -EXTRA_DIST = json.mal jaql.mal 30_jaql.mal +EXTRA_DIST = json_jaql.mal jaql.mal 30_jaql.mal EXTRA_DIST_DIR = jaqltests Tests diff --git a/monetdb5/extras/jaql/jaql.c b/monetdb5/extras/jaql/jaql.c --- a/monetdb5/extras/jaql/jaql.c +++ b/monetdb5/extras/jaql/jaql.c @@ -25,7 +25,7 @@ #include "jaql.h" #include "mal_client.h" #include "jaqlgencode.h" -#include "json.h" +#include "json_jaql.h" #include "gdk.h" #include "mal.h" #include "mal_exception.h" diff --git a/monetdb5/extras/jaql/json.c b/monetdb5/extras/jaql/json_jaql.c rename from monetdb5/extras/jaql/json.c rename to monetdb5/extras/jaql/json_jaql.c --- a/monetdb5/extras/jaql/json.c +++ b/monetdb5/extras/jaql/json_jaql.c @@ -24,7 +24,7 @@ */ #include "monetdb_config.h" -#include "json.h" +#include "json_jaql.h" #include "gdk.h" #include "mal.h" #include "mal_client.h" diff --git a/monetdb5/extras/jaql/json.h b/monetdb5/extras/jaql/json_jaql.h rename from monetdb5/extras/jaql/json.h rename to monetdb5/extras/jaql/json_jaql.h diff --git a/monetdb5/extras/jaql/json.mal b/monetdb5/extras/jaql/json_jaql.mal rename from monetdb5/extras/jaql/json.mal rename to monetdb5/extras/jaql/json_jaql.mal diff --git a/monetdb5/modules/atoms/Makefile.ag b/monetdb5/modules/atoms/Makefile.ag --- a/monetdb5/modules/atoms/Makefile.ag +++ b/monetdb5/modules/atoms/Makefile.ag @@ -35,7 +35,7 @@ lib_atoms = { streams.c streams.h \ str.c str.h \ url.c url.h \ - json_atom.c json_atom.h \ + json.c json.h \ uuid.c \ mcurl.c \ xml.c xml.h @@ -53,7 +53,7 @@ headers_mal = { streams.mal \ str.mal \ url.mal \ - json_atom.mal \ + json.mal \ uuid.mal \ xml.mal \ mcurl.mal \ @@ -61,4 +61,4 @@ headers_mal = { } EXTRA_DIST_DIR = Tests -EXTRA_DIST = blob.mal color.mal identifier.mal inet.mal xml.mal xml.sql batxml.sql str.mal batxml.mal url.mal json_atom.mal uuid.mal streams.mal mtime.mal mcurl.mal +EXTRA_DIST = blob.mal color.mal identifier.mal inet.mal xml.mal xml.sql batxml.sql str.mal batxml.mal url.mal json.mal uuid.mal streams.mal mtime.mal mcurl.mal diff --git a/monetdb5/modules/atoms/Tests/All b/monetdb5/modules/atoms/Tests/All --- a/monetdb5/modules/atoms/Tests/All +++ b/monetdb5/modules/atoms/Tests/All @@ -24,6 +24,11 @@ json05 json07 json08 json09 +json10 +json11 +json12 +json13 +json14 jsonrender uuid00 diff --git a/monetdb5/modules/atoms/Tests/json00.stable.out b/monetdb5/modules/atoms/Tests/json00.stable.out --- a/monetdb5/modules/atoms/Tests/json00.stable.out +++ b/monetdb5/modules/atoms/Tests/json00.stable.out _______________________________________________ checkin-list mailing list [email protected] https://www.monetdb.org/mailman/listinfo/checkin-list
