Changeset: fe2fc41f7a15 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fe2fc41f7a15
Added Files:
        sql/backends/monet5/rest/Tests/jsonstore01.sql
        sql/backends/monet5/rest/Tests/jsonstore01.stable.err
        sql/backends/monet5/rest/Tests/jsonstore01.stable.out
Modified Files:
        sql/backends/monet5/rest/Tests/All
        sql/backends/monet5/rest/rest_jsonstore_handle_get.c
Branch: default
Log Message:

add deleted field and new set of tests


diffs (truncated from 468 to 300 lines):

diff --git a/sql/backends/monet5/rest/Tests/All 
b/sql/backends/monet5/rest/Tests/All
--- a/sql/backends/monet5/rest/Tests/All
+++ b/sql/backends/monet5/rest/Tests/All
@@ -1,1 +1,2 @@
 jsonstore00
+jsonstore01
diff --git a/sql/backends/monet5/rest/Tests/jsonstore01.sql 
b/sql/backends/monet5/rest/Tests/jsonstore01.sql
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/rest/Tests/jsonstore01.sql
@@ -0,0 +1,123 @@
+CREATE TABLE json_first (
+  _id uuid, _rev VARCHAR(34),
+  deleted BOOLEAN,
+  js json);
+
+CREATE FUNCTION first_update_doc
+( doc_id VARCHAR(36),
+  doc json )
+  RETURNS TABLE ( OK BOOLEAN )
+BEGIN
+ DECLARE ISNEW INTEGER;
+ DECLARE VERSION INT;
+ DECLARE NEWVER VARCHAR(6);
+ SET ISNEW = (SELECT
+  COUNT(*) FROM json_first
+  WHERE _id = doc_id);
+   IF (ISNEW = 0) THEN
+    SET NEWVER = '1';
+   ELSE
+    SET VERSION = (
+     SELECT MAX(
+      CAST(
+       SUBSTRING(_rev,
+        1,POSITION('-'
+         IN _rev) - 1)
+       AS INT) + 1)
+     FROM json_first
+     WHERE _id =
+      doc_id);
+     SET NEWVER =
+      CAST(VERSION AS
+       VARCHAR(6));
+   END IF;
+  INSERT INTO json_first (
+   _id, _rev, deleted, js )
+  VALUES ( doc_id,
+   CONCAT(NEWVER,
+    CONCAT('-',
+     md5(doc))),
+   FALSE,
+   doc );
+  RETURN
+   SELECT TRUE;
+END;
+
+INSERT INTO json_first (_id, _rev, deleted, js)
+VALUES ('4b5b0c91-61f3-46db-b279-1535c8e2bd41', concat('1-', md5('{}')), 
FALSE, '{}');
+
+SELECT * FROM json_first;
+
+WITH curr_first(maxrev, _id) AS (
+  SELECT MAX(CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS INT)), 
+         _id
+  FROM json_first
+  GROUP BY _id)
+SELECT json_first._id,
+       json_first._rev,
+       json_first.js
+FROM curr_first,
+     json_first
+WHERE curr_first._id = json_first._id
+AND json_first.deleted = FALSE
+AND curr_first.maxrev = CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS 
INT);
+
+SELECT * FROM json_first WHERE _id = '4b5b0c91-61f3-46db-b279-1535c8e2bd41';
+
+WITH curr_first(maxrev, _id) AS (
+  SELECT MAX(CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS INT)), 
+         _id
+  FROM json_first
+  WHERE _id = '4b5b0c91-61f3-46db-b279-1535c8e2bd41'
+  GROUP BY _id)
+SELECT json_first._id,
+       json_first._rev,
+       json_first.js
+FROM curr_first,
+     json_first
+WHERE curr_first._id = json_first._id
+AND json_first.deleted = FALSE
+AND curr_first.maxrev = CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS 
INT);
+
+SELECT * FROM first_update_doc ('4b5b0c91-61f3-46db-b279-1535c8e2bd41', 
'{"message":"hello world"}');
+
+INSERT INTO json_first (_id, _rev, deleted, js) 
+VALUES ('4b5b0c91-61f3-46db-b279-1535c8e2bd42', concat('1-', md5('{}')), 
FALSE, '{}');
+
+UPDATE json_first SET deleted = TRUE WHERE _id = 
'4b5b0c91-61f3-46db-b279-1535c8e2bd41';
+
+SELECT * FROM json_first;
+
+WITH curr_first(maxrev, _id) AS (
+  SELECT MAX(CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS INT)), 
+         _id
+  FROM json_first
+  GROUP BY _id) 
+SELECT json_first._id, 
+       json_first._rev, 
+       json_first.js 
+FROM curr_first, 
+     json_first
+WHERE curr_first._id = json_first._id
+AND json_first.deleted = FALSE
+AND curr_first.maxrev = CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS 
INT);
+
+SELECT * FROM json_first WHERE _id = '4b5b0c91-61f3-46db-b279-1535c8e2bd41';
+
+WITH curr_first(maxrev, _id) AS (
+  SELECT MAX(CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS INT)), 
+         _id
+  FROM json_first
+  WHERE _id = '4b5b0c91-61f3-46db-b279-1535c8e2bd41'
+  GROUP BY _id) 
+SELECT json_first._id, 
+       json_first._rev, 
+       json_first.js 
+FROM curr_first, 
+     json_first
+WHERE curr_first._id = json_first._id
+AND json_first.deleted = FALSE
+AND curr_first.maxrev = CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS 
INT);
+
+DROP FUNCTION first_update_doc;
+DROP TABLE json_first;
diff --git a/sql/backends/monet5/rest/Tests/jsonstore01.stable.err 
b/sql/backends/monet5/rest/Tests/jsonstore01.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/rest/Tests/jsonstore01.stable.err
@@ -0,0 +1,35 @@
+stderr of test 'jsonstore01` in directory 'sql/backends/monet5/rest` itself:
+
+
+# 14:35:29 >  
+# 14:35:29 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=36192" "--set" 
"mapi_usock=/var/tmp/mtest-4657/.s.monetdb.36192" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/export/scratch2/rijke/monetdb/default/var/MonetDB/mTests_sql_backends_monet5_rest"
 "--set" "mal_listing=0"
+# 14:35:29 >  
+
+# builtin opt  gdk_dbpath = 
/export/scratch2/rijke/monetdb/default/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 = 36192
+# cmdline opt  mapi_usock = /var/tmp/mtest-4657/.s.monetdb.36192
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbpath = 
/export/scratch2/rijke/monetdb/default/var/MonetDB/mTests_sql_backends_monet5_rest
+# cmdline opt  mal_listing = 0
+
+# 14:35:29 >  
+# 14:35:29 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-4657" "--port=36192"
+# 14:35:29 >  
+
+
+# 14:35:30 >  
+# 14:35:30 >  "Done."
+# 14:35:30 >  
+
diff --git a/sql/backends/monet5/rest/Tests/jsonstore01.stable.out 
b/sql/backends/monet5/rest/Tests/jsonstore01.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/rest/Tests/jsonstore01.stable.out
@@ -0,0 +1,177 @@
+stdout of test 'jsonstore01` in directory 'sql/backends/monet5/rest` itself:
+
+
+# 14:35:29 >  
+# 14:35:29 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=36192" "--set" 
"mapi_usock=/var/tmp/mtest-4657/.s.monetdb.36192" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/export/scratch2/rijke/monetdb/default/var/MonetDB/mTests_sql_backends_monet5_rest"
 "--set" "mal_listing=0"
+# 14:35:29 >  
+
+# MonetDB 5 server v11.16.0
+# This is an unreleased version
+# Serving database 'mTests_sql_backends_monet5_rest', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically 
linked
+# Found 15.592 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://rotterdam.ins.cwi.nl:36192/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-4657/.s.monetdb.36192
+# MonetDB/GIS module loaded
+# MonetDB/JAQL module loaded
+# MonetDB/SQL module loaded
+
+Ready.
+
+# 14:35:29 >  
+# 14:35:29 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-4657" "--port=36192"
+# 14:35:29 >  
+
+#CREATE TABLE json_first (
+#  _id uuid, _rev VARCHAR(34),
+#  deleted BOOLEAN,
+#  js json);
+#CREATE FUNCTION first_update_doc
+#( doc_id VARCHAR(36),
+#  doc json )
+#  RETURNS TABLE ( OK BOOLEAN )
+#BEGIN
+# DECLARE ISNEW INTEGER;
+# DECLARE VERSION INT;
+# DECLARE NEWVER VARCHAR(6);
+# SET ISNEW = (SELECT
+#  COUNT(*) FROM json_first
+#  WHERE _id = doc_id);
+#   IF (ISNEW = 0) THEN
+#    SET NEWVER = '1';
+#   ELSE
+#    SET VERSION = (
+#     SELECT MAX(
+#      CAST(
+#       SUBSTRING(_rev,
+#        1,POSITION('-'
+#         IN _rev) - 1)
+#       AS INT) + 1)
+#     FROM json_first
+#     WHERE _id =
+#      doc_id);
+#     SET NEWVER =
+#INSERT INTO json_first (_id, _rev, deleted, js)
+#VALUES ('4b5b0c91-61f3-46db-b279-1535c8e2bd41', concat('1-', md5('{}')), 
FALSE, '{}');
+[ 1    ]
+#SELECT * FROM json_first;
+% sys.json_first,      sys.json_first, sys.json_first, sys.json_first # 
table_name
+% _id, _rev,   deleted,        js # name
+% uuid,        varchar,        boolean,        json # type
+% 36,  34,     5,      2 # length
+[ 4b5b0c91-61f3-46db-b279-1535c8e2bd41,        
"1-99914b932bd37a50b983c5e7c90ae93b",   false,  "{}"    ]
+#WITH curr_first(maxrev, _id) AS (
+#  SELECT MAX(CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS INT)), 
+#         _id
+#  FROM json_first
+#  GROUP BY _id)
+#SELECT json_first._id,
+#       json_first._rev,
+#       json_first.js
+#FROM curr_first,
+#     json_first
+#WHERE curr_first._id = json_first._id
+#AND json_first.deleted = FALSE
+#AND curr_first.maxrev = CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS 
INT);
+% sys.json_first,      sys.json_first, sys.json_first # table_name
+% _id, _rev,   js # name
+% uuid,        varchar,        json # type
+% 36,  34,     2 # length
+[ 4b5b0c91-61f3-46db-b279-1535c8e2bd41,        
"1-99914b932bd37a50b983c5e7c90ae93b",   "{}"    ]
+#SELECT * FROM json_first WHERE _id = '4b5b0c91-61f3-46db-b279-1535c8e2bd41';
+% sys.json_first,      sys.json_first, sys.json_first, sys.json_first # 
table_name
+% _id, _rev,   deleted,        js # name
+% uuid,        varchar,        boolean,        json # type
+% 36,  34,     5,      2 # length
+[ 4b5b0c91-61f3-46db-b279-1535c8e2bd41,        
"1-99914b932bd37a50b983c5e7c90ae93b",   false,  "{}"    ]
+#WITH curr_first(maxrev, _id) AS (
+#  SELECT MAX(CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS INT)), 
+#         _id
+#  FROM json_first
+#  WHERE _id = '4b5b0c91-61f3-46db-b279-1535c8e2bd41'
+#  GROUP BY _id)
+#SELECT json_first._id,
+#       json_first._rev,
+#       json_first.js
+#FROM curr_first,
+#     json_first
+#WHERE curr_first._id = json_first._id
+#AND json_first.deleted = FALSE
+#AND curr_first.maxrev = CAST(SUBSTRING(_rev,1,POSITION('-' IN _rev) - 1) AS 
INT);
+% sys.json_first,      sys.json_first, sys.json_first # table_name
+% _id, _rev,   js # name
+% uuid,        varchar,        json # type
+% 36,  34,     2 # length
+[ 4b5b0c91-61f3-46db-b279-1535c8e2bd41,        
"1-99914b932bd37a50b983c5e7c90ae93b",   "{}"    ]
+#SELECT * FROM first_update_doc ('4b5b0c91-61f3-46db-b279-1535c8e2bd41', 
'{"message":"hello world"}');
+% . # table_name
+% ok # name
+% boolean # type
+% 5 # length
+[ true ]
+#INSERT INTO json_first (_id, _rev, deleted, js) 
+#VALUES ('4b5b0c91-61f3-46db-b279-1535c8e2bd42', concat('1-', md5('{}')), 
FALSE, '{}');
+[ 1    ]
+#UPDATE json_first SET deleted = TRUE WHERE _id = 
'4b5b0c91-61f3-46db-b279-1535c8e2bd41';
+[ 2    ]
+#SELECT * FROM json_first;
+% sys.json_first,      sys.json_first, sys.json_first, sys.json_first # 
table_name
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to