Primitive Data Types --Hive 支持数据类型
Hive supports several sizes of integer and floating-point types, a Boolean type, and
character strings of arbitrary length. Hive v0.8.0 added types for timestamps and binary
fields.
What if you run a query that wants to interpret a string column as a number? You can
explicitly cast one type to another as in the following example, where s is a string
column that holds a value representing an integer:
... cast(s AS INT) ...;
(To be clear, the AS INT are keywords, so lowercase would be fine.)
Collection Data Types -- 特殊数据类型
Hive supports columns that are structs, maps, and arrays.
Here is a table declaration that demonstrates how to use these types, an employees table
in a fictitious Human Resources application:
CREATE TABLE employees (
name STRING,
salary FLOAT,
subordinates ARRAY<STRING>,
deductions MAP<STRING, FLOAT>,
address STRUCT<street:STRING, city:STRING, state:STRING, zip:INT>);
Text File Encoding of Data Values -- 文本文件编码
Let’s begin our exploration of file formats by looking at the simplest example, text files.
You are no doubt familiar with text files delimited with commas or tabs, the so-called
comma-separated values (CSVs) or tab-separated values (TSVs), respectively. Hive can
use those formats if you want and we’ll show you how shortly. However, there is a
drawback to both formats; you have to be careful about commas or tabs embedded in
text and not intended as field or column delimiters. For this reason, Hive uses various
control characters by default, which are less likely to appear in value strings. Hive uses
the term field when overriding the default delimiter, as we’ll see shortly.
John Doe^A100000.0^AMary Smith^BTodd Jones^AFederal Taxes^C.2^BState
Taxes^C.05^BInsurance^C.1^A1 Michigan Ave.^BChicago^BIL^B60600
Mary Smith^A80000.0^ABill King^AFederal Taxes^C.2^BState Taxes^C.
05^BInsurance^C.1^A100 Ontario St.^BChicago^BIL^B60601
Todd Jones^A70000.0^AFederal Taxes^C.15^BState Taxes^C.03^BInsurance^C.
1^A200 Chicago Ave.^BOak Park^BIL^B60700
Bill King^A60000.0^AFederal Taxes^C.15^BState Taxes^C.03^BInsurance^C.
1^A300 Obscure Dr.^BObscuria^BIL^B60100
This is a little hard to read, but you would normally let Hive do that for you, of course.
Let’s walk through the first line to understand the structure. First, here is what it would
look like in JavaScript Object Notation (JSON), where we have also inserted the names
from the table schema:
{
"name": "John Doe",
"salary": 100000.0,
"subordinates": ["Mary Smith", "Todd Jones"],
"deductions": {
"Federal Taxes": .2,
"State Taxes": .05,
"Insurance": .1
},
"address": {
"street": "1 Michigan Ave.",
"city": "Chicago",
"state": "IL",
"zip": 60600
}
}
You’ll note that maps and structs are effectively the same thing in JSON.
Now, here’s how the first line of the text file breaks down:
• John Doe is the name.
• 100000.0 is the salary.
• Mary Smith^BTodd Jones are the subordinates “Mary Smith” and “Todd Jones.”
• Federal Taxes^C.2^BState Taxes^C.05^BInsurance^C.1 are the deductions, where
20% is deducted for “Federal Taxes,” 5% is deducted for “State Taxes,” and 10%
is deducted for “Insurance.”
• 1 Michigan Ave.^BChicago^BIL^B60600 is the address, “1 Michigan Ave., Chicago,
60600.”
You can override these default delimiters. This might be necessary if another applica-
tion writes the data using a different convention. Here is the same table declaration
again, this time with all the format defaults explicitly specified:
CREATE TABLE employees (
name STRING,
salary FLOAT,
subordinates ARRAY<STRING>,
deductions MAP<STRING, FLOAT>,
address STRUCT<street:STRING, city:STRING, state:STRING, zip:INT>
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\001'
COLLECTION ITEMS TERMINATED BY '\002'
MAP KEYS TERMINATED BY '\003'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
分享到:
相关推荐
本资料“hive数据类型共6页.pdf”可能详细介绍了Hive中的各种数据类型及其使用方法。以下是关于Hive数据类型的详细解释: 1. **基本数据类型**: - **STRING**:用于存储字符串,可以包含字母、数字和特殊字符。 ...
3. **Hive基础**:本章涉及Hive的数据类型、运算符、数据存储方式和存储格式,以及常用的交互命令。学习者需要掌握不同数据类型的操作,理解Hive的数据存储机制,如TextFile、SequenceFile、Orc和Parquet等。 4. **...
这两个jar包分别是Hive执行引擎和ORC文件格式处理的实现,更新它们可能是为了修复特定版本中的已知问题或提供更好的兼容性。 CDH(Cloudera Distribution Including Apache Hadoop)是Cloudera公司提供的Hadoop发行...
5. **解析键和值**:在数据块中,根据已知的Hive文件格式,解析键和值的结构。这涉及到读取和解码数据,如字符串、DWORD、QWORD等。 6. **递归解析子键**:由于键可以有子键,解析过程中需要递归地处理这些子结构。...
- HIVE文件是二进制格式,包含键、值对,用于存储和加载注册表信息。 - 解析库文件(如FS.DLL)可能包含用于读取、修改或解析注册表HIVE的函数。 3. FAT (File Allocation Table): - FAT是早期Windows和MS-DOS...
这可能包括数据清洗、填充缺失值、转换数据类型等。 3. **数据加载**:使用`LOAD DATA`命令将“uaction.dat”文件加载到之前创建的Hive表中。 4. **查询优化**:编写SQL查询来探索数据,如统计每个用户的活跃度、...
2. 创建Hive表:使用HQL创建表结构,定义列名、数据类型以及可能的分区。例如: ```sql CREATE TABLE IF NOT EXISTS my_table (column1 string, column2 int) PARTITIONED BY (date string); ``` 3. 加载数据:...
### ES-HIVE数据互通知识点详解 #### 环境配置 在进行Elasticsearch与Hive的数据互通之前,首先需要确保环境配置正确无误。本文档提到的环境为实验性的单节点集群,具体配置如下: - **操作系统**:Vagrant + ...
### Hive数据存储模式详解 #### 一、Hive的数据存储 Hive作为一款基于Hadoop的数据仓库工具,其核心功能之一就是提供了一种高效的管理大数据的方式。Hive的数据分为两大类:**表数据**和**元数据**。 - **表数据*...
4. **文件格式**:Hive支持多种文件格式,如TextFile、SequenceFile、ORC和Parquet,每种格式都有其特定的优缺点,适用于不同的场景。 5. **表分区**:通过将大表按照某个或某些列的值划分为较小的部分,可以显著...
hive测试数据,其中为日志类型,用于验证在hive中主流文件存储格式对比实验
2. **表**:表是数据的基本存储单元,它由一系列列组成,每列有自己的数据类型。 3. **列**:列定义了表的结构,包括列名和数据类型,例如INT、STRING、DATE等。 4. **分区**:分区是一种优化查询的方法,将大表逻辑...
### Hive 数据加载与导出详解 #### 创建 Hive 表 在使用 Hive 进行数据分析之前,首先需要创建一张表来存储数据。以下是一段创建分区表的 SQL 语句示例: ```sql CREATE TABLE db_0309.emp ( empno INT, ename ...
知识点2:Hive数据类型 Hive支持多种数据类型,包括String、Integer、Float、Double、Boolean等。在该资源中,我们使用String类型来存储电影名称、票房数据等信息。 知识点3:Hive表创建 在Hive中,创建表需要...
总结起来,将Hive metastore迁移到达梦数据库涉及创建数据库用户和表空间、修改Hive配置文件以及初始化元数据等步骤。这个过程不仅可以提升元数据管理的性能,还可以利用达梦数据库的特性来增强数据安全性。然而,...
4. **hive-site.xml**:这是Hive的核心配置文件,包含了Hive的各种配置选项,如Hive的元数据存储位置、执行引擎类型(如MapReduce或Tez)、HDFS路径、临时目录设置等。比如,你可以在这里配置Hive连接MySQL的URL、...
标题 "hive测试题(包含万级测试数据文件)" 指的是一个与Hive相关的练习或测试集,其中可能包含了用于大数据分析的万级条目数据。这些数据可能被设计成模拟真实世界的业务场景,帮助学习者或者从业者检验和提升在Hive...
这是因为 Hive 中建议统一使用 string 类型,以减少数据类型的不匹配问题。 - **字段匹配**:确保 Oracle 表与 Hive 表之间的字段一一对应,字段数量也需相同。这是为了避免数据迁移过程中因字段数量或类型不匹配而...