Changeset: 7a144a8b8dcc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7a144a8b8dcc
Modified Files:
        gdk/gdk_calc.c
        monetdb5/modules/kernel/aggr.mx
Branch: default
Log Message:

Fix alignment conversion in compatibility code for grouped aggregates.


diffs (65 lines):

diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -10057,7 +10057,8 @@ initgroupaggr(const BAT *b, const BAT *g
                GDKerror("BATgroupsum: b must be dense-headed\n");
                return GDK_FAIL;
        }
-       if (g == NULL || !BAThdense(g) || b->hseqbase != g->hseqbase || 
BATcount(b) != BATcount(g)) {
+       if (g == NULL || !BAThdense(g) || BATcount(b) != BATcount(g) ||
+           (BATcount(b) != 0 && b->hseqbase != g->hseqbase)) {
                GDKerror("BATgroupsum: b and g must be aligned\n");
                return GDK_FAIL;
        }
diff --git a/monetdb5/modules/kernel/aggr.mx b/monetdb5/modules/kernel/aggr.mx
--- a/monetdb5/modules/kernel/aggr.mx
+++ b/monetdb5/modules/kernel/aggr.mx
@@ -421,29 +421,36 @@ AGGRgrouped(bat *retval, BAT *b, BAT *g,
        if (!BAThdense(b) || !BAThdense(g)) {
                /* if b or g don't have a dense head, replace the head with a
                 * dense sequence */
-               t = BATmirror(BATmark(BATmirror(b), 0)); /* [dense,value] */
+               t = BATjoin(BATmirror(b), g, MIN(BATcount(b), BATcount(g)));
                BBPreleaseref(b->batCacheid);
-               b = t;
-               t = BATmirror(BATmark(BATmirror(g), 0)); /* [dense,gid] */
                BBPreleaseref(g->batCacheid);
-               g = t;
+               b = BATmirror(BATmark(t, 0));
+               g = BATmirror(BATmark(BATmirror(t), 0));
+               BBPreleaseref(t->batCacheid);
        }
        if (b->hseqbase != g->hseqbase || BATcount(b) != BATcount(g)) {
                /* b and g are not aligned: align them by creating a view on
                 * one or the other */
-               oid max = b->hseqbase + BATcount(b);
+               oid min;                                /* lowest common oid */
+               oid max;                                /* highest common oid */
+               min = b->hseqbase;
+               if (min < g->hseqbase)
+                       min = g->hseqbase;
+               max = b->hseqbase + BATcount(b);
                if (g->hseqbase + BATcount(g) < max)
                        max = g->hseqbase + BATcount(g);
-               if (b->hseqbase < g->hseqbase ||
-                       (b->hseqbase == g->hseqbase && BATcount(b) > 
BATcount(g))) {
-                       t = BATslice(b, BUNfirst(b) + (BUN) (g->hseqbase - 
b->hseqbase),
+               if (b->hseqbase != min || b->hseqbase + BATcount(b) != max) {
+                       if (min >= max)
+                               min = max = b->hseqbase;
+                       t = BATslice(b, BUNfirst(b) + (BUN) (min - b->hseqbase),
                                                 BUNfirst(b) + (BUN) (max - 
b->hseqbase));
                        BBPreleaseref(b->batCacheid);
                        b = t;
-               } else {
-                       /* b->hseqbase > g->hseqbase ||
-                        * (b->hseqbase == g->hseqbase && BATcount(b) < 
BATcount(g)) */
-                       t = BATslice(g, BUNfirst(g) + (BUN) (b->hseqbase - 
g->hseqbase),
+               }
+               if (g->hseqbase != min || g->hseqbase + BATcount(g) != max) {
+                       if (min >= max)
+                               min = max = g->hseqbase;
+                       t = BATslice(g, BUNfirst(g) + (BUN) (min - g->hseqbase),
                                                 BUNfirst(g) + (BUN) (max - 
g->hseqbase));
                        BBPreleaseref(g->batCacheid);
                        g = t;
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to