Top Banner

of 51

Routines Advance 3

Apr 09, 2018

Download

Documents

sam2sung2
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/8/2019 Routines Advance 3

    1/51

    1

    Routines(Transform Functions)

    DataStage

  • 8/8/2019 Routines Advance 3

    2/51

    2

    The Process

    Identify Need

    does something already exist?

    Specification business rules

    Design

    algorithm selection

    name of function (must be unique in project)

  • 8/8/2019 Routines Advance 3

    3/51

    3

    Example 1

    Identify need

    need to encode weekdays as TinyInt

    DayofWeek function exists in Dev category

    StringDecode function exists in SDK\String

    need high performance (rapid return)

  • 8/8/2019 Routines Advance 3

    4/51

    4

    Example 1

    Specification

    week begins on Sunday, which is day 1

    week ends on Saturday, which is day 7

    invalid input (not day name) returns zero

    input is not case sensitive

  • 8/8/2019 Routines Advance 3

    5/51

    5

    Example 1

    Design

    existing DayofWeek function is case sensitive(so does not suit requirement)

    however this routine may be able to subsumefunctionality of DayofWeek (and thereforereplace it)

    StringDecode requires passing searchablestructure every row; cumbersome (slow?)

  • 8/8/2019 Routines Advance 3

    6/51

    6

    DayofWeekAns =0

    InputArg = TrimB(InputArg)Begin Case

    Case InputArg = "MONDAY"

    Ans= 2

    Case InputArg = "TUESDAY"

    Ans= 3

    Case InputArg = "WEDNESDAY"Ans= 4

    Case InputArg = "THURSDAY"

    Ans= 5

    Case InputArg = "FRIDAY"

    Ans= 6

    Case InputArg = "SATURDAY"Ans= 7

    Case InputArg = "SUNDAY"

    Ans= 1

    Case @True ;* all other values

    Ans = -1

    End CaseRETURN(Ans)

  • 8/8/2019 Routines Advance 3

    7/51

    7

    StringDecode

  • 8/8/2019 Routines Advance 3

    8/51

    8

    Example 1

    Design possible algorithms

    Iconv(DayName, "DWA")

    does this work? how to test?

    StringDecode function (SDK\String)

    Case construct (as in DayofWeek)

    positional field search (as in StringDecode)

    positional field search using static variables

  • 8/8/2019 Routines Advance 3

    9/51

    9

    Algorithm Selection

    Document pro's and con's

    Document decision

  • 8/8/2019 Routines Advance 3

    10/51

    10

    Example 1

    Algorithm Pro Con

    Iconv(x, "DWA") Doesn't work

    StringDecode Exists, works Slow

    DayofWeek Exists, works Case sensitive

    Case Works Slow

    Field search Works Already exists

    Field search static Fast

  • 8/8/2019 Routines Advance 3

    11/51

    11

    Creating Transform Functions

    DataStage

  • 8/8/2019 Routines Advance 3

    12/51

    12

    Creating Transform Function

    Select Routinesbranch

    New server routine

    Ensure routine typeis "TransformFunction"

  • 8/8/2019 Routines Advance 3

    13/51

    13

    General tab

    Name

    meaningful

    Category

    standards? Short desc

    helps futureselection

    Long desc

    purpose,business rules,special conditions

  • 8/8/2019 Routines Advance 3

    14/51

    14

    Creator tab

    Why?

    so they knowwho to ask

    Update at eachmodification

    Version 2.0.0

    may bechanged by

    developer,Version Control

  • 8/8/2019 Routines Advance 3

    15/51

    15

    Arguments tab

    Argumentname

    standards?

    meaningful

    Description

    assists

    future usersof Routine

  • 8/8/2019 Routines Advance 3

    16/51

    16

    Code tab

    We will returnto the code tabshortly

  • 8/8/2019 Routines Advance 3

    17/51

    17

    Dependencies tab

    If Routine callsother Routines,record the others

    here checklist for

    deployment

  • 8/8/2019 Routines Advance 3

    18/51

    18

    Code tab

    Function declaration filled in with arguments

    RETURN(Ans) function filled in

    your code must assign a value to Ans variable

    History block

  • 8/8/2019 Routines Advance 3

    19/51

    19

    Code tab

  • 8/8/2019 Routines Advance 3

    20/51

    2

    0

    Some Rules

    Function must return to caller

    proper operation of DataStage depends on it

    you must not use any of the followingstatements

    DSLogFatal Chain

    Stop Debug

    Abort

  • 8/8/2019 Routines Advance 3

    21/51

    2

    1

    Example (continued)

    Documentreason forunusual

    techniques Format

    source code

  • 8/8/2019 Routines Advance 3

    22/51

    22

    Example (continued)

    Documentreason forunusual

    techniques Save button

    enabled

  • 8/8/2019 Routines Advance 3

    23/51

    23

    Example (continued)

    Save sourcecode

    Compile

    buttonenabled

  • 8/8/2019 Routines Advance 3

    24/51

    24

    Example (continued)

    Compilesourcecode

  • 8/8/2019 Routines Advance 3

    25/51

    25

    Example (continued)

    Resultdisplayed

    correcterrors

    Testenabled

  • 8/8/2019 Routines Advance 3

    26/51

    26

    Exercise

    Let's Do One Together

  • 8/8/2019 Routines Advance 3

    27/51

    27

    Need: Determine Week Number

    Business Rules

    expected input (date?) (exceptions?)

    expected output (WEEK.TAG?)

    definition of week number 1 in year

  • 8/8/2019 Routines Advance 3

    28/51

    28

    Specification

    Business rules

    Week begins on Sunday

    Week number 1 begins on first Sunday inJanuary

    Expected input is internal format date

    return "" otherwise, or NULL if input NULL

    Expected output is WEEK.TAG see Data Element for definition (yyyyWnn)

  • 8/8/2019 Routines Advance 3

    29/51

    29

    Thought Process

    What is week number today?

    How did you calculate it?

    Inspect calendar for January

    identify week number 1

    Document "business rule"

    Get Business Analyst to verify

    if appropriate

  • 8/8/2019 Routines Advance 3

    30/51

    30

    Sample Rules

    Business rules

    Week begins on Sunday

    Week number 1 begins on first Sunday inJanuary

  • 8/8/2019 Routines Advance 3

    31/51

    31

    Algorithm Development

    Algorithm

    (FirstSundayYear)-(SundayThisWeek)

    ((FirstSundayYear)-(SundayThisWeek)) / 7

    Int(((FirstSundayYear)-(SundayThisWeek)) / 7)

    Int(((FirstSundayYear)-(SundayThisWeek)) / 7)

    + 1

    Adjust for days earlier then (FirstSundayYear),which will be in week 53 of prior year.

    days

    weeks

    integer

    week#

  • 8/8/2019 Routines Advance 3

    32/51

    32

    Algorithm Development

    How to calculate Sunday of this week?

    internal format dates, Mod(Sunday,7) = 0

    therefore TheDate Mod(TheDate,7)

    How to calculate first Sunday in year?

    Iconv(01/01/yyyy, "D") + N

  • 8/8/2019 Routines Advance 3

    33/51

    33

    Demonstration

    DataStage Manager

  • 8/8/2019 Routines Advance 3

    34/51

    34

    Creating New Routine

    Tip: Start indesiredcategory;category filledin for you

  • 8/8/2019 Routines Advance 3

    35/51

    35

    New Routine Created

    Ensure that routinetype is TransformFunction

  • 8/8/2019 Routines Advance 3

    36/51

    36

    General Tab

    Meaningful name

    Short description

    Long description

    Anotherdeveloper could take over now; your intentions are clear.

  • 8/8/2019 Routines Advance 3

    37/51

    37

    Creator Tab

    Author keptupdated

    Future developer

    knows where toseek advice

  • 8/8/2019 Routines Advance 3

    38/51

    38

    Arguments Tab

    Meaningful name

    Description can bemulti-line

    Ctrl Enter forline break

  • 8/8/2019 Routines Advance 3

    39/51

    39

    Code Tab (1)

    History block

    Commentsshowing purpose,

    etc.

  • 8/8/2019 Routines Advance 3

    40/51

    40

    Code Tab (2)

    Initialize Ansvariable

    Handle abnormal

    input could test at thispoint

  • 8/8/2019 Routines Advance 3

    41/51

    41

    Code Tab (3)

    Documentreason forchoosingunusualalgorithm

  • 8/8/2019 Routines Advance 3

    42/51

    42

    Code Tab (4)

    Outline algorithmusing commentsonly

  • 8/8/2019 Routines Advance 3

    43/51

    43

    Code Tab (5)

    Developalgorithm usingDataStageBASICstatements

  • 8/8/2019 Routines Advance 3

    44/51

    44

    Save and Compile

    Go backand fix anyerrors, save

    andcompileagain

  • 8/8/2019 Routines Advance 3

    45/51

    45

    Testing

    Test Grid

  • 8/8/2019 Routines Advance 3

    46/51

    46

    Test Using Test Grid

    Generate testvalues to testnormal andabnormal

    conditions

  • 8/8/2019 Routines Advance 3

    47/51

  • 8/8/2019 Routines Advance 3

    48/51

    48

    Debugging Statements

    Surround with$IFDEF and$ENDIF

    Use$DEFINE

  • 8/8/2019 Routines Advance 3

    49/51

    49

    Debugging Statements

    Enable using$DEFINE

    Save,compile, andtest

  • 8/8/2019 Routines Advance 3

    50/51

    50

    Debugging Statements

    Enableusing$DEFINE

    Save,compile, andtest

    Double-click

    Results

  • 8/8/2019 Routines Advance 3

    51/51

    51

    Ready for Production

    Disable testingstatements using$UNDEFINE

    Save, compile

    controlledstatementsnot compiled