Changeset: f3cde2c667cc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f3cde2c667cc
Modified Files:
gdk/gdk_analytic_func.c
gdk/gdk_calc.h
gdk/gdk_string.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_rank.c
sql/backends/monet5/sql_rank.h
Branch: window-tunning
Log Message:
Updated group_concat window function and some other minor fixes. Now every
window function has been updated to support the global cases. Now into the next
optimizations
diffs (truncated from 675 to 300 lines):
diff --git a/gdk/gdk_analytic_func.c b/gdk/gdk_analytic_func.c
--- a/gdk/gdk_analytic_func.c
+++ b/gdk/gdk_analytic_func.c
@@ -193,7 +193,7 @@ GDKanalyticalfirst(BAT *r, BAT *b, BAT *
default:{
for (; k < cnt; k++) {
const void *curval = (end[k] > start[k]) ? BUNtail(bpi,
start[k]) : nil;
- if (tfastins_nocheckVAR(r, k, curval, Tsize(r)) !=
GDK_SUCCEED)
+ if (tfastins_nocheckVAR(r, (BUN) k, curval, Tsize(r))
!= GDK_SUCCEED)
return GDK_FAIL;
has_nils |= atomcmp(curval, nil) == 0;
}
@@ -254,7 +254,7 @@ GDKanalyticallast(BAT *r, BAT *b, BAT *s
default:{
for (; k < cnt; k++) {
const void *curval = (end[k] > start[k]) ? BUNtail(bpi,
(BUN) (end[k] - 1)) : nil;
- if (tfastins_nocheckVAR(r, k, curval, Tsize(r)) !=
GDK_SUCCEED)
+ if (tfastins_nocheckVAR(r, (BUN) k, curval, Tsize(r))
!= GDK_SUCCEED)
return GDK_FAIL;
has_nils |= atomcmp(curval, nil) == 0;
}
@@ -355,7 +355,7 @@ GDKanalyticalnthvalue(BAT *r, BAT *b, BA
curval = BUNtail(bpi, (BUN) (start[k] +
lnth - 1));
has_nils |= atomcmp(curval, nil) == 0;
}
- if (tfastins_nocheckVAR(r, k, curval, Tsize(r))
!= GDK_SUCCEED)
+ if (tfastins_nocheckVAR(r, (BUN) k, curval,
Tsize(r)) != GDK_SUCCEED)
return GDK_FAIL;
}
}
@@ -391,13 +391,13 @@ GDKanalyticalnthvalue(BAT *r, BAT *b, BA
if (is_lng_nil(nth)) {
has_nils = true;
for (; k < cnt; k++)
- if (tfastins_nocheckVAR(r, k, nil,
Tsize(r)) != GDK_SUCCEED)
+ if (tfastins_nocheckVAR(r, (BUN) k,
nil, Tsize(r)) != GDK_SUCCEED)
return GDK_FAIL;
} else {
nth--;
for (; k < cnt; k++) {
const void *curval = (end[k] > start[k]
&& nth < (end[k] - start[k])) ? BUNtail(bpi, (BUN) (start[k] + nth)) : nil;
- if (tfastins_nocheckVAR(r, k, curval,
Tsize(r)) != GDK_SUCCEED)
+ if (tfastins_nocheckVAR(r, (BUN) k,
curval, Tsize(r)) != GDK_SUCCEED)
return GDK_FAIL;
has_nils |= atomcmp(curval, nil) == 0;
}
@@ -796,7 +796,7 @@ GDKanalyticallead(BAT *r, BAT *b, BAT *p
k++; \
} while (k < i && !op[k]); \
for (; j < k; j++) \
- if (tfastins_nocheckVAR(r, j, curval, Tsize(r))
!= GDK_SUCCEED) \
+ if (tfastins_nocheckVAR(r, (BUN) j, curval,
Tsize(r)) != GDK_SUCCEED) \
return GDK_FAIL; \
has_nils |= atomcmp(curval, nil) == 0; \
} \
@@ -816,7 +816,7 @@ GDKanalyticallead(BAT *r, BAT *b, BAT *p
} \
if (op[j] || j == k) { \
for (; l >= j; l--) \
- if (tfastins_nocheckVAR(r, l, curval,
Tsize(r)) != GDK_SUCCEED) \
+ if (tfastins_nocheckVAR(r, (BUN) l,
curval, Tsize(r)) != GDK_SUCCEED) \
return GDK_FAIL; \
has_nils |= atomcmp(curval, nil) == 0;
\
if (j == k) \
@@ -840,7 +840,7 @@ GDKanalyticallead(BAT *r, BAT *b, BAT *p
} \
} \
for (; k < i; k++) \
- if (tfastins_nocheckVAR(r, k, curval, Tsize(r)) !=
GDK_SUCCEED) \
+ if (tfastins_nocheckVAR(r, (BUN) k, curval, Tsize(r))
!= GDK_SUCCEED) \
return GDK_FAIL; \
has_nils |= atomcmp(curval, nil) == 0; \
} while (0)
@@ -849,7 +849,7 @@ GDKanalyticallead(BAT *r, BAT *b, BAT *p
do { \
for (; k < i; k++) { \
void *next = BUNtail(bpi, k); \
- if (tfastins_nocheckVAR(r, k, next, Tsize(r)) !=
GDK_SUCCEED) \
+ if (tfastins_nocheckVAR(r, (BUN) k, next, Tsize(r)) !=
GDK_SUCCEED) \
return GDK_FAIL; \
has_nils |= atomcmp(next, nil) == 0; \
} \
@@ -871,7 +871,7 @@ GDKanalyticallead(BAT *r, BAT *b, BAT *p
curval = atomcmp(next, curval)
GT_LT 0 ? curval : next; \
} \
} \
- if (tfastins_nocheckVAR(r, k, curval, Tsize(r)) !=
GDK_SUCCEED) \
+ if (tfastins_nocheckVAR(r, (BUN) k, curval, Tsize(r))
!= GDK_SUCCEED) \
return GDK_FAIL; \
has_nils |= atomcmp(curval, nil) == 0; \
} \
diff --git a/gdk/gdk_calc.h b/gdk/gdk_calc.h
--- a/gdk/gdk_calc.h
+++ b/gdk/gdk_calc.h
@@ -165,4 +165,4 @@ gdk_export BAT *BATgroupcorrelation(BAT
gdk_export BAT *BATgroupstr_group_concat(BAT *b, BAT *g, BAT *e, BAT *s, BAT
*sep, bool skip_nils, bool abort_on_error, const char *restrict separator);
gdk_export gdk_return BATstr_group_concat(ValPtr res, BAT *b, BAT *s, BAT
*sep, bool skip_nils, bool abort_on_error, bool nil_if_empty, const char
*restrict separator);
-gdk_export gdk_return GDKanalytical_str_group_concat(BAT *r, BAT *b, BAT *sep,
BAT *s, BAT *e, const char *restrict separator);
+gdk_export gdk_return GDKanalytical_str_group_concat(BAT *r, BAT *p, BAT *o,
BAT *b, BAT *sep, BAT *s, BAT *e, const char *restrict separator, int
frame_type);
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -1176,26 +1176,198 @@ BATgroupstr_group_concat(BAT *b, BAT *g,
return bn;
}
+#define compute_next_single_str(START, END) \
+ do { \
+ for (lng m = START; m < END; m++) { \
+ sb = BUNtvar(bi, (BUN) m); \
+ \
+ if (separator) { \
+ if (!strNil(sb)) { \
+ next_group_length += strlen(sb);
\
+ if (!empty) \
+ next_group_length +=
separator_length; \
+ empty = false; \
+ } \
+ } else { /* sep case */ \
+ assert(sep != NULL); \
+ sl = BUNtvar(bis, (BUN) m); \
+ \
+ if (!strNil(sb)) { \
+ next_group_length += strlen(sb);
\
+ if (!empty && !strNil(sl)) \
+ next_group_length +=
strlen(sl); \
+ empty = false; \
+ } \
+ } \
+ } \
+ if (empty) { \
+ if (single_str == NULL) { /* reuse the same buffer,
resize it when needed */ \
+ max_group_length = 1; \
+ if ((single_str = GDKmalloc(max_group_length +
1)) == NULL) \
+ goto allocation_error; \
+ } else if (1 > max_group_length) { \
+ max_group_length = 1; \
+ if ((next_single_str = GDKrealloc(single_str,
max_group_length + 1)) == NULL) \
+ goto allocation_error; \
+ single_str = next_single_str; \
+ } \
+ strcpy(single_str, str_nil); \
+ has_nils = true; \
+ } else { \
+ empty = true; \
+ if (single_str == NULL) { /* reuse the same buffer,
resize it when needed */ \
+ max_group_length = next_group_length; \
+ if ((single_str = GDKmalloc(max_group_length +
1)) == NULL) \
+ goto allocation_error; \
+ } else if (next_group_length > max_group_length) {
\
+ max_group_length = next_group_length; \
+ if ((next_single_str = GDKrealloc(single_str,
max_group_length + 1)) == NULL) \
+ goto allocation_error; \
+ single_str = next_single_str; \
+ } \
+\
+ for (lng m = START; m < END; m++) { \
+ sb = BUNtvar(bi, (BUN) m); \
+\
+ if (separator) { \
+ if (strNil(sb)) \
+ continue; \
+ if (!empty) { \
+ memcpy(single_str + offset,
separator, separator_length); \
+ offset += separator_length;
\
+ } \
+ next_length = strlen(sb); \
+ memcpy(single_str + offset, sb,
next_length); \
+ offset += next_length; \
+ empty = false; \
+ } else { /* sep case */ \
+ assert(sep != NULL); \
+ sl = BUNtvar(bis, (BUN) m); \
+\
+ if (strNil(sb)) \
+ continue; \
+ if (!empty && !strNil(sl)) { \
+ next_length = strlen(sl);
\
+ memcpy(single_str + offset, sl,
next_length); \
+ offset += next_length; \
+ } \
+ next_length = strlen(sb); \
+ memcpy(single_str + offset, sb,
next_length); \
+ offset += next_length; \
+ empty = false; \
+ } \
+ } \
+\
+ single_str[offset] = '\0'; \
+ } \
+} while (0)
+
+#define ANALYTICAL_STR_GROUP_CONCAT_UNBOUNDED_TILL_CURRENT_ROW \
+ do { \
+ size_t slice_length = 0; \
+ next_group_length = next_length = offset = 0; \
+ empty = true; \
+ compute_next_single_str(k, i); /* compute the entire string
then slice it starting from the beginning */ \
+ empty = true; \
+ for (; k < i;) { \
+ str nsep, nstr; \
+ lng m = k; \
+ j = k; \
+ do { \
+ k++; \
+ } while (k < i && !op[k]); \
+ for (; j < k; j++) { \
+ nstr = BUNtvar(bi, (BUN) j); \
+ if (!strNil(nstr)) { \
+ slice_length += strlen(nstr); \
+ if (!empty) { \
+ if (separator) { \
+ nsep = (str) separator;
\
+ } else { /* sep case */ \
+ assert(sep != NULL);
\
+ nsep = BUNtvar(bis,
(BUN) j); \
+ } \
+ if (!strNil(nsep)) \
+ slice_length +=
strlen(nsep); \
+ } \
+ empty = false; \
+ } \
+ } \
+ if (empty) { \
+ for (j = m; j < k; j++) \
+ if (tfastins_nocheckVAR(r, (BUN) j,
str_nil, Tsize(r)) != GDK_SUCCEED) \
+ goto allocation_error; \
+ has_nils = true; \
+ } else { \
+ char save = single_str[slice_length]; \
+ single_str[slice_length] = '\0'; \
+ for (j = m; j < k; j++) \
+ if (tfastins_nocheckVAR(r, (BUN) j,
single_str, Tsize(r)) != GDK_SUCCEED) \
+ goto allocation_error; \
+ single_str[slice_length] = save; \
+ } \
+ } \
+ } while (0)
+
+#define ANALYTICAL_STR_GROUP_CONCAT_ALL_ROWS \
+ do { \
+ next_group_length = next_length = offset = 0; \
+ empty = true; \
+ compute_next_single_str(k, i); \
+ for (; k < i; k++) \
+ if (tfastins_nocheckVAR(r, (BUN) k, single_str,
Tsize(r)) != GDK_SUCCEED) \
+ goto allocation_error; \
+ } while (0)
+
+#define ANALYTICAL_STR_GROUP_CONCAT_CURRENT_ROW \
+ do { \
+ for (; k < i; k++) { \
+ str next = BUNtvar(bi, (BUN) k); \
+ if (tfastins_nocheckVAR(r, (BUN) k, next, Tsize(r)) !=
GDK_SUCCEED) \
+ goto allocation_error; \
+ has_nils |= strNil(next); \
+ } \
+ } while (0)
+
+#define ANALYTICAL_STR_GROUP_CONCAT_OTHERS \
+ do { \
+ for (; k < i; k++) { \
+ next_group_length = next_length = offset = 0; \
+ empty = true; \
+ compute_next_single_str(start[k], end[k]); \
+ if (tfastins_nocheckVAR(r, (BUN) k, single_str,
Tsize(r)) != GDK_SUCCEED) \
+ goto allocation_error; \
+ } \
+ } while (0)
+
+#define ANALYTICAL_STR_GROUP_CONCAT_PARTITIONS(IMP) \
+ do { \
+ if (p) { \
+ for (; i < cnt; i++) { \
+ if (np[i]) \
+ IMP; \
+ } \
+ } \
+ i = cnt; \
+ IMP; \
+ } while (0)
+
gdk_return
-GDKanalytical_str_group_concat(BAT *r, BAT *b, BAT *sep, BAT *s, BAT *e, const
char *restrict separator)
+GDKanalytical_str_group_concat(BAT *r, BAT *p, BAT *o, BAT *b, BAT *sep, BAT
*s, BAT *e, const char *restrict separator, int frame_type)
{
- BUN i = 0, cnt = BATcount(b);
- lng *restrict start, *restrict end, j, l;
+ bool has_nils = false, empty;
+ lng i = 0, j = 0, k = 0, cnt = (lng) BATcount(b);
+ lng *restrict start = s ? (lng*)Tloc(s, 0) : NULL, *restrict end = e ?
(lng*)Tloc(e, 0) : NULL;
+ bit *np = p ? Tloc(p, 0) : NULL, *op = o ? Tloc(o, 0) : NULL;
BATiter bi, bis = (BATiter) {0};
str sb, sl, single_str = NULL, next_single_str;
- bool empty;
size_t separator_length = 0, next_group_length, max_group_length = 0,
next_length, offset;
- bool hasnil = 0;
- assert(s && e && ((sep && !separator && BATcount(b) == BATcount(sep))
|| (!sep && separator)));
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list