问题描述
基于以下,Hive具有地图类型。然而,似乎没有文档方式通过带有一些UDF或内置函数的 SELECT 将新的键值对插入Hive映射中。这是可能的吗?
作为一个说明,假设我有一个名为 foo 的单个列的表,输入 map ,名为 column_containing_map 。
现在我想创建一个新表也有一列,键入 map ,但我希望每个映射(包含在单个列中)都有一个额外的键值对。 p>
查询可能如下所示:
CREATE TABLE IF NOT EXISTS bar AS
SELECT ADD_TO_MAP(column_containing_map,NewKey,NewValue)
FROM foo;
然后,表 bar 会包含相同的除了 bar 中的每张地图都会有一个额外的键值对之外, foo $ b
考虑你有一张学生表,其中包含各个科目的学生分数。
蜂房> desc学生;
id字符串
名称字符串
类字符串
标记映射< string,string>
您可以直接在表格中插入值。
INSERT INTO TABLE student
SELECT STACK(1,
'100','Sekar','Mathematics',map(Mathematics,78 )
)
从empinfo
限制1;
这里'empinfo'表可以是数据库中的任何表。
并且结果是:
100 Sekar Mathematics {Mathematics:78}
code>
Based on the following tutorial, Hive has a map type. However, there does not seem to be a documented way to insert a new key-value pair into a Hive map, via a SELECT with some UDF or built-in function. Is this possible?
As a clarification, suppose I have a table called foo with a single column, typed map, named column_containing_map.
Now I want to create a new table that also has one column, typed map, but I want each map (which is contained within a single column) to have an additional key-value pair.
A query might look like this:
CREATE TABLE IF NOT EXISTS bar AS SELECT ADD_TO_MAP(column_containing_map, "NewKey", "NewValue") FROM foo;
Then the table bar would contain the same maps as table foo except each map in bar would have an additional key-value pair.
Consider you have a student table which contains student marks in various subjects.
hive> desc student; id string name string class string marks map<string,string>
You can insert values directly to table as below.
INSERT INTO TABLE student SELECT STACK(1, '100','Sekar','Mathematics',map("Mathematics","78") ) FROM empinfo LIMIT 1;
Here 'empinfo' table can be any table in your database.And Results are:
100 Sekar Mathematics {"Mathematics":"78"}
这篇关于我如何将一个键值对插入配置单元映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!