Update of /cvsroot/monetdb/pathfinder/runtime
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3350

Modified Files:
      Tag: xquery-decomposition
        xrpc_client.mx 
Log Message:
- adopt Stefan's tips: used rangesplit to split item|kind per container
(Thanks!).

- a lot of corrections to get this thing working



Index: xrpc_client.mx
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/runtime/xrpc_client.mx,v
retrieving revision 1.41.2.8
retrieving revision 1.41.2.9
diff -u -d -r1.41.2.8 -r1.41.2.9
--- xrpc_client.mx      8 Mar 2008 21:17:27 -0000       1.41.2.8
+++ xrpc_client.mx      10 Mar 2008 02:01:13 -0000      1.41.2.9
@@ -94,94 +94,40 @@
         BAT[void, dbl] dbl_values,
         BAT[void, dbl] dec_values,
         BAT[void, str] str_values) : oid {
-
     var maxnconts := ws.fetch(0).count();
     # split used_<item|kind> into multiple BATs according to their container 
IDs
     var uitems := bat(oid, bat, maxnconts); # container ID in head
     var ukinds := bat(oid, bat, maxnconts);
-    var conts := used_kind.[int]().[>>](6).tsort(); # [oid,int]: container IDs 
in tail
-    var nconts := conts.tunique().count();
-    if(nconts = 1){ # all items are from the same container
-        uitems.insert(conts.fetch(0).oid(), used_item);
-        ukinds.insert(conts.fetch(0).oid(), used_kind);
-    } else {
-        # sort used_<item|kind> on container ID
-        var itemcont := used_item.reverse().join(conts).reverse().tmark([EMAIL 
PROTECTED]);
-        var kindcont := used_kind.reverse().join(conts).reverse().tmark([EMAIL 
PROTECTED]);
-
-        var curcont := conts.fetch(0);
-        var tmpitem := bat(void, oid).seqbase([EMAIL PROTECTED]);
-        var tmpkind := bat(void, int).seqbase([EMAIL PROTECTED]);
-
-        conts := conts.tmark([EMAIL PROTECTED]); # conts[void,int]
-        [EMAIL PROTECTED](){
-            # start of next container, save items|kinds of previous container
-            if($t != curcont) {
-                curcont := $t;
-                uitems.insert(curcont, tmpitem);
-                ukinds.insert(curcont, tmpkind);
-                tmpitem := bat(void, oid).seqbase([EMAIL PROTECTED]);
-                tmpkind := bat(void, int).seqbase([EMAIL PROTECTED]);
-            }
-
-            tmpitem.append(itemcont.fetch($h));
-            tmpkind.append(kindcont.fetch($h));
-        }
-        uitems.insert(curcont, tmpitem);
-        ukinds.insert(curcont, tmpkind);
-    }
+    var conts := get_container([int](used_kind)); # [oid,int]: container IDs 
in tail
+    var unq_conts := tunique(conts).hmark([EMAIL PROTECTED]);
+    var nconts := count(unq_conts);
+    var rs := rangesplit(conts, nconts).tmark([EMAIL 
PROTECTED]).reverse().join(unq_conts).reverse();
+    uitems := rs.[mirror]().[leftfetchjoin](const used_item);
+    uitems := [tmark](uitems, const [EMAIL PROTECTED]);
+    ukinds := rs.[mirror]().[leftfetchjoin](const used_kind);
+    ukinds := [tmark](ukinds, const [EMAIL PROTECTED]);
 
     # split returned_<item|kind> into multiple BATs according to their 
container IDs
     var ritems := bat(oid, bat, maxnconts); # container ID in head
     var rkinds := bat(oid, bat, maxnconts);
-    conts := returned_kind.[int]().[>>](6).tsort(); # [oid,int]: container IDs 
in tail
-    nconts := conts.tunique().count();
-    if(nconts = 1){ # all items are from the same container
-        ritems.insert(conts.fetch(0).oid(), returned_item);
-        rkinds.insert(conts.fetch(0).oid(), returned_kind);
-    } else {
-        # sort used_<item|kind> on container ID
-        var itemcont := 
returned_item.reverse().join(conts).reverse().tmark([EMAIL PROTECTED]);
-        var kindcont := 
returned_kind.reverse().join(conts).reverse().tmark([EMAIL PROTECTED]);
-
-        var curcont := conts.fetch(0);
-        var tmpitem := bat(void, oid).seqbase([EMAIL PROTECTED]);
-        var tmpkind := bat(void, int).seqbase([EMAIL PROTECTED]);
-
-        conts := conts.tmark([EMAIL PROTECTED]); # conts[void,int]
-        [EMAIL PROTECTED](){
-            # start of next container, save items|kinds of previous container
-            if($t != curcont) {
-                curcont := $t;
-                ritems.insert(curcont, tmpitem);
-                rkinds.insert(curcont, tmpkind);
-                tmpitem := bat(void, oid).seqbase([EMAIL PROTECTED]);
-                tmpkind := bat(void, int).seqbase([EMAIL PROTECTED]);
-            }
-
-            tmpitem.append(itemcont.fetch($h));
-            tmpkind.append(kindcont.fetch($h));
-        }
-        ritems.insert(curcont, tmpitem);
-        rkinds.insert(curcont, tmpkind);
-    }
+    conts := get_container([int](returned_kind)); # [oid,int]: container IDs 
in tail
+    unq_conts := tunique(conts).hmark([EMAIL PROTECTED]);
+    nconts := count(unq_conts);
+    rs := rangesplit(conts, nconts).tmark([EMAIL 
PROTECTED]).reverse().join(unq_conts).reverse();
+    ritems := rs.[mirror]().[leftfetchjoin](const returned_item);
+    ritems := [tmark](ritems, const [EMAIL PROTECTED]);
+    rkinds := rs.[mirror]().[leftfetchjoin](const returned_kind);
+    rkinds := [tmark](rkinds, const [EMAIL PROTECTED]);
 
     # align uitems|kinds and ritems|kinds,
     # fill missing container with emtpybat
     var emptybat := bat(void,void,0);
-    [EMAIL PROTECTED](){
-        var err := CATCH({ritems.find($h);});
-        if(err.search("not found") >= 0){
-            ritems.insert($h, emptybat);
-        }
-    }
-    [EMAIL PROTECTED](){
-        var err := CATCH({uitems.find($h);});
-        if(err.search("not found") >= 0){
-            uitems.insert($h, emptybat);
-        }
-    }
-
+    var usedonly := kdiff(uitems,ritems).project(emptybat);
+    ritems.access(BAT_WRITE).insert(usedonly);
+    rkinds.access(BAT_WRITE).insert(usedonly);
+    var returnedonly := kdiff(ritems,uitems).project(emptybat);
+    uitems.access(BAT_WRITE).insert(returnedonly);
+    ukinds.access(BAT_WRITE).insert(returnedonly);
 
     var rpcres := http_post(options, dst, moduleNS, location, method,
                     updCall, arity, iterc, ws, 
@@ -313,7 +259,7 @@
                     if (count(tpe_attr_attr) != 1) {
                         ERROR("get_rpc_res (batloop %d): " +
                               "\"atomic-value\" should only have one " +
-                              "\"xsi:type\" attributed!\n", pre);
+                              "\"xsi:type\" attribute!\n", pre);
                     }
                     var tpe_attr_prop := tpe_attr_attr.join(attr_prop);
                     subtpe := tpe_attr_prop.join(prop_val).fetch(0);
@@ -632,14 +578,6 @@
             "CMDhttp_post: argc must not be negative (<0).\n");                
             \
     ERRORcheck(!BAThdense(ws),                                                 
             \
             "CMDhttp_post: head of 'ws' must be dense.\n");                    
             \
-    ERRORcheck(!BAThdense(used_item),                                          
             \
-            "CMDhttp_post: head of 'used_item' must be dense.\n");             
             \
-    ERRORcheck(!BAThdense(used_kind),                                          
             \
-            "CMDhttp_post: head of 'used_kind' must be dense.\n");             
             \
-    ERRORcheck(!BAThdense(returned_item),                                      
             \
-            "CMDhttp_post: head of 'returned_item' must be dense.\n");         
             \
-    ERRORcheck(!BAThdense(returned_kind),                                      
             \
-            "CMDhttp_post: head of 'returned_kind' must be dense.\n");         
             \
     ERRORcheck(!BAThdense(upath_item),                                         
             \
             "CMDhttp_post: head of 'upath_item' must be dense.\n");            
             \
     ERRORcheck(!BAThdense(rpath_item),                                         
             \
@@ -703,8 +641,8 @@
 typedef struct {
     oid contIDold;
     oid contIDnew;
-    BAT *nid_pre;
-    oid *pre; /* pointer to PRE values in 'nid_pre' */
+    BAT *pre_nid;
+    oid *pre_nidT; /* directly points to the tail of 'pre_nid' */
 } projection_mapping;
 
 /* Create a HTTP client socket.
@@ -1029,26 +967,21 @@
         BAT *str_values)
 {
     projection_mapping *pm = NULL;
-    oid i, nconts = oid_nil;
-    oid *curcontIDs = NULL;
+    oid i, nconts = oid_nil, curcontID = oid_nil;
     BATiter uitemsi, ukindsi, ritemsi, rkindsi;
     BAT *uitems = NULL, *ukinds = NULL, *ritems = NULL, *rkinds = NULL;
     BAT *pre_nid = NULL;
     BUN uitem_base, ukind_base, ritem_base, rkind_base;
     int contIDnew = int_nil;
+    char printmode[64] = "xml-noheader-root-xrpc:fragment\0";
 
     assert(BATcount(used_item) > 0 && BATcount(returned_item)); /* may not be 
empty */
     assert(BATcount(used_item) == BATcount(returned_item)); /* must be aligned 
*/
 
     /* Serialize node-typed parameter's in xrpc:fragments */
     nconts = BATcount(used_item);
-    if(!(curcontIDs = GDKmalloc(nconts * sizeof(oid)))){
-        GDKerror("serialize_fragments: failed to malloc 'curcontIDs'\n");
-        return NULL;
-    }
     if(!(pm = GDKmalloc((nconts+1) * sizeof(projection_mapping)))){
         GDKerror("serialize_fragments: failed to malloc 'pm'\n");
-        GDKfree(curcontIDs);
         return NULL;
     }
     pm[nconts].contIDold = pm[nconts].contIDnew = oid_nil;
@@ -1063,51 +996,41 @@
     ritem_base = BUNfirst(returned_item);
     rkind_base = BUNfirst(returned_kind);
 
-    curcontIDs = (oid*) Hloc(used_item, BUNfirst(used_item));
     for(i = 0; i < nconts; i++){
+        curcontID = *(oid*)BUNhead(uitemsi, uitem_base + i);
         uitems = BATdescriptor(*(bat*)BUNtail(uitemsi, uitem_base + i));
         ukinds = BATdescriptor(*(bat*)BUNtail(ukindsi, ukind_base + i));
         ritems = BATdescriptor(*(bat*)BUNtail(ritemsi, ritem_base + i));
         rkinds = BATdescriptor(*(bat*)BUNtail(rkindsi, rkind_base + i));
 
-        str2buf(b, "<xrpc:fragments><xrpc:fragment>");
+        str2buf(b, "<xrpc:fragments>");
         contIDnew = runtime_doc_projection2stream(NULL,
-                "xml-nohead-root-xrpc:fragment", bs, ws,
+                printmode, bs, ws,
                 uitems, ukinds, ritems, rkinds,
                 int_values, dbl_values, dec_values, str_values);
-        str2buf(b, "</xrpc:fragment></xrpc:fragments>");
+        str2buf(b, "</xrpc:fragments>");
         BBPunfix(BBPcacheid(uitems));
         BBPunfix(BBPcacheid(ukinds));
         BBPunfix(BBPcacheid(ritems));
         BBPunfix(BBPcacheid(rkinds));
         if(contIDnew < 0){
             GDKerror("serialize_fragments: failed to project nodes in 
container "OIDFMT"\n",
-                    curcontIDs[i]);
-            GDKfree(curcontIDs);
+                    curcontID);
             GDKfree(pm);
             return NULL;
         }
 
         if(!(pre_nid = getBatFromContainer(ws, PRE_NID, contIDnew))) {
-            GDKfree(curcontIDs);
             GDKfree(pm);
             return NULL;
         }
-        pm[i].contIDold = curcontIDs[i];
+        pm[i].contIDold = curcontID;
         pm[i].contIDnew = (oid)contIDnew;
-        pm[i].nid_pre = BATsort(BATmirror(pre_nid));
+        pm[i].pre_nid = pre_nid;
+        pm[i].pre_nidT = (oid*) Tloc(pre_nid, BUNfirst(pre_nid));
         BBPunfix(BBPcacheid(pre_nid));
-        if(!pm[i].nid_pre){
-            GDKerror("serialize_fragments: failed to sort PRE_NID BAT of 
container "OIDFMT"\n",
-                    contIDnew);
-            GDKfree(curcontIDs);
-            GDKfree(pm);
-            return NULL;
-        }
-        pm[i].pre = (oid*) Tloc(pm[i].nid_pre, BUNfirst(pm[i].nid_pre));
     }
 
-    GDKfree(curcontIDs);
     return pm;
 }
 
@@ -1157,9 +1080,9 @@
 
     /* BATs needed for serializing attributes */
     BAT *pre_nid = NULL, *attr_own = NULL, *attr_qn = NULL;
-    BAT *qn_prefix = NULL, *qn_loc = NULL;
+    BAT *qn_prefix = NULL, *qn_uri = NULL, *qn_loc = NULL;
     oid *pre_nid_lst = NULL, *attr_own_lst = NULL, *attr_qn_lst = NULL;
-    BATiter strValsi, qn_prefixi, qn_loci, upathi, rpathi;
+    BATiter strValsi, qn_prefixi, qn_urii, qn_loci, upathi, rpathi;
     BUN upath_base, rpath_base;
 
     lng time_xrpcClntSeria = 0, time_xrpcClntDeSeria = 0;
@@ -1252,14 +1175,14 @@
     i = BATcount(upath_item);
     a = BATcount(rpath_item);
     if(i > 0 || a > 0) {
-        str2buf(b, "<xrpc:project-paths>");
+        str2buf(b, "<xrpc:projection-paths>");
         if(i > 0) {
             upathi = bat_iterator(upath_item);
             upath_base = BUNfirst(upath_item);
             for(cnt = 0; cnt < (size_t) i; cnt++){
                 b->pos += snprintf((b->buf + b->pos), (b->len - b->pos),
                         "<xrpc:used-path>%s</xrpc:used-path>",
-                        BUNtail(upathi, upath_base + cnt));
+                        BUNtail(strValsi, *(oid*)BUNtail(upathi, upath_base + 
cnt)));
             }
         }
         if(a > 0) {
@@ -1267,11 +1190,11 @@
             rpath_base = BUNfirst(rpath_item);
             for(cnt = 0; cnt < (size_t) a; cnt++){
                 b->pos += snprintf((b->buf + b->pos), (b->len - b->pos),
-                        "<xrpc:used-path>%s</xrpc:used-path>",
-                        BUNtail(rpathi, rpath_base + cnt));
+                        "<xrpc:returned-path>%s</xrpc:returned-path>",
+                        BUNtail(strValsi, *(oid*)BUNtail(rpathi, rpath_base + 
cnt)));
             }
         }
-        str2buf(b, "</xrpc:project-paths>");
+        str2buf(b, "</xrpc:projection-paths>");
     }
 
     for (my_iter = 0; my_iter < iterc; my_iter++) {
@@ -1358,12 +1281,14 @@
                         attr_own  = getBatFromContainer(ws, ATTR_OWN, contID);
                         attr_qn   = getBatFromContainer(ws, ATTR_QN, contID);
                         qn_prefix = getBatFromContainer(ws, QN_PREFIX, contID);
+                        qn_uri    = getBatFromContainer(ws, QN_URI, contID);
                         qn_loc    = getBatFromContainer(ws, QN_LOC, contID);
-                        if( !pre_nid || !attr_own || !attr_qn || !qn_prefix || 
!qn_loc ){
+                        if( !pre_nid || !attr_own || !attr_qn || !qn_prefix || 
!qn_uri || !qn_loc ){
                             if(pre_nid)   BBPunfix(BBPcacheid(pre_nid));
                             if(attr_own)  BBPunfix(BBPcacheid(attr_own));
                             if(attr_qn)   BBPunfix(BBPcacheid(attr_qn));
                             if(qn_prefix) BBPunfix(BBPcacheid(qn_prefix));
+                            if(qn_uri)    BBPunfix(BBPcacheid(qn_uri));
                             if(qn_loc)    BBPunfix(BBPcacheid(qn_loc));
                             clean_up(sock, out, bs, b, argcnt, iterc, pm);
                             return GDK_FAIL;
@@ -1372,6 +1297,7 @@
                         attr_own_lst = (oid*) Tloc(attr_own, 
BUNfirst(attr_own));
                         attr_qn_lst  = (oid*) Tloc(attr_qn, BUNfirst(attr_qn));
                         qn_prefixi = bat_iterator(qn_prefix);
+                        qn_urii = bat_iterator(qn_uri);
                         qn_loci = bat_iterator(qn_loc);
 
                         owner = attr_own_lst[item]; /* nid of attr_own */
@@ -1385,21 +1311,31 @@
                         }
 
                         char *prefix = (char*)BUNtail(qn_prefixi, 
attr_qn_lst[item]);
+                        char *uri    = (char*)BUNtail(qn_urii,    
attr_qn_lst[item]);
                         char *loc    = (char*)BUNtail(qn_loci,    
attr_qn_lst[item]);
                         for(i = 0; pm[i].contIDold != oid_nil; i++){
+                            /* in a projected doc, 'pre' becomes 'nid',
+                             * so need to find the new 'pre' of the old
+                             * 'pre' */
+                            for(a = 0; (size_t) a < BATcount(pm[i].pre_nid); 
a++) {
+                                if(owner == pm[i].pre_nidT[a]) {
+                                    owner = a;
+                                    break;
+                                }
+                            }
                             if(pm[i].contIDold == (unsigned int)contID){
                                 if(prefix && *prefix)
                                     b->pos += snprintf((b->buf + b->pos), 
(b->len - b->pos),
                                             "<xrpc:attribute 
xrpc:fragsid=\"%lld\""
                                             " xrpc:nodeid=\""OIDFMT"\" "
-                                            " xrpc:atrr-qname=\"%s:%s\"/>",
-                                            i+1, pm[i].pre[owner]+1, prefix, 
loc);
+                                            " xrpc:attr-qname=\"%s:%s:%s\"/>",
+                                            i+1, owner+1, prefix, uri, loc);
                                 else
                                     b->pos += snprintf((b->buf + b->pos), 
(b->len - b->pos),
                                             "<xrpc:attribute 
xrpc:fragsid=\"%lld\""
                                             " xrpc:nodeid=\""OIDFMT"\" "
-                                            " xrpc:atrr-qname=\"%s\"/>",
-                                            i+1, pm[i].pre[owner]+1, loc);
+                                            " xrpc:attr-qname=\"%s\"/>",
+                                            i+1, owner+1, loc);
                                 break;
                             }
                         }
@@ -1419,21 +1355,30 @@
                             return GDK_FAIL;
                         }
                         for(i = 0; pm[i].contIDold != oid_nil; i++){
+                            /* found the 'pm' entry */
                             if(pm[i].contIDold == (oid) contID) break;
                         }
+                        /* in a projected doc, 'pre' becomes 'nid', so
+                         * need to find the new 'pre' of the old 'pre' */
+                        for(a = 0; (size_t) a < BATcount(pm[i].pre_nid); a++) {
+                            if(item == pm[i].pre_nidT[a]) {
+                                item = a;
+                                break;
+                            }
+                        }
                         switch(elem_kind) {
                             case 0: /* ELEMENT */
                                 b->pos += snprintf((b->buf + b->pos), (b->len 
- b->pos),
                                         "<xrpc:element xrpc:fragsid=\"%lld\""
                                         " xrpc:nodeid=\""OIDFMT"\"/>",
-                                        i+1, pm[i].pre[item]+1);
+                                        i+1, item+1);
                                 break;
                             case 1: /* TEXT */
                                 /*
                                 b->pos += snprintf((b->buf + b->pos), (b->len 
- b->pos),
                                         "<xrpc:text xrpc:fragsid=\"%lld\""
                                         " xrpc:nodeid=\""OIDFMT"\"/>",
-                                        i+1, pm[i].pre[item]+1);
+                                        i+1, item+1);
                                 */
                                 GDKerror("CMDhttp_post: 
call%d/sequence%d/item%d has "
                                         "type TEXT, not supported yet!\n", 
my_iter, my_argc);
@@ -1444,19 +1389,19 @@
                                 b->pos += snprintf((b->buf + b->pos), (b->len 
- b->pos),
                                         "<xrpc:comment xrpc:fragsid=\"%lld\""
                                         " xrpc:nodeid=\""OIDFMT"\"/>",
-                                        i+1, pm[i].pre[item]+1);
+                                        i+1, item+1);
                                 break;
                             case 3: /* PI */
                                 b->pos += snprintf((b->buf + b->pos), (b->len 
- b->pos),
                                         "<xrpc:pi xrpc:fragsid=\"%lld\""
                                         " xrpc:nodeid=\""OIDFMT"\"/>",
-                                        i+1, pm[i].pre[item]+1);
+                                        i+1, item+1);
                                 break;
                             case 4: /* DOCUMENT */
                                 b->pos += snprintf((b->buf + b->pos), (b->len 
- b->pos),
                                         "<xrpc:document xrpc:fragsid=\"%lld\""
                                         " xrpc:nodeid=\""OIDFMT"\"/>",
-                                        i+1, pm[i].pre[item]);
+                                        i+1, item);
                                 break;
                             case 5: /* COLLECTION */
                                 GDKerror("CMDhttp_post: 
call%d/sequence%d/item%d has "


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to