Changeset: 00590870dcd2 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=00590870dcd2 Added Files: monetdb5/modules/atoms/Tests/json15.mal monetdb5/modules/atoms/Tests/json15.stable.err monetdb5/modules/atoms/Tests/json15.stable.out sql/benchmarks/nobench/Tests/All sql/benchmarks/nobench/Tests/nobench.sql sql/benchmarks/nobench/Tests/nobench.stable.err sql/benchmarks/nobench/Tests/nobench.stable.out Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/exports.stable.out monetdb5/modules/atoms/Tests/All monetdb5/modules/atoms/Tests/json01.mal monetdb5/modules/atoms/Tests/json01.stable.out sql/scripts/40_json.sql Branch: default Log Message:
Extension with number casting and sample from nobench.. diffs (truncated from 628 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 @@ -32200,7 +32200,7 @@ command bbp.getName(b:bat[:oid,:any_2]): address CMDbbpName; comment Map a BAT into its internal name -command bbp.get() (ns:bat[:any_1,:any_2],ht:bat[:int,:str],tt:bat[:int,:str],cnt:bat[:int,:lng],refcnt:bat[:int,:int],lrefcnt:bat[:int,:int],location:bat[:int,:str],heat:bat[:int,:int],dirty:bat[:int,:str],status:bat[:int,:str],kind:bat[:int,:str]) +command bbp.get() (id:bat[:oid,:int],ns:bat[:oid,:str],ht:bat[:oid,:str],tt:bat[:oid,:str],cnt:bat[:oid,:lng],refcnt:bat[:oid,:int],lrefcnt:bat[:oid,:int],location:bat[:oid,:str],heat:bat[:oid,:int],dirty:bat[:oid,:str],status:bat[:oid,:str],kind:bat[:oid,:str]) address CMDbbp; comment bpp @@ -39748,6 +39748,10 @@ command json.isvalid(val:json):bit address JSONisvalid; comment Validate the string as a valid JSON document +command json.integer(j:json):lng +address JSONjson2integer; +comment Convert sinple JSON values to an integer, return nil upon error. + command json.keys(val:json):bat[:oid,:str] address JSONkeyTable; comment Expands the outermost JSON object names. @@ -39768,6 +39772,10 @@ command json.nextid(kind:bat[:oid,:bte]) address JSONnextid; comment Returns the next free id for the kind BAT +command json.number(j:json):dbl +address JSONjson2number; +comment Convert sinple JSON values to a double, return nil upon error. + command json.new(j:str):json address JSONstr2json; comment Convert string to its JSON. Dealing with escape characters @@ -39805,7 +39813,7 @@ comment Convert JSON to its string equiv command json.text(j:json,s:str):str address JSONjson2textSeparator; -comment Convert JSON values to their plain string equivalent. +comment Convert JSON values to their plain string equivalent, injecting a separator. command json.text(j:json):str address JSONjson2text; @@ -42043,7 +42051,6 @@ pattern sql.abort():void address SQLabort; comment Trigger the abort operation for a MAL block -function sql.bbp() (id:bat[:oid,:int],name:bat[:oid,:str],htype:bat[:oid,:str],ttype:bat[:oid,:str],count:bat[:oid,:lng],refcnt:bat[:oid,:int],lrefcnt:bat[:oid,:int],location:bat[:oid,:str],heat:bat[:oid,:int],dirty:bat[:oid,:str],status:bat[:oid,:str],kind:bat[:oid,:str]); pattern sql.bind(mvc:int,schema:str,table:str,column:str,access:int,part_nr:int,nr_parts:int) (uid:bat[:oid,:oid],uval:bat[:oid,:any_1]) address mvc_bind_wrap; comment Bind the 'schema.table.column' BAT with access kind: 0 - base table 1 - inserts 2 - updates 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 @@ -1483,6 +1483,8 @@ int JSONfromString(str src, int *len, js str JSONisarray(bit *ret, json *j); str JSONisobject(bit *ret, json *j); str JSONisvalid(bit *ret, json *j); +str JSONjson2integer(lng *ret, json *arg); +str JSONjson2number(dbl *ret, json *arg); str JSONjson2str(str *ret, json *j); str JSONjson2text(str *ret, json *arg); str JSONjson2textSeparator(str *ret, json *arg, str *sep); 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 @@ -29,6 +29,7 @@ json11 json12 json13 json14 +json15 jsonrender uuid00 diff --git a/monetdb5/modules/atoms/Tests/json01.mal b/monetdb5/modules/atoms/Tests/json01.mal --- a/monetdb5/modules/atoms/Tests/json01.mal +++ b/monetdb5/modules/atoms/Tests/json01.mal @@ -20,6 +20,8 @@ io.print(f); f:= json.filter(b,"*"); io.print(f); b:= json.new("{\"f1\":{\"f12\":3},\"f2\":[2,3,4]}"); +f:= json.filter(b,"..f12,$..f2[1]"); +io.print(f); f:= json.filter(b,"f1"); io.print(f); f:= json.filter(b,"f1.f12"); diff --git a/monetdb5/modules/atoms/Tests/json01.stable.out b/monetdb5/modules/atoms/Tests/json01.stable.out --- a/monetdb5/modules/atoms/Tests/json01.stable.out +++ b/monetdb5/modules/atoms/Tests/json01.stable.out @@ -41,6 +41,8 @@ function user.main():void; f := json.filter(b,"*"); io.print(f); b := json.new("{\"f1\":{\"f12\":3},\"f2\":[2,3,4]}"); + f := json.filter(b,"..f12,$..f2[1]"); + io.print(f); f := json.filter(b,"f1"); io.print(f); f := json.filter(b,"f1.f12"); @@ -84,6 +86,7 @@ end main; [ "[3]" ] [ "[]" ] [ "[1,2,3]" ] +[ "[3,[2,3,4]]" ] [ "[{\"f12\":3}]" ] [ "[3]" ] [ "[3]" ] diff --git a/monetdb5/modules/atoms/Tests/json15.mal b/monetdb5/modules/atoms/Tests/json15.mal new file mode 100644 --- /dev/null +++ b/monetdb5/modules/atoms/Tests/json15.mal @@ -0,0 +1,38 @@ +j1:= json.new("3.14"); +#json.dump(j1); +d:= json.number(j1); +io.print(d); + +j1:= json.new("[3.14]"); +#json.dump(j1); +d:= json.number(j1); +io.print(d); + +j1:= json.new("{\"tag\":3.14}"); +json.dump(j1); +d:= json.number(j1); +io.print(d); + +j1:= json.new("[3.14,2.1]"); +d:= json.number(j1); +io.print(d); + + +j1:= json.new("314"); +#json.dump(j1); +i:= json.integer(j1); +io.print(i); + +j1:= json.new("{\"tag\":314}"); +#json.dump(j1); +i:= json.integer(j1); +io.print(i); + +j1:= json.new("[314]"); +#json.dump(j1); +i:= json.integer(j1); +io.print(i); + +j1:= json.new("[314,2.1]"); +i:= json.integer(j1); +io.print(i); diff --git a/monetdb5/modules/atoms/Tests/json15.stable.err b/monetdb5/modules/atoms/Tests/json15.stable.err new file mode 100644 --- /dev/null +++ b/monetdb5/modules/atoms/Tests/json15.stable.err @@ -0,0 +1,29 @@ +stderr of test 'json15` in directory 'monetdb5/modules/atoms` itself: + + +# 11:57:32 > +# 11:57:32 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=37511" "--set" "mapi_usock=/var/tmp/mtest-3805/.s.monetdb.37511" "--set" "monet_prompt=" "--forcemito" "--set" "mal_listing=2" "--dbpath=/export/scratch1/mk/current//Linux/var/MonetDB/mTests_monetdb5_modules_atoms" "json15.mal" +# 11:57:32 > + +# builtin opt gdk_dbpath = /export/scratch1/mk/current//Linux/var/monetdb5/dbfarm/demo +# builtin opt gdk_debug = 0 +# builtin opt gdk_vmtrim = no +# 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 = 37511 +# cmdline opt mapi_usock = /var/tmp/mtest-3805/.s.monetdb.37511 +# cmdline opt monet_prompt = +# cmdline opt mal_listing = 2 +# cmdline opt gdk_dbpath = /export/scratch1/mk/current//Linux/var/MonetDB/mTests_monetdb5_modules_atoms + +# 11:57:32 > +# 11:57:32 > "Done." +# 11:57:32 > + diff --git a/monetdb5/modules/atoms/Tests/json15.stable.out b/monetdb5/modules/atoms/Tests/json15.stable.out new file mode 100644 --- /dev/null +++ b/monetdb5/modules/atoms/Tests/json15.stable.out @@ -0,0 +1,68 @@ +stdout of test 'json15` in directory 'monetdb5/modules/atoms` itself: + + +# 11:57:32 > +# 11:57:32 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=37511" "--set" "mapi_usock=/var/tmp/mtest-3805/.s.monetdb.37511" "--set" "monet_prompt=" "--forcemito" "--set" "mal_listing=2" "--dbpath=/export/scratch1/mk/current//Linux/var/MonetDB/mTests_monetdb5_modules_atoms" "json15.mal" +# 11:57:32 > + +# MonetDB 5 server v11.18.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.591 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2014 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:37511/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-3805/.s.monetdb.37511 +# MonetDB/GIS module loaded +# MonetDB/JAQL module loaded +# MonetDB/SQL module loaded +function user.main():void; + j1 := json.new("3.14"); +#json.dump(j1); + d := json.number(j1); + io.print(d); + j1 := json.new("[3.14]"); +#json.dump(j1); + d := json.number(j1); + io.print(d); + j1 := json.new("{\"tag\":3.14}"); + json.dump(j1); + d := json.number(j1); + io.print(d); + j1 := json.new("[3.14,2.1]"); + d := json.number(j1); + io.print(d); + j1 := json.new("314"); +#json.dump(j1); + i := json.integer(j1); + io.print(i); + j1 := json.new("{\"tag\":314}"); +#json.dump(j1); + i := json.integer(j1); + io.print(i); + j1 := json.new("[314]"); +#json.dump(j1); + i := json.integer(j1); + io.print(i); + j1 := json.new("[314,2.1]"); + i := json.integer(j1); + io.print(i); +end main; +[ 3.1400000000000001 ] +[ 3.1400000000000001 ] +[0] object child 0 list 1 {"tag":3.14} +[1] element child 2 list tag +[2] number child 0 list 3.14 +[ 3.1400000000000001 ] +[ nil ] +[ 314 ] +[ 314 ] +[ 314 ] +[ nil ] + +# 11:57:32 > +# 11:57:32 > "Done." +# 11:57:32 > + diff --git a/sql/benchmarks/nobench/Tests/All b/sql/benchmarks/nobench/Tests/All new file mode 100644 --- /dev/null +++ b/sql/benchmarks/nobench/Tests/All @@ -0,0 +1,1 @@ +nobench diff --git a/sql/benchmarks/nobench/Tests/nobench.sql b/sql/benchmarks/nobench/Tests/nobench.sql new file mode 100644 --- /dev/null +++ b/sql/benchmarks/nobench/Tests/nobench.sql @@ -0,0 +1,46 @@ +create table bench10(js json); +copy 10 records into bench10 from stdin; +{"nested_obj": {"num": 4, "str": "GBRDCMBQ"}, "dyn2": true, "dyn1": 9, "nested_arr": ["especially"], "str2": "GBRDCMBQ", "str1": "GBRDCMBQGE======", "sparse_093": "GBRDCMBQGE======", "thousandth": 9, "sparse_090": "GBRDCMBQGE======", "sparse_091": "GBRDCMBQGE======", "sparse_092": "GBRDCMBQGE======", "num": 9, "bool": true, "sparse_095": "GBRDCMBQGE======", "sparse_096": "GBRDCMBQGE======", "sparse_097": "GBRDCMBQGE======", "sparse_098": "GBRDCMBQGE======", "sparse_094": "GBRDCMBQGE======", "sparse_099": "GBRDCMBQGE======"}, +{"nested_obj": {"num": 2, "str": "GBRDCMA="}, "dyn2": "GBRDCMJR", "dyn1": 7, "nested_arr": ["its", "for", "if", "he", "questions", "to", "put"], "str2": "GBRDCMA=", "str1": "GBRDCMJR", "sparse_079": "GBRDCMJR", "thousandth": 7, "sparse_078": "GBRDCMJR", "num": 7, "bool": true, "sparse_072": "GBRDCMJR", "sparse_073": "GBRDCMJR", "sparse_070": "GBRDCMJR", "sparse_071": "GBRDCMJR", "sparse_076": "GBRDCMJR", "sparse_077": "GBRDCMJR", "sparse_074": "GBRDCMJR", "sparse_075": "GBRDCMJR"}, +{"nested_obj": {"num": 3, "str": "GBRDCMI="}, "dyn2": 8, "dyn1": 8, "nested_arr": [], "str2": "GBRDCMI=", "str1": "GBRDCMBQGA======", "thousandth": 8, "sparse_087": "GBRDCMBQGA======", "sparse_086": "GBRDCMBQGA======", "sparse_085": "GBRDCMBQGA======", "num": 8, "bool": false, "sparse_082": "GBRDCMBQGA======", "sparse_081": "GBRDCMBQGA======", "sparse_080": "GBRDCMBQGA======", "sparse_083": "GBRDCMBQGA======", "sparse_084": "GBRDCMBQGA======", "sparse_089": "GBRDCMBQGA======", "sparse_088": "GBRDCMBQGA======"}, +{"nested_obj": {"num": 0, "str": "GBRDA==="}, "dyn2": 5, "dyn1": 5, "nested_arr": ["the", "state", "aware", "''", "the"], "str2": "GBRDA===", "str1": "GBRDCMBR", "sparse_058": "GBRDCMBR", "thousandth": 5, "num": 5, "bool": true, "sparse_059": "GBRDCMBR", "sparse_054": "GBRDCMBR", "sparse_055": "GBRDCMBR", "sparse_056": "GBRDCMBR", "sparse_057": "GBRDCMBR", "sparse_050": "GBRDCMBR", "sparse_051": "GBRDCMBR", "sparse_052": "GBRDCMBR", "sparse_053": "GBRDCMBR"}, +{"nested_obj": {"num": 8, "str": "GBRDCMBQGA======"}, "sparse_035": "GBRDCMI=", "dyn2": true, "dyn1": 3, "nested_arr": ["check", "it", "the"], "str2": "GBRDCMBQGA======", "str1": "GBRDCMI=", "thousandth": 3, "sparse_036": "GBRDCMI=", "sparse_037": "GBRDCMI=", "sparse_034": "GBRDCMI=", "num": 3, "bool": true, "sparse_033": "GBRDCMI=", "sparse_030": "GBRDCMI=", "sparse_031": "GBRDCMI=", "sparse_032": "GBRDCMI=", "sparse_038": "GBRDCMI=", "sparse_039": "GBRDCMI="}, +{"nested_obj": {"num": 9, "str": "GBRDCMBQGE======"}, "sparse_040": "GBRDCMBQ", "dyn2": "GBRDCMBQ", "dyn1": 4, "nested_arr": ["potatoes", "a", "to", "authentic"], "str2": "GBRDCMBQGE======", "str1": "GBRDCMBQ", "thousandth": 4, "sparse_043": "GBRDCMBQ", "sparse_042": "GBRDCMBQ", "sparse_041": "GBRDCMBQ", "num": 4, "bool": false, "sparse_046": "GBRDCMBQ", "sparse_045": "GBRDCMBQ", "sparse_044": "GBRDCMBQ", "sparse_047": "GBRDCMBQ", "sparse_049": "GBRDCMBQ", "sparse_048": "GBRDCMBQ"}, +{"sparse_018": "GBRDC===", "nested_obj": {"num": 6, "str": "GBRDCMJQ"}, "dyn2": "GBRDC===", "dyn1": 1, "nested_arr": ["button-down"], "sparse_010": "GBRDC===", "str2": "GBRDCMJQ", "str1": "GBRDC===", "sparse_013": "GBRDC===", "sparse_014": "GBRDC===", "sparse_015": "GBRDC===", "sparse_016": "GBRDC===", "sparse_017": "GBRDC===", "num": 1, "bool": true, "sparse_011": "GBRDC===", "thousandth": 1, "sparse_019": "GBRDC===", "sparse_012": "GBRDC==="}, +{"nested_obj": {"num": 7, "str": "GBRDCMJR"}, "dyn2": 2, "dyn1": 2, "nested_arr": ["she", "beyond"], "str2": "GBRDCMJR", "str1": "GBRDCMA=", "thousandth": 2, "sparse_025": "GBRDCMA=", "sparse_024": "GBRDCMA=", "sparse_027": "GBRDCMA=", "num": 2, "bool": false, "sparse_020": "GBRDCMA=", "sparse_023": "GBRDCMA=", "sparse_022": "GBRDCMA=", "sparse_021": "GBRDCMA=", "sparse_029": "GBRDCMA=", "sparse_028": "GBRDCMA=", "sparse_026": "GBRDCMA="}, +{"nested_obj": {"num": 5, "str": "GBRDCMBR"}, "sparse_008": "GBRDA===", "sparse_009": "GBRDA===", "dyn2": false, "dyn1": "GBRDA===", "nested_arr": [], "sparse_007": "GBRDA===", "str2": "GBRDCMBR", "str1": "GBRDA===", "sparse_004": "GBRDA===", "sparse_003": "GBRDA===", "sparse_002": "GBRDA===", "sparse_001": "GBRDA===", "sparse_000": "GBRDA===", "num": 0, "bool": false, "sparse_006": "GBRDA===", "thousandth": 0, "sparse_005": "GBRDA==="}, +{"nested_obj": {"num": 1, "str": "GBRDC==="}, "dyn2": false, "dyn1": 6, "nested_arr": ["to", "interrupted", "some", "daily", "has", "averages"], "str2": "GBRDC===", "str1": "GBRDCMJQ", "thousandth": 6, "sparse_069": "GBRDCMJQ", "sparse_068": "GBRDCMJQ", "num": 6, "bool": false, "sparse_061": "GBRDCMJQ", "sparse_060": "GBRDCMJQ", "sparse_063": "GBRDCMJQ", "sparse_062": "GBRDCMJQ", "sparse_065": "GBRDCMJQ", "sparse_064": "GBRDCMJQ", "sparse_067": "GBRDCMJQ", "sparse_066": "GBRDCMJQ"} + +select count(*) from bench10; +--Q1 all documents have it + +select json.filter(js, '$..str1,$..num') from bench10; + +-- Q2 +select json.filter(js,'.nested_obj.str,.nested_obj.num') from bench10; + +-- Q3 +select json.filter(js,'..sparse_000,..sparse_001') from bench10; + +select json.filter(js,'str1') from bench10; + +select json.text(json.filter(js,'str1')) from bench10; + +--Q5 point +select * from bench10 where json.text(json.filter(js,'str1')) = 'GBRDCMBR'; + +--Q6 +select json.number(json.filter(js,'num')) from bench10; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list