Skip to content

Commit

Permalink
enhancement(vrl): use undefined when merging instead of null (vec…
Browse files Browse the repository at this point in the history
…tordotdev#14670)

use undefined when merging instead of null
  • Loading branch information
fuchsnj authored Oct 4, 2022
1 parent ca8faf5 commit 9182031
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/value/src/kind/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<T: Ord + Clone> Collection<T> {
}
} else if !overwrite {
// other is missing this field, which returns null
self_kind.add_null();
self_kind.add_undefined();
}
}

Expand All @@ -246,7 +246,7 @@ impl<T: Ord + Clone> Collection<T> {
} else {
for (key, other_kind) in other.known {
// self is missing this field, which returns null
self.known.insert(key, other_kind.or_null());
self.known.insert(key, other_kind.or_undefined());
}
}
self.unknown.merge(other.unknown, overwrite);
Expand Down Expand Up @@ -530,8 +530,8 @@ mod tests {
other: Collection::from(BTreeMap::from([("bar", Kind::bytes())])),
overwrite: false,
want: Collection::from(BTreeMap::from([
("foo", Kind::integer().or_null()),
("bar", Kind::bytes().or_null()),
("foo", Kind::integer().or_undefined()),
("bar", Kind::bytes().or_undefined()),
])),
},
),
Expand All @@ -558,7 +558,7 @@ mod tests {
overwrite: false,
want: Collection::from(BTreeMap::from([
("foo", Kind::integer().or_bytes()),
("bar", Kind::boolean().or_null()),
("bar", Kind::boolean().or_undefined()),
])),
},
),
Expand Down
8 changes: 4 additions & 4 deletions lib/value/src/kind/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ mod tests {
Kind::object(BTreeMap::from([
("qux".into(), Kind::bytes().or_integer()),
("quux".into(), Kind::boolean().or_regex()),
("this".into(), Kind::timestamp().or_null()),
("that".into(), Kind::null()),
("this".into(), Kind::timestamp().or_undefined()),
("that".into(), Kind::null().or_undefined()),
])),
),
("bar".into(), Kind::integer().or_null()),
("baz".into(), Kind::boolean().or_null()),
("bar".into(), Kind::integer().or_undefined()),
("baz".into(), Kind::boolean().or_undefined()),
])),
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# result: {
# "object": {
# "x": { "boolean": true, "null": true },
# "y": { "bytes": true, "null": true }
# "x": { "boolean": true, "undefined": true },
# "y": { "bytes": true, "undefined": true }
# }
# }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# result: {
# "x": {},
# "x_type": { "object": {"foo": {"boolean": true, "null": true }}},
# "x_type": { "object": {"foo": {"boolean": true, "undefined": true }}},
# "y": { "foo": true },
# "y_type": { "object": {"foo": {"boolean": true, "null": true }}},
# "y_type": { "object": {"foo": {"boolean": true, "undefined": true }}},
# "x2": {},
# "x2_type": { "object": {"foo": {"boolean": true, "null": true }}},
# "x2_type": { "object": {"foo": {"boolean": true, "undefined": true }}},
# "y2": { "foo": true },
# "y2_type": { "object": {"foo": {"boolean": true, "null": true }}}
# "y2_type": { "object": {"foo": {"boolean": true, "undefined": true }}}
# }

.x = if true {
Expand Down

0 comments on commit 9182031

Please sign in to comment.