1.hive函数计算
计算公式如下:
6378137*2*ASIN(SQRT(POWER(SIN((ta.start_point_lat-ta.end_point_lat)*ACOS(-1)/360),2) +
COS(ta.start_point_lat*ACOS(-1)/180)*COS(ta.end_point_lat*ACOS(-1)/180)
*POWER(SIN((ta.start_point_lng-ta.end_point_lng)*ACOS(-1)/360),2)))
as distance
2.UDF 计算
package com.sankuai.general.dw.udf.locationDistance;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hive.ql.exec.UDF;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class LocationDistance extends UDF {
private static final double EARTH_RADIUS = 6378137;
private static double rad(double d){
return d * Math.PI / 180.0;
}
public double evaluate(dou