Java 基本数学运算

Java 基本数学运算,java,hadoop,apache-pig,Java,Hadoop,Apache Pig,如何使用Pig拉丁语进行基本的数学运算? 我进入Grunt shell并尝试了例如dump1+2,但得到了 2014-11-28 23:23:48011[main]错误org.apache.pig.tools.grunt.grunt -错误2997:遇到IOException。未找到以前定义的别名。请定义别名并使用“转储”运算符 更新 DUMP B; 执行A=1+2转储A我得到: grunt> A = 1 + 2 DUMP A >> [ENTER] >> [ENT

如何使用Pig拉丁语进行基本的数学运算?
我进入Grunt shell并尝试了例如
dump1+2,但得到了

2014-11-28 23:23:48011[main]错误org.apache.pig.tools.grunt.grunt -错误2997:遇到IOException。未找到以前定义的别名。请定义别名并使用“转储”运算符

更新

DUMP B;
执行
A=1+2转储A
我得到:

grunt> A = 1 + 2 DUMP A
>> [ENTER]
>> [ENTER]
...

这给出了使用PIG的算术运算符的示例


DUMP用于显示结果数据数组。

不能像pythonshell那样使用pig-grunt shell。Pig是数据流语言,它将关系作为输入,并生成另一个关系作为输出。 清管器STMT通常以这种形式组织

1.LOAD stmt to load data from local file system or HDFS file system
2.A series of stmts to process the data using pig built-in function or Custom UDF
3.DUMP stmt to display the data in console, it will take only relation as input(No constant values as you mentioned)
4.STORE stmt to store the output into local file system or HDFS file system
示例:
input.txt

1,5,10.0
2,6,20.0
3,7,30.0
使用分隔符“,”从本地文件系统加载文件。

A = LOAD 'input.txt' USING PigStorage(',') AS (f1:int,f2:int,f3:float);
处理数据、添加、差异和div

B = FOREACH A GENERATE f1+10 AS sum, f2-2 AS diff, f3/10 AS div;
在控制台中显示结果

DUMP B;
您可以从grunt shell或thru pig脚本执行一系列清管器stmt

Grunt外壳:

grunt> A = LOAD 'input.txt' USING PigStorage(',') AS (f1:int,f2:int,f3:float);
grunt> B = FOREACH A GENERATE f1+10 AS sum, f2-2 AS diff, f3/10 AS div;
grunt> DUMP B;
(11,2,1.0)
(12,3,2.0)
(13,4,3.0)
1.Add the above three lines of pig stmt into a file Ex: test.pig
2.Run from terminal
清管器脚本:

grunt> A = LOAD 'input.txt' USING PigStorage(',') AS (f1:int,f2:int,f3:float);
grunt> B = FOREACH A GENERATE f1+10 AS sum, f2-2 AS diff, f3/10 AS div;
grunt> DUMP B;
(11,2,1.0)
(12,3,2.0)
(13,4,3.0)
1.Add the above three lines of pig stmt into a file Ex: test.pig
2.Run from terminal
清管器-x本地测试.pig(本地模式)

pig test.pig(或)pig-x mapreduce test.pig(mapreduce模式)

请参考基本的清管器文档,它将为您提供更多帮助