Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/38query.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,19 @@ function queryfn3(query) {
if (query.aggrKeys.length > 0) {
var gfns = '';
query.aggrKeys.forEach(function (col) {
// For multi-column aggregates, pass undefined for each column parameter
var undefinedArgs = '';
if (col.args && col.args.length > 1) {
// Multi-column: pass undefined for each argument, then accumulator, then stage
undefinedArgs = Array(col.args.length).fill('undefined').join(',') + ',';
} else {
// Single column: pass undefined, accumulator, stage
undefinedArgs = 'undefined,';
}
gfns += `
g[${JSON.stringify(col.nick)}] = alasql.aggr[${JSON.stringify(
col.funcid
)}](undefined,g[${JSON.stringify(col.nick)}],3); `;
)}](${undefinedArgs}g[${JSON.stringify(col.nick)}],3); `;
});
var gfn = new Function('g,params,alasql', 'var y;' + gfns);
}
Expand Down
27 changes: 22 additions & 5 deletions src/423groupby.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ yy.Select.prototype.compileGroup = function (query) {
} else if (col.aggregatorid === 'REDUCE') {
query.aggrKeys.push(col);
const extraParams = getGroupConcatParams(col);
return `'${colas}':alasql.aggr['${col.funcid}'](${colexp},undefined,1${extraParams}),`;
// Support multiple arguments for user-defined aggregates
if (col.args && col.args.length > 1) {
// Multiple arguments - pass all of them
let argExpressions = col.args.map(arg => arg.toJS('p', tableid, defcols)).join(',');
return `'${colas}':alasql.aggr['${col.funcid}'](${argExpressions},undefined,1${extraParams}),`;
} else {
// Single argument - backward compatibility
return `'${colas}':alasql.aggr['${col.funcid}'](${colexp},undefined,1${extraParams}),`;
}
}
return '';
}
Expand Down Expand Up @@ -435,11 +443,20 @@ yy.Select.prototype.compileGroup = function (query) {
${post}`;
} else if (col.aggregatorid === 'REDUCE') {
const extraParams = getGroupConcatParams(col);
return `${pre}
g['${colas}'] = alasql.aggr.${col.funcid}(${colexp},g['${colas}'],2${extraParams});
${post}`;
// Support multiple arguments for user-defined aggregates
if (col.args && col.args.length > 1) {
// Multiple arguments - pass all of them
let argExpressions = col.args.map(arg => arg.toJS('p', tableid, defcols)).join(',');
return `${pre}
g['${colas}'] = alasql.aggr.${col.funcid}(${argExpressions},g['${colas}'],2${extraParams});
${post}`;
} else {
// Single argument - backward compatibility
return `${pre}
g['${colas}'] = alasql.aggr.${col.funcid}(${colexp},g['${colas}'],2${extraParams});
${post}`;
}
}

return '';
}

Expand Down
3 changes: 2 additions & 1 deletion src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,7 @@ Aggregator
| AGGR { $$ = "AGGR"; }
| ARRAY { $$ = "ARRAY"; }
| GROUP_CONCAT { $$ = "GROUP_CONCAT"; }
| CORR { $$ = "CORR"; }
/* | REDUCE { $$ = "REDUCE"; } */
;

Expand All @@ -1474,7 +1475,7 @@ FuncValue
$$ = new yy.FuncValue({funcid: funcid, args: exprlist, over: $6});
} else if(alasql.aggr[$1]) {
$$ = new yy.AggrValue({aggregatorid: 'REDUCE',
funcid: funcid, expression: exprlist.pop(),distinct:($3=='DISTINCT'), over: $6 });
funcid: funcid, expression: exprlist[0], args: exprlist, distinct:($3=='DISTINCT'), over: $6 });
} else {
$$ = new yy.FuncValue({funcid: funcid, args: exprlist, over: $6});
};
Expand Down
Loading
Loading