ramitg254 commented on code in PR #6813: URL: https://github.com/apache/hive/pull/6813#discussion_r4102970919
########## ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomFromGeoHash.java: ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.hadoop.hive.ql.udf.esri; + +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; +import org.locationtech.jts.geom.Polygon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Description( + name = "ST_GeomFromGeoHash", + value = """ + _FUNC_(geohash) - polygon for the geohash cell + _FUNC_(geohash, precision) - polygon using the first precision characters + """, + extended = """ + SELECT ST_AsText(_FUNC_('9ptty', 5)); + """) +public class ST_GeomFromGeoHash extends ST_Geometry { + + static final Logger LOG = LoggerFactory.getLogger(ST_GeomFromGeoHash.class.getName()); + + public BytesWritable evaluate(Text geohashText) { + return evaluate(geohashText, null); + } + + public BytesWritable evaluate(Text geohashText, IntWritable precisionArg) { + String geohash = geohashText != null ? geohashText.toString().trim() : null; + if (geohash == null || geohash.isEmpty()) { + LogUtils.Log_ArgumentsNull(LOG); + return null; + } + + int characterPrecision = GeoHashUtils.resolveDecodePrecision(precisionArg == null ? null : precisionArg.get(), + geohash.length()); + if (characterPrecision < 0) { + LogUtils.Log_InvalidPrecision(LOG, GeoHashUtils.MIN_CHARACTER_PRECISION, + Math.min(geohash.length(), GeoHashUtils.MAX_CHARACTER_PRECISION)); Review Comment: when we are construct geometry from geoshash string, specifying precision beyond string length doesn't yield anything and will be wrong as per behaviour: https://github.com/apache/hive/pull/6813#discussion_r4102893643 so for string of length 10 precison 12 is wrong will be wrong as construction of geometry depends on the no. of chars in the string we are gonna use which are at max 10 in that case -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
