Changeset: f071fac0fdba for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f071fac0fdba Added Files: sql/test/BugTracker-2013/Tests/singleton-median.Bug-3389.sql sql/test/BugTracker-2013/Tests/singleton-median.Bug-3389.stable.err sql/test/BugTracker-2013/Tests/singleton-median.Bug-3389.stable.out Modified Files: clients/mapiclient/ReadlineTools.c gdk/gdk_aggr.c sql/test/BugTracker-2013/Tests/All Branch: default Log Message:
Merge with Feb2013 branch. diffs (truncated from 472 to 300 lines): diff --git a/clients/mapiclient/ReadlineTools.c b/clients/mapiclient/ReadlineTools.c --- a/clients/mapiclient/ReadlineTools.c +++ b/clients/mapiclient/ReadlineTools.c @@ -70,12 +70,14 @@ sql_tablename_generator(const char *text static int seekpos, len, rowcount; static MapiHdl table_hdl; - char *name; if (!state) { + char query[512]; + seekpos = 0; len = strlen(text); - if ((table_hdl = mapi_query(_mid, "SELECT t.\"name\", s.\"name\" FROM \"sys\".\"tables\" t, \"sys\".\"schemas\" s where t.schema_id = s.id")) == NULL || mapi_error(_mid)) { + snprintf(query, sizeof(query), "SELECT t.\"name\", s.\"name\" FROM \"sys\".\"tables\" t, \"sys\".\"schemas\" s where t.schema_id = s.id AND t.\"name\" like '%s%%'", text); + if ((table_hdl = mapi_query(_mid, query)) == NULL || mapi_error(_mid)) { if (table_hdl) { mapi_explain_query(table_hdl, stderr); mapi_close_handle(table_hdl); @@ -88,18 +90,18 @@ sql_tablename_generator(const char *text } while (seekpos < rowcount) { + const char *name; + mapi_seek_row(table_hdl, seekpos++, MAPI_SEEK_SET); mapi_fetch_row(table_hdl); name = mapi_fetch_field(table_hdl, 0); if (strncmp(name, text, len) == 0) { - char *s, *schema = mapi_fetch_field(table_hdl, 1); - int l1 = strlen(name), l2 = strlen(schema); + char *s; + const char *schema = mapi_fetch_field(table_hdl, 1); + size_t l1 = strlen(name), l2 = strlen(schema); - s = malloc(l1 + l2 + 2); - s[0] = 0; - strcat(s, schema); - strcat(s, "."); - strcat(s, name); + s = malloc(l1 + l2 + 6); + snprintf(s, l1 + l2 + 6, "\"%s\".\"%s\"", schema, name); return s; } } diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c --- a/gdk/gdk_aggr.c +++ b/gdk/gdk_aggr.c @@ -158,6 +158,7 @@ BATgroupaggrinit(const BAT *b, const BAT TYPE1 x; \ const TYPE1 *vals = (const TYPE1 *) values; \ if (ngrp == 1 && cand == NULL) { \ + /* single group, no candidate list */ \ TYPE2 sum; \ ALGODEBUG fprintf(stderr, \ "#%s: no candidates, no groups; " \ @@ -196,6 +197,7 @@ BATgroupaggrinit(const BAT *b, const BAT if (*seen) \ *sums = sum; \ } else if (ngrp == 1) { \ + /* single group, with candidate list */ \ TYPE2 sum; \ int seenval = 0; \ ALGODEBUG fprintf(stderr, \ @@ -204,7 +206,7 @@ BATgroupaggrinit(const BAT *b, const BAT "\n", \ func, start, end); \ sum = 0; \ - while (cand < candend) { \ + while (cand < candend && nils == 0) { \ i = *cand++ - seqb; \ if (i >= end) \ break; \ @@ -225,6 +227,7 @@ BATgroupaggrinit(const BAT *b, const BAT if (seenval) \ *sums = sum; \ } else if (cand == NULL) { \ + /* multiple groups, no candidate list */ \ ALGODEBUG fprintf(stderr, \ "#%s: no candidates, with groups; " \ "start " BUNFMT ", end " BUNFMT \ @@ -235,27 +238,32 @@ BATgroupaggrinit(const BAT *b, const BAT (gids[i] >= min && gids[i] <= max)) { \ gid = gids ? gids[i] - min : (oid) i; \ x = vals[i]; \ - if (nil_if_empty && x != TYPE1##_nil && \ - !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ - seen[gid >> 5] |= 1 << (gid & 0x1F); \ - sums[gid] = 0; \ - } \ if (x == TYPE1##_nil) { \ if (!skip_nils) { \ sums[gid] = TYPE2##_nil; \ - nils++; \ + nils++; \ } \ - } else if (sums[gid] != TYPE2##_nil) { \ - ADD_WITH_CHECK(TYPE1, x, \ - TYPE2, \ - sums[gid], \ - TYPE2, \ - sums[gid], \ - goto overflow); \ + } else { \ + if (nil_if_empty && \ + !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ + seen[gid >> 5] |= 1 << (gid & 0x1F); \ + sums[gid] = 0; \ + } \ + if (sums[gid] != TYPE2##_nil) { \ + ADD_WITH_CHECK( \ + TYPE1, \ + x, \ + TYPE2, \ + sums[gid], \ + TYPE2, \ + sums[gid], \ + goto overflow); \ + } \ } \ } \ } \ } else { \ + /* multiple groups, with candidate list */ \ ALGODEBUG fprintf(stderr, \ "#%s: with candidates, with " \ "groups; start " BUNFMT ", " \ @@ -268,24 +276,28 @@ BATgroupaggrinit(const BAT *b, const BAT if (gids == NULL || \ (gids[i] >= min && gids[i] <= max)) { \ gid = gids ? gids[i] - min : (oid) i; \ - if (nil_if_empty && \ - !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ - seen[gid >> 5] |= 1 << (gid & 0x1F); \ - sums[gid] = 0; \ - } \ x = vals[i]; \ if (x == TYPE1##_nil) { \ if (!skip_nils) { \ sums[gid] = TYPE2##_nil; \ nils++; \ } \ - } else if (sums[gid] != TYPE2##_nil) { \ - ADD_WITH_CHECK(TYPE1, x, \ - TYPE2, \ - sums[gid], \ - TYPE2, \ - sums[gid], \ - goto overflow); \ + } else { \ + if (nil_if_empty && \ + !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ + seen[gid >> 5] |= 1 << (gid & 0x1F); \ + sums[gid] = 0; \ + } \ + if (sums[gid] != TYPE2##_nil) { \ + ADD_WITH_CHECK( \ + TYPE1, \ + x, \ + TYPE2, \ + sums[gid], \ + TYPE2, \ + sums[gid], \ + goto overflow); \ + } \ } \ } \ } \ @@ -638,22 +650,25 @@ BATsum(void *res, int tp, BAT *b, BAT *s else \ gid = (oid) i; \ } \ - if (nil_if_empty && \ - !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ - seen[gid >> 5] |= 1 << (gid & 0x1F); \ - prods[gid] = 1; \ - } \ if (vals[i] == TYPE1##_nil) { \ if (!skip_nils) { \ prods[gid] = TYPE2##_nil; \ nils++; \ } \ - } else if (prods[gid] != TYPE2##_nil) { \ - MUL4_WITH_CHECK(TYPE1, vals[i], \ + } else { \ + if (nil_if_empty && \ + !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ + seen[gid >> 5] |= 1 << (gid & 0x1F); \ + prods[gid] = 1; \ + } \ + if (prods[gid] != TYPE2##_nil) { \ + MUL4_WITH_CHECK( \ + TYPE1, vals[i], \ TYPE2, prods[gid], \ TYPE2, prods[gid], \ TYPE3, \ goto overflow); \ + } \ } \ } \ } \ @@ -684,21 +699,24 @@ BATsum(void *res, int tp, BAT *b, BAT *s else \ gid = (oid) i; \ } \ - if (nil_if_empty && \ - !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ - seen[gid >> 5] |= 1 << (gid & 0x1F); \ - prods[gid] = 1; \ - } \ if (vals[i] == TYPE##_nil) { \ if (!skip_nils) { \ prods[gid] = lng_nil; \ nils++; \ } \ - } else if (prods[gid] != lng_nil) { \ - LNGMUL_CHECK(TYPE, vals[i], \ - lng, prods[gid], \ - prods[gid], \ - goto overflow); \ + } else { \ + if (nil_if_empty && \ + !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ + seen[gid >> 5] |= 1 << (gid & 0x1F); \ + prods[gid] = 1; \ + } \ + if (prods[gid] != lng_nil) { \ + LNGMUL_CHECK( \ + TYPE, vals[i], \ + lng, prods[gid], \ + prods[gid], \ + goto overflow); \ + } \ } \ } \ } \ @@ -729,25 +747,27 @@ BATsum(void *res, int tp, BAT *b, BAT *s else \ gid = (oid) i; \ } \ - if (nil_if_empty && vals[i] != TYPE1##_nil && \ - !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ - seen[gid >> 5] |= 1 << (gid & 0x1F); \ - prods[gid] = 1; \ - } \ if (vals[i] == TYPE1##_nil) { \ if (!skip_nils) { \ prods[gid] = TYPE2##_nil; \ nils++; \ } \ - } else if (prods[gid] != TYPE2##_nil) { \ - if (ABSOLUTE(vals[i]) > 1 && \ - GDK_##TYPE2##_max / ABSOLUTE(vals[i]) < ABSOLUTE(prods[gid])) { \ - if (abort_on_error) \ - goto overflow; \ - prods[gid] = TYPE2##_nil; \ - nils++; \ - } else { \ - prods[gid] *= vals[i]; \ + } else { \ + if (nil_if_empty && \ + !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \ + seen[gid >> 5] |= 1 << (gid & 0x1F); \ + prods[gid] = 1; \ + } \ + if (prods[gid] != TYPE2##_nil) { \ + if (ABSOLUTE(vals[i]) > 1 && \ + GDK_##TYPE2##_max / ABSOLUTE(vals[i]) < ABSOLUTE(prods[gid])) { \ + if (abort_on_error) \ + goto overflow; \ + prods[gid] = TYPE2##_nil; \ + nils++; \ + } else { \ + prods[gid] *= vals[i]; \ + } \ } \ } \ } \ @@ -2205,6 +2225,8 @@ BATgroupmedian(BAT *b, BAT *g, BAT *e, B } if (s) { + /* there is a candidate list, replace b (and g, if + * given) with just the values we're interested in */ b = BATleftjoin(s, b, BATcount(s)); if (b->htype != TYPE_void) { t1 = BATmirror(BATmark(BATmirror(b), 0)); @@ -2223,7 +2245,19 @@ BATgroupmedian(BAT *b, BAT *g, BAT *e, B } } + /* we want to sort b so that we can figure out the median, but + * if g is given, sort g and subsort b so that we can get the + * median for each group */ if (g) { + if (BATtdense(g)) { + /* singleton groups, so calculating medians is + * easy */ + bn = BATcopy(b, TYPE_void, b->ttype, 0); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list