You are on page 1of 26

Module 5: FastExport

After completing this module, you will be able to: State FastExport capabilities. Describe how sorted output is produced from a multiplesession SELECT. Prepare a FastExport script.

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

Takes advantage of multiple sessions.


Export from multiple tables. Uses Support Environment. Fully automated restart.

Uses one of the Loader slots.

FastExport

Teradata Database

Host

.BEGIN and .END EXPORT


.BEGIN EXPORT SESSIONS TENACITY SLEEP NOTIFY SESSIONS max min hours minutes OFF | LOW | MEDIUM | HIGH ;

Maximum, and optionally, minimum number of sessions the utility may use - defaults to 4 for UNIX
FastExport. The utility will log on two additional SQL 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.

.EXPORT
.EXPORT [ MODE [ FORMAT [ OUTLIMIT OUTFILE fileid [ AXSMOD name [ 'init-string'] ] [ OUTMOD module_name ] RECORD | INDICATOR ] FASTLOAD | BINARY | TEXT | VARTEXT | UNFORMAT ] record_count ]

[ BLOCKSIZE integer ]

[ MLSCRIPT
MODE

fileid ] ;

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. Defines the maximum number of records to be written to the output host file. FastExport generates a MultiLoad script that can be used later to load the

OUTLIMIT

MLSCRIPT

A FastExport Script
Define Restart Log .LOGTABLE RestartLog1_fxp; .RUN .SET .SET Specify number of sessions Destination file Via a SELECT, specify the columns and rows to export. .BEGIN .EXPORT SELECT FILE logon ; CityName TO 'Los Angeles'; ZipCode TO 90666; EXPORT SESSIONS 4 ; OUTFILE custacct_data;

A.Account_Number , C.Last_Name , C.First_Name , A.Balance_Current FROM Accounts A INNER JOIN Accounts_Customer AC INNER JOIN Customer C ON 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 ;

Send request. Terminate sessions

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.

Impact of Requesting Sorted Output


A special FastExport sort protocol is used to take advantage of multiple sessions. 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.

The SORT Procedure


Response rows locally sorted in SPOOL:
AMP 1
ADAMS BOYCE FIELD JONES SMITH WILSON

AMP 2
BATES DAVIS KIEL NICHOLS PETERS TIBBS TOMS

AMP 3
BOYCE CHARLES HERBERT POTTER

AMP 4
ADAMS DAVIS GEORGE HANCOCK HERBERT MERCER

Vertical Distribution:

ADAMS ADAMS DAVIS DAVIS HERBERT HERBERT NICHOLS TIBBS BLOCK 1 ADAMS ADAMS BATES BOYCE BLOCK 5 NICHOLS PETERS POTTER SMITH

BATES FIELD JONES PETERS TOMS BLOCK 2 BOYCE CHARLES DAVIS DAVIS BLOCK 6 TIBBS TOMS WILSON

BOYCE BOYCE GEORGE KIEL POTTER WILSON BLOCK 3 FIELD GEORGE HANCOCK HERBERT

CHARLES HANCOCK MERCER SMITH

Horizontal Distribution:

BLOCK 4 HERBERT JONES KIEL MERCER

Multiple Exports in one FastExport Job


cust_trans.fxp .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 ; 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

Invoking FastExport
Network Attached Systems: Channel-Attached MVS Systems: Channel-Attached VM Systems:
Channel Parameter BRIEF Network Parameter -b

fexp [PARAMETERS] < scriptname >outfilename // EXEC TDSFEXP FEXPPARM= [PARAMETERS] EXEC FASTEXPT [PARAMETERS]
Description
Reduces print output runtime to the least information required to determine success or failure. Specify a character set or its code. Examples are EBCDIC, ASCII, or Kanji sets. Alternate file specification for error messages; produces a duplicate record. Signifies the start of a FastExport job; usually a RUN FILE command that specifies the script file. Maximum number of FastExport sessions logged on. Minimum number of FastExport sessions logged on. Name of file that contains FastExport commands and SQL statements. Name of output file for FastExport messages.

CHARSET=charsetname -c charsetname ERRLOG=filename "fastexport command" MAXSESS=max sessions MINSESS=min sessions < scriptname > outfilename -e filename -r 'fastexport cmd' -M max sessions -N min sessions

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 each input variable value to every SELECT 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.

A FastExport Script with ACCEPT


parmfile1
'Los Angeles' 90066

par_City

par_Zip

.LOGTABLE RestartLog1_fxp; .RUN FILE logon ; par_City, par_Zip FROM FILE parmfile1; EXPORT SESSIONS 4 ;

ACCEPT variables from input record.

.ACCEPT .BEGIN

.EXPORT
SELECT

OUTFILE custacct_data;

Reference accepted variables with an &.

A.Account_Number , C.Last_Name , C.First_Name , A.Balance_Current FROM Accounts A INNER JOIN Accounts_Customer AC INNER JOIN Customer C ON 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 ;

A FastExport Script with LAYOUT


city_zip_infile
Los Angeles San Diego 90066 90217 .LOGTABLE RestartLog1_fxp; .RUN .BEGIN FILE logon ; EXPORT SESSIONS 4 ;

in_City

in_Zip

.LAYOUT .FIELD .FIELD


.IMPORT .EXPORT SELECT

Record_Layout ; in_City in_Zip

1 CHAR(20) ; * CHAR(5);

IMPORT fields from input records.

INFILE city_zip_infile LAYOUT Record_Layout ;

Reference imported fields with a:

OUTFILE cust_acct_outfile2 ; A.Account_Number , C.Last_Name , C.First_Name , A.Balance_Current FROM Accounts A INNER JOIN Accounts_Customer AC INNER JOIN Customer C ON 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 ;

.LAYOUT, .FIELD and .FILLER


.LAYOUT layoutname CONTINUEIF position = variable INDICATORS ;

.LAYOUT Describes the layout of externally stored records 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 Fieldexpr identifies the start of a field relative to 1. specifies a concatenation of fields in the format: fn1 || fn2 [ || fn3 ]

The option DROP 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.

INMODs and OUTMODs


CALL READ

FASTEXPORT
SELECT CALL

INMOD

INPUT DATA

WRITE

OUTMOD

OUTPUT 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.

OUTMOD Return Codes


FastExport OUTMOD Return Codes 1 Initial Entry Specifies the initial entry call that the FastExport utility makes before sending the first 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. Response Row Entry Specifies a response row call that the FastExport utility makes for each row of export data from the Teradata RDBMS. 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. Client Restart Entry Specifies the first call that resumes processing after a client system restart.

Application Utility Checklist


Feature BTEQ FastLoad FastExport MultiLoad TPump

DDL Functions
DML Functions Multiple DML Multiple Tables Multiple Sessions Protocol Used Conditional Expressions Arithmetic Calculations

ALL
ALL Yes Yes Yes SQL Yes Yes

LIMITED
INSERT No No Yes
FASTLOAD

No
SELECT Yes Yes Yes EXPORT Yes Yes

No No

Data Conversion
Error Files Error Limits User-written Routines

Yes
No No No

1 per column
Yes Yes Yes

Yes
No No Yes

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 one


time (FastLoad, MultiLoad, FastExport).

Review Questions
Answer True or False. 1. True or False. 2. True or False. FastExport requires the use of a PI or USI in the SELECTs. The number of FastExport sessions (for a UNIX server) defaults to the number of AMPs. The maximum block size you can specify is 32K. You can export from multiple tables with FastExport. You can use multiple SELECTs in one FastExport job. The default lock for a SELECT in a FastExport job is a table level ACCESS lock.

3. True or False. 4. True or False. 5. True or False. 6. True or False.

Module 5: Review Question Answers


Answer True or False. 1. True or False. 2. True or False. FastExport requires the use of a PI or USI in the SELECTs. The number of FastExport sessions (for a UNIX server) defaults to the number of AMPs. (The UNIX default is 4 sessions.) The maximum block size you can specify is 32K. (It is 64 KB.) You can export from multiple tables with FastExport. You can use multiple SELECTs in one FastExport job. The default lock for a SELECT in a FastExport job is a table level ACCESS lock.

3. True or False. 4. True or False. 5. True or False. 6. True or False.

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.

Lab Exercises
Lab Exercise 5-2
Purpose 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 a minimum 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 TEXT 3. Run the test and view the result using the UNIX more command.

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;

(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 < lab512.fxp

fexp < lab512a.fxp

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; Account_Number (CHAR(10)), City, Balance_Current (CHAR(12)), (CASE WHEN Balance_Current < &LoVal WHEN Balance_Current > &HiVal 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 SELECT

THEN 'Below MIN' THEN 'Above MAX'

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

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 .FIELD .IMPORT Record_Layout; in_city * CHAR(15); 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) AU.Accounts City = :par_city (Balance_Current < &LoVal OR Balance_Current > &HiVal) Account_Number ;

FROM WHERE AND ORDER BY .END EXPORT; .LOGOFF; fexp < lab522c.fxp

You might also like