Changeset: b911afb34d41 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b911afb34d41
Modified Files:
        sql/backends/monet5/sql_statement.c
Branch: default
Log Message:

Helping on bug #7285 Don't push unecessary arguments for R/Python/C udf 
aggregates


diffs (89 lines):

diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -3355,6 +3355,8 @@ stmt_binop(backend *be, stmt *op1, stmt 
        return r;
 }
 
+#define LANG_INT_OR_MAL(l)  ((l)==FUNC_LANG_INT || (l)==FUNC_LANG_MAL)
+
 stmt *
 stmt_Nop(backend *be, stmt *ops, stmt *sel, sql_subfunc *f, stmt* rows)
 {
@@ -3483,7 +3485,7 @@ stmt_Nop(backend *be, stmt *ops, stmt *s
                        }
                }
                /* special case for round function on decimals */
-               if (strcmp(fimp, "round") == 0 && tpe && tpe->type->eclass == 
EC_DEC && ops->op4.lval->h && ops->op4.lval->h->data) {
+               if (LANG_INT_OR_MAL(f->func->lang) && strcmp(fimp, "round") == 
0 && tpe && tpe->type->eclass == EC_DEC && ops->op4.lval->h && 
ops->op4.lval->h->data) {
                        q = pushInt(mb, q, tpe->digits);
                        q = pushInt(mb, q, tpe->scale);
                }
@@ -3619,8 +3621,7 @@ stmt_aggr(backend *be, stmt *op1, stmt *
        const char *mod, *aggrfunc;
        sql_subtype *res = op->res->h->data;
        int restype = res->type->localtype;
-       bool complex_aggr = false;
-       bool abort_on_error;
+       bool complex_aggr = false, abort_on_error = false;
        int *stmt_nr = NULL;
        int avg = 0;
 
@@ -3631,16 +3632,18 @@ stmt_aggr(backend *be, stmt *op1, stmt *
        mod = sql_func_mod(op->func);
        aggrfunc = backend_function_imp(be, op->func);
 
-       if (strcmp(aggrfunc, "avg") == 0)
-               avg = 1;
-       if (avg || strcmp(aggrfunc, "sum") == 0 || strcmp(aggrfunc, "prod") == 0
-               || strcmp(aggrfunc, "str_group_concat") == 0)
-               complex_aggr = true;
-       if (restype == TYPE_dbl)
-               avg = 0;
-       /* some "sub" aggregates have an extra argument "abort_on_error" */
-       abort_on_error = complex_aggr || strncmp(aggrfunc, "stdev", 5) == 0 || 
strncmp(aggrfunc, "variance", 8) == 0 ||
-                                       strncmp(aggrfunc, "covariance", 10) == 
0 || strncmp(aggrfunc, "corr", 4) == 0;
+       if (LANG_INT_OR_MAL(op->func->lang)) {
+               if (strcmp(aggrfunc, "avg") == 0)
+                       avg = 1;
+               if (avg || strcmp(aggrfunc, "sum") == 0 || strcmp(aggrfunc, 
"prod") == 0
+                       || strcmp(aggrfunc, "str_group_concat") == 0)
+                       complex_aggr = true;
+               if (restype == TYPE_dbl)
+                       avg = 0;
+               /* some "sub" aggregates have an extra argument 
"abort_on_error" */
+               abort_on_error = complex_aggr || strncmp(aggrfunc, "stdev", 5) 
== 0 || strncmp(aggrfunc, "variance", 8) == 0 ||
+                                               strncmp(aggrfunc, "covariance", 
10) == 0 || strncmp(aggrfunc, "corr", 4) == 0;
+       }
 
        int argc = 1
                + 2 * avg
@@ -3715,18 +3718,18 @@ stmt_aggr(backend *be, stmt *op1, stmt *
        if (grp) {
                q = pushArgument(mb, q, grp->nr);
                q = pushArgument(mb, q, ext->nr);
-               if (avg) /* push nil candidates */
-                       q = pushNil(mb, q, TYPE_bat);
-               if (q == NULL)
-                       return NULL;
+               if (LANG_INT_OR_MAL(op->func->lang)) {
+                       if (avg) /* push nil candidates */
+                               q = pushNil(mb, q, TYPE_bat);
+                       q = pushBit(mb, q, no_nil);
+                       if (!avg && abort_on_error)
+                               q = pushBit(mb, q, TRUE);
+               }
+       } else if (LANG_INT_OR_MAL(op->func->lang) && no_nil && 
strncmp(aggrfunc, "count", 5) == 0) {
                q = pushBit(mb, q, no_nil);
-               if (!avg && abort_on_error)
-                       q = pushBit(mb, q, TRUE);
-       } else if (no_nil && strncmp(aggrfunc, "count", 5) == 0) {
-               q = pushBit(mb, q, no_nil);
-       } else if (!nil_if_empty && strncmp(aggrfunc, "sum", 3) == 0) {
+       } else if (LANG_INT_OR_MAL(op->func->lang) && !nil_if_empty && 
strncmp(aggrfunc, "sum", 3) == 0) {
                q = pushBit(mb, q, FALSE);
-       } else if (avg) { /* push candidates */
+       } else if (LANG_INT_OR_MAL(op->func->lang) && avg) { /* push candidates 
*/
                q = pushNil(mb, q, TYPE_bat);
                q = pushBit(mb, q, no_nil);
        }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to