UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.28 kB
import{SqlError as e,SqlErrorCodes as t}from"./errorsupport.js";import{FeatureServiceDatabaseType as r}from"./shared.js";import{toWhereClauseFromTree as n}from"./sqlUtils.js";import{WhereClause as i}from"../../../core/sql/WhereClause.js";function s(s){if("function"===s.parseTree.type){if(0===s.parseTree.args.value.length)return{name:s.parseTree.name,expr:null};if(s.parseTree.args.value.length>1)throw new e(t.MissingStatisticParameters);const a=i.create(n(s.parseTree.args.value[0],r.Standardised,s.parameters),s.fieldsIndex);return{name:s.parseTree.name,expr:a}}return null}class a{constructor(){this.field="",this.tofieldname="",this.typeofstat="MIN",this.workingexpr=null}clone(){const e=new a;return e.field=this.field,e.tofieldname=this.tofieldname,e.typeofstat=this.typeofstat,e.workingexpr=this.workingexpr,e}static parseStatField(r,n,o){const l=new a;l.field=r;const p=i.create(n,o),f=s(p);if(null===f)throw new e(t.UnsupportedSqlFunction,{function:""});const u=f.name.toUpperCase().trim();if("MIN"===u){if(l.typeofstat="MIN",l.workingexpr=f.expr,null===p)throw new e(t.InvalidFunctionParameters,{function:"min"})}else if("MAX"===u){if(l.typeofstat="MAX",l.workingexpr=f.expr,null===p)throw new e(t.InvalidFunctionParameters,{function:"max"})}else if("COUNT"===u)l.typeofstat="COUNT",l.workingexpr=f.expr;else if("STDEV"===u){if(l.typeofstat="STDDEV",l.workingexpr=f.expr,null===p)throw new e(t.InvalidFunctionParameters,{function:"stdev"})}else if("SUM"===u){if(l.typeofstat="SUM",l.workingexpr=f.expr,null===p)throw new e(t.InvalidFunctionParameters,{function:"sum"})}else if("MEAN"===u){if(l.typeofstat="AVG",l.workingexpr=f.expr,null===p)throw new e(t.InvalidFunctionParameters,{function:u})}else if("AVG"===u){if(l.typeofstat="AVG",l.workingexpr=f.expr,null===p)throw new e(t.InvalidFunctionParameters,{function:"avg"})}else{if("VAR"!==u)throw new e(t.UnsupportedSqlFunction,{function:u});if(l.typeofstat="VAR",l.workingexpr=f.expr,null===p)throw new e(t.InvalidFunctionParameters,{function:"var"})}return l}toStatisticsName(){switch(this.typeofstat.toUpperCase()){case"MIN":return"min";case"MAX":return"max";case"SUM":return"sum";case"COUNT":default:return"count";case"VAR":return"var";case"STDDEV":return"stddev";case"AVG":return"avg"}}}export{a as default};