Hadoop 向udf发送矩阵
我对UDF猪拉丁语有问题。 我正在尝试实现一个系统,该系统必须验证本地存储的矩阵和hadoop存储库中存储的一组矩阵之间是否存在“映射”。 对于映射,我的意思是,如果hadoop中存在一个存储矩阵的行和列的排列,它将矩阵转换为与本地存储矩阵相同的矩阵。 因为矩阵可以有数百个元素,所以我想在hadoop上执行映射算法以使用并行性。 我正在寻找UDF pig拉丁语,但我不知道如何将本地矩阵“发送”到UDF函数Hadoop 向udf发送矩阵,hadoop,matrix,user-defined-functions,apache-pig,Hadoop,Matrix,User Defined Functions,Apache Pig,我对UDF猪拉丁语有问题。 我正在尝试实现一个系统,该系统必须验证本地存储的矩阵和hadoop存储库中存储的一组矩阵之间是否存在“映射”。 对于映射,我的意思是,如果hadoop中存在一个存储矩阵的行和列的排列,它将矩阵转换为与本地存储矩阵相同的矩阵。 因为矩阵可以有数百个元素,所以我想在hadoop上执行映射算法以使用并行性。 我正在寻找UDF pig拉丁语,但我不知道如何将本地矩阵“发送”到UDF函数 public class Mapping extends EvalFunc<Stri
public class Mapping extends EvalFunc<String>
{
private int[][] matrixToMap; //The local matrix i want to map
public String exec(Tuple input) throws IOException { //Here the tuple are the matrix stored in hadoop
if (input == null || input.size() == 0)
return null;
try{
//HERE THE CODE FOR THE MAPPING
}
}
}
假设pig脚本是在java程序中调用的,并且本地矩阵存储在java矩阵中。因此java程序看起来像:
int [][] localMatrix;
pigServer.registerJar("/Users/myudfs.jar");
//Some code to make Mapping.matrixToMap = localMatrix
pigServer.registerQuery("records = LOAD 'Sample7.txt';");
pigServer.registerQuery("B = FOREACH records GENERATE myudfs.Mapping(formula);");
你知道吗?
谢谢您可以像在自定义项的构造函数中那样初始化类变量:
public class Mapping extends EvalFunc<String>
{
private int[][] matrixToMap; //The local matrix i want to map
public Mapping(String filename) {
// Code to populate matrixToMap from the data in filename
}
public String exec(Tuple input) throws IOException { //Here the tuple are the matrix stored in hadoop
if (input == null || input.size() == 0)
return null;
try{
//HERE THE CODE FOR THE MAPPING
}
}
}
使用此方法,您的矩阵必须存储在HDFS上,以便初始化并调用构造函数的映射器或还原器能够访问数据。谢谢您的回答,我非常感谢。因此,如果我理解,您建议:1)将本地矩阵存储在hdfs上2)定义映射myudfs.Mapping('/path/to/matrix/on/hdfs');3) pigServer.registerJar(“/Users/myudfs.jar”);4) registerQuery(“records=LOAD'Sample7.txt';”;我错过了关于如何通过Java调用它的部分。在这种情况下,我不确定
DEFINE
语句是否能正常工作。但是试试看。
public class Mapping extends EvalFunc<String>
{
private int[][] matrixToMap; //The local matrix i want to map
public Mapping(String filename) {
// Code to populate matrixToMap from the data in filename
}
public String exec(Tuple input) throws IOException { //Here the tuple are the matrix stored in hadoop
if (input == null || input.size() == 0)
return null;
try{
//HERE THE CODE FOR THE MAPPING
}
}
}
DEFINE Mapping myudfs.Mapping('/path/to/matrix/on/HDFS');