Changeset: d44ce9912112 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d44ce9912112
Modified Files:
        sql/backends/monet5/Tests/All
        sql/backends/monet5/Tests/pyloader06.stable.out
        sql/backends/monet5/Tests/pyloader07.stable.out
        sql/backends/monet5/UDF/pyapi/emit.c
Branch: Dec2016
Log Message:

Correctly infer BAT type from value passed to Python Loader emit function.


diffs (62 lines):

diff --git a/sql/backends/monet5/Tests/All b/sql/backends/monet5/Tests/All
--- a/sql/backends/monet5/Tests/All
+++ b/sql/backends/monet5/Tests/All
@@ -61,6 +61,7 @@ HAVE_LIBPY?pyloader04
 HAVE_LIBPY?pyloader05
 HAVE_LIBPY?pyloader06
 HAVE_LIBPY?pyloader07
+HAVE_LIBPY?pyloader08
 
 # should this work?
 #inlineUDF
diff --git a/sql/backends/monet5/Tests/pyloader06.stable.out 
b/sql/backends/monet5/Tests/pyloader06.stable.out
--- a/sql/backends/monet5/Tests/pyloader06.stable.out
+++ b/sql/backends/monet5/Tests/pyloader06.stable.out
@@ -73,7 +73,7 @@ Ready.
 #SELECT * FROM pyloader06table;
 % sys.pyloader06table, sys.pyloader06table,    sys.pyloader06table # table_name
 % a,   c,      b # name
-% int, int,    int # type
+% bigint,      bigint, bigint # type
 % 1,   1,      1 # length
 [ 1,   3,      2       ]
 #ROLLBACK;
diff --git a/sql/backends/monet5/Tests/pyloader07.stable.out 
b/sql/backends/monet5/Tests/pyloader07.stable.out
--- a/sql/backends/monet5/Tests/pyloader07.stable.out
+++ b/sql/backends/monet5/Tests/pyloader07.stable.out
@@ -69,7 +69,7 @@ Ready.
 #SELECT * FROM pyloader07table;
 % sys.pyloader07table, sys.pyloader07table # table_name
 % s,   t # name
-% int, int # type
+% bigint,      bigint # type
 % 2,   2 # length
 [ 33,  42      ]
 #DROP TABLE pyloader07table;
diff --git a/sql/backends/monet5/UDF/pyapi/emit.c 
b/sql/backends/monet5/UDF/pyapi/emit.c
--- a/sql/backends/monet5/UDF/pyapi/emit.c
+++ b/sql/backends/monet5/UDF/pyapi/emit.c
@@ -155,7 +155,22 @@ PyEmit_Emit(PyEmitObject *self, PyObject
             }
             if (!found) {
                 // unrecognized column, create the column in the table
-                self->cols[self->ncols].b = COLnew(0, TYPE_int, 0, TRANSIENT);
+                // first infer the type from the value
+                // we use NumPy for this by creating an array from the object
+                // without specifying the type
+                PyObject* value = PyDict_GetItem(args, key);
+                PyObject* array = PyArray_FromAny(value, NULL, 0, 0, 
NPY_ARRAY_CARRAY | NPY_ARRAY_FORCECAST, NULL);
+                PyArray_Descr* array_type = NULL;
+                int bat_type = TYPE_int;
+                if (!array) {
+                    PyErr_Format(PyExc_TypeError, "Failed to create NumPy 
array.");
+                    return NULL;
+                }
+                array_type = (PyArray_Descr*) 
PyArray_DESCR((PyArrayObject*)array);
+                bat_type = PyType_ToBat(array_type->type_num);
+                Py_DECREF(array);
+
+                self->cols[self->ncols].b = COLnew(0, bat_type, 0, TRANSIENT);
                 self->cols[self->ncols].name = GDKstrdup(val);
                 if (self->nvals > 0) {
                     // insert NULL values up until the current entry
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to