Skip to content

Commit 5660dba

Browse files
zhengruifengcloud-fan
authored andcommitted
[SPARK-53334][CONNECT] LiteralValueProtoConverter should keep the order of input map
### What changes were proposed in this pull request? - use `LinkedHashMap` in the `typedLit` test - make `LiteralValueProtoConverter` keep the order of input map ### Why are the changes needed? It might increase randomness of transformed literal values, e.g. the `typedLit` test, it is non-determinisitc ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? ci ### Was this patch authored or co-authored using generative AI tooling? no Closes #52078 from zhengruifeng/proto_test_map. Authored-by: Ruifeng Zheng <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent 33df1b6 commit 5660dba

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,7 @@ class PlanGenerationTestSuite
34053405
fn.typedLit(Some(1)),
34063406
fn.typedLit(Array(1, 2, 3)),
34073407
fn.typedLit(Seq(1, 2, 3)),
3408-
fn.typedLit(Map("a" -> 1, "b" -> 2)),
3408+
fn.typedLit(mutable.LinkedHashMap("a" -> 1, "b" -> 2)),
34093409
fn.typedLit(("a", 2, 1.0)),
34103410
fn.typedLit[Option[Int]](None),
34113411
fn.typedLit[Array[Option[Int]]](Array(Some(1))),
@@ -3414,9 +3414,20 @@ class PlanGenerationTestSuite
34143414
fn.typedlit[collection.immutable.Map[Int, Option[Int]]](
34153415
collection.immutable.Map(1 -> None)),
34163416
fn.typedLit(Seq(Seq(1, 2, 3), Seq(4, 5, 6), Seq(7, 8, 9))),
3417-
fn.typedLit(Seq(Map("a" -> 1, "b" -> 2), Map("a" -> 3, "b" -> 4), Map("a" -> 5, "b" -> 6))),
3418-
fn.typedLit(Map(1 -> Map("a" -> 1, "b" -> 2), 2 -> Map("a" -> 3, "b" -> 4))),
3419-
fn.typedLit((Seq(1, 2, 3), Map("a" -> 1, "b" -> 2), ("a", Map(1 -> "a", 2 -> "b")))))
3417+
fn.typedLit(
3418+
Seq(
3419+
mutable.LinkedHashMap("a" -> 1, "b" -> 2),
3420+
mutable.LinkedHashMap("a" -> 3, "b" -> 4),
3421+
mutable.LinkedHashMap("a" -> 5, "b" -> 6))),
3422+
fn.typedLit(
3423+
mutable.LinkedHashMap(
3424+
1 -> mutable.LinkedHashMap("a" -> 1, "b" -> 2),
3425+
2 -> mutable.LinkedHashMap("a" -> 3, "b" -> 4))),
3426+
fn.typedLit(
3427+
(
3428+
Seq(1, 2, 3),
3429+
mutable.LinkedHashMap("a" -> 1, "b" -> 2),
3430+
("a", mutable.LinkedHashMap(1 -> "a", 2 -> "b")))))
34203431
}
34213432

34223433
/* Window API */

sql/connect/common/src/main/scala/org/apache/spark/sql/connect/common/LiteralValueProtoConverter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ object LiteralValueProtoConverter {
439439
valueConverter: proto.Expression.Literal => V)(implicit
440440
tagK: ClassTag[K],
441441
tagV: ClassTag[V]): mutable.Map[K, V] = {
442-
val builder = mutable.HashMap.empty[K, V]
442+
val builder = mutable.LinkedHashMap.empty[K, V]
443443
val keys = map.getKeysList.asScala
444444
val values = map.getValuesList.asScala
445445
builder.sizeHint(keys.size)

0 commit comments

Comments
 (0)