szehon-ho commented on code in PR #52491: URL: https://github.com/apache/spark/pull/52491#discussion_r2393531931
########## sql/api/src/main/scala/org/apache/spark/sql/types/CrsMappings.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.spark.sql.types; + +import java.util.HashMap; + +/* + * Class for maintaining mappings between supported SRID values and the string ID of the + * corresponding CRS. + */ +public class CrsMappings { + + // We implement this class as a singleton (we disallow construction). + private CrsMappings() {} + + private static CrsMappings instance = new CrsMappings(); Review Comment: also , question is it worth to make get() lazily or not? (else why not just expose INSTANCE) ########## sql/api/src/main/scala/org/apache/spark/sql/types/GeographyType.scala: ########## @@ -0,0 +1,274 @@ +/* + * 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.spark.sql.types + +import org.json4s.JsonAST.{JString, JValue} + +import org.apache.spark.SparkIllegalArgumentException +import org.apache.spark.annotation.Experimental + +/** + * The data type representing GEOGRAPHY values which are spatial objects, as defined in the + * Open Geospatial Consortium (OGC) Simple Feature Access specification + * (https://portal.ogc.org/files/?artifact_id=25355), with a geographic coordinate system. + */ +@Experimental +class GeographyType private (val crs: String, val algorithm: EdgeInterpolationAlgorithm) + extends AtomicType + with Serializable { + + /** + * Spatial Reference Identifier (SRID) value of the geography type. + */ + val srid: Int = toSrid(crs) + + /** + * The default size of a value of the GeographyType is 2048 bytes, which can store roughly 120 + * 2D points. + */ + override def defaultSize: Int = 2048 + + /** + * The GeographyType is a mixed SRID type iff the SRID is GEOGRAPHY_MIXED_SRID. + * Semantically, this means that different SRID values per row are allowed. + */ + def isMixedSrid: Boolean = srid == GeographyType.GEOGRAPHY_MIXED_SRID + + /** + * Type name that is displayed to users. + */ + override def typeName: String = { + if (isMixedSrid) { + // The mixed SRID type is displayed with a special specifier value "ANY". + "geography(any)" + } else { + // The fixed SRID type is always displayed with the appropriate SRID value. + s"geography($srid)" + } + } + + /** + * String representation of the GeographyType, which uses SRID for fixed SRID types and "ANY" + * for mixed SRID types, providing a clear and concise user-friendly format for this type. + */ + override def toString: String = { + if (isMixedSrid) { + // The mixed SRID type is displayed with a special specifier value "ANY". + "GeographyType(ANY)" + } else { + // The fixed SRID type is always displayed with the appropriate SRID value. + s"GeographyType($srid)" + } + } + + /** + * JSON representation of the GeographyType, which uses the CRS string and edge interpolation + * algorithm string, in line with the current storage specifications (e.g. Parquet, Delta, + * Iceberg). Note that mixed SRID is disallowed, and only fixed SRID types can be stored. This + * is also in accordance to storage formats. + */ + override def jsonValue: JValue = JString(s"geography($crs, $algorithm)") + + private[spark] override def asNullable: GeographyType = this + + /** + * Two types are considered equal iff they are both GeographyTypes and have the same SRID value. + */ + override def equals(obj: Any): Boolean = { + obj match { + case g: GeographyType => + // Iff two GeographyTypes have the same SRID, they are considered equal. + g.srid == srid Review Comment: do we need to check alg? -- 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]
