Changeset: 2e0a466bf36c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2e0a466bf36c
Branch: default
Log Message:

Merge with monetdbe-proxy.


diffs (truncated from 3257 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
@@ -9114,13 +9114,14 @@ stdout of test 'MAL-signatures` in direc
 [ "remote",    "batbincopy",   "pattern remote.batbincopy(X_1:bat[:any]):void 
",       "RMTbincopyto;",        ""      ]
 [ "remote",    "batload",      "pattern remote.batload(X_1:any_1, 
X_2:int):bat[:any_1] ",      "RMTbatload;",  ""      ]
 [ "remote",    "bintype",      "pattern remote.bintype():void ",       
"RMTbintype;",  ""      ]
-[ "remote",    "connect",      "command remote.connect(X_1:str, X_2:str, 
X_3:str):str ",       "RMTconnect;",  ""      ]
-[ "remote",    "connect",      "command remote.connect(X_1:str, X_2:str, 
X_3:str, X_4:str):str ",      "RMTconnectScen;",      ""      ]
+[ "remote",    "connect",      "command remote.connect(X_1:str, X_2:str, 
X_3:str, X_4:str):str ",      "RMTconnect;",  ""      ]
+[ "remote",    "connect",      "command remote.connect(X_1:str, X_2:str, 
X_3:str, X_4:str, X_5:bit):str ",     "RMTconnectScen;",      ""      ]
 [ "remote",    "connect",      "pattern remote.connect(X_1:str, X_2:str):str 
",        "RMTconnectTable;",     ""      ]
 [ "remote",    "disconnect",   "command remote.disconnect(X_1:str):void ",     
"RMTdisconnect;",       ""      ]
 [ "remote",    "epilogue",     "command remote.epilogue():void ",      
"RMTepilogue;", ""      ]
 [ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str):str ",  
"RMTexec;",     ""      ]
 [ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str):str... 
",       "RMTexec;",     ""      ]
+[ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str, 
X_4:ptr, X_5:str...):void ",    "RMTexec;",     ""      ]
 [ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str, 
X_4:str...):str ",      "RMTexec;",     ""      ]
 [ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str, 
X_4:str...):str... ",   "RMTexec;",     ""      ]
 [ "remote",    "get",  "pattern remote.get(X_1:str, X_2:str):any ",    
"RMTget;",      ""      ]
@@ -9308,6 +9309,7 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "rt_credentials",       "pattern sql.rt_credentials(X_3:str) 
(X_0:bat[:str], X_1:bat[:str], X_2:bat[:str]) ",   "sql_rt_credentials_wrap;",  
   ""      ]
 [ "sql",       "sessions",     "pattern sql.sessions() (X_0:bat[:int], 
X_1:bat[:str], X_2:bat[:timestamp], X_3:bat[:timestamp], X_4:bat[:str], 
X_5:bat[:int], X_6:bat[:int], X_7:bat[:int], X_8:bat[:int]) ",  
"sql_sessions_wrap;",   ""      ]
 [ "sql",       "setVariable",  "unsafe pattern sql.setVariable(X_1:int, 
X_2:str, X_3:str, X_4:any_1):int ",    "setVariable;", ""      ]
+[ "sql",       "set_protocol", "unsafe pattern sql.set_protocol(X_1:int):int 
",        "SQLset_protocol;",     ""      ]
 [ "sql",       "setmemorylimit",       "unsafe pattern 
sql.setmemorylimit(X_1:int):void ",     "SQLsetmemorylimit;",   ""      ]
 [ "sql",       "setmemorylimit",       "unsafe pattern 
sql.setmemorylimit(X_1:sht, X_2:int):void ",    "SQLsetmemorylimit;",   ""      
]
 [ "sql",       "setoptimizer", "unsafe pattern sql.setoptimizer(X_1:int, 
X_2:str):void ",      "SQLsetoptimizer;",     ""      ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -12455,13 +12455,14 @@ stdout of test 'MAL-signatures` in direc
 [ "remote",    "batbincopy",   "pattern remote.batbincopy(X_1:bat[:any]):void 
",       "RMTbincopyto;",        ""      ]
 [ "remote",    "batload",      "pattern remote.batload(X_1:any_1, 
X_2:int):bat[:any_1] ",      "RMTbatload;",  ""      ]
 [ "remote",    "bintype",      "pattern remote.bintype():void ",       
"RMTbintype;",  ""      ]
-[ "remote",    "connect",      "command remote.connect(X_1:str, X_2:str, 
X_3:str):str ",       "RMTconnect;",  ""      ]
-[ "remote",    "connect",      "command remote.connect(X_1:str, X_2:str, 
X_3:str, X_4:str):str ",      "RMTconnectScen;",      ""      ]
+[ "remote",    "connect",      "command remote.connect(X_1:str, X_2:str, 
X_3:str, X_4:str):str ",      "RMTconnect;",  ""      ]
+[ "remote",    "connect",      "command remote.connect(X_1:str, X_2:str, 
X_3:str, X_4:str, X_5:bit):str ",     "RMTconnectScen;",      ""      ]
 [ "remote",    "connect",      "pattern remote.connect(X_1:str, X_2:str):str 
",        "RMTconnectTable;",     ""      ]
 [ "remote",    "disconnect",   "command remote.disconnect(X_1:str):void ",     
"RMTdisconnect;",       ""      ]
 [ "remote",    "epilogue",     "command remote.epilogue():void ",      
"RMTepilogue;", ""      ]
 [ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str):str ",  
"RMTexec;",     ""      ]
 [ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str):str... 
",       "RMTexec;",     ""      ]
+[ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str, 
X_4:ptr, X_5:str...):void ",    "RMTexec;",     ""      ]
 [ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str, 
X_4:str...):str ",      "RMTexec;",     ""      ]
 [ "remote",    "exec", "pattern remote.exec(X_1:str, X_2:str, X_3:str, 
X_4:str...):str... ",   "RMTexec;",     ""      ]
 [ "remote",    "get",  "pattern remote.get(X_1:str, X_2:str):any ",    
"RMTget;",      ""      ]
@@ -12661,6 +12662,7 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "rt_credentials",       "pattern sql.rt_credentials(X_3:str) 
(X_0:bat[:str], X_1:bat[:str], X_2:bat[:str]) ",   "sql_rt_credentials_wrap;",  
   ""      ]
 [ "sql",       "sessions",     "pattern sql.sessions() (X_0:bat[:int], 
X_1:bat[:str], X_2:bat[:timestamp], X_3:bat[:timestamp], X_4:bat[:str], 
X_5:bat[:int], X_6:bat[:int], X_7:bat[:int], X_8:bat[:int]) ",  
"sql_sessions_wrap;",   ""      ]
 [ "sql",       "setVariable",  "unsafe pattern sql.setVariable(X_1:int, 
X_2:str, X_3:str, X_4:any_1):int ",    "setVariable;", ""      ]
+[ "sql",       "set_protocol", "unsafe pattern sql.set_protocol(X_1:int):int 
",        "SQLset_protocol;",     ""      ]
 [ "sql",       "setmemorylimit",       "unsafe pattern 
sql.setmemorylimit(X_1:int):void ",     "SQLsetmemorylimit;",   ""      ]
 [ "sql",       "setmemorylimit",       "unsafe pattern 
sql.setmemorylimit(X_1:sht, X_2:int):void ",    "SQLsetmemorylimit;",   ""      
]
 [ "sql",       "setoptimizer", "unsafe pattern sql.setoptimizer(X_1:int, 
X_2:str):void ",      "SQLsetoptimizer;",     ""      ]
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
@@ -602,6 +602,7 @@ int mapi_fetch_row(MapiHdl hdl) __attrib
 MapiMsg mapi_finish(MapiHdl hdl) __attribute__((__nonnull__(1)));
 MapiHdl mapi_get_active(Mapi mid) __attribute__((__nonnull__(1)));
 bool mapi_get_autocommit(Mapi mid) __attribute__((__nonnull__(1)));
+bool mapi_get_columnar_protocol(Mapi mid) __attribute__((__nonnull__(1)));
 const char *mapi_get_dbname(Mapi mid) __attribute__((__nonnull__(1)));
 int mapi_get_digits(MapiHdl hdl, int fnr) __attribute__((__nonnull__(1)));
 int mapi_get_field_count(MapiHdl hdl) __attribute__((__nonnull__(1)));
@@ -660,9 +661,11 @@ int64_t mapi_rows_affected(MapiHdl hdl) 
 MapiMsg mapi_seek_row(MapiHdl hdl, int64_t rowne, int whence) 
__attribute__((__nonnull__(1)));
 MapiHdl mapi_send(Mapi mid, const char *cmd) __attribute__((__nonnull__(1)));
 MapiMsg mapi_setAutocommit(Mapi mid, bool autocommit) 
__attribute__((__nonnull__(1)));
+MapiMsg mapi_set_columnar_protocol(Mapi mid, bool columnar_protocol) 
__attribute__((__nonnull__(1)));
 MapiMsg mapi_set_size_header(Mapi mid, bool value) 
__attribute__((__nonnull__(1)));
 void mapi_setfilecallback(Mapi mid, char *(*getfunc)(void *priv, const char 
*filename, bool binary, uint64_t offset, size_t *size), char *(*putfunc)(void 
*priv, const char *filename, const void *data, size_t size), void *priv) 
__attribute__((__nonnull__(1)));
 int mapi_split_line(MapiHdl hdl) __attribute__((__nonnull__(1)));
+
 MapiMsg mapi_store_field(MapiHdl hdl, int fnr, int outtype, void *outparam) 
__attribute__((__nonnull__(1)));
 MapiMsg mapi_timeout(Mapi mid, unsigned int time) 
__attribute__((__nonnull__(1)));
 void mapi_trace(Mapi mid, bool flag) __attribute__((__nonnull__(1)));
@@ -949,6 +952,7 @@ int QLOGisset(void);
 str QLOGissetFcn(int *ret);
 str QOToptimize(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 QueryQueue QRYqueue;
+str RMTdisconnect(void *ret, str *conn);
 str SERVERbindBAT(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str SERVERclient(void *res, const Stream *In, const Stream *Out);
 str SERVERconnect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pc);
@@ -1623,6 +1627,7 @@ str setVariableRef;
 void setVariableScope(MalBlkPtr mb);
 void setVariableType(MalBlkPtr mb, const int idx, malType type);
 str setWriteModeRef;
+str set_protocolRef;
 void setprofilerlimit(int limit);
 void showAllScenarios(stream *f);
 void showCurrentScenario(void);
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -13,6 +13,37 @@
 #include <unistd.h>
 #include <string.h>
 #include <ctype.h>
+
+// TODO get rid of this ugly work around: Properly factor out mapi cals from 
dump.c
+#ifdef COMPILING_MONETDBE
+
+#define Mapi monetdbe_Mapi
+#define MapiHdl monetdbe_MapiHdl
+#define MapiHdl monetdbe_MapiHdl
+#define MapiMsg monetdbe_MapiMsg
+
+#define mapi_error monetdbe_mapi_error
+#define mapi_query monetdbe_mapi_query
+#define mapi_error monetdbe_mapi_error
+#define mapi_close_handle monetdbe_mapi_close_handle
+#define mapi_fetch_row monetdbe_mapi_fetch_row
+#define mapi_fetch_field monetdbe_mapi_fetch_field
+#define mapi_get_type monetdbe_mapi_get_type
+#define mapi_seek_row monetdbe_mapi_seek_row
+#define mapi_get_row_count monetdbe_mapi_get_row_count
+#define mapi_rows_affected monetdbe_mapi_rows_affected
+#define mapi_get_field_count monetdbe_mapi_get_field_count
+#define mapi_result_error monetdbe_mapi_result_error
+#define mapi_get_len monetdbe_mapi_get_len
+#define mapi_explain monetdbe_mapi_explain
+#define mapi_explain_query monetdbe_mapi_explain_query
+#define mapi_explain_result monetdbe_mapi_explain_result
+
+#include "monetdbe_mapi.h"
+#else
+#include "mapi.h"
+#endif
+
 #include "msqldump.h"
 
 static const char *
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -880,6 +880,7 @@ struct MapiStruct {
        bool connected;
        bool trace;             /* Trace Mapi interaction */
        bool auto_commit;
+       bool columnar_protocol;
        MapiHdl first;          /* start of doubly-linked list */
        MapiHdl active;         /* set when not all rows have been received */
 
@@ -1371,6 +1372,13 @@ mapi_get_autocommit(Mapi mid)
        return mid->auto_commit;
 }
 
+bool
+mapi_get_columnar_protocol(Mapi mid)
+{
+       mapi_check0(mid);
+       return mid->columnar_protocol;
+}
+
 static int64_t
 usec(void)
 {
@@ -3633,6 +3641,18 @@ mapi_setAutocommit(Mapi mid, bool autoco
 }
 
 MapiMsg
+mapi_set_columnar_protocol(Mapi mid, bool columnar_protocol)
+{
+       if (mid->columnar_protocol == columnar_protocol)
+               return MOK;
+       mid->columnar_protocol = columnar_protocol;
+       if (columnar_protocol)
+               return mapi_Xcommand(mid, "columnar_protocol", "1");
+       else
+               return mapi_Xcommand(mid, "columnar_protocol", "0");
+}
+
+MapiMsg
 mapi_set_size_header(Mapi mid, bool value)
 {
        if (mid->languageId != LANG_SQL) {
diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -105,10 +105,14 @@ mapi_export bool mapi_get_trace(Mapi mid
        __attribute__((__nonnull__(1)));
 mapi_export bool mapi_get_autocommit(Mapi mid)
        __attribute__((__nonnull__(1)));
+mapi_export bool mapi_get_columnar_protocol(Mapi mid)
+       __attribute__((__nonnull__(1)));
 mapi_export MapiMsg mapi_log(Mapi mid, const char *nme)
        __attribute__((__nonnull__(1)));
 mapi_export MapiMsg mapi_setAutocommit(Mapi mid, bool autocommit)
        __attribute__((__nonnull__(1)));
+mapi_export MapiMsg mapi_set_columnar_protocol(Mapi mid, bool 
columnar_protocol)
+       __attribute__((__nonnull__(1)));
 mapi_export MapiMsg mapi_set_size_header(Mapi mid, bool value)
        __attribute__((__nonnull__(1)));
 mapi_export MapiMsg mapi_release_id(Mapi mid, int id)
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -232,7 +232,8 @@ stream_export stream *bs_stream(stream *
 typedef enum {
        PROTOCOL_AUTO = 0, // unused
        PROTOCOL_9 = 1, // mal_mapi.c, mal_client.c;
-       PROTOCOL_10 = 2 // mal_mapi.c, sql_result.c
+       PROTOCOL_10 = 2, // mal_mapi.c, sql_result.c
+       PROTOCOL_COLUMNAR = 3 // sql_result.c
 } protocol_version;
 
 typedef enum {
diff --git a/ctest/tools/monetdbe/CMakeLists.txt 
b/ctest/tools/monetdbe/CMakeLists.txt
--- a/ctest/tools/monetdbe/CMakeLists.txt
+++ b/ctest/tools/monetdbe/CMakeLists.txt
@@ -20,6 +20,12 @@ target_link_libraries(example2
     monetdbe)
 add_test(run_example2 example2)
 
+add_executable(example_proxy example_proxy.c)
+target_link_libraries(example_proxy
+  PRIVATE
+    monetdb_config_header
+    monetdbe)
+
 add_executable(example_temporal example_temporal.c)
 target_link_libraries(example_temporal
   PRIVATE
diff --git a/ctest/tools/monetdbe/example_proxy.c 
b/ctest/tools/monetdbe/example_proxy.c
new file mode 100644
--- /dev/null
+++ b/ctest/tools/monetdbe/example_proxy.c
@@ -0,0 +1,299 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V.
+ */
+
+#include "monetdbe.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <inttypes.h>
+
+#define error(msg) {fprintf(stderr, "Failure: %s\n", msg); return -1;}
+
+int
+main(void)
+{
+       char* err = NULL;
+       monetdbe_database mdbe = NULL;
+       monetdbe_result* result = NULL;
+
+    monetdbe_remote remote = {
+        .host = "127.0.0.1",
+        .port = 50001,
+        .username="monetdb",
+        .password="monetdb",
+        .lang="sql"};
+
+    monetdbe_options opt = {.remote = &remote};
+
+       // second argument is a string for the db directory or NULL for 
in-memory mode
+       if (monetdbe_open(&mdbe, 
"mapi:monetdb://127.0.0.1:50000?database=devdb", &opt))
+               error("Failed to open database")
+
+       if ((err = monetdbe_query(mdbe, "SELECT x, y, 1 AS some_int FROM test; 
", &result, NULL)) != NULL)
+               error(err)
+
+       fprintf(stdout, "Query result with %zu cols and %"PRId64" rows\n", 
result->ncols, result->nrows);
+       for (int64_t r = 0; r < result->nrows; r++) {
+               for (size_t c = 0; c < result->ncols; c++) {
+                       monetdbe_column* rcol;
+                       if ((err = monetdbe_result_fetch(result, &rcol, c)) != 
NULL)
+                               error(err)
+                       switch (rcol->type) {
+                               case monetdbe_int8_t: {
+                                       monetdbe_column_int8_t * col = 
(monetdbe_column_int8_t *) rcol;
+                                       if (col->data[r] == col->null_value) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%d", col->data[r]);
+                                       }
+                                       break;
+                               }
+                               case monetdbe_int16_t: {
+                                       monetdbe_column_int16_t * col = 
(monetdbe_column_int16_t *) rcol;
+                                       if (col->data[r] == col->null_value) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%d", col->data[r]);
+                                       }
+                                       break;
+                               }
+                               case monetdbe_int32_t: {
+                                       monetdbe_column_int32_t * col = 
(monetdbe_column_int32_t *) rcol;
+                                       if (col->data[r] == col->null_value) {
+                                               printf("NULL");
+                                       } else {
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to