str MseedLoadSQL(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { int *ret = (int*) getArgReference(stk,pci,0); str *targetfile = (str*) getArgReference(stk,pci,1); str msg = MAL_SUCCEED; BAT *btime, *bdata, *table; (void) cntxt; (void) mb; /* XXX: BATs of BATs are no longer allowed and this code hasn't worked * for quite some time anyway */ table = BATnew(TYPE_str,TYPE_bat,0); if ( table == NULL) throw(MAL, "mseed.load", MAL_MALLOC_FAIL); msg = MseedLoadIntern(&btime, &bdata, *targetfile); if ( msg == MAL_SUCCEED){ BUNins(table, (ptr)"time", (ptr)&btime->batCacheid, FALSE); BUNins(table, (ptr)"data", (ptr)&bdata->batCacheid, FALSE); BBPreleaseref(btime->batCacheid); BBPreleaseref(bdata->batCacheid); BBPkeepref(*ret= table->batCacheid); } return msg; }
str CMDbbpHeat(bat *ret) { BAT *b; int i; b = BATnew(TYPE_void, TYPE_int, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpHeat", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpHeat"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid) { if (BBP_cache(i) && !monet_modulesilent) { int heat = BBP_lastused(i); BUNins(b, &i, &heat, FALSE); } else if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { int zero = 0; BUNins(b, &i, &zero, FALSE); } } BBPunlock("CMDbbpHeat"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","heat"); return MAL_SUCCEED; }
/* actual implementation */ static char * UDFBATreverse_(BAT **ret, BAT *src) { BATiter li; BAT *bn = NULL; BUN p = 0, q = 0; /* assert calling sanity */ assert(ret != NULL); /* handle NULL pointer */ if (src == NULL) throw(MAL, "batudf.reverse", RUNTIME_OBJECT_MISSING); /* check tail type */ if (src->ttype != TYPE_str) { throw(MAL, "batudf.reverse", "tail-type of input BAT must be TYPE_str"); } /* allocate result BAT */ bn = BATnew(src->htype, TYPE_str, BATcount(src)); if (bn == NULL) { throw(MAL, "batudf.reverse", MAL_MALLOC_FAIL); } BATseqbase(bn, src->hseqbase); /* create BAT iterator */ li = bat_iterator(src); /* the core of the algorithm, expensive due to malloc/frees */ BATloop(src, p, q) { char *tr = NULL, *err = NULL; /* get original head & tail value */ ptr h = BUNhead(li, p); const char *t = (const char *) BUNtail(li, p); /* revert tail value */ err = UDFreverse_(&tr, t); if (err != MAL_SUCCEED) { /* error -> bail out */ BBPreleaseref(bn->batCacheid); return err; } /* assert logical sanity */ assert(tr != NULL); /* insert original head and reversed tail in result BAT */ /* BUNins() takes care of all necessary administration */ BUNins(bn, h, tr, FALSE); /* free memory allocated in UDFreverse_() */ GDKfree(tr); }
BUN copy_inserted(BAT *b, BAT *i ) { BUN nr = 0; BUN r; BATiter ii = bat_iterator(i); for (r = i->batInserted; r < BUNlast(i); r++) { BUNins(b, BUNhead(ii,r), BUNtail(ii,r), TRUE); nr++; } return nr; }
str batnil_2_timestamp(bat *res, const bat *bid) { BAT *b, *dst; BATiter bi; BUN p, q; if ((b = BATdescriptor(*bid)) == NULL) { throw(SQL, "batcalc.nil_2_timestamp", "Cannot access descriptor"); } bi = bat_iterator(b); dst = BATnew(b->htype, TYPE_timestamp, BATcount(b), TRANSIENT); if (dst == NULL) { BBPunfix(b->batCacheid); throw(SQL, "sql.2_timestamp", MAL_MALLOC_FAIL); } BATseqbase(dst, b->hseqbase); BATloop(b, p, q) { timestamp r = *timestamp_nil; BUNins(dst, BUNhead(bi, p), &r, FALSE); }