Changeset: a07b07c51ebf for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a07b07c51ebf
Added Files:
        monetdb5/modules/mal/json_util.c
        monetdb5/modules/mal/json_util.h
        monetdb5/modules/mal/json_util.mal
Branch: default
Log Message:

Check in missing files.


diffs (155 lines):

diff --git a/monetdb5/modules/mal/json_util.c b/monetdb5/modules/mal/json_util.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/mal/json_util.c
@@ -0,0 +1,72 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/*
+ * (c) Martin Kersten
+ */
+
+#include "monetdb_config.h"
+#include <gdk.h>
+#include <mal_exception.h>
+#include "json_util.h"
+
+str
+JSONresultSet(str *res, bat *uuid, bat *rev, bat *js)
+{
+       BAT *bu, *br, *bj;
+       char *result;
+       size_t sz, len=0;
+
+       if ((bu = BATdescriptor(*uuid)) == NULL) 
+               throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
+       if ((br = BATdescriptor(*rev)) == NULL) {
+               BBPreleaseref(bu->batCacheid);
+               throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
+       }
+       if ((bj = BATdescriptor(*js)) == NULL) {
+               BBPreleaseref(bu->batCacheid);
+               BBPreleaseref(br->batCacheid);
+               throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
+       }
+       if ( !(BATcount(bu) == BATcount(br) && BATcount(br) == BATcount(bj)) ){
+               BBPreleaseref(bu->batCacheid);
+               BBPreleaseref(br->batCacheid);
+               BBPreleaseref(bj->batCacheid);
+               throw(MAL, "json.resultset", "Input not aligned");
+       }
+       sz= (22 + 12 + 20) * BATcount(bu);
+       result = (char*) GDKmalloc(sz);
+       if (result == NULL){
+               BBPreleaseref(bu->batCacheid);
+               BBPreleaseref(br->batCacheid);
+               BBPreleaseref(bj->batCacheid);
+               throw(MAL, "json.resultset", MAL_MALLOC_FAIL);
+       }
+       snprintf(result,sz,"[");
+       len += strlen(result);
+       /* here the dirty work follows */
+       /* loop over the triple store */
+       snprintf(result+len,sz-len,"]");
+       BBPreleaseref(bu->batCacheid);
+       BBPreleaseref(br->batCacheid);
+       BBPreleaseref(bj->batCacheid);
+       *res = result;
+       return MAL_SUCCEED;
+
+}
diff --git a/monetdb5/modules/mal/json_util.h b/monetdb5/modules/mal/json_util.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/mal/json_util.h
@@ -0,0 +1,42 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/*
+ * (c) Martin Kersten
+ */
+
+#ifndef _JSON_H_
+#define _JSON_H_
+
+/* #define _DEBUG_JSON_ */
+
+#ifdef WIN32
+#if !defined(LIBMAL) && !defined(LIBATOMS) && !defined(LIBKERNEL) && 
!defined(LIBMAL) && !defined(LIBOPTIMIZER) && !defined(LIBSCHEDULER) && 
!defined(LIBMONETDB5)
+#define json_export extern __declspec(dllimport)
+#else
+#define json_export extern __declspec(dllexport)
+#endif
+#else
+#define json_export extern
+#endif
+
+json_export str
+JSONresultSet(str *res,bat *u, bat *rev, bat *js);
+
+#endif
diff --git a/monetdb5/modules/mal/json_util.mal 
b/monetdb5/modules/mal/json_util.mal
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/mal/json_util.mal
@@ -0,0 +1,26 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2013 MonetDB B.V.
+# All Rights Reserved.
+
+#
+# @a Martin Kersten
+
+module json;
+
+command resultSet(u:bat[:oid,:uuid],rev:bat[:oid,:lng],js:bat[:oid,:json]):json
+address JSONresultSet
+comment "Converts the json store into a single json string:";
+
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to