Changeset: e4634c4d8fd1 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e4634c4d8fd1 Modified Files: clients/Tests/exports.stable.out monetdb5/modules/atoms/blob.c monetdb5/modules/atoms/blob.mal monetdb5/modules/atoms/mtime.c sql/test/miscellaneous/Tests/simple_selects.sql sql/test/miscellaneous/Tests/simple_selects.stable.out Branch: unlock Log Message:
merged with default diffs (193 lines): diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -949,6 +949,7 @@ BUN BLOBhash(const blob *b); void BLOBheap(Heap *heap, size_t capacity); size_t BLOBlength(const blob *p); str BLOBnitems(int *ret, blob **b); +str BLOBnitems_bulk(bat *ret, const bat *bid); const blob *BLOBnull(void); str BLOBprelude(void *ret); var_t BLOBput(Heap *h, var_t *bun, const blob *val); diff --git a/monetdb5/modules/atoms/blob.c b/monetdb5/modules/atoms/blob.c --- a/monetdb5/modules/atoms/blob.c +++ b/monetdb5/modules/atoms/blob.c @@ -45,6 +45,7 @@ mal_export size_t BLOBlength(const blob mal_export void BLOBheap(Heap *heap, size_t capacity); mal_export str BLOBtoblob(blob **retval, str *s); mal_export str BLOBnitems(int *ret, blob **b); +mal_export str BLOBnitems_bulk(bat *ret, const bat *bid); mal_export int BLOBget(Heap *h, int *bun, int *l, blob **val); mal_export blob * BLOBread(blob *a, stream *s, size_t cnt); mal_export gdk_return BLOBwrite(const blob *a, stream *s, size_t cnt); @@ -180,16 +181,59 @@ BLOBput(Heap *h, var_t *bun, const blob return *bun; } +static inline int +blob_nitems(blob *b) +{ + if (is_blob_nil(b)) + return int_nil; + assert(b->nitems <INT_MAX); + return (int) b->nitems; +} + str BLOBnitems(int *ret, blob **b) { - if (is_blob_nil(*b)) { - *ret = int_nil; - return MAL_SUCCEED; + *ret = blob_nitems(*b); + return MAL_SUCCEED; +} + +str +BLOBnitems_bulk(bat *ret, const bat *bid) +{ + BAT *b = NULL, *bn = NULL; + BUN n, p, q; + int *dst, i = 0; + str msg = MAL_SUCCEED; + BATiter bi; + + if ((b = BATdescriptor(*bid)) == NULL) { + throw(MAL, "blob.nitems_bulk", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); + goto bailout; } - assert((*b)->nitems <INT_MAX); - *ret = (int) (*b)->nitems; - return MAL_SUCCEED; + n = BATcount(b); + if ((bn = COLnew(b->hseqbase, TYPE_int, n, TRANSIENT)) == NULL) { + msg = createException(MAL, "blob.nitems_bulk", SQLSTATE(HY013) MAL_MALLOC_FAIL); + goto bailout; + } + dst = Tloc(bn, 0); + bi = bat_iterator(b); + BATloop(b, p, q) { + blob *next = BUNtvar(bi, p); + dst[i++] = blob_nitems(next); + } + bn->tnonil = b->tnonil; + bn->tnil = b->tnil; + BATsetcount(bn, n); + bn->tsorted = bn->trevsorted = n < 2; + bn->tkey = false; +bailout: + if (b) + BBPunfix(b->batCacheid); + if (msg && bn) + BBPreclaim(bn); + else if (bn) + BBPkeepref(*ret = bn->batCacheid); + return msg; } str diff --git a/monetdb5/modules/atoms/blob.mal b/monetdb5/modules/atoms/blob.mal --- a/monetdb5/modules/atoms/blob.mal +++ b/monetdb5/modules/atoms/blob.mal @@ -4,6 +4,7 @@ # # Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V. +module batblob; module blob; atom blob; @@ -38,6 +39,8 @@ comment "store a string as a blob."; command nitems(b:blob):int address BLOBnitems comment "get the number of bytes in this blob."; +command batblob.nitems(b:bat[:blob]):bat[:int] +address BLOBnitems_bulk; command prelude() :void address BLOBprelude; diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c --- a/monetdb5/modules/atoms/mtime.c +++ b/monetdb5/modules/atoms/mtime.c @@ -95,7 +95,6 @@ NAMEBULK(bat *ret, const bat *bid) } \ n = BATcount(b); \ if ((bn = COLnew(b->hseqbase, TYPE_##OUTYPE, n, TRANSIENT)) == NULL) { \ - BBPunfix(b->batCacheid); \ msg = createException(MAL, "batmtime." MALFUNC, \ SQLSTATE(HY013) MAL_MALLOC_FAIL); \ goto bailout; \ @@ -148,25 +147,17 @@ NAMEBULK(bat *ret, const bat *bid1, cons b1 = BATdescriptor(*bid1); \ b2 = BATdescriptor(*bid2); \ if (b1 == NULL || b2 == NULL) { \ - if (b1) \ - BBPunfix(b1->batCacheid); \ - if (b2) \ - BBPunfix(b2->batCacheid); \ msg = createException(MAL, "batmtime." MALFUNC, \ SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); \ goto bailout; \ } \ n = BATcount(b1); \ if (n != BATcount(b2)) { \ - BBPunfix(b1->batCacheid); \ - BBPunfix(b2->batCacheid); \ msg = createException(MAL, "batmtime." MALFUNC, \ "inputs not the same size"); \ goto bailout; \ } \ if ((bn = COLnew(b1->hseqbase, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) { \ - BBPunfix(b1->batCacheid); \ - BBPunfix(b2->batCacheid); \ msg = createException(MAL, "batmtime." MALFUNC, \ SQLSTATE(HY013) MAL_MALLOC_FAIL); \ goto bailout; \ diff --git a/sql/test/miscellaneous/Tests/simple_selects.sql b/sql/test/miscellaneous/Tests/simple_selects.sql --- a/sql/test/miscellaneous/Tests/simple_selects.sql +++ b/sql/test/miscellaneous/Tests/simple_selects.sql @@ -162,3 +162,11 @@ set "current_schema" = null; --error, de select greatest(null, null); select sql_min(null, null); + +start transaction; +create table tab1(col1 blob); +insert into tab1 values('2233'); +select length(col1) from tab1; +insert into tab1 values(null), (null), ('11'), ('2233'); +select length(col1) from tab1; +rollback; diff --git a/sql/test/miscellaneous/Tests/simple_selects.stable.out b/sql/test/miscellaneous/Tests/simple_selects.stable.out --- a/sql/test/miscellaneous/Tests/simple_selects.stable.out +++ b/sql/test/miscellaneous/Tests/simple_selects.stable.out @@ -385,6 +385,29 @@ stdout of test 'simple_selects` in direc % char # type % 0 # length [ NULL ] +#start transaction; +#create table tab1(col1 blob); +#insert into tab1 values('2233'); +[ 1 ] +#select length(col1) from tab1; +% sys.%1 # table_name +% %1 # name +% int # type +% 1 # length +[ 2 ] +#insert into tab1 values(null), (null), ('11'), ('2233'); +[ 4 ] +#select length(col1) from tab1; +% sys.%1 # table_name +% %1 # name +% int # type +% 1 # length +[ 2 ] +[ NULL ] +[ NULL ] +[ 1 ] +[ 2 ] +#rollback; # 17:31:38 > # 17:31:38 > "Done." _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list