Changeset: 87dd4dfd4c5f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/87dd4dfd4c5f
Modified Files:
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/sql_statement.c
Branch: nested
Log Message:

insert vectors from array literal


diffs (146 lines):

diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -2347,13 +2347,27 @@ ARRAYparser(allocator *ma, char **S, Col
                /* insert values */
                if (t->type->composite) {
                        msg = TUPLEparser(ma, &s, cols, nr, &i, t);
+               } else if (t->multiset == MS_VECTOR) {
+                       for (size_t j=0; j < t->digits; j++) {
+                               msg = VALUEparser(ma, &s, cols, i, t, ',', '}');
+                               i++;
+                               skipspace(s);
+                               /* handle optinal ',' */
+                               if (*s && s[0] != ',')
+                                       break;
+                               s++;
+                               skipspace(s);
+                       }
                } else {
                        msg = VALUEparser(ma, &s, cols, i, t, ',', '}');
                        i++;
                }
                /* insert msid */
                if (t->multiset) {
-                       id = (int)BATcount(cols[i + (t->multiset == 
MS_ARRAY?2:1)].c);
+                       if (t->multiset == MS_VECTOR)
+                               id = (int)BATcount(cols[i].c);
+                       else
+                               id = (int)BATcount(cols[i + (t->multiset == 
MS_ARRAY?2:1)].c);
                        if (i < 0 || BUNappend(cols[i].c, &id, false) != 
GDK_SUCCEED)
                                throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"append failed");
                        i++;
@@ -2374,7 +2388,7 @@ ARRAYparser(allocator *ma, char **S, Col
                anr++;
        }
        /* insert row-id */
-       if (t->multiset) {
+       if (t->multiset == MS_ARRAY || t->multiset == MS_SETOF) {
                if (i < 0 || BUNappend(cols[i].c, &id, false) != GDK_SUCCEED)
                        throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "append 
failed");
                i++;
@@ -2410,12 +2424,23 @@ from_string_cols(Column *fmt, BAT **bats
        } else {
                if (i < 0 || i >= nr)
                        return -10;
-               fmt[i].frstr = &_ASCIIadt_frStr;
-               fmt[i].extra = t;
-               fmt[i].adt = t->type->localtype;
-               fmt[i].len = ATOMlen(fmt[i].adt, ATOMnilptr(fmt[i].adt));
-               fmt[i].c = bats[i];
-               i++;
+               if (t->multiset == MS_VECTOR) {
+                       for (size_t j=0; j<t->digits; j++) {
+                               fmt[i].frstr = &_ASCIIadt_frStr;
+                               fmt[i].extra = t;
+                               fmt[i].adt = t->type->localtype;
+                               fmt[i].len = ATOMlen(fmt[i].adt, 
ATOMnilptr(fmt[i].adt));
+                               fmt[i].c = bats[i];
+                               i++;
+                       }
+               } else {
+                       fmt[i].frstr = &_ASCIIadt_frStr;
+                       fmt[i].extra = t;
+                       fmt[i].adt = t->type->localtype;
+                       fmt[i].len = ATOMlen(fmt[i].adt, 
ATOMnilptr(fmt[i].adt));
+                       fmt[i].c = bats[i];
+                       i++;
+               }
        }
        if (t->multiset) {
                /* msid */
@@ -2438,14 +2463,16 @@ from_string_cols(Column *fmt, BAT **bats
                        fmt[i].c = bats[i];
                        i++;
                }
-               if (i < 0 || i >= nr)
-                       return -10;
-               fmt[i].frstr = &_ASCIIadt_frStr;
-               fmt[i].extra = sql_fetch_localtype(TYPE_int);
-               fmt[i].adt = TYPE_int;
-               fmt[i].len = ATOMlen(fmt[i].adt, ATOMnilptr(fmt[i].adt));
-               fmt[i].c = bats[i];
-               i++;
+               if (t->multiset == MS_ARRAY || t->multiset == MS_SETOF) {
+                       if (i < 0 || i >= nr)
+                               return -10;
+                       fmt[i].frstr = &_ASCIIadt_frStr;
+                       fmt[i].extra = sql_fetch_localtype(TYPE_int);
+                       fmt[i].adt = TYPE_int;
+                       fmt[i].len = ATOMlen(fmt[i].adt, 
ATOMnilptr(fmt[i].adt));
+                       fmt[i].c = bats[i];
+                       i++;
+               }
        }
        return i;
 }
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
@@ -4278,8 +4278,13 @@ composite_type_resultsize(sql_subtype *t
 {
        int nr = 0;
 
-       if (t->multiset)
-               nr += 2 + (t->multiset == MS_ARRAY);
+       if (t->multiset) {
+               if (t->multiset == MS_VECTOR) {
+                       return 1 + t->digits;
+               } else {
+                       nr += 2 + (t->multiset == MS_ARRAY);
+               }
+       }
        if (t->type->composite) {
                for (node *n = t->type->d.fields->h; n; n = n->next) {
                        sql_arg *a = n->data;
@@ -4300,7 +4305,7 @@ typedef struct result_subtype {
 static int
 composite_type_result(backend *be, InstrPtr q, sql_subtype *t, result_subtype 
*tps)
 {
-       int i = 0;
+       unsigned int i = 0;
        if (t->multiset || t->type->composite) {
                if (t->type->composite) {
                        for (node *n = t->type->d.fields->h; n; n = n->next) {
@@ -4310,6 +4315,12 @@ composite_type_result(backend *be, Instr
                                        return -1;
                                i += r;
                        }
+               } else if (t->multiset == MS_VECTOR) {
+                       for (; i < t->digits; i++) {
+                               q = pushReturn(be->mb, q, 
newTmpVariable(be->mb, newBatType(t->type->localtype)));
+                               tps[i].st = *t;
+                               tps[i].multiset = false;
+                       }
                } else {
                        q = pushReturn(be->mb, q, newTmpVariable(be->mb, 
newBatType(t->type->localtype)));
                        tps[i].st = *t;
@@ -4326,7 +4337,7 @@ composite_type_result(backend *be, Instr
                        tps[i++].multiset = false;
                }
                /* end with the rowid */
-               if (t->multiset) { /* id col : rowid */
+               if (t->multiset == MS_ARRAY || t->multiset == MS_SETOF) { /* id 
col : rowid */
                        q = pushReturn(be->mb, q, newTmpVariable(be->mb, 
newBatType(TYPE_int)));
                        tps[i].st = *sql_fetch_localtype(TYPE_int);
                        tps[i++].multiset = true;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to