Hive从表中选择复杂类型
问题描述:
考虑基表employee
和从名为employee_salary_period
的雇员派生的表,其中包含复杂数据类型map
。如何选择和插入来自employee
数据到employee_salary_period
其中salary_period_map
是一个键值对,即salary: period
Hive从表中选择复杂类型
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
答
考虑使用提供str_to_map功能蜂巢。我希望你在地图上只有一把钥匙(工资)
select
emp_id
name,
salary,
period,
str_to_map(concat(salary,":",period),'&',':') as salary_period_map
from employee_salary_period