Transcript delimited-file - Forums
Teradata Parallel Transporter Scripts with Simplified Syntax
Nam Tran, Teradata Parallel Transporter
Teradata Corporation
October 6, 2011
Today’s Agenda
5.
6.
7.
1.
2.
3.
4.
Introduction Job Script Example Before Simplified Syntax Using Operator Templates Using Generated Schemas Using Generated SQL INSERT Statements Job Script Example After Simplified Syntax Q & A
Introduction
• Customer ease-of syntax: use is of paramount importance to Teradata’s strategy. Teradata Parallel Transporter 13.10 and 14.0 introduces a simplified script > > > > > > Smaller and simpler job scripts Less job script maintenance with use of operator templates User-defined templates allow any degree of customization Generated schema objects Generated SQL insert statement Standardized the names of job variables that correspond to operator attributes • Target audience of this presentation: > Users of script-based TPT > > Users who write TPT job scripts Users who work with TPT job script generation tools
Job Script Example Before Simplified Syntax
DEFINE JOB File_Load DESCRIPTION ‘Load table from flat file’ ( DEFINE SCHEMA Customer_Accounts ( Account_Number INTEGER, Account_Name VARCHAR(50), Trans_Number INTEGER, Trans_Date ANSIDATE, Trans_Amount VARCHAR(20) ); DEFINE OPERATOR File_Reader TYPE DATACONNECTOR PRODUCER SCHEMA Customer_Accounts ATTRIBUTES ( VARCHAR FileName = @Filename, VARCHAR Format = @Format, VARCHAR OpenMode = @Openmode, VARCHAR TextDelimiter = @Delimiter, VARCHAR PrivateLogName = @DCLog ); /* continued on next page */ • Two main script sections > Declarative Section Defines the “what”: DEFINE SCHEMA object(s) DEFINE OPERATOR object(s)
Job Script Example Before Simplified Syntax
(continued)
/* continued from previous page */ DEFINE OPERATOR Load_Op TYPE LOAD SCHEMA * ATTRIBUTES ( VARCHAR TdpId = @TdpId, VARCHAR UserName = @UserName, VARCHAR UserPassword = @UserPW, VARCHAR TargetTable = @TarTable, VARCHAR LogTable = @LogTable, VARCHAR PrivateLogName = @LoadLog ); ); APPLY ‘INSERT INTO TABLE_X VALUES (:Account_Number, :Account_Name, :Trans_Number, :Trans_Date, :Trans_Amount);’ TO OPERATOR( Load_Op[2] ) SELECT * FROM OPERATOR( File_Reader ); > Executive Section Defines the “how” APPLY statement(s)
Job Variables File
• Stores and specifies common operator attributes > Reusable across multiple job scripts Tdpid = ‘drill’ ,Username = ‘johndoe’ ,Userpw = ‘janedoe’ ,TarTable = ‘TABLE_X’ ,LogTable = ‘TABLE_X_LOG’ ,LoadLog = ‘load.log’ ,Filename = ‘flatfile1.txt’ ,Format = ‘formatted’ ,Openmode = ‘read’ ,TextDelimiter = ‘|’ ,DCLog = ‘dc.log’
Job Variables
• Defined as
• TPT simplified syntax will rely heavily on predefined job variable names
Simplifying TPT Syntax
• Our goal? To make job scripts simpler by: > > Removing the declarative section Reusing common job variables > Reducing potential keystroke errors • DEFINE OPERATOR object: > Using Operator Templates instead • DEFINE SCHEMA object: > Using Generated Schemas instead • SQL INSERT statement: > Using Generated SQL INSERT Statements instead
Using Operator Templates
• What are operator templates?
> > Stored DEFINE OPERATOR statements for all TPT operators Uses formulaic names for the operators they define: $EXPORT , $LOAD , $UPDATE , $STREAM , etc.
> > > All possible operator attributes are declared Each operator attribute has a job variable reference as its value Standardizes job variable names that correspond to operator attributes
Operator Template Example
DEFINE OPERATOR $DDL DESCRIPTION 'Teradata Parallel Transporter DDL Operator' TYPE DDL ATTRIBUTES ( VARCHAR UserName = @TargetUserName, VARCHAR UserPassword = @TargetUserPassword, VARCHAR TdpId = @TargetTdpId, VARCHAR AccountId = @TargetAccountId, VARCHAR WorkingDatabase = @TargetWorkingDatabase, VARCHAR LogonMech = @TargetLogonMech, VARCHAR LogonMechData = @TargetLogonMechData, VARCHAR DataEncryption = @DDLDataEncryption, VARCHAR ARRAY ErrorList = @DDLErrorList, VARCHAR LogSQL = @DDLLogSQL, VARCHAR PrivateLogName = @DDLPrivateLogName, VARCHAR ARRAY QueryBandSessInfo = @DDLQueryBandSessInfo, VARCHAR ReplicationOverride = @DDLReplicationOverride, VARCHAR ARRAY TraceLevel = @DDLTraceLevel );
Referencing Templates in Your Script
• Templates are imported into the job script when operators are referenced in an APPLY statement using their template name, for example: APPLY ‘INSERT INTO TABLE_X (:col1, :col2);’ TO OPERATOR ($LOAD ); • By referencing the $LOAD operator template name, TPT knows to import the corresponding template
Using Template Job Variables
• Templates contain predefined, conventionally-named job variables assigned to each operator attribute • Assign predefined job variables as
= ‘value’
pair, for example: SourceUserName = ‘johndoe’ SourceUserPassword = ‘janedoe’ • Unassigned job variables cause TPT to ignore value assignments
Job Variables Naming Convention
• For producer templates: Logon-associated: Source
User-Defined Templates
• Users can create their own templates to maximize usefulness: > Template name must begin with ‘ $ ’ and be unique > Use SCHEMA * for consumer template and SCHEMA $ for producer template > > All operator attributes not assigned fixed values should be assigned predefined, conventionally-named job variables Store template in $TWB_ROOT/template directory
User-Defined Operator Template Example
DEFINE OPERATOR $MY_DELIMITED_READER DESCRIPTION ‘My user-defined delimited file reader’ TYPE DATACONNECTOR PRODUCER SCHEMA $ ATTRIBUTES ( VARCHAR FileName = @SourceFileName, VARCHAR Format = ‘Delimited’, VARCHAR TextDelimiter = ‘,’, INTEGER IOBufferSize = @FileReaderIOBufferSize, : : : : VARCHAR PrivateLogName = @FileReaderPrivateLogName, VARCHAR TraceLevel = @FileReaderSkipRows, );
Using Generated Schemas
• All producer operators require a schema specification. How does TPT simplified syntax overcome this?
> Explicitly generated schemas A simpler way of defining a schema object via a DBS table name and allowing TPT to auto-generate the column definitions > Inferred generated schemas A method by which TPT analyzes job step information to auto generate a schema object and its column definitions
Explicitly Generated Schemas
• Explicitly specify the name of a DBS table in DEFINE SCHEMA to: > auto-generate a schema, for example: DEFINE SCHEMA WEEKLY_TRANSACTIONS ‘Weekly_Trans’ ; > auto-generate a
delimited-file
schema, for example: DEFINE SCHEMA WEEKLY_TRANSACTIONS DELIMITED ‘Weekly_Trans’ ; • Explicitly specify the name of a DBS table in the APPLY statement’s producer operator reference to: > auto-generate a schema, for example: APPLY ‘INSERT INTO TABLE_X (:col1, :col2);’ TO OPERATOR ( $LOAD) ; FROM OPERATOR ($EXPORT (‘TABLE_X’) ); > auto-generate a
delimited-file
schema, for example: APPLY ‘INSERT INTO TABLE_X (:col1, :col2);’ TO OPERATOR ( $LOAD) ; FROM OPERATOR ($EXPORT (DELIMITED ‘TABLE_X’) );
Inferred Generated Schemas
• What is an inferred schema?
> The schema of a producer template operator whose column content can be inferred from information in the same job step • How does TPT infer a schema? > By analyzing the script information of all operators invoked in any job step that employs one of more producer templates
Inferred Generated Schemas:
Example 1
• • • • STEP LOAD_2 ( APPLY
Inferred Generated Schemas:
Example 2
• • • • STEP INSERT_DAILY_TRANS ( APPLY
Inferred Generated Schemas:
Example 3
• • • • STEP INSERT_MONTHLY_SHIPMENTS ( APPLY
How TPT Generates Schema
• Whenever TPT generates a schema based on a DBS table, it must: > > > > Make a HELP TABLE call to DBS Construct DEFINE SCHEMA object Merge generated DEFINE SCHEMA object into job script Substitute generated schema for the SCHEMA $ in producer operator template
Generated Schemas Advantages & Limitations
• Generated schemas > > > Major convenience when number of schema column definitions is large Reducing keyboarding time and keystroke errors TPT job scripts simpler, more compact, easier to read • Limitations > > Requires the name of a DBS table that already exists prior to running the job Inferred schemas based on TargetTable attribute assumes data loaded unchanged
Using Generated SQL INSERT Statements
• TPT supports one additional feature to reduce script size and eliminate keystroke errors: Generating any SQL INSERT statement: > if the target table is specified or can be unambiguously determined • For example: > DBS table ’Invoice_Counts’ has 4 columns col1 , col2 , col3 , and col4 > By specifying: APPLY $INSERT 'Invoice_Counts' TO OPERATOR( $UPDATE ) SELECT * FROM OPERATOR( $SELECTOR ); > TPT will replace $INSERT 'Invoice_Counts' SQL INSERT statement: with the following generated 'INSERT INTO Invoice_Counts VALUES ( :col1, :col2, :col3, :col4 );'
Our Example Job Script – Simplified!
DEFINE JOB File_Load DESCRIPTION ‘Load table from flat file’ ( DEFINE SCHEMA Customer_Accounts ( Account_Number INTEGER, Account_Name VARCHAR(50), Trans_Number INTEGER, Trans_Date ANSIDATE, Trans_Amount VARCHAR(20) ); DEFINE OPERATOR File_Reader TYPE DATACONNECTOR PRODUCER SCHEMA Customer_Accounts ATTRIBUTES ( VARCHAR FileName = @Filename, VARCHAR Format = @Format, VARCHAR OpenMode = @Openmode, VARCHAR TextDelimiter = @Delimiter, VARCHAR PrivateLogName = @DCLog ); /* continued on next page */ DEFINE JOB File_Load DESCRIPTION ‘Load table from flat file’ ( APPLY $INSERT TO OPERATOR( $LOAD[2] ) SELECT * FROM OPERATOR( $FILE_READER ); );
Our Example Job Script – Simplified!
(continued)
/* continued from previous page */ DEFINE OPERATOR Load_Op TYPE LOAD SCHEMA * ATTRIBUTES ( VARCHAR TdpId = @TdpId, VARCHAR UserName = @UserName, VARCHAR UserPassword = @UserPW, VARCHAR TargetTable = @TarTable, VARCHAR LogTable = @LogTable, VARCHAR PrivateLogName = @LoadLog ); ); APPLY ‘INSERT INTO TABLE_X VALUES (:Account_Number, :Account_Name, :Trans_Number, :Trans_Date, :Trans_Amount);’ TO OPERATOR( Load_Op[2] ) SELECT * FROM OPERATOR( File_Reader ); DEFINE JOB File_Load DESCRIPTION ‘Load table from flat file’ ( APPLY $INSERT TO OPERATOR( $LOAD[2] ) SELECT * FROM OPERATOR( $FILE_READER ); );
Job Variables Files
Before Tdpid = ‘drill’ ,Username = ‘johndoe’ ,Userpw = ‘janedoe’ ,TarTable = ‘TABLE_X’ ,LogTable = ‘TABLE_X_LOG’ ,LoadLog = ‘load.log’ Filename = ‘flatfile1.txt’ ,Format = ‘formatted’ ,Openmode = ‘read’ ,TextDelimiter = ‘|’ ,DCLog = ‘dc.log’ After, with Conventionalized Names TargetTdpId = ‘drill’ ,TargetUserName = ‘johndoe’ ,TargetUserPassword = ‘janedoe’ ,LoadTargetTable = ‘TABLE_X’ ,LoadLogTable = ‘TABLE_X_LOG’ ,LoadPrivateLogName = ‘load.log’ ,FileReaderFileName = ‘flatfile1.txt’ ,FileReaderFormat = ‘formatted’ ,FileReaderOpenmode = ‘read’ ,FileReaderTextDelimiter = ‘|’ ,FileReaderPrivateLogName = ‘dc.log’