Pig教程

Pig MIN

Apache Pig MIN 函数

Apache Pig MIN 函数用于找出单列包中数值或字符数组的最小值。它需要前面的 GROUP ALL 语句用于全局最小值和 GROUP BY 语句用于组最小值。但是,它会忽略 NULL 值。

语法

MIN(exp)
Here,
exp-它是一个具有字符数组、int、float、long 等数据类型的表达式。

MIN 函数示例

在此示例中,我们将找出给定值的最小值。

执行 MIN 函数的步骤

在本地机器上创建一个文本文件并插入元组列表。
$ nano evalmin.txt
Apache Pig MIN 函数 检查插入到文本文件中的元组。
$ cat evalmin.txt
Apache Pig MIN 函数 上传特定目录下 HDFS 上的文本文件。
$ hdfs dfs-put evalmin.txt /pigexample
开启猪 MapReduce 运行模式。
$ pig
加载包含数据的文件。
grunt> A = LOAD '/pigexample/evalmin.txt' USING PigStorage(',') AS (a1:chararray,a2:chararray,a3:float) ;
现在,执行并验证数据。
grunt> DUMP A;
Apache Pig MIN 函数 让我们根据"a1"字段对数据进行分组。
grunt> B = GROUP A BY a1; 
grunt> DUMP B;
Apache Pig MIN 函数 让我们返回给定数值的最小值。
grunt> Result = FOREACH B GENERATE group, MIN(A.a3);
grunt> DUMP Result;
Apache Pig MIN Function
在这里,我们得到了想要的输出。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4