SQL Scripting for ETL: Difference between revisions
Line 62: | Line 62: | ||
|- | |- | ||
|#_Selection | |#_Selection | ||
| | |Objects user has currently selected on the analysis. Supported objects are the event types and flows in the Flowchart or Path analyses and the Excel cells in the Duration, Profiling, Cases, Variations, Event Types, or Flows analyses. Any filters already applied are included in the selection. The maximum amount for the selection is 1000 separate objects and 10000 cells and their values. Represented as a four column table variable, where columns are: | ||
* '''Type''': type of the selected object. INT. Types is described in the table below. | * '''Type''': type of the selected object. INT. Types is described in the table below. | ||
* '''IntValue''': integer representation of the selection value (used for object IDs etc). Data type is BIGINT. | * '''IntValue''': integer representation of the selection value (used for object IDs etc.). Data type is BIGINT. | ||
* '''Value''': string representation of the selected value. Used for selections that require more complex representation than single integer value. Data type is NVARCHAR(MAX). | * '''Value''': string representation of the selected value. Used for selections that require more complex representation than a single integer value. Data type is NVARCHAR(MAX). | ||
* '''Name''': the unique name for the selection value. See the table above for the list of name used for each type. Note that there can be multiple rows with the same name if the selection consists of multiple "objects". Data type is NVARCHAR(MAX). | * '''Name''': the unique name for the selection value. See the table above for the list of name used for each type. Note that there can be multiple rows with the same name if the selection consists of multiple "objects". Data type is NVARCHAR(MAX). | ||
|- | |- | ||
Line 158: | Line 158: | ||
|SelectionType | |SelectionType | ||
|What was selected. The value for this parameter is shown on the "Value" column instead of the IntValue column. | |What was selected. The value for this parameter is shown on the "Value" column instead of the IntValue column. | ||
|} | |} | ||
Revision as of 09:38, 4 February 2018
This page describes how to extract data from source systems and load data into QPR ProcessAnalyzer, i.e. how to do ETL (extract, transform and load). The supported commands and their descriptions are listed in Supported QPR ProcessAnalyzer Commands in Scripts.
It is possible to load raw data into QPR ProcessAnalyzer, and do the data transformation and loading into QPR ProcessAnalyzer Service via scripts using temporary database tables, so that the resulting transformed data can be used for analyses in QPR ProcessAnalyzer.
A user with the ManageIntegrations and RunScripts permissions can define a script via the Manage Scripts dialog. The script consists of SQL statements and QPR ProcessAnalyzer commands that take the preceding SQL statements as parameters.
Script Variables
The scripts have variables available listed in the table below. Even when a script context hasn't been selected, the variables get their values from a default filter. The default filter is the filter that was last used by the user in the model the user has last opened. If the user hasn't opened any model before, the default filter is taken from the last created model to which the user has access rights.
Variable name | Description |
---|---|
@_CurrentScriptId | Id the the script being run. BIGINT. The difference between @_ScriptId and @_CurrentScriptId is apparent with nested scripts. @_ScriptId gives the id of the script that was started and which can call other scripts, @_CurrentScriptId gives the id of the script that is being run after the script has been called by the original script. That is, if you have nested scripts, @_ScriptId doesn't change, whereas @_CurrentScriptId is updated when the original script calls some other script. |
@_DatabaseId | the Id of the database in use. GUID. |
@_EngineScriptingVersion | The scripting version that identifies the functionalities available from QPR ProcessAnalyzer server. A script created for newer (bigger) scripting version doesn't necessarily work on a QPR ProcessAnalyzer server supporting older (smaller) version. INT. |
@_ExceptionDetails | if there was an exception when running the script, contains the details that would have been displayed, including the system stack trace, NVARCHAR(MAX), otherwise NULL. |
@_ExceptionMessage | if there was an exception when running the script, contains a message that would have been displayed, NVARCHAR(MAX), otherwise NULL. |
@_ExceptionOccurred | if there was an exception when running the script, then this value is 1, otherwise 0. INT |
@_ExceptionType | if there was an exception when running the script, shows the C# class name for the exception, NVARCHAR(MAX), otherwise NULL. |
@_FilterId | the Id of the filter in whose context the script is being run. BIGINT. Undefined if filter context has not been specified in script execution parameters. |
@_ModelId | the Id of the model in whose context the script is being run. BIGINT. Undefined if model context has not been specified in script execution parameters. |
@_ProjectId | the Id of the project in whose context the script is being run. BIGINT. Undefined if project context has not been specified in script execution parameters. |
@_QPRProcessAnalyzerVersion | the QPR Process Analyzer core dll version as string in the format: <major>.<minor>.<build>.<revision>. NVARCHAR(64). |
@_ScriptId | Id of the script that was started. BIGINT. |
@_ScriptingVersion | The scripting version number that identifies the version which was used when script was saved. Can be used for indicating, for example, the version for which the script was originally planned. A script created for newer (bigger) scripting version doesn't necessarily work on a PA server supporting older (smaller) version. INT. |
@_UserId | the Id of the user running the script. INT. |
#_ViewSettings | The Settings shown in the right-hand pane in Excel used to generate the selected view. Note that this doesn't include analysis results or QPR ProcessAnalyzer Server related information, such as FilterId, TotalEventCount, or DatabaseId. Represented as a table two column table variable. The columns are:
|
#_Selection | Objects user has currently selected on the analysis. Supported objects are the event types and flows in the Flowchart or Path analyses and the Excel cells in the Duration, Profiling, Cases, Variations, Event Types, or Flows analyses. Any filters already applied are included in the selection. The maximum amount for the selection is 1000 separate objects and 10000 cells and their values. Represented as a four column table variable, where columns are:
|
|
Script Variable ExamplesThe following script fragment defines the ProjectId, ModelId, and FilterId parameters by using the script variables: SELECT @_ProjectId as ProjectId, @_ModelId as ModelId, @_FilterId as FilterId; The following script gets the View Settings currently in use in the Settings pane in Excel and shows them as a table in a new Excel sheet: (SELECT * FROM #_ViewSettings) (SELECT 'SheetName', 'ViewSettings') --#ShowReport The following script gets the current selection on the analysis and shows the data as a table in a new Excel sheet: (SELECT * FROM #_Selection) (SELECT 'SheetName' , 'Selection') --#ShowReport The following script gets various information about the environment and shows them in a new Excel sheet: SELECT @_QPRProcessAnalyzerVersion as QPRProcessAnalyzerVersion, @_ScriptingVersion as ScriptingVersion, @_EngineScriptingVersion as EngineScriptingVersion, @_UserId as Userid, @_DatabaseId as DatabaseId (SELECT 'SheetName', 'Info') --#ShowReport Exception HandlingIn general, scripts are meant to be developed in such a way that in the end you can run the scripts without any errors. However, sometimes there may be some system issues (timeouts SAP etc.) that can cause for example data extraction scripts to fail. For these kind of situations and for development time and troubleshooting purposes, you can use the CatchOperationExceptions parameter and the @_ExceptionOccurred, @_ExceptionType, @_ExceptionMessage, and @_ExceptionDetails script variables with the QPR ProcessAnalyzer script commands to handle exceptions in ProcessAnalyzer. Out of these, the @_ExceptionOccurred is handy for example in defining some other command to be run in case there was an exception. For SQL errors, the TRY-CATCH error handling should be used. SELECT @_ExceptionOccurred 'ExceptionOccurred', @_ExceptionType 'ExceptionType', @_ExceptionMessage 'ExceptionMessage', @_ExceptionDetails 'ExceptionDetails' INTO #PACommandExceptions Using temporary tables in SQL ServerWhen transforming data in QPR ProcessAnalyzer Pro (i.e. when connected to the QPR ProcessAnalyzer Service), only temporary tables (#) should be used. Note that global temporary tables (##) cannot be used in the SQL scripts, as using them is not allowed. When using QPR ProcessAnalyzer Xpress, these limitations do not apply. Print Command in SQL ServerThe Print SQL statement can be used to generate log entries into the script execution log. Running ScriptsA script can be run in the following ways:
Terminating ScriptsScripts can be terminated in the following ways:
Note that terminating a script will not revert any changes the script has already done in the database before the Cancel button is clicked. Things to Note About ScriptsWhen writing and using scripts, take the following things into account:
Supported Transport Layer Security ProtocolsThe following transport layer security protocols are supported when using for example the CallWebService, ImportOdbcQuery, ImportOleDbQuery, ImportSapQuery, ImportSqlQuery, and SendEmail script commands:
SSL2 and SSL3 are not supported. Troubleshooting ScriptsAfter a script has been run, the Script Log dialog is shown. You can use it to troubleshoot your script. Invalid Object Name
/*This is the GetAnalysis part */ (SELECT 'AnalysisType', '6') UNION ALL (SELECT 'MaximumCount', '0') UNION ALL (SELECT 'FilterId', '10') UNION ALL (SELECT 'SelectedEventAttributes', '*') UNION ALL (SELECT 'TargetTable', '#AnalysisResult') --#GetAnalysis /*Here we create the event table, if it is missing */ IF object_id('tempdb..#AnalysisResult') is null BEGIN CREATE TABLE #AnalysisResult ( CaseName NVARCHAR(MAX), EventTypeName NVARCHAR(MAX), TimeStamp DATETIME, Cost FLOAT, TotalCost FLOAT ); END /*Then we use the ImportEvents */ (SELECT 'ProjectName', 'ExampleProject') UNION ALL (SELECT 'ModelName', 'ExampleModel') (SELECT * FROM [#AnalysisResult]) --#ImportEvents Incorrect Syntax When Using ' Characters
Incorrect Syntax When Running Scripts Copied from QPR ProcessAnalyzer Wiki
Using "##" in a Script
The ? Character in Project and Model Names
Multiple Projects with the Same Name
Multiple Models with the Same Name
DECLARE @referenceAscii int = 0 IF object_id('tempdb..#ids') is null CREATE TABLE #ids ( id int) DECLARE @i int = 0 WHILE @i < 70000 BEGIN SET @i = @i + 1 INSERT #ids VALUES (@i) END select * FROM ( select sys.fn_varbintohexstr(CONVERT(varBINARY(8), id)) as CharacterAsHex, id as ASCIICode, nchar(id) as Character, (CASE WHEN Nchar(@referenceAscii) = NCHAR(id) THEN 1 ELSE 0 END) as ShownAsSimilar FROM #ids ) as x where x.ShownAsSimilar = 1 --#ShowReport Client Exception When Using #ImportSapQuery Command
#ImportSapQuery: SAP.Middleware.Connector.RfcAbapRuntimeException: SAP.Middleware.Connector.RfcAbapRuntimeException: Error in module RSQL of the database interface at SAP.Middleware.Connector.RfcConnection.ThrowRfcErrorMsg() at SAP.Middleware.Connector.RfcConnection.ReadBytes(Byte* buffer, Int32 count) at SAP.Middleware.Connector.RfcConnection.ReadRfcIDBegin(Int32& length) at SAP.Middleware.Connector.RfcConnection.ReadUpTo(RFCGET readState, RfcFunction function, RFCID toRid) at SAP.Middleware.Connector.RfcConnection.RfcReceive(RfcFunction function) at SAP.Middleware.Connector.RfcFunction.RfcDeserialize(RfcConnection conn, IRfcIOStream stream) at SAP.Middleware.Connector.RfcFunction.RfcCallReceive(RfcConnection conn, IRfcIOStream stream, RFCID rid) at SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination) at Qpr.ProcessAnalyzer.Common.Integration.Sap.SapQuery(RfcDestination destination, Action`2 getSapWhereClauseSelect, Boolean enableStreamCompression, IDictionary`2 parameters) System.ServiceModel.FaultException`1[Qpr.Utils.SapError]: SAP.Middleware.Connector.RfcAbapRuntimeException: Error in module RSQL of the database interface (Fault Detail is equal to SAP.Middleware.Connector.RfcAbapRuntimeException: Error in module RSQL of the database interface
See Also
|