fastload(2)

lightningmn發表於2016-01-04
FASTLOAD的特性:
1)FASTLOAD指令碼包含三個主要模組:
建表模組、Define模組、Insert模組。
[@more@]

2)FASTLOAD分為兩個階段:
第1階段 - 從資料文字中讀取記錄,只需放到目標AMP上即可
第2階段 - 在AMP內部按Rowhash進行排序
3)FASTLOAD的目標表初始的時候只能是個空表。
4)FASTLOAD的目標表不能定義次索引,但可以定義分割槽欄位。
5)FASTLOAD一次只能對一張表進行載入,不支援對多張表進行載入。
6)FASTLOAD支援多個資料檔案一次性加入一張表中,但這些資料檔案是序列載入並非並行載入。
7)FASTLOAD在載入的時候會自動剔除文字中的重複記錄,即使目標表定義為multiset table。

典型的fastload指令碼示例如下:
/* 限制錯誤記錄條數*/
ERRLIMIT 1;

/* 資料庫登入語句*/
LOGON ETL_TD_STAGE,ETL_TD_STAGE;

/* 建表模組*/
DATABASE TD_STAGE;
DROP TABLE AUCTION_PROPERTY;
DROP TABLE PLOG.AUCTION_PROPERTY_E1;
DROP TABLE PLOG.AUCTION_PROPERTY_E2;

CREATE MULTISET TABLE AUCTION_PROPERTY ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
AUCTION_ID CHAR(32) CHARACTER SET LATIN CASESPECIFIC,
PROPERTY_ID DECIMAL(11,0),
PROP_VID INTEGER,
STATUS INTEGER,
GMT_CREATE TIMESTAMP(0),
GMT_MODIFIED TIMESTAMP(0),
INS_DATE TIMESTAMP(0))
PRIMARY INDEX ( AUCTION_ID );

/* 方式一:設定載入方式為變長,分割符為Tab鍵*/
/* 同時,進入載入第1階段*/
.SET RECORD VARTEXT " " NOSTOP
BEGIN LOADING AUCTION_PROPERTY ERRORFILES PLOG.AUCTION_PROPERTY_E1,PLOG.AUCTION_PROPERTY_E2;

/* DEFINE模組,定義資料文字格式和存放路徑*/
DEFINE
AUCTION_ID (VARCHAR(42),nullif='')
,PROPERTY_ID (VARCHAR(21),nullif='')
,PROP_VID (VARCHAR(20),nullif='')
,STATUS (VARCHAR(20),nullif='')
,GMT_CREATE (VARCHAR(25),nullif='')
,GMT_MODIFIED (VARCHAR(25),nullif='')
,INS_DATE (VARCHAR(25),nullif='')

FILE=/bak/Teradata/auction_property.txt;

/* 方式二:設定載入方式為定長,分割符為Tab鍵*/

DEFINE
AUCTION_ID (VARCHAR(42),nullif='')
,TAB1 (CHAR(1))
,PROPERTY_ID (VARCHAR(21),nullif='')
,TAB2 (CHAR(1))
,PROP_VID (VARCHAR(20),nullif='')
,TAB3 (CHAR(1))
,STATUS (VARCHAR(20),nullif='')
,TAB4 (CHAR(1))
,GMT_CREATE (VARCHAR(25),nullif='')
,TAB5 (CHAR(1))
,GMT_MODIFIED (VARCHAR(25),nullif='')
,TAB6 (CHAR(1))
,INS_DATE (VARCHAR(25),nullif='')
,NEWLINE (CHAR(1))

FILE=/bak/Teradata/auction_property.txt;

/* 設定載入起點,也可以設定載入終點(THRU)*/
RECORD 1;

/* INSERT模組,定義物理表對應的格式*/
INSERT INTO TD_STAGE.AUCTION_PROPERTY(
AUCTION_ID
,PROPERTY_ID
,PROP_VID
,STATUS
,GMT_CREATE
,GMT_MODIFIED
,INS_DATE
)
VALUES (
:AUCTION_ID
,:PROPERTY_ID
,:PROP_VID
,:STATUS
,:GMT_CREATE (format 'yyyymmddhhmiss')
,:GMT_MODIFIED (format 'yyyymmddhhmiss')
,:INS_DATE (format 'yyyymmddhhmiss')
);

/* 第1階段結束,進入載入第2階段*/
END LOADING;

/* 資料庫退出語句*/
LOGOFF;


典型的fastload日誌示例如下:

/* 第1階段,文字記錄無序錄入到AMP上*/

**** 19:44:59 Number of recs/msg: 3
**** 19:44:59 Starting to send to RDBMS with record 1
**** 19:45:08 Starting row 100000
**** 19:45:18 Starting row 200000
**** 19:45:28 Starting row 300000
**** 19:45:38 Starting row 400000
**** 19:45:48 Starting row 500000
**** 19:45:58 Starting row 600000
**** 19:46:08 Starting row 700000
**** 19:46:18 Starting row 800000
**** 19:46:28 Starting row 900000
**** 19:46:38 Starting row 1000000
**** 19:46:39 Sending row 1015760
**** 19:46:39 Finished sending rows to the RDBMS

/* 第2階段,AMP內部進行排序*/
===================================================================
= =
= End Loading Phase =
= =
===================================================================

0013 END LOADING;

**** 19:47:58 END LOADING COMPLETE

Total Records Read = 1015760
- skipped by RECORD command = 0
- sent to the RDBMS = 1015760
Total Error Table 1 = 0 ---- Table has been dropped
Total Error Table 2 = 0 ---- Table has been dropped
Total Inserts Applied = 1015760
Total Duplicate Rows = 0

Start: Thu Mar 01 19:46:40 2007
End : Thu Mar 01 19:47:58 2007


2.Using fastload

batch mode執行引數:

3.兩個錯誤日誌表區別:
errortname1
• Constraint violations
• Conversion errors
• Unavailable AMP conditions
These types of errors always occur during the loading phase of your FastLoad job—after executing the BEGIN LOADING command, but
before the END LOADING command.

errortname2
Unique primary index violations
This type of error always occurs during the end-loading phase of your FastLoad job—after executing the END LOADING command.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29048952/viewspace-1970808/,如需轉載,請註明出處,否則將追究法律責任。