在Hadoop上使用Apache-Pig无法识别JAR

时间:2016-08-02 11:39:52

标签: hadoop apache-pig hadoop2

我的目标是在我的猪脚本中使用鸽子的空间功能。为了使用鸽子功能,我在开始时注册了三个JAR(pigeon-0.2.1.jar,esri-geometry-api-1.2.1.jar和jts-1.8.jar),运行没有错误和警告。 当我在pig命令行(grunt)中运行pig命令时,一切都很好(除了一些删除警告,但是引用其他帖子这可以被忽略)但是只要我想运行像ST_MakePoint这样的pigeon命令就会出现错误:

ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve ST_MakePoint using imports: [, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.]

我正在使用:Ubuntu 14.04.4 LTS,Hadoop 2.7.1(单节点),猪0.15.0

有关如何解决此问题的任何建议吗?

1 个答案:

答案 0 :(得分:3)

第一路:

在Pig中调用语法:select up.object_name, up.procedure_name, case ua.position when 0 then 'FUNCTION' else 'PROCEDURE' end as type from user_procedures up left join user_arguments ua on ua.object_id = up.object_id and ua.subprogram_id = up.subprogram_id and position = 0 where up.object_type = 'PACKAGE' and up.object_name = 'TEST_PACKAGE' and up.procedure_name is not null; OBJECT_NAME PROCEDURE_NAME TYPE ------------------------------ ------------------------------ --------- TEST_PACKAGE TEST_FUNCTION FUNCTION TEST_PACKAGE TEST_PROCEDURE PROCEDURE

来自Github的源代码:

packagename.ClassName(arg0...)

语法就是

    package edu.umn.cs.pigeon;

    import java.io.IOException;

    import org.apache.pig.EvalFunc;
    import org.apache.pig.data.DataByteArray;
    import org.apache.pig.data.Tuple;

    import com.esri.core.geometry.Point;
    import com.esri.core.geometry.SpatialReference;
    import com.esri.core.geometry.ogc.OGCPoint;

    /**
     * @author Ahmed Eldawy
     *
     */

    public class MakePoint extends EvalFunc<DataByteArray> {

      @Override
      public DataByteArray exec(Tuple input) throws IOException {
        if (input.size() != 2)
          throw new IOException("MakePoint takes two numerical arguments");
        double x = ESRIGeometryParser.parseDouble(input.get(0));
        double y = ESRIGeometryParser.parseDouble(input.get(1));
        Point point = new Point(x, y);
        OGCPoint ogc_point = new OGCPoint(point, SpatialReference.create(4326));
        return new DataByteArray(ogc_point.asBinary().array());
      }
    }

第二种方式: 使用短名称

为避免编写完整的函数名称(包+类名),您可以使用&#39; pigeon_import.pig&#39;为所有函数创建短名称的文件。您可以下载文件here并将其放在Pigeon脚本旁边。要将此文件加载到脚本中,请将以下行发布到脚本的开头。 IMPORT&#39; pigeon_import.pig&#39 ;; 之后,您可以将信封函数写为ST_MakePoint而不是edu.umn.cs.pigeon.MakePoint

Reference Blog

希望这有帮助!!!