Changeset: 4aab4a55d975 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4aab4a55d975 Modified Files: gdk/gdk_analytic.c gdk/gdk_analytic.h sql/backends/monet5/rel_bin.c sql/backends/monet5/sql_rank.c sql/backends/monet5/sql_rank.h sql/backends/monet5/sql_rank.mal sql/backends/monet5/sql_rank.mal.sh sql/backends/monet5/sql_rank_hge.mal sql/backends/monet5/sql_rank_hge.mal.sh sql/common/sql_types.c sql/include/sql_catalog.h sql/server/rel_select.c Branch: analytics Log Message:
Major cleanup in gdk_analytic. My implementation of range frame was indeed the
groups frame. With this cleanup, rows, range and groups frames are properly
implemented.
Meanwhile as the code was growing significantly for each frame implementation,
it was becoming difficult to maintain. The MAL generation was changed for
aggregations on a window where each row overlap is a calculated with
sql.window_start_bound and sql.window_end_bound calls. This approach simplifies
the implementation for each aggregate and upcoming steps such as varying row
bounds and the EXCLUDE clause.
diffs (truncated from 4970 to 300 lines):
diff --git a/gdk/gdk_analytic.c b/gdk/gdk_analytic.c
--- a/gdk/gdk_analytic.c
+++ b/gdk/gdk_analytic.c
@@ -15,9 +15,9 @@
do { \
TPE *bp = (TPE*)Tloc(b, 0); \
TPE prev = *bp, *end = bp + cnt; \
- if(rp) { \
- for(; bp<end; bp++, rb++, rp++) { \
- *rb = *rp; \
+ if(np) { \
+ for(; bp<end; bp++, rb++, np++) { \
+ *rb = *np; \
if (*bp != prev) { \
*rb = TRUE; \
prev = *bp; \
@@ -25,21 +25,21 @@
} \
} else { \
for(; bp<end; bp++, rb++) { \
- *rb = FALSE; \
if (*bp != prev) { \
*rb = TRUE; \
prev = *bp; \
+ } else { \
+ *rb = FALSE; \
} \
} \
} \
} while(0);
gdk_return
-GDKanalyticaldiff(BAT *r, BAT *b, BAT *c, int tpe)
+GDKanalyticaldiff(BAT *r, BAT *b, BAT *p, int tpe)
{
BUN i, cnt = BATcount(b);
- bit *restrict rb = (bit*)Tloc(r, 0), *restrict rp = c ? (bit*)Tloc(c,
0) : NULL;
- int (*atomcmp)(const void *, const void *);
+ bit *restrict rb = (bit*)Tloc(r, 0), *restrict np = p ? (bit*)Tloc(p,
0) : NULL;
switch(tpe) {
case TYPE_bit:
@@ -71,10 +71,10 @@ GDKanalyticaldiff(BAT *r, BAT *b, BAT *c
default: {
BATiter it = bat_iterator(b);
ptr v = BUNtail(it, 0), next;
- atomcmp = ATOMcompare(tpe);
- if(rp) {
- for (i=0; i<cnt; i++, rb++, rp++) {
- *rb = *rp;
+ int (*atomcmp)(const void *, const void *) =
ATOMcompare(tpe);
+ if(np) {
+ for (i=0; i<cnt; i++, rb++, np++) {
+ *rb = *np;
next = BUNtail(it, i);
if (atomcmp(v, next) != 0) {
*rb = TRUE;
@@ -83,11 +83,12 @@ GDKanalyticaldiff(BAT *r, BAT *b, BAT *c
}
} else {
for(i=0; i<cnt; i++, rb++) {
- *rb = FALSE;
next = BUNtail(it, i);
if (atomcmp(v, next) != 0) {
*rb = TRUE;
v = next;
+ } else {
+ *rb = FALSE;
}
}
}
@@ -101,6 +102,400 @@ GDKanalyticaldiff(BAT *r, BAT *b, BAT *c
#undef ANALYTICAL_DIFF_IMP
+#define ANALYTICAL_WINDOW_BOUNDS_FIXED_ROWS_START(TPE) \
+ do { \
+ TPE *bs = MIN(pbp + limit, bp); \
+ int curval = 0; \
+ for(; pbp<bs; pbp++, rb++) \
+ *rb = curval++; \
+ for(; pbp<bp; pbp++, rb++) \
+ *rb = curval; \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_FIXED_ROWS_END(TPE) \
+ do { \
+ int curval = MIN(ncnt, limit); \
+ TPE *bs = bp - curval; \
+ curval++; \
+ for(; pbp<bs; pbp++, rb++) \
+ *rb = curval; \
+ for(; pbp<bp; pbp++, rb++) \
+ *rb = --curval; \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_FIXED_RANGE_START(TPE) \
+ do { \
+ TPE *bl = pbp-1, *bs, v, blimit = (TPE) limit; \
+ int curval; \
+ for(; pbp<bp; pbp++, rb++) { \
+ curval = 0; \
+ v = *pbp; \
+ for(bs=pbp-1; bs>bl; bs--, curval++) { \
+ if (ABSOLUTE(v - *bs) > blimit) \
+ break; \
+ } \
+ *rb = curval; \
+ } \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_FIXED_RANGE_END(TPE) \
+ do { \
+ TPE *bs, v, blimit = (TPE) limit; \
+ int curval; \
+ for(; pbp<bp; pbp++, rb++) { \
+ curval = 1; \
+ v = *pbp; \
+ for(bs=pbp+1; bs<bp; bs++, curval++) { \
+ if (ABSOLUTE(v - *bs) > blimit) \
+ break; \
+ } \
+ *rb = curval; \
+ } \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_FIXED_GROUPS_START(TPE) \
+ do { \
+ TPE *bl = pbp-1, *bs, v; \
+ int curval; \
+ BUN rlimit; \
+ for(; pbp<bp; pbp++, rb++) { \
+ curval = 0; \
+ rlimit = limit; \
+ v = *pbp; \
+ for(bs=pbp-1; bs>bl; bs--, curval++) { \
+ if(v != *bs) { \
+ if(rlimit == 0) \
+ break;
\
+ rlimit--; \
+ v = *bs; \
+ } \
+ } \
+ *rb = curval; \
+ } \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_FIXED_GROUPS_END(TPE) \
+ do { \
+ TPE *bs, v; \
+ int curval; \
+ BUN rlimit; \
+ for(; pbp<bp; pbp++, rb++) { \
+ curval = 1; \
+ rlimit = limit; \
+ v = *pbp; \
+ for(bs=pbp+1; bs<bp; bs++, curval++) { \
+ if(v != *bs) { \
+ if(rlimit == 0) \
+ break; \
+ rlimit--; \
+ v = *bs; \
+ } \
+ } \
+ *rb = curval; \
+ } \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_FIXED_ALL_START(TPE) \
+ do { \
+ int curval = 0; \
+ for(; pbp<bp; pbp++, rb++) \
+ *rb = curval++; \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_FIXED_ALL_END(TPE) \
+ do { \
+ int curval = ncnt + 1; \
+ for(; pbp<bp; pbp++, rb++) \
+ *rb = --curval; \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_CALC_FIXED(TPE, IMP) \
+ do { \
+ TPE *pbp, *bp; \
+ pbp = bp = (TPE*)Tloc(b, 0); \
+ if(start) { \
+ if(np) { \
+ nend += cnt; \
+ for(; np<nend; np++) { \
+ if (*np) { \
+ ncnt = (np - pnp); \
+ bp += ncnt; \
+ IMP##_START(TPE) \
+ pnp = np; \
+ pbp = bp; \
+ } \
+ } \
+ ncnt = (np - pnp); \
+ bp += ncnt; \
+ IMP##_START(TPE) \
+ } else { \
+ ncnt = cnt; \
+ bp += ncnt; \
+ IMP##_START(TPE) \
+ } \
+ } else if(np) { \
+ nend += cnt; \
+ for(; np<nend; np++) { \
+ if (*np) { \
+ ncnt = (np - pnp); \
+ bp += ncnt; \
+ IMP##_END(TPE) \
+ pnp = np; \
+ pbp = bp; \
+ } \
+ } \
+ ncnt = (np - pnp); \
+ bp += ncnt; \
+ IMP##_END(TPE) \
+ } else { \
+ ncnt = cnt; \
+ bp += ncnt; \
+ IMP##_END(TPE) \
+ } \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_VARSIZED_ROWS_START \
+ do { \
+ int curval = 0; \
+ BUN l = MIN(k + limit, i); \
+ for(; k<l; k++, rb++) \
+ *rb = curval++; \
+ for(; k<i; k++, rb++) \
+ *rb = curval; \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_VARSIZED_ROWS_END \
+ do { \
+ int curval = MIN(ncnt, limit); \
+ BUN l = i - curval; \
+ curval++; \
+ for(; k<l; k++, rb++) \
+ *rb = curval; \
+ for(; k<i; k++, rb++) \
+ *rb = --curval; \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_VARSIZED_RANGE_START \
+ do { \
+ void *v; \
+ int curval, llimit = (int)limit; \
+ BUN j; \
+ *rb = 0; /* the first element's window size is hardcoded to
avoid overflow in BUN */ \
+ rb++; \
+ k++; \
+ j = k - 1; \
+ for(; k<i; k++, rb++) { \
+ curval = 1; \
+ v = BUNtail(bpi, k); \
+ for(BUN l=k-1; l>j; l--, curval++) { \
+ if (ABSOLUTE(atomcmp(v, BUNtail(bpi, l))) >
llimit) \
+ break; \
+ } \
+ *rb = curval; \
+ } \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_VARSIZED_RANGE_END \
+ do { \
+ void *v; \
+ int curval, llimit = (int)limit; \
+ for(; k<i; k++, rb++) { \
+ curval = 1; \
+ v = BUNtail(bpi, k); \
+ for(BUN l=k+1; l<i; l++, curval++) { \
+ if (ABSOLUTE(atomcmp(v, BUNtail(bpi, l))) >
llimit) \
+ break; \
+ } \
+ *rb = curval; \
+ } \
+ } while(0);
+
+#define ANALYTICAL_WINDOW_BOUNDS_VARSIZED_GROUPS_START \
+ do { \
+ void *v, *next; \
+ int curval; \
+ BUN j, rlimit; \
+ *rb = 0; /* the first element's window size is hardcoded to
avoid overflow in BUN */ \
+ rb++; \
+ k++; \
+ j = k - 1; \
+ for(; k<i; k++, rb++) { \
+ curval = 1; \
+ rlimit = limit; \
+ v = BUNtail(bpi, k); \
+ for(BUN l=k-1; l>j; l--, curval++) { \
+ next = BUNtail(bpi, l); \
+ if(atomcmp(v, next)) { \
+ if(rlimit == 0) \
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list
