-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-48186][SQL] Add support for AbstractMapType
### What changes were proposed in this pull request? Addition of an abstract MapType (similar to abstract ArrayType in sql internal types) which accepts `StringTypeCollated` as `keyType` & `valueType`. Apart from extending this interface for all Spark functions, this PR also introduces collation awareness for json expression: schema_of_json. ### Why are the changes needed? This is needed in order to enable collation support for functions that use collated maps. ### Does this PR introduce _any_ user-facing change? Yes, users should now be able to use collated strings within arguments for json function: schema_of_json. ### How was this patch tested? E2e sql tests. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #46458 from uros-db/abstract-map. Authored-by: Uros Bojanic <157381213+uros-db@users.noreply.github.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
- Loading branch information
Showing
4 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
sql/api/src/main/scala/org/apache/spark/sql/internal/types/AbstractMapType.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.internal.types | ||
|
||
import org.apache.spark.sql.types.{AbstractDataType, DataType, MapType} | ||
|
||
|
||
/** | ||
* Use AbstractMapType(AbstractDataType, AbstractDataType) | ||
* for defining expected types for expression parameters. | ||
*/ | ||
case class AbstractMapType( | ||
keyType: AbstractDataType, | ||
valueType: AbstractDataType | ||
) extends AbstractDataType { | ||
|
||
override private[sql] def defaultConcreteType: DataType = | ||
MapType(keyType.defaultConcreteType, valueType.defaultConcreteType, valueContainsNull = true) | ||
|
||
override private[sql] def acceptsType(other: DataType): Boolean = { | ||
other.isInstanceOf[MapType] && | ||
keyType.acceptsType(other.asInstanceOf[MapType].keyType) && | ||
valueType.acceptsType(other.asInstanceOf[MapType].valueType) | ||
} | ||
|
||
override private[spark] def simpleString: String = | ||
s"map<${keyType.simpleString}, ${valueType.simpleString}>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters