Changeset: 870aa0af7e1a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=870aa0af7e1a
Modified Files:
gdk/gdk_firstn.c
Branch: Jul2017
Log Message:
Fixed some thinkos in BATfirstn_unique_with_groups.
- Make sure *lastp and *lastgp are assigned a value.
- Don't blindly assume there is a candidate list if there are groups.
- Copy correct bit of candidate list, or create a dense bat referring
to correct part of input bat.
This fixes bug 6478.
diffs (69 lines):
diff --git a/gdk/gdk_firstn.c b/gdk/gdk_firstn.c
--- a/gdk/gdk_firstn.c
+++ b/gdk/gdk_firstn.c
@@ -394,25 +394,48 @@ BATfirstn_unique_with_groups(BAT *b, BAT
oid item;
BUN pos, childpos;
- if (BATtdense(g)) {
- /* trivial: g determines ordering, return initial
- * slice of s */
- return BATslice(s, 0, n);
- }
-
CANDINIT(b, s, start, end, cnt, cand, candend);
+ cnt = cand ? (BUN) (candend - cand) : end - start;
if (n > cnt)
n = cnt;
- if (cand && n > (BUN) (candend - cand))
- n = (BUN) (candend - cand);
if (n == 0) {
/* candidate list might refer only to values outside
* of the bat and hence be effectively empty */
+ if (lastp)
+ *lastp = 0;
+ if (lastgp)
+ *lastgp = 0;
return BATdense(0, 0, 0);
}
+ if (BATtdense(g)) {
+ /* trivial: g determines ordering, return reference to
+ * initial part of b (or slice of s) */
+ if (lastgp)
+ *lastgp = g->tseqbase + n - 1;
+ if (cand) {
+ if (lastp)
+ *lastp = cand[n - 1];
+ bn = COLnew(0, TYPE_oid, n, TRANSIENT);
+ if (bn == NULL)
+ return NULL;
+ memcpy(Tloc(bn, 0), cand, n * sizeof(oid));
+ BATsetcount(bn, n);
+ bn->tsorted = 1;
+ bn->trevsorted = n <= 1;
+ bn->tkey = 1;
+ bn->tseqbase = (bn->tdense = n <= 1) != 0 ? cand[0] :
oid_nil;
+ bn->tnil = 0;
+ bn->tnonil = 1;
+ return bn;
+ }
+ if (lastp)
+ *lastp = b->hseqbase + start + n - 1;
+ return BATdense(0, b->hseqbase + start, n);
+ }
+
bn = COLnew(0, TYPE_oid, n, TRANSIENT);
if (bn == NULL)
return NULL;
@@ -735,7 +758,7 @@ BATfirstn_grouped_with_groups(BAT **topn
BBPunfix(bn1->batCacheid);
return GDK_FAIL;
}
- bn4 = BATselect(b, bn3, BUNtail(bi, BUNlast(b) - b->hseqbase),
NULL, 1, 0, 0);
+ bn4 = BATselect(b, bn3, BUNtail(bi, last - b->hseqbase), NULL,
1, 0, 0);
BBPunfix(bn3->batCacheid);
if (bn4 == NULL) {
BBPunfix(bn1->batCacheid);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list