将键值加载到配置单元中的地图

Loading key-values in to a map in hive

我有一个 table 表 1 有 5 列和 table 2 有 3 列

DESCRIBE Table1;

col1 int
col2 int
col3 int
col4 int
col5 int

DESCRIBE Table2;

col1 int
col2 int
mapcol map<string, int>

我现在想将数据从 Table1 复制到 Table2,其中 col3、col4、col5 将作为键值对存储在 mapcol 中。类似 mapcol < col3:value_of_col3, col4:value_of_col4, col5:value_of_col5>

我尝试使用 INSERT INTO 直接从 table 1 复制到 table 2,但没有成功。

我用过的查询是这样的

INSERT INTO TABLE Table2 SELECT
t1.col1 AS col1,
t1.col2 AS col2,
t1.col3 AS mapcol ["col3"]
FROM Table1 t1

Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
FAILED: NullPointerException null

有人可以帮我解决这个问题吗?

为此找到了一种快速而肮脏的方法! 我们可以通过在 hive 中使用 string_to_map 函数来做到这一点。但是,我们必须将地图更改为 map 才能使用 string_to_map.