Skip to content

Commit 2f587d4

Browse files
author
Piotr Fałdrowicz
committed
fixed ordering of map fields
1 parent 9a859cb commit 2f587d4

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/typeinformation/internal/typedobject/TypedJavaMapBasedTypeInformation.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package pl.touk.nussknacker.engine.process.typeinformation.internal.typedobject
22

3-
import java.{util => jutil}
3+
import java.{util, util => jutil}
44
import org.apache.flink.api.common.typeinfo.TypeInformation
55
import org.apache.flink.api.common.typeutils.{TypeSerializer, TypeSerializerSnapshot}
66

@@ -24,7 +24,7 @@ case class TypedJavaMapSerializer(
2424
override def duplicate(serializers: Array[(String, TypeSerializer[_])]): TypeSerializer[jutil.Map[String, AnyRef]] =
2525
TypedJavaMapSerializer(serializers)
2626

27-
override def createInstance(): jutil.Map[String, AnyRef] = new jutil.HashMap()
27+
override def createInstance(): jutil.Map[String, AnyRef] = new util.LinkedHashMap(serializers.length)
2828

2929
override def snapshotConfiguration(
3030
snapshots: Array[(String, TypeSerializerSnapshot[_])]

engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/typeinformation/internal/typedobject/TypedObjectBasedTypeInformation.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class TypedObjectBasedTypeInformation[T: ClassTag](informations: Array[
3131
extends TypeInformation[T] {
3232

3333
def this(fields: Map[String, TypeInformation[_]]) = {
34-
this(fields.toArray.sortBy(_._1))
34+
this(fields.toArray)
3535
}
3636

3737
override def isBasicType: Boolean = false

engine/flink/executor/src/test/scala/pl/touk/nussknacker/engine/process/typeinformation/TypingResultAwareTypeInformationDetectionSpec.scala

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import pl.touk.nussknacker.engine.process.typeinformation.internal.typedobject._
2929
import pl.touk.nussknacker.engine.process.typeinformation.testTypedObject.CustomTypedObject
3030

3131
import java.time.{LocalDate, LocalDateTime, LocalTime}
32+
import scala.collection.immutable.ListMap
3233
import scala.jdk.CollectionConverters._
3334

3435
@silent("deprecated")
@@ -43,7 +44,7 @@ class TypingResultAwareTypeInformationDetectionSpec
4344
test("test map serialization") {
4445
val map = Map("intF" -> 11, "strF" -> "sdfasf", "longF" -> 111L, "fixedLong" -> 12L, "taggedString" -> "1")
4546
val typingResult = Typed.record(
46-
Map(
47+
ListMap(
4748
"intF" -> Typed[Int],
4849
"strF" -> Typed[String],
4950
"longF" -> Typed[Long],
@@ -61,10 +62,10 @@ class TypingResultAwareTypeInformationDetectionSpec
6162

6263
assertMapSerializers(
6364
typeInfo.createSerializer(executionConfigWithoutKryo),
64-
("fixedLong", new LongSerializer),
6565
("intF", new IntSerializer),
66-
("longF", new LongSerializer),
6766
("strF", new StringSerializer),
67+
("longF", new LongSerializer),
68+
("fixedLong", new LongSerializer),
6869
("taggedString", new StringSerializer)
6970
)
7071
}
@@ -87,7 +88,7 @@ class TypingResultAwareTypeInformationDetectionSpec
8788

8889
test("test context serialization") {
8990
val ctx = Context("11").copy(variables =
90-
Map(
91+
ListMap(
9192
"one" -> 11,
9293
"two" -> "ala",
9394
"three" -> Map("key" -> "value"),
@@ -96,7 +97,7 @@ class TypingResultAwareTypeInformationDetectionSpec
9697
)
9798
)
9899
val vCtx = ValidationContext(
99-
Map(
100+
ListMap(
100101
"one" -> Typed[Int],
101102
"two" -> Typed[String],
102103
"three" -> Typed.record(Map("key" -> Typed[String]), Typed.typedClass[Map[String, Any]]),
@@ -117,11 +118,11 @@ class TypingResultAwareTypeInformationDetectionSpec
117118

118119
assertSerializersInContext(
119120
typeInfo.createSerializer(executionConfigWithoutKryo),
120-
("arrayOfInts", _ shouldBe new GenericArraySerializer(classOf[Integer], new IntSerializer)),
121-
("arrayOfStrings", _ shouldBe new StringArraySerializer),
122121
("one", _ shouldBe new IntSerializer),
122+
("two", _ shouldBe new StringSerializer),
123123
("three", assertMapSerializers(_, ("key", new StringSerializer))),
124-
("two", _ shouldBe new StringSerializer)
124+
("arrayOfStrings", _ shouldBe new StringArraySerializer),
125+
("arrayOfInts", _ shouldBe new GenericArraySerializer(classOf[Integer], new IntSerializer)),
125126
)
126127
}
127128

utils/utils/src/main/scala/pl/touk/nussknacker/engine/util/json/ToJsonEncoder.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.circe.Json._
99
import pl.touk.nussknacker.engine.api.DisplayJson
1010
import java.util.ServiceLoader
1111
import java.util.UUID
12+
import scala.collection.immutable.ListMap
1213
import scala.jdk.CollectionConverters._
1314

1415
object ToJsonEncoder {
@@ -66,7 +67,7 @@ case class ToJsonEncoder(
6667
case a: UUID => safeString(a.toString)
6768
case a: DisplayJson => a.asJson
6869
case a: scala.collection.Map[_, _] => encodeMap(a.toMap)
69-
case a: java.util.Map[_, _] => encodeMap(a.asScala.toMap)
70+
case a: java.util.Map[_, _] => encode(ListMap.from(a.asScala))
7071
case a: Iterable[_] => fromValues(a.map(encode))
7172
case a: Enum[_] => safeString(a.toString)
7273
case a: java.util.Collection[_] => fromValues(a.asScala.map(encode))

0 commit comments

Comments
 (0)