Changeset: 36cdcb642edc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/36cdcb642edc
Modified Files:
        sql/backends/monet5/sql.c
Branch: nested
Log Message:

wip


diffs (88 lines):

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
@@ -5820,6 +5820,21 @@ insert_json_array(char **msg, JSON *js, 
 }
 
 static str
+insert_json_str(const char *jstr, BAT **bats, int cnt, sql_subtype *t)
+{
+       char *res = MAL_SUCCEED;
+       JSON *js = JSONparse(jstr);
+       if (!js)
+               throw(SQL, "insert_json_str", "JSONparse error");
+       if (t->multiset)
+               (void)insert_json_array(&res, js, bats, cnt, 0, 1, 1, t);
+       else
+               (void)insert_json_object(&res, js, bats, cnt, 0, 1, 1, t);
+       JSONfree(js);
+       return res;
+}
+
+static str
 SQLfrom_json(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        str msg = NULL;
@@ -5830,6 +5845,18 @@ SQLfrom_json(Client cntxt, MalBlkPtr mb,
        if ((msg = checkSQLContext(cntxt)) != NULL)
                return msg;
        int mtype = getArgType(mb, pci, pci->retc);
+       sql_subtype *t = *(sql_subtype**)getArgReference(stk, pci, pci->retc+1);
+
+       BAT **bats = (BAT**)GDKzalloc(sizeof(BAT*) * pci->retc);
+       if (!bats)
+               throw(SQL, "SQLfrom_json", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       for(int i = 0; i < pci->retc; i++) {
+               bats[i] = COLnew(0, getBatType(getArgType(mb, pci, i)), 10, 
TRANSIENT);
+               if (!bats[i])
+                       goto bailout;
+       }
+
+       (void)m;
 
        if (isaBatType(mtype)) {
                if(strcmp(BATatoms[getBatType(mtype)].name, "json") != 0 )
@@ -5840,38 +5867,18 @@ SQLfrom_json(Client cntxt, MalBlkPtr mb,
                BUN p, q;
                BATloop(b, p, q) {
                        const char *json = (const char *) BUNtail(bi, p);
-                       (void) json;
+                       if ((msg = insert_json_str(json, bats, pci->retc, t )) 
!= MAL_SUCCEED)
+                               goto bailout;
                }
                bat_iterator_end(&bi);
        } else {
                if (strcmp(BATatoms[mtype].name, "json") != 0)
                        throw(SQL, "SQLfrom_json", SQLSTATE(HY013) "Incorrect 
argument type");
-       }
-
-       str json = *(str*)getArgReference(stk, pci, pci->retc);
-       sql_subtype *t = *(sql_subtype**)getArgReference(stk, pci, pci->retc+1);
-
-       BAT **bats = (BAT**)GDKzalloc(sizeof(BAT*) * pci->retc);
-       if (!bats)
-               throw(SQL, "SQLfrom_json", SQLSTATE(HY013) MAL_MALLOC_FAIL);
-       for(int i = 0; i < pci->retc; i++) {
-               bats[i] = COLnew(0, getBatType(getArgType(mb, pci, i)), 10, 
TRANSIENT);
-               if (!bats[i])
+               str json = *(str*)getArgReference(stk, pci, pci->retc);
+               if ((msg = insert_json_str(json, bats, pci->retc, t )) != 
MAL_SUCCEED)
                        goto bailout;
        }
-       (void)m;
-
-       JSON *js = JSONparse(json);
-       if (!js) /* TODO output parser error ?? */
-               goto bailout;
-
-       if (t->multiset)
-               (void)insert_json_array(&msg, js, bats, pci->retc, 0, 1, 1, t);
-       else
-               (void)insert_json_object(&msg, js, bats, pci->retc, 0, 1, 1, t);
-       JSONfree(js);
-       if (msg)
-               goto bailout;
+
        for(int i = 0; i < pci->retc && bats[i]; i++) {
                *getArgReference_bat(stk, pci, i) = bats[i]->batCacheid;
                BBPkeepref(bats[i]);
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to