VenuReddy2103 commented on a change in pull request #3436: [CARBONDATA-3548]Geospatial Support: Modified to create and load the table with a nonschema dimension sort column. And added InPolygon UDF
URL: https://github.com/apache/carbondata/pull/3436#discussion_r373027979 ########## File path: core/src/main/java/org/apache/carbondata/core/util/GeoHashDefault.java ########## @@ -0,0 +1,255 @@ +package org.apache.carbondata.core.util; + +import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException; +import org.apache.carbondata.core.constants.CarbonCommonConstants; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class GeoHashDefault implements CustomIndex<Long, String, List<Long[]>> { + // 角度转弧度的转换因子 + private final static double CONVERT_FACTOR = 180.0; + // 地球半径 + private final static double EARTH_RADIUS = 6371004.0; + + private static double transValue = Math.PI / CONVERT_FACTOR * EARTH_RADIUS; // 赤道经度1度或者纬度1度对应的地理空间距离 + + private double oriLongitude = 0; // 坐标原点的经度 + + private double oriLatitude = 0; // 坐标原点的纬度 + + private double userDefineMaxLongitude = 0; // 用户定义地图最大的经度 + + private double userDefineMaxLatitude = 0; // 用户定义地图最大的纬度 + + private double userDefineMinLongitude = 0; // 用户定义地图最小的经度 + + private double userDefineMinLatitude = 0; // 用户定义地图最小的纬度 + + private double CalculateMaxLongitude = 0; // 计算后得出的补齐地图最大的经度 + + private double CalculateMaxLatitude = 0; // 计算后得出的补齐地图最大的纬度 + + private int gridSize = 0; //栅格长度单位是米 + + private double mCos; // 坐标原点纬度的余玄数值 + + private double deltaY = 0; // 每一个gridSize长度对应Y轴的度数 + + private double deltaX = 0; // 每一个gridSize长度应X轴的度数 + + private double deltaYByRatio = 0; // 每一个gridSize长度对应Y轴的度数 * 系数 + + private double deltaXByRatio = 0; // 每一个gridSize长度应X轴的度数 * 系数 + + private int cutLevel = 0; // 对整个区域切的刀数(一横一竖为1刀),就是四叉树的深度 + + private int totalRowNumber = 0; // 整个区域的行数,从左上开始到右下 + + private int totalCloumnNumber = 0; // 整个区域的列数,从左上开始到右下 + + private int udfRowStartNumber = 0; // 用户定义区域的开始行数 + + private int udfRowEndNumber = 0; // 用户定义区域的结束的行数 + + private int udfCloumnStartNumber = 0; // 用户定义区域的开始列数 + + private int udfCloumnEndNumber = 0; // 用户定义区域的开始结束列数 + + private double lon0 = 0; // 栅格最小数值的经度坐标,最小栅格坐标是扩展区域最左上角的经纬度坐标 + + private double lat0 = 0; // 栅格最小数值的纬度坐标,最小栅格坐标是扩展区域最左上角的经纬度坐标 + + private double lon0ByRation = 0; // *系数的常量 + private double lat0ByRation = 0; // *系数的常量 + + private int conversionRatio = 1; // 系数,用于将double类型的经纬度,转换成int类型后计算 + + + @Override + public void validateOption(Map<String, String> properties) throws Exception { + String option = properties.get(CarbonCommonConstants.INDEX_HANDLER); + if (option == null || option.isEmpty()) { + throw new MalformedCarbonCommandException( + String.format("%s property is invalid.", CarbonCommonConstants.INDEX_HANDLER)); + } + + String commonKey = "." + option + "."; + String sourceColumnsOption = properties.get(CarbonCommonConstants.INDEX_HANDLER + commonKey + "sourcecolumns"); + if (sourceColumnsOption == null) { + throw new MalformedCarbonCommandException( + String.format("%s property is invalid. %s property is not specified.", + CarbonCommonConstants.INDEX_HANDLER, + CarbonCommonConstants.INDEX_HANDLER + commonKey + "sourcecolumns")); + } + + if (sourceColumnsOption.split(",").length != 2) { + throw new MalformedCarbonCommandException( + String.format("%s property is invalid. %s property must have 2 columns.", + CarbonCommonConstants.INDEX_HANDLER, + CarbonCommonConstants.INDEX_HANDLER + commonKey + "sourcecolumns")); + } + + String type = properties.get(CarbonCommonConstants.INDEX_HANDLER + commonKey + "type"); + if (type != null && !"geohash".equalsIgnoreCase(type)) { + throw new MalformedCarbonCommandException( + String.format("%s property is invalid. %s property must be geohash for this class", + CarbonCommonConstants.INDEX_HANDLER, + CarbonCommonConstants.INDEX_HANDLER + commonKey + "type")); + } + + properties.put(CarbonCommonConstants.INDEX_HANDLER + commonKey + "type", "geohash"); + + String sourceDataTypes = properties.get(CarbonCommonConstants.INDEX_HANDLER + commonKey + "sourcecolumntypes"); + String[] srcTypes = sourceDataTypes.split(","); + for (String srcdataType : srcTypes) { + if (!"int".equalsIgnoreCase(srcdataType)) { + throw new MalformedCarbonCommandException( + String.format("%s property is invalid. source columns datatype must be int", + CarbonCommonConstants.INDEX_HANDLER)); + } + } + + String dataType = properties.get(CarbonCommonConstants.INDEX_HANDLER + commonKey + "datatype"); + if (dataType != null && !"long".equalsIgnoreCase(dataType)) { Review comment: done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |