12 |
- "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4251],{38667:(e,t,a)=>{a.r(t),a.d(t,{AnnotationsQueryCtrl:()=>M,ConfigCtrl:()=>T,Datasource:()=>b,MysqlDatasource:()=>b,QueryCtrl:()=>A,plugin:()=>I});var r=a(43215),i=a(4344),s=a(82897),n=a(58788),l=a(2937),u=a(10010),o=a(76913),m=a(69649),h=a(90923),d=a(62362),c=a(7166);function p(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}class g{constructor(e,t,a){p(this,"target",void 0),p(this,"templateSrv",void 0),p(this,"scopedVars",void 0),this.target=e,this.templateSrv=t,this.scopedVars=a,e.format=e.format||"time_series",e.timeColumn=e.timeColumn||"time",e.metricColumn=e.metricColumn||"none",e.group=e.group||[],e.where=e.where||[{type:"macro",name:"$__timeFilter",params:[]}],e.select=e.select||[[{type:"column",params:["value"]}]],"rawQuery"in this.target||(e.rawQuery="rawSql"in e),this.interpolateQueryStr=this.interpolateQueryStr.bind(this)}unquoteIdentifier(e){return'"'===e[0]&&'"'===e[e.length-1]?e.substring(1,e.length-1).replace(/""/g,'"'):e}quoteIdentifier(e){return'"'+e.replace(/"/g,'""')+'"'}quoteLiteral(e){return"'"+e.replace(/'/g,"''")+"'"}escapeLiteral(e){return String(e).replace(/'/g,"''")}hasTimeGroup(){return(0,s.find)(this.target.group,(e=>"time"===e.type))}hasMetricColumn(){return"none"!==this.target.metricColumn}interpolateQueryStr(e,t,a){if(!t.multi&&!t.includeAll)return this.escapeLiteral(e);if("string"==typeof e)return this.quoteLiteral(e);return(0,s.map)(e,this.quoteLiteral).join(",")}render(e){const t=this.target;return this.target.rawQuery||"table"in this.target?(t.rawQuery||(t.rawSql=this.buildQuery()),e?this.templateSrv.replace(t.rawSql,this.scopedVars,this.interpolateQueryStr):t.rawSql):""}hasUnixEpochTimecolumn(){return["int","bigint","double"].indexOf(this.target.timeColumnType)>-1}buildTimeColumn(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];const t=this.hasTimeGroup();let a,r="$__timeGroup";if(t){let i;i=t.params.length>1&&"none"!==t.params[1]?t.params.join(","):t.params[0],this.hasUnixEpochTimecolumn()&&(r="$__unixEpochGroup"),e&&(r+="Alias"),a=r+"("+this.target.timeColumn+","+i+")"}else a=this.target.timeColumn,e&&(a+=' AS "time"');return a}buildMetricColumn(){return this.hasMetricColumn()?this.target.metricColumn+" AS metric":""}buildValueColumns(){let e="";for(const t of this.target.select)e+=",\n "+this.buildValueColumn(t);return e}buildValueColumn(e){let t="";t=(0,s.find)(e,(e=>"column"===e.type)).params[0];const a=(0,s.find)(e,(e=>"aggregate"===e.type));if(a){t=a.params[0]+"("+t+")"}const r=(0,s.find)(e,(e=>"alias"===e.type));return r&&(t+=" AS "+this.quoteIdentifier(r.params[0])),t}buildWhereClause(){let e="";const t=(0,s.map)(this.target.where,((e,t)=>{switch(e.type){case"macro":return e.name+"("+this.target.timeColumn+")";case"expression":return e.params.join(" ")}}));return t.length>0&&(e="\nWHERE\n "+t.join(" AND\n ")),e}buildGroupClause(){let e="",t="";for(let e=0;e<this.target.group.length;e++){const a=this.target.group[e];e>0&&(t+=", "),"time"===a.type?t+="1":t+=a.params[0]}return t.length&&(e="\nGROUP BY "+t,this.hasMetricColumn()&&(e+=",2")),e}buildQuery(){let e="SELECT";return e+="\n "+this.buildTimeColumn(),this.hasMetricColumn()&&(e+=",\n "+this.buildMetricColumn()),e+=this.buildValueColumns(),e+="\nFROM "+this.target.table,e+=this.buildWhereClause(),e+=this.buildGroupClause(),e+="\nORDER BY "+this.buildTimeColumn(!1),e}}g.$inject=["target","templateSrv","scopedVars"];var y=a(5970);class f{transformMetricFindResponse(e){const t=(0,h.toDataQueryResponse)(e).data;if(!t||!t.length)return[];const a=t[0],r=[],i=a.fields.find((e=>"__text"===e.name)),s=a.fields.find((e=>"__value"===e.name));if(i&&s)for(let e=0;e<i.values.length;e++)r.push({text:""+i.values.get(e),value:""+s.values.get(e)});else r.push(...a.fields.flatMap((e=>e.values.toArray())).map((e=>({text:e}))));return Array.from(new Set(r.map((e=>e.text)))).map((e=>{var t;return{text:e,value:null===(t=r.find((t=>t.text===e)))||void 0===t?void 0:t.value}}))}async transformAnnotationResponse(e,t){const a=(0,h.toDataQueryResponse)({data:t}).data;if(!a||!a.length)return[];const r=a[0],i=r.fields.find((e=>"time"===e.name||"time_sec"===e.name));if(!i)throw new Error("Missing mandatory time column (with time column alias) in annotation query");if(r.fields.find((e=>"title"===e.name)))throw new Error("The title column for annotations is deprecated, now only a column named text is returned");const s=r.fields.find((e=>"timeend"===e.name)),n=r.fields.find((e=>"text"===e.name)),l=r.fields.find((e=>"tags"===e.name)),u=[];for(let t=0;t<r.length;t++){const a=s&&s.values.get(t)?Math.floor(s.values.get(t)):void 0;u.push({annotation:e.annotation,time:Math.floor(i.values.get(t)),timeEnd:a,text:n&&n.values.get(t)?n.values.get(t):"",tags:l&&l.values.get(t)?l.values.get(t).trim().split(/\s*,\s*/):[]})}return u}}function v(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}class b extends h.DataSourceWithBackend{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(0,c.J)();super(e),v(this,"id",void 0),v(this,"name",void 0),v(this,"responseParser",void 0),v(this,"queryModel",void 0),v(this,"interval",void 0),v(this,"interpolateVariable",((e,t)=>{if("string"==typeof e){if(t.multi||t.includeAll){return this.queryModel.quoteLiteral(e)}return e}if("number"==typeof e)return e;return(0,s.map)(e,(e=>this.queryModel.quoteLiteral(e))).join(",")})),this.templateSrv=t,this.name=e.name,this.id=e.id,this.responseParser=new f,this.queryModel=new g({});const a=e.jsonData||{};this.interval=a.timeInterval||"1m"}interpolateVariablesInQueries(e,t){let a=e;return e&&e.length>0&&(a=e.map((e=>Object.assign({},e,{datasource:this.getRef(),rawSql:this.templateSrv.replace(e.rawSql,t,this.interpolateVariable),rawQuery:!0})))),a}filterQuery(e){return!e.hide}applyTemplateVariables(e,t){const a=new g(e,this.templateSrv,t);return{refId:e.refId,datasource:this.getRef(),rawSql:a.render(this.interpolateVariable),format:e.format}}async annotationQuery(e){if(!e.annotation.rawQuery)return Promise.reject({message:"Query missing in annotation definition"});const t={refId:e.annotation.name,datasource:this.getRef(),rawSql:this.templateSrv.replace(e.annotation.rawQuery,e.scopedVars,this.interpolateVariable),format:"table"};return(0,n.n)((0,h.getBackendSrv)().fetch({url:"/api/ds/query",method:"POST",data:{from:e.range.from.valueOf().toString(),to:e.range.to.valueOf().toString(),queries:[t]},requestId:e.annotation.name}).pipe((0,u.U)((async t=>await this.responseParser.transformAnnotationResponse(e,t.data)))))}metricFindQuery(e,t){var a,r,i,s;let m="tempvar";t&&t.variable&&t.variable.name&&(m=t.variable.name);const d=this.templateSrv.replace(e,(0,y._6)({query:e,wildcardChar:"%",options:t}),this.interpolateVariable),c={refId:m,datasource:this.getRef(),rawSql:d,format:"table"},p=null==t?void 0:t.range;return(0,n.n)((0,h.getBackendSrv)().fetch({url:"/api/ds/query",method:"POST",data:{from:null==p||null===(a=p.from)||void 0===a||null===(r=a.valueOf())||void 0===r?void 0:r.toString(),to:null==p||null===(i=p.to)||void 0===i||null===(s=i.valueOf())||void 0===s?void 0:s.toString(),queries:[c]},requestId:m}).pipe((0,u.U)((e=>this.responseParser.transformMetricFindResponse(e))),(0,o.K)((e=>(0,l.of)([])))))}testDatasource(){return(0,n.n)((0,h.getBackendSrv)().fetch({url:"/api/ds/query",method:"POST",data:{from:"5m",to:"now",queries:[{refId:"A",intervalMs:1,maxDataPoints:1,datasource:this.getRef(),rawSql:"SELECT 1",format:"table"}]}}).pipe((0,m.h)({status:"success",message:"Database Connection OK"}),(0,o.K)((e=>(0,l.of)((0,d.Gw)(e))))))}targetContainsTemplate(e){let t="";if(e.rawQuery)t=e.rawSql;else{t=new g(e).buildQuery()}return t=t.replace("$__",""),this.templateSrv.containsTemplate(t)}}var S=a(5831),w=a(60974),C=a(21169);class _{constructor(e,t){this.target=e,this.queryModel=t}getOperators(e){switch(e){case"double":case"float":return["=","!=","<","<=",">",">="];case"text":case"tinytext":case"mediumtext":case"longtext":case"varchar":case"char":return["=","!=","<","<=",">",">=","IN","NOT IN","LIKE","NOT LIKE"];default:return["=","!=","<","<=",">",">=","IN","NOT IN"]}}quoteIdentAsLiteral(e){return this.queryModel.quoteLiteral(this.queryModel.unquoteIdentifier(e))}findMetricTable(){return"\n SELECT\n table_name as table_name,\n ( SELECT\n column_name as column_name\n FROM information_schema.columns c\n WHERE\n c.table_schema = t.table_schema AND\n c.table_name = t.table_name AND\n c.data_type IN ('timestamp', 'datetime')\n ORDER BY ordinal_position LIMIT 1\n ) AS time_column,\n ( SELECT\n column_name AS column_name\n FROM information_schema.columns c\n WHERE\n c.table_schema = t.table_schema AND\n c.table_name = t.table_name AND\n c.data_type IN('float', 'int', 'bigint')\n ORDER BY ordinal_position LIMIT 1\n ) AS value_column\n FROM information_schema.tables t\n WHERE\n t.table_schema = database() AND\n EXISTS\n ( SELECT 1\n FROM information_schema.columns c\n WHERE\n c.table_schema = t.table_schema AND\n c.table_name = t.table_name AND\n c.data_type IN ('timestamp', 'datetime')\n ) AND\n EXISTS\n ( SELECT 1\n FROM information_schema.columns c\n WHERE\n c.table_schema = t.table_schema AND\n c.table_name = t.table_name AND\n c.data_type IN('float', 'int', 'bigint')\n )\n LIMIT 1\n;"}buildTableConstraint(e){let t="";if(e.includes(".")){const a=e.split(".");return t="table_schema = "+this.quoteIdentAsLiteral(a[0]),t+=" AND table_name = "+this.quoteIdentAsLiteral(a[1]),t}return t="table_schema = database() AND table_name = "+this.quoteIdentAsLiteral(e),t}buildTableQuery(){return"SELECT table_name FROM information_schema.tables WHERE table_schema = database() ORDER BY table_name"}buildColumnQuery(e){let t="SELECT column_name FROM information_schema.columns WHERE ";switch(t+=this.buildTableConstraint(this.target.table),e){case"time":t+=" AND data_type IN ('timestamp','datetime','bigint','int','double','float')";break;case"metric":case"group":t+=" AND data_type IN ('text','tinytext','mediumtext','longtext','varchar','char')";break;case"value":t+=" AND data_type IN ('bigint','int','smallint','mediumint','tinyint','double','decimal','float')",t+=" AND column_name <> "+this.quoteIdentAsLiteral(this.target.timeColumn)}return t+=" ORDER BY column_name",t}buildValueQuery(e){let t="SELECT DISTINCT QUOTE("+e+")";return t+=" FROM "+this.target.table,t+=" WHERE $__timeFilter("+this.target.timeColumn+")",t+=" ORDER BY 1 LIMIT 100",t}buildDatatypeQuery(e){let t="\nSELECT data_type\nFROM information_schema.columns\nWHERE ";return t+=" table_name = "+this.quoteIdentAsLiteral(this.target.table),t+=" AND column_name = "+this.quoteIdentAsLiteral(e),t}}var P=a(79281);const E=[];function R(e){E[e.type]=new P.m(e)}R({type:"column",style:"label",params:[{type:"column",dynamicLookup:!0}],defaultParams:["value"]}),R({type:"expression",style:"expression",label:"Expr:",params:[{name:"left",type:"string",dynamicLookup:!0},{name:"op",type:"string",dynamicLookup:!0},{name:"right",type:"string",dynamicLookup:!0}],defaultParams:["value","=","value"]}),R({type:"macro",style:"label",label:"Macro:",params:[],defaultParams:[]}),R({type:"aggregate",style:"label",params:[{name:"name",type:"string",options:["avg","count","min","max","sum","stddev","variance"]}],defaultParams:["avg"]}),R({type:"alias",style:"label",params:[{name:"name",type:"string",quote:"double"}],defaultParams:["alias"]}),R({type:"time",style:"function",label:"time",params:[{name:"interval",type:"interval",options:["$__interval","1s","10s","1m","5m","10m","15m","1h"]},{name:"fill",type:"string",options:["none","NULL","previous","0"]}],defaultParams:["$__interval","none"]});const Q={create:function(e){const t=E[e.type];return t?new P.H(e,t):null}};function x(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}class A extends w.QueryCtrl{constructor(e,t,a,i){super(e,t),x(this,"formats",void 0),x(this,"lastQueryError",void 0),x(this,"showHelp",void 0),x(this,"queryModel",void 0),x(this,"metaBuilder",void 0),x(this,"lastQueryMeta",void 0),x(this,"tableSegment",void 0),x(this,"whereAdd",void 0),x(this,"timeColumnSegment",void 0),x(this,"metricColumnSegment",void 0),x(this,"selectMenu",[]),x(this,"selectParts",[]),x(this,"groupParts",[]),x(this,"whereParts",[]),x(this,"groupAdd",void 0),this.templateSrv=a,this.uiSegmentSrv=i,this.target=this.target,this.queryModel=new g(this.target,a,this.panel.scopedVars),this.metaBuilder=new _(this.target,this.queryModel),this.updateProjection(),this.formats=[{text:"Time series",value:"time_series"},{text:"Table",value:"table"}],this.target.rawSql||("table"===this.panelCtrl.panel.type?(this.target.format="table",this.target.rawSql="SELECT 1",this.target.rawQuery=!0):(this.target.rawSql="SELECT\n UNIX_TIMESTAMP(<time_column>) as time_sec,\n <value column> as value,\n <series name column> as metric\nFROM <table name>\nWHERE $__timeFilter(time_column)\nORDER BY <time_column> ASC\n",this.datasource.metricFindQuery(this.metaBuilder.findMetricTable()).then((e=>{if(e.length>0){this.target.table=e[0].text;let t=this.uiSegmentSrv.newSegment(this.target.table);this.tableSegment.html=t.html,this.tableSegment.value=t.value,this.target.timeColumn=e[1].text,t=this.uiSegmentSrv.newSegment(this.target.timeColumn),this.timeColumnSegment.html=t.html,this.timeColumnSegment.value=t.value,this.target.timeColumnType="timestamp",this.target.select=[[{type:"column",params:[e[2].text]}]],this.updateProjection(),this.updateRawSqlAndRefresh()}})))),this.target.table?this.tableSegment=i.newSegment(this.target.table):this.tableSegment=i.newSegment({value:"select table",fake:!0}),this.timeColumnSegment=i.newSegment(this.target.timeColumn),this.metricColumnSegment=i.newSegment(this.target.metricColumn),this.buildSelectMenu(),this.whereAdd=this.uiSegmentSrv.newPlusButton(),this.groupAdd=this.uiSegmentSrv.newPlusButton(),this.panelCtrl.events.on(r.PanelEvents.dataReceived,this.onDataReceived.bind(this),e),this.panelCtrl.events.on(r.PanelEvents.dataError,this.onDataError.bind(this),e)}updateRawSqlAndRefresh(){this.target.rawQuery||(this.target.rawSql=this.queryModel.buildQuery()),this.panelCtrl.refresh()}updateProjection(){this.selectParts=(0,s.map)(this.target.select,(e=>(0,s.map)(e,Q.create).filter((e=>e)))),this.whereParts=(0,s.map)(this.target.where,Q.create).filter((e=>e)),this.groupParts=(0,s.map)(this.target.group,Q.create).filter((e=>e))}updatePersistedParts(){this.target.select=(0,s.map)(this.selectParts,(e=>(0,s.map)(e,(e=>({type:e.def.type,datatype:e.datatype,params:e.params}))))),this.target.where=(0,s.map)(this.whereParts,(e=>({type:e.def.type,datatype:e.datatype,name:e.name,params:e.params}))),this.target.group=(0,s.map)(this.groupParts,(e=>({type:e.def.type,datatype:e.datatype,params:e.params})))}buildSelectMenu(){this.selectMenu.push({text:"Aggregate Functions",value:"aggregate",submenu:[{text:"Average",value:"avg"},{text:"Count",value:"count"},{text:"Maximum",value:"max"},{text:"Minimum",value:"min"},{text:"Sum",value:"sum"},{text:"Standard deviation",value:"stddev"},{text:"Variance",value:"variance"}]}),this.selectMenu.push({text:"Alias",value:"alias"}),this.selectMenu.push({text:"Column",value:"column"})}toggleEditorMode(){this.target.rawQuery?S.Z.publish(new C.VJ({title:"Warning",text2:"Switching to query builder may overwrite your raw SQL.",icon:"exclamation-triangle",yesText:"Switch",onConfirm:()=>{this.$scope.$evalAsync((()=>{this.target.rawQuery=!this.target.rawQuery}))}})):this.$scope.$evalAsync((()=>{this.target.rawQuery=!this.target.rawQuery}))}resetPlusButton(e){const t=this.uiSegmentSrv.newPlusButton();e.html=t.html,e.value=t.value}getTableSegments(){return this.datasource.metricFindQuery(this.metaBuilder.buildTableQuery()).then(this.transformToSegments({})).catch(this.handleQueryError.bind(this))}tableChanged(){this.target.table=this.tableSegment.value,this.target.where=[],this.target.group=[],this.updateProjection();const e=this.uiSegmentSrv.newSegment("none");this.metricColumnSegment.html=e.html,this.metricColumnSegment.value=e.value,this.target.metricColumn="none";const t=this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery("time")).then((e=>{if(e.length>0&&!(0,s.find)(e,(e=>e.text===this.target.timeColumn))){const t=this.uiSegmentSrv.newSegment(e[0].text);this.timeColumnSegment.html=t.html,this.timeColumnSegment.value=t.value}return this.timeColumnChanged(!1)})),a=this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery("value")).then((e=>{e.length>0&&(this.target.select=[[{type:"column",params:[e[0].text]}]],this.updateProjection())}));Promise.all([t,a]).then((()=>{this.updateRawSqlAndRefresh()}))}getTimeColumnSegments(){return this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery("time")).then(this.transformToSegments({})).catch(this.handleQueryError.bind(this))}timeColumnChanged(e){return this.target.timeColumn=this.timeColumnSegment.value,this.datasource.metricFindQuery(this.metaBuilder.buildDatatypeQuery(this.target.timeColumn)).then((t=>{if(1===t.length){let e;this.target.timeColumnType!==t[0].text&&(this.target.timeColumnType=t[0].text),e=this.queryModel.hasUnixEpochTimecolumn()?Q.create({type:"macro",name:"$__unixEpochFilter",params:[]}):Q.create({type:"macro",name:"$__timeFilter",params:[]}),this.whereParts.length>=1&&"macro"===this.whereParts[0].def.type?this.whereParts[0]=e:this.whereParts.splice(0,0,e)}this.updatePersistedParts(),!1!==e&&this.updateRawSqlAndRefresh()}))}getMetricColumnSegments(){return this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery("metric")).then(this.transformToSegments({addNone:!0})).catch(this.handleQueryError.bind(this))}metricColumnChanged(){this.target.metricColumn=this.metricColumnSegment.value,this.updateRawSqlAndRefresh()}onDataReceived(e){var t;this.lastQueryError=void 0,this.lastQueryMeta=null===(t=e[0])||void 0===t?void 0:t.meta}onDataError(e){if(e.data&&e.data.results){const t=e.data.results[this.target.refId];t&&(this.lastQueryError=t.error)}}transformToSegments(e){return t=>{const a=(0,s.map)(t,(e=>this.uiSegmentSrv.newSegment({value:e.text,expandable:e.expandable})));if(e.addTemplateVars)for(const t of this.templateSrv.getVariables()){let r;r="$"+t.name,e.templateQuoter&&!1===t.multi&&(r=e.templateQuoter(r)),a.unshift(this.uiSegmentSrv.newSegment({type:"template",value:r,expandable:!0}))}return e.addNone&&a.unshift(this.uiSegmentSrv.newSegment({type:"template",value:"none",expandable:!0})),a}}findAggregateIndex(e){return(0,s.findIndex)(e,(e=>"aggregate"===e.def.type||"percentile"===e.def.type))}findWindowIndex(e){return(0,s.findIndex)(e,(e=>"window"===e.def.type||"moving_window"===e.def.type))}addSelectPart(e,t,a){let r=t.value;a&&a.type&&(r=a.type);let i=Q.create({type:r});a&&(i.params[0]=a.value);let n=!1;switch(r){case"column":const t=(0,s.map)(e,(e=>Q.create({type:e.def.type,params:(0,s.clone)(e.params)})));this.selectParts.push(t);break;case"percentile":case"aggregate":0===this.target.group.length&&this.addGroup("time","$__interval");const a=this.findAggregateIndex(e);-1!==a?e[a]=i:e.splice(1,0,i),(0,s.find)(e,(e=>"alias"===e.def.type))||(n=!0);break;case"moving_window":case"window":const r=this.findWindowIndex(e);if(-1!==r)e[r]=i;else{const t=this.findAggregateIndex(e);-1!==t?e.splice(t+1,0,i):e.splice(1,0,i)}(0,s.find)(e,(e=>"alias"===e.def.type))||(n=!0);break;case"alias":n=!0}n&&(i=Q.create({type:"alias",params:[e[0].params[0].replace(/"/g,"")]}),"alias"===e[e.length-1].def.type?e[e.length-1]=i:e.push(i)),this.updatePersistedParts(),this.updateRawSqlAndRefresh()}removeSelectPart(e,t){if("column"===t.def.type){if(this.selectParts.length>1){const t=(0,s.indexOf)(this.selectParts,e);this.selectParts.splice(t,1)}}else{const a=(0,s.indexOf)(e,t);e.splice(a,1)}this.updatePersistedParts()}handleSelectPartEvent(e,t,a){switch(a.name){case"get-param-options":if("column"===t.def.type)return this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery("value")).then(this.transformToSegments({})).catch(this.handleQueryError.bind(this));case"part-param-changed":this.updatePersistedParts(),this.updateRawSqlAndRefresh();break;case"action":this.removeSelectPart(e,t),this.updateRawSqlAndRefresh();break;case"get-part-actions":return Promise.resolve([{text:"Remove",value:"remove-part"}])}}handleGroupPartEvent(e,t,a){switch(a.name){case"get-param-options":return this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery()).then(this.transformToSegments({})).catch(this.handleQueryError.bind(this));case"part-param-changed":this.updatePersistedParts(),this.updateRawSqlAndRefresh();break;case"action":this.removeGroup(e,t),this.updateRawSqlAndRefresh();break;case"get-part-actions":return Promise.resolve([{text:"Remove",value:"remove-part"}])}}addGroup(e,t){let a=[t];"time"===e&&(a=["$__interval","none"]);const r=Q.create({type:e,params:a});"time"===e?this.groupParts.splice(0,0,r):this.groupParts.push(r);for(const e of this.selectParts)if(!e.some((e=>"aggregate"===e.def.type))){const t=Q.create({type:"aggregate",params:["avg"]});if(e.splice(1,0,t),!e.some((e=>"alias"===e.def.type))){const t=Q.create({type:"alias",params:[e[0].part.params[0]]});e.push(t)}}this.updatePersistedParts()}removeGroup(e,t){"time"===e.def.type&&(this.selectParts=(0,s.map)(this.selectParts,(e=>(0,s.filter)(e,(e=>"aggregate"!==e.def.type&&"percentile"!==e.def.type))))),this.groupParts.splice(t,1),this.updatePersistedParts()}handleWherePartEvent(e,t,a,r){switch(a.name){case"get-param-options":switch(a.param.name){case"left":return this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery()).then(this.transformToSegments({})).catch(this.handleQueryError.bind(this));case"right":return["int","bigint","double","datetime"].indexOf(t.datatype)>-1?Promise.resolve([]):this.datasource.metricFindQuery(this.metaBuilder.buildValueQuery(t.params[0])).then(this.transformToSegments({addTemplateVars:!0,templateQuoter:e=>this.queryModel.quoteLiteral(e)})).catch(this.handleQueryError.bind(this));case"op":return Promise.resolve(this.uiSegmentSrv.newOperators(this.metaBuilder.getOperators(t.datatype)));default:return Promise.resolve([])}case"part-param-changed":this.updatePersistedParts(),this.datasource.metricFindQuery(this.metaBuilder.buildDatatypeQuery(t.params[0])).then((e=>{1===e.length&&(t.datatype=e[0].text)})),this.updateRawSqlAndRefresh();break;case"action":e.splice(r,1),this.updatePersistedParts(),this.updateRawSqlAndRefresh();break;case"get-part-actions":return Promise.resolve([{text:"Remove",value:"remove-part"}])}}getWhereOptions(){const e=[];return this.queryModel.hasUnixEpochTimecolumn()?e.push(this.uiSegmentSrv.newSegment({type:"macro",value:"$__unixEpochFilter"})):e.push(this.uiSegmentSrv.newSegment({type:"macro",value:"$__timeFilter"})),e.push(this.uiSegmentSrv.newSegment({type:"expression",value:"Expression"})),Promise.resolve(e)}addWhereAction(e,t){switch(this.whereAdd.type){case"macro":{const e=Q.create({type:"macro",name:this.whereAdd.value,params:[]});this.whereParts.length>=1&&"macro"===this.whereParts[0].def.type?this.whereParts[0]=e:this.whereParts.splice(0,0,e);break}default:this.whereParts.push(Q.create({type:"expression",params:["value","=","value"]}))}this.updatePersistedParts(),this.resetPlusButton(this.whereAdd),this.updateRawSqlAndRefresh()}getGroupOptions(){return this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery("group")).then((e=>{const t=[];this.queryModel.hasTimeGroup()||t.push(this.uiSegmentSrv.newSegment({type:"time",value:"time($__interval,none)"}));for(const a of e)t.push(this.uiSegmentSrv.newSegment({type:"column",value:a.text}));return t})).catch(this.handleQueryError.bind(this))}addGroupAction(){this.groupAdd.value,this.addGroup(this.groupAdd.type,this.groupAdd.value),this.resetPlusButton(this.groupAdd),this.updateRawSqlAndRefresh()}handleQueryError(e){return this.error=e.message||"Failed to issue metric query",[]}}function q(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}A.$inject=["$scope","$injector","templateSrv","uiSegmentSrv"],x(A,"templateUrl","partials/query.editor.html");class T{constructor(){q(this,"current",void 0),q(this,"onPasswordReset",void 0),q(this,"onPasswordChange",void 0),this.onPasswordReset=(0,i.Xr)(this,i.HX.Password),this.onPasswordChange=(0,i.wP)(this,i.HX.Password)}}q(T,"templateUrl","partials/config.html");class M{constructor(e){this.annotation=e.ctrl.annotation,this.annotation.rawQuery=this.annotation.rawQuery||"SELECT\n UNIX_TIMESTAMP(<time_column>) as time_sec,\n <text_column> as text,\n <tags_column> as tags\n FROM <table name>\n WHERE $__timeFilter(time_column)\n ORDER BY <time_column> ASC\n LIMIT 100\n "}}M.$inject=["$scope"],q(M,"templateUrl","partials/annotations.editor.html");const I=new r.DataSourcePlugin(b).setQueryCtrl(A).setConfigCtrl(T).setAnnotationQueryCtrl(M)}}]);
- //# sourceMappingURL=mysqlPlugin.db022442881163470d6f.js.map
|