B305 Fastexport

download B305 Fastexport

of 26

Transcript of B305 Fastexport

  • 7/30/2019 B305 Fastexport

    1/26

    Module 5: FastExport

    After completing this module, you will be able to:

    State FastExport capabilities.

    Describe how sorted output is produced from a multiple-session SELECT.

    Prepare a FastExport script.

  • 7/30/2019 B305 Fastexport

    2/26

    FastExport

    Exports large volumes of formatted data from Teradata to a host file oruser-written application.

    Takes advantage of multiple sessions.

    Export from multiple tables.

    Uses Support Environment.

    Fully automated restart.

    Uses one of the Loader slots.

    Teradata

    Database

    Host

    FastExport

  • 7/30/2019 B305 Fastexport

    3/26

    .BEGIN and .END EXPORT

    .BEGIN EXPORT

    SESSIONS max minTENACITY hours

    SLEEP minutes

    NOTIFY OFF | LOW | MEDIUM | HIGH ;

    SESSIONS

    Maximum, and optionally, minimum number of sessions the utility may use - defaults to 4 for UNIX

    FastExport. The utility will log on two addit ionalSQL sessions: one for the Restart Log and one for the

    SELECT.

    TENACITY

    Number of hours FastExport will try to establish a connection to the system; default is 4.

    SLEEP

    Number of minutes that FastExport will wait between logon attempts; default is 6.NOTIFY

    Parameter for specifying the notify user exit option

    The FastExport manual specifies in detail which events are associated with each level.

    .END EXPORT;

    Delimits a series of commands that define a single EXPORT action. Causes the utility to send the SELECT(s) to the Teradata Database.

  • 7/30/2019 B305 Fastexport

    4/26

    .EXPORT

    .EXPORT OUTFILE fileid [ AXSMOD name [ ' in i t -s t r ing '] ] [ OUTMOD module_name ]

    [ MODE RECORD | INDICATOR ]

    [ BLOCKSIZE integer ]

    [ FORMAT FASTLOAD | BINARY | TEXT | VARTEXT | UNFORMAT ]

    [ OUTLIMIT record_count ]

    [ MLSCRIPT fileid ] ;

    MODE If RECORD, then indicator bytes for NULLs are not included in exported

    data.

    If INDICATOR, then indicator bytes for NULLs are included in exported data.

    BLOCKSIZE Defines the maximum block size to be used in returning exported data.

    Default (and maximum) is 63.5 KB.

    FORMAT Record format of the export file on network-attached UNIX and Windows

    platforms.

    OUTLIMIT Defines the maximum number of records to be written to the output host

    file.

    MLSCRIPT FastExport generates a MultiLoad script that can be used later to load the

  • 7/30/2019 B305 Fastexport

    5/26

    A FastExport Script

    .LOGTABLE RestartLog1_fxp;

    .RUN FILE logon ;

    .SET CityName TO 'Los Angeles';

    .SET ZipCode TO 90666;

    .BEGIN EXPORT SESSIONS 4 ;

    .EXPORT OUTFILE custacct_data;

    SELECT A.Account_Number

    , C.Last_Name

    , C.First_Name

    , A.Balance_Current

    FROM Accounts A INNER JOIN

    Accounts_Customer AC INNER JOIN

    Customer CON C.Customer_Number = AC.Customer_Number

    ON A.Account_Number = AC.Account_Number

    WHERE A.City = '&CityName'

    AND A.Zip_Code = &ZipCode

    ORDER BY 1 ;

    .END EXPORT ;

    .LOGOFF ;

    Define Restart Log

    Specify number of sessions

    Destination file

    Send request.

    Terminate sessions

    Via a SELECT, specify the

    columns and rows to

    export.

  • 7/30/2019 B305 Fastexport

    6/26

    The SELECT Request

    Defines the data to be returned to the host, server, or client workstation.

    The job may consist of multiple SELECT statements which will be executed

    sequentially by FastExport.

    Applies normal transaction locks (READ lock) which are fully automatic.

    These locks are normally held by the utility until all response rows have

    been moved to AMP spool, and then are released.

    Supports the LOCKING FOR ACCESS modifier to request an access

    lock.

    Restrictions - you cannot use SELECT (in a FastExport job) with the

    following:

    Non-data tables (e.g. CURRENT_DATE, ...) Equality condition for a Primary Index or USI

    WITH option to generate total or subtotal response rows.

    The USING modifier to submit data parameters as a constraint to the

    SELECT.

  • 7/30/2019 B305 Fastexport

    7/26

    Impact of Requesting Sorted Output

    A special FastExport sort protocol is used to take advantage of multiplesessions. Each session transfers data a block at a time from multiple

    AMPs.

    This protocol includes the following steps:

    The SELECT request is fully processed in the normal way using

    DBC/SQL protocol.

    At this point, response data is maintained in spool, sorted locally by

    the AMPs.

    Two further distributions between the AMPs (using the BYNET) are

    required to complete the sort.

    Sort notes:

    Requesting sorted data adds additional work (overhead and time) to

    Teradata.

    If the exported rows are to be loaded back into a Teradata DB (e.g.,

    MultiLoad), there probably is no need to sort the exported rows.

  • 7/30/2019 B305 Fastexport

    8/26

    The SORT Procedure

    Response rows locally

    sorted in SPOOL:

    Horizontal Distribution:

    Vertical Distribution:

    ADAMS BATES BOYCE ADAMS

    BOYCE DAVIS CHARLES DAVISFIELD KIEL HERBERT GEORGE

    JONES NICHOLS POTTER HANCOCK

    SMITH PETERS HERBERT

    WILSON TIBBS MERCER

    TOMS

    BLOCK 1 BLOCK 2 BLOCK 3 BLOCK 4

    ADAMS BOYCE FIELD HERBERT

    ADAMS CHARLES GEORGE JONES

    BATES DAVIS HANCOCK KIEL

    BOYCE DAVIS HERBERT MERCER

    BLOCK 5 BLOCK 6

    NICHOLS TIBBS

    PETERS TOMS

    POTTER WILSONSMITH

    AMP 1 AMP 2 AMP 3 AMP 4

    ADAMS

    ADAMS BATES BOYCE CHARLESDAVIS BOYCE

    DAVIS FIELD GEORGE HANCOCK

    HERBERT

    HERBERT JONES KIEL MERCER

    NICHOLS PETERS POTTER SMITH

    TIBBS TOMS WILSON

  • 7/30/2019 B305 Fastexport

    9/26

    Multiple Exports in one FastExport Job

    .LOGTABLE RestartLog2_fxp;.LOGON . . . . . . . . ;

    .DISPLAY 'Exporting Cust_file - &SYSDATE4' TO FILE /dev/tty;

    .BEGIN EXPORT;

    .EXPORT OUTFILE Cust_file;

    SELECT * FROM Customer;

    .END EXPORT;

    .DISPLAY 'Exporting Trans_file - &SYSDATE4' TO FILE /dev/tty;

    .BEGIN EXPORT;

    .EXPORT OUTFILE Trans_file;

    SELECT * FROM Transactions;

    .END EXPORT;

    .LOGOFF ;

    cust_trans.fxp

    To execute: fexp < cust_trans.fxp > cust_trans.out

    Exported data file: Cust_file Output to screen: Exporting Cust_file - 2003/02/28

    Exported data file: Trans_file Output to screen: Exporting Trans_file - 2003/02/28

  • 7/30/2019 B305 Fastexport

    10/26

    Invoking FastExport

    Network Attached Systems: fexp [PARAMETERS] < scr ip tname >outf i lename

    Channel-Attached MVS Systems: // EXEC TDSFEXP FEXPPARM= [PARAMETERS]

    Channel-Attached VM Systems: EXEC FASTEXPT [PARAMETERS]

    Channel Network DescriptionParameter Parameter

    BRIEF -b Reduces print output runtime to the least informationrequired to determine success or failure.

    CHARSET=charsetname -c charsetname Specify a character set or its code. Examples are EBCDIC,ASCII, or Kanji sets.

    ERRLOG=f i lename -e f i lename Alternate file specification for error messages; produces aduplicate record.

    "fastexpor t command" -r 'fastexport cmd ' Signifies the start of a FastExport job; usually a RUN FILEcommand that specifies the script file.

    MAXSESS=max sess ions -M max sessions Maximum number of FastExport sessions logged on.

    MINSESS=min sess ions -N min sessions Minimum number of FastExport sessions logged on.

    < scr ip tname Name of file that contains FastExport commands and SQLstatements.

    > outf i lename Name of output file for FastExport messages.

  • 7/30/2019 B305 Fastexport

    11/26

    FastExport and Variable Input

    Selection Controls

    There are two techniques that can be used to provide variable input to

    FastExport.

    ACCEPT from a parameter file; only accept from a single record.

    IMPORT from a data file; each import record is applied to every SELECT.

    Read input variables from a host input data file described by the .LAYOUT

    command.

    Apply eachinput variable value to everySELECT in the exact order listed in

    the FastExport script before reading the next.

    Defines a host file as the source of the data values required for the SELECT

    REQUEST.

    Permits the use of a user-written INMOD routine to (optionally) read and

    (always) process the input record before passing it to the utility.

  • 7/30/2019 B305 Fastexport

    12/26

    A FastExport Script with ACCEPT

    .LOGTABLE RestartLog1_fxp;

    .RUN FILE logon ;

    .ACCEPT par_City, par_Zip FROM FILE parmfile1;

    .BEGIN EXPORT SESSIONS 4 ;

    .EXPORT OUTFILE custacct_data;

    SELECT A.Account_Number

    , C.Last_Name

    , C.First_Name

    , A.Balance_Current

    FROM Accounts A INNER JOIN

    Accounts_Customer AC INNER JOIN

    Customer CON C.Customer_Number = AC.Customer_Number

    ON A.Account_Number = AC.Account_Number

    WHERE A.City = '&par_City'

    AND A.Zip_Code = &par_Zip

    ORDER BY 1 ;

    .END EXPORT ;

    .LOGOFF ;

    'Los Angeles' 90066parmfile1

    ACCEPT variables from input

    record.

    Reference accepted variables

    with an &.

    par_City par_Zip

  • 7/30/2019 B305 Fastexport

    13/26

    A FastExport Script with LAYOUT

    .LOGTABLE RestartLog1_fxp;

    .RUN FILE logon ;

    .BEGIN EXPORT SESSIONS 4 ;

    .LAYOUT Record_Layout ;

    .FIELD in_City 1 CHAR(20) ;

    .FIELD in_Zip * CHAR(5);

    .IMPORT INFILE city_zip_infile LAYOUT Record_Layout ;

    .EXPORT OUTFILE cust_acct_outfile2 ;

    SELECT A.Account_Number

    , C.Last_Name

    , C.First_Name

    , A.Balance_Current

    FROM Accounts A INNER JOIN

    Accounts_Customer AC INNER JOIN

    Customer CON C.Customer_Number = AC.Customer_Number

    ON A.Account_Number = AC.Account_Number

    WHERE A.City = :in_City

    AND A.Zip_Code = :in_Zip

    ORDER BY 1 ;

    .END EXPORT ;

    .LOGOFF ;

    Los Angeles 90066San Diego 90217

    city_zip_infile

    IMPORT fields from input

    records.

    Reference imported fields with

    a :

    in_City in_Zip

  • 7/30/2019 B305 Fastexport

    14/26

    .LAYOUT, .FIELD and .FILLER

    .LAYOUT

    Describes the layout of externally storedrecords used to supply values for SELECT.

    Followed by .FIELD and .FILLER

    commands.

    .FIELD fieldname { startpos datadesc } || fieldexp [ NULLIF nullexpr ]

    [ DROP {LEADING / TRAILING } { BLANKS / NULLS }[ [ AND ] {TRAILING / LEADING } { NULLS / BLANKS } ] ] ;

    .FILLER [ fieldname ] startpos datadesc ;

    .FIELD

    Input fields supporting redefinition and concatenation.

    Startpos identifies the start of a field relative to 1.

    Fieldexpr specifies a concatenation of fields in the format: fn1 || fn2 [ || fn3 ]

    The optionDROP LEADING / TRAILING BLANKS / NULLS is applicable only to

    character datatypes, and is sent as a VARCHAR with a 2-byte length field.

    .FILLER

    Identifies data NOT to be sent to the Teradata database.

    .LAYOUT layoutname

    CONTINUEIF position = variable ;INDICATORS

  • 7/30/2019 B305 Fastexport

    15/26

    INMODs and OUTMODs

    READ

    FASTEXPORT

    CALL

    SELECT

    OUTPUT

    DATA

    INMOD

    OUTMOD

    CALL

    WRITE

    INPUT

    DATA

    INMODs

    Read input data values from a file.

    Qualify SELECT requests.

    Usually more applicable to an import utility such as MultiLoad.

    OUTMODs

    Process answer-set data.

    Modify, discard, or record responses.

    Usually more applicable to an export utility such as FastExport.

  • 7/30/2019 B305 Fastexport

    16/26

    OUTMOD Return Codes

    1 Initial Entry Specifies the initial entry call that the FastExport utility makes before sending thefirst SELECT statement to the Teradata RDBMS.

    There is only one initial entry call for a FastExport job. If the utility is in a restart mode, the utility

    uses an entry code value of 5 or 6 to specify the first call after a Teradata RDBMS or client

    system restart.

    2 End of Response Entry Specifies the end of response call that the Fast Export utility makes

    after receiving the last row of export data from the Teradata RDBMS.

    3 Response Row Entry Specifies a response row call that the FastExport utility makes for each

    row of export data from the Teradata RDBMS.

    4 Checkpoint Entry Specifies a checkpoint call that the FastExport utility makes after

    processing the last response row for each SELECT statement.

    This call signifies that the OUTMOD routine should capture checkpoint data to support a restart

    operation if the Teradata RDBMS or client system fails.

    5 Teradata RDBMS Restart Entry Specifies the first call that resumes processing after a

    Teradata RDBMS restart.

    6 Client Restart Entry Specifies the first call that resumes processing after a client system

    restart.

    FastExport OUTMOD Return Codes

  • 7/30/2019 B305 Fastexport

    17/26

    Application Utility Checklist

    Feature BTEQ FastLoad FastExport MultiLoad TPump

    DDL Functions ALL LIMITED No

    DML Functions ALL INSERT SELECT

    Multiple DML Yes No Yes

    Multiple Tables Yes No Yes

    Multiple Sessions Yes Yes Yes

    Protocol Used SQL FASTLOAD EXPORT

    Conditional Expressions Yes No Yes

    Arithmetic Calculations Yes No YesData Conversion Yes 1percolumn Yes

    Error Files No Yes No

    Error Limits No Yes No

    User-written Routines No Yes Yes

  • 7/30/2019 B305 Fastexport

    18/26

    Summary

    Best choice for exporting large amounts of data from the Teradata database

    to a host file using multiple sessions.

    Fully automatic restart capability.

    Specialized processing of output data can be handled using an OUTMOD

    routine.

    Teradata accommodates not more than 15 LOAD applications at any onetime (FastLoad, MultiLoad, FastExport).

  • 7/30/2019 B305 Fastexport

    19/26

    Review Questions

    Answer True or False.

    1. True or False. FastExport requires the use of a PI or USI in the SELECTs.

    2. True or False. The number of FastExport sessions (for a UNIX server) defaults to the number of

    AMPs.

    3. True or False. The maximum block size you can specify is 32K.

    4. True or False. You can export from multiple tables with FastExport.

    5. True or False. You can use multiple SELECTs in one FastExport job.

    6. True or False. The default lock for a SELECT in a FastExport job is a table level ACCESS lock.

  • 7/30/2019 B305 Fastexport

    20/26

    Module 5: Review Question Answers

    Answer True or False.

    1. True orFalse. FastExport requires the use of a PI or USI in the SELECTs.

    2. True orFalse. The number of FastExport sessions (for a UNIX server) defaults to the number of

    AMPs. (The UNIX default is 4 sess ion s.)

    3. True orFalse. The maximum block size you can specify is 32K. (It is 64 KB.)

    4. Trueor False. You can export from multiple tables with FastExport.

    5. Trueor False. You can use multiple SELECTs in one FastExport job.

    6. True orFalse. The default lock for a SELECT in a FastExport job is a table level ACCESS lock.

  • 7/30/2019 B305 Fastexport

    21/26

    Lab Exercises

    Lab Exercise 5-1

    Purpose

    In this lab, you will use FastExport to create an export file that contains one record for each

    transaction. You will have to join columns from two different tables in order to create the export file.

    What you need

    Populated AU.Accounts and AU.Trans tables.

    Tasks

    1. Create a FastExport script that outputs to file data5_1. For each transaction in the AU.Trans table,

    include the transaction_number, account_number, number, street, city, state and zip of the associated

    account (AU.Accounts).

    2. Run the script.

    3. Test the result by using the UNIX ls -l command.

  • 7/30/2019 B305 Fastexport

    22/26

    Lab Exercises

    Lab Exercise 5-2Purpose

    In this lab, you will use FastExport to read input data from a data set / file or accepting input values as

    a parameter, and export a report to another data set / file. In order to produce readable output, all

    selected data should be converted to FIXED CHARACTER as outlined below:

    What you need

    Populated AU.Accounts table.

    Tasks

    This exercise involves the FastExport of 'EXCEPTION' data, a list of Accounts which either fall below aminimum Balance_Current or exceed a maximum value and are from the cities in the input data set.

    The output file (report) mode should be RECORD and format should be TEXT.

    1. Create an input file named data5_2 with 1 line of input: 'Los Angeles'

    2. Prepare a FastExport script which does the following:

    a. Treats this as a parameter file and ACCEPT from it. Treat this data as variable input for the

    SELECT.

    b. Uses the .SET command to initialize two variables: LoVal 500 and HiVal 9499

    c. Includes a SELECT statement that projects ACCOUNT NUMBER, CITY, BALANCE CURRENT, and

    a character string of either BELOW MIN or ABOVE MAX and sorts by Account_Number. Simply

    display 'BELOW MIN' or 'ABOVE MAX' as a literal with the SELECT. Use CHAR to convert the

    Account_Number from INTEGER to CHAR data.

    d. Creates an output file named report5_2. Note: MODE RECORD and FORMAT TEXT3. Run the test and view the result using the UNIX morecommand.

  • 7/30/2019 B305 Fastexport

    23/26

    Lab Solutions for Lab 5-1

    Lab Exercise 5-1

    cat lab512.fxp

    .LOGTABLE Restartlog512_fxp ;

    .LOGON u4455/tljc30,tljc30 ;

    .BEGIN EXPORT;

    .EXPORT OUTFILE data5_1;

    SELECT T.trans_number

    ,A.account_number

    ,A.number,A.street

    ,A.city

    ,A.state

    ,A.zip_code

    FROM AU.Accounts A

    INNER JOIN AU.Trans T

    ON A.Account_number = T.Account_number;

    .END EXPORT;

    .LOGOFF;fexp < lab512.fxp

    (alternative join syntax))

    cat lab512a.fxp.LOGTABLE Restartlog512a_fxp ;

    .LOGON u4455/tljc30,tljc30 ;

    .BEGIN EXPORT;

    .EXPORT OUTFILE data5_1;

    SELECT T.trans_number

    ,A.account_number

    ,A.number,A.street

    ,A.city

    ,A.state

    ,A.zip_code

    FROM AU.Accounts A

    , AU.Trans T

    WHERE A.Account_number = T.Account_number ;

    .END EXPORT;

    .LOGOFF;

    fexp < lab512a.fxp

  • 7/30/2019 B305 Fastexport

    24/26

    Lab Solutions for Lab 5-2 (ACCEPT and CASE)

    cat lab522a.fxp

    .LOGTABLE Restartlog522a_fxp;

    .LOGON u4455/tljc30,tljc30;

    .SET LoVal TO 500;

    .SET HiVal TO 9499;

    .ACCEPT par_city FROM FILE data5_2;

    .BEGIN EXPORT;

    .EXPORT OUTFILE report522_a MODE RECORD FORMAT TEXT;

    SELECT Account_Number (CHAR(10)),

    City,

    Balance_Current (CHAR(12)),

    (CASE WHEN Balance_Current < &LoVal THEN 'Below MIN'

    WHEN Balance_Current > &HiVal THEN 'Above MAX'

    END)

    FROM AU.Accounts

    WHERE City = '&par_city'AND (Balance_Current < &LoVal OR

    Balance_Current > &HiVal)

    ORDER BY Account_Number ;

    .END EXPORT;

    .LOGOFF;

    fexp < lab522a.fxp

  • 7/30/2019 B305 Fastexport

    25/26

    Lab Solutions for Lab 5-2 (ACCEPT and UNION)

    cat lab522b.fxp

    .LOGTABLE Restartlog522b_fxp;

    .LOGON u4455/tljc30,tljc30;

    .SET LoVal TO 500;

    .SET HiVal TO 9499;

    .ACCEPT par_city FROM FILE data5_2;

    .BEGIN EXPORT;

    .EXPORT OUTFILE report522_b MODE RECORD FORMAT TEXT;

    SELECT Account_Number (CHAR(10)), City, Balance_Current (CHAR(12)),'Above MAX'

    FROM AU.Accounts

    WHERE City = '&par_city'

    AND Balance_Current > &HiVal

    UNION

    SELECT Account_Number (CHAR(10)), City, Balance_Current (CHAR(12)),

    'Below MIN'

    FROM AU.Accounts

    WHERE City = '&par_city'

    AND Balance_Current < &LoVal

    ORDER BY 1;

    .END EXPORT;

    .LOGOFF;

    fexp < lab522b.fxp

  • 7/30/2019 B305 Fastexport

    26/26

    Lab Solutions for Lab 5-2 (.IMPORT)

    cat lab522c.fxp

    .LOGTABLE Restartlog522c_fxp;

    .LOGON u4455/tljc30,tljc30;

    .SET LoVal TO 500;

    .SET HiVal TO 9499;

    .BEGIN EXPORT;

    .LAYOUT Record_Layout;

    .FIELD in_city * CHAR(15);

    .IMPORT INFILE data5_2c FORMAT TEXT LAYOUT Record_Layout ;

    .EXPORT OUTFILE report522_c MODE RECORD FORMAT TEXT;

    SELECT Account_Number (CHAR(10)),

    City,

    Balance_Current (CHAR(12)),

    (CASE WHEN Balance_Current < &LoVal THEN 'Below MIN'

    WHEN Balance_Current > &HiVal THEN 'Above MAX'END)

    FROM AU.Accounts

    WHERE City = :par_city

    AND (Balance_Current < &LoVal OR Balance_Current > &HiVal)

    ORDER BY Account_Number ;

    .END EXPORT;

    .LOGOFF;

    f l b522 f