cloud-fan commented on a change in pull request #24223: [SPARK-27278][SQL]
Optimize GetMapValue when the map is a foldable and the key is not
URL: https://github.com/apache/spark/pull/24223#discussion_r271560401
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/ComplexTypes.scala
##########
@@ -59,6 +63,16 @@ object SimplifyExtractValueOps extends Rule[LogicalPlan] {
Literal(null, ga.dataType)
}
case GetMapValue(CreateMap(elems), key) => CaseKeyWhen(key, elems)
+ // The case below happens when the map is foldable, but the key is not,
so ConstantFolding
+ // converts the map in a Literal, but the GetMapValue is still there
since the key is not
+ // foldable. It cannot happen in any other case.
+ case GetMapValue(Literal(map: MapData, MapType(kt, vt, _)), key) if
!key.foldable =>
+ val elems = new mutable.ListBuffer[Literal]
+ map.foreach(kt, vt, (key, value) => {
+ elems.append(Literal(key, kt))
+ elems.append(Literal(value, vt))
+ })
+ CaseKeyWhen(key, elems.result())
Review comment:
Why is `CaseKeyWhen` faster than `GetMapValue`? they both do a linear scan
right?
----------------------------------------------------------------
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]