Changeset: 7839a8fd547c for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7839a8fd547c Modified Files: MonetDB5/src/mal/Tests/tst866.mal MonetDB5/src/mal/Tests/tst866.stable.out MonetDB5/src/mal/Tests/tst867.mal MonetDB5/src/mal/Tests/tst867.stable.out MonetDB5/src/modules/kernel/bat5.mx MonetDB5/src/modules/mal/Tests/inspect05.stable.out Branch: default Log Message:
Create the vacuum maps The schrinkMap and reuseMap can be used to propagate the reshuffles into the join indices. diffs (294 lines): diff -r f3a79dc97500 -r 7839a8fd547c MonetDB5/src/mal/Tests/tst866.mal --- a/MonetDB5/src/mal/Tests/tst866.mal Thu May 20 21:19:05 2010 +0200 +++ b/MonetDB5/src/mal/Tests/tst866.mal Fri May 21 08:43:31 2010 +0200 @@ -18,3 +18,6 @@ s:= bat.reuse(b,d); io.print(s); + +so:= bat.reuseMap(b,d); +io.print(so); diff -r f3a79dc97500 -r 7839a8fd547c MonetDB5/src/mal/Tests/tst866.stable.out --- a/MonetDB5/src/mal/Tests/tst866.stable.out Thu May 20 21:19:05 2010 +0200 +++ b/MonetDB5/src/mal/Tests/tst866.stable.out Fri May 21 08:43:31 2010 +0200 @@ -35,6 +35,8 @@ io.print(d); s := bat.reuse(b,d); io.print(s); + so := bat.reuseMap(b,d); + io.print(so); end main; #-----------------# # h t # name @@ -66,6 +68,16 @@ [ 3...@0, 4 ] [ 4...@0, 5 ] [ 5...@0, 6 ] +#-----------------# +# h t # name +# void oid # type +#-----------------# +[ 0...@0, 0...@0 ] +[ 1...@0, 8...@0 ] +[ 2...@0, 7...@0 ] +[ 3...@0, 3...@0 ] +[ 4...@0, 4...@0 ] +[ 5...@0, 5...@0 ] # 16:27:48 > # 16:27:48 > Done. diff -r f3a79dc97500 -r 7839a8fd547c MonetDB5/src/mal/Tests/tst867.mal --- a/MonetDB5/src/mal/Tests/tst867.mal Thu May 20 21:19:05 2010 +0200 +++ b/MonetDB5/src/mal/Tests/tst867.mal Fri May 21 08:43:31 2010 +0200 @@ -17,3 +17,6 @@ s:= bat.shrink(b,d); io.print(s); + +so:= bat.shrinkMap(b,d); +io.print(so); diff -r f3a79dc97500 -r 7839a8fd547c MonetDB5/src/mal/Tests/tst867.stable.out --- a/MonetDB5/src/mal/Tests/tst867.stable.out Thu May 20 21:19:05 2010 +0200 +++ b/MonetDB5/src/mal/Tests/tst867.stable.out Fri May 21 08:43:31 2010 +0200 @@ -34,6 +34,8 @@ bat.append(d,7...@0); s := bat.shrink(b,d); io.print(s); + so := bat.shrinkMap(b,d); + io.print(so); end main; #-----------------# # h t # name @@ -58,6 +60,16 @@ [ 3...@0, 6 ] [ 4...@0, 7 ] [ 5...@0, 9 ] +#-----------------# +# h t # name +# void oid # type +#-----------------# +[ 0...@0, 0...@0 ] +[ 1...@0, 3...@0 ] +[ 2...@0, 4...@0 ] +[ 3...@0, 5...@0 ] +[ 4...@0, 6...@0 ] +[ 5...@0, 8...@0 ] # 17:00:21 > # 17:00:21 > Done. diff -r f3a79dc97500 -r 7839a8fd547c MonetDB5/src/modules/kernel/bat5.mx --- a/MonetDB5/src/modules/kernel/bat5.mx Thu May 20 21:19:05 2010 +0200 +++ b/MonetDB5/src/modules/kernel/bat5.mx Fri May 21 08:43:31 2010 +0200 @@ -580,10 +580,18 @@ address BKCshrinkBAT comment "shrinkt the BAT based on a list of entries identified as to-be-deleted"; +command shrinkMap(b:bat[:oid,:any_1],del:bat[:oid,:oid]):bat[:oid,:oid] +address BKCshrinkBATmap +comment "Derive the oid mapping for shrink BAT based on list of to-be-deleted"; + command reuse(b:bat[:oid,:any_1],del:bat[:oid,:oid]):bat[:oid,:any_1] address BKCreuseBAT comment "shuffle the values around to restore a dense representation of buns."; +command reuseMap(b:bat[:oid,:any_1],del:bat[:oid,:oid]):bat[:oid,:oid] +address BKCreuseBATmap +comment "Derive the oid mapping for reuse BAT based on list of to-be-deleted"; + @+ Implementation Code In Version 5, we are not going to support recursive BATs. It is up to the programmer to translate a bat into a @@ -696,6 +704,8 @@ bat5_export str BKCgetSequenceBase(oid *r, int *bid); bat5_export str BKCshrinkBAT(int *ret, int *bid, int *did); bat5_export str BKCreuseBAT(int *ret, int *bid, int *did); +bat5_export str BKCshrinkBATmap(int *ret, int *bid, int *did); +bat5_export str BKCreuseBATmap(int *ret, int *bid, int *did); bat5_export BUN void_replace_bat5(BAT *b, BAT *u, bit force); bat5_export int void_inplace5(BAT *b, oid id, ptr val, bit force); @@ -3890,8 +3900,8 @@ throw(MAL, "bat.shrink", MAL_MALLOC_FAIL ); } - o = (oid*)Tloc(d, BUNfirst(d)); - ol= (oid*)Tloc(d, BUNlast(d)); + o = (oid*)Tloc(bs, BUNfirst(bs)); + ol= (oid*)Tloc(bs, BUNlast(bs)); BATaccessBegin(d, USE_TAIL, MMAP_SEQUENTIAL); BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); @@ -3921,6 +3931,73 @@ bn->tsorted = 0; bn->tdense = 0; bn->tkey = b->tkey; + bn->T->nonil = b->T->nonil; + bn->T->nil = b->T->nil; + + if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); + + BBPreleaseref(b->batCacheid); + BBPreleaseref(d->batCacheid); + BBPkeepref(*ret= bn->batCacheid); + return MAL_SUCCEED; +} + +str +BKCshrinkBATmap(int *ret, int *bid, int *did) +{ + BAT *b, *d, *bn, *bs; + oid lim,oidx = 0, *o, *ol; + oid *r; + + if ((b = BATdescriptor(*bid)) == NULL) { + throw(MAL, "bat.shrinkMap", RUNTIME_OBJECT_MISSING); + } + if ( b->htype != TYPE_void) { + BBPreleaseref(b->batCacheid); + throw(MAL, "bat.shrinkMap", SEMANTIC_TYPE_MISMATCH); + } + if ((d = BATdescriptor(*did)) == NULL) { + BBPreleaseref(b->batCacheid); + throw(MAL, "bat.shrinkMap", RUNTIME_OBJECT_MISSING); + } + if ( d->htype != TYPE_void) { + BBPreleaseref(d->batCacheid); + throw(MAL, "bat.shrinkMap", SEMANTIC_TYPE_MISMATCH); + } + + bn= BATnew(TYPE_void, TYPE_oid, BATcount(b) ); + BATseqbase(bn, 0); + if (bn == NULL) { + BBPreleaseref(b->batCacheid); + BBPreleaseref(d->batCacheid); + throw(MAL, "bat.shrinkMap", MAL_MALLOC_FAIL ); + } + bs = BATmirror(BATsort(BATmirror(d))); + if (bs == NULL) { + BBPreleaseref(b->batCacheid); + BBPreleaseref(d->batCacheid); + BBPreleaseref(bn->batCacheid); + throw(MAL, "bat.shrinkMap", MAL_MALLOC_FAIL ); + } + + o = (oid*)Tloc(bs, BUNfirst(bs)); + ol= (oid*)Tloc(bs, BUNlast(bs)); + r = (oid*)Tloc(bn, BUNfirst(bn)); + lim = BATcount(b); + + BATaccessBegin(d, USE_TAIL, MMAP_SEQUENTIAL); + for (;oidx<lim; oidx++) { + if ( *o == oidx ){ + o += (o < ol); + } else { + *r++ = oidx; + } + } + BATaccessEnd(d, USE_TAIL, MMAP_SEQUENTIAL); + + BATsetcount(bn, BATcount(b)-BATcount(d)); + bn->tsorted = 0; + bn->tdense = 0; if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); @@ -3984,8 +4061,8 @@ } bidx= BUNlast(b)-1; - o = (oid*)Tloc(d, BUNfirst(d)); - ol= (oid*)Tloc(d, BUNlast(d))-1; + o = (oid*)Tloc(bs, BUNfirst(bs)); + ol= (oid*)Tloc(bs, BUNlast(bs))-1; BATaccessBegin(d, USE_TAIL, MMAP_SEQUENTIAL); BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL); @@ -4024,5 +4101,69 @@ BBPkeepref(*ret= bn->batCacheid); return MAL_SUCCEED; } +str +BKCreuseBATmap(int *ret, int *bid, int *did) +{ + BAT *b, *d, *bn, *bs; + oid bidx, oidx = 0, *o, *ol; + oid *r; + + if ((b = BATdescriptor(*bid)) == NULL) { + throw(MAL, "bat.shrinkMap", RUNTIME_OBJECT_MISSING); + } + if ( b->htype != TYPE_void) { + BBPreleaseref(b->batCacheid); + throw(MAL, "bat.shrinkMap", SEMANTIC_TYPE_MISMATCH); + } + if ((d = BATdescriptor(*did)) == NULL) { + BBPreleaseref(b->batCacheid); + throw(MAL, "bat.shrinkMap", RUNTIME_OBJECT_MISSING); + } + bn= BATnew(TYPE_void, TYPE_oid, BATcount(b) ); + BATseqbase(bn, 0); + if (bn == NULL) { + BBPreleaseref(b->batCacheid); + BBPreleaseref(d->batCacheid); + throw(MAL, "bat.shrinkMap", MAL_MALLOC_FAIL ); + } + bs = BATmirror(BATsort(BATmirror(d))); + if (bs == NULL) { + BBPreleaseref(b->batCacheid); + BBPreleaseref(d->batCacheid); + BBPreleaseref(bn->batCacheid); + throw(MAL, "bat.shrinkMap", MAL_MALLOC_FAIL ); + } + + bidx= BUNlast(b)-1; + o = (oid*)Tloc(d, BUNfirst(d)); + ol= (oid*)Tloc(d, BUNlast(d)); + r = (oid*)Tloc(bn, BUNfirst(bn)); + + BATaccessBegin(d, USE_TAIL, MMAP_SEQUENTIAL); + for (;oidx<bidx; oidx++) { + if ( *o == oidx ){ + while ( *ol == bidx && ol>o) { + bidx--; + ol--; + } + *r++ = bidx; + o += (o < ol); + bidx--; + } else + *r++ = oidx; + } + BATaccessEnd(d, USE_TAIL, MMAP_SEQUENTIAL); + + BATsetcount(bn, BATcount(b)-BATcount(d)); + bn->tsorted = 0; + bn->tdense = 0; + + if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); + + BBPreleaseref(b->batCacheid); + BBPreleaseref(d->batCacheid); + BBPkeepref(*ret= bn->batCacheid); + return MAL_SUCCEED; +} @} diff -r f3a79dc97500 -r 7839a8fd547c MonetDB5/src/modules/mal/Tests/inspect05.stable.out --- a/MonetDB5/src/modules/mal/Tests/inspect05.stable.out Thu May 20 21:19:05 2010 +0200 +++ b/MonetDB5/src/modules/mal/Tests/inspect05.stable.out Fri May 21 08:43:31 2010 +0200 @@ -6156,6 +6156,7 @@ [ "partition", "pattern", "bat", "(b:bat[:any_1,:any_2],pieces:int,part:int):bat[:any_1,:any_2] ", "CMDbatpartition2;" ] [ "partition", "pattern", "bat", "(b:bat[:any_1,:any_2]):bat[:any_1,:any_2]... ", "CMDbatpartition;" ] [ "reduce", "command", "bat", "(b:bat[:any_1,:any_2]):bat[:any_1,:any_2] ", "CMDBATreduce;" ] +[ "reuseMap", "command", "bat", "(b:bat[:oid,:any_1],del:bat[:oid,:oid]):bat[:oid,:oid] ", "BKCreuseBATmap;" ] [ "reuse", "command", "bat", "(b:bat[:oid,:any_1],del:bat[:oid,:oid]):bat[:oid,:any_1] ", "BKCreuseBAT;" ] [ "replace", "command", "bat", "(b:bat[:any_1,:any_2],h:any_1,t:any_2,force:bit):bat[:any_1,:any_2] ", "BKCreplace_bun_force;" ] [ "replace", "command", "bat", "(b:bat[:any_1,:any_2],h:any_1,t:any_2):bat[:any_1,:any_2] ", "BKCreplace_bun;" ] @@ -6165,6 +6166,7 @@ [ "reverse", "command", "bat", "(b:bat[:any_1,:any_2]):bat[:any_2,:any_1] ", "BKCreverse;" ] [ "setBase", "pattern", "bat", "(b:bat[:any_1,:any_2],c:bat[:any_1,:any_2]...):void ", "CMDsetBase;" ] [ "setGarbage", "pattern", "bat", "(b:bat[:any_1,:any_2]):void ", "CMDBATsetGarbage;" ] +[ "shrinkMap", "command", "bat", "(b:bat[:oid,:any_1],del:bat[:oid,:oid]):bat[:oid,:oid] ", "BKCshrinkBATmap;" ] [ "shrink", "command", "bat", "(b:bat[:oid,:any_1],del:bat[:oid,:oid]):bat[:oid,:any_1] ", "BKCshrinkBAT;" ] [ "setHash", "command", "bat", "(b:bat[:any_1,:any_2],prop:bit):bit ", "BKCsetHash;" ] [ "setMemoryAdvise", "command", "bat", "(b:bat[:any_1,:any_2],mode:int):bit ", "BKCmadvise2;" ] _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list