2016-09-15 79 views
0

考虑基表employee和从名为employee_salary_period的雇员派生的表,其中包含复杂数据类型map。如何选择和插入来自employee数据到employee_salary_period其中salary_period_map是一个键值对,即salary: periodHive从表中选择复杂类型

CREATE TABLE employee(
    emp_id bigint, 
    name string, 
    address string, 
    salary double, 
    period string, 
    position string 
) 
PARTITIONED BY ( 
    dept_id bigint) 
STORED AS PARQUET 


CREATE TABLE employee_salary_period(
    emp_id 
    name string, 
    salary string, 
    period string, 
    salary_period_map Map<String,String>, 
) 
PARTITIONED BY ( 
    dept_id bigint) 
STORED AS PARQUET 

我卡试图弄清楚如何选择数据salary_period_map

回答

1

考虑使用提供str_to_map功能蜂巢。我希望你在地图上只有一把钥匙(工资)

select 
emp_id 
name, 
salary, 
period, 
str_to_map(concat(salary,":",period),'&',':') as salary_period_map 
from employee_salary_period