Changeset: e0e485da570b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e0e485da570b
Modified Files:
gdk/gdk_group.c
gdk/gdk_unique.c
Branch: string-dedup
Log Message:
Merge with default branch.
diffs (truncated from 421 to 300 lines):
diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -73,7 +73,7 @@
if (ngrp == maxgrps) { \
/* we need to extend extents and histo bats, */ \
/* do it at most once */ \
- maxgrps = BATcount(b); \
+ maxgrps = bi.count; \
if (extents) { \
BATsetcount(en, ngrp); \
if (BATextend(en, maxgrps) != GDK_SUCCEED) \
@@ -965,15 +965,13 @@ BATgroup_internal(BAT **groups, BAT **ex
/* byte-sized values, use 256 entry array to keep
* track of doled out group ids; note that we can't
* possibly have more than 256 groups, so the group id
- * fits in an unsigned char */
- unsigned char *restrict bgrps = GDKmalloc(256);
- const unsigned char *restrict w = (const unsigned char *)
bi.base;
- unsigned char v;
+ * fits in an uint8_t */
+ uint8_t bgrps[256];
+ const uint8_t *restrict w = (const uint8_t *) bi.base;
+ uint8_t v;
algomsg = "byte-sized groups -- ";
- if (bgrps == NULL)
- goto error1;
- memset(bgrps, 0xFF, 256);
+ memset(bgrps, 0xFF, sizeof(bgrps));
if (histo)
memset(cnts, 0, maxgrps * sizeof(lng));
ngrp = 0;
@@ -982,7 +980,7 @@ BATgroup_internal(BAT **groups, BAT **ex
oid o = canditer_next(&ci);
p = o - b->hseqbase;
if ((v = bgrps[w[p]]) == 0xFF && ngrp < 256) {
- bgrps[w[p]] = v = (unsigned char) ngrp++;
+ bgrps[w[p]] = v = (uint8_t) ngrp++;
maxgrppos = r;
if (extents)
exts[v] = o;
@@ -995,20 +993,19 @@ BATgroup_internal(BAT **groups, BAT **ex
}
TIMEOUT_CHECK(timeoffset,
GOTO_LABEL_TIMEOUT_HANDLER(error));
- GDKfree(bgrps);
} else if (g == NULL && t == TYPE_sht) {
/* short-sized values, use 65536 entry array to keep
* track of doled out group ids; note that we can't
* possibly have more than 65536 groups, so the group
- * id fits in an unsigned short */
- unsigned short *restrict sgrps = GDKmalloc(65536 *
sizeof(short));
- const unsigned short *restrict w = (const unsigned short *)
bi.base;
- unsigned short v;
+ * id fits in an uint16_t */
+ uint16_t *restrict sgrps = GDKmalloc(65536 * sizeof(short));
+ const uint16_t *restrict w = (const uint16_t *) bi.base;
+ uint16_t v;
algomsg = "short-sized groups -- ";
if (sgrps == NULL)
goto error1;
- memset(sgrps, 0xFF, 65536 * sizeof(short));
+ memset(sgrps, 0xFF, 65536 * sizeof(uint16_t));
if (histo)
memset(cnts, 0, maxgrps * sizeof(lng));
ngrp = 0;
@@ -1017,7 +1014,7 @@ BATgroup_internal(BAT **groups, BAT **ex
oid o = canditer_next(&ci);
p = o - b->hseqbase;
if ((v = sgrps[w[p]]) == 0xFFFF && ngrp < 65536) {
- sgrps[w[p]] = v = (unsigned short) ngrp++;
+ sgrps[w[p]] = v = (uint16_t) ngrp++;
maxgrppos = r;
if (extents)
exts[v] = o;
@@ -1190,7 +1187,7 @@ BATgroup_internal(BAT **groups, BAT **ex
const bte *w = (bte *) bi.base;
GRP_create_partial_hash_table_core(
(void) 0,
- (v = ((ulng)grps[r]<<8)|(unsigned
char)w[p], hash_lng(hs, &v)),
+ (v = ((ulng)grps[r]<<8)|(uint8_t)w[p],
hash_lng(hs, &v)),
w[p] == w[hb] && grps[r] == grps[q],
(void) 0,
NOGRPTST);
@@ -1207,7 +1204,7 @@ BATgroup_internal(BAT **groups, BAT **ex
const sht *w = (sht *) bi.base;
GRP_create_partial_hash_table_core(
(void) 0,
- (v = ((ulng)grps[r]<<16)|(unsigned
short)w[p], hash_lng(hs, &v)),
+ (v =
((ulng)grps[r]<<16)|(uint16_t)w[p], hash_lng(hs, &v)),
w[p] == w[hb] && grps[r] == grps[q],
(void) 0,
NOGRPTST);
diff --git a/gdk/gdk_unique.c b/gdk/gdk_unique.c
--- a/gdk/gdk_unique.c
+++ b/gdk/gdk_unique.c
@@ -35,7 +35,6 @@ BATunique(BAT *b, BAT *s)
const char *nme;
Hash *hs = NULL;
BUN hb;
- BATiter bi;
int (*cmp)(const void *, const void *);
struct canditer ci;
const char *algomsg = "";
@@ -79,35 +78,34 @@ BATunique(BAT *b, BAT *s)
assert(b->ttype != TYPE_void);
+ BATiter bi = bat_iterator(b);
BUN initsize = BUN_NONE;
if (s == NULL) {
MT_rwlock_rdlock(&b->thashlock);
if (b->thash != NULL && b->thash != (Hash *) 1)
initsize = b->thash->nunique;
MT_rwlock_rdunlock(&b->thashlock);
- if (initsize == BUN_NONE) {
- MT_lock_set(&b->theaplock);
- if (b->tunique_est != 0)
- initsize = (BUN) b->tunique_est;
- MT_lock_unset(&b->theaplock);
- }
+ if (initsize == BUN_NONE && bi.unique_est != 0)
+ initsize = (BUN) bi.unique_est;
}
if (initsize == BUN_NONE)
initsize = 1024;
bn = COLnew(0, TYPE_oid, initsize, TRANSIENT);
- if (bn == NULL)
+ if (bn == NULL) {
+ bat_iterator_end(&bi);
return NULL;
- bi = bat_iterator(b);
+ }
vals = bi.base;
- if (b->tvarsized && b->ttype)
+ if (b->tvarsized && bi.type)
vars = bi.vh->base;
else
vars = NULL;
width = bi.width;
- cmp = ATOMcompare(b->ttype);
+ cmp = ATOMcompare(bi.type);
- if (ATOMbasetype(b->ttype) == TYPE_bte ||
- (b->twidth == 1 && ATOMstorage(b->ttype) == TYPE_str)) {
+ if (ATOMbasetype(bi.type) == TYPE_bte ||
+ (bi.width == 1 &&
+ ATOMstorage(bi.type) == TYPE_str)) {
uint8_t val;
algomsg = "unique: byte-sized atoms";
@@ -130,8 +128,9 @@ BATunique(BAT *b, BAT *s)
}
TIMEOUT_CHECK(timeoffset,
GOTO_LABEL_TIMEOUT_HANDLER(bunins_failed));
- } else if (ATOMbasetype(b->ttype) == TYPE_sht ||
- (b->twidth == 2 && ATOMstorage(b->ttype) == TYPE_str)) {
+ } else if (ATOMbasetype(bi.type) == TYPE_sht ||
+ (bi.width == 2 &&
+ ATOMstorage(bi.type) == TYPE_str)) {
uint16_t val;
algomsg = "unique: short-sized atoms";
@@ -170,7 +169,7 @@ BATunique(BAT *b, BAT *s)
GOTO_LABEL_TIMEOUT_HANDLER(bunins_failed));
} else if (BATcheckhash(b) ||
(!b->batTransient &&
- cnt == BATcount(b) &&
+ cnt == bi.count &&
BAThash(b) == GDK_SUCCEED)) {
BUN lo = 0;
oid seq;
@@ -223,10 +222,10 @@ BATunique(BAT *b, BAT *s)
GDKclrerr(); /* not interested in BAThash errors */
algomsg = "unique: new partial hash";
nme = BBP_physical(b->batCacheid);
- if (ATOMbasetype(b->ttype) == TYPE_bte) {
+ if (ATOMbasetype(bi.type) == TYPE_bte) {
mask = (BUN) 1 << 8;
cmp = NULL; /* no compare needed, "hash" is perfect */
- } else if (ATOMbasetype(b->ttype) == TYPE_sht) {
+ } else if (ATOMbasetype(bi.type) == TYPE_sht) {
mask = (BUN) 1 << 16;
cmp = NULL; /* no compare needed, "hash" is perfect */
} else {
@@ -238,11 +237,11 @@ BATunique(BAT *b, BAT *s)
GDKerror("cannot allocate hash table\n");
goto bunins_failed;
}
- if ((hs->heaplink.farmid = BBPselectfarm(TRANSIENT, b->ttype,
hashheap)) < 0 ||
- (hs->heapbckt.farmid = BBPselectfarm(TRANSIENT, b->ttype,
hashheap)) < 0 ||
+ if ((hs->heaplink.farmid = BBPselectfarm(TRANSIENT, bi.type,
hashheap)) < 0 ||
+ (hs->heapbckt.farmid = BBPselectfarm(TRANSIENT, bi.type,
hashheap)) < 0 ||
snprintf(hs->heaplink.filename,
sizeof(hs->heaplink.filename), "%s.thshunil%x", nme, (unsigned) THRgettid()) >=
(int) sizeof(hs->heaplink.filename) ||
snprintf(hs->heapbckt.filename,
sizeof(hs->heapbckt.filename), "%s.thshunib%x", nme, (unsigned) THRgettid()) >=
(int) sizeof(hs->heapbckt.filename) ||
- HASHnew(hs, b->ttype, BUNlast(b), mask, BUN_NONE, false) !=
GDK_SUCCEED) {
+ HASHnew(hs, bi.type, BUNlast(b), mask, BUN_NONE, false) !=
GDK_SUCCEED) {
GDKfree(hs);
hs = NULL;
GDKerror("cannot allocate hash table\n");
@@ -281,7 +280,7 @@ BATunique(BAT *b, BAT *s)
bn->tkey = true;
bn->tnil = false;
bn->tnonil = true;
- if (BATcount(bn) == BATcount(b)) {
+ if (BATcount(bn) == bi.count) {
/* it turns out all values are distinct */
assert(b->tnokey[0] == 0);
assert(b->tnokey[1] == 0);
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -988,7 +988,7 @@ create_func(mvc *sql, char *sname, char
if (!sff->s || sff->system)
throw(SQL,"sql.create_func", SQLSTATE(42000)
"%s %s: not allowed to replace system %s %s;", base, F, fn, sff->base.name);
- if (sff->lang == FUNC_LANG_MAL &&
!mal_function_find_implementation_address(&fimp, sql, sff)) {
+ if (sff->lang == FUNC_LANG_MAL &&
mal_function_find_implementation_address(&fimp, sql, sff) < 0) {
backend_ok = false;
sql->session->status = 0; /* clean the error */
sql->errstr[0] = '\0';
diff --git a/sql/backends/monet5/sql_gencode.c
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -1106,81 +1106,77 @@ backend_create_c_func(backend *be, sql_f
int
mal_function_find_implementation_address(str *res, mvc *m, sql_func *f)
{
- mvc *o = m;
+ mvc o = *m;
buffer *b = NULL;
bstream *bs = NULL;
stream *buf = NULL;
char *n = NULL;
int len = _strlen(f->query);
- sql_schema *s = cur_schema(m);
dlist *l, *ext_name;
- if (!(m = ZNEW(mvc))) {
- (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
- }
- m->type = Q_PARSE;
- m->user_id = m->role_id = USER_MONETDB;
- m->store = o->store;
- if (!(m->pa = sa_create(NULL))) {
- (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
+ if (!(b = (buffer*)malloc(sizeof(buffer)))) {
+ (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ return -1;
}
- if (!(m->session = sql_session_create(m->store, m->pa, 0))) {
- (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
- }
- if (s)
- m->session->schema = s;
- if (!(m->sa = sa_create(NULL))) {
- (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
- }
- if (!(b = (buffer*)GDKmalloc(sizeof(buffer)))) {
- (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
- }
- if (!(n = GDKmalloc(len + 2))) {
- (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
+ if (!(n = malloc(len + 2))) {
+ free(b);
+ (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ return -1;
}
snprintf(n, len + 2, "%s\n", f->query);
len++;
buffer_init(b, n, len);
if (!(buf = buffer_rastream(b, "sqlstatement"))) {
- (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
+ buffer_destroy(b);
+ (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ return -1;
}
if (!(bs = bstream_create(buf, b->len))) {
- (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
+ buffer_destroy(b);
+ (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ return -1;
}
scanner_init(&m->scanner, bs, NULL);
m->scanner.mode = LINE_1;
bstream_next(m->scanner.rs);
- (void) sqlparse(m); /* blindly ignore errors */
- assert(m->sym->token == SQL_CREATE_FUNC);
- l = m->sym->data.lval;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list