14-1 7 oracle data integrator user functions, variables and advanced mappings

19
14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

Upload: garey-dickerson

Post on 19-Jan-2016

236 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-1

7Oracle Data IntegratorUser Functions, Variables and Advanced

Mappings

Page 2: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-2

Objectives

• Variables• Sequences• User Functions• Advanced Mappings

After completing this lesson, you will know how to use:

Page 3: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-3

What Is a Variable?

Variable – An ODI object which stores a typed value, such as a number, string or date.Variables are used to customize transformations as well as to implement control structures, such as if-then statements and loops, into packages.

Page 4: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-4

Variable Scope

• Scope defines where the variable can be used.• Global variables are accessible everywhere (defined

in the Others tab of the Designer tree).• Project variables are accessible within the project

(and defined under the project in the Designer tree).

• The scope is defined by the location of the variable:• Global variables: in the Others view, under Global

variables• Project variables: in the Projects view, under

Variables

• To refer to a variable, prefix its name according to its scope:• Global variables: GLOBAL.<variable_name>• Project variables: <project_code>.<variable_name>

Page 5: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-5

Variable Configuration: The Definition

• Historize: keep all values taken by the Variable• Last value: only keep the most recent value• Not persistent: discard the value

Description of variable

Data type:Alphanumeric (250 chars)

Date (Java format)Numeric (10 digits).

Value given if no stored value

Page 6: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-6

Variable Configuration: The Query

SQL Refresh instruction

Logical Schema used for refreshing

• The result of a SQL query can be stored into a variable:• The query must return a single value of the correct type.• The query is executed by a Refresh Variable package step.• Can also refresh manually.

Page 7: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-7

Using a Variable in The Mappings

• When used, a variable is prefixed according to its scope:• Global variable: GLOBAL.<variable_name>

• Project variable: <project_code>.<variable_name>

• Tip: Use the Expression Editor to avoid mistakes in variables names.

• Variables are used either by string substitution or by parameter binding.• Substitution: #<project_code>.<variable_name>

• Binding: :<project_code>.<variable_name>

Page 8: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-8

How to Create a Variable Step in a Package

1. Select the variable from the Projects orOthers view.

2. Drag and drop it into the package.

3. Select the type of operation to perform:evaluate, set/increment,refresh or declare.

4. Set the options for the operation to perform.

Page 9: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-9

Variable Steps

• Declare Variable step type:• Forces a variable to be taken into account.• Use this step for variables used in transformations, or in the

topology.

• Set Variable step type:• Assigns a value to a

variable or increments the numeric variable of the value.

Page 10: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-10

Variable Steps (cont.)

• Refresh Variable step type:• Refreshes the value of the variable by executing the defined SQL

query.

• Evaluate Variable step type:• Compares the variable value with a given value, according to an

operator.• You can use a variable in the value in the value

Page 11: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-11

User Functions

Page 12: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-12

What Is a User Function?

User Function – A cross-technology macro defined in a lightweight syntax used to create an alias for a recurrent piece of code or encapsulate a customized transformation.

Page 13: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-13

Simple Example #1

• A simple formula: If <param1> is null then <param2> else <param1> end if

• Can be implemented differently in different technologies:• Oracle

nvl(<param1>, <param2>)

• Other technologies: case when <param1> is null then <param2> else <param1> end

• And could be aliased to:NumberToTitle(<param1>, <param2>)

Page 14: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-14

Simple Example #2

• A commonly used formula: If <param1> = ‘1’ then ‘Mr’else if <param1> = ‘2’ then ‘Ms’else if <param1> = ‘3’ then ‘Mrs’else if <param2> = 77 then ‘Dr’else if <Param2> = 78 then ‘Prof’

else ‘’ end if

• Could be aliased to:NumberToTitle(<param1>, <param2>)

Page 15: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-15

Properties of User Functions

• A user function always has:• A syntax: defines how the function is called by other objects

in ODI• Several implementations specific to different technologies• A scope

• Global functions can be used anywhere.• Project functions can be used within their project.

• User functions are organized into groups.

Page 16: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-16

How to Create a User Function

1. Select the Functions node in a project, or in the Others view

2. Right-click > Insert Function

3. Fill in the:• Name

• Syntax

• Description

4. Select the Group, or type in the name of a new group.

Page 17: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-17

Defining the Implementations

1. Select the Implementations tab

2. Click the Add button.3. Enter the code for the

implementation4. Select the applicable

technologies.

Page 18: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-18

Syntax of the Implementations

• The function's syntax and implementation arguments are specified in one of the following formats:• $(<arg_name>)• $(<arg_name>)<arg_type>

• If <arg_type> is supplied it must be s (string), n (numeric) or d (date).• For example: $(title)s

• Argument names in the syntax and implementation should match exactly.

• Examples:• Syntax:NullValue($(myvariable), $(mydefault))

• Implementation:case when $(myvariable) is null

then $(mydefault)else $(myvariable)

end

Page 19: 14-1 7 Oracle Data Integrator User Functions, Variables and Advanced Mappings

14-19

Using User Functions

• At design-time, you can refer to user functions like any regular database function

• You can use them in mappings, joins, filters, procedures, etc.

• They are available in the expression editor.

• When the code is generated:• Project functions are identified first, then global functions.

• If a function is recognized, it is turned into the implementation corresponding to the technology of the generated code.

• If the function is not recognized, the generated code remains unchanged.