zoukankan      html  css  js  c++  java
  • hive 复杂类型

    hive提供一种复合类型的数据

    struct:可以使用“.”来存取数据
    map:可以使用键值对来存取数据
    array:array中存取的数据为相同类型,其中的数据可以通过下表获取数据
     
    创建 struct类型
    create table student_struct(id INT, info struct<name:STRING, age:INT>)
    ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' //指定表在加载数据时候的列分割符
    COLLECTION ITEMS TERMINATED BY ':'; //指定每个字段之间的item的分隔符
    导入测试数据
    1,zhang:24
    2,wang:23
    3,feng:22
    4,li:22
    5,zhou:21
    6,xing:20
    7,cai:19
    8,yi:18
    9,lan:17
    查询表中数据
    使用struct的"."来查询数据
    hive> select*from student_struct where info.age>20;
    OK
    1 {"name":"zhang","age":24}
    2 {"name":"wang","age":23}
    3 {"name":"feng","age":22}
    4 {"name":"li","age":22}
    5 {"name":"zhou","age":21}
    Time taken: 2.31 seconds, Fetched: 5 row(s)
    创建array
    create table student_array(id INT, stuArray array<String>)
    ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
    COLLECTION ITEMS TERMINATED BY ':';
    加载测试数据(stuArray里面存储的是相同的数据类型,可以有多个值)
    struct 数据
    查询表中数据(array类型,可以通过你创建表时定义列的别名,通过下标来获取数据)
    hive> select*from student_array where stuArray[1]>20;
    OK
    1 ["zhang","24"]
    2 ["wang","23"]
    3 ["feng","22"]
    4 ["li","22"]
    5 ["zhou","21"]
    Time taken: 2.63 seconds, Fetched: 5 row(s)
    创建Map(stuMap可以有多个,我这里写了两个)
    create table student_map(id string, stuMap map<string, int>)
    ROW FORMAT DELIMITED
    FIELDS TERMINATED BY '	'
    COLLECTION ITEMS TERMINATED BY ','
    MAP KEYS TERMINATED BY ':';
    导入测试数据
    1 zhang:24,shangHai:100
    2 wang:23,shangHai:200
    3 feng:22,shangHai:1900
    4 li:22,shangHai:2900
    5 zhou:21,shangHai:1200
    6 xing:20,shangHai:1200
    7 cai:19,shangHai:600
    8 yi:18,shangHai:7600
    9 lan:17,shangHai:8000
    查询数据
    hive> select * from student_map where stuMap['shangHai']=100;
    OK
    1 {"zhang":24,"shangHai":100}
    Time taken: 0.944 seconds, Fetched: 1 row(s)
    hive>
     
  • 相关阅读:
    explicit for ctors taking more than one argument
    Python 的 encode 和 decode
    Tripwire配置和运行
    man twadmin
    Tripwire策略说明
    Tripwire安装
    [部分翻译] tripwire(8)
    snort-2.9.3.1安装
    [转载] snort中文手册
    wireshark_1.2.11安装
  • 原文地址:https://www.cnblogs.com/zhangXingSheng/p/6223465.html
Copyright © 2011-2022 走看看