Update of /cvsroot/monetdb/MonetDB5/src/modules/mal
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15018/src/modules/mal

Modified Files:
      Tag: GDK-2
        batxml.mx 
Log Message:
propagated changes of Friday Aug 24 2007 - Tuesday Aug 28 2007
from the development trunk to the GDK-2 branch

There were inexplicable conflicts in src/modules/mal/batxml.mx and
src/modules/mal/Tests/inspect05.stable.out, neither of which had been
changed on the branch.  I just copied the HEAD version to the branch
to resolve the conflicts.


Index: batxml.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/mal/batxml.mx,v
retrieving revision 1.4.2.2
retrieving revision 1.4.2.3
diff -u -d -r1.4.2.2 -r1.4.2.3
--- batxml.mx   23 Aug 2007 13:32:49 -0000      1.4.2.2
+++ batxml.mx   28 Aug 2007 13:15:26 -0000      1.4.2.3
@@ -35,10 +35,18 @@
 address BATXMLstr2xml
 comment "Cast the string to an xml compliant string";
 
-pattern xml.str(src:bat[:oid,:xml]):bat[:oid,:str]
+command xml.str(src:bat[:oid,:xml]):bat[:oid,:str]
 address BATXMLxml2str
 comment "Cast the string to an xml compliant string";
 
+command xml.document(src:bat[:oid,:str]):bat[:oid,:xml]
+address BATXMLdocument
+comment "Parse the string as a document";
+
+command xml.content(src:bat[:oid,:str]):bat[:oid,:xml]
+address BATXMLcontent
+comment "Parse the string as a document";
+
 command xml.tag(nme:str,val:bat[:oid,:xml]):bat[:oid,:xml]
 address BATXMLtag
 comment "Routine to put element brackets around an XML value";
@@ -59,7 +67,7 @@
 address BATXMLxml2str
 comment "Serialize the XQuery object to a string";
 
-command xml.query(val:bat[:oid,:str],expr:str):bat[:oid,:xml]
+command xml.xquery(val:bat[:oid,:str],expr:str):bat[:oid,:xml]
 address BATXMLxquery
 comment "Execute the XQuery against the elements";
 
@@ -77,16 +85,21 @@
 comment "Construct an attribute value pair";
 
 command xml.element(name:str, s:bat[:oid,:xml]) :bat[:oid,:xml]
-address BATXMLelementSmall
+address BATXMLtag
 comment "The basic building block for XML elements are namespaces, 
 attributes and a sequence of xml elements. The name space and 
 the attributes may be left unspecified."; 
 
-command xml.element(name:str, ns:bat[:oid,:str], attr:bat[:oid,:xml], 
s:bat[:oid,:xml]):bat[:oid,:xml]
+command xml.options(tag:str, option:str,left:bat[:oid,:xml]):bat[:oid,:xml]
+address BATXMLoptions
+comment "Create the components including NULL conversions";
+
+
+command xml.element(name:str, ns:xml, attr:xml, 
s:bat[:oid,:xml]):bat[:oid,:xml]
 address BATXMLelement
 comment "The basic building block for XML elements are namespaces, 
 attributes and a sequence of xml elements. The name space and the 
-attributes may be left unspecified(=nil:bat).";
+attributes may be left unspecified(=nilt).";
 
 command xml.concat(left:bat[:oid,:xml],right:bat[:oid,:xml] ):bat[:oid,:xml]
 address BATXMLconcat
@@ -96,9 +109,14 @@
 address BATXMLforest
 comment "Construct an element list");
 
-pattern xml.agg(val:bat[:oid,:xml], order:str...):bat[:oid,:xml]
+command xml.agg(grp:bat[:oid,:oid],val:bat[:oid,:xml]):bat[:oid,:xml]
 address BATXMLagg
-comment "Aggregate the XML values over grouping specified@;
+comment "Aggregate the XML values over grouping specified";
+
+command xml.agg(val:bat[:oid,:xml]):bat[:oid,:xml]
+address BATXMLgroup
+comment "Aggregate the XML values over grouping specified";
+
 
 command xml.root(val:bat[:oid,:xml], version:str, 
standalone:str):bat[:oid,:xml]
 address BATXMLroot
@@ -136,28 +154,31 @@
 #define batxml_export extern
 #endif
 
-batxml_export str BATXMLxml2str(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
+batxml_export str BATXMLxml2str(int *ret, int *bid);
 batxml_export str BATXMLstr2xml(int *x, int *s);
+batxml_export str BATXMLdocument(int *x, int *s);
+batxml_export str BATXMLcontent(int *x, int *s);
 batxml_export str BATXMLisdocument(int *x, int *s);
 batxml_export str BATXMLtag(int *x, str *name, int *s);
+batxml_export str BATXMLoptions(int *x, str *name, str *options, int *s);
 batxml_export str BATXMLcomment(int *x, int *s);
 batxml_export str BATXMLparse(int *x, int *s);
 batxml_export str BATXMLxquery(int *x, int *s, str *expr);
 batxml_export str BATXMLpi(int *x, str *oper, int *s);
 batxml_export str BATXMLroot(int *ret, int *bid, str *version, str 
*standalone);
 batxml_export str BATXMLattribute(int *ret, str *name, int *bid);
-batxml_export str BATXMLelementSmall(int *ret, str *name, int *bid);
-batxml_export str BATXMLelement(int *ret, str *name, int *ns, int *attr, int 
*bid);
+batxml_export str BATXMLelement(int *ret, str *name, str *ns, str *attr, int 
*bid);
 batxml_export str BATXMLconcat(int *ret, int *bid, int *rid);
 batxml_export str BATXMLforest(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
-batxml_export str BATXMLagg(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
+batxml_export str BATXMLagg(int *ret, int *grp,int *bid);
+batxml_export str BATXMLgroup(int *ret, int *bid);
 #endif  /* _BATXML_H_ */
 @c
 #include "batxml.h"
 
 #define prepareOperand(X,Y,Z) \
     if( (X= BATdescriptor(*Y)) == NULL ) \
-        throw(MAL, "batxml." Z, "Cannot access descriptor");
+        throw(MAL, "xml." Z, "Cannot access descriptor");
 
 #define prepareResult(X,Y,T,Z) \
     X= BATnew(Y->htype,T,BATcount(Y)); \
@@ -165,7 +186,7 @@
         BATseqbase(X, Y->hseqbase); \
     if( X == NULL){ \
         BBPreleaseref(Y->batCacheid); \
-        throw(MAL, "batxml." Z, "no space available "); \
+        throw(MAL, "xml." Z, "no space available "); \
     } \
     X->hsorted=Y->hsorted; \
     X->tsorted=0;
@@ -177,9 +198,11 @@
     BBPreleaseref(Z->batCacheid);
 
 str
-BATXMLstr2xml(int *ret, int *bid)
+BATXMLxml2str(int *ret, int *bid)
 {
-       *ret= BBPincref(*bid,TRUE);
+       BAT *b;
+       @:getBATdescriptor(bid,b,"xml.xml")@
+       BBPkeepref(*ret= b->batCacheid);
        return MAL_SUCCEED;
 }
 @-
@@ -190,54 +213,104 @@
 This way, we know that as long as the xml-variables are not
 reused, the complete structure of the xml document(s) are available.
 We merely have to collect the pieces.
-[FOR LATER, FIRST GO FOR THE EASY IMPLEMENTATION
-
-static str
-BATtreeWalker(MalBlkPtr mb, InstrPtr p, str base, int size, int offset){
-       (void)mb;
-       (void) p;
-       snprintf(base+offset,size-offset,"dummy");
-       return MAL_SUCCEED;
+[FOR LATER, FIRST GO FOR THE EASY IMPLEMENTATION]
[EMAIL PROTECTED]
+XML values are represented by strings already.
[EMAIL PROTECTED]
+static 
+int
+BATXMLcountEscape(char *s){
+       int cnt=0;
+       for(; s && *s; s++)
+       switch(*s){
+       case '&':
+       case '>':
+       case '<':
+       case '"':
+       case '\'':
+               cnt++;
+               break;
+       default:
+               if ((*s & 0xFF) < 0x20)
+                       cnt++;
+       }
+       return cnt;
 }
 str
-BATXMLxml2str(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+BATXMLstr2xml(int *ret, int *bid)
 {
-       int *ret= (int*) getArgReference(stk,pci,0);
-       int *bid= (int*) getArgReference(stk,pci,1);
        BAT *b,*bn;
-       ptr p,q;
-       str buf,msg= MAL_SUCCEED;
+       BUN p,q;
+       int xx;
+       str s,buf= GDKmalloc(BUFSIZ);
+       int elm,len,size= BUFSIZ;
 
-       @:getBATdescriptor(bid,b,"batxml.str")@
-       bn= BATnew(TYPE_oid,TYPE_str,BATTINY);
-       if( bn == NULL){
-               BBPunfix(b->batCacheid);
-               throw(MAL,"batxml.str","Can not create BAT");
-       }
-       buf= GDKmalloc(BUFSIZ);
-       BATloop(b,p,q){
-               if( (msg= BATtreeWalker(mb,pci,buf,BUFSIZ,0)))
-                       break;
+       prepareOperand(b,bid,"str");
+       prepareResult(bn,b,TYPE_str,"str");
+       BATloopFast(b,p,q,xx){
+               ptr h= BUNhead(b,p);
+               str t= (str) BUNtail(b,p);
+               if( (elm=BATXMLcountEscape(t)) ){
+                       if( (len=strlen(t)+6*elm+1) >= size){
+                               buf= GDKrealloc(buf, len);
+                               size= len;
+                       }
+                       for(s=buf ; *t; t++)
+                       if (*t == '&'){
+                               strcat(s,"&amp;"); 
+                               while(*s) s++;
+                       } else if (*t == '<'){
+                               strcat(s,"&lt;"); 
+                               while(*s) s++;
+                       } else if (*t == '>'){
+                               strcat(s,"&gt;");
+                               while(*s) s++;
+                       }else if (*t == '"'){
+                               strcat(s,"&quot;");
+                               while(*s) s++;
+                       } else if (*t == '\''){
+                               strcat(s,"&apos;");
+                               while(*s) s++;
+                       } else if ((*t & 0xFF) < 0x20){
+                               sprintf(s, "&#%d;", *t & 0xFF);
+                               while(*s) s++;
+                       } else
+                               *s++= *t;
+                       *s=0;
+                       bunfastins(bn,h,buf);
+               } else 
+                       bunfastins(bn,h,t);
        }
-       BBPkeepref(*ret= bn->batCacheid);
-       (void)mb;
-       return msg;
+       GDKfree(buf);
+       finalizeResult(ret,bn,b);
+       return MAL_SUCCEED;
+bunins_failed:
+       BBPreleaseref(b->batCacheid);
+       BBPunfix(bn->batCacheid);
+       GDKfree(buf);
+       throw(MAL, "batstr.xml", "bunins failed");
 }
[EMAIL PROTECTED]
-XML values are represented by strings already.
[EMAIL PROTECTED]
 str
-BATXMLxml2str(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+BATXMLdocument(int *ret, int *bid)
 {
-       int *ret= (int*) getArgReference(stk,pci,0);
-       int *bid= (int*) getArgReference(stk,pci,1);
-       (void) mb;
-       BBPincref(*ret= *bid,TRUE);
-       return MAL_SUCCEED;
+/* ue libxml for validity checkes */
+       (void) ret;
+       (void) bid;
+       throw(MAL, "batstr.document", "Not yet implemented");
+}
+
+str
+BATXMLcontent(int *ret, int *bid)
+{
+       /* ue libxml for validity checkes */
+       (void) ret;
+       (void) bid;
+       throw(MAL, "batstr.content", "Not yet implemented");
 }
 
 str
 BATXMLisdocument(int *x, int *s){
+       /* ue libxml for validity checkes */
        (void) x;
        (void) s;
        throw(MAL,"xml.isdocument","Not yet implemented");
@@ -260,8 +333,7 @@
                ptr h= BUNhead(b,p);
                str t= (str) BUNtail(b,p);
                if( (len=strlen(t) + 2*tlen+10) >= size){
-                       if(buf) GDKfree(buf);
-                       buf= GDKmalloc(len);
+                       buf= GDKrealloc(buf,len);
                        snprintf(buf,size,"<%s>",*name);
                        size= len;
                }
@@ -275,8 +347,73 @@
        BBPreleaseref(b->batCacheid);
        BBPunfix(bn->batCacheid);
        GDKfree(buf);
-       throw(MAL, "batstr.comment", "bunins failed");
+       throw(MAL, "batstr.tag", "bunins failed");
 }
[EMAIL PROTECTED]
+The standard supports specific mappings for
+NULL values,i.e. {null,abscent,empty,nil,niloncontent)
+in the context of an element and forest construction.
+The standard should be studied in more detail, because
+the syntax(rules) seem ambiguous.
+It applies to all components of an element or their
+concatenation.
+
+For the time being, the variaton on XMLtag seems the
+most reasonable interpretation.
[EMAIL PROTECTED]
+str
+BATXMLoptions(int *ret, str *name, str *options, int *bid)
+{
+       BAT *b,*bn;
+       BUN p,q;
+       int xx;
+       str buf= GDKmalloc(BUFSIZ);
+       str val= GDKmalloc(BUFSIZ);
+       int size= BUFSIZ, len=strlen(*name);
+
+       prepareOperand(b,bid,"options");
+       prepareResult(bn,b,TYPE_str,"options");
+
+       if( strcmp(*options,"abscent")==0)
+               buf[0]=0;
+       else
+       if( strcmp(*options,"empty")==0)
+               snprintf(buf,size,"<%s></%s>",*name,*name);
+       else
+       if( strcmp(*options,"null")==0)
+               snprintf(buf,size,"null");
+       else
+       if( strcmp(*options,"nil")==0)
+               snprintf(buf,size,"nil");
+       else
+       /*if( strcmp(*options,"niloncontent")==0) */
+               throw(MAL,"xml.options","Not yet implemented");
+
+       snprintf(val,size,"<%s>",*name);
+       BATloopFast(b,p,q,xx){
+               ptr h= BUNhead(b,p);
+               str t= (str) BUNtail(b,p);
+               if(strNil(t)){
+                       bunfastins(bn,h,buf);
+               } else {
+                       if( (int)strlen(t)> size-2*len-6){
+                               size+= strlen(t);
+                               val= (char*) GDKrealloc(val, size+strlen(t));
+                       }
+                       snprintf(val+len+2,size-len,"%s</%s>",t,*name);
+                       bunfastins(bn,h, val);
+               }
+       }
+       GDKfree(buf);
+       finalizeResult(ret,bn,b);
+       return MAL_SUCCEED;
+bunins_failed:
+       BBPreleaseref(b->batCacheid);
+       BBPunfix(bn->batCacheid);
+       GDKfree(buf);
+       throw(MAL, "batxml.options", "bunins failed");
+}
+
 str
 BATXMLcomment(int *ret, int *bid)
 {
@@ -292,8 +429,7 @@
                ptr h= BUNhead(b,p);
                str t= (str) BUNtail(b,p);
                if( (len=strlen(t)) >= size){
-                       if(buf) GDKfree(buf);
-                       buf= GDKmalloc(size+20);
+                       buf= GDKrealloc(buf,len+20);
                        size= len+20;
                }
                snprintf(buf,size,"<!-- %s -->",t);
@@ -346,15 +482,33 @@
        BAT *b,*bn;
        BUN p,q;
        int xx;
+       str buf= GDKmalloc(BUFSIZ);
+       int len,size= BUFSIZ;
 
        prepareOperand(b,bid,"root");
        prepareResult(bn,b,TYPE_str,"root");
+
+       len= strlen(*version)+strlen(*standalone)+
+                       strlen("<? version=\"\" standalone=\"\"?>");
        BATloopFast(b,p,q,xx){
+               ptr h= BUNhead(b,p);
+               str t= (str) BUNtail(b,p);
+               if( (len=strlen(t)) >= size){
+                       buf= GDKrealloc(buf,len+20);
+                       size= len+20;
+               }
+               snprintf(buf,size,"<? version=\"%s\" stanalone=\"%s\"?>%s",
+                       *version,*standalone,t);
+               bunfastins(bn,h,buf);
        }
+       GDKfree(buf);
        finalizeResult(ret,bn,b);
-       (void) version;
-       (void) standalone;
-       throw(MAL,"xml.root","Not yet implemented");
+       return MAL_SUCCEED;
+bunins_failed:
+       BBPreleaseref(b->batCacheid);
+       BBPunfix(bn->batCacheid);
+       GDKfree(buf);
+       throw(MAL, "batstr.root", "bunins failed");
 }
 
 str
@@ -372,8 +526,7 @@
                ptr h= BUNhead(b,p);
                str t= (str) BUNtail(b,p);
                if( (len=strlen(t)) >= size){
-                       if(buf) GDKfree(buf);
-                       buf= GDKmalloc(size+20);
+                       buf= GDKrealloc(buf,len+20);
                        size= len+20;
                }
                snprintf(buf,size," %s=\"%s\"",*name,t);
@@ -390,74 +543,45 @@
 }
 
 str
-BATXMLelementSmall(int *ret, str *name, int *bid)
-{
-       return BATXMLtag(ret,name,bid);
-}
-str
-BATXMLelement(int *ret, str *name, int *namespace, int *attributes, int *bid)
+BATXMLelement(int *ret, str *name, str *namespace, str *attributes, int *bid)
 {
-       BAT *b,*a=0, *n=0, *bn;
-       BUN p,q, ap, aq, np, nq;
-       int xx, axx, nxx;
+       BAT *b,*bn;
+       BUN p,q;
+       int xx;
        str buf= GDKmalloc(BUFSIZ);
        int offset,len,size= BUFSIZ;
 
-       /* check the namespaces */
-       if( *namespace && (n=  BATdescriptor( *namespace)) ){
-               np = BUNfirst(n);
-               nq = BUNlast(n);
-               nxx= BUNsize(n);
-       }
-
-       /* check for attributes */
-       if( *attributes && (a=  BATdescriptor( *attributes)) ){
-               ap= BUNfirst(a);
-               aq= BUNlast(a);
-               axx= BUNsize(a);
-       }
+       (void) namespace;
        /* collect the admin for the xml elements */
-       if ( (b=  BATdescriptor( *bid)) ){
-               p= BUNfirst(b);
-               q= BUNlast(b);
-               xx= BUNsize(b);
-       }
+       b=  BATdescriptor( *bid);
 
 /* check for errors */
-       if( b== NULL){
-               if(a) BBPunfix(a->batCacheid);
-               if(n) BBPunfix(n->batCacheid);
-               throw(MAL,"batxml.element","Can not access BAT");
-       }
+       if( b== NULL)
+               throw(MAL,"xml.element","Can not access BAT");
 
        prepareResult(bn,b,TYPE_str,"element");
 
-       while(p < q){
-               str t;
-               oid *h;
+       BATloopFast(b,p,q,xx){
+               str t= (str) BUNtail(b,p);
+               oid *h= (oid*) BUNhead(b,p);
                int elm;
 
                /* include attributes */
-               if( a) {
-                       t= (str) BUNtail(a,ap);
+               if( attributes) {
 
                        if( (len=strlen(t)) >= size){
-                               if(buf) GDKfree(buf);
-                               buf= GDKmalloc(len+strlen(*name)+BUFSIZ);
+                               buf= GDKrealloc(buf,len+strlen(*name)+BUFSIZ);
                                size= len+strlen(*name)+BUFSIZ;
                        }
-                       snprintf(buf,size,"<%s %s>",*name,t);
+                       snprintf(buf,size,"<%s %s>",*name,*attributes);
                } else 
                        snprintf(buf,size,"<%s>",*name);
                elm= offset= strlen(buf);
 
                /* fetch the elements */
-               h= (oid*) BUNhead(b,p);
-               t= (str) BUNtail(b,p);
 
-               if( (len=strlen(t)) >= size-offset){
-                       if(buf) GDKfree(buf);
-                       buf= GDKmalloc(size+2*elm);
+               if( (len=strlen(t)+elm) >= size-offset){
+                       buf= GDKrealloc(buf,size+2*elm);
                        size= len+2*elm;
                }
                snprintf(buf+offset,size-offset,"%s",t);
@@ -465,29 +589,17 @@
        
                snprintf(buf + offset,size-offset, "</%s>\n",*name);
                bunfastins(bn,h,buf);
-
-               if(a) 
-                       ap= (ptr) ( ((char*)ap)+ axx);
-               if(n) 
-                       np= (ptr) ( ((char*)np)+ nxx);
-               if(b) 
-                       p= (ptr) ( ((char*)p)+ nxx);
        }
        GDKfree(buf);
        finalizeResult(ret,bn,b);
        return MAL_SUCCEED;
 bunins_failed:
-       if(a)
-               BBPreleaseref(a->batCacheid);
-       if(n)
-               BBPreleaseref(n->batCacheid);
        BBPreleaseref(b->batCacheid);
        BBPunfix(bn->batCacheid);
        GDKfree(buf);
        throw(MAL, "xml.element", "bunins failed");
 }
 
-
 str
 BATXMLforest(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
@@ -516,7 +628,7 @@
        if( i!= pci->argc) {
                for( i--; i>=pci->retc; i--)
                        BBPunfix(b[i]->batCacheid);
-               throw(MAL,"batxml.element","Can not access BAT");
+               throw(MAL,"xml.forest","Can not access BAT");
        }
 
        prepareResult(bn,b[pci->retc],TYPE_str,"attribute");
@@ -524,18 +636,17 @@
        while(p[pci->retc] < q[pci->retc]){
                str t;
                oid *h;
-               int elm;
 
                /* fetch the elements */
-               h= (oid*) BUNhead(b[4],p[4]);
+               h= (oid*) BUNhead(b[pci->retc],p[pci->retc]);
+               offset=0;
                for(i= pci->retc; i< pci->argc; i++)
                {
                        t= (str) BUNtail(b[i],p[i]);
 
                        if( (len=strlen(t)) >= size-offset){
-                               if(buf) GDKfree(buf);
-                               buf= GDKmalloc(size+2*elm);
-                               size= len+2*elm;
+                               buf= GDKrealloc(buf,size+len);
+                               size= size+len;
                        }
                        snprintf(buf+offset,size-offset,"%s",t);
                        offset+= strlen(buf+offset);
@@ -572,7 +683,7 @@
                rxx= BUNsize(r);
        }
        if(r==0)
-               throw(MAL,"batxml.concat","Can not access BAT");
+               throw(MAL,"xml.concat","Can not access BAT");
 
        /* collect the admin for the xml elements */
        if ( (b=  BATdescriptor( *bid)) ){
@@ -582,7 +693,7 @@
        }
        if( b== NULL){
                if(r) BBPunfix(r->batCacheid);
-               throw(MAL,"batxml.concat","Can not access BAT");
+               throw(MAL,"xml.concat","Can not access BAT");
        }
 
        prepareResult(bn,b,TYPE_str,"concat");
@@ -611,19 +722,89 @@
        BBPreleaseref(b->batCacheid);
        BBPunfix(bn->batCacheid);
        GDKfree(buf);
-       throw(MAL, "xml.element", "bunins failed");
+       throw(MAL, "xml.concat", "bunins failed");
 }
 
 str
-BATXMLagg(MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
+BATXMLagg(int *ret, int *grp,int *bid)
 {
-       (void) mb;
-       (void) stk;
-       (void) p;
-       throw(MAL,"xml.agg","Not yet implemented");
+       BAT *j, *r, *g, *b, *bn;
+       BUN p,q;
+       int xx;
+       oid gid,o=0;
+       int first= 1;
+       str t;
+       str buf= GDKmalloc(BUFSIZ);
+       int len, size=BUFSIZ,offset;
+       
+       @:getBATdescriptor(grp,g,"xml.agg")@
+       @:getBATdescriptor(bid,b,"xml.agg",BBPunfix(g->batCacheid))@
+       
+       bn= BATnew(g->htype, b->ttype,BATcount(g));
+       if( bn== NULL){
+               BBPunfix(b->batCacheid);
+               BBPunfix(g->batCacheid);
+               throw(MAL,"xml.agg","Could not create BAT");
+       }
+
+       j= BATjoin(g,b,oid_nil);
+    r= BATsort(j);
+       /* now we can perform a simple scan and emit the group*/
+
+       buf[0]=0; 
+       offset=0;
+       first=1;
+       BATloopFast(r,p,q,xx){
+               o= *(oid*) BUNhead(r,p);
+               t= (str) BUNtail(r,p);
+               if( gid != o && first==0){
+                       /* flush */
+                       bunfastins(bn,&gid,buf);
+                       buf[0]=0;
+                       offset =0;
+               }
+               gid=o;
+               first=0;
+               len= strlen(t)+1;
+               if( len >= size-offset){
+                       if(buf) GDKfree(buf);
+                       buf= GDKrealloc(buf,size+len);
+                       size= size+len;
+               }
+               snprintf(buf+offset,size-offset,"%s",t);
+               offset+= len-1;
+       }
+       /* end the leftover element */
+       if( first ==0)
+               bunfastins(bn,&gid,buf);
+
+       BBPunfix(r->batCacheid);
+       BBPunfix(j->batCacheid);
+       GDKfree(buf);
+       BBPkeepref(*ret=bn->batCacheid);
+       return MAL_SUCCEED;
+bunins_failed:
+       BBPreleaseref(g->batCacheid);
+       BBPreleaseref(b->batCacheid);
+       BBPunfix(bn->batCacheid);
+       GDKfree(buf);
+       throw(MAL, "xml.agg", "bunins failed");
 }
 
 str
+BATXMLgroup(int *ret, int *bid)
+{
+       BAT *b, *g;
+       str msg= MAL_SUCCEED;
+       oid o= oid_nil;
+
+       @:getBATdescriptor(bid,b,"xml.group")@
+       g= BATmirror(BATconst(b,TYPE_oid,(ptr) &o));
+       msg= BATXMLagg(ret,&g->batCacheid,bid);
+       BBPunfix(g->batCacheid);
+       return msg;
+}
+str
 BATXMLxquery(int *ret, int *bid, str *expr)
 {
        (void) ret;


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to