Changeset: 9b550d4d77de for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9b550d4d77de
Modified Files:
        gdk/gdk_group.c
Branch: Jul2017
Log Message:

Fixes for grouping.


diffs (142 lines):

diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -468,7 +468,7 @@ pop(oid x)
                                     hb != HASHnil(hs) && hb >= start;  \
                                     hb = HASHgetlink(hs, hb)) {        \
                                        ASSERT;                         \
-                                       GRPTST(hb, r);                  \
+                                       GRPTST(hb - start, r);          \
                                        grp = ngrps[hb - start];        \
                                        if (COMP) {                     \
                                                ngrps[r] = grp;         \
@@ -499,7 +499,7 @@ pop(oid x)
                        if (gc) {                                       \
                                
GRP_create_partial_hash_table_core(INIT_1,HASH,COMP,assert(HASHgetlink(hs, hb) 
== HASHnil(hs) || HASHgetlink(hs, hb) < hb),GCGRPTST); \
                        } else {                                \
-                               GRP_create_partial_hash_table_core(INIT_1,HASH 
^ (rev(grps[p]) >> bits),COMP,(void)0,GRPTST); \
+                               GRP_create_partial_hash_table_core(INIT_1,HASH 
^ (rev(grps[r]) >> bits),COMP,(void)0,GRPTST); \
                        }                                               \
                } else {                                                \
                        
GRP_create_partial_hash_table_core(INIT_1,HASH,COMP,(void)0,NOGRPTST); \
@@ -546,7 +546,7 @@ BATgroup_internal(BAT **groups, BAT **ex
 #endif
        BUN start, end, cnt;
        const oid *restrict cand, *candend;
-       oid maxgrp = 0;         /* maximum value of g BAT (if subgrouping) */
+       oid maxgrp = oid_nil;   /* maximum value of g BAT (if subgrouping) */
        PROPrec *prop;
 
        if (b == NULL) {
@@ -633,6 +633,8 @@ BATgroup_internal(BAT **groups, BAT **ex
                        if (prop)
                                maxgrp = prop->v.val.oval;
                }
+               if (maxgrp == 0)
+                       g = NULL; /* single group */
        }
        if (BATordered(b) && BATordered_rev(b)) {
                /* all values are equal */
@@ -695,7 +697,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                        gn = COLcopy(g, g->ttype, 0, TRANSIENT);
                        if (gn == NULL)
                                goto error;
-                       if (maxgrp > 0) {
+                       if (maxgrp != oid_nil) {
                                prop = BATgetprop(g, GDK_MAX_VALUE);
                                if (prop)
                                        BATsetprop(gn, GDK_MAX_VALUE, TYPE_oid, 
&maxgrp);
@@ -725,7 +727,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                goto error;
        ngrps = (oid *) Tloc(gn, 0);
        maxgrps = cnt / 10;
-       if (maxgrps < maxgrp)
+       if (maxgrp != oid_nil && maxgrps < maxgrp)
                maxgrps += maxgrp;
        if (e && maxgrps < BATcount(e))
                maxgrps += BATcount(e);
@@ -754,6 +756,8 @@ BATgroup_internal(BAT **groups, BAT **ex
        if (g && (!BATordered(g) || !BATordered_rev(g)))
                grps = (const oid *) Tloc(g, 0);
 
+       hseqb = b->hseqbase;    /* abbreviation */
+
        /* figure out if we can use the storage type also for
         * comparing values */
        t = ATOMbasetype(b->ttype);
@@ -1010,7 +1014,6 @@ BATgroup_internal(BAT **groups, BAT **ex
                                  e ? BATgetId(e) : "NULL", e ? BATcount(e) : 0,
                                  h ? BATgetId(h) : "NULL", h ? BATcount(h) : 0,
                                  subsorted);
-               hseqb = b->hseqbase;
 #ifndef DISABLE_PARENT_HASH
                if (b->thash == NULL && (parent = VIEWtparent(b)) != 0) {
                        /* b is a view on another bat (b2 for now).
@@ -1116,7 +1119,7 @@ BATgroup_internal(BAT **groups, BAT **ex
 
                switch (t) {
                case TYPE_bte:
-                       if (grps && maxgrp > 1
+                       if (grps && maxgrp != oid_nil
 #if SIZEOF_OID == SIZEOF_LNG
                            && maxgrp < ((oid) 1 << (SIZEOF_LNG * 8 - 8))
 #endif
@@ -1126,14 +1129,14 @@ BATgroup_internal(BAT **groups, BAT **ex
                                GRP_create_partial_hash_table_core(
                                        (void) 0,
                                        (v = ((ulng)grps[r]<<8)|(unsigned 
char)w[p], hash_lng(hs, &v)),
-                                       w[p] == w[hb] && grps[r] == grps[hb],
+                                       w[p] == w[hb] && grps[r] == grps[hb - 
start],
                                        (void) 0,
                                        NOGRPTST);
                        } else
                                GRP_create_partial_hash_table_tpe(bte);
                        break;
                case TYPE_sht:
-                       if (grps && maxgrp > 1
+                       if (grps && maxgrp != oid_nil
 #if SIZEOF_OID == SIZEOF_LNG
                            && maxgrp < ((oid) 1 << (SIZEOF_LNG * 8 - 16))
 #endif
@@ -1143,14 +1146,14 @@ BATgroup_internal(BAT **groups, BAT **ex
                                GRP_create_partial_hash_table_core(
                                        (void) 0,
                                        (v = ((ulng)grps[r]<<16)|(unsigned 
short)w[p], hash_lng(hs, &v)),
-                                       w[p] == w[hb] && grps[r] == grps[hb],
+                                       w[p] == w[hb] && grps[r] == grps[hb - 
start],
                                        (void) 0,
                                        NOGRPTST);
                        } else
                                GRP_create_partial_hash_table_tpe(sht);
                        break;
                case TYPE_int:
-                       if (grps && maxgrp > 1
+                       if (grps && maxgrp != oid_nil
 #if SIZEOF_OID == SIZEOF_LNG
                            && maxgrp < ((oid) 1 << (SIZEOF_LNG * 8 - 32))
 #endif
@@ -1160,7 +1163,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                                GRP_create_partial_hash_table_core(
                                        (void) 0,
                                        (v = ((ulng)grps[r]<<32)|(unsigned 
int)w[p], hash_lng(hs, &v)),
-                                       w[p] == w[hb] && grps[r] == grps[hb],
+                                       w[p] == w[hb] && grps[r] == grps[hb - 
start],
                                        (void) 0,
                                        NOGRPTST);
                        } else
@@ -1168,13 +1171,13 @@ BATgroup_internal(BAT **groups, BAT **ex
                        break;
                case TYPE_lng:
 #ifdef HAVE_HGE
-                       if (grps && maxgrp > 1) {
+                       if (grps) {
                                uhge v;
                                const lng *w = (lng *) Tloc(b, 0);
                                GRP_create_partial_hash_table_core(
                                        (void) 0,
                                        (v = ((uhge)grps[r]<<64)|(ulng)w[p], 
hash_hge(hs, &v)),
-                                       w[p] == w[hb] && grps[r] == grps[hb],
+                                       w[p] == w[hb] && grps[r] == grps[hb - 
start],
                                        (void) 0,
                                        NOGRPTST);
                        } else
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to