Changeset: b3bc5cb7c32e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b3bc5cb7c32e
Modified Files:
        sql/backends/monet5/Tests/pyloader01.sql
        sql/backends/monet5/Tests/pyloader01.stable.out
        sql/backends/monet5/UDF/pyapi/emit.c
        
sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.err
        
sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.out
Branch: Jul2017
Log Message:

Remove support for default values in the Python loader and throw an error 
message if they are encountered instead of adding incorrect values to the table.


diffs (242 lines):

diff --git a/sql/backends/monet5/Tests/pyloader01.sql 
b/sql/backends/monet5/Tests/pyloader01.sql
--- a/sql/backends/monet5/Tests/pyloader01.sql
+++ b/sql/backends/monet5/Tests/pyloader01.sql
@@ -1,7 +1,7 @@
 
 START TRANSACTION;
 
-CREATE TABLE mytable(a DOUBLE, d int, s STRING DEFAULT 'hello');
+CREATE TABLE mytable(a DOUBLE, d int, s STRING);
 
 CREATE LOADER myfunc() LANGUAGE PYTHON {
        _emit.emit({'a':42,'d':1})
diff --git a/sql/backends/monet5/Tests/pyloader01.stable.out 
b/sql/backends/monet5/Tests/pyloader01.stable.out
--- a/sql/backends/monet5/Tests/pyloader01.stable.out
+++ b/sql/backends/monet5/Tests/pyloader01.stable.out
@@ -56,11 +56,11 @@ Ready.
 % sys.mytable, sys.mytable,    sys.mytable # table_name
 % a,   d,      s # name
 % double,      int,    clob # type
-% 24,  1,      7 # length
-[ 42,  1,      "'hello'"       ]
+% 24,  1,      5 # length
+[ 42,  1,      NULL    ]
 [ 46,  4,      "hello" ]
-[ 45,  3,      "'hello'"       ]
-[ 44,  2,      "'hello'"       ]
+[ 45,  3,      NULL    ]
+[ 44,  2,      NULL    ]
 #DROP TABLE mytable;
 #DROP ALL LOADER myfunc;
 #CREATE LOADER myfunc() LANGUAGE PYTHON {
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
@@ -338,21 +338,19 @@ PyObject *PyEmit_Emit(PyEmitObject *self
                                self->cols[i].b->tnonil = 1 - 
self->cols[i].b->tnil;
                        }
                } else {
-                       void* nill_value = ATOMnil(self->cols[i].b->ttype);
-                       void* default_value = self->cols[i].def ?
-                                                               
self->cols[i].def :
-                                                               nill_value;
+                       if (self->cols[i].def != NULL) {
+                               msg = GDKstrdup("Inserting into columns with 
default values is not supported currently.");
+                               goto wrapup;
+                       }
                        for (ai = 0; ai < (size_t)el_count; ai++) {
                                if (BUNappend(self->cols[i].b,
-                                                         default_value,
+                                                         
ATOMnil(self->cols[i].b->ttype),
                                                          0) != GDK_SUCCEED) {
                                        goto wrapup;
                                }
                        }
-                       if 
(BATatoms[self->cols[i].b->ttype].atomCmp(default_value, nill_value) == 0) {
-                               self->cols[i].b->tnil = 1;
-                               self->cols[i].b->tnonil = 0;
-                       }
+                       self->cols[i].b->tnil = 1;
+                       self->cols[i].b->tnonil = 0;
                }
                BATsetcount(self->cols[i].b, self->nvals + el_count);
        }
diff --git 
a/sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.err
 
b/sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.err
--- 
a/sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.err
+++ 
b/sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.err
@@ -56,6 +56,102 @@ ERROR = !INSERT INTO: NOT NULL constrain
 MAPI  = (monetdb) /var/tmp/mtest-17575/.s.monetdb.32655
 QUERY = insert into t (a) values (-1);
 ERROR = !INSERT INTO: PRIMARY KEY constraint 't.t_a_pkey' violated
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-30,'abcdeg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = x - i
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-40,'abcdfg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = x - i
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-50,'abcefg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = x - i
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-60,'abdefg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = x - i
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-70,'acdefg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = x - i
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-80,'bcdefg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = x - i
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-300,'abcdeg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = numpy.array([ x - 10 - i , x - 20 - i ])
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-400,'abcdfg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = numpy.array([ x - 10 - i , x - 20 - i ])
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-500,'abcefg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = numpy.array([ x - 10 - i , x - 20 - i ])
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-600,'abdefg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = numpy.array([ x - 10 - i , x - 20 - i ])
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-700,'acdefg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = numpy.array([ x - 10 - i , x - 20 - i ])
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
+MAPI  = (monetdb) /var/tmp/mtest-80053/.s.monetdb.38101
+QUERY = COPY LOADER INTO t FROM myloader(-800,'bcdefg');
+ERROR = !Python exception
+        !  6.     if j in y:
+        !  7.       z[j] = numpy.array([ x - 10 - i , x - 20 - i ])
+        !> 8.   _emit.emit(z)
+        !  9. 
+        !Failed conversion: Inserting into columns with default values is not 
supported currently.
 
 # 17:58:15 >  
 # 17:58:15 >  "Done."
diff --git 
a/sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.out
 
b/sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.out
--- 
a/sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.out
+++ 
b/sql/test/BugTracker-2017/Tests/python_loader_clobbers_default_with_null.Bug-6464.stable.out
@@ -275,18 +275,6 @@ Ready.
 [ 1    ]
 #COPY LOADER INTO t FROM myloader(-20,'abcdef');
 [ 1    ]
-#COPY LOADER INTO t FROM myloader(-30,'abcdeg');
-[ 1    ]
-#COPY LOADER INTO t FROM myloader(-40,'abcdfg');
-[ 1    ]
-#COPY LOADER INTO t FROM myloader(-50,'abcefg');
-[ 1    ]
-#COPY LOADER INTO t FROM myloader(-60,'abdefg');
-[ 1    ]
-#COPY LOADER INTO t FROM myloader(-70,'acdefg');
-[ 1    ]
-#COPY LOADER INTO t FROM myloader(-80,'bcdefg');
-[ 1    ]
 #select * from t;
 % sys.t,       sys.t,  sys.t,  sys.t,  sys.t,  sys.t,  sys.t # table_name
 % a,   b,      c,      d,      e,      f,      g # name
@@ -294,12 +282,6 @@ Ready.
 % 3,   3,      3,      3,      3,      3,      3 # length
 [ -11, -12,    -13,    -14,    -15,    -16,    -17     ]
 [ -21, -22,    -23,    -24,    -25,    -26,    NULL    ]
-[ -31, -32,    -33,    -34,    -35,    6,      -37     ]
-[ -41, -42,    -43,    -44,    5,      -46,    -47     ]
-[ -51, -52,    -53,    4,      -55,    -56,    -57     ]
-[ -61, -62,    3,      -64,    -65,    -66,    -67     ]
-[ -71, 2,      -73,    -74,    -75,    -76,    -77     ]
-[ 1,   -82,    -83,    -84,    -85,    -86,    -87     ]
 #drop table t;
 #drop loader myloader;
 #CREATE LOADER myloader(x integer, y string) LANGUAGE PYTHON {
@@ -324,18 +306,6 @@ Ready.
 [ 2    ]
 #COPY LOADER INTO t FROM myloader(-200,'abcdef');
 [ 2    ]
-#COPY LOADER INTO t FROM myloader(-300,'abcdeg');
-[ 2    ]
-#COPY LOADER INTO t FROM myloader(-400,'abcdfg');
-[ 2    ]
-#COPY LOADER INTO t FROM myloader(-500,'abcefg');
-[ 2    ]
-#COPY LOADER INTO t FROM myloader(-600,'abdefg');
-[ 2    ]
-#COPY LOADER INTO t FROM myloader(-700,'acdefg');
-[ 2    ]
-#COPY LOADER INTO t FROM myloader(-800,'bcdefg');
-[ 2    ]
 #select * from t;
 % sys.t,       sys.t,  sys.t,  sys.t,  sys.t,  sys.t,  sys.t # table_name
 % a,   b,      c,      d,      e,      f,      g # name
@@ -345,18 +315,6 @@ Ready.
 [ -121,        -122,   -123,   -124,   -125,   -126,   -127    ]
 [ -211,        -212,   -213,   -214,   -215,   -216,   NULL    ]
 [ -221,        -222,   -223,   -224,   -225,   -226,   NULL    ]
-[ -311,        -312,   -313,   -314,   -315,   6,      -317    ]
-[ -321,        -322,   -323,   -324,   -325,   6,      -327    ]
-[ -411,        -412,   -413,   -414,   5,      -416,   -417    ]
-[ -421,        -422,   -423,   -424,   5,      -426,   -427    ]
-[ -511,        -512,   -513,   4,      -515,   -516,   -517    ]
-[ -521,        -522,   -523,   5,      -525,   -526,   -527    ]
-[ -611,        -612,   3,      -614,   -615,   -616,   -617    ]
-[ -621,        -622,   4,      -624,   -625,   -626,   -627    ]
-[ -711,        2,      -713,   -714,   -715,   -716,   -717    ]
-[ -721,        3,      -723,   -724,   -725,   -726,   -727    ]
-[ 1,   -812,   -813,   -814,   -815,   -816,   -817    ]
-[ 2,   -822,   -823,   -824,   -825,   -826,   -827    ]
 #drop table t;
 #drop loader myloader;
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to