Changeset: a56a6e196725 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a56a6e196725
Modified Files:
sql/backends/monet5/UDF/ssdb.c
Branch: ssdb
Log Message:
Chang position of memory allocation in grouping function.
diffs (125 lines):
diff --git a/sql/backends/monet5/UDF/ssdb.c b/sql/backends/monet5/UDF/ssdb.c
--- a/sql/backends/monet5/UDF/ssdb.c
+++ b/sql/backends/monet5/UDF/ssdb.c
@@ -1350,42 +1350,6 @@ SSDBgrouping(Client cntxt, MalBlkPtr mb,
return sql_message("42S02!GROUPING(): no such table '%s'",
tout_obs_name);
- groupFrom = GDKmalloc(nr_obs * sizeof(obs_group*));
- if (!groupFrom)
- return sql_message("GROUPING(): GDKzalloc 'groupFrom' failed");
- for (l=0;l<nr_obs;l++) {
- groupFrom[l] = GDKmalloc(sizeof(obs_group));
- if (!groupFrom[l]) {
- msg = sql_message("GROUPING(): GDKmalloc
'groupFrom[%d]' failed", l);
- goto CLEANUP_RETURN;
- }
- groupFrom[l]->obsid = GDKzalloc(nr_obs*sizeof(int));
- if (!(groupFrom[l]->obsid)) {
- msg = sql_message("GROUPING(): GDKzalloc
'groupFrom[%d]->obsid' failed", l);
- goto CLEANUP_RETURN;
- }
- groupFrom[l]->fromtime=0;
- groupFrom[l]->totime=0;
- groupFrom[l]->totalx=0;
- groupFrom[l]->totaly=0;
- groupFrom[l]->cnt=0;
- }
-
- groupTo = GDKmalloc(nr_obs*sizeof(int*));
- if (!groupTo)
- return sql_message("GROUPING(): GDKmalloc 'groupTo' failed");
- for (l=0;l<nr_obs;l++) {
- groupTo[l] = GDKzalloc(nr_obs*sizeof(int));
- if (!groupTo[l]) {
- msg = sql_message("GROUPING(): GDKzalloc 'groupTo[%d]'
failed", l);
- goto CLEANUP_RETURN;
- }
- }
-
- current_groupids = GDKzalloc(nr_obs*sizeof(int));
- if (!current_groupids)
- return sql_message("GROUPING(): GDKzalloc 'current_groupids'
failed");
-
/* get the BATs of all columns of the input table 'tin' */
/* RD_INS means we want the insert BATs, since all input tables are
@@ -1432,9 +1396,49 @@ SSDBgrouping(Client cntxt, MalBlkPtr mb,
tin_r_centerx_t = (int*)Tloc(tin_r_centerx, BUNfirst(tin_r_centerx));
tin_r_centery_t = (int*)Tloc(tin_r_centery, BUNfirst(tin_r_centery));
- /*main algorithm*/
+
+ /*assign memory to structures*/
nr_points = BATcount(tin_l_obsid);
nr_obs = tin_l_obsid_t[nr_points-1]+1;
+
+ groupFrom = GDKmalloc(nr_obs * sizeof(obs_group*));
+ if (!groupFrom)
+ return sql_message("GROUPING(): GDKmalloc 'groupFrom' failed");
+ for (l=0;l<nr_obs;l++) {
+ groupFrom[l] = GDKmalloc(sizeof(obs_group));
+ if (!groupFrom[l]) {
+ msg = sql_message("GROUPING(): GDKmalloc
'groupFrom[%d]' failed", l);
+ goto CLEANUP_RETURN;
+ }
+ groupFrom[l]->obsid = GDKzalloc(nr_obs*sizeof(int));
+ if (!(groupFrom[l]->obsid)) {
+ msg = sql_message("GROUPING(): GDKzalloc
'groupFrom[%d]->obsid' failed", l);
+ goto CLEANUP_RETURN;
+ }
+ groupFrom[l]->fromtime=0;
+ groupFrom[l]->totime=0;
+ groupFrom[l]->totalx=0;
+ groupFrom[l]->totaly=0;
+ groupFrom[l]->cnt=0;
+ }
+
+ groupTo = GDKmalloc(nr_obs*sizeof(int*));
+ if (!groupTo)
+ return sql_message("GROUPING(): GDKmalloc 'groupTo' failed");
+ for (l=0;l<nr_obs;l++) {
+ groupTo[l] = GDKzalloc(nr_obs*sizeof(int));
+ if (!groupTo[l]) {
+ msg = sql_message("GROUPING(): GDKzalloc 'groupTo[%d]'
failed", l);
+ goto CLEANUP_RETURN;
+ }
+ }
+
+ current_groupids = GDKzalloc(nr_obs*sizeof(int));
+ if (!current_groupids)
+ return sql_message("GROUPING(): GDKzalloc 'current_groupids'
failed");
+
+ /*main algorithm*/
+
for(idx=0; idx<nr_points; idx++)
{
obsid=tin_r_obsid_t[idx];
@@ -1528,21 +1532,21 @@ SSDBgrouping(Client cntxt, MalBlkPtr mb,
tout_grp_center_traj_y_t[j]=(groupFrom[j]->totaly)/(groupFrom[j]->cnt);
tout_grp_fromtime_t[j]=groupFrom[j]->fromtime;
tout_grp_totime_t[j]=groupFrom[j]->totime;
- found=0;
}
else
break;
+ found=0;
}
/* Set proper properties for output BATs */
- BATsetcount(tout_grp_obsgroupid, j+1);
- BATsetcount(tout_grp_center_traj_x, j+1);
- BATsetcount(tout_grp_center_traj_y, j+1);
- BATsetcount(tout_grp_fromtime, j+1);
- BATsetcount(tout_grp_totime, j+1);
+ BATsetcount(tout_grp_obsgroupid, j);
+ BATsetcount(tout_grp_center_traj_x, j);
+ BATsetcount(tout_grp_center_traj_y, j);
+ BATsetcount(tout_grp_fromtime, j);
+ BATsetcount(tout_grp_totime, j);
BATsetcount(tout_obs_obsgroupid, nr_obs);
BATsetcount(tout_obs_obsid, nr_obs);
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list