Changeset: 31cdfdd5920d for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=31cdfdd5920d Modified Files: monetdb5/modules/atoms/blob.c monetdb5/modules/atoms/str.c sql/server/rel_select.c sql/test/miscellaneous/Tests/simple_selects.sql sql/test/miscellaneous/Tests/simple_selects.stable.out Branch: linear-hashing Log Message:
Merge with Nov2019 branch. diffs (196 lines): 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 @@ -52,6 +52,12 @@ mal_export gdk_return BLOBwrite(const bl mal_export str BLOBblob_blob(blob **d, blob **s); mal_export str BLOBblob_fromstr(blob **b, const char **d); +static blob nullval = { + ~(size_t) 0 +}; + +#define is_blob_nil(x) ((x)->nitems == nullval.nitems) + str BLOBprelude(void *ret) { @@ -63,16 +69,12 @@ BLOBprelude(void *ret) var_t blobsize(size_t nitems) { - if (nitems == ~(size_t) 0) + if (nitems == nullval.nitems) nitems = 0; assert(offsetof(blob, data) + nitems <= VAR_MAX); return (var_t) (offsetof(blob, data) + nitems); } -static blob nullval = { - ~(size_t) 0 -}; - static char hexit[] = "0123456789ABCDEF"; /* @@ -85,9 +87,9 @@ int BLOBcmp(const blob *l, const blob *r) { int c; - if (r->nitems == ~(size_t)0) - return l->nitems != ~(size_t)0; - if (l->nitems == ~(size_t)0) + if (is_blob_nil(r)) + return !is_blob_nil(l); + if (is_blob_nil(l)) return -1; if (l->nitems < r->nitems) { c = memcmp(l->data, r->data, l->nitems); @@ -181,6 +183,10 @@ BLOBput(Heap *h, var_t *bun, const blob str BLOBnitems(int *ret, blob **b) { + if (is_blob_nil(*b)) { + *ret = int_nil; + return MAL_SUCCEED; + } assert((*b)->nitems <INT_MAX); *ret = (int) (*b)->nitems; return MAL_SUCCEED; @@ -207,7 +213,7 @@ BLOBtostr(str *tostr, size_t *l, const b size_t i; size_t expectedlen; - if (p->nitems == ~(size_t) 0) + if (is_blob_nil(p)) expectedlen = external ? 4 : 2; else expectedlen = 24 + (p->nitems * 3); @@ -218,7 +224,7 @@ BLOBtostr(str *tostr, size_t *l, const b return -1; *l = expectedlen; } - if (p->nitems == ~(size_t) 0) { + if (is_blob_nil(p)) { if (external) { strcpy(*tostr, "nil"); return 3; @@ -341,7 +347,7 @@ BLOBblob_blob(blob **d, blob **s) if (b == NULL) throw(MAL,"blob", SQLSTATE(HY013) MAL_MALLOC_FAIL); b->nitems = (*s)->nitems; - if (b->nitems != ~(size_t) 0 && b->nitems != 0) + if (!is_blob_nil(b) && b->nitems != 0) memcpy(b->data, (*s)->data, b->nitems); return MAL_SUCCEED; } diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c --- a/monetdb5/modules/atoms/str.c +++ b/monetdb5/modules/atoms/str.c @@ -3343,8 +3343,13 @@ str STRBytes(int *res, const str *arg1) { size_t l; + const char *s = *arg1; - l = strlen(*arg1); + if (strNil(s)) { + *res = int_nil; + return MAL_SUCCEED; + } + l = strlen(s); assert(l < INT_MAX); *res = (int) l; return MAL_SUCCEED; @@ -3566,7 +3571,7 @@ STRsplitpart(str *res, str *haystack, st const char *s = *haystack; const char *s2 = *needle; - if (strNil(s) || is_int_nil(*field)) { + if (strNil(s) || strNil(s2) || is_int_nil(*field)) { *res = GDKstrdup(str_nil); if (*res == NULL) throw(MAL, "str.splitpart", SQLSTATE(HY013) MAL_MALLOC_FAIL); @@ -3774,7 +3779,7 @@ STRStrip2(str *res, const str *arg1, con size_t nchars; int *chars; - if (strNil(s)) { + if (strNil(s) || strNil(*arg2)) { *res = GDKstrdup(str_nil); } else { chars = trimchars(*arg2, &nchars); @@ -3804,7 +3809,7 @@ STRLtrim2(str *res, const str *arg1, con size_t nchars; int *chars; - if (strNil(s)) { + if (strNil(s) || strNil(*arg2)) { *res = GDKstrdup(str_nil); } else { chars = trimchars(*arg2, &nchars); @@ -3831,7 +3836,7 @@ STRRtrim2(str *res, const str *arg1, con size_t nchars; int *chars; - if (strNil(s)) { + if (strNil(s) || strNil(*arg2)) { *res = GDKstrdup(str_nil); } else { chars = trimchars(*arg2, &nchars); @@ -4117,7 +4122,7 @@ STRinsert(str *ret, const str *s, const { str v; int strt = *start; - if (strcmp(*s2, str_nil) == 0 || strcmp(*s, str_nil) == 0) { + if (strNil(*s) || strNil(*s2) || is_int_nil(*start) || is_int_nil(*l)) { if ((*ret = GDKstrdup(str_nil)) == NULL) throw(MAL, "str.insert", SQLSTATE(HY013) MAL_MALLOC_FAIL); } else { @@ -4163,7 +4168,7 @@ STRrepeat(str *ret, const str *s, const int i; size_t l; - if (*c < 0 || strcmp(*s, str_nil) == 0) { + if (*c < 0 || strNil(*s)) { if ((*ret = GDKstrdup(str_nil)) == NULL) throw(MAL, "str.repeat", SQLSTATE(HY013) MAL_MALLOC_FAIL); } else { diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c --- a/sql/server/rel_select.c +++ b/sql/server/rel_select.c @@ -4253,7 +4253,7 @@ rel_order_by(sql_query *query, sql_rel * if (e && e->card <= CARD_ATOM) { sql_subtype *tpe = exp_subtype(e); /* integer atom on the stack */ - if (e->type == e_atom && + if (!is_sql_window(f) && e->type == e_atom && tpe->type->eclass == EC_NUM) { atom *a = e->l?e->l:sql->args[e->flag]; int nr = (int)atom_get_int(a); 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 @@ -21,3 +21,6 @@ select cast(true as interval month); --e select substring('abc' from 1 for null); select substring('abc' from null for 2); select substring('abc' from null for null); + +select length(myblob), octet_length(myblob), length(mystr), octet_length(mystr) +from (values (cast(null as blob), cast(null as char(32)))) as my(myblob, mystr); 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 @@ -161,6 +161,13 @@ stdout of test 'simple_selects` in direc % clob # type % 0 # length [ NULL ] +#select length(myblob), octet_length(myblob), length(mystr), octet_length(mystr) +#from (values (cast(null as blob), cast(null as char(32)))) as my(myblob, mystr); +% .L5, .L6, .L7, .L10 # table_name +% L5, L6, L7, L10 # name +% int, int, int, int # type +% 1, 1, 1, 1 # length +[ NULL, NULL, NULL, NULL ] # 17:31:38 > # 17:31:38 > "Done." _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list