maropu commented on a change in pull request #24179: [SPARK-27241][SQL] Support
map_keys in SelectedField
URL: https://github.com/apache/spark/pull/24179#discussion_r268137902
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SelectedField.scala
##########
@@ -97,6 +97,19 @@ object SelectedField {
val MapType(keyType, _, valueContainsNull) = child.dataType
val opt = dataTypeOpt.map(dt => MapType(keyType, dt,
valueContainsNull))
selectField(child, opt)
+ case MapKeys(child) =>
+ val MapType(_, valueType, valueContainsNull) = child.dataType
+ // MapKeys does not select a field from a struct (i.e. prune the
struct) so it can't be
+ // the top-level extractor. However it can be part of an extractor
chain.
+ val newKeyType = dataTypeOpt match {
+ case None => None
+ case Some(ArrayType(dataType, _)) => Some(dataType)
+ case Some(x) =>
+ // This should not happen.
+ throw new AnalysisException(s"DataType '$x' is not supported by
MapKeys.")
+ }
+ val opt = dataTypeOpt.map(dt => MapType(newKeyType.get, valueType,
valueContainsNull))
Review comment:
nit: like this?
```
case MapKeys(child) =>
val MapType(_, valueType, valueContainsNull) = child.dataType
// MapKeys does not select a field from a struct (i.e. prune the
struct) so it can't be
// the top-level extractor. However it can be part of an extractor
chain.
val opt = dataTypeOpt.map {
case ArrayType(dataType, _) => MapType(dataType, valueType,
valueContainsNull)
case x =>
// This should not happen.
throw new AnalysisException(s"DataType '$x' is not supported by
MapKeys.")
}
selectField(child, opt)
```
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]