Changeset: a951ee924c15 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a951ee924c15
Modified Files:
sql/backends/monet5/sql.c
Branch: sequences_7184
Log Message:
merged with default
diffs (truncated from 482 to 300 lines):
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -1078,28 +1078,39 @@ BATstr_group_concat(ValPtr res, BAT *b,
{
BUN ncand;
struct canditer ci;
+ gdk_return r = GDK_SUCCEED;
+ bool free_nseparator = false;
+ char *nseparator = (char *)separator;
(void) abort_on_error;
- assert((separator && !sep) || (!separator && sep)); /* only one of them
must be set */
+ assert((nseparator && !sep) || (!nseparator && sep)); /* only one of
them must be set */
res->vtype = TYPE_str;
ncand = canditer_init(&ci, b, s);
if (sep && BATcount(sep) == 1) { /* Only one element in sep */
BATiter bi = bat_iterator(sep);
- separator = BUNtvar(bi, 0);
+ nseparator = GDKstrdup(BUNtvar(bi, 0));
bat_iterator_end(&bi);
+ if (!nseparator)
+ return GDK_FAIL;
+ free_nseparator = true;
sep = NULL;
}
- if (ncand == 0 || (separator && strNil(separator))) {
+ if (ncand == 0 || (nseparator && strNil(nseparator))) {
if (VALinit(res, TYPE_str, nil_if_empty ? str_nil : "") == NULL)
- return GDK_FAIL;
- return GDK_SUCCEED;
+ r = GDK_FAIL;
+ if (free_nseparator)
+ GDKfree(nseparator);
+ return r;
}
- return concat_strings(NULL, res, b, b->hseqbase, 1, &ci, ncand, NULL,
0, 0,
- skip_nils, sep, separator, NULL);
+ r = concat_strings(NULL, res, b, b->hseqbase, 1, &ci, ncand, NULL, 0, 0,
+ skip_nils, sep, nseparator, NULL);
+ if (free_nseparator)
+ GDKfree(nseparator);
+ return r;
}
BAT *
@@ -1112,8 +1123,10 @@ BATgroupstr_group_concat(BAT *b, BAT *g,
struct canditer ci;
const char *err;
gdk_return res;
+ bool free_nseparator = false;
+ char *nseparator = (char *)separator;
- assert((separator && !sep) || (!separator && sep)); /* only one of them
must be set */
+ assert((nseparator && !sep) || (!nseparator && sep)); /* only one of
them must be set */
(void) skip_nils;
if ((err = BATgroupaggrinit(b, g, e, s, &min, &max, &ngrp,
@@ -1128,29 +1141,37 @@ BATgroupstr_group_concat(BAT *b, BAT *g,
if (sep && BATcount(sep) == 1) { /* Only one element in sep */
BATiter bi = bat_iterator(sep);
- separator = BUNtvar(bi, 0);
+ nseparator = GDKstrdup(BUNtvar(bi, 0));
bat_iterator_end(&bi);
+ if (!nseparator)
+ return NULL;
+ free_nseparator = true;
sep = NULL;
}
- if (ncand == 0 || ngrp == 0 || (separator && strNil(separator))) {
+ if (ncand == 0 || ngrp == 0 || (nseparator && strNil(nseparator))) {
/* trivial: no strings to concat, so return bat
* aligned with g with nil in the tail */
- return BATconstant(ngrp == 0 ? 0 : min, TYPE_str, str_nil,
ngrp, TRANSIENT);
+ bn = BATconstant(ngrp == 0 ? 0 : min, TYPE_str, str_nil, ngrp,
TRANSIENT);
+ goto done;
}
if (BATtdense(g) || (g->tkey && g->tnonil)) {
/* trivial: singleton groups, so all results are equal
* to the inputs (but possibly a different type) */
- return BATconvert(b, s, TYPE_str, abort_on_error, 0, 0, 0);
+ bn = BATconvert(b, s, TYPE_str, abort_on_error, 0, 0, 0);
+ goto done;
}
res = concat_strings(&bn, NULL, b, b->hseqbase, ngrp, &ci, ncand,
(const oid *) Tloc(g, 0), min, max, skip_nils, sep,
- separator, &nils);
+ nseparator, &nils);
if (res != GDK_SUCCEED)
- return NULL;
+ bn = NULL;
+done:
+ if (free_nseparator)
+ GDKfree(nseparator);
return bn;
}
diff --git a/gdk/gdk_unique.c b/gdk/gdk_unique.c
--- a/gdk/gdk_unique.c
+++ b/gdk/gdk_unique.c
@@ -31,7 +31,7 @@ BATunique(BAT *b, BAT *s)
const char *vals;
const char *vars;
int width;
- oid i, o;
+ oid i, o, hseq;
const char *nme;
Hash *hs = NULL;
BUN hb;
@@ -102,6 +102,7 @@ BATunique(BAT *b, BAT *s)
vars = NULL;
width = bi.width;
cmp = ATOMcompare(bi.type);
+ hseq = b->hseqbase;
if (ATOMbasetype(bi.type) == TYPE_bte ||
(bi.width == 1 &&
@@ -114,7 +115,7 @@ BATunique(BAT *b, BAT *s)
memset(seen, 0, sizeof(seen));
TIMEOUT_LOOP_IDX(i, cnt, timeoffset) {
o = canditer_next(&ci);
- val = ((const uint8_t *) vals)[o - b->hseqbase];
+ val = ((const uint8_t *) vals)[o - hseq];
uint32_t m = UINT32_C(1) << (val & 0x1F);
if (!(seen[val >> 5] & m)) {
seen[val >> 5] |= m;
@@ -140,7 +141,7 @@ BATunique(BAT *b, BAT *s)
memset(seen, 0, sizeof(seen));
TIMEOUT_LOOP_IDX(i, cnt, timeoffset) {
o = canditer_next(&ci);
- val = ((const uint16_t *) vals)[o - b->hseqbase];
+ val = ((const uint16_t *) vals)[o - hseq];
uint32_t m = UINT32_C(1) << (val & 0x1F);
if (!(seen[val >> 5] & m)) {
seen[val >> 5] |= m;
@@ -160,7 +161,7 @@ BATunique(BAT *b, BAT *s)
algomsg = "unique: sorted";
TIMEOUT_LOOP_IDX(i, cnt, timeoffset) {
o = canditer_next(&ci);
- v = VALUE(o - b->hseqbase);
+ v = VALUE(o - hseq);
if (prev == NULL || (*cmp)(v, prev) != 0) {
if (bunfastappTYPE(oid, bn, &o) != GDK_SUCCEED)
goto bunins_failed;
@@ -174,13 +175,11 @@ BATunique(BAT *b, BAT *s)
cnt == bi.count &&
BAThash(b) == GDK_SUCCEED)) {
BUN lo = 0;
- oid seq;
/* we already have a hash table on b, or b is
* persistent and we could create a hash table, or b
* is a view on a bat that already has a hash table */
algomsg = "unique: existing hash";
- seq = b->hseqbase;
MT_rwlock_rdlock(&b->thashlock);
hs = b->thash;
if (hs == NULL) {
@@ -191,14 +190,14 @@ BATunique(BAT *b, BAT *s)
BUN p;
o = canditer_next(&ci);
- p = o - seq;
+ p = o - hseq;
v = VALUE(p);
for (hb = HASHgetlink(hs, p + lo);
hb != BUN_NONE && hb >= lo;
hb = HASHgetlink(hs, hb)) {
assert(hb < p + lo);
if (cmp(v, BUNtail(bi, hb)) == 0 &&
- canditer_contains(&ci, hb - lo + seq)) {
+ canditer_contains(&ci, hb - lo + hseq)) {
/* we've seen this value
* before */
break;
@@ -251,7 +250,7 @@ BATunique(BAT *b, BAT *s)
}
TIMEOUT_LOOP_IDX(i, cnt, timeoffset) {
o = canditer_next(&ci);
- v = VALUE(o - b->hseqbase);
+ v = VALUE(o - hseq);
prb = HASHprobe(hs, v);
for (hb = HASHget(hs, prb);
hb != BUN_NONE;
@@ -260,7 +259,7 @@ BATunique(BAT *b, BAT *s)
break;
}
if (hb == BUN_NONE) {
- p = o - b->hseqbase;
+ p = o - hseq;
if (bunfastappTYPE(oid, bn, &o) != GDK_SUCCEED)
goto bunins_failed;
/* enter into hash table */
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -1980,14 +1980,15 @@ JSONrenderRowObject(BAT **bl, MalBlkPtr
len = 1;
for (i = pci->retc; i < pci->argc; i += 2) {
name = stk->stk[getArg(pci, i)].val.sval;
+ tpe = getBatType(getArgType(mb, pci, i + 1));
bi = bat_iterator(bl[i + 1]);
p = BUNtail(bi, idx);
- bat_iterator_end(&bi);
- tpe = getBatType(getArgType(mb, pci, i + 1));
if ((val = ATOMformat(tpe, p)) == NULL) {
+ bat_iterator_end(&bi);
GDKfree(row);
return NULL;
}
+ bat_iterator_end(&bi);
if (strncmp(val, "nil", 3) == 0) {
GDKfree(val);
val = NULL;
@@ -2096,13 +2097,14 @@ JSONrenderRowArray(BAT **bl, MalBlkPtr m
row[1] = 0;
len = 1;
for (i = pci->retc; i < pci->argc; i++) {
+ tpe = getBatType(getArgType(mb, pci, i));
bi = bat_iterator(bl[i]);
p = BUNtail(bi, idx);
- bat_iterator_end(&bi);
- tpe = getBatType(getArgType(mb, pci, i));
if ((val = ATOMformat(tpe, p)) == NULL) {
+ bat_iterator_end(&bi);
goto memfail;
}
+ bat_iterator_end(&bi);
if (strcmp(val, "nil") == 0) {
GDKfree(val);
val = NULL;
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3161,6 +3161,7 @@ SQLbat_alpha_cst(bat *res, const bat *de
if (BUNappend(bn, &r, false) != GDK_SUCCEED) {
BBPreclaim(bn);
bat_iterator_end(&bi);
+ BBPunfix(b->batCacheid);
throw(SQL, "sql.alpha", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
}
@@ -3207,6 +3208,7 @@ SQLcst_alpha_bat(bat *res, const dbl *de
if (BUNappend(bn, &r, false) != GDK_SUCCEED) {
BBPreclaim(bn);
bat_iterator_end(&bi);
+ BBPunfix(b->batCacheid);
throw(SQL, "sql.alpha", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
}
diff --git a/sql/backends/monet5/sql_subquery.c
b/sql/backends/monet5/sql_subquery.c
--- a/sql/backends/monet5/sql_subquery.c
+++ b/sql/backends/monet5/sql_subquery.c
@@ -16,18 +16,17 @@ zero_or_one_error(ptr ret, const bat *bi
BAT *b;
BUN c;
size_t _s;
+ BATiter bi = {0};
const void *p = NULL;
- if ((b = BATdescriptor(*bid)) == NULL) {
+ if ((b = BATdescriptor(*bid)) == NULL)
throw(SQL, "sql.zero_or_one", SQLSTATE(HY005) "Cannot access
column descriptor");
- }
c = BATcount(b);
if (c == 0) {
p = ATOMnilptr(b->ttype);
} else if (c == 1 || (c > 1 && *err == false)) {
- BATiter bi = bat_iterator(b);
+ bi = bat_iterator(b);
p = BUNtail(bi, 0);
- bat_iterator_end(&bi);
} else {
p = NULL;
BBPunfix(b->batCacheid);
@@ -40,6 +39,8 @@ zero_or_one_error(ptr ret, const bat *bi
_s = ATOMlen(ATOMtype(b->ttype), p);
*(ptr *) ret = GDKmalloc(_s);
if (*(ptr *) ret == NULL) {
+ if (bi.b)
+ bat_iterator_end(&bi);
BBPunfix(b->batCacheid);
throw(SQL, "sql.zero_or_one", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
@@ -47,6 +48,8 @@ zero_or_one_error(ptr ret, const bat *bi
} else if (b->ttype == TYPE_bat) {
bat bid = *(bat *) p;
if ((*(BAT **) ret = BATdescriptor(bid)) == NULL){
+ if (bi.b)
+ bat_iterator_end(&bi);
BBPunfix(b->batCacheid);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list