Changeset: 97eadd40f2c6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=97eadd40f2c6
Modified Files:
        gdk/ChangeLog.Oct2014
        gdk/gdk_sample.c
        monetdb5/modules/mal/manifold.c
Branch: default
Log Message:

Merge with Oct2014 branch.


diffs (162 lines):

diff --git a/gdk/ChangeLog.Oct2014 b/gdk/ChangeLog.Oct2014
--- a/gdk/ChangeLog.Oct2014
+++ b/gdk/ChangeLog.Oct2014
@@ -1,3 +1,10 @@
 # ChangeLog file for MonetDB
 # This file is updated with Maddlog
 
+* Wed Nov  5 2014 Sjoerd Mullender <[email protected]>
+- Fixed some problems with BATsample.  It was possible for BATsample to
+  return a value that was just beyond the end of the sampled BAT.  Also,
+  on some systems the range of the rand() function is rather limited
+  (0..32767) and trying to get a sample larger than this range would
+  result in an infinite loop.
+
diff --git a/gdk/gdk_sample.c b/gdk/gdk_sample.c
--- a/gdk/gdk_sample.c
+++ b/gdk/gdk_sample.c
@@ -57,13 +57,13 @@
 
 /* this is a straightforward implementation of a binary tree */
 struct oidtreenode {
-       BUN oid;
+       oid o;
        struct oidtreenode *left;
        struct oidtreenode *right;
 };
 
 static struct oidtreenode *
-OIDTreeNew(BUN oid)
+OIDTreeNew(oid o)
 {
        struct oidtreenode *node = GDKmalloc(sizeof(struct oidtreenode));
 
@@ -71,24 +71,24 @@ OIDTreeNew(BUN oid)
                GDKerror("#BATsample: memory allocation error");
                return NULL ;
        }
-       node->oid = oid;
+       node->o = o;
        node->left = NULL;
        node->right = NULL;
        return node;
 }
 
 static int
-OIDTreeMaybeInsert(struct oidtreenode **nodep, BUN oid)
+OIDTreeMaybeInsert(struct oidtreenode **nodep, oid o)
 {
        while (*nodep) {
-               if (oid == (*nodep)->oid)
+               if (o == (*nodep)->o)
                        return 0;
-               if (oid < (*nodep)->oid)
+               if (o < (*nodep)->o)
                        nodep = &(*nodep)->left;
                else
                        nodep = &(*nodep)->right;
        }
-       if ((*nodep = OIDTreeNew(oid)) == NULL)
+       if ((*nodep = OIDTreeNew(o)) == NULL)
                return -1;
        return 1;
 }
@@ -99,27 +99,27 @@ OIDTreeToBAT(struct oidtreenode *node, B
 {
        if (node->left != NULL)
                OIDTreeToBAT(node->left, bat);
-       ((oid *) bat->T->heap.base)[bat->batFirst + bat->batCount++] = 
node->oid;
+       ((oid *) bat->T->heap.base)[bat->batFirst + bat->batCount++] = node->o;
        if (node->right != NULL )
                OIDTreeToBAT(node->right, bat);
 }
 
 /* Antiset traversal, give us all values but the ones in the tree */
 static void
-OIDTreeToBATAntiset(struct oidtreenode *node, BAT *bat, BUN start, BUN stop)
+OIDTreeToBATAntiset(struct oidtreenode *node, BAT *bat, oid start, oid stop)
 {
-       BUN noid;
+       oid noid;
 
        if (node->left != NULL)
-               OIDTreeToBATAntiset(node->left, bat, start, node->oid);
+               OIDTreeToBATAntiset(node->left, bat, start, node->o);
        else
-               for (noid = start+1; noid < node->oid; noid++)
+               for (noid = start; noid < node->o; noid++)
                        ((oid *) bat->T->heap.base)[bat->batFirst + 
bat->batCount++] = noid;
 
         if (node->right != NULL)
-               OIDTreeToBATAntiset(node->right, bat, node->oid, stop);
+               OIDTreeToBATAntiset(node->right, bat, node->o, stop);
        else
-               for (noid = node->oid+1; noid < stop; noid++)
+               for (noid = node->o+1; noid < stop; noid++)
                         ((oid *) bat->T->heap.base)[bat->batFirst + 
bat->batCount++] = noid;
 }
 
@@ -176,8 +176,8 @@ BATsample(BAT *b, BUN n)
                BATseqbase(bn, 0);
                BATseqbase(BATmirror(bn), b->H->seq);
        } else {
-               BUN minoid = b->hseqbase;
-               BUN maxoid = b->hseqbase + cnt;
+               oid minoid = b->hseqbase;
+               oid maxoid = b->hseqbase + cnt;
                /* if someone samples more than half of our tree, we
                 * do the antiset */
                bit antiset = n > cnt / 2;
@@ -192,11 +192,11 @@ BATsample(BAT *b, BUN n)
                }
                /* while we do not have enough sample OIDs yet */
                while (rescnt < n) {
-                       BUN candoid;
+                       oid candoid;
                        int rc;
                        do {
                                /* generate a new random OID */
-                               candoid = (BUN) (minoid + DRAND * (maxoid - 
minoid));
+                               candoid = (oid) (minoid + DRAND * (maxoid - 
minoid));
                                /* if that candidate OID was already
                                 * generated, try again */
                        } while ((rc = OIDTreeMaybeInsert(&tree, candoid)) == 
0);
@@ -212,7 +212,7 @@ BATsample(BAT *b, BUN n)
                if (!antiset) {
                        OIDTreeToBAT(tree, bn);
                } else {
-                       OIDTreeToBATAntiset(tree, bn, minoid - 1, maxoid + 1);
+                       OIDTreeToBATAntiset(tree, bn, minoid, maxoid);
                }
                OIDTreeDestroy(tree);
 
diff --git a/monetdb5/modules/mal/manifold.c b/monetdb5/modules/mal/manifold.c
--- a/monetdb5/modules/mal/manifold.c
+++ b/monetdb5/modules/mal/manifold.c
@@ -220,8 +220,10 @@ MANIFOLDtypecheck(Client cntxt, MalBlkPt
        tpe =getColumnType(getArgType(mb,pci,0));
        k= getArg(q,0);
        setVarType(nmb,k,tpe);
-       setVarFixed(nmb,k);
-       setVarUDFtype(nmb,k);
+       if ( isVarFixed(nmb,k)) 
+               setVarFixed(nmb,k);
+       if (isVarUDFtype(nmb,k))
+               setVarUDFtype(nmb,k);
        
        // extract their scalar argument type
        for ( i = pci->retc+2; i < pci->argc; i++){
@@ -241,8 +243,12 @@ MANIFOLDtypecheck(Client cntxt, MalBlkPt
        if (nmb->errors || q->fcn == NULL || q->token != CMDcall ||
                varGetProp( q->blk, getArg(getInstrPtr(q->blk,0), 0), 
PropertyIndex("unsafe") ) != NULL)
                fcn = NULL;
-       else
+       else {
                fcn = q->fcn;
+               // retain the type detected
+               if ( !isVarFixed(mb, getArg(pci,0)))
+                       setVarType( mb, getArg(pci,0), 
newBatType(TYPE_void,getArgType(nmb,q,0)) );
+       }
 #ifdef _DEBUG_MANIFOLD_
        mnstr_printf(cntxt->fdout,"success? %s\n",(fcn == NULL? "no":"yes"));
        printInstruction(cntxt->fdout,nmb,0,q,LIST_MAL_ALL);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to