@@ -98,9 +98,9 @@ yy.Select.prototype.compileGroup = function (query) {
9898 if ( col . aggregatorid === 'SUM' ) {
9999 if ( 'funcid' in col . expression ) {
100100 let colexp1 = colExpIfFunIdExists ( col . expression ) ;
101- return `'${ colas } ':(${ colexp1 } ) || typeof ${ colexp1 } == 'number' ? ${ colexp } : null,` ;
101+ return `'${ colas } ':(__alasql_tmp = ${ colexp } , (__alasql_tmp instanceof Date) ? null : ((__alasql_tmp || typeof __alasql_tmp == 'number') ? __alasql_tmp : null)) ,` ;
102102 }
103- return `'${ colas } ':(${ colexp } ) || typeof ${ colexp } == 'number' ? ${ colexp } : null,` ;
103+ return `'${ colas } ':(__alasql_tmp = ${ colexp } , (__alasql_tmp instanceof Date) ? null : ((__alasql_tmp || typeof __alasql_tmp == 'number') ? __alasql_tmp : null)) ,` ;
104104 } else if ( col . aggregatorid === 'TOTAL' ) {
105105 if ( 'funcid' in col . expression ) {
106106 let colexp1 = colExpIfFunIdExists ( col . expression ) ;
@@ -117,16 +117,13 @@ yy.Select.prototype.compileGroup = function (query) {
117117 if ( 'funcid' in col . expression ) {
118118 let colexp1 = colExpIfFunIdExists ( col . expression ) ;
119119
120- return `'${ colas } ': (typeof ${ colexp1 } == 'number' || typeof ${ colexp1 } == 'bigint' ? ${ colexp } : typeof ${ colexp1 } == 'object' ?
121- typeof Number(${ colexp1 } ) == 'number' && ${ colexp1 } !== null? ${ colexp } : null : null),` ;
120+ return `'${ colas } ': (__alasql_tmp = ${ colexp } , typeof __alasql_tmp == 'number' || typeof __alasql_tmp == 'bigint' || (typeof __alasql_tmp == 'object' && (typeof Number(__alasql_tmp) == 'number' || __alasql_tmp instanceof Date)) ? __alasql_tmp : null),` ;
122121 }
123- return `'${ colas } ': (typeof ${ colexp } == 'number' || typeof ${ colexp } == 'bigint' ? ${ colexp } : typeof ${ colexp } == 'object' ?
124- typeof Number(${ colexp } ) == 'number' && ${ colexp } !== null? ${ colexp } : null : null),` ;
122+ return `'${ colas } ': (__alasql_tmp = ${ colexp } , typeof __alasql_tmp == 'number' || typeof __alasql_tmp == 'bigint' || (typeof __alasql_tmp == 'object' && (typeof Number(__alasql_tmp) == 'number' || __alasql_tmp instanceof Date)) ? __alasql_tmp : null),` ;
125123 } else if ( col . aggregatorid === 'MAX' ) {
126124 if ( 'funcid' in col . expression ) {
127125 let colexp1 = colExpIfFunIdExists ( col . expression ) ;
128- return `'${ colas } ' : (typeof ${ colexp1 } == 'number' || typeof ${ colexp1 } == 'bigint' ? ${ colexp } : typeof ${ colexp1 } == 'object' ?
129- typeof Number(${ colexp1 } ) == 'number' ? ${ colexp } : null : null),` ;
126+ return `'${ colas } ': (__alasql_tmp = ${ colexp } , typeof __alasql_tmp == 'number' || typeof __alasql_tmp == 'bigint' || (typeof __alasql_tmp == 'object' && (typeof Number(__alasql_tmp) == 'number' || __alasql_tmp instanceof Date)) ? __alasql_tmp : null),` ;
130127 }
131128 return `'${ colas } ' : (typeof ${ colexp } == 'number' || typeof ${ colexp } == 'bigint' ? ${ colexp } : typeof ${ colexp } == 'object' ?
132129 typeof Number(${ colexp } ) == 'number' ? ${ colexp } : null : null),` ;
@@ -142,7 +139,7 @@ yy.Select.prototype.compileGroup = function (query) {
142139 query . removeKeys . push ( `_SUM_${ colas } ` ) ;
143140 query . removeKeys . push ( `_COUNT_${ colas } ` ) ;
144141
145- return `'${ colas } ':${ colexp } ,'_SUM_${ colas } ':(${ colexp } )||0 ,'_COUNT_${ colas } ':(typeof ${ colexp } == "undefined" || ${ colexp } === null) ? 0 : 1,` ;
142+ return `'${ colas } ':(function() { var t = ${ colexp } ; return (t instanceof Date) ? null : t; })() ,'_SUM_${ colas } ':(function() { var t = ${ colexp } ; return (t instanceof Date) ? null : (t || 0); })() ,'_COUNT_${ colas } ':(typeof ${ colexp } == "undefined" || ${ colexp } === null) ? 0 : 1,` ;
146143 } else if ( col . aggregatorid === 'AGGR' ) {
147144 aft += `,g['${ colas } ']=${ col . expression . toJS ( 'g' , - 1 ) } ` ;
148145 return '' ;
@@ -190,13 +187,16 @@ yy.Select.prototype.compileGroup = function (query) {
190187 } else if (typeof __g_colas === 'bigint' || typeof __colexp1 === 'bigint') {
191188 g['${ colas } '] = BigInt(__g_colas) + BigInt(__colexp);
192189 } else if ((typeof __g_colas !== 'object' && typeof __g_colas !== 'number' && __typeof_colexp1 !== 'object' && __typeof_colexp1 !== 'number') ||
193- (__g_colas == null || (typeof __g_colas !== 'number' && typeof __g_colas !== 'object')) && (${ colexp1 } == null || (__typeof_colexp1 !== 'number' && __typeof_colexp1 !== 'object'))) {
190+ (__g_colas == null || (typeof __g_colas !== 'number' && typeof __g_colas !== 'object')) && (${ colexp1 } == null || (__typeof_colexp1 !== 'number' && __typeof_colexp1 !== 'object'))) {
194191 g['${ colas } '] = null;
195192 } else if ((typeof __g_colas !== 'object' && typeof __g_colas !== 'number' && __typeof_colexp1 == 'number') ||
196193 (__g_colas == null && __typeof_colexp1 == 'number')) {
197194 g['${ colas } '] = ${ colexp } ;
198195 } else if (typeof __g_colas == 'number' && ${ colexp1 } == null) {
199196 g['${ colas } '] = __g_colas;
197+ } else if (__g_colas instanceof Date || __colexp1 instanceof Date) {
198+ // Date objects cause string concatenation with +=, return null instead
199+ g['${ colas } '] = null;
200200 } else {
201201 g['${ colas } '] += ${ colexp } || 0;
202202 }
@@ -226,6 +226,9 @@ yy.Select.prototype.compileGroup = function (query) {
226226 g['${ colas } '] = __g_colas;
227227 } else if (__g_colas == null && __typeof_colexp == 'number') {
228228 g['${ colas } '] = ${ colexp } ;
229+ } else if (__g_colas instanceof Date || __colexp instanceof Date) {
230+ // Date objects cause string concatenation with +=, return null instead
231+ g['${ colas } '] = null;
229232 } else {
230233 g['${ colas } '] += ${ colexp } || 0;
231234 }
@@ -369,19 +372,19 @@ yy.Select.prototype.compileGroup = function (query) {
369372 }
370373 return (
371374 pre +
372- `if((g['${ colas } '] == null && ${ colexp } !== null) ? y = ${ colexp } :
373- (g['${ colas } ']!== null && ${ colexp } == null) ? y = g['${ colas } '] :
374- ((y= ${ colexp } ) > g['${ colas } '])) {
375- if(typeof y == 'number' || typeof y == 'bigint') {
376- g['${ colas } '] = y;
377- } else if(typeof y == 'object' && y instanceof Date) {
378- g['${ colas } '] = y;
379- } else if(typeof y == 'object' && typeof Number(y) == 'number') {
380- g['${ colas } '] = Number(y);
375+ `if ((g['${ colas } '] == null && ${ colexp } !== null) ? y = ${ colexp } :
376+ (g['${ colas } '] !== null && ${ colexp } == null) ? y = g['${ colas } '] :
377+ ((y = ${ colexp } ) > g['${ colas } '])) {
378+ if (typeof y == 'number' || typeof y == 'bigint') {
379+ g['${ colas } '] = y;
380+ } else if (typeof y == 'object' && y instanceof Date) {
381+ g['${ colas } '] = y;
382+ } else if (typeof y == 'object' && typeof Number(y) == 'number') {
383+ g['${ colas } '] = Number(y);
381384 }
382- } else if(g['${ colas } ']!== null && typeof g['${ colas } '] == 'object' && y instanceof Date) {
385+ } else if (g['${ colas } '] !== null && typeof g['${ colas } '] == 'object' && y instanceof Date) {
383386 g['${ colas } '] = g['${ colas } '];
384- } else if(g['${ colas } ']!== null && typeof g['${ colas } '] == 'object') {
387+ } else if (g['${ colas } '] !== null && typeof g['${ colas } '] == 'object') {
385388 g['${ colas } '] = Number(g['${ colas } ']);
386389 }` +
387390 post
@@ -394,7 +397,11 @@ yy.Select.prototype.compileGroup = function (query) {
394397 return `${ pre }
395398 y= (${ colexp } );
396399 g['_COUNT_${ colas } '] += (typeof y == "undefined" || y === null) ? 0 : 1;
397- if (typeof g['_SUM_${ colas } '] === 'bigint' || typeof y === 'bigint') {
400+ if (y instanceof Date || (g['_SUM_${ colas } '] && g['_SUM_${ colas } '] instanceof Date)) {
401+ // AVG on Date objects doesn't make semantic sense - return null
402+ g['_SUM_${ colas } '] = null;
403+ g['${ colas } '] = null;
404+ } else if (typeof g['_SUM_${ colas } '] === 'bigint' || typeof y === 'bigint') {
398405 g['_SUM_${ colas } '] = BigInt(g['_SUM_${ colas } ']);
399406 g['_SUM_${ colas } '] += BigInt(y || 0);
400407 g['${ colas } '] = BigInt(g['_SUM_${ colas } ']) / BigInt(g['_COUNT_${ colas } ']);
0 commit comments