Changeset: d3b9afcfe7bf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d3b9afcfe7bf
Added Files:
        sql/test/BugTracker-2019/Tests/view-where-cast-error.Bug-6712.sql
        sql/test/BugTracker-2019/Tests/view-where-cast-error.Bug-6712.stable.err
        sql/test/BugTracker-2019/Tests/view-where-cast-error.Bug-6712.stable.out
Modified Files:
        clients/mapiclient/mclient.c
        common/stream/stream.c
        gdk/gdk_hash.c
        monetdb5/mal/mal_exception.c
        monetdb5/modules/kernel/algebra.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/sql_statement.c
        sql/backends/monet5/sql_statement.h
        sql/server/rel_sequence.c
        sql/test/BugTracker-2018/Tests/lateral-join-crash.Bug-6613.stable.err
        sql/test/BugTracker-2018/Tests/lateral-join-crash.Bug-6613.stable.out
        sql/test/BugTracker-2019/Tests/All
        
sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
        sql/test/pg_regress/Tests/timestamp.sql
        sql/test/pg_regress/Tests/timestamptz.sql
Branch: mtime
Log Message:

Merge with default branch.


diffs (truncated from 555 to 300 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1872,6 +1872,11 @@ format_result(Mapi mid, MapiHdl hdl, boo
        timerHumanCalled = false;
 
        do {
+               // get the timings as reported by the backend
+               sqloptimizer = mapi_get_sqloptimizertime(hdl);
+               maloptimizer = mapi_get_maloptimizertime(hdl);
+               querytime = mapi_get_querytime(hdl);
+               timerHumanStop();
                /* handle errors first */
                if (mapi_result_error(hdl) != NULL) {
                        mnstr_flush(toConsole);
@@ -1884,14 +1889,10 @@ format_result(Mapi mid, MapiHdl hdl, boo
                        errseen = true;
                        /* don't need to print something like '0
                         * tuples' if we got an error */
+                       timerHuman(sqloptimizer, maloptimizer, querytime, 
singleinstr, false);
                        continue;
                }
 
-               // get the timings as reported by the backend
-               sqloptimizer = mapi_get_sqloptimizertime(hdl);
-               maloptimizer = mapi_get_maloptimizertime(hdl);
-               querytime = mapi_get_querytime(hdl);
-               timerHumanStop();
                switch (mapi_get_querytype(hdl)) {
                case Q_BLOCK:
                case Q_PARSE:
@@ -3084,7 +3085,8 @@ getfile(void *data, const char *filename
        struct privdata *priv = data;
        ssize_t s;
 
-       *size = 0;              /* most returns require this */
+       if (size)
+               *size = 0;      /* most returns require this */
        if (priv->buf == NULL) {
                priv->buf = malloc(READSIZE);
                if (priv->buf == NULL)
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -1588,18 +1588,15 @@ open_xzstream(const char *restrict filen
                    strncmp(buf, UTF8BOM, UTF8BOMLENGTH) == 0) {
                        s->isutf8 = true;
                } else {
-                       FILE *fp = xz->fp;
-                       lzma_ret ret;
                        lzma_end(&xz->strm);
-                       ret = lzma_stream_decoder(&xz->strm, UINT64_MAX, 
LZMA_CONCATENATED);
-                       if (ret != LZMA_OK) {
+                       if (lzma_stream_decoder(&xz->strm, UINT64_MAX, 
LZMA_CONCATENATED) != LZMA_OK
+                               || fseek (xz->fp, 0L, SEEK_SET) < 0) {
+                               fclose(xz->fp);
+                               free(xz);
                                destroy(s);
-                               free(xz);
-                               fclose(fp);
                                return NULL;
                        }
-                       rewind(fp);
-                       xz->fp = fp;
+                       xz->todo = 0;
                }
        }
        return s;
diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -76,7 +76,7 @@ HASHmask(BUN cnt)
        return m;
 }
 
-static void
+static inline void
 HASHclear(Hash *h)
 {
        /* since BUN2_NONE, BUN4_NONE, BUN8_NONE
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -357,7 +357,7 @@ getExceptionMessageAndState(const char *
                if (strncmp(exceptionNames[i], exception, l) == 0 &&
                        exception[l] == ':') {
                        s = exception + l + 1;
-                       if ((t = strchr(s, ':')) != NULL)
+                       if ((t = strpbrk(s, ":\n")) != NULL && *t == ':')
                                return (str) (t + 1);
                        return (str) s;
                }
diff --git a/monetdb5/modules/kernel/algebra.c 
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -382,7 +382,7 @@ do_join(bat *r1, bat *r2, const bat *lid
        else
                est = (BUN) *estimate;
 
-       err = GDK_EXCEPTION;            /* most likely error now */
+       err = NULL;             /* most likely error now is GDK_EXCEPTION */
 
        if (thetafunc) {
                assert(joinfunc == NULL);
@@ -453,6 +453,8 @@ do_join(bat *r1, bat *r2, const bat *lid
                BBPunfix(candleft->batCacheid);
        if (candright)
                BBPunfix(candright->batCacheid);
+       if (err == NULL)
+               throw(MAL, funcname, GDK_EXCEPTION);
        throw(MAL, funcname, "%s", err);
 }
 
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -577,7 +577,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                }
                if (!l) 
                        return NULL;
-               s = stmt_convert(be, l, from, to);
+               s = stmt_convert(be, l, from, to, sel);
        }       break;
        case e_func: {
                node *en;
@@ -1173,7 +1173,7 @@ check_types(backend *be, sql_subtype *ct
                    (c == 3 && tpe != type_cast)) { 
                        s = NULL;
                } else {
-                       s = stmt_convert(be, s, st, ct);
+                       s = stmt_convert(be, s, st, ct, NULL);
                }
        } 
        if (!s) {
@@ -2976,6 +2976,11 @@ rel2bin_select(backend *be, sql_rel *rel
                if (s->nrcols == 0){
                        if (!predicate && sub)
                                predicate = stmt_const(be, bin_first_column(be, 
sub), stmt_bool(be, 1));
+                       if (e->type != e_cmp) {
+                               sql_subtype *bt = sql_bind_localtype("bit");
+
+                               s = stmt_convert(be, s, exp_subtype(e), bt, 
NULL);
+                       }
                        sel = stmt_uselect(be, predicate, s, cmp_equal, sel, 0);
                } else if (e->type != e_cmp) {
                        sel = stmt_uselect(be, s, stmt_bool(be, 1), cmp_equal, 
NULL, 0);
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1304,18 +1304,19 @@ SQLCacheRemove(Client c, str nme)
 
 str
 SQLcallback(Client c, str msg){
-       if(msg &&  (strstr(msg, "MALexception") || strstr(msg,"GDKexception"))) 
{
+       char newerr[1024];
+
+       if (msg && (strstr(msg, "MALexception") || strstr(msg,"GDKexception"))) 
{
                // massage the error to comply with SQL
                char *s;
-               s= strchr(msg,(int)':');
-               if (s ) 
-                       s= strchr(msg,(int)':');
-               if( s){
-                       char newerr[1024];
+               s = strchr(msg, ':');
+               if (s) {
                        s++;
+                       if (s - msg >= (ptrdiff_t) sizeof(newerr))
+                               s = msg + sizeof(newerr) - 1;
                        strncpy(newerr, msg, s - msg);
                        newerr[s-msg] = 0;
-                       snprintf(newerr + (s-msg), 1024 -(s-msg), 
SQLSTATE(HY020) "%s",s);
+                       snprintf(newerr + (s-msg), sizeof(newerr) -(s-msg), 
SQLSTATE(HY020) "%s",s);
                        freeException(msg);
                        msg = GDKstrdup(newerr);
                }
@@ -1325,23 +1326,25 @@ SQLcallback(Client c, str msg){
                char *m, *n, *p, *s;
                size_t l;
 
-               m = p = msg;
+               m = msg;
+               p = newerr;
                while (m && *m) {
                        n = strchr(m, '\n');
-                       if (n)
-                               *n = 0;
                        s = getExceptionMessageAndState(m);
                        if (n) {
-                               *n++ = '\n';
+                               n++; /* include newline */
                                l = n - s;
                        } else {
                                l = strlen(s);
                        }
-                       memmove(p, s, l);
+                       if (p + l >= newerr + sizeof(newerr))
+                               l = newerr + sizeof(newerr) - p - 1;
+                       memcpy(p, s, l);
                        p += l;
                        m = n;
                }
                *p = 0;
+               msg = GDKstrdup(newerr);
        }
        return MALcallback(c,msg);
 }
diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -2740,7 +2740,7 @@ stmt_exception(backend *be, stmt *cond, 
 }
 
 stmt *
-stmt_convert(backend *be, stmt *v, sql_subtype *f, sql_subtype *t)
+stmt_convert(backend *be, stmt *v, sql_subtype *f, sql_subtype *t, stmt *sel)
 {
        MalBlkPtr mb = be->mb;
        InstrPtr q = NULL;
@@ -2799,6 +2799,8 @@ stmt_convert(backend *be, stmt *v, sql_s
                /* scale of the current decimal */
                q = pushInt(mb, q, f->scale);
        q = pushArgument(mb, q, v->nr);
+       if (sel && v->nrcols && f->type->eclass != EC_DEC && 
!EC_TEMP_FRAC(t->type->eclass) && !EC_INTERVAL(t->type->eclass))
+               q = pushArgument(mb, q, sel->nr);
 
        if (t->type->eclass == EC_DEC || EC_TEMP_FRAC(t->type->eclass) || 
EC_INTERVAL(t->type->eclass)) {
                /* digits, scale of the result decimal */
@@ -2840,6 +2842,7 @@ stmt_convert(backend *be, stmt *v, sql_s
                        return NULL;
                }
                s->op1 = v;
+               s->op2 = sel;
                s->nrcols = 0;  /* function without arguments returns single 
value */
                s->key = v->key;
                s->nrcols = v->nrcols;
diff --git a/sql/backends/monet5/sql_statement.h 
b/sql/backends/monet5/sql_statement.h
--- a/sql/backends/monet5/sql_statement.h
+++ b/sql/backends/monet5/sql_statement.h
@@ -215,7 +215,7 @@ extern stmt *stmt_sample(backend *be, st
 extern stmt *stmt_order(backend *be, stmt *s, int direction, int nullslast);
 extern stmt *stmt_reorder(backend *be, stmt *s, int direction, int nullslast, 
stmt *orderby_ids, stmt *orderby_grp);
 
-extern stmt *stmt_convert(backend *sa, stmt *v, sql_subtype *from, sql_subtype 
*to);
+extern stmt *stmt_convert(backend *sa, stmt *v, sql_subtype *from, sql_subtype 
*to, stmt *sel);
 extern stmt *stmt_unop(backend *be, stmt *op1, sql_subfunc *op);
 extern stmt *stmt_binop(backend *be, stmt *op1, stmt *op2, sql_subfunc *op);
 extern stmt *stmt_Nop(backend *be, stmt *ops, sql_subfunc *op);
diff --git a/sql/server/rel_sequence.c b/sql/server/rel_sequence.c
--- a/sql/server/rel_sequence.c
+++ b/sql/server/rel_sequence.c
@@ -261,6 +261,11 @@ rel_alter_seq(
                val = rel_value_exp2(query, &r, start_list->h->next->data.sym, 
sql_sel, ek, &is_last);
                if (!val || !(val = rel_check_type(sql, lng_t, val, 
type_equal)))
                        return NULL;
+               if (val && r && r->op == op_project) {
+                       exp_label(sql->sa, val, ++sql->label);
+                       val = rel_project_add_exp(sql, r, val);
+                       val = exp_ref(sql->sa, val);
+               }
        } else if (start_type == 2) {
                assert (start_list->h->next->type == type_lng);
                val = exp_atom_lng(sql->sa, start_list->h->next->data.l_val);
diff --git a/sql/test/BugTracker-2019/Tests/All 
b/sql/test/BugTracker-2019/Tests/All
--- a/sql/test/BugTracker-2019/Tests/All
+++ b/sql/test/BugTracker-2019/Tests/All
@@ -2,13 +2,15 @@ copy-into-from-stdin-empty-line.Bug-6669
 HAVE_LIBR?r-date.Bug-6674
 date_trunc
 date_trunc_bulk
-KNOWNFAIL?subselect-contradiction.Bug-6683
+subselect-contradiction.Bug-6683
 insert-replica-table.Bug-6684
-KNOWNFAIL?subselect-count.Bug-6686
-KNOWNFAIL?subselect.Bug-6688
+subselect-count.Bug-6686
+subselect.Bug-6688
 timestamptransformation.Bug-6695
 duplicates-not-eliminated-long-CASE-stmt.Bug-6697
-KNOWNFAIL?subselect.Bug-6700
+subselect.Bug-6700
 alter_table_set_schema.Bug-6701
 crash-in-rel_dependencies.Bug-6703
 prepared-merge-statement.Bug-6706
+view-where-cast-error.Bug-6712
+
diff --git a/sql/test/BugTracker-2019/Tests/view-where-cast-error.Bug-6712.sql 
b/sql/test/BugTracker-2019/Tests/view-where-cast-error.Bug-6712.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2019/Tests/view-where-cast-error.Bug-6712.sql
@@ -0,0 +1,12 @@
+start transaction;
+CREATE TABLE x ("id" INTEGER, "attribute" CHARACTER LARGE OBJECT, "value" 
CHARACTER LARGE OBJECT);
+INSERT INTO x VALUES (1, 'version', '3.15.0');
+INSERT INTO x VALUES (1, 'executiontime', '100848');
+INSERT INTO x VALUES (2, 'version', '3.15.0');
+INSERT INTO x VALUES (2, 'executiontime', '54340');
+INSERT INTO x VALUES (3, 'version', '3.15.0');
+INSERT INTO x VALUES (3, 'executiontime', '96715');
+create view executiontimes as select * from x where attribute = 
'executiontime';
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to