Skip to content

Commit b517636

Browse files
committed
Revert "[SPARK-27278][SQL] Optimize GetMapValue when the map is a foldable and the key is not"
This reverts commit 5888b15.
1 parent ffb362a commit b517636

File tree

2 files changed

+0
-25
lines changed

2 files changed

+0
-25
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/ComplexTypes.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717

1818
package org.apache.spark.sql.catalyst.optimizer
1919

20-
import scala.collection.mutable
21-
2220
import org.apache.spark.sql.catalyst.expressions._
2321
import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, LogicalPlan}
2422
import org.apache.spark.sql.catalyst.rules.Rule
25-
import org.apache.spark.sql.catalyst.util.MapData
26-
import org.apache.spark.sql.types.MapType
2723

2824
/**
2925
* Simplify redundant [[CreateNamedStructLike]], [[CreateArray]] and [[CreateMap]] expressions.
@@ -63,16 +59,6 @@ object SimplifyExtractValueOps extends Rule[LogicalPlan] {
6359
Literal(null, ga.dataType)
6460
}
6561
case GetMapValue(CreateMap(elems), key) => CaseKeyWhen(key, elems)
66-
// The case below happens when the map is foldable, but the key is not, so ConstantFolding
67-
// converts the map in a Literal, but the GetMapValue is still there since the key is not
68-
// foldable. It cannot happen in any other case.
69-
case GetMapValue(Literal(map: MapData, MapType(kt, vt, _)), key) if !key.foldable =>
70-
val elems = new mutable.ListBuffer[Literal]
71-
map.foreach(kt, vt, (key, value) => {
72-
elems.append(Literal(key, kt))
73-
elems.append(Literal(value, vt))
74-
})
75-
CaseKeyWhen(key, elems.result())
7662
}
7763
}
7864
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/complexTypesSuite.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,4 @@ class ComplexTypesSuite extends PlanTest with ExpressionEvalHelper {
452452
checkEvaluation(GetMapValue(mb0, Literal(Array[Byte](2, 1), BinaryType)), "2")
453453
checkEvaluation(GetMapValue(mb0, Literal(Array[Byte](3, 4))), null)
454454
}
455-
456-
test("SPARK-27278: simplify map access with non-foldable key and foldable map") {
457-
val query = relation.select(GetMapValue(CreateMap(Seq(
458-
1L, "a",
459-
2L, "b")), 'id) as "a")
460-
val expected = relation.select(
461-
CaseWhen(Seq(
462-
(EqualTo('id, 1L), "a"),
463-
(EqualTo('id, 2L), "b"))) as "a")
464-
checkRule(query, expected)
465-
}
466455
}

0 commit comments

Comments
 (0)