gpt4 book ai didi

arrays - 如何在 Hive 中使用数据类型为 array> 的列创建表

转载 作者:行者123 更新时间:2023-12-03 23:24:30 27 4
gpt4 key购买 nike

我正在尝试创建一个具有复杂数据类型的表。下面列出了数据类型。

  • 阵列
  • map
  • 数组<映射<字符串,字符串>>

  • 我正在尝试创建 3 类型的数据结构。是否有可能在 Hive 中创建?我的表 DDL 如下所示。
    create table complexTest(names array<String>,infoMap map<String,String>, deatils array<map<String,String>>)           
    row format delimited
    fields terminated by '/'
    collection items terminated by '|'
    map keys terminated by '='
    lines terminated by '\n';

    我的示例数据如下所示。
    Abhieet|Test|Complex/Name=abhi|age=31|Sex=male/Name=Test,age=30,Sex=male|Name=Complex,age=30,Sex=female

    无论我从表中查询数据,我都会得到以下值
    ["Abhieet"," Test"," Complex"]  {"Name":"abhi","age":"31","Sex":"male"} [{"Name":null,"Test,age":null,"31,Sex":null,"male":null},{"Name":null,"Complex,age":null,"30,Sex":null,"female":null}]

    这不是我所期待的。如果数据类型 array< map < String,String>> 可能的话,您能帮我找出DDL 应该是什么吗?

    最佳答案

    我认为使用内置的 serde 是不可能的。如果您事先知道 map 中的值将是什么,那么我认为解决这个问题的更好方法是将您的输入数据转换为 JSON,然后使用 the Hive json serde :

    样本数据:

    {'Name': ['Abhieet', 'Test', 'Complex'],
    'infoMap': {'Sex': 'male', 'Name': 'abhi', 'age': '31'},
    'details': [{'Sex': 'male', 'Name': 'Test', 'age': '30'}, {'Sex': 'female', 'Name': 'Complex', 'age': '30'}]
    }

    表定义代码:
    create table complexTest
    (
    names array<string>,
    infomap struct<Name:string,
    age:string,
    Sex:string>,
    details array<struct<Name:string,
    age:string,
    Sex:string>>
    )
    row format serde 'org.openx.data.jsonserde.JsonSerDe'

    关于arrays - 如何在 Hive 中使用数据类型为 array<map<string, string>> 的列创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30744963/

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