gpt4 book ai didi

nested - 如何在 Hive 中定义嵌套的集合项

转载 作者:行者123 更新时间:2023-12-04 05:52:34 25 4
gpt4 key购买 nike

我正在尝试创建一个带有嵌套集合项的配置单元表。假设我有一个结构数组。

    CREATE TABLE SAMPLE(
record array<struct<col1:string,col2:string>>
)row format delimited
fields terminated by ','
collection items terminated by '|';

第一级,分隔符 ',' 将覆盖默认分隔符 '^A'。

第二级,分隔符'|'将覆盖默认的第二级分隔符 '^B' 以分离出最外面的结构(即数组)。

第三级配置单元将使用默认的第三级分隔符 '^C' 作为 Struct 的分隔符

现在我的问题是如何为第二级(即结构)定义分隔符,因为 '^C' 字符难以阅读和生成。

有没有办法明确定义分隔符而不是 ^C ?

提前致谢。

最佳答案

尝试这样的事情:

CREATE TABLE SAMPLE(
id BIGINT,
record array<struct<col1:string,col2:string>>
)row format delimited
fields terminated by ','
collection items terminated by '|'
map keys terminated by ':';

现在文本文件中的数据将如下所示:
1345653,110909316904:1341894546|221065796761:1341887508

然后您可以像这样查询它:
select record.col1 from SAMPLE;

关于nested - 如何在 Hive 中定义嵌套的集合项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18011252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com