大数据--Apache Pig

1、Apache Pig 介绍

Apache Pig is a platform for analyzing large data sets that consists of a high-level language for expressing data analysis programs, coupled with infrastructure for evaluating these programs. The salient property of Pig programs is that their structure is amenable to substantial parallelization, which in turns enables them to handle very large data sets.

At the present time, Pig's infrastructure layer consists of a compiler that produces sequences of Map-Reduce programs, for which large-scale parallel implementations already exist (e.g., the Hadoop subproject). Pig's language layer currently consists of a textual language called Pig Latin, which has the following key properties:

Ease of programming. It is trivial to achieve parallel execution of simple, "embarrassingly parallel" data analysis tasks. Complex tasks comprised of multiple interrelated data transformations are explicitly encoded as data flow sequences, making them easy to write, understand, and maintain.

Optimization opportunities. The way in which tasks are encoded permits the system to optimize their execution automatically, allowing the user to focus on semantics rather than efficiency.

Extensibility. Users can create their own functions to do special-purpose processing.

Pig是一个基于Hadoop的大规模数据分析平台,它提供的SQL-LIKE语言叫Pig Latin,该语言的编译器会把类SQL的数据分析请求转换为一系列经过优化处理的MapReduce运算。Pig为复杂的海量数据并行计算提供了一个简单的操作和编程接口。

Apache Pig 是apache平台下的一个免费开源项目,Pig为大型数据集的处理提供了更高层次的抽象,很多时候数据的处理需要多个MapReduce过程才能实现,使得数据处理过程与该模式匹配可能很困难。有了Pig就能够使用更丰富的数据结构。

Pig LatinPig Latin 是一个相对简单的语言,一条语句 就是一个操作,与数据库的表类似,可以在关系数据库中找到它(其中,元组代表行,并且每个元组都由字段组成)。

Pig 拥有大量的数据类型,不仅支持包、元组和映射等高级概念,还支持简单的数据类型,如 int、long、float、double、chararray 和 bytearray。并且,还有一套完整的比较运算符,包括使用正则表达式的丰富匹配模式



 

2、Pig Latin 的基础知识

Pig Latin 是一个相对简单的语言,它可以执行语句。一调语句 就是一个操作,它需要输入一些内容(比如代表一个元组集的包),并发出另一个包作为其输出。一个 就是一个关系,与表类似,您可以在关系数据库中找到它(其中,元组代表行,并且每个元组都由字段组成)。

用 Pig Latin 编写的脚本往往遵循以下特定格式,从文件系统读取数据,对数据执行一系列操作(以一种或多种方式转换它),然后,将由此产生的关系写回文件系统。您可以在 清单 1 中看到该模式的最简单形式(一个转换)。

Pig 拥有大量的数据类型,不仅支持包、元组和映射等高级概念,还支持简单的数据类型,如 intlongfloatdoublechararray 和bytearray。如果使用简单的类型,您会发现,除了称为 bincond 的条件运算符(其操作类似于 C ternary 运算符)之外,还有其他许多算术运算符(比如 addsubtractmultiplydivide 和 module)。并且,如您所期望的那样,还有一套完整的比较运算符,包括使用正则表达式的丰富匹配模式。

所有 Pig Latin 语句都需要对关系进行操作(并被称为关系运算符)。正如您在 清单 1 中看到的,有一个运算符用于从文件系统加载数据和将数据存储到文件系统中。有一种方式可以通过迭代关系的行来 FILTER 数据。此功能常用于从后续操作不再需要的关系中删除数据。另外,如果您需要对关系的列进行迭代,而不是对行进行迭代,您可以使用 FOREACH 运算符。FOREACH 允许进行嵌套操作,如 FILTER 和 ORDER,以便在迭代过程中转换数据。

ORDER 运算符提供了基于一个或多个字段对关系进行排序的功能。JOIN 运算符基于公共字段执行两个或两个以上的关系的内部或外部联接。SPLIT 运算符提供了根据用户定义的表达式将一个关系拆分成两个或两个以上关系的功能。最后,GROUP 运算符根据某个表达式将数据分组成为一个或多个关系。

猜你喜欢

转载自gaojingsong.iteye.com/blog/2324050
pig
今日推荐