Skip to content

Commit

Permalink
add sort to make result deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
xxchan committed Aug 14, 2024
1 parent 5f1ab1a commit f22c883
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/connector/codec/src/decoder/avro/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ impl<'a> AvroParseOptions<'a> {
.create_array_builder(map.len());
// Since the map is HashMap, we can ensure
// key is non-null and unique, keys and values have the same length.
for (k, v) in map {

// NOTE: HashMap's iter order is non-deterministic, but MapValue's
// order matters. We sort by key here to have deterministic order
// in tests. We might consider removing this, or make all MapValue sorted
// in the future.
for (k, v) in map.iter().sorted_by_key(|(k, _v)| *k) {
let value_datum = Self {
schema,
relax_numeric: self.relax_numeric,
Expand Down
20 changes: 10 additions & 10 deletions src/connector/codec/tests/integration_tests/avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,28 +948,28 @@ fn test_map() {
])
Owned([
StructValue(
Utf8("m2"),
Utf8("m1"),
[
StructValue(
Utf8("d"),
Int32(4),
Utf8("a"),
Int32(1),
),
StructValue(
Utf8("c"),
Int32(3),
Utf8("b"),
Int32(2),
),
],
),
StructValue(
Utf8("m1"),
Utf8("m2"),
[
StructValue(
Utf8("b"),
Int32(2),
Utf8("c"),
Int32(3),
),
StructValue(
Utf8("a"),
Int32(1),
Utf8("d"),
Int32(4),
),
],
),
Expand Down

0 comments on commit f22c883

Please sign in to comment.