Changeset: 138e0cb7cbe7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/138e0cb7cbe7
Modified Files:
gdk/gdk_string.c
Branch: Dec2025
Log Message:
Do some cleanup.
diffs (208 lines):
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -1331,13 +1331,11 @@ GDKanalytical_str_group_concat(BAT *r, B
{
bool has_nils = false;
BATiter pi = bat_iterator(p);
- BATiter oi = bat_iterator(o);
BATiter bi = bat_iterator(b);
BATiter sepi = bat_iterator(sep);
BATiter si = bat_iterator(s);
- BATiter ei = bat_iterator(e);
- oid i = 0, j = 0, k = 0, cnt = bi.count, *restrict start = si.base,
*restrict end = ei.base;
- bit *np = pi.base, *op = oi.base;
+ oid i = 0, k = 0;
+ bit *np = pi.base;
char *single_str = NULL;
size_t separator_length = 0, max_group_length = 0;
allocator *ta = MT_thread_getallocator();
@@ -1346,14 +1344,7 @@ GDKanalytical_str_group_concat(BAT *r, B
assert((sep && !separator && bi.count == sepi.count) || (!sep &&
separator));
if (b->ttype != TYPE_str || r->ttype != TYPE_str || (sep && sep->ttype
!= TYPE_str)) {
GDKerror("only string type is supported\n");
- bat_iterator_end(&pi);
- bat_iterator_end(&oi);
- bat_iterator_end(&bi);
- bat_iterator_end(&sepi);
- bat_iterator_end(&si);
- bat_iterator_end(&ei);
- ma_close(&ta_state);
- return GDK_FAIL;
+ goto bailout;
}
if (sep && sepi.count == 1) { /* Only one element in sep */
separator = BUNtvar(sepi, 0);
@@ -1363,22 +1354,27 @@ GDKanalytical_str_group_concat(BAT *r, B
if (sep == NULL)
separator_length = strlen(separator);
- if (cnt > 0) {
+ if (bi.count > 0) {
switch (frame_type) {
- case FRAME_UNBOUNDED_TILL_CURRENT_ROW:
- for (i = p ? 0 : cnt; i <= cnt; i++) {
- if (i == cnt || np[i]) {
+ case FRAME_UNBOUNDED_TILL_CURRENT_ROW: {
+ BATiter oi = bat_iterator(o);
+ bit *op = oi.base;
+ for (i = p ? 0 : bi.count; i <= bi.count; i++) {
+ if (i == bi.count || np[i]) {
size_t slice_length = 0;
+ /* compute the entire string then slice
it starting from the beginning */
if
(compute_next_single_str(&max_group_length, &single_str,
&has_nils,
ta, separator_length,
separator,
&sepi, &bi,
- k, i) !=
GDK_SUCCEED) /* compute the entire string then slice it starting from the
beginning */
- goto allocation_error;
+ k, i) !=
GDK_SUCCEED) {
+ bat_iterator_end(&oi);
+ goto bailout;
+ }
bool empty = true;
while (k < i) {
const char *nsep;
oid m = k;
- j = k;
+ oid j = k;
do {
k++;
} while (k < i && !op[k]);
@@ -1401,44 +1397,51 @@ GDKanalytical_str_group_concat(BAT *r, B
}
if (empty) {
for (j = m; j < k; j++)
- if
(tfastins_nocheckVAR(r, j, str_nil) != GDK_SUCCEED)
- goto
allocation_error;
+ if
(tfastins_nocheckVAR(r, j, str_nil) != GDK_SUCCEED) {
+
bat_iterator_end(&oi);
+ goto
bailout;
+ }
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, j, single_str) != GDK_SUCCEED)
- goto
allocation_error;
+ if
(tfastins_nocheckVAR(r, j, single_str) != GDK_SUCCEED) {
+
bat_iterator_end(&oi);
+ goto
bailout;
+ }
single_str[slice_length] = save;
}
}
}
}
+ bat_iterator_end(&oi);
break;
+ }
case FRAME_CURRENT_ROW_TILL_UNBOUNDED:
- goto notimplemented;
+ GDKerror("str_group_concat not yet implemented for
current row until unbounded case\n");
+ goto bailout;
case FRAME_ALL:
- for (i = p ? 0 : cnt; i <= cnt; i++) {
- if (i == cnt || np[i]) {
+ for (i = p ? 0 : bi.count; i <= bi.count; i++) {
+ if (i == bi.count || np[i]) {
if
(compute_next_single_str(&max_group_length, &single_str,
&has_nils,
ta, separator_length,
separator,
&sepi, &bi,
k, i) !=
GDK_SUCCEED)
- goto allocation_error;
+ goto bailout;
for (; k < i; k++)
if (tfastins_nocheckVAR(r, k,
single_str) != GDK_SUCCEED)
- goto allocation_error;
+ goto bailout;
}
}
break;
case FRAME_CURRENT_ROW:
- for (i = p ? 0 : cnt; i <= cnt; i++) {
- if (i == cnt || np[i]) {
+ for (i = p ? 0 : bi.count; i <= bi.count; i++) {
+ if (i == bi.count || np[i]) {
for (; k < i; k++) {
const char *next = BUNtvar(bi,
k);
if (tfastins_nocheckVAR(r, k,
next) != GDK_SUCCEED)
- goto allocation_error;
+ goto bailout;
has_nils |= strNil(next);
}
}
@@ -1446,55 +1449,50 @@ GDKanalytical_str_group_concat(BAT *r, B
break;
case FRAME_ROWS:
case FRAME_RANGE:
- case FRAME_GROUPS:
- for (i = p ? 0 : cnt; i <= cnt; i++) {
- if (i == cnt || np[i]) {
+ case FRAME_GROUPS: {
+ BATiter ei = bat_iterator(e);
+ const oid *start = si.base, *end = ei.base;
+ for (i = p ? 0 : bi.count; i <= bi.count; i++) {
+ if (i == bi.count || np[i]) {
for (; k < i; k++) {
if
(compute_next_single_str(&max_group_length,
&single_str, &has_nils,
ta,
separator_length,
separator, &sepi, &bi,
-
start[k], end[k]) != GDK_SUCCEED)
- goto allocation_error;
- if (tfastins_nocheckVAR(r, k,
single_str) != GDK_SUCCEED)
- goto allocation_error;
+
start[k], end[k]) != GDK_SUCCEED) {
+ bat_iterator_end(&ei);
+ goto bailout;
+ }
+ if (tfastins_nocheckVAR(r, k,
single_str) != GDK_SUCCEED) {
+ bat_iterator_end(&ei);
+ goto bailout;
+ }
}
}
}
+ bat_iterator_end(&ei);
break;
+ }
default:
MT_UNREACHABLE();
}
}
+ BATsetcount(r, bi.count);
bat_iterator_end(&pi);
- bat_iterator_end(&oi);
bat_iterator_end(&bi);
bat_iterator_end(&sepi);
bat_iterator_end(&si);
- bat_iterator_end(&ei);
- BATsetcount(r, cnt);
r->tnonil = !has_nils;
r->tnil = has_nils;
ma_close(&ta_state);
return GDK_SUCCEED;
- allocation_error:
+
+ bailout:
bat_iterator_end(&pi);
- bat_iterator_end(&oi);
bat_iterator_end(&bi);
bat_iterator_end(&sepi);
bat_iterator_end(&si);
- bat_iterator_end(&ei);
- ma_close(&ta_state);
- return GDK_FAIL;
- notimplemented:
- bat_iterator_end(&pi);
- bat_iterator_end(&oi);
- bat_iterator_end(&bi);
- bat_iterator_end(&sepi);
- bat_iterator_end(&si);
- bat_iterator_end(&ei);
- GDKerror("str_group_concat not yet implemented for current row until
unbounded case\n");
ma_close(&ta_state);
return GDK_FAIL;
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]