• Hive中的数据类型和存储格式总结


    1.数据类型

    Hive 支持多种数据类型,分为原始数据类型和复杂数据类型两类。以下是 Hive 支持的数据类型:

    原始数据类型

            1.整数类型

                    tinyint: 1字节有符号整数
                    smallint: 2字节有符号整数
                    int: 4字节有符号整数
                    bigint: 8字节有符号整数
                    float: 4字节单精度浮点数
                    double: 8字节双精度浮点数
                    decimal: 高精度数字类型,可以指定精度和标度,例如 decimal(10,2)

            字节(Byte):计算机中最基本的存储单元之一,1字节占8位(bit)  ,数据范围:负数范围: -128 到 -1,正数范围: 0 到 127   

            2.字符串类型:

                    string: 可变长度字符串
                    varchar: 具有最大长度限制的可变长度字符串,例如 varchar(255)
                    char: 固定长度字符串,例如 char(10)

            3.日期/时间类型:

                    timestamp: 包含日期和时间的时间戳,精确到纳秒
                    date: 仅包含日期部分,不包含时间部分
                    interval: 时间间隔,用于表示两个日期或时间之间的差值

            4.Boolean类型:

                    boolean: 布尔值,取值为 true 或 false

            5.二进制类型:

                    binary: 任意长度的字节数组

    复杂数据类型:
            1.数组类型

            array: 包含多个相同类型元素的有序列表,例如 array

            2.映射类型

            map: 键值对的无序集合,其中键和值可以是任意数据类型,例如 map


            3.结构类型

            struct: 包含多个字段的记录,每个字段可以是不同的数据类型,例如 struct

    1. CREATE TABLE example_table (
    2. tinyint_col tinyint,
    3. smallint_col smallint,
    4. int_col int,
    5. bigint_col bigint,
    6. float_col float,
    7. double_col double,
    8. decimal_col decimal(10, 2),
    9. string_col string,
    10. varchar_col varchar(255),
    11. char_col char(10),
    12. timestamp_col timestamp,
    13. date_col date,
    14. boolean_col boolean,
    15. binary_col binary,
    16. array_col array<int>,
    17. map_col map<string, int>,
    18. struct_col struct<name: string, age: int>,
    19. union_col uniontype<int, string>
    20. );

    2.Hive的文件存储格式

    hive的存储格式分为两大类:

    一类纯文本文件:textfile,不压缩,也是hive的默认存储格式

    一类是二进制文件存储:    

    sequencefile:会压缩,不能使用load方式加载数据

    orcfile:会压缩,不能使用load方式加载数据

    parquet:会压缩,不能使用load方式加载数据

    rcfile:会压缩,不能使用load方式加载数据,是orcfile的低配

    textfile和sequencefile的存储格式都是基于行存储的;orc和parquet是基于列式存储的,rcfile是行列混合存储。

    在创建表格的时候可以使用stored as parquet指定表格的存储格式,例:

    1. create table if not exists stocks_parquet (
    2. track_time string,
    3. url string,
    4. session_id string,
    5. referer string,
    6. ip string,
    7. end_user_id string,
    8. city_id string
    9. )
    10. stored as parquet;

    修改hive的默认存储格式:

    1. <property>
    2. <name>hive.default.fileformat</name>
    3. <value>TextFile</value>
    4. <description>
    5. Expects one of [textfile, sequencefile, rcfile, orc].
    6. Default file format for CREATE TABLE statement. Users can explicitly override it by CREATE TABLE ... STORED AS [FORMAT]
    7. </description>
    8. </property>
    9. 也可以使用set方式修改:
    10. set hive.default.fileformat=TextFile

  • 相关阅读:
    UNIAPP实战项目笔记2 创建项目和引入文件 导航开发和顶部开发
    深圳市商务局2022年度中央资金(跨境电子商务企业市场开拓扶持事项)申报指南
    pytorch从零实现resnet
    Warning: [antd: Switch] `value` is not a valid prop, do you mean `checked`?
    Ingress Controller
    ccf序列查询新解python满分_纯数学规律(学霸怎么想到的啊......)
    Camera/Lens流程(1)——点亮
    代码随想录一刷打卡——.二叉树的层次遍历(十题特别版)
    Node的api
    【JVM】经典垃圾收集器
  • 原文地址:https://blog.csdn.net/limenghao2002/article/details/140348353