Changeset: 0430cf8508fa for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0430cf8508fa Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/MAL-signatures.stable.out.int128 monetdb5/modules/kernel/mmath.c sql/backends/monet5/rel_bin.c Branch: default Log Message:
Merged with Oct2020 diffs (217 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -6064,6 +6064,8 @@ stdout of test 'MAL-signatures` in direc [ "batmmath", "radians", "pattern batmmath.radians(X_1:bat[:dbl], X_2:bat[:oid]):bat[:dbl] ", "CMDscience_bat_radians;", "" ] [ "batmmath", "radians", "pattern batmmath.radians(X_1:bat[:flt]):bat[:flt] ", "CMDscience_bat_radians;", "" ] [ "batmmath", "radians", "pattern batmmath.radians(X_1:bat[:flt], X_2:bat[:oid]):bat[:flt] ", "CMDscience_bat_radians;", "" ] +[ "batmmath", "rand", "unsafe pattern batmmath.rand(X_1:bat[:int]):bat[:int] ", "CMDscience_bat_randintarg;", "" ] +[ "batmmath", "rand", "unsafe pattern batmmath.rand(X_1:bat[:int], X_2:bat[:oid]):bat[:int] ", "CMDscience_bat_randintarg;", "" ] [ "batmmath", "sin", "pattern batmmath.sin(X_1:bat[:dbl]):bat[:dbl] ", "CMDscience_bat_sin;", "" ] [ "batmmath", "sin", "pattern batmmath.sin(X_1:bat[:dbl], X_2:bat[:oid]):bat[:dbl] ", "CMDscience_bat_sin;", "" ] [ "batmmath", "sin", "pattern batmmath.sin(X_1:bat[:flt]):bat[:flt] ", "CMDscience_bat_sin;", "" ] diff --git a/clients/Tests/MAL-signatures.stable.out.int128 b/clients/Tests/MAL-signatures.stable.out.int128 --- a/clients/Tests/MAL-signatures.stable.out.int128 +++ b/clients/Tests/MAL-signatures.stable.out.int128 @@ -8594,6 +8594,8 @@ stdout of test 'MAL-signatures` in direc [ "batmmath", "radians", "pattern batmmath.radians(X_1:bat[:dbl], X_2:bat[:oid]):bat[:dbl] ", "CMDscience_bat_radians;", "" ] [ "batmmath", "radians", "pattern batmmath.radians(X_1:bat[:flt]):bat[:flt] ", "CMDscience_bat_radians;", "" ] [ "batmmath", "radians", "pattern batmmath.radians(X_1:bat[:flt], X_2:bat[:oid]):bat[:flt] ", "CMDscience_bat_radians;", "" ] +[ "batmmath", "rand", "unsafe pattern batmmath.rand(X_1:bat[:int]):bat[:int] ", "CMDscience_bat_randintarg;", "" ] +[ "batmmath", "rand", "unsafe pattern batmmath.rand(X_1:bat[:int], X_2:bat[:oid]):bat[:int] ", "CMDscience_bat_randintarg;", "" ] [ "batmmath", "sin", "pattern batmmath.sin(X_1:bat[:dbl]):bat[:dbl] ", "CMDscience_bat_sin;", "" ] [ "batmmath", "sin", "pattern batmmath.sin(X_1:bat[:dbl], X_2:bat[:oid]):bat[:dbl] ", "CMDscience_bat_sin;", "" ] [ "batmmath", "sin", "pattern batmmath.sin(X_1:bat[:flt]):bat[:flt] ", "CMDscience_bat_sin;", "" ] diff --git a/monetdb5/modules/kernel/batmmath.c b/monetdb5/modules/kernel/batmmath.c --- a/monetdb5/modules/kernel/batmmath.c +++ b/monetdb5/modules/kernel/batmmath.c @@ -7,11 +7,10 @@ */ #include "monetdb_config.h" -#include "gdk.h" #include <fenv.h> +#include "mmath_private.h" #include "mal_exception.h" #include "mal_interpreter.h" -#include "mmath_private.h" static str CMDscienceUNARY(MalStkPtr stk, InstrPtr pci, @@ -414,6 +413,62 @@ degreesf(float x) return (float) (x * (180.0 / M_PI)); } +static str +CMDscience_bat_randintarg(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + BAT *bn = NULL, *b = NULL, *bs = NULL; + BUN q = 0; + int *restrict vals; + str msg = MAL_SUCCEED; + struct canditer ci = {0}; + bat *res = getArgReference_bat(stk, pci, 0), *bid = getArgReference_bat(stk, pci, 1), + *sid = pci->argc == 3 ? getArgReference_bat(stk, pci, 2) : NULL; + + (void) cntxt; + (void) mb; + if (!(b = BATdescriptor(*bid))) { + msg = createException(MAL, "batmmath.rand", SQLSTATE(HY005) RUNTIME_OBJECT_MISSING); + goto bailout; + } + if (sid && !is_bat_nil(*sid) && !(bs = BATdescriptor(*sid))) { + msg = createException(MAL, "batmmath.rand", SQLSTATE(HY005) RUNTIME_OBJECT_MISSING); + goto bailout; + } + q = canditer_init(&ci, b, bs); + if (!(bn = COLnew(ci.hseq, TYPE_int, q, TRANSIENT))) { + msg = createException(MAL, "batmmath.rand", SQLSTATE(HY013) MAL_MALLOC_FAIL); + goto bailout; + } + + vals = Tloc(bn, 0); +#ifdef STATIC_CODE_ANALYSIS + for (BUN i = 0; i < q; i++) + vals[i] = 0; +#else + MT_lock_set(&mmath_rse_lock); + for (BUN i = 0; i < q; i++) + vals[i] = (int) (next(mmath_rse) >> 33); + MT_lock_unset(&mmath_rse_lock); +#endif + +bailout: + if (b) + BBPunfix(b->batCacheid); + if (bs) + BBPunfix(bs->batCacheid); + if (bn && !msg) { + BATsetcount(bn, q); + bn->tnil = false; + bn->tnonil = true; + bn->tkey = BATcount(bn) <= 1; + bn->tsorted = BATcount(bn) <= 1; + bn->trevsorted = BATcount(bn) <= 1; + BBPkeepref(*res = bn->batCacheid); + } else if (bn) + BBPreclaim(bn); + return msg; +} + scienceImpl(acos) scienceImpl(asin) scienceImpl(atan) @@ -566,6 +621,8 @@ mel_func batmmath_init_funcs[] = { pattern("batmmath", "pow", CMDscience_bat_pow, false, "", args(1,4, batarg("",dbl),arg("x",dbl),batarg("y",dbl),batarg("s",oid))), pattern("batmmath", "pow", CMDscience_bat_pow, false, "", args(1,3, batarg("",flt),arg("x",flt),batarg("y",flt))), pattern("batmmath", "pow", CMDscience_bat_pow, false, "", args(1,4, batarg("",flt),arg("x",flt),batarg("y",flt),batarg("s",oid))), + pattern("batmmath", "rand", CMDscience_bat_randintarg, true, "", args(1,2, batarg("",int),batarg("v",int))), + pattern("batmmath", "rand", CMDscience_bat_randintarg, true, "", args(1,3, batarg("",int),batarg("v",int),batarg("s",oid))), { .imp=NULL } }; #include "mal_import.h" diff --git a/monetdb5/modules/kernel/mmath.c b/monetdb5/modules/kernel/mmath.c --- a/monetdb5/modules/kernel/mmath.c +++ b/monetdb5/modules/kernel/mmath.c @@ -240,12 +240,10 @@ MATHunary_FINITE(bit *res, const dbl *a) return MAL_SUCCEED; } -#include "xoshiro256starstar.h" - /* global pseudo random generator state */ -static random_state_engine mmath_rse; +random_state_engine mmath_rse; /* serialize access to state */ -static MT_Lock mmath_rse_lock = MT_LOCK_INITIALIZER(mmath_rse_lock); +MT_Lock mmath_rse_lock = MT_LOCK_INITIALIZER(mmath_rse_lock); static str MATHprelude(void *ret) diff --git a/monetdb5/modules/kernel/mmath_private.h b/monetdb5/modules/kernel/mmath_private.h --- a/monetdb5/modules/kernel/mmath_private.h +++ b/monetdb5/modules/kernel/mmath_private.h @@ -6,6 +6,16 @@ * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V. */ +#include "gdk.h" +#include "xoshiro256starstar.h" + +/* global pseudo random generator state */ +extern random_state_engine mmath_rse +__attribute__((__visibility__("hidden"))); +/* serialize access to state */ +extern MT_Lock mmath_rse_lock +__attribute__((__visibility__("hidden"))); + /* return the logarigthm of the first argument with the second * argument as base */ extern double logbs(double, double); diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -997,6 +997,10 @@ exp_bin(backend *be, sql_exp *e, stmt *l stmt *rows = NULL, *isel = sel; int nrcands = 0, push_cands = 0; + if (sel && (strcmp(sql_func_mod(f->func), "calc") == 0 || strcmp(sql_func_mod(f->func), "mmath") == 0 || strcmp(sql_func_mod(f->func), "mtime") == 0 + || (strcmp(sql_func_mod(f->func), "str") == 0 && batstr_func_has_candidates(sql_func_imp(f->func))))) + push_cands = 1; + if (f->func->side_effect && left && left->nrcols > 0) { sql_subfunc *f1 = NULL; /* we cannot assume all SQL functions with no arguments have a correspondent with one argument, so attempt to find it. 'rand' function is the exception */ @@ -1005,6 +1009,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l f = f1; list_append(l, stmt_const(be, bin_first_column(be, left), stmt_atom(be, atom_general(sql->sa, f1 ? &(((sql_arg*)f1->func->ops->h->data)->type) : sql_bind_localtype("int"), NULL)))); + nrcands++; /* increment cands */ } else if (exps_card(exps) < CARD_MULTI) { rows = bin_first_column(be, left); } @@ -1012,12 +1017,9 @@ exp_bin(backend *be, sql_exp *e, stmt *l assert(!e->r); if (strcmp(sql_func_mod(f->func), "") == 0 && strcmp(sql_func_imp(f->func), "") == 0 && strcmp(f->func->base.name, "star") == 0) return left->op4.lval->h->data; - else if (exps) { + else if (!list_empty(exps)) { unsigned nrcols = 0; - if (sel && (strcmp(sql_func_mod(f->func), "calc") == 0 || strcmp(sql_func_mod(f->func), "mmath") == 0 || strcmp(sql_func_mod(f->func), "mtime") == 0 - || (strcmp(sql_func_mod(f->func), "str") == 0 && batstr_func_has_candidates(sql_func_imp(f->func))))) - push_cands = 1; if (strcmp(sql_func_mod(f->func), "calc") == 0 && strcmp(sql_func_imp(f->func), "ifthenelse") == 0) return exp2bin_case(be, e, left, right, sel, depth); if (strcmp(sql_func_mod(f->func), "") == 0 && strcmp(sql_func_imp(f->func), "") == 0 && strcmp(f->func->base.name, "coalesce") == 0) @@ -1045,18 +1047,18 @@ exp_bin(backend *be, sql_exp *e, stmt *l if (push_cands && es->nrcols) nrcands++; } - if (push_cands) { - int i; - for (i=0, en = l->h; i<nrcands && en; en = en->next) { - stmt *s = en->data; - /* if handled use bat nil */ - if (s->nrcols) { /* only for cols not values */ - i++; - if (s->cand && s->cand == isel) - list_append(l, NULL); - else - list_append(l,sel); - } + } + if (push_cands) { + int i; + for (i=0, en = l->h; i<nrcands && en; en = en->next) { + stmt *s = en->data; + /* if handled use bat nil */ + if (s->nrcols) { /* only for cols not values */ + i++; + if (s->cand && s->cand == isel) + list_append(l, NULL); + else + list_append(l,sel); } } } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list