table 中的 Hive select 作为复杂类型

Hive select from table as complex type

考虑基数 table employee 和从名为 employee_salary_period 的员工派生的 table,其中包含复杂数据类型 map。如何 select 并将数据从 employee 插入 employee_salary_period,其中 salary_period_map 是键值对,即 salary: period

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

我一直在试图弄清楚如何 select 数据作为 salary_period_map

考虑使用 hive 提供的 str_to_map 函数。希望你map里只有一个key(salary)

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