Skip to content

Commit

Permalink
Revert "PR for AlaSQL#1533 AlaSQL#1532 and AlaSQL#1553 issues (AlaSQL…
Browse files Browse the repository at this point in the history
…#1555)"

This reverts commit 1ce099f
  • Loading branch information
alsundukov committed Jan 5, 2023
1 parent 94673d7 commit 241368a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 277 deletions.
96 changes: 6 additions & 90 deletions src/423groupby.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,37 +148,16 @@ if(false) {
",g['$$_VALUES_" + colas + "']={},g['$$_VALUES_" + colas + "'][" + colexp + ']=true';
}
if (col.aggregatorid === 'SUM') {
if ('funcid' in col.expression) {
let colexpression = col.expression.args[0];
let colexp1 = colexpression.toJS('p', tableid, defcols);
return `'${colas}':(${colexp1})|| typeof ${colexp1} == 'number' ? ${colexp1} : null,`;
}
return `'${colas}':(${colexp})|| typeof ${colexp} == 'number' ? ${colexp} : null,`;
return "'" + colas + "':(" + colexp + ')||0,';
} else if (
col.aggregatorid === 'MIN' ||
col.aggregatorid === 'MAX' ||
col.aggregatorid === 'FIRST' ||
col.aggregatorid === 'LAST'
// || col.aggregatorid == 'AVG'
// ) { return "'"+col.as+'\':r[\''+col.as+'\'],'; }//f.field.arguments[0].toJS();
) {
return "'" + colas + "':" + colexp + ','; //f.field.arguments[0].toJS();
} else if (col.aggregatorid === 'MIN') {
if ('funcid' in col.expression) {
let colexpression = col.expression.args[0];
let colexp1 = colexpression.toJS('p', tableid, defcols);
return `'${colas}': (typeof ${colexp1} == 'number' ? ${colexp1} : typeof ${colexp1} == 'object' ?
typeof Number(${colexp1}) == 'number' && ${colexp1}!== null? ${colexp1} : null : null),`;
}
return `'${colas}': (typeof ${colexp} == 'number' ? ${colexp} : typeof ${colexp} == 'object' ?
typeof Number(${colexp}) == 'number' && ${colexp}!== null? ${colexp} : null : null),`;
} else if (col.aggregatorid === 'MAX') {
if ('funcid' in col.expression) {
let colexpression = col.expression.args[0];
let colexp1 = colexpression.toJS('p', tableid, defcols);
return `'${colas}' : (typeof ${colexp1} == 'number' ? ${colexp1} : typeof ${colexp1} == 'object' ?
typeof Number(${colexp1}) == 'number' ? ${colexp1} : null : null),`;
}
return `'${colas}' : (typeof ${colexp} == 'number' ? ${colexp} : typeof ${colexp} == 'object' ?
typeof Number(${colexp}) == 'number' ? ${colexp} : null : null),`;
} else if (col.aggregatorid === 'ARRAY') {
return "'" + colas + "':[" + colexp + '],';
} else if (col.aggregatorid === 'COUNT') {
Expand Down Expand Up @@ -324,34 +303,7 @@ if(false) {
var post = "g['$$_VALUES_" + colas + "'][" + colexp + ']=true;}';
}
if (col.aggregatorid === 'SUM') {
if ('funcid' in col.expression) {
let colexpression = col.expression.args[0];
let colexp1 = colexpression.toJS('p', tableid, defcols);
return (
pre +
`if(g['${colas}'] == null && ${colexp1} == null){g['${colas}'] = null}
else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp1}!== 'object' && typeof ${colexp1}!== 'number'){g['${colas}'] = null}
else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp1} == 'number'){g['${colas}'] = ${colexp1}}
else if(typeof g['${colas}']!== 'number' && typeof ${colexp1}!== 'number' && typeof ${colexp1}!== 'object'){g['${colas}'] = g['${colas}']}
else if((g['${colas}'] == null || (typeof g['${colas}']!== 'number' && typeof g['${colas}']!== 'object')) && (${colexp1} == null || (typeof ${colexp1}!== 'number' && typeof ${colexp1}!== 'object'))){g['${colas}'] = null}
else if(typeof g['${colas}'] == 'number' && typeof ${colexp1} ==null){g['${colas}'] = g['${colas}']}
else if(typeof g['${colas}'] == null && typeof ${colexp1} =='number'){g['${colas}'] = ${colexp1}}
else{g['${colas}'] += ${colexp1}||0}` +
post
);
}
return (
pre +
`if(g['${colas}'] == null && ${colexp} == null){g['${colas}'] = null}
else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number'&& typeof ${colexp}!== 'object' && typeof ${colexp}!== 'number'){g['${colas}'] = null}
else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp} == 'number'){g['${colas}'] = ${colexp}}
else if(typeof g['${colas}']!== 'number' && typeof ${colexp}!== 'number' && typeof ${colexp}!== 'object'){g['${colas}'] = g['${colas}']}
else if((g['${colas}'] == null || (typeof g['${colas}']!== 'number' && typeof g['${colas}']!== 'object')) && (${colexp} == null || (typeof ${colexp}!== 'number' && typeof ${colexp}!== 'object'))){g['${colas}'] = null}
else if(typeof g['${colas}'] == 'number' && typeof ${colexp} ==null){g['${colas}'] = g['${colas}']}
else if(typeof g['${colas}'] == null && typeof ${colexp} =='number'){g['${colas}'] = ${colexp}}
else{g['${colas}'] += ${colexp}||0}` +
post
);
return pre + "g['" + colas + "']+=(" + colexp + '||0);' + post; //f.field.arguments[0].toJS();
} else if (col.aggregatorid === 'COUNT') {
// console.log(221,col.expression.columnid == '*');
if (col.expression.columnid === '*') {
Expand All @@ -372,48 +324,12 @@ if(false) {
} else if (col.aggregatorid === 'ARRAY') {
return pre + "g['" + colas + "'].push(" + colexp + ');' + post;
} else if (col.aggregatorid === 'MIN') {
if ('funcid' in col.expression) {
let colexpression = col.expression.args[0];
let colexp1 = colexpression.toJS('p', tableid, defcols);
return (
pre +
`if((g['${colas}'] == null && ${colexp1}!== null) ? y = ${colexp1} : (g['${colas}']!== null &&
${colexp1} == null) ? y = g['${colas}']:((y=${colexp1}) < g['${colas}'])){ if(typeof y == 'number')
{g['${colas}'] = y;}else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}
else if(g['${colas}']!== null && typeof g['${colas}'] == 'object' && y instanceof Date){g['${colas}'] = g['${colas}']}
else if(g['${colas}']!== null && typeof g['${colas}'] == 'object'){g['${colas}'] = Number(g['${colas}'])}` +
post
);
}
return (
pre +
`if((g['${colas}'] == null && ${colexp}!== null) ? y = ${colexp} : (g['${colas}']!== null &&
${colexp} == null) ? y = g['${colas}']:((y=${colexp}) < g['${colas}'])){ if(typeof y == 'number')
{g['${colas}'] = y;}else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}
else if(g['${colas}']!== null && typeof g['${colas}'] == 'object' && y instanceof Date){g['${colas}'] = g['${colas}']}
else if(g['${colas}']!== null && typeof g['${colas}'] == 'object'){g['${colas}'] = Number(g['${colas}'])}` +
post
pre + 'if ((y=' + colexp + ") < g['" + colas + "']) g['" + colas + "'] = y;" + post
);
} else if (col.aggregatorid === 'MAX') {
if ('funcid' in col.expression) {
let colexpression = col.expression.args[0];
let colexp1 = colexpression.toJS('p', tableid, defcols);
return (
pre +
`if((y=${colexp1}) > g['${colas}']){if(typeof y == 'number'){g['${colas}'] = y;}
else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}` +
post
);
}
return (
pre +
`if((y=${colexp}) > g['${colas}']){if(typeof y == 'number'){g['${colas}'] = y;}
else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}` +
post
pre + 'if ((y=' + colexp + ") > g['" + colas + "']) g['" + colas + "'] = y;" + post
);
} else if (col.aggregatorid === 'FIRST') {
return '';
Expand Down
10 changes: 1 addition & 9 deletions test/test020.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ describe('Test 20 - User-defined functions', function () {
num = 0;
var runspy2 = alasql.compile('select value max(spy(a)) from one');
var res = runspy2();
assert.deepEqual(res, 30);

var runspy3 = alasql.compile('select value sum(spy(a)) from one');
var res = runspy3();
assert.deepEqual(res, 60);

var runspy4 = alasql.compile('select value min(spy(a)) from one');
var res = runspy4();
assert.deepEqual(res, 10);
assert.deepEqual(res, 3);

alasql('drop database test20');
done();
Expand Down
178 changes: 0 additions & 178 deletions test/test846.js

This file was deleted.

0 comments on commit 241368a

Please sign in to comment.