Changeset: 9384239abf77 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9384239abf77
Modified Files:
monetdb5/extras/pyapi/Makefile.ag
monetdb5/extras/pyapi/formatinput.c
monetdb5/extras/pyapi/pyapi.c
Branch: pyapi
Log Message:
Allow users to use loopback queries (query MonetDB from within MonetDB/Python).
diffs (105 lines):
diff --git a/monetdb5/extras/pyapi/Makefile.ag
b/monetdb5/extras/pyapi/Makefile.ag
--- a/monetdb5/extras/pyapi/Makefile.ag
+++ b/monetdb5/extras/pyapi/Makefile.ag
@@ -5,11 +5,18 @@
# Copyright 2008-2015 MonetDB B.V.
INCLUDES = \
+ ../../../clients/mapilib \
../../../common/options \
../../../common/stream \
+ ../../modules/atoms \
+ ../../modules/mal \
../../../gdk \
../../mal \
+ ../../../sql/backends/monet5 \
+ ../../../sql/common \
../../../sql/include \
+ ../../../sql/server \
+ ../../../sql/storage \
$(libpy_CFLAGS)
MTSAFE
@@ -17,10 +24,10 @@ MTSAFE
lib__pyapi = {
MODULE
DIR = libdir/monetdb5
- SOURCES = pyapi.c pyapi.h unicode.c unicode.h pytypes.c pytypes.h
type_conversion.c type_conversion.h bytearray.c bytearray.h formatinput.c
formatinput.h benchmark.c benchmark.h lazyarray.c lazyarray.h
+ SOURCES = pyapi.c pyapi.h unicode.c unicode.h pytypes.c pytypes.h
type_conversion.c type_conversion.h bytearray.c bytearray.h formatinput.c
formatinput.h benchmark.c benchmark.h lazyarray.c lazyarray.h connection.c
connection.h
XDEPS = $(libpy_LIBDEP)
LIBS = ../../tools/libmonetdb5 \
- ../../../gdk/libbat \
+ ../../../gdk/libbat \
$(MALLOC_LIBS) $(libpy_LIBS)
}
diff --git a/monetdb5/extras/pyapi/formatinput.c
b/monetdb5/extras/pyapi/formatinput.c
--- a/monetdb5/extras/pyapi/formatinput.c
+++ b/monetdb5/extras/pyapi/formatinput.c
@@ -10,8 +10,8 @@
#include "gdk.h"
#include "mal_exception.h"
-const size_t additional_argcount = 3;
-const char * additional_args[] = {"_columns", "_column_types", "_values"};
+const size_t additional_argcount = 4;
+const char * additional_args[] = {"_columns", "_column_types", "_values",
"_conn"};
//! Parse a PyCodeObject from a string, the string is expected to be in the
format {@<encoded_function>};, where <encoded_function> is all the PyCodeObject
properties in order
PyObject *PyCodeObject_ParseString(char *string, char **msg);
diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c
--- a/monetdb5/extras/pyapi/pyapi.c
+++ b/monetdb5/extras/pyapi/pyapi.c
@@ -14,6 +14,7 @@
#include "gdk.h"
#include "sql_catalog.h"
#include "pyapi.h"
+#include "connection.h"
// Python library
#undef _GNU_SOURCE
@@ -406,7 +407,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
BAT *b = NULL;
node * argnode;
int seengrp = FALSE;
- PyObject *pArgs = NULL, *pColumns = NULL, *pColumnTypes = NULL, *pDict =
NULL, *pResult = NULL; // this is going to be the parameter tuple
+ PyObject *pArgs = NULL, *pColumns = NULL, *pColumnTypes = NULL,
*pConnection, *pDict = NULL, *pResult = NULL; // this is going to be the
parameter tuple
PyObject *code_object = NULL;
PyReturn *pyreturn_values = NULL;
PyInput *pyinput_values = NULL;
@@ -710,9 +711,10 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
// Now we will do the input handling (aka converting the input BATs to
numpy arrays)
// We will put the python arrays in a PyTuple object, we will use this
PyTuple object as the set of arguments to call the Python function
- pArgs = PyTuple_New(pci->argc - (pci->retc + 2) + (code_object == NULL ? 3
: 0));
+ pArgs = PyTuple_New(pci->argc - (pci->retc + 2) + (code_object == NULL ? 4
: 0));
pColumns = PyDict_New();
pColumnTypes = PyDict_New();
+ pConnection = Py_Connection_Create(cntxt);
pDict = GetDictionary(cntxt);
// Now we will loop over the input BATs and convert them to python objects
@@ -754,6 +756,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
PyTuple_SetItem(pArgs, ai++, pColumns);
PyTuple_SetItem(pArgs, ai++, pColumnTypes);
PyTuple_SetItem(pArgs, ai++, pDict);
+ PyTuple_SetItem(pArgs, ai++, pConnection);
Py_INCREF(pDict);
}
@@ -818,6 +821,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
Py_DECREF(pArgs);
Py_DECREF(pColumns);
Py_DECREF(pColumnTypes);
+ Py_DECREF(pConnection);
if (PyErr_Occurred()) {
msg = PyError_CreateException("Python exception", pycall);
@@ -1162,6 +1166,7 @@ str
import_array1(iar);
initialize_shared_memory();
lazyarray_init();
+ _connection_init();
PyEval_SaveThread();
pyapiInitialized++;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list