如何在 Teradata 中导出 Varbyte
How to export Varbyte in Teradata
我有一个 table 示例数据如下:
Num JobId
1 12345678
其中 Num 是 Integer 数据类型,JobId 是 Varbyte 数据类型。
我需要解压,我使用的TPT脚本是:
USING CHARACTER SET UTF8
DEFINE JOB EXPORT_DELIMITED_FILE
DESCRIPTION 'Export' ( DEFINE SCHEMA FILE_SCHEMA (
Num INTEGER,
JobID Varbyte(16)
);
DEFINE OPERATOR SQL_SELECTOR
TYPE SELECTOR
SCHEMA FILE_SCHEMA ATTRIBUTES
(
VARCHAR PrivateLogName = 'selector_log',
VARCHAR TdpId = '192.168.xx.xxx',
VARCHAR UserName = 'dbc', VARCHAR UserPassword = 'dbc',
VARCHAR SelectStmt = 'SELECT * FROM AdventureWorksDW.DB1_TB1;',
DEFINE OPERATOR FILE_WRITER
TYPE DATACONNECTOR CONSUMER
SCHEMA *
ATTRIBUTES
(
VARCHAR PrivateLogName = 'dataconnector_log',
VARCHAR DirectoryPath = 'filepath',
VARCHAR FileName = 'DB1_TB1.csv',
VARCHAR FORMAT= 'DELIMITED', //delimited doesn't work
VARCHAR TextDelimiter= '|',
VARCHAR OpenMode = 'Write'
);
APPLY TO OPERATOR (FILE_WRITER)
SELECT * FROM OPERATOR (SQL_SELECTOR);
);
我需要以下格式的 csv 文件:
1 | 12345678
如何实现?
delimited 格式不支持二进制数据。但是您可以在 select:
中使用 from_bytes
将其转换为字符串
USING CHARACTER SET UTF8
DEFINE JOB EXPORT_DELIMITED_FILE
DESCRIPTION 'Export'
(
APPLY TO OPERATOR
( $FILE_WRITER[1]
ATTR ( VARCHAR PrivateLogName = 'dataconnector_log',
VARCHAR DirectoryPath = 'filepath',
VARCHAR FileName = 'DB1_TB1.csv',
VARCHAR FORMAT= 'DELIMITED',
VARCHAR TextDelimiter= '|',
VARCHAR OpenMode = 'Write'
)
)
SELECT *
FROM OPERATOR
( $SELECTOR[1]
ATTR
( PrivateLogName = 'selector_log',
TdpId = '192.168.xx.xxx',
UserName = 'dbc',
UserPassword = 'dbc',
SelectStmt = 'SELECT num, from_bytes(jobid, ''base16'') FROM td01.testtab;'
)
);
);
我有一个 table 示例数据如下:
Num JobId
1 12345678
其中 Num 是 Integer 数据类型,JobId 是 Varbyte 数据类型。
我需要解压,我使用的TPT脚本是:
USING CHARACTER SET UTF8
DEFINE JOB EXPORT_DELIMITED_FILE
DESCRIPTION 'Export' ( DEFINE SCHEMA FILE_SCHEMA (
Num INTEGER,
JobID Varbyte(16)
);
DEFINE OPERATOR SQL_SELECTOR
TYPE SELECTOR
SCHEMA FILE_SCHEMA ATTRIBUTES
(
VARCHAR PrivateLogName = 'selector_log',
VARCHAR TdpId = '192.168.xx.xxx',
VARCHAR UserName = 'dbc', VARCHAR UserPassword = 'dbc',
VARCHAR SelectStmt = 'SELECT * FROM AdventureWorksDW.DB1_TB1;',
DEFINE OPERATOR FILE_WRITER
TYPE DATACONNECTOR CONSUMER
SCHEMA *
ATTRIBUTES
(
VARCHAR PrivateLogName = 'dataconnector_log',
VARCHAR DirectoryPath = 'filepath',
VARCHAR FileName = 'DB1_TB1.csv',
VARCHAR FORMAT= 'DELIMITED', //delimited doesn't work
VARCHAR TextDelimiter= '|',
VARCHAR OpenMode = 'Write'
);
APPLY TO OPERATOR (FILE_WRITER)
SELECT * FROM OPERATOR (SQL_SELECTOR);
);
我需要以下格式的 csv 文件:
1 | 12345678
如何实现?
delimited 格式不支持二进制数据。但是您可以在 select:
中使用from_bytes
将其转换为字符串
USING CHARACTER SET UTF8
DEFINE JOB EXPORT_DELIMITED_FILE
DESCRIPTION 'Export'
(
APPLY TO OPERATOR
( $FILE_WRITER[1]
ATTR ( VARCHAR PrivateLogName = 'dataconnector_log',
VARCHAR DirectoryPath = 'filepath',
VARCHAR FileName = 'DB1_TB1.csv',
VARCHAR FORMAT= 'DELIMITED',
VARCHAR TextDelimiter= '|',
VARCHAR OpenMode = 'Write'
)
)
SELECT *
FROM OPERATOR
( $SELECTOR[1]
ATTR
( PrivateLogName = 'selector_log',
TdpId = '192.168.xx.xxx',
UserName = 'dbc',
UserPassword = 'dbc',
SelectStmt = 'SELECT num, from_bytes(jobid, ''base16'') FROM td01.testtab;'
)
);
);