Skip to content

MySQL Server Transformation

The MySQL Server Transformation is used in the enterprise version of process.science for Power BI to prepare the data. The package is designed to transform the data from the MySQL database into a form that is suitable for Power BI. It creates four tables that can be used for analysis in Power BI.

Preparing the input table

Before the scripts can be used, you must ensure that your input table fulfils the following requirements. The column names for case_id, activity and timestamp are fixed and must be present in your input table. The other names can be changed in the script.

Field NameDescriptionData TypeMandatory
case_idThrough this field the process instances can be differentiated.text
activityThis field describes the activity that has taken place.text
activity_groupedThis field describes the group of the activity that has taken place.text
timestampThis field describes when an event has taken place.timestamp
timestamp_endThis field can be used to calculate the duration of activities.timestamp
sort_keyThis field can be used to adjust the sorting of the event log.bigint
valueThis allows you to set the costs for the current event.bigint
automatedThis allows you to set wether the activity was automated or not.bigint
resourceThis allows you to set user information for each activity.‚Any
Additional Activity ValuesFurther information per activity, e.g. quantity of items. All fields, not matching other names will be mapped as additional activity values and will be stored in the newly created event log table.Any
Additional Cases ValuesFurther information per case, e.g. a company division. All fields starting with case_ will be mapped as additional cases values and will be stored in the newly created cases table.Any
Additional Activity Values GroupedFurther information per activity group, e.g. quantity of items. All fields ending with _grouped will be mapped as additional activity group values and will be stored in the newly created event log table.Any

Downloading the scripts

The scripts can always be downloaded in the latest version from our Self Service Portal. The scripts are contained in a ZIP file and must be unpacked.

Installation and configuration

Customise scheme

If the output schema is not public, you must adapt the scripts to use the correct schema. To do this, replace public with the desired schema.

Creating the static tables

  1. open the script 1_CreateStaticTables.sql and execute it in your database.
  2. the script creates the tables filter_and, filter_or and if the grouped calculation is to take place also the tables filter_and_grouped, filter_or_grouped and activity_group_map in your output schema.

This script must be executed whenever the structure of the input table changes.

Creating the procedures

The next step is to create the procedures that write the data to the tables. To do this, the scripts 2_CreateEventLogProcedure.sql, 3_CreateEventLogGroupedProcedure.sql, 4_CreateAdditionalGroupedTablesProcedure.sql , 5_CreateCasesDataProcedure.sql must be executed. This only needs to be done once.

Event log

The procedure ps_createEventLogDataTable creates the table eventlog in your output schema and fills it with the data from the input table. All additional columns that do not begin with case_ or end with _grouped are stored in the eventlog table.

sql
DROP PROCEDURE  IF EXISTS  ps_createEventLogTable;
CREATE PROCEDURE ps_createEventLogTable(
    IN SchemaName TEXT,
    IN TableName TEXT,
    IN ActivityGroupedName TEXT,
    IN TimestampEndName TEXT,
    IN ValueName TEXT,
    IN AutomatedName TEXT,
    IN ResourceName TEXT,
    IN SortKeyName TEXT
)

If the dynamic columns (timestamp_end, sort_key, value, automated and resource) are not present in the input table, they are automatically filled with default values.

Event log grouped

The procedure ps_createEventLogGroupedTable creates the table eventlog_grouped in your output schema and fills it with the data from the input table. This script is only executed if the grouped calculation is to take place, i.e. the activity_grouped column is present in the input table. All additional columns with the suffix _grouped are saved in the eventlog_grouped table.

sql
DROP PROCEDURE IF EXISTS ps_createEventLogGroupedTable;
CREATE PROCEDURE ps_createEventLogGroupedTable(
    IN SchemaName VARCHAR(255),
    IN TableName VARCHAR(255),
    IN ActivityGroupedName VARCHAR(255),
    IN TimestampEndName VARCHAR(255),
    IN ValueName VARCHAR(255),
    IN AutomatedName VARCHAR(255),
    IN ResourceName VARCHAR(255),
    IN SortKeyName VARCHAR(255),
    OUT success_flag INT
)

Additional grouped tables

The procedure ps_createAdditionalGroupedTables creates the tables filter_and_grouped and filter_or_grouped. This procedure is only executed if the grouped calculation is to take place.

sql
DROP PROCEDURE  IF EXISTS ps_createAdditionalGroupedTables;
CREATE PROCEDURE ps_createAdditionalGroupedTables()

Case table

The procedure ps_createCasesDataTable creates the table cases_data in your output schema and fills it with the data from the input table. All additional columns beginning with case_ are stored in the cases_data table.

sql
DROP PROCEDURE IF EXISTS ps_createCasesDataTable;
CREATE PROCEDURE ps_createCasesDataTable(
    IN SchemaName TEXT,
    IN TableName TEXT,
    IN PerformGroupedCalculation INT
)

Loading the data

To load the data, the script 6_CreatePerformTransformationProcedure.sql must be executed. This script creates a procedure that calls all other procedures that write the data to the tables. In this script, the information on the input table and the dynamic columns must be adapted above.

sql
DROP PROCEDURE IF EXISTS ps_performTransformation;
CREATE PROCEDURE ps_performTransformation()
    -- **************** Define the table and column names here ********************** --
    DECLARE SchemaName VARCHAR(255) DEFAULT 'public';
    DECLARE TableName VARCHAR(255) DEFAULT 'eventlog_en';
    DECLARE ActivityGroupedName VARCHAR(255) DEFAULT 'activity_grouped';
    DECLARE TimestampEndName VARCHAR(255) DEFAULT 'timestamp_end';
    DECLARE ValueName VARCHAR(255) DEFAULT 'activity_cost';
    DECLARE AutomatedName VARCHAR(255) DEFAULT 'automated';
    DECLARE ResourceName VARCHAR(255) DEFAULT 'user_name';
    DECLARE SortKeyName VARCHAR(255) DEFAULT 'sort_key';
    DECLARE PerformGroupedCalculation INT;
    -- **************** Define the table and column names here ********************** --

Once this procedure has been created, it can be executed to write the data to the tables.

sql
CALL public.ps_PerformTransformation();

Scheduling

You can use a tool of your choice to automate the last Call. This allows you to update your data regularly and always see the latest information in Power BI. The MySQL Event Scheduler can be used for this.

sql
CREATE EVENT IF NOT EXISTS update_ps4pbi_data
ON SCHEDULE
  EVERY 1 DAY
  STARTS '2024-01-22 09:00:00'
ENABLE
COMMENT 'Daily task: Update the ps4pbi Process Mining Tables for Power BI'
DO
    CALL public.ps_PerformTransformation();