B305 Fastexport
B305 Fastexport
B305 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.
FastExport
Teradata Database
Host
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 ;
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.
Restrictions - you cannot use SELECT (in a FastExport job) with the
following:
Two further distributions between the AMPs (using the BYNET) are
required to complete the sort.
Sort notes:
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
Horizontal Distribution:
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
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.
par_City
par_Zip
.LOGTABLE RestartLog1_fxp; .RUN FILE logon ; par_City, par_Zip FROM FILE parmfile1; EXPORT SESSIONS 4 ;
.ACCEPT .BEGIN
.EXPORT
SELECT
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 = '&par_City' AND A.Zip_Code = &par_Zip ORDER BY 1 ; .END EXPORT ; .LOGOFF ;
in_City
in_Zip
1 CHAR(20) ; * CHAR(5);
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 Describes the layout of externally stored records used to supply values for SELECT. Followed by .FIELD and .FILLER commands.
[ NULLIF nullexpr ] [ DROP {LEADING / TRAILING } { BLANKS / NULLS } [ [ AND ] {TRAILING / LEADING } { NULLS / BLANKS } ] ] ;
.FIELD
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
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.
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.
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.
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.
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.
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:
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.
.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