Changeset: d88a02f096c1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d88a02f096c1
Added Files:
        sql/backends/monet5/Tests/pyapi12.sql
        sql/backends/monet5/Tests/pyapi12.stable.err
        sql/backends/monet5/Tests/pyapi12.stable.out
        sql/backends/monet5/Tests/rapi13.sql
        sql/backends/monet5/Tests/rapi13.stable.err
        sql/backends/monet5/Tests/rapi13.stable.out
Modified Files:
        monetdb5/extras/pyapi/pyapi.c
        sql/backends/monet5/Tests/pyapi08.sql
Branch: pyapi
Log Message:

Added some broken testcases.


diffs (truncated from 487 to 300 lines):

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
@@ -28,9 +28,11 @@
 #include "type_conversion.h"
 #include "shared_memory.h"
 
-#define _PYAPI_VERBOSE_
+//#define _PYAPI_VERBOSE_
 #define _PYAPI_DEBUG_
 
+bool memory_mapping = TRUE;
+
 #include <stdint.h>
 
 #include <stdio.h>
@@ -254,21 +256,22 @@ static int pyapiInitialized = FALSE;
             goto wrapup;                                                       
                                                                                
\
         }                                                                      
                                                                                
\
         data = (char*) ret->array_data;                                        
                                                                                
\
-        if (memory_mapping && TYPE_##mtpe == PyType_ToBat(ret->result_type) && 
(ret->count * ret->memory_size < BUN_MAX) &&                                    
\
+        if (memory_mapping && ret->count > 0 && TYPE_##mtpe == 
PyType_ToBat(ret->result_type) && (ret->count * ret->memory_size < BUN_MAX) &&  
                \
             (ret->numpy_array == NULL || PyArray_FLAGS(ret->numpy_array) & 
NPY_ARRAY_OWNDATA))                                                             
    \
         {                                                                      
                                                                                
\
             /*We can only create a direct map if the numpy array type and 
target BAT type*/                                                               
     \
             /*are identical, otherwise we have to do a conversion.*/           
                                                                                
\
+            assert(ret->array_data != NULL);                                   
                                                                                
\
             if (ret->numpy_array == NULL)                                      
                                                                                
\
             {                                                                  
                                                                                
\
                 /*shared memory return*/                                       
                                                                                
\
-                VERBOSE_MESSAGE("Shared memory map!\n");                       
                                                                                
\
+                VERBOSE_MESSAGE("- Shared memory map!\n");                     
                                                                                
\
                 BAT_MMAP(bat, mtpe, STORE_SHARED);                             
                                                                                
\
                 ret->array_data = NULL;                                        
                                                                                
\
             }                                                                  
                                                                                
\
             else                                                               
                                                                                
\
             {                                                                  
                                                                                
\
-                VERBOSE_MESSAGE("Memory map!\n");                              
                                                                                
\
+                VERBOSE_MESSAGE("- Memory map!\n");                            
                                                                                
\
                 BAT_MMAP(bat, mtpe, STORE_CMEM);                               
                                                                                
\
             }                                                                  
                                                                                
\
         }                                                                      
                                                                                
\
@@ -364,7 +367,6 @@ str PyAPIeval(MalBlkPtr mb, MalStkPtr st
     BATiter li;
     PyReturn *pyreturn_values = NULL;
     PyInput *pyinput_values = NULL;
-    bool memory_mapping = TRUE;
 
 #ifndef WIN32
     bool single_fork = mapped == 1;
@@ -1318,8 +1320,6 @@ str PyAPIeval(MalBlkPtr mb, MalStkPtr st
 
     //ReleaseLock(gstate, &holds_gil);
 
-    VERBOSE_MESSAGE("Returning values.\n");
-
 #ifndef WIN32
     if (mapped && process_id)
     {
@@ -1481,6 +1481,7 @@ str PyAPIeval(MalBlkPtr mb, MalStkPtr st
     }
 returnvalues:
 #endif
+    VERBOSE_MESSAGE("Returning values.\n");
     //dereference the input BATs
     for (i = pci->retc + 2; i < pci->argc; i++) 
     {
@@ -1496,7 +1497,7 @@ returnvalues:
         b = ret->bat_return;    
 
         if (ret->multidimensional) index_offset = i;
-
+        VERBOSE_MESSAGE("- Returning a Numpy Array of type %s of size %zu and 
storing it in a BAT of type %s\n", PyType_Format(ret->result_type), ret->count, 
 BatType_Format(bat_type));
         switch (bat_type) 
         {
         case TYPE_bte:
diff --git a/sql/backends/monet5/Tests/pyapi08.sql 
b/sql/backends/monet5/Tests/pyapi08.sql
--- a/sql/backends/monet5/Tests/pyapi08.sql
+++ b/sql/backends/monet5/Tests/pyapi08.sql
@@ -1013,7 +1013,9 @@ 2015-06-03 15:11:40.000000|1|"244650760"
 
 
 
-CREATE FUNCTION numpy_distance(stt string, tss bigint, lat double, lon double, 
alt double) returns table (s1 string, s2 string, timestamp int, mindist int) 
language P {
+#CREATE FUNCTION numpy_distance(stt string, tss bigint, lat double, lon 
double, alt double) returns table (s1 string, s2 string, timestamp int, mindist 
int) language P {
+#temporary fix
+CREATE FUNCTION numpy_distance(stt string, tss bigint, lat double, lon double, 
alt double) returns table (s1 string, s2 string, timestamp int) language P {
 import numpy as np
 import math
 timelimit = 10
@@ -1054,14 +1056,14 @@ while not it.finished:
             mindist = distdiff
             otheridx = it2.index
         it2.iternext()
-    out = ''
-    if mindist < distlimit:
-        rets1.append(stt[it.index])
-        rets2.append(stt[otheridx])
-        retts.append(int(it[0]/1000))
-        retmd.append(int(mindist))
+    #if mindist < distlimit:
+    rets1 = numpy.append(rets1, stt[it.index])
+    rets2 = numpy.append(rets2, stt[otheridx])
+    retts = numpy.append(retts, int(it[0]/1000))
+    retmd = numpy.append(retmd, int(mindist))
     it.iternext()
-return([rets1, rets2, retts, retmd])
+return([rets1, rets2, retts]) 
+#return([rets1, rets2, retts, retmd])
 };
 
 create temporary table planes as SELECT station, (ts-CAST('1970-01-01' AS 
timestamp)), lat, lon, alt*0.3048 FROM streams WHERE type = 2 and alt > 0 with 
data;
diff --git a/sql/backends/monet5/Tests/pyapi12.sql 
b/sql/backends/monet5/Tests/pyapi12.sql
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/pyapi12.sql
@@ -0,0 +1,15 @@
+START TRANSACTION;
+
+CREATE TABLE rval(i integer);
+INSERT INTO rval VALUES (1),(2),(3),(4),(-1),(0);
+
+CREATE FUNCTION pyapi12(i integer,z integer) returns boolean language 
PYTHON_MAP
+{
+       return(numpy.greater(i,z))
+};
+SELECT * FROM rval WHERE pyapi12(i,2);
+DROP FUNCTION pyapi12;
+DROP TABLE rval;
+
+
+ROLLBACK;
diff --git a/sql/backends/monet5/Tests/pyapi12.stable.err 
b/sql/backends/monet5/Tests/pyapi12.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/pyapi12.stable.err
@@ -0,0 +1,38 @@
+stderr of test 'pyapi12` in directory 'sql/backends/monet5` itself:
+
+
+# 17:13:01 >  
+# 17:13:01 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=39806" "--set" 
"mapi_usock=/var/tmp/mtest-29161/.s.monetdb.39806" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/mytherin/opt/var/mTests_sql_backends_monet5" "--set" 
"mal_listing=0" "--set" "embedded_r=true" "--set" "embedded_py=true"
+# 17:13:01 >  
+
+# builtin opt  gdk_dbpath = /home/mytherin/opt/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 39806
+# cmdline opt  mapi_usock = /var/tmp/mtest-29161/.s.monetdb.39806
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbpath = /home/mytherin/opt/var/mTests_sql_backends_monet5
+# cmdline opt  mal_listing = 0
+# cmdline opt  embedded_r = true
+# cmdline opt  embedded_py = true
+# cmdline opt  gdk_debug = 536870922
+
+# 17:13:01 >  
+# 17:13:01 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-29161" "--port=39806"
+# 17:13:01 >  
+
+
+# 17:13:01 >  
+# 17:13:01 >  "Done."
+# 17:13:01 >  
+
diff --git a/sql/backends/monet5/Tests/pyapi12.stable.out 
b/sql/backends/monet5/Tests/pyapi12.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/pyapi12.stable.out
@@ -0,0 +1,83 @@
+stdout of test 'pyapi12` in directory 'sql/backends/monet5` itself:
+
+
+# 17:13:01 >  
+# 17:13:01 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=39806" "--set" 
"mapi_usock=/var/tmp/mtest-29161/.s.monetdb.39806" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/mytherin/opt/var/mTests_sql_backends_monet5" "--set" 
"mal_listing=0" "--set" "embedded_r=true" "--set" "embedded_py=true"
+# 17:13:01 >  
+
+# MonetDB 5 server v11.20.0
+# This is an unreleased version
+# Serving database 'mTests_sql_backends_monet5', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs and 128bit 
integers dynamically linked
+# Found 7.684 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2015 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://mytherin-N750JV:39806/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-29161/.s.monetdb.39806
+# Start processing logs sql/sql_logs version 52200
+# Finished processing logs sql/sql_logs
+# MonetDB/SQL module loaded
+# MonetDB/Python module loaded
+# MonetDB/R   module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
+# loading sql script: 13_date.sql
+# loading sql script: 14_inet.sql
+# loading sql script: 15_querylog.sql
+# loading sql script: 16_tracelog.sql
+# loading sql script: 17_temporal.sql
+# loading sql script: 20_vacuum.sql
+# loading sql script: 21_dependency_functions.sql
+# loading sql script: 22_clients.sql
+# loading sql script: 23_skyserver.sql
+# loading sql script: 24_zorder.sql
+# loading sql script: 25_debug.sql
+# loading sql script: 26_sysmon.sql
+# loading sql script: 39_analytics.sql
+# loading sql script: 39_analytics_hge.sql
+# loading sql script: 40_json.sql
+# loading sql script: 40_json_hge.sql
+# loading sql script: 41_md5sum.sql
+# loading sql script: 45_uuid.sql
+# loading sql script: 51_sys_schema_extension.sql
+# loading sql script: 75_storagemodel.sql
+# loading sql script: 80_statistics.sql
+# loading sql script: 80_udf.sql
+# loading sql script: 80_udf_hge.sql
+# loading sql script: 90_generator.sql
+# loading sql script: 90_generator_hge.sql
+# loading sql script: 99_system.sql
+
+# 17:13:01 >  
+# 17:13:01 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-29161" "--port=39806"
+# 17:13:01 >  
+
+#START TRANSACTION;
+#CREATE TABLE rval(i integer);
+#INSERT INTO rval VALUES (1),(2),(3),(4),(-1),(0);
+[ 6    ]
+#CREATE FUNCTION pyapi12(i integer,z integer) returns boolean language P
+#{
+#      return(numpy.greater(i,z))
+#};
+#SELECT * FROM rval WHERE pyapi12(i,2);
+% sys.rval # table_name
+% i # name
+% int # type
+% 1 # length
+[ 3    ]
+[ 4    ]
+#DROP FUNCTION pyapi12;
+#DROP TABLE rval;
+#ROLLBACK;
+
+# 17:13:01 >  
+# 17:13:01 >  "Done."
+# 17:13:01 >  
+
diff --git a/sql/backends/monet5/Tests/rapi13.sql 
b/sql/backends/monet5/Tests/rapi13.sql
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/rapi13.sql
@@ -0,0 +1,39 @@
+start transaction;
+
+CREATE TABLE "streams" (
+    "ts"      TIMESTAMP,
+    "type"    TINYINT,
+    "station" CHARACTER LARGE OBJECT,
+    "lat"     DOUBLE,
+    "lon"     DOUBLE,
+    "alt"     DOUBLE
+);
+
+copy 5 records into streams from stdin;
+2015-06-03 15:11:17.000000|2|"4CA56B"|52.08069|5.86654|3.8e+04
+2015-06-03 15:11:17.000000|2|"4010EA"|51.19084|4.98646|38025
+2015-06-03 15:11:17.000000|2|"406C71"|52.36768|7.17085|3.5e+04
+2015-06-03 15:11:17.000000|2|"4006A4"|52.44951|5.21294|37025
+2015-06-03 15:11:17.000000|2|"45AC45"|52.12491|6.03063|3.6e+04
+
+# three return columns works
+CREATE FUNCTION working_test(stt string, tss bigint, lat double, lon double, 
alt double) returns table (i int, j int, k int) language R {
+       return(data.frame(1:10, 1:10, 1:10))
+};
+
+# but four does not? something to do with the amount of return columns?
+CREATE FUNCTION broken_test(stt string, tss bigint, lat double, lon double, 
alt double) returns table (i int, j int, k int, l int) language R {
+       return(data.frame(1:10, 1:10, 1:10, 1:10))
+};
+
+create temporary table planes as SELECT station, (ts-CAST('1970-01-01' AS 
timestamp)), lat, lon, alt*0.3048 FROM streams WHERE type = 2 and alt > 0 with 
data;
+#this is the input
+select * from planes;
+select * from working_test( (SELECT * FROM planes AS p) );
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to