From aeb11808159455cad3fb41ba01b01aa2c2c3a8ad Mon Sep 17 00:00:00 2001 From: Dmitrij Vladimirov <47441164+Frisle@users.noreply.github.com> Date: Tue, 25 Apr 2023 15:49:13 +0600 Subject: [PATCH 1/2] Update Utils.cls Improved method. Now it provides complete result set with series and properties based on SQL. Part of this was taken from ##class(%DeepSee.REST.v1.DataServer).WriteJSONfromKPI --- MDX2JSON/Utils.cls | 75 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/MDX2JSON/Utils.cls b/MDX2JSON/Utils.cls index 60c3b11..affbb16 100644 --- a/MDX2JSON/Utils.cls +++ b/MDX2JSON/Utils.cls @@ -89,6 +89,35 @@ ClassMethod WriteJSONfromQuery(CubeKey As %String, QueryKey As %String, Timeout return $$$OK } + +/// Execute SQL query taken from KPI and extract column values by name of column +/// Output array with list of values like so pValue(n) = $LB(sNameList(i)...) +ClassMethod getSQLValues(pSQL, Output pValues As %String) As %Status +{ + + set st = $$$OK + Set tResultSet = ##class(%SQL.Statement).%ExecDirect(,pSQL) + set tCount = 0 + + while tResultSet.%Next() + { + set lValue = "" + for i=1:1:tResultSet.%GetMetadata().columnCount + { + set sNameList(i) = tResultSet.%GetMetadata().columns.GetAt(i).label + set lValue = lValue _ $lb(tResultSet.%Get(sNameList(i))) // append next column to the list + } + + Set tCount = tCount + 1 + set pValues(tCount) = lValue + } + return st +} + + +/// This method provides listing execution for KPI. +/// tKPI as a name of KPI class. pFilters not yet implemented +/// as a pSelection. Thats for future use. ClassMethod WriteDrillthroughJSONKPI(tKPI As %String, pFilters As %String, pSelection As %String) As %Status { @@ -98,15 +127,53 @@ ClassMethod WriteDrillthroughJSONKPI(tKPI As %String, pFilters As %String, pSele set kpitype = $classmethod(tKpiClassName, "%GetSourceType") if (kpitype="sql") { - set pSQL = $classmethod(tKpiClassName, "%OnGetListingSQL", pFilters,pSelection) // invoke corresponding method from given kpi and get sql query + set pSQL = $classmethod(tKpiClassName,"%OnGetListingSQL",pFilters,pSelection) // invoke corresponding method from given kpi and get sql query + Set stmt = ##class(%SQL.Statement).%ExecDirect(,pSQL) + set values = ..getSQLValues(pSQL, .pValue) + + for i=1:1:stmt.%GetMetadata().columnCount + { + set pList(i) = stmt.%GetMetadata().columns.GetAt(i).label + set pList(i, "columnNo") = i + Set tKpiPropIdx = $O(pList(""),1,tProperty) + Set tKpiPropList = "" + While (tKpiPropIdx'="") { + Set tKpiPropList = tKpiPropList _ $LB(tProperty) + Set tKpiPropArray(tKpiPropIdx) = $LB(tProperty,$G(pList(tKpiPropIdx,"name")),$G(pList(tKpiPropIdx,"columnNo"))) + Set tKpiPropIdx = $O(pList(tKpiPropIdx),1,tProperty) + + } + + } + Set tKpiSC = $classmethod(tKpiClassName,"%GetKPIValueArray",tKpiClassName,,.tKpiPropList,.tFilters) + + Set tSC = ##class(%DeepSee.REST.v1.DataServer).%CreateObjectFromArray(.pValue,tKpiPropList,.tValueObj) + If $$$ISERR(tSC) Quit + + Set tSC = ##class(%DeepSee.REST.v1.DataServer).%CreateObjectFromArray(.tKpiPropArray,$LB("name","caption","columnNo"),.tPropObj) + If $$$ISERR(tSC) + + // Use consistent objects for normalized return + Set tProvider = ##class(%ZEN.Auxiliary.jsonMDXProvider).%New() + Set tInfoObj = tProvider.%ConstructNewDynamicObject() + Set tResultObj = tProvider.%ConstructNewDynamicObject() + + Set:$IsObject(tPropObj.children) tResultObj.Properties = tPropObj.children + Set:$IsObject(tValueObj.children) tResultObj.Series = tValueObj.children + + Set tInfoObj.Error = tProvider.%StatusToDynamicObject(tKpiSC) + Set tInfoObj.KpiName = tKpiClassName + + Set tKpiObj = tProvider.%ConstructNewDynamicObject() + Set tKpiObj.Info = tInfoObj + Set tKpiObj.Result = tResultObj + + Set tSC = tProvider.%ObjectToJSON(tKpiObj) }else{ quit $$$ERROR($$$GeneralError, "KPI type " _ kpitype _ " not supported") } - - set st = ##class(%ZEN.Auxiliary.altJSONSQLProvider).%WriteJSONFromSQL(,pSQL,,$$$MaxCacheInt) // receiving sql and process it - return:$$$ISERR(st) st return st } From c027f351293ec156247bd628aa5f929693f31484 Mon Sep 17 00:00:00 2001 From: Dmitrij Vladimirov <47441164+Frisle@users.noreply.github.com> Date: Fri, 28 Apr 2023 20:05:59 +0600 Subject: [PATCH 2/2] Update Utils.cls Additional changes to improve execution speed --- MDX2JSON/Utils.cls | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/MDX2JSON/Utils.cls b/MDX2JSON/Utils.cls index affbb16..d302b55 100644 --- a/MDX2JSON/Utils.cls +++ b/MDX2JSON/Utils.cls @@ -92,7 +92,7 @@ ClassMethod WriteJSONfromQuery(CubeKey As %String, QueryKey As %String, Timeout /// Execute SQL query taken from KPI and extract column values by name of column /// Output array with list of values like so pValue(n) = $LB(sNameList(i)...) -ClassMethod getSQLValues(pSQL, Output pValues As %String) As %Status +ClassMethod GetSQLValues(pSQL, Output pValues As %String, Output tResultSet As %SQL.Statement) As %Status { set st = $$$OK @@ -128,12 +128,11 @@ ClassMethod WriteDrillthroughJSONKPI(tKPI As %String, pFilters As %String, pSele if (kpitype="sql") { set pSQL = $classmethod(tKpiClassName,"%OnGetListingSQL",pFilters,pSelection) // invoke corresponding method from given kpi and get sql query - Set stmt = ##class(%SQL.Statement).%ExecDirect(,pSQL) - set values = ..getSQLValues(pSQL, .pValue) + set values = ..GetSQLValues(pSQL, .pValue, .tResultSet) - for i=1:1:stmt.%GetMetadata().columnCount + for i=1:1:tResultSet.%GetMetadata().columnCount { - set pList(i) = stmt.%GetMetadata().columns.GetAt(i).label + set pList(i) = tResultSet.%GetMetadata().columns.GetAt(i).label set pList(i, "columnNo") = i Set tKpiPropIdx = $O(pList(""),1,tProperty) Set tKpiPropList = ""