1

Recently writing a UDF for hash geometry points on HIVE. In this udf I import com.vividsolutions.jts.geom.

The code is below,

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.hadoop.hive.ql.exec.UDF;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;

public class tenthudf extends UDF{
    public String evaluate (String pointstr,Integer level){

        int sindex=pointstr.indexOf('(');
        int eindex=pointstr.indexOf(')');

        String[] temps=(pointstr.substring(sindex+1,eindex)).split(" ");
        double lon=Double.parseDouble(temps[0]);
        double lat=Double.parseDouble(temps[1]);

        GeometryFactory geometryFactory = new GeometryFactory();

        GeoHashGeometry gg=new GeoHashGeometry(level);

        Coordinate coord = new Coordinate(lon,lat);
        Point point = geometryFactory.createPoint(coord);

        return gg.encodePoint(point);
    }
}

The code runs on my eclipse but when I upload and register it in HIVE. Then I use it as:

SELECT tenthhh('POINT (103.95651 31.32475)',8)

Error goes as:

Error while compiling statement: FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments '8': org.apache.hadoop.hive.ql.metadata.HiveException: Unable to execute method public java.lang.String com.zebra.drivingbehavior.tenthudf.evaluate(java.lang.String,java.lang.Integer) on object com.zebra.drivingbehavior.tenthudf@3000f271 of class com.zebra.drivingbehavior.tenthudf with arguments {POINT (103.95651 31.32475):java.lang.String, 8:java.lang.Integer} of size 2

I founded out the min function works is:

public String evaluate (String pointstr,Integer level){

        int sindex=pointstr.indexOf('(');
        int eindex=pointstr.indexOf(')');

        String[] temps=(pointstr.substring(sindex+1,eindex)).split(" ");
        double lon=Double.parseDouble(temps[0]);
        double lat=Double.parseDouble(temps[1]);

        //GeometryFactory geometryFactory = new GeometryFactory();

        //GeoHashGeometry gg=new GeoHashGeometry(level);

        //Coordinate coord = new Coordinate(lon,lat);
        //Point point = geometryFactory.createPoint(coord);

        //return gg.encodePoint(point);
        return pointstr+" "+level.toString()+" "+String.valueOf(lon)+" "+String.valueOf(lat);
    }

so I'm nearly sure the trouble happens when I use external library jar. I use maven assembly plugin to package the jar file and I checked the existence of the dependency jars.

I searched on stack overflow and found two similar problems,while neither receive useful answers...

Hive gives SemanticException [Error 10014]: when Running my UDF

Hadoop Hive UDF with external library

mrsrinivas
  • 34,112
  • 13
  • 125
  • 125
Yi LIU
  • 11
  • 3

0 Answers0