Changeset: 9bb4efad1778 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9bb4efad1778
Modified Files:
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_upgrades.c
        sql/server/rel_schema.c
        sql/storage/store.c
        tools/monetdbe/monetdbe.c
Branch: default
Log Message:

Merged with Jul2021


diffs (truncated from 3493 to 300 lines):

diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -2436,6 +2436,7 @@ JSONgroupStr(str *ret, const bat *bid)
                GDKfree(buf);
                throw(MAL, "json.group", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
        }
+       assert(maxlen > 256); /* make sure every floating point fits on the 
dense case */
        assert(b->ttype == TYPE_str || b->ttype == TYPE_dbl);
 
        bi = bat_iterator(b);
@@ -2447,7 +2448,8 @@ JSONgroupStr(str *ret, const bat *bid)
 
                                if (strNil(v))
                                        continue;
-                               JSON_AGGR_CHECK_NEXT_LENGTH(strlen(v) * 2 + 5); 
/* opening bracket and optional ',' */
+                               /* '[' or ',' plus space and null terminator 
and " ]" final string */
+                               JSON_AGGR_CHECK_NEXT_LENGTH(strlen(v) * 2 + 7);
                                char *dst = buf + buflen, *odst = dst;
                                if (buflen == 0)
                                        *dst++ = '[';
@@ -2457,7 +2459,6 @@ JSONgroupStr(str *ret, const bat *bid)
                                *dst++ = '"';
                                JSON_STR_CPY;
                                *dst++ = '"';
-                               *dst = '\0';
                                buflen += (dst - odst);
                        }
                        break;
@@ -2467,9 +2468,16 @@ JSONgroupStr(str *ret, const bat *bid)
 
                                if (is_dbl_nil(val))
                                        continue;
-                               JSON_AGGR_CHECK_NEXT_LENGTH(128 + 3); /* 
opening bracket and optional ',' */
-                               len = snprintf(buf + buflen, maxlen - buflen, 
"%c %f", buflen == 0 ? '[' : ',', val);
-                               buflen += len;
+                               /* '[' or ',' plus space and null terminator 
and " ]" final string */
+                               JSON_AGGR_CHECK_NEXT_LENGTH(130 + 6);
+                               char *dst = buf + buflen;
+                               if (buflen == 0)
+                                       *dst++ = '[';
+                               else
+                                       *dst++ = ',';
+                               *dst++ = ' ';
+                               buflen += 2;
+                               buflen += snprintf(buf + buflen, maxlen - 
buflen, "%f", val);
                        }
                        break;
                default:
@@ -2477,9 +2485,8 @@ JSONgroupStr(str *ret, const bat *bid)
        }
        bat_iterator_end(&bi);
        BBPunfix(b->batCacheid);
-       assert(maxlen > buflen + 3);
        if (buflen > 0)
-               buflen += snprintf(buf + buflen, maxlen - buflen, " ]");
+               strcpy(buf + buflen, " ]");
        else
                strcpy(buf, str_nil);
        *ret = GDKstrdup(buf);
@@ -2509,6 +2516,7 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
        size_t buflen, maxlen = BUFSIZ, len;
        dbl *restrict vals;
 
+       assert(maxlen > 256); /* make sure every floating point fits on the 
dense case */
        assert(b->ttype == TYPE_str || b->ttype == TYPE_dbl);
        if ((err = BATgroupaggrinit(b, g, e, s, &min, &max, &ngrp, &ci, 
&ncand)) != NULL) {
                return err;
@@ -2617,7 +2625,13 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                                                        nils = 1;
                                                }
                                        } else {
-                                               snprintf(buf, maxlen, "[ %f ]", 
val);
+                                               char *dst = buf;
+                                               *dst++ = '[';
+                                               *dst++ = ' ';
+                                               dst += sprintf(dst, "%f", val);
+                                               *dst++ = ' ';
+                                               *dst++ = ']';
+                                               *dst = '\0';
                                        }
                                        if (bunfastapp_nocheckVAR(bn, buf) != 
GDK_SUCCEED)
                                                goto bunins_failed;
@@ -2637,12 +2651,11 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                prev = grps[0];
                for (p = 0, q = BATcount(g); p <= q; p++) {
                        if (p == q || grps[p] != prev) {
-                               assert(maxlen > buflen + 3);
                                if (isnil) {
                                        strcpy(buf, str_nil);
                                        nils = 1;
                                } else if (buflen == 0) {
-                                       strcpy(buf + buflen, "[  ]");
+                                       strcpy(buf, "[  ]");
                                } else {
                                        strcpy(buf + buflen, " ]");
                                }
@@ -2669,7 +2682,8 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                                                continue;
                                        isnil = 1;
                                } else {
-                                       JSON_AGGR_CHECK_NEXT_LENGTH(strlen(v) * 
2 + 5);
+                                       /* '[' or ',' plus space and null 
terminator and " ]" final string */
+                                       JSON_AGGR_CHECK_NEXT_LENGTH(strlen(v) * 
2 + 7);
                                        char *dst = buf + buflen, *odst = dst;
                                        if (buflen == 0)
                                                *dst++ = '[';
@@ -2679,7 +2693,6 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                                        *dst++ = '"';
                                        JSON_STR_CPY;
                                        *dst++ = '"';
-                                       *dst = '\0';
                                        buflen += (dst - odst);
                                }
                        } break;
@@ -2690,9 +2703,16 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                                                continue;
                                        isnil = 1;
                                } else {
-                                       JSON_AGGR_CHECK_NEXT_LENGTH(128 + 3);
-                                       len = snprintf(buf + buflen, maxlen - 
buflen, "%c %f", buflen == 0 ? '[' : ',', val);
-                                       buflen += len;
+                                       /* '[' or ',' plus space and null 
terminator and " ]" final string */
+                                       JSON_AGGR_CHECK_NEXT_LENGTH(130 + 6);
+                                       char *dst = buf + buflen;
+                                       if (buflen == 0)
+                                               *dst++ = '[';
+                                       else
+                                               *dst++ = ',';
+                                       *dst++ = ' ';
+                                       buflen += 2;
+                                       buflen += snprintf(buf + buflen, maxlen 
- buflen, "%f", val);
                                }
                        } break;
                        default:
@@ -2712,7 +2732,8 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                                        nils = 1;
                                        break;
                                }
-                               JSON_AGGR_CHECK_NEXT_LENGTH(strlen(v) * 2 + 5);
+                               /* '[' or ',' plus space and null terminator 
and " ]" final string */
+                               JSON_AGGR_CHECK_NEXT_LENGTH(strlen(v) * 2 + 7);
                                char *dst = buf + buflen, *odst = dst;
                                if (buflen == 0)
                                        *dst++ = '[';
@@ -2722,7 +2743,6 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                                *dst++ = '"';
                                JSON_STR_CPY;
                                *dst++ = '"';
-                               *dst = '\0';
                                buflen += (dst - odst);
                        }
                        break;
@@ -2735,19 +2755,25 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                                        nils = 1;
                                        break;
                                }
-                               JSON_AGGR_CHECK_NEXT_LENGTH(128 + 3);
-                               len = snprintf(buf + buflen, maxlen - buflen, 
"%c %f", buflen == 0 ? '[' : ',', val);
-                               buflen += len;
+                               /* '[' or ',' plus space and null terminator 
and " ]" final string */
+                               JSON_AGGR_CHECK_NEXT_LENGTH(130 + 6);
+                               char *dst = buf + buflen;
+                               if (buflen == 0)
+                                       *dst++ = '[';
+                               else
+                                       *dst++ = ',';
+                               *dst++ = ' ';
+                               buflen += 2;
+                               buflen += snprintf(buf + buflen, maxlen - 
buflen, "%f", val);
                        }
                        break;
                default:
                        assert(0);
                }
-               assert(maxlen > buflen + 3);
                if (nils) {
                        strcpy(buf, str_nil);
                } else if (buflen == 0) {
-                       strcpy(buf + buflen, "[  ]");
+                       strcpy(buf, "[  ]");
                } else {
                        strcpy(buf + buflen, " ]");
                }
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -340,11 +340,15 @@ create_table_or_view(mvc *sql, char *sna
        if (temp == SQL_DECLARED_TABLE && ol_length(t->keys))
                throw(SQL, "sql.catalog", SQLSTATE(42000) "%s %s: '%s' cannot 
have constraints", action, obj, t->base.name);
 
-       nt = sql_trans_create_table(sql->session->tr, s, tname, t->query, 
t->type, t->system, temp, t->commit_action,
-                                                               t->sz, 
t->properties);
-       if (!nt)
-               throw(SQL, "sql.catalog", SQLSTATE(42000) "%s %s: '%s' name 
conflicts", action, obj, t->base.name);
-
+       switch (sql_trans_create_table(&nt, sql->session->tr, s, tname, 
t->query, t->type, t->system, temp, t->commit_action, t->sz, t->properties)) {
+               case -1:
+                       throw(SQL, "sql.catalog", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               case -2:
+               case -3:
+                       throw(SQL, "sql.catalog", SQLSTATE(42000) "%s %s: '%s' 
name conflicts", action, obj, t->base.name);
+               default:
+                       break;
+       }
        osa = sql->sa;
        sql->sa = sql->ta;
        /* first check default values */
@@ -416,7 +420,7 @@ create_table_or_view(mvc *sql, char *sna
                }
        }
        check = sql_trans_set_partition_table(sql->session->tr, nt);
-       if (check == -1) {
+       if (check == -4) {
                sql->sa = osa;
                throw(SQL, "sql.catalog", SQLSTATE(42000) "CREATE TABLE: %s_%s: 
the partition's expression is too long", s->base.name, t->base.name);
        } else if (check) {
@@ -558,8 +562,8 @@ str
 create_table_from_emit(Client cntxt, char *sname, char *tname, sql_emit_col 
*columns, size_t ncols)
 {
        size_t i;
-       sql_table *t;
-       sql_schema *s;
+       sql_table *t = NULL;
+       sql_schema *s = NULL;
        mvc *sql = NULL;
        str msg = MAL_SUCCEED;
 
@@ -574,8 +578,15 @@ create_table_from_emit(Client cntxt, cha
                throw(SQL, "sql.catalog", SQLSTATE(3F000) "CREATE TABLE: no 
such schema '%s'", sname);
        if (!mvc_schema_privs(sql, s))
                throw(SQL, "sql.catalog", SQLSTATE(42000) "CREATE TABLE: Access 
denied for %s to schema '%s'", get_string_global_var(sql, "current_user"), 
s->base.name);
-       if (!(t = mvc_create_table(sql, s, tname, tt_table, 0, 
SQL_DECLARED_TABLE, CA_COMMIT, -1, 0)))
-               throw(SQL, "sql.catalog", SQLSTATE(3F000) "CREATE TABLE: could 
not create table '%s'", tname);
+       switch (mvc_create_table(&t, sql, s, tname, tt_table, 0, 
SQL_DECLARED_TABLE, CA_COMMIT, -1, 0)) {
+               case -1:
+                       throw(SQL, "sql.catalog", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               case -2:
+               case -3:
+                       throw(SQL, "sql.catalog", SQLSTATE(42000) "CREATE 
TABLE: transaction conflict detected");
+               default:
+                       break;
+       }
 
        for (i = 0; i < ncols; i++) {
                BAT *b = columns[i].b;
@@ -594,8 +605,15 @@ create_table_from_emit(Client cntxt, cha
 
                if (columns[i].name && columns[i].name[0] == '%')
                        throw(SQL, "sql.catalog", SQLSTATE(42000) "CREATE 
TABLE: generated labels not allowed in column names, use an alias instead");
-               if (!(col = mvc_create_column(sql, t, columns[i].name, &tpe)))
-                       throw(SQL, "sql.catalog", SQLSTATE(3F000) "CREATE 
TABLE: could not create column %s", columns[i].name);
+               switch (mvc_create_column(&col, sql, t, columns[i].name, &tpe)) 
{
+                       case -1:
+                               throw(SQL, "sql.catalog", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+                       case -2:
+                       case -3:
+                               throw(SQL, "sql.catalog", SQLSTATE(42000) 
"CREATE TABLE: transaction conflict detected");
+                       default:
+                               break;
+               }
        }
        if ((msg = create_table_or_view(sql, sname, t->base.name, t, 0, 0)) != 
MAL_SUCCEED)
                return msg;
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -555,41 +555,46 @@ create_trigger(mvc *sql, char *sname, ch
                                break;
                }
        }
-       if ((tri = mvc_create_trigger(sql, t, triggername, time, orientation, 
event, old_name, new_name, condition, query))) {
-               char *buf;
-               sql_rel *r = NULL;
-               sql_allocator *sa = sql->sa;
+       switch (mvc_create_trigger(&tri, sql, t, triggername, time, 
orientation, event, old_name, new_name, condition, query)) {
+               case -1:
+                       throw(SQL,"sql.create_trigger", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               case -2:
+               case -3:
+                       throw(SQL,"sql.create_trigger", SQLSTATE(42000) "%s: 
transaction conflict detected", base);
+               default: {
+                       char *buf;
+                       sql_rel *r = NULL;
+                       sql_allocator *sa = sql->sa;
 
-               if (!(sql->sa = sa_create(sql->pa))) {
-                       sql->sa = sa;
-                       throw(SQL, "sql.create_trigger", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-               }
-               if (!(buf = sa_strdup(sql->sa, query))) {
-                       sa_destroy(sql->sa);
-                       sql->sa = sa;
-                       throw(SQL, "sql.create_trigger", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-               }
-               r = rel_parse(sql, s, buf, m_deps);
-               if (r)
-                       r = sql_processrelation(sql, r, 0, 0);
-               if (r) {
-                       list *blist = rel_dependencies(sql, r);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to