Changeset: 1a83ea778949 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1a83ea778949
Modified Files:
monetdb5/modules/mal/Makefile.ag
monetdb5/modules/mal/mal_init.mal
monetdb5/optimizer/Makefile.ag
monetdb5/optimizer/opt_prelude.c
monetdb5/optimizer/opt_prelude.h
monetdb5/optimizer/opt_support.c
monetdb5/optimizer/opt_support.h
monetdb5/optimizer/opt_wrapper.c
monetdb5/optimizer/optimizer.mal
sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:
Json result rendering infrasstructure
-Add an optimizer to replace a single SQL json table into a sjon string
-Add the basics to pick a string result in SQLstatementIntern
(also useful for embedded MonetDB)
-Add the basics for the json triple store rendering
diffs (188 lines):
diff --git a/monetdb5/modules/mal/Makefile.ag b/monetdb5/modules/mal/Makefile.ag
--- a/monetdb5/modules/mal/Makefile.ag
+++ b/monetdb5/modules/mal/Makefile.ag
@@ -64,6 +64,7 @@ lib_mal = {
urlbox.c urlbox.h \
zorder.c zorder.h \
sample.c sample.h \
+ json_util.c json_util.h \
calc.c batcalc.c
}
@@ -79,14 +80,14 @@ headers_mal = {
mal_mapi.mal sabaoth.mal remote.mal \
txtsim.mal recycle.mal \
cluster.mal trader.mal \
- tokenizer.mal zorder.mal sample.mal \
+ tokenizer.mal zorder.mal json_util.mal \
calc.mal batcalc.mal batmtime.mal querylog.mal sysmon.mal
}
EXTRA_DIST = batExtensions.mal iterator.mal constraints.mal \
groupby.mal mal_init.mal manual.mal mkey.mal pcre.mal \
profiler.mal recycle.mal remote.mal sabaoth.mal trader.mal \
- transaction.mal txtsim.mal tablet.mal tablet.h sample.mal \
+ transaction.mal txtsim.mal tablet.mal tablet.h json_util.mal \
mal_mapi.mal mat.mal tokenizer.mal pqueue.mal calc.mal \
batcalc.mal batmtime.mal querylog.mal sysmon.mal
diff --git a/monetdb5/modules/mal/mal_init.mal
b/monetdb5/modules/mal/mal_init.mal
--- a/monetdb5/modules/mal/mal_init.mal
+++ b/monetdb5/modules/mal/mal_init.mal
@@ -61,8 +61,9 @@ include blob;
include color;
include str;
include url;
+include uuid;
include json_atom;
-include uuid;
+include json_util;
include mtime;
include inet;
include identifier;
diff --git a/monetdb5/optimizer/Makefile.ag b/monetdb5/optimizer/Makefile.ag
--- a/monetdb5/optimizer/Makefile.ag
+++ b/monetdb5/optimizer/Makefile.ag
@@ -51,6 +51,7 @@ lib_optimizer = {
opt_macro.c opt_macro.h \
opt_mapreduce.c opt_mapreduce.h \
opt_matpack.c opt_matpack.h \
+ opt_json.c opt_json.h \
opt_mergetable.c opt_mergetable.h \
opt_mitosis.c opt_mitosis.h \
opt_multiplex.c opt_multiplex.h \
diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c
--- a/monetdb5/optimizer/opt_prelude.c
+++ b/monetdb5/optimizer/opt_prelude.c
@@ -109,6 +109,7 @@ str ioRef;
str iteratorRef;
str joinRef;
str joinPathRef;
+str jsonRef;
str bandjoinRef;
str thetajoinRef;
str thetauselectRef;
@@ -375,6 +376,7 @@ void optimizerInit(void){
thetajoinRef = putName("thetajoin",9);
thetauselectRef = putName("thetauselect",12);
thetaselectRef = putName("thetaselect",11);
+ jsonRef = putName("json",4);
kdifferenceRef= putName("kdifference",11);
kunionRef= putName("kunion",6);
kuniqueRef= putName("kunique",7);
diff --git a/monetdb5/optimizer/opt_prelude.h b/monetdb5/optimizer/opt_prelude.h
--- a/monetdb5/optimizer/opt_prelude.h
+++ b/monetdb5/optimizer/opt_prelude.h
@@ -108,6 +108,7 @@ opt_export str ioRef;
opt_export str iteratorRef;
opt_export str joinRef;
opt_export str joinPathRef;
+opt_export str jsonRef;
opt_export str bandjoinRef;
opt_export str thetajoinRef;
opt_export str thetauselectRef;
diff --git a/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c
--- a/monetdb5/optimizer/opt_support.c
+++ b/monetdb5/optimizer/opt_support.c
@@ -162,6 +162,7 @@ struct OPTcatalog {
{"history", 0, 0, 0, DEBUG_OPT_HISTORY},
{"inline", 0, 0, 0, DEBUG_OPT_INLINE},
{"joinPath", 0, 0, 0, DEBUG_OPT_JOINPATH},
+{"json", 0, 0, 0, DEBUG_OPT_JSON},
{"macro", 0, 0, 0, DEBUG_OPT_MACRO},
{"mapreduce", 0, 0, 0, DEBUG_OPT_MAPREDUCE},
{"matpack", 0, 0, 0, DEBUG_OPT_MATPACK},
diff --git a/monetdb5/optimizer/opt_support.h b/monetdb5/optimizer/opt_support.h
--- a/monetdb5/optimizer/opt_support.h
+++ b/monetdb5/optimizer/opt_support.h
@@ -91,6 +91,7 @@
#define DEBUG_OPT_HEURISTIC 49
#define DEBUG_OPT_CENTIPEDE 50
#define DEBUG_OPT_PUSHSELECT 51
+#define DEBUG_OPT_JSON 54
#define DEBUG_OPT(X) ((lng) 1 << (X))
opt_export lng optDebug;
diff --git a/monetdb5/optimizer/opt_wrapper.c b/monetdb5/optimizer/opt_wrapper.c
--- a/monetdb5/optimizer/opt_wrapper.c
+++ b/monetdb5/optimizer/opt_wrapper.c
@@ -58,6 +58,7 @@ All Rights Reserved.
#include "opt_joinpath.h"
#include "opt_mapreduce.h"
#include "opt_matpack.h"
+#include "opt_json.h"
#include "opt_mergetable.h"
#include "opt_mitosis.h"
#include "opt_multiplex.h"
@@ -102,6 +103,7 @@ struct{
{"joinPath", &OPTjoinPathImplementation},
{"mapreduce", &OPTmapreduceImplementation},
{"matpack", &OPTmatpackImplementation},
+ {"json", &OPTjsonImplementation},
{"mergetable", &OPTmergetableImplementation},
{"mitosis", &OPTmitosisImplementation},
{"multiplex", &OPTmultiplexImplementation},
diff --git a/monetdb5/optimizer/optimizer.mal b/monetdb5/optimizer/optimizer.mal
--- a/monetdb5/optimizer/optimizer.mal
+++ b/monetdb5/optimizer/optimizer.mal
@@ -349,6 +349,13 @@ pattern optimizer.matpack(mod:str, fcn:s
address OPTwrapper
comment "Unroll the mat.pack operation";
+#opt_json
+pattern optimizer.json():str
+address OPTwrapper;
+pattern optimizer.json(mod:str, fcn:str):str
+address OPTwrapper
+comment "Unroll the mat.pack operation";
+
#opt_octopus.mal
module octopus;
pattern optimizer.octopus():str
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1171,11 +1171,32 @@ SQLstatementIntern(Client c, str *expr,
#endif
if ( execute) {
+ bstream *tmp=NULL;
+ buffer *b= (buffer*) GDKmalloc(sizeof(buffer));
+ MalBlkPtr mb = c->curprg->def;
+
if (!output)
sql->out = NULL; /* no output */
- msg = (str) runMAL(c, c->curprg->def, 0, 0);
- MSresetInstructions(c->curprg->def, oldstop);
- freeVariables(c,c->curprg->def, c->glb, oldvtop);
+
+ /* if the MAL program has been turned into a string
returing function
+ * then pick the result set from a scratch file (as is)
*/
+ if ( mb->var[0]->type == TYPE_str){
+ tmp = bstream_create(buffer_rastream(b,
"SQLoutput"), 0);
+ if ( tmp == NULL){
+ msg =
createException(SQL,"sql.eval","Can not create tmp file");
+ GDKfree(b);
+ goto noexecution;
+ }
+ //sql->out = tmp;
+ }
+ msg = (str) runMAL(c, mb, 0, 0);
+noexecution:
+ MSresetInstructions(mb, oldstop);
+ freeVariables(c, mb, c->glb, oldvtop);
+ if (msg == MAL_SUCCEED && tmp){
+ msg = GDKstrdup(b->buf);
+ (void) bstream_destroy(tmp);
+ }
}
sqlcleanup(m, 0);
if (!execute)
@@ -1185,7 +1206,6 @@ SQLstatementIntern(Client c, str *expr,
#endif
}
/*
- * @-
* We are done; a MAL procedure recides in the cache.
*/
endofcompile:
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list