在配置单元的外部 table 中插入逗号分隔的数据
Insert comma separated data in external table in hive
create external table transaction_usa_canada
(
tran_id int,
acct_id int,
tran_date string,
amount double,
description string,
branch_code string,
product string,
tran_state string,
tran_city string,
speendby string,
tran_zip int,
source_table string
)
row format delimited
stored as textfile
location '/user/DSNew18/Bank_DS18/tran_usa_canada';
INSERT INTO TABLE myproject.transaction_usa_canada
SELECT tran_id, acct_id, tran_date, amount, description, branch_code,'', tran_state, tran_city, speendby, tran_zip, 'usa' AS source_table FROM transaction_usanew18
UNION ALL
SELECT tran_id, acct_id, tran_date, amount, description, branch_code,'', tran_state, tran_city, speendby, tran_zip, 'canada' AS source_table FROM transaction_canadanew18;
以上是我通过组合 2 个其他外部 table 插入配置单元中的外部 table 的查询。一切运行良好。只是问题是存储在 table 中的数据不是逗号分隔的。为了以逗号分隔格式获取数据,我应该进行哪些更改。
添加创建table
CREATE Table table(
....
)
row format delimited
FIELDS TERMINATED BY ‘,’
create external table transaction_usa_canada
(
tran_id int,
acct_id int,
tran_date string,
amount double,
description string,
branch_code string,
product string,
tran_state string,
tran_city string,
speendby string,
tran_zip int,
source_table string
)
row format delimited
fields terminated by ','
stored as textfile
location '/user/DSNew18/Bank_DS18/tran_usa_canada';
INSERT INTO TABLE myproject.transaction_usa_canada
SELECT tran_id, acct_id, tran_date, amount, description, branch_code,'', tran_state, tran_city, speendby, tran_zip, 'usa' AS source_table FROM transaction_usanew18
UNION ALL
SELECT tran_id, acct_id, tran_date, amount, description, branch_code,'', tran_state, tran_city, speendby, tran_zip, 'canada' AS source_table FROM transaction_canadanew18;
使用上面的代码获取逗号分隔的数据。
create external table transaction_usa_canada
(
tran_id int,
acct_id int,
tran_date string,
amount double,
description string,
branch_code string,
product string,
tran_state string,
tran_city string,
speendby string,
tran_zip int,
source_table string
)
row format delimited
stored as textfile
location '/user/DSNew18/Bank_DS18/tran_usa_canada';
INSERT INTO TABLE myproject.transaction_usa_canada
SELECT tran_id, acct_id, tran_date, amount, description, branch_code,'', tran_state, tran_city, speendby, tran_zip, 'usa' AS source_table FROM transaction_usanew18
UNION ALL
SELECT tran_id, acct_id, tran_date, amount, description, branch_code,'', tran_state, tran_city, speendby, tran_zip, 'canada' AS source_table FROM transaction_canadanew18;
以上是我通过组合 2 个其他外部 table 插入配置单元中的外部 table 的查询。一切运行良好。只是问题是存储在 table 中的数据不是逗号分隔的。为了以逗号分隔格式获取数据,我应该进行哪些更改。
添加创建table
CREATE Table table(
....
)
row format delimited
FIELDS TERMINATED BY ‘,’
create external table transaction_usa_canada
(
tran_id int,
acct_id int,
tran_date string,
amount double,
description string,
branch_code string,
product string,
tran_state string,
tran_city string,
speendby string,
tran_zip int,
source_table string
)
row format delimited
fields terminated by ','
stored as textfile
location '/user/DSNew18/Bank_DS18/tran_usa_canada';
INSERT INTO TABLE myproject.transaction_usa_canada
SELECT tran_id, acct_id, tran_date, amount, description, branch_code,'', tran_state, tran_city, speendby, tran_zip, 'usa' AS source_table FROM transaction_usanew18
UNION ALL
SELECT tran_id, acct_id, tran_date, amount, description, branch_code,'', tran_state, tran_city, speendby, tran_zip, 'canada' AS source_table FROM transaction_canadanew18;
使用上面的代码获取逗号分隔的数据。