Teradata Utilities FastExport
Teradata Utilities FastExport
Reprinted for KV Satish Kumar, IBM [email protected] Reprinted with permission as a subscription benefit of Books24x7, http://www.books24x7.com/
Table of Contents
Chapter 6: FastExport.....................................................................................................................1 Why it is Called "FAST" Export..............................................................................................1 How FastExport Works....................................................................................................1 FastExport Fundamentals......................................................................................................2 FastExport Supported Operating Systems .......................................................................2 Maximum of 15 Loads ............................................................................................................3 FastExport Support and Task Commands.............................................................................3 Support Environment Commands..........................................................................................3 Task Commands....................................................................................................................4 FastExport Supported SQL Commands................................................................................5 SQL Commands ...............................................................................................................5 A FastExport in its Simplest Form ..........................................................................................5 Sample FastExport Script......................................................................................................6 FastExport Modes and Formats .............................................................................................7 Modes..............................................................................................................................7 Formats............................................................................................................................8 A FastExport Script using Binary Mode.................................................................................8
Chapter 6: FastExport
"An invasion of armies can be resisted, but not an idea whose time has come." - Victor Hugo
Teradata Utilities: BTEQ, FastLoad, MultiLoad, TPump, and FastExport, Second Edition
FastExport Fundamentals
#1: FastExport EXPORTS data from Teradata. The reason they call it FastExport is because it takes data off of Teradata (Exports Data). FastExport does not import data into Teradata. Additionally, like BTEQ it can output multiple files in a single run. #2: FastExport only supports the SELECT statement. The only DML statement that FastExport understands is SELECT. You SELECT the data you want exported and FastExport will take care of the rest. #3: Choose FastExport over BTEQ when Exporting Data of more than half a million+ rows. When a large amount of data is being exported, FastExport is recommended over BTEQ Export. The only drawback is the total number of FastLoads, FastExports, and MultiLoads that can run at the same time, which is limited to 15. BTEQ Export does not have this restriction. Of course, FastExport will work with less data, but the speed may not be much faster than BTEQ. #4: FastExport supports multiple SELECT statements and multiple tables in a single run. You can have multiple SELECT statements with FastExport and each SELECT can join information up to 64 tables. #5: FastExport supports conditional logic, conditional expressions, arithmetic calculations, and data conversions. FastExport is flexible and supports the above conditions, calculations, and conversions. #6: FastExport does NOT support error files or error limits. FastExport does not record particular error types in a table. The FastExport utility will terminate after a certain number of errors have been encountered. #7: FastExport supports user-written routines INMODs and OUTMODs. FastExport allows you write INMOD and OUTMOD routines so you can select, validate and preprocess the exported data
Teradata Utilities: BTEQ, FastLoad, MultiLoad, TPump, and FastExport, Second Edition
The Mainframe (Channel Attached) environment supports the following Operating Systems:
MVS VM
Maximum of 15 Loads
The Teradata RDBMS will only support a maximum of 15 simultaneous FastLoad, MultiLoad, or FastExport utility jobs. This maximum value is determined and configured in the DBS Control record. This value can be set from 0 to 15. When Teradata is initially installed, this value is set at 5. The reason for this limitation is that FastLoad, MultiLoad, and FastExport all use large blocks to transfer data. If more then 15 simultaneous jobs were supported, a saturation point could be reached on the availability of resources. In this case, Teradata does an excellent job of protecting system resources by queuing up additional FastLoad, MultiLoad, and FastExport jobs that are attempting to connect. For example, if the maximum number of utilities on the Teradata system is reached and another job attempts to run, that job will not start. This limitation should be viewed as a safety control feature. A tip for remembering how the load limit applies is this, "If the name of the load utility contains either the word "Fast" or the word "Load", then there can be only a total of fifteen of them running at any one time". BTEQ does not have this load limitation. FastExport is clearly the better choice when exporting data. However, if two many load jobs are running. BTEQ is an alternate choice for exporting data.
Teradata Utilities: BTEQ, FastLoad, MultiLoad, TPump, and FastExport, Second Edition
ACCEPT DATEFORM DISPLAY ELSE ENDIF IF LOGOFF LOGON LOGTABLE ROUTE MESSAGES RUN FILE SET SYSTEM
Allows the value of utility variables to be accepted directly from a file or from environmental variables. Specifies the style of the DATE data types for FastExport. Writes messages to the specific location. Used in conjunction with the IF statement. ELSE commands and statements will execute when a proceeding IF condition is false. Used in conjunction with the IF or ELSE statements. Delimits the commands that were subject to previous IF or ELSE conditions. Introduces a conditional expression. If true then execution of subsequent commands will happen. Disconnects all FastExport active sessions and terminates FastExport. LOGON command or string used to connect sessions established through the FastExport utility. FastExport utilizes this to specify a restart log table. The purpose is for FastExport checkpoint information. Will route FastExport messages to an alternate destination. Used to point to a file that FastExport is to use as standard input. This will Invoke the specified external file as the current source of utility and Teradata SQL commands. Assigns a data type and value to a variable. Suspends the FastExport utility temporarily and executes any valid local operating system command before returning.
Figure 3-1
Task Commands
BEGIN EXPORT END EXPORT EXPORT Begins the export task and sets the specifications for the number of sessions with Teradata. Ends the export task and initiates processing by Teradata. Provides two things which are: The client destination and file format specifications for the export data retrieved from Teradata A generated MultiLoad script file that can be used later to reload the export data back into Teradata FIELD FILLER IMPORT LAYOUT Constitutes a field in the input record section that provides data values for the SELECT statement. Specifies a field in the input record that will not be sent to Teradata for processing. It is part of the input record to provide data values for the SELECT statement. Defines the file that provides the USING data values for the SELECT. Specifies the data layout for a file. It contains a sequence of FIELD and FILLER commands. This is used to describe the import file that can optionally provide data values for the SELECT.
Figure 3-2
Reprinted for [email protected], IBM Coffing Data Warehousing, Coffing Publishing (c) 2005, Copying Prohibited
Teradata Utilities: BTEQ, FastLoad, MultiLoad, TPump, and FastExport, Second Edition
SQL Commands
ALTER TABLE Change a column or table options of a table. CHECKPOINT Add a checkpoint entry in the journal table. COLLECT STATISTICS Collect statistics for one or more columns or indexes in a table. COMMENT Store or retrieve a comment string for a particular object. CREATE DATABASE Creates a new database. CREATE TABLE Creates a new table. CREATE VIEW Creates a new view. CREATE MACRO Creates a new macro. DATABASE Specify a default database for the session. DELETE Delete rows from a table. DELETE DATABASE Removes all tables, views, macros, and stored procedures from a database. DROP DATABASE Drops a database. GIVE Transfer ownership of a database or user to another user. GRANT Grant access privileges to an object. MODIFY DATABASE Change the options for a database. RENAME Change the name of a table, view, or macro. REPLACE MACRO Change a macro. REPLACE VIEW Change a view. REVOKE Revoke privileges to an object. SET SESSION Override the collation specification during the current COLLATION session. UPDATE Change a column value of an existing row or rows in a table.
Figure 3-3
Teradata Utilities: BTEQ, FastLoad, MultiLoad, TPump, and FastExport, Second Edition
Exports the data to the specified file or OUTMOD routine Logs off of Teradata
Logon to Teradata
.LOGON CDW/sql01,whynot; .BEGIN EXPORT SESSIONS 12;
Begin the Export and set the number of sessions on Teradata Defines the output file name. In addition, specifies the output mode and format (LAN - ONLY) The SELECT defines the columns used to create the exported file.
/* Get Data From the Student Table */ SELECT Student_ID (CHAR(11)), Last_name (CHAR(20)), First_name (CHAR(14)), Class_code (CHAR(2)), Grade_Pt (CHAR(9)) FROM SQL_CLASS.Student_Table;
NOTE: The selected columns for the export are being converted to character types. This will simplify the importing process into a different database. End the Export and logoff /* Finish the Export Job and Write to File */ Teradata.
.END EXPORT; .LOGOFF;
Figure 3-4
Teradata Utilities: BTEQ, FastLoad, MultiLoad, TPump, and FastExport, Second Edition
/* ---------------------------------------------------*/ /*@(#) FASTEXPORT SCRIPT */ /*@(#) Version 1.1 /*@(#) Created by CoffingDW */ /* ---------------------------------------------------*/
ALWAYS GOOD TO IDENTIFY THE */ SCRIPT AND AUTHOR IN COMMENTS CREATE LOGTABLE AND LOGON; BEGIN EXPORT STATEMENT. SESSIONS 12; DEFINES THE OUTPUT FILE NAME. IN ADDITION, SPECIFIES THE OUTPUT MODE AND FORMAT(LAN - ONLY) MODE RECORD FORMAT TEXT; THE SELECT PULLS DATA FROM TWO TABLES. IT IS GOOD TO QUALILY WHEN DOING A TWO-TABLE JOIN. END THE JOB AND LOGOFF TERADATA;
/* Setup the Fast Export Parameters */ .LOGTABLE SQL01.CDW_Log; .LOGON CDW/SQL01,whynot; .BEGIN EXPORT SESSIONS 12;
/* Join Data From the Employee and Department Table */ SELECT EMP.Employee_No (CHAR(11)) ,EMP.First_Name (CHAR(14)) ,EMP.Last_Name (CHAR(20)) ,DEPT.Dept_No (CHAR(6)) ,DEPT.Dept_name (CHAR(20)) FROM SQL_CLASS.Employee_table AS EMP INNER JOIN SQL_CLASS.Department_Table AS DEPT ON EMP.Dept_No = DEPT.Dept_No ;
/* Finish the Export Job and Write to File */ .END EXPORT; .LOGOFF;
Figure 3-5
Teradata Utilities: BTEQ, FastLoad, MultiLoad, TPump, and FastExport, Second Edition
Both modes return data in a client internal format with variable-length records. Each individual record has a value for all of the columns specified by the SELECT statement. All variable-length columns are preceded by a two-byte control value indicating the length of the column data. NULL columns have a value that is appropriate for the column data type. Remember, INDICATOR mode will set bit flags that identify the columns that have a null value.
Formats
FastExport has many possible formats in the UNIX or LAN environment. The FORMAT statement specifies the format for each record being exported which are: FASTLOAD BINARY TEXT UNFORMAT
The default FORMAT is FASTLOAD in a UNIX or LAN environment. FASTLOAD format has a two-byte integer, followed by the data, followed by an end-of-record marker. It is called FASTLOAD because the data is exported in a format ready for FASTLOAD. BINARY format is a two-byte integer, followed by data. TEXT format is an arbitrary number of bytes followed by an end-of-record marker. UNFORMAT format is exactly as received from CLIv2 without any client modifications.
CREATE LOGTABLE AND LOGON TO TERADATA; BEGIN EXPORT STATEMENT; NAME THE OUTPUT FILE AND SET THE FORMAT TO BINARY; GET THE DATA FROM THE STUDENT TABLE;
Coffing Data Warehousing, Coffing Publishing (c) 2005, Copying Prohibited
(CHAR(11)),
Teradata Utilities: BTEQ, FastLoad, MultiLoad, TPump, and FastExport, Second Edition
Last_name (CHAR(20)), First_name (CHAR(14)), Class_code (CHAR(2)), Grade_Pt (CHAR(8)) FROM SQL_CLASS.Student_Table; /* Finish the Export Job and Write to File */
Figure 3-6