From 31ca4b33dd1cbe9cf8dd6f692ac1f294acb2e5f4 Mon Sep 17 00:00:00 2001 From: Don Anderson Date: Wed, 6 Aug 2014 21:36:47 -0400 Subject: Add JSON loading to cursors and wt load utility. refs #740. Allow set_key and set_value on JSON cursors. The argument is a string that is interpreted as JSON and must match the format created by a JSON dump cursor or the 'wt dump -j' command. Add -j option to 'wt load' utility to allow loading JSON. Small adjustment to Python interface so that JSON cursor key/values inputs are always treated as strings. Added doc and Python tests for JSON cursors and wt load -j. --- lang/python/wiredtiger.i | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'lang') diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i index 0c228c56e5f..be55845a7b2 100644 --- a/lang/python/wiredtiger.i +++ b/lang/python/wiredtiger.i @@ -388,7 +388,9 @@ COMPARE_OK(__wt_cursor::search_near) %exception __wt_async_op::_set_key; %exception __wt_async_op::_set_value; %exception __wt_cursor::_set_key; +%exception __wt_cursor::_set_key_str; %exception __wt_cursor::_set_value; +%exception __wt_cursor::_set_value_str; %exception wiredtiger_strerror; %exception wiredtiger_version; @@ -577,6 +579,11 @@ typedef int int_void; $self->set_key($self, &k); } + /* Get / set keys and values */ + void _set_key_str(char *str) { + $self->set_key($self, str); + } + int_void _set_recno(uint64_t recno) { WT_ITEM k; uint8_t recno_buf[20]; @@ -601,6 +608,11 @@ typedef int int_void; $self->set_value($self, &v); } + /* Get / set keys and values */ + void _set_value_str(char *str) { + $self->set_value($self, str); + } + /* Don't return values, just throw exceptions on failure. */ int_void _get_key(char **datap, int *sizep) { WT_ITEM k; @@ -739,6 +751,8 @@ typedef int int_void; args = args[0] if self.is_column: self._set_recno(long(args[0])) + elif self.is_json: + self._set_key_str(args[0]) else: # Keep the Python string pinned self._key = pack(self.key_format, *args) @@ -748,11 +762,14 @@ typedef int int_void; '''set_value(self) -> None @copydoc WT_CURSOR::set_value''' - if len(args) == 1 and type(args[0]) == tuple: - args = args[0] - # Keep the Python string pinned - self._value = pack(self.value_format, *args) - self._set_value(self._value) + if self.is_json: + self._set_value_str(args[0]) + else: + if len(args) == 1 and type(args[0]) == tuple: + args = args[0] + # Keep the Python string pinned + self._value = pack(self.value_format, *args) + self._set_value(self._value) def __iter__(self): '''Cursor objects support iteration, equivalent to calling -- cgit v1.2.1 From 84be8984da331e0b67b0003eb67108ad34ba0bd5 Mon Sep 17 00:00:00 2001 From: Don Anderson Date: Mon, 6 Oct 2014 13:49:13 -0400 Subject: Multiple language doc support. refs #1130. doxfilter modified to know about new macros: @m_page, @m_if, @m_else, @m_endif. Pages with @m_page have all its snippets/subpages point to the language specific example/subpage. The java examples directory added to EXAMPLE_PATH in Doxyfile. Added @m_page to any doc page that also needs a Java version. Added cast to wiredtiger.i for stricter compiler checking. --- lang/java/wiredtiger.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lang') diff --git a/lang/java/wiredtiger.i b/lang/java/wiredtiger.i index fdcc0144508..71aed8b7866 100644 --- a/lang/java/wiredtiger.i +++ b/lang/java/wiredtiger.i @@ -127,7 +127,7 @@ static void throwWiredTigerException(JNIEnv *jenv, const char *msg) { %typemap(in) WT_ITEM * (WT_ITEM item) %{ $1 = &item; $1->data = (*jenv)->GetByteArrayElements(jenv, $input, 0); - $1->size = (*jenv)->GetArrayLength(jenv, $input); + $1->size = (size_t)(*jenv)->GetArrayLength(jenv, $input); %} %typemap(argout) WT_ITEM * %{ -- cgit v1.2.1 From 5c2c195438f899c07e9b041e139b5a95acc700a4 Mon Sep 17 00:00:00 2001 From: Michael Cahill Date: Mon, 13 Oct 2014 17:08:20 +1100 Subject: Make sure the Java examples are built along with the API. Make section names language-specific to avoid errors from newer releases of doxygen. --- lang/java/Makefile.am | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lang') diff --git a/lang/java/Makefile.am b/lang/java/Makefile.am index 29ef00a7842..0fcb1455c6e 100644 --- a/lang/java/Makefile.am +++ b/lang/java/Makefile.am @@ -29,7 +29,15 @@ JAVA_SRC = \ $(JAVADESTFULL)/wiredtiger.java \ $(JAVADESTFULL)/wiredtigerConstants.java \ $(JAVADESTFULL)/wiredtigerJNI.java \ - $(JAVAEXAMPLES)/ex_access.java + $(JAVAEXAMPLES)/ex_access.java \ + $(JAVAEXAMPLES)/ex_all.java \ + $(JAVAEXAMPLES)/ex_async.java \ + $(JAVAEXAMPLES)/ex_call_center.java \ + $(JAVAEXAMPLES)/ex_cursor.java \ + $(JAVAEXAMPLES)/ex_log.java \ + $(JAVAEXAMPLES)/ex_schema.java \ + $(JAVAEXAMPLES)/ex_stat.java \ + $(JAVAEXAMPLES)/ex_thread.java JAVA_JUNIT = \ $(JAVATEST)/AutoCloseTest.java \ -- cgit v1.2.1 From 0a2e70dc3064fdbbb8c72c96e444bedd4c74ae96 Mon Sep 17 00:00:00 2001 From: Michael Cahill Date: Sat, 18 Oct 2014 13:51:07 +1100 Subject: Allow Python tests to detect whether verbose support is configured. --- lang/python/wiredtiger.i | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lang') diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i index be55845a7b2..f9b76a352d3 100644 --- a/lang/python/wiredtiger.i +++ b/lang/python/wiredtiger.i @@ -807,6 +807,14 @@ typedef int int_void; return 1; %#else return 0; +%#endif + } + + int verbose_build() { +%#ifdef HAVE_VERBOSE + return 1; +%#else + return 0; %#endif } }; -- cgit v1.2.1 From 484c6ccd26ef2c5e5893cac00eaa5b627d4f4839 Mon Sep 17 00:00:00 2001 From: Michael Cahill Date: Sat, 18 Oct 2014 13:51:07 +1100 Subject: Add a "verbose=[transaction]" mode, output a message if a snapshot falls a long way behind. Add a test case that generates this message. Remember the last operation on a session after it leaves the library. --- lang/python/wiredtiger.i | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lang') diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i index f9b76a352d3..3573ce8c127 100644 --- a/lang/python/wiredtiger.i +++ b/lang/python/wiredtiger.i @@ -567,6 +567,12 @@ typedef int int_void; if self.search() != 0: raise KeyError return self.get_value() + + def __setitem__(self, key, value): + '''Python convenience for inserting''' + self.set_key(key) + self.set_key(value) + self.insert() %} }; -- cgit v1.2.1 From 5d55a2812130f2fbfb7046f3b376948959ce843e Mon Sep 17 00:00:00 2001 From: Michael Cahill Date: Sat, 18 Oct 2014 14:24:21 +1100 Subject: Fix the Python check for a verbose build: it can't be a connection method, that's too late. --- lang/python/wiredtiger.i | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'lang') diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i index 3573ce8c127..5e88855276a 100644 --- a/lang/python/wiredtiger.i +++ b/lang/python/wiredtiger.i @@ -381,7 +381,6 @@ COMPARE_OK(__wt_cursor::compare) COMPARE_OK(__wt_cursor::search_near) /* Lastly, some methods need no (additional) error checking. */ -%exception __wt_connection::diagnostic_build; %exception __wt_connection::get_home; %exception __wt_connection::is_new; %exception __wt_connection::search_near; @@ -393,6 +392,8 @@ COMPARE_OK(__wt_cursor::search_near) %exception __wt_cursor::_set_value_str; %exception wiredtiger_strerror; %exception wiredtiger_version; +%exception diagnostic_build; +%exception verbose_build; /* WT_ASYNC_OP customization. */ /* First, replace the varargs get / set methods with Python equivalents. */ @@ -807,23 +808,27 @@ typedef int int_void; int _freecb() { return (0); } +}; - int diagnostic_build() { -%#ifdef HAVE_DIAGNOSTIC - return 1; -%#else - return 0; -%#endif - } +%{ +int diagnostic_build() { +#ifdef HAVE_DIAGNOSTIC + return 1; +#else + return 0; +#endif +} - int verbose_build() { -%#ifdef HAVE_VERBOSE - return 1; -%#else - return 0; -%#endif - } -}; +int verbose_build() { +#ifdef HAVE_VERBOSE + return 1; +#else + return 0; +#endif +} +%} +int diagnostic_build(); +int verbose_build(); /* Remove / rename parts of the C API that we don't want in Python. */ %immutable __wt_cursor::session; -- cgit v1.2.1