str BKCisSorted(bit *res, const bat *bid) { BAT *b; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.isSorted", RUNTIME_OBJECT_MISSING); } *res = BATordered(BATmirror(b)); BBPunfix(b->batCacheid); return MAL_SUCCEED; }
str MATproject(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { bat *res_id = (bat*) getArgReference(stk,pci,0); bat map_id = *(bat*) getArgReference(stk,pci,1); BAT *res = NULL, *map; /* rest of the args are parts, (excluding result and map) */ BAT **bats = GDKzalloc(sizeof(BAT*) * pci->argc - 2); BUN bcnt = 0; int i, len = pci->argc-2, sorted = 1; (void) cntxt; (void) mb; (void) stk; if( bats == NULL) throw(SQL, "mat.project",MAL_MALLOC_FAIL); map = BATdescriptor(map_id); if (!map) goto error; for (i=2; i<pci->argc; i++) { bat id = *(bat*) getArgReference(stk,pci,i); bats[i-2] = BATdescriptor(id); if (!bats[i-2]) goto error; bcnt += BATcount(bats[i-2]); if (!bats[i-2]->T->sorted) sorted = 0; } assert(bcnt == BATcount(map)); res = MATproject_(map, bats, len ); if (sorted && res) BATordered(BATmirror(res)); error: if (map) BBPunfix(map->batCacheid); if (bats) { for (i=0; i<len && bats[i]; i++) BBPunfix(bats[i]->batCacheid); GDKfree(bats); } if (res) { BATsettrivprop(res); BBPkeepref( *res_id = res->batCacheid); return MAL_SUCCEED; } throw(SQL, "mat.project","Cannot access descriptor"); }