Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

On this Page

Table of Contents
maxLevel2
excludeOlder Versions|Additional Resources|Related Links|Related Information

Snap Type:Write
Description:

This Snap executes a stored procedure in a MySQL database and writes the values of OUT and INOUT parameters to the output views.

ETL Transformations & Data Flow

The Snap invokes the Stored procedure, and the ETL operations are carried out as specified on the stored procedure.

Ideally, there is no data flow from the Snap to the database, however, the results computed in the store procedure or the result of queries executed in the stored procedure can be fetched by the Snap through output parameters.

Input & Output

  • Input:  This Snap can have an upstream Snap that can pass a document to the output view (for example, Structure or JSON Generator). The input document may contain values for the Snap expression properties, typically for the Parameter values property.

    Example:     "John" and "Smith" are values for the stored procedure's input parameters, the first and the second, respectively.


Code Block
{
firstName: "John". lastName: "Smith" 
  • Output:   Output document in the output view contains a key-value pair for each output parameter. It will be an empty map document if there is no output parameter. Output document in the Result Set output view contains the result set of the stored procedure.

  • Expected upstream Snaps:  Any Snap with document output view

    Expected downstream Snaps:  Any Snap with document input view

Modes

Prerequisites:None at the moment.
Limitation and Known Issues
Multiexcerpt include macro
nameMySQLKI
pageMySQL Snap Pack
Views:


InputThis Snap has exactly one document input view.
OutputThis Snap has exactly two document output views, one regular output view, and one Result Set output view.
ErrorThis Snap has at most one document error view and produces zero or more documents in the view.


Settings

Label


Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline.

Schema Name

The schema name where the procedure resides. The property is suggestible and will return all schemas of the DB.

The values can be passed using the pipeline parameters, but not the upstream parameter.

Example: dbo

Default value: [None] 

Stored procedure name

Required. Stored procedure to execute. The property is suggestible and will return all procedures of the DB. If a schema is defined then it will return all procedures of that schema.

Example: addSeventeen

Default value: [None] 

Parameter values

Select the input parameter values for the stored procedure. 
If you define parameter values, you must do so in the same order as they appear in the stored procedure definition to ensure that the data type of the values you enter matches the data type of their corresponding parameters. If the values do not match the defined data type for the parameter an exception is thrown and the Snap does not execute.

Example: Suppose there is a stored procedure named createGreeting.  It has three parameters p1,p2, p3 and p4.  p1 and p2 are input parameters of type VARCHAR2, p3 is INOUT parameter of type VARCHAR2, then three string values provided.  The first value goes to p1, the second to p2, and the third to p3.

Quotation marks should not be used when setting input parameters unless they are part of the input value itself, since they are treated as escaped plain characters. For example, if the desired input value is TEST_VALUE1, the input parameter should be set as TEST_VALUE1, if you set it as "TEST_VALUE1", it will be recognized as \"TEST_VALUE1\".

Default value: [None]

Info

If you do not provide any parameters in the Snap, you can still view the required input parameters in the Target Schema of the upstream Mapper Snap. The parameters are dynamically populated based on the column keys of the stored procedure; you can map the parameters and pass them as an input to the Stored Procedure Snap.


Pass through

If selected, the input document will be passed through to the output views under the key 'original'. The document will be passed to the Parameter output view, and it will also be passed to the Result Set output view if there is output sent from this view.

This property applies only to the Execute Snaps with SELECT statement or the Select Snaps. 

Default value: Not selected 

Multiexcerpt include macro
nameSnap Execution
pageSOAP Execute

Multiexcerpt include macro
nameExecution_Detail_Write
pageSOAP Execute


Examples

Basic Use Case 1


The following pipeline describes how the Snap functions as a standalone Snap in a pipeline:



In this pipeline the stored procedure 'date rs2 demo' from the 'enron' schema is invoked using the MySQL Stored Procedure Snap. The stored procedure is as below:

Code Block
CREATE DEFINER=`mysqlqatest`@`%` PROCEDURE `date_rs2_demo`(IN inparam INT, OUT dc date, OUT dtc datetime, OUT tsc timestamp)
      BEGIN
           select dateC INTO dc from DateTypesDemo limit 1;
           select datetimeC INTO dtc from DateTypesDemo limit 1;
           select timestampC INTO tsc from DateTypesDemo limit 1;
           select * from DateTypesDemo;
           select * from AVemployees;	
      END


The value for the IN parameter is passed in the Parameter values property in the Snap: 

The output from the Snap are the OUT parameters and their values, and the result set from  the output parameters as seen in the images below:



Basic Use Case 2


In this example, the parameter values are passed to the MySQL Stored Procedure Snap through a Mapper Snap. 

View file
name5.webp
height250
Attachments
patterns*.slp


In this case, the MySQL Stored Procedure Snap will invoke the following stored procedure:


Code Block
DELIMITER $$

USE `enron`$$

DROP PROCEDURE IF EXISTS `basicDataTypes`$$

CREATE DEFINER=`mysqlqatest`@`%` PROCEDURE `basicDataTypes`(IN inParamInt INT, IN inParamVarchar VARCHAR(32), IN inParamBit BIT, OUT outParamInt INT, OUT outParamVarchar VARCHAR(32), OUT outParamBit BIT)
       BEGIN
            SET outParamInt= inParamInt;
            SET outParamVarchar= inParamVarchar;
            SET outParamBit= inParamBit;
       END$$

DELIMITER ;

In this stored procedure there is no result set; therefore, none will be generated when the pipeline is executed.

The Mapper Snap is used to pass the IN parameter's value to $id, the output preview can also be seen in the Output preview data section: 

The MySQL Stored Procedure Snap is configured as shown below. One of the IN parameters is passed as an expression. This is is the data received from the Mapper Snap:

As mentioned earlier, there will be no output result set because there is no result set from the stored procedure. The Result Set Ouput View will have no outputs and just the output parameters and their corresponding values will be shown by the Snap (in the Output Parameter output view). See the image below:


Typical Snap Configurations


The key configuration lies in how the SQL statement is passed. In this Snap it is possible to pass the values in the following ways:

  • Without Expression
    The values can be passed directly in the Snap: 

    With Expression
    • Using Pipeline Parameters:
      The Parameter value is passed as a pipeline parameter.


        
      View file
      name11.webp
      height400

Advanced Use Case

The following pipeline is an example of how the MySQL Stored Procedure Snap is used in a scenario where data from a MySQL instance is inserted in a SQL instance. The pipeline can be downloaded from the Downloads section below:

In this pipeline there are two stored procedures that will be invoked - "enron.SP_Emp_Delete" and "enron.Multiple_Statements".


The first stored procedure is as shown below:

Code Block
CREATE PROCEDURE enron.SP_Emp_Delete(IN empno1 INT,IN empno2 INT)
      BEGIN
           DELETE FROM sp_emp WHERE empid=empno1;
           DELETE FROM sp_emp WHERE empid=empno2;
      END

There are no OUT parameters in this stored procedure. No outputs will be shown in the Output Parameter output view.

The second stored procedure is as shown below:

Code Block
CREATE PROCEDURE enron.Multiple_Statements(IN empno1 INT,empno2 INT, OUT result1  INT,OUT result2 INT)
      BEGIN
           INSERT INTO sp_emp (empid,ename) VALUES (empno1,'snaplogic1');
           INSERT INTO sp_emp (empid,ename) VALUES (empno2,'snaplogic12');
           SELECT empid INTO result1 FROM sp_emp WHERE ename='snaplogic1';
           SELECT empid INTO result2 FROM sp_emp WHERE ename='snaplogic2';
      END


This pipeline does the following ETL operations:

  • Load: The first Mapper Snap maps the values "501", and "502" to the fields "empno1" and "empno2" in the target schema.
  • Transform: The first MySQL Stored Procedure Snap invokes the stored procedure "enron.SP_Emp_Delete" that deletes the records in the table that match the values in the "empno1" and "empno2" fields.
  • Load: The second Mapper Snap maps the values "501", "502", "snaplogic1", and "snaplogic12" to the "empno1", "empno2", "ename1", and "ename2" fields in the target schema.
  • Load: The second MySQL Stored Procedure Snap invokes the stored procedure "enron.Multiple_Statements" that inserts the records into the target table.
  • Extract & Load: The stored procedure "enron.Multiple_Statements" invoked by the second MySQL Stored Procedure Snap also extracts records from the table and writes the "empid" into the "result1" and "result2" fields where there is a matching record based on the "ename" field.
  • Load: The data passed from the second MySQL Stored Procedure Snap is inserted into the specified SQL database by the SQL Server Insert Snap.
  • Extract: The records in the specified SQL table are retrieved by the SQL Server Select Snap, demonstrating that the pipeline was executed successfully.


 The e
xported pipeline is available for download in the Download section.



Downloads

Multiexcerpt include macro
namedownload_instructions
pageOpenAPI

Attachments
patterns.*slp, .*zip

Insert excerpt
MySQL Snap Pack
MySQL Snap Pack
nopaneltrue