From 9182031cb173f467d1d293c1e7853eb0e2681f5c Mon Sep 17 00:00:00 2001 From: Nathan Fox Date: Tue, 4 Oct 2022 14:42:25 -0400 Subject: [PATCH] enhancement(vrl): use `undefined` when merging instead of `null` (#14670) use undefined when merging instead of null --- lib/value/src/kind/collection.rs | 10 +++++----- lib/value/src/kind/merge.rs | 8 ++++---- .../if_statement/conditional_assignment.vrl | 4 ++-- .../tests/expressions/if_statement/if_else_object.vrl | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/value/src/kind/collection.rs b/lib/value/src/kind/collection.rs index 03f2fae2f0f6b..0df97f50ef4f6 100644 --- a/lib/value/src/kind/collection.rs +++ b/lib/value/src/kind/collection.rs @@ -229,7 +229,7 @@ impl Collection { } } else if !overwrite { // other is missing this field, which returns null - self_kind.add_null(); + self_kind.add_undefined(); } } @@ -246,7 +246,7 @@ impl Collection { } 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); @@ -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()), ])), }, ), @@ -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()), ])), }, ), diff --git a/lib/value/src/kind/merge.rs b/lib/value/src/kind/merge.rs index 99d41e4b0a5ec..63e40687946a8 100644 --- a/lib/value/src/kind/merge.rs +++ b/lib/value/src/kind/merge.rs @@ -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()), ])), }, ), diff --git a/lib/vrl/tests/tests/expressions/if_statement/conditional_assignment.vrl b/lib/vrl/tests/tests/expressions/if_statement/conditional_assignment.vrl index c72e3434ec4d6..78e2baf755e57 100644 --- a/lib/vrl/tests/tests/expressions/if_statement/conditional_assignment.vrl +++ b/lib/vrl/tests/tests/expressions/if_statement/conditional_assignment.vrl @@ -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 } # } # } diff --git a/lib/vrl/tests/tests/expressions/if_statement/if_else_object.vrl b/lib/vrl/tests/tests/expressions/if_statement/if_else_object.vrl index 30b2921619765..cbc2663914a7e 100644 --- a/lib/vrl/tests/tests/expressions/if_statement/if_else_object.vrl +++ b/lib/vrl/tests/tests/expressions/if_statement/if_else_object.vrl @@ -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 {