根据横向视图的结果创建 Hive External table
Creating Hive External table from the result of a Lateral View
我正在尝试创建外部配置单元 table 并使用横向视图分解,我看到的结果是正确的。但是在创建 table 我想查询主 table 没有
使用横向视图。
我的代码:
ADD JAR wasb:///user/hivexmlserde-1.0.5.3.jar;
SET mapred.input.dir.recursive=true;
SET hive.mapred.supports.subdirectories=true;
DROP TABLE IF EXISTS losApplicantEmployer;
CREATE EXTERNAL TABLE losApplicantEmployer
(customer array<struct<customer_id:string, type:string>>, employer array<struct<employer_id:string,type:string,employer_name:string,years_employed:int,months_employed:int,create_date:string, update_date:string >>)
ROW FORMAT SERDE
'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES(
"column.xpath.customer" = "/LoanApplications/LoanApplication[@deal_type='REQUESTED']/LoanApplicationStates/LoanApplicationState/Customers/Customer",
"column.xpath.employer" = "/LoanApplications/LoanApplication[@deal_type='REQUESTED']/LoanApplicationStates/LoanApplicationState/Customers/Customer/Employers/Employer"
)
STORED AS INPUTFORMAT
'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION'wasb://glshadoopd3@glsllcteststorage1.blob.core.windows.net/Safe/2016/05/12'
TBLPROPERTIES ("xmlinput.start"="<LoanApplications xmlns","xmlinput.end"="</LoanApplications>" );
select exp_cust.customer_id, exp_cust.type, exp_emp.employer_id, exp_emp.type, exp_emp.employer_name, exp_emp.years_employed, exp_emp.months_employed, exp_emp.create_date, exp_emp.update_date
from losApplicantEmployer
lateral view explode(customer) exp_customer as exp_cust
lateral view explode(employer) exp_employer as exp_emp;
我想将上面代码的结果保存为table。这样我就可以用它来查询。请让我知道如何?
我不想用Lateral View Explode,每次都想看结果。所以我觉得将整个结果存储在一个新的 table 中是最理想的。因为 table losApplicantEmployer 只是一个结构数组。
您可以使用 CREATE TABLE AS SELECT:
存储结果
CREATE TABLE exploded_table AS SELECT exp_cust.customer_id,
exp_cust.type, exp_emp.employer_id, exp_emp.type,
exp_emp.employer_name, exp_emp.years_employed,
exp_emp.months_employed, exp_emp.create_date,
exp_emp.update_date
FROM losApplicantEmployer
lateral view explode(customer) exp_customer as exp_cust
lateral view explode(employer) exp_employer as exp_emp;
我正在尝试创建外部配置单元 table 并使用横向视图分解,我看到的结果是正确的。但是在创建 table 我想查询主 table 没有 使用横向视图。
我的代码:
ADD JAR wasb:///user/hivexmlserde-1.0.5.3.jar;
SET mapred.input.dir.recursive=true;
SET hive.mapred.supports.subdirectories=true;
DROP TABLE IF EXISTS losApplicantEmployer;
CREATE EXTERNAL TABLE losApplicantEmployer
(customer array<struct<customer_id:string, type:string>>, employer array<struct<employer_id:string,type:string,employer_name:string,years_employed:int,months_employed:int,create_date:string, update_date:string >>)
ROW FORMAT SERDE
'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES(
"column.xpath.customer" = "/LoanApplications/LoanApplication[@deal_type='REQUESTED']/LoanApplicationStates/LoanApplicationState/Customers/Customer",
"column.xpath.employer" = "/LoanApplications/LoanApplication[@deal_type='REQUESTED']/LoanApplicationStates/LoanApplicationState/Customers/Customer/Employers/Employer"
)
STORED AS INPUTFORMAT
'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION'wasb://glshadoopd3@glsllcteststorage1.blob.core.windows.net/Safe/2016/05/12'
TBLPROPERTIES ("xmlinput.start"="<LoanApplications xmlns","xmlinput.end"="</LoanApplications>" );
select exp_cust.customer_id, exp_cust.type, exp_emp.employer_id, exp_emp.type, exp_emp.employer_name, exp_emp.years_employed, exp_emp.months_employed, exp_emp.create_date, exp_emp.update_date
from losApplicantEmployer
lateral view explode(customer) exp_customer as exp_cust
lateral view explode(employer) exp_employer as exp_emp;
我想将上面代码的结果保存为table。这样我就可以用它来查询。请让我知道如何?
我不想用Lateral View Explode,每次都想看结果。所以我觉得将整个结果存储在一个新的 table 中是最理想的。因为 table losApplicantEmployer 只是一个结构数组。
您可以使用 CREATE TABLE AS SELECT:
存储结果CREATE TABLE exploded_table AS SELECT exp_cust.customer_id,
exp_cust.type, exp_emp.employer_id, exp_emp.type,
exp_emp.employer_name, exp_emp.years_employed,
exp_emp.months_employed, exp_emp.create_date,
exp_emp.update_date
FROM losApplicantEmployer
lateral view explode(customer) exp_customer as exp_cust
lateral view explode(employer) exp_employer as exp_emp;