Changeset: 391183393633 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/391183393633
Modified Files:
sql/backends/monet5/sql.c
sql/test/sysmon/vacuum/Tests/test_vacuum.SQL.py
Branch: default
Log Message:
Merge with Aug2024 branch.
diffs (192 lines):
diff --git a/.hgeol b/.hgeol
--- a/.hgeol
+++ b/.hgeol
@@ -14,6 +14,7 @@
**.ico = BIN
**.jpg = BIN
**.lz4 = BIN
+**.parquet = BIN
**.pdf = BIN
**.png = BIN
**.xz = BIN
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
@@ -84,6 +84,13 @@ target_link_libraries(example_connection
monetdbe)
add_test(run_example_connections example_connections)
+add_executable(example_sessions example_sessions.c)
+target_link_libraries(example_sessions
+ PRIVATE
+ monetdb_config_header
+ monetdbe)
+add_test(run_example_sessions example_sessions)
+
if(WITH_CMOCKA)
add_executable(cmocka_test cmocka_test.c test_helper.c)
target_include_directories(cmocka_test PRIVATE "${CMOCKA_INCLUDE_DIR}")
diff --git a/ctest/tools/monetdbe/example_sessions.c
b/ctest/tools/monetdbe/example_sessions.c
new file mode 100644
--- /dev/null
+++ b/ctest/tools/monetdbe/example_sessions.c
@@ -0,0 +1,75 @@
+/*
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * 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 2024 MonetDB Foundation;
+ * Copyright August 2008 - 2023 MonetDB B.V.;
+ * Copyright 1997 - July 2008 CWI.
+ */
+
+#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;
+
+ // second argument is a string for the db directory or NULL for
in-memory mode
+ if (monetdbe_open(&mdbe, NULL, NULL))
+ error("Failed to open database")
+ if ((err = monetdbe_query(mdbe, "SELECT * FROM sys.sessions", &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_int32_t: {
+ monetdbe_column_int32_t * col =
(monetdbe_column_int32_t *) rcol;
+ if (col->data[r] == col->null_value) {
+ printf("NULL");
+ } else {
+ printf("%d", col->data[r]);
+ }
+ break;
+ }
+ case monetdbe_str: {
+ monetdbe_column_str * col =
(monetdbe_column_str *) rcol;
+ if (col->is_null(col->data+r)) {
+ printf("NULL");
+ } else {
+ printf("%s", (char*)
col->data[r]);
+ }
+ break;
+ }
+ default: {
+ printf("UNKNOWN");
+ }
+ }
+
+ if (c + 1 < result->ncols) {
+ printf(", ");
+ }
+ }
+ printf("\n");
+ }
+
+ if ((err = monetdbe_cleanup_result(mdbe, result)) != NULL)
+ error(err)
+ if (monetdbe_close(mdbe))
+ error("Failed to close database")
+ return 0;
+}
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3719,7 +3719,10 @@ sql_sessions_wrap(Client cntxt, MalBlkPt
goto bailout;
if (BUNappend(mlimit, &c->memorylimit, false) != GDK_SUCCEED)
goto bailout;
- if (BUNappend(language, getScenarioLanguage(c), false) !=
GDK_SUCCEED)
+ // If the scenario is NULL we assume we're in monetdbe/e which
+ // is always SQL.
+ s = c->scenario ? getScenarioLanguage(c) : "sql";
+ if (BUNappend(language, s, false) != GDK_SUCCEED)
goto bailout;
s = c->peer ? c->peer : str_nil;
if (BUNappend(peer, s, false) != GDK_SUCCEED)
diff --git a/sql/test/sysmon/vacuum/Tests/test_vacuum.SQL.py
b/sql/test/sysmon/vacuum/Tests/test_vacuum.SQL.py
--- a/sql/test/sysmon/vacuum/Tests/test_vacuum.SQL.py
+++ b/sql/test/sysmon/vacuum/Tests/test_vacuum.SQL.py
@@ -20,8 +20,3 @@ with SQLTestCase() as tc:
#print(f'{heap_init}', file=sys.stderr)
#print(f'{heap_small} < {heap_large}', file=sys.stderr)
assert(heap_small < heap_large)
-
-
-
-
-
diff --git a/testing/sqltest.py b/testing/sqltest.py
--- a/testing/sqltest.py
+++ b/testing/sqltest.py
@@ -586,10 +586,12 @@ class SQLTestCase():
self.err_file = err_file
self.test_results = []
self._conn_ctx = None
+ self._conn_trash = []
self.in_memory = False
self.client = 'pymonetdb'
def __enter__(self):
+ self.connect()
return self
def __exit__(self, exc_type, exc_value, traceback):
@@ -599,6 +601,9 @@ class SQLTestCase():
if self._conn_ctx:
self._conn_ctx.close()
self._conn_ctx = None
+ for ctx in self._conn_trash:
+ ctx.close()
+ self._conn_trash = []
def exit(self):
self.close()
@@ -617,8 +622,9 @@ class SQLTestCase():
def connect(self,
username='monetdb', password='monetdb', port=MAPIPORT,
hostname='localhost', database=TSTDB, language='sql'):
- if self._conn_ctx:
- self.close()
+ old = self._conn_ctx
+ if old:
+ self._conn_trash.append(old)
if database == 'in-memory' \
or database == ':memory:': # backward compatibility
import monetdbe
@@ -634,17 +640,10 @@ class SQLTestCase():
port=port,
database=database or 'in-memory',
language=language)
- return self._conn_ctx
-
- def default_conn_ctx(self):
- if self.in_memory:
- return monetdbe.connect('in-memory', autocommit=True)
- ctx = PyMonetDBConnectionContext()
- return ctx
@property
def conn_ctx(self):
- return self._conn_ctx or self.default_conn_ctx()
+ return self._conn_ctx
def execute(self, query:str, *args, client='pymonetdb', stdin=None,
result_id=None):
'''Execute query with specified client. Default client is pymonetbd.'''
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]