Changeset: 22b783ba2620 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=22b783ba2620
Modified Files:
        monetdb5/modules/kernel/algebra.c
        monetdb5/modules/mal/tokenizer.c
Branch: Oct2014
Log Message:

Count groups instead of result of BATkunique to find count of distinct values.


diffs (55 lines):

diff --git a/monetdb5/modules/kernel/algebra.c 
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -350,17 +350,17 @@ ALGgroupby(int *res, int *gids, int *cnt
 str
 ALGcard(lng *result, int *bid)
 {
-       BAT *b, *bn;
+       BAT *b, *gn, *en;
 
        if ((b = BATdescriptor(*bid)) == NULL) {
                throw(MAL, "algebra.card", RUNTIME_OBJECT_MISSING);
        }
-       bn = (BAT *) BATkunique(BATmirror(b));
-       if (bn == NULL) {
+       if (BATgroup(&gn, &en, NULL, b, NULL, NULL, NULL) != GDK_SUCCEED) {
                throw(MAL, "algebra.card", GDK_EXCEPTION);
        }
-       *result = BATcount(bn);
-       BBPunfix(bn->batCacheid);
+       *result = BATcount(en);
+       BBPunfix(gn->batCacheid);
+       BBPunfix(en->batCacheid);
        BBPreleaseref(b->batCacheid);
        return MAL_SUCCEED;
 }
diff --git a/monetdb5/modules/mal/tokenizer.c b/monetdb5/modules/mal/tokenizer.c
--- a/monetdb5/modules/mal/tokenizer.c
+++ b/monetdb5/modules/mal/tokenizer.c
@@ -629,7 +629,7 @@ TKNZRgetCount(int *r)
 str
 TKNZRgetCardinality(int *r)
 {
-       BAT *b, *bn;
+       BAT *b, *gn, *en;
        int i;
        wrd cnt;
 
@@ -640,9 +640,13 @@ TKNZRgetCardinality(int *r)
                throw(MAL, "tokenizer.getCardinality", MAL_MALLOC_FAIL);
        BATseqbase(b, 0);
        for (i = 0; i < tokenDepth; i++) {
-               bn = (BAT *) BATkunique(BATmirror(tokenBAT[i].val));
-               cnt = (wrd) BATcount(bn);
-               BBPunfix(bn->batCacheid);
+               if (BATgroup(&gn, &en, NULL, tokenBAT[i].val, NULL, NULL, NULL) 
!= GDK_SUCCEED) {
+                       BBPreclaim(b);
+                       throw(MAL, "tokenizer.getCardinality", GDK_EXCEPTION);
+               }
+               cnt = (wrd) BATcount(en);
+               BBPunfix(gn->batCacheid);
+               BBPunfix(en->batCacheid);
                BUNappend(b, &cnt, FALSE);
        }
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to