/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","./shared","./sqlUtils"],(function(t,n,e,r){"use strict";function u(t){return t=+t,isFinite(t)?t-t%1||(t<0?-0:0===t?t:0):t}function i(t){let n=0;for(let e=0;e<t.length;e++)n+=t[e];return n/t.length}function l(t){const n=i(t);let e=0;for(let r=0;r<t.length;r++)e+=(n-t[r])**2;return e/t.length}function a(t){const n=i(t);let e=0;for(let r=0;r<t.length;r++)e+=(n-t[r])**2;return e/(t.length-1)}function c(t){let n=0;for(let e=0;e<t.length;e++)n+=t[e];return n}function o(t,n){const r=[],u={},i=[];for(let l=0;l<t.length;l++){if(void 0!==t[l]&&null!==t[l]){const n=t[l];if(e.isNumber(n)||e.isString(n))void 0===u[n]&&(r.push(n),u[n]=1);else{let t=!1;for(let r=0;r<i.length;r++)!0===e.equalityTest(i[r],n)&&(t=!0);!1===t&&(i.push(n),r.push(n))}}if(r.length>=n&&-1!==n)return r}return r}function s(t){switch(t.toLowerCase()){case"distinct":return"distinct";case"avg":case"mean":return"avg";case"min":return"min";case"sum":return"sum";case"max":return"max";case"stdev":case"stddev":return"stddev";case"var":case"variance":return"var";case"count":return"count"}return""}function h(t,n,e=1e3){switch(t.toLowerCase()){case"distinct":return o(n,e);case"avg":case"mean":return i(n);case"min":return Math.min.apply(Math,n);case"sum":return c(n);case"max":return Math.max.apply(Math,n);case"stdev":case"stddev":return Math.sqrt(l(n));case"var":case"variance":return l(n);case"count":return n.length}return 0}function p(t,n,e){return f.apply(this,arguments)}function f(){return(f=n._asyncToGenerator((function*(t,n,e){const r=yield b(t,n,e,!0);return 0===r.length?null:Math.min.apply(Math,r)}))).apply(this,arguments)}function y(t,n,e){return d.apply(this,arguments)}function d(){return(d=n._asyncToGenerator((function*(t,n,e){const r=yield b(t,n,e,!0);return 0===r.length?null:Math.max.apply(Math,r)}))).apply(this,arguments)}function g(t,n,e){return m.apply(this,arguments)}function m(){return(m=n._asyncToGenerator((function*(t,n,e){let l="";!1===r.isSingleField(n)&&(l=r.predictType(n,t.fields,null));const a=yield b(t,n,e,!0);if(0===a.length)return null;const c=i(a);return null===c?c:"integer"===l?u(c):c}))).apply(this,arguments)}function v(t,n,e){return T.apply(this,arguments)}function T(){return(T=n._asyncToGenerator((function*(t,n,e){const r=yield b(t,n,e,!0);return 0===r.length?null:a(r)}))).apply(this,arguments)}function M(t,n,e){return _.apply(this,arguments)}function _(){return(_=n._asyncToGenerator((function*(t,n,e){const r=yield b(t,n,e,!0);return 0===r.length?null:Math.sqrt(a(r))}))).apply(this,arguments)}function x(t,n,e){return w.apply(this,arguments)}function w(){return(w=n._asyncToGenerator((function*(t,n,e){const r=yield b(t,n,e,!0);return 0===r.length?null:c(r)}))).apply(this,arguments)}function k(t,n){return G.apply(this,arguments)}function G(){return(G=n._asyncToGenerator((function*(t,n){return t.iterator(n).count()}))).apply(this,arguments)}function b(t,n,e){return S.apply(this,arguments)}function S(){return(S=n._asyncToGenerator((function*(t,n,e,r=!1){const u=t.iterator(e),i=[],l={ticker:0};let a=yield u.next();for(;null!==a;){if(l.ticker++,e.aborted)throw new Error("Cancelled");l.ticker%100==0&&(l.ticker=0,yield new Promise((t=>{setTimeout(t,0)})));const t=n.calculateValue(a);null===t?!1===r&&(i[i.length]=t):i[i.length]=t,a=yield u.next()}return i}))).apply(this,arguments)}function q(t,n){return C.apply(this,arguments)}function C(){return(C=n._asyncToGenerator((function*(t,n,e=1e3,r=null){const u=t.iterator(r),i=[],l={},a={ticker:0};let c=yield u.next();for(;null!==c;){if(a.ticker++,r.aborted)throw new Error("Cancelled");a.ticker%100==0&&(a.ticker=0,yield new Promise((t=>{setTimeout(t,0)})));const t=n.calculateValue(c);if(null!=t&&void 0===l[t]&&(i.push(t),l[t]=1),i.length>=e&&-1!==e)return i;c=yield u.next()}return i}))).apply(this,arguments)}t.calculateStat=h,t.count=k,t.decodeStatType=s,t.distinct=q,t.max=y,t.mean=g,t.min=p,t.stdev=M,t.sum=x,t.variance=v,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
