Hi Mark, Is it possible to return Table or multiple columns from a C function? Any example or existing function I can check in the code? Also is it possible using a C function to expand table rows instead of joining to a calendar table, what i am trying to do is to expand a row and return an entry for each month bracket between startdate and enddate? Thanks On Tue, Jan 3, 2017 at 4:45 PM, imad hajj chahine < imad.hajj.chahine@gmail.com> wrote:
Thank you Mark,
I should refresh my memory about C programming, I never thought i would code in C again.
On Tue, Jan 3, 2017 at 3:48 PM, Mark Raasveldt
wrote: Hey Imad,
No, it does not apply to integers because you are not doing any heap allocation.
Mark
On 02 Jan 2017, at 19:03, imad hajj chahine
wrote: Mark,
Does the same apply for Integer values, Meaning its better to declare one the int value and used in all the iteration, do I have a performance issue with the following code:
str UDFyearlag(int *ret, const date *v1, const date *v2) { if (*v1 == date_nil || *v2 == date_nil) { *ret = int_nil; } else { int y1 = 0, y2 = 0; fromdate(*v1, NULL, NULL, &y1); fromdate(*v2, NULL, NULL, &y2); *ret = y2 - y1; } return MAL_SUCCEED; }
str UDFBATyearlag(bat *ret, const bat *bid1, const bat *bid2) { BAT *b1, *b2, *bn; BATiter bi1, bi2; BUN i,n;
b1 = BATdescriptor(*bid1); b2 = BATdescriptor(*bid2); if (b1 == NULL || b2 == NULL) { if (b1) BBPunfix(b1->batCacheid); if (b2) BBPunfix(b2->batCacheid); throw(MAL, "UDF.BATyearlag", "Cannot access descriptor"); } n = BATcount(b1);
bn = COLnew(b1->hseqbase, TYPE_int, BATcount(b1), TRANSIENT); if (bn == NULL) { BBPunfix(b1->batCacheid); BBPunfix(b2->batCacheid); throw(MAL, "UDF.BATyearlag", "memory allocation failure"); }
bi1 = bat_iterator(b1); bi2 = bat_iterator(b2); BATloop(b1, i, n) { int y; const date *t1 = (const date *) BUNtail(bi1, i); const date *t2 = (const date *) BUNtail(bi2, i); if (*t1 == date_nil || *t2 == date_nil) { y = int_nil; } else UDFyearlag(&y, t1, t2); if (BUNappend(bn, &y, 0) != GDK_SUCCEED) { goto bailout; } }
BBPkeepref(*ret = bn->batCacheid); BBPunfix(b1->batCacheid); BBPunfix(b2->batCacheid); return MAL_SUCCEED; bailout: BBPunfix(b1->batCacheid); BBPunfix(b2->batCacheid); BBPunfix(bn->batCacheid); throw(MAL, "UDF.BATyearlag", MAL_MALLOC_FAIL); } _______________________________________________ users-list mailing list users-list@monetdb.org https://www.monetdb.org/mailman/listinfo/users-list
_______________________________________________ users-list mailing list users-list@monetdb.org https://www.monetdb.org/mailman/listinfo/users-list