Changeset: 9875e705f062 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9875e705f062
Added Files:
        sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.sql
        sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.stable.err
        sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.stable.out
        sql/test/BugTracker-2014/Tests/python-microseconds.Bug-3439.SQL.py
        sql/test/BugTracker-2014/Tests/python-microseconds.Bug-3439.stable.err
        sql/test/BugTracker-2014/Tests/python-microseconds.Bug-3439.stable.out
Modified Files:
        clients/python2/monetdb/sql/pythonize.py
        clients/python3/monetdb/sql/pythonize.py
        gdk/gdk_calc.c
        sql/test/ADT2006/bram.sql
        sql/test/BugTracker-2014/Tests/All
Branch: default
Log Message:

Merge with Jan2014 branch.


diffs (truncated from 468 to 300 lines):

diff --git a/clients/python2/monetdb/sql/pythonize.py 
b/clients/python2/monetdb/sql/pythonize.py
--- a/clients/python2/monetdb/sql/pythonize.py
+++ b/clients/python2/monetdb/sql/pythonize.py
@@ -40,6 +40,22 @@ def _extract_timezone(data):
 
     return dt, tzhour, tzmin
 
+def _extract_time(data, tzhour = 0, tzmin = 0):
+    time = data.split(':')
+    hour = int(time[0]) + tzhour
+    minute = int(time[1]) + tzmin
+    second = time[2]
+    if '.' in second:
+        second, microsecond = second.split('.')
+        while len(microsecond) < 6:
+            microsecond += '0'
+        while len(microsecond) > 6:
+            microsecond = microsecond[:-1]
+        microsecond = int(microsecond)
+    else:
+        microsecond = 0
+    second = int(second)
+    return hour, minute, second, microsecond
 
 def strip(data):
     """ returns a python string, with chopped off quotes,
@@ -55,29 +71,28 @@ def py_bool(data):
 def py_time(data):
     """ returns a python Time
     """
-    return Time(*[int(float(x)) for x in data.split(':')])
+    return Time(*_extract_time(data))
 
 
 def py_timetz(data):
     """ returns a python Time where data contains a tz code
     """
     dt, tzhour, tzmin = _extract_timezone(data)
-    hour, minute, second = [int(float(x)) for x in dt.split(':')]
-    return Time(hour + tzhour, minute + tzmin, second)
+    return Time(*_extract_time(dt, tzhour, tzmin))
 
 
 def py_date(data):
     """ Returns a python Date
     """
-    return Date(*[int(float(x)) for x in data.split('-')])
+    return Date(*[int(x) for x in data.split('-')])
 
 
 def py_timestamp(data):
     """ Returns a python Timestamp
     """
-    splitted = data.split(" ")
-    date = [int(float(x)) for x in splitted[0].split('-')]
-    time = [int(float(x)) for x in splitted[1].split(':')]
+    (datestr, timestr) = data.split(" ")
+    date = [int(x) for x in datestr.split('-')]
+    time = list(_extract_time(timestr))
     return Timestamp(*(date + time))
 
 
@@ -86,11 +101,9 @@ def py_timestamptz(data):
     """
     dt, tzhour, tzmin = _extract_timezone(data)
     (datestr, timestr) = dt.split(" ")
-    date = [int(float(x)) for x in datestr.split('-')]
-    time = [int(float(x)) for x in timestr.split(':')]
-    year, month, day = date
-    hour, minute, second = time
-    return Timestamp(year, month, day, hour + tzhour, minute + tzmin, second)
+    date = [int(x) for x in datestr.split('-')]
+    time = list(_extract_time(timestr, tzhour, tzmin))
+    return Timestamp(*(date + time))
 
 
 mapping = {
diff --git a/clients/python3/monetdb/sql/pythonize.py 
b/clients/python3/monetdb/sql/pythonize.py
--- a/clients/python3/monetdb/sql/pythonize.py
+++ b/clients/python3/monetdb/sql/pythonize.py
@@ -41,6 +41,22 @@ def _extract_timezone(data):
 
     return dt, tzhour, tzmin
 
+def _extract_time(data, tzhour = 0, tzmin = 0):
+    time = data.split(':')
+    hour = int(time[0]) + tzhour
+    minute = int(time[1]) + tzmin
+    second = time[2]
+    if '.' in second:
+        second, microsecond = second.split('.')
+        while len(microsecond) < 6:
+            microsecond += '0'
+        while len(microsecond) > 6:
+            microsecond = microsecond[:-1]
+        microsecond = int(microsecond)
+    else:
+        microsecond = 0
+    second = int(second)
+    return hour, minute, second, microsecond
 
 def strip(data):
     """ returns a python string, with chopped off quotes,
@@ -59,29 +75,28 @@ def py_bool(data):
 def py_time(data):
     """ returns a python Time
     """
-    return Time(*[int(float(x)) for x in data.split(':')])
+    return Time(*_extract_time(data))
 
 
 def py_timetz(data):
     """ returns a python Time where data contains a tz code
     """
     dt, tzhour, tzmin = _extract_timezone(data)
-    hour, minute, second = [int(float(x)) for x in dt.split(':')]
-    return Time(hour + tzhour, minute + tzmin, second)
+    return Time(*_extract_time(dt, tzhour, tzmin))
 
 
 def py_date(data):
     """ Returns a python Date
     """
-    return Date(*[int(float(x)) for x in data.split('-')])
+    return Date(*[int(x) for x in data.split('-')])
 
 
 def py_timestamp(data):
     """ Returns a python Timestamp
     """
-    splitted = data.split(" ")
-    date = [int(float(x)) for x in splitted[0].split('-')]
-    time = [int(float(x)) for x in splitted[1].split(':')]
+    (datestr, timestr) = data.split(" ")
+    date = [int(x) for x in datestr.split('-')]
+    time = list(_extract_time(timestr))
     return Timestamp(*(date + time))
 
 
@@ -90,11 +105,9 @@ def py_timestamptz(data):
     """
     dt, tzhour, tzmin = _extract_timezone(data)
     (datestr, timestr) = dt.split(" ")
-    date = [int(float(x)) for x in datestr.split('-')]
-    time = [int(float(x)) for x in timestr.split(':')]
-    year, month, day = date
-    hour, minute, second = time
-    return Timestamp(year, month, day, hour + tzhour, minute + tzmin, second)
+    date = [int(x) for x in datestr.split('-')]
+    time = list(_extract_time(timestr, tzhour, tzmin))
+    return Timestamp(*(date + time))
 
 
 mapping = {
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -9198,6 +9198,7 @@ convert_str_any(BAT *b, int tp, void *ds
        char *s;
        void *d;
        int len = ATOMsize(tp);
+       int l;
        int (*atomfromstr)(const char *, int *, ptr *) = 
BATatoms[tp].atomFromStr;
        BATiter bi = bat_iterator(b);
 
@@ -9223,7 +9224,8 @@ convert_str_any(BAT *b, int tp, void *ds
                        nils++;
                } else {
                        d = dst;
-                       if ((*atomfromstr)(s, &len, &d) <= 0) {
+                       if ((l = (*atomfromstr)(s, &len, &d)) <= 0 ||
+                           l < (int) strlen(s)) {
                                if (abort_on_error) {
                                        GDKerror("22018!conversion of string "
                                                 "'%s' to type %s failed.\n",
@@ -9828,11 +9830,12 @@ VARconvert(ValPtr ret, const ValRecord *
                                                      1, 0, 1, NULL, NULL, 0,
                                                      abort_on_error);
                } else {
+                       int len;
                        p = VALget(ret);
                        ret->len = BATatoms[ret->vtype].size;
-                       if ((*BATatoms[ret->vtype].atomFromStr)(v->val.sval,
-                                                               &ret->len,
-                                                               &p) <= 0) {
+                       if ((len = (*BATatoms[ret->vtype].atomFromStr)(
+                                    v->val.sval, &ret->len, &p)) <= 0 ||
+                           len < (int) strlen(v->val.sval)) {
                                GDKerror("22018!conversion of string "
                                         "'%s' to type %s failed.\n",
                                         v->val.sval, ATOMname(ret->vtype));
diff --git a/sql/test/ADT2006/bram.sql b/sql/test/ADT2006/bram.sql
--- a/sql/test/ADT2006/bram.sql
+++ b/sql/test/ADT2006/bram.sql
@@ -357,7 +357,7 @@ where
     length is not NULL and length like '%\'' and hair like '%blonde%')
 UNION ALL
 (select name, (12*cast(substring(length from 0 for (position('\'' in length) - 
1)) AS integer)
-    + cast(substring(length from (position('\'' in length) + 1) for 
(position('"' in length) + 1)) AS integer)) as height from victim v
+    + cast(substring(length from (position('\'' in length) + 1) for 
(position('"' in length) - position('\'' in length) - 1)) AS integer)) as 
height from victim v
     where
     length is not NULL and length like '%\'%"' and hair like '%blonde%')) AS h
 )
@@ -371,7 +371,7 @@ where
     length is not NULL and length like '%\'' and hair like '%brown%')
 UNION ALL
 (select name, (12*cast(substring(length from 0 for (position('\'' in length) - 
1)) AS integer)
-    + cast(substring(length from (position('\'' in length) + 1) for 
(position('"' in length) + 1)) AS integer)) as height from victim v
+    + cast(substring(length from (position('\'' in length) + 1) for 
(position('"' in length) - position('\'' in length) - 1)) AS integer)) as 
height from victim v
     where
     length is not NULL and length like '%\'%"' and hair like '%brown%')) AS h
 );
diff --git a/sql/test/BugTracker-2014/Tests/All 
b/sql/test/BugTracker-2014/Tests/All
--- a/sql/test/BugTracker-2014/Tests/All
+++ b/sql/test/BugTracker-2014/Tests/All
@@ -3,18 +3,19 @@ nested_common_table_exp.Bug-3417
 query-crash.Bug-3418
 groupby.Bug-3421
 groupby_distict.Bug-3423
+integer-cast.Bug-3424
 current_timestamp.Bug-3427
 two-column-aggr-with-null.Bug-3428
 sample-crash.Bug-3429
 temporary.Bug-3430
 indices.Bug-3435
 utf8bom.Bug-3436
+python-microseconds.Bug-3439
 left-outer-join-with-and.Bug-3444
 setreadonly_forgets_changes.Bug-3446
 select-having.Bug-3458
 crash_on_or_with_in.Bug-3461
 in_incorrect_multi.Bug-3462
 crash_on_groupby_distinct_serial.Bug-3463
-local-temp-1.Bug-3468.sql 
-local-temp-2.Bug-3468.sql 
-
+local-temp-1.Bug-3468
+local-temp-2.Bug-3468
diff --git a/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.sql 
b/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.sql
@@ -0,0 +1,1 @@
+select cast('00asdf1' as INTEGER);
diff --git a/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.stable.err 
b/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.stable.err
@@ -0,0 +1,38 @@
+stderr of test 'integer-cast.Bug-3424` in directory 'sql/test/BugTracker-2014` 
itself:
+
+
+# 17:58:28 >  
+# 17:58:28 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=38988" "--set" 
"mapi_usock=/var/tmp/mtest-25467/.s.monetdb.38988" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/sjoerd/Monet-stable/var/MonetDB/mTests_sql_test_BugTracker-2014"
 "--set" "mal_listing=0"
+# 17:58:28 >  
+
+# builtin opt  gdk_dbpath = /home/sjoerd/Monet-stable/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 = 38988
+# cmdline opt  mapi_usock = /var/tmp/mtest-25467/.s.monetdb.38988
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbpath = 
/home/sjoerd/Monet-stable/var/MonetDB/mTests_sql_test_BugTracker-2014
+# cmdline opt  mal_listing = 0
+
+# 17:58:28 >  
+# 17:58:28 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-25467" "--port=38988"
+# 17:58:28 >  
+
+MAPI  = (monetdb) /var/tmp/mtest-25467/.s.monetdb.38988
+QUERY = select cast('00asdf1' as INTEGER);
+ERROR = !conversion of string '00asdf1' to type int failed.
+
+# 17:58:29 >  
+# 17:58:29 >  "Done."
+# 17:58:29 >  
+
diff --git a/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.stable.out 
b/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2014/Tests/integer-cast.Bug-3424.stable.out
@@ -0,0 +1,58 @@
+stdout of test 'integer-cast.Bug-3424` in directory 'sql/test/BugTracker-2014` 
itself:
+
+
+# 17:58:28 >  
+# 17:58:28 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=38988" "--set" 
"mapi_usock=/var/tmp/mtest-25467/.s.monetdb.38988" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/sjoerd/Monet-stable/var/MonetDB/mTests_sql_test_BugTracker-2014"
 "--set" "mal_listing=0"
+# 17:58:28 >  
+
+# MonetDB 5 server v11.17.14 (hg id: a1c694f27eeb+)
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to