Changeset: ba049766b598 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ba049766b598 Added Files: sql/test/BugTracker-2016/Tests/string-length.Bug-3999.sql sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.err sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.out Modified Files: java/ChangeLog.Jul2015 java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java sql/jdbc/tests/Tests/Test_JdbcClient.stable.out sql/test/BugTracker-2016/Tests/All Branch: Jun2016 Log Message:
Merge with Jul2015 branch. diffs (truncated from 421 to 300 lines): diff --git a/java/ChangeLog.Jul2015 b/java/ChangeLog.Jul2015 --- a/java/ChangeLog.Jul2015 +++ b/java/ChangeLog.Jul2015 @@ -1,7 +1,18 @@ # ChangeLog file for java # This file is updated with Maddlog +* Thu May 12 2016 Martin van Dinther <[email protected]> +- Improved JdbcClient program when presenting query data to console. + It used to send an SQL catalog query for each query result column + which slowed down the interactive response considerably. + These additional SQL catalog queries have been eliminated. + +* Thu May 12 2016 Martin van Dinther <[email protected]> +- Corrected MonetResultSet.getObject(String columnName). It no longer + throws a NullPointerException in cases where internally a + MonetVirtualResultSet is used. + * Sun May 8 2016 Jennie Zhang <[email protected]> - Fixed Connection.isValid(): this method should never attempt to - close the connection, even an error has occurred + close the connection, even if an error has occurred. diff --git a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java --- a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java +++ b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java @@ -2018,7 +2018,7 @@ public class MonetResultSet extends Mone */ @Override public Object getObject(String columnName) throws SQLException { - return getObject(columnName, this.getStatement().getConnection().getTypeMap()); + return getObject(findColumn(columnName)); } /** diff --git a/java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java b/java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java --- a/java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java +++ b/java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java @@ -402,18 +402,19 @@ public class SQLExporter extends Exporte public void resultSetToTable(ResultSet rs) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int cols = md.getColumnCount(); - // find the presentation widths of the columns - int[] width = new int[cols +1]; - for (int j = 1; j <= cols; j++) { - int displaySize = md.getColumnDisplaySize(j); - int labelLength = md.getColumnLabel(j).length(); - width[j] = (displaySize > labelLength) ? displaySize : labelLength; - if (md.isNullable(j) != ResultSetMetaData.columnNoNulls) { - width[j] = Math.max("<NULL>".length(), width[j]); - } + // find the optimal display widths of the columns + int[] width = new int[cols + 1]; + boolean[] isSigned = new boolean[cols + 1]; + for (int j = 1; j <= width.length; j++) { + int coldisplaysize = md.getColumnDisplaySize(j); + int collabellength = md.getColumnLabel(j).length(); + int maxwidth = (coldisplaysize > collabellength) ? coldisplaysize : collabellength; + // the minimum width should be 4 to represent: "NULL" + width[j] = (maxwidth > 4) ? maxwidth : 4; + isSigned[j] = md.isSigned(j); } - // print header + // print the header text out.print("+"); for (int j = 1; j < width.length; j++) out.print(repeat('-', width[j] +1) + "-+"); @@ -439,23 +440,30 @@ public class SQLExporter extends Exporte Object rdata = rs.getObject(j); String data; if (rdata == null || rs.wasNull()) { - data = "<NULL>"; + data = "NULL"; } else { data = rdata.toString(); + if (data == null) + data = "NULL"; } - String filler = repeat(' ', Math.max(width[j] - data.length(), 0)); - if (md.isSigned(j)) { - // we have a numeric type here, right align presented data - out.print(" " + filler + data + " |"); + + int filler_length = width[j] - data.length(); + if (filler_length <= 0) { + out.print(" " + data + " |"); } else { - // something else - out.print(" " + data + filler + " |"); + if (isSigned[j]) { + // we have a numeric type here, right align + out.print(" " + repeat(' ', filler_length) + data + " |"); + } else { + // all other left align + out.print(" " + data + repeat(' ', filler_length) + " |"); + } } } out.println(); } - // print footer + // print the footer text out.print("+"); for (int j = 1; j < width.length; j++) out.print(repeat('-', width[j] +1) + "-+"); diff --git a/sql/jdbc/tests/Tests/Test_JdbcClient.stable.out b/sql/jdbc/tests/Tests/Test_JdbcClient.stable.out --- a/sql/jdbc/tests/Tests/Test_JdbcClient.stable.out +++ b/sql/jdbc/tests/Tests/Test_JdbcClient.stable.out @@ -86,30 +86,30 @@ 1 affected row 1 affected row -+----+---------+-----------+--------+----------+ -| id | subject | predicate | object | explicit | -+====+=========+===========+========+==========+ -| 1 | 1 | 1 | 1 | false | -| 2 | 1 | 1 | 2 | false | -| 3 | 1 | 2 | 1 | false | -| 4 | 2 | 1 | 1 | false | -| 5 | 1 | 2 | 2 | false | -| 6 | 2 | 2 | 1 | false | -| 7 | 2 | 2 | 2 | false | -+----+---------+-----------+--------+----------+ ++------+---------+-----------+--------+----------+ +| id | subject | predicate | object | explicit | ++======+=========+===========+========+==========+ +| 1 | 1 | 1 | 1 | false | +| 2 | 1 | 1 | 2 | false | +| 3 | 1 | 2 | 1 | false | +| 4 | 2 | 1 | 1 | false | +| 5 | 1 | 2 | 2 | false | +| 6 | 2 | 2 | 1 | false | +| 7 | 2 | 2 | 2 | false | ++------+---------+-----------+--------+----------+ 7 rows -+----+---------+-----------+--------+ -| id | subject | predicate | object | -+====+=========+===========+========+ -| 1 | 1 | 1 | 1 | -| 2 | 2 | 2 | 2 | -| 3 | 1 | 2 | 2 | -| 4 | 2 | 2 | 1 | -| 5 | 2 | 1 | 1 | -| 6 | 1 | 2 | 1 | -| 7 | 1 | 1 | 2 | -+----+---------+-----------+--------+ ++------+---------+-----------+--------+ +| id | subject | predicate | object | ++======+=========+===========+========+ +| 1 | 1 | 1 | 1 | +| 2 | 2 | 2 | 2 | +| 3 | 1 | 2 | 2 | +| 4 | 2 | 2 | 1 | +| 5 | 2 | 1 | 1 | +| 6 | 1 | 2 | 1 | +| 7 | 1 | 1 | 2 | ++------+---------+-----------+--------+ 7 rows Operation successful diff --git a/sql/test/BugTracker-2016/Tests/All b/sql/test/BugTracker-2016/Tests/All --- a/sql/test/BugTracker-2016/Tests/All +++ b/sql/test/BugTracker-2016/Tests/All @@ -30,3 +30,4 @@ subcorr-missing.Bug-3978 epoch.Bug-3979 fk-smaller-pk.Bug-3983 isaUUID_function.Bug-3997 +string-length.Bug-3999 diff --git a/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.sql b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.sql new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.sql @@ -0,0 +1,43 @@ +SELECT length('123 ') as "four"; +SELECT length('123 ') as "ten"; +SELECT length('1234567890') as "ten"; +SELECT length(' 67890') as "ten"; +SELECT length(reverse(' 67890')) as "ten"; + +SELECT sys.length('123 ') as "four"; +SELECT sys.length('123 ') as "ten"; +SELECT sys.length('1234567890') as "ten"; +SELECT sys.length(' 67890') as "ten"; +SELECT sys.length(reverse(' 67890')) as "ten"; + +-- test trailing spaces with VarChar +CREATE TABLE tvarchar (val VARCHAR(9) NOT NULL); +INSERT INTO tvarchar VALUES ('A'), (' BC '); +SELECT val, length(val) FROM tvarchar; +-- returned wrong length for second row + +UPDATE tvarchar SET val = val || ' '; +SELECT val, length(val) FROM tvarchar; +-- returned wrong length for both rows + +UPDATE tvarchar SET val = (val || 'x'); +SELECT val, length(val) FROM tvarchar; + +DROP TABLE tvarchar; + + +-- test trailing spaces with Char +CREATE TABLE tchar (val CHAR(9) NOT NULL); +INSERT INTO tchar VALUES ('A'), (' BC '); +SELECT val, length(val) FROM tchar; +-- returned wrong length for second row + +UPDATE tchar SET val = val || ' '; +SELECT val, length(val) FROM tchar; +-- returned wrong length for both rows + +UPDATE tchar SET val = (val || 'x'); +SELECT val, length(val) FROM tchar; + +DROP TABLE tchar; + diff --git a/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.err b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.err new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.err @@ -0,0 +1,38 @@ +stderr of test 'string-length.Bug-3999` in directory 'sql/test/BugTracker-2016` itself: + + +# 11:44:26 > +# 11:44:26 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=30837" "--set" "mapi_usock=/var/tmp/mtest-9650/.s.monetdb.30837" "--set" "monet_prompt=" "--forcemito" "--set" "mal_listing=2" "--dbpath=/export/scratch2/dinther/INSTALL/var/MonetDB/mTests_sql_test_BugTracker-2016" "--set" "mal_listing=0" "--set" "embedded_r=yes" +# 11:44:26 > + +# builtin opt gdk_dbpath = /export/scratch2/dinther/INSTALL/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 = 30837 +# cmdline opt mapi_usock = /var/tmp/mtest-9650/.s.monetdb.30837 +# cmdline opt monet_prompt = +# cmdline opt mal_listing = 2 +# cmdline opt gdk_dbpath = /export/scratch2/dinther/INSTALL/var/MonetDB/mTests_sql_test_BugTracker-2016 +# cmdline opt mal_listing = 0 +# cmdline opt embedded_r = yes +# cmdline opt gdk_debug = 536870922 + +# 11:44:27 > +# 11:44:27 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-9650" "--port=30837" +# 11:44:27 > + + + +# 11:44:27 > +# 11:44:27 > "Done." +# 11:44:27 > + diff --git a/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.out b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.out new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.out @@ -0,0 +1,154 @@ +stdout of test 'string-length.Bug-3999` in directory 'sql/test/BugTracker-2016` itself: + + +# 11:44:26 > +# 11:44:26 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=30837" "--set" "mapi_usock=/var/tmp/mtest-9650/.s.monetdb.30837" "--set" "monet_prompt=" "--forcemito" "--set" "mal_listing=2" "--dbpath=/export/scratch2/dinther/INSTALL/var/MonetDB/mTests_sql_test_BugTracker-2016" "--set" "mal_listing=0" "--set" "embedded_r=yes" +# 11:44:26 > + +# MonetDB 5 server v11.21.20 +# This is an unreleased version +# Serving database 'mTests_sql_test_BugTracker-2016', using 8 threads +# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs and 128bit integers dynamically linked +# Found 15.589 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://toulouse.da.cwi.nl:30837/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-9650/.s.monetdb.30837 +# MonetDB/GIS module loaded +# Start processing logs sql/sql_logs version 52200 +# Start reading the write-ahead log 'sql_logs/sql/log.15' +# Finished reading the write-ahead log 'sql_logs/sql/log.15' +# Finished processing logs sql/sql_logs +# MonetDB/SQL module loaded +# MonetDB/R module loaded + +Ready. + +# 11:44:27 > +# 11:44:27 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-9650" "--port=30837" +# 11:44:27 > + +#SELECT length('123 ') as "four"; +% .L # table_name _______________________________________________ checkin-list mailing list [email protected] https://www.monetdb.org/mailman/listinfo/checkin-list
