You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
If you are interested in working on this issue or have submitted a pull request, please leave a comment
Problem
VRL function object_from_array when used with a single parameter requires unnecessary push to that parameter to work properly. See VRL example in respective section.
What I expect:
{
...
"foo": "bar",
"propstructLen": 1,
...
}
What I get:
{
...
"propstructLen": 0,
...
}
The function is also not fallible depsite the doc page.
Configuration
config.toml:
[sources.demo_logs]
type = "demo_logs"
format = "json"
lines = [ "line1" ]
[transforms.remap_logs]
inputs = ["demo_logs"]
type = "remap"
file = "/Users/username/test/transform_tj.vrl"
[sinks.print_ok]
type = "console"
encoding.codec = "json"
encoding.json.pretty = true
inputs = [ "remap_logs" ]
transform_tj.vrl:
proparr = [{"key":"foo", "value":"bar"}]
keyvalarr = []
for_each(proparr) -> |_index, item| {
PropKey = item.key
PropValue = item.value
if is_string(PropKey) {
keyvalarr = push(keyvalarr, [PropKey, PropValue])
}
}
# keyvalarr = push(keyvalarr, [null, null]) # <-- when this line is commented out or removed, the next line returns an empty object
propstruct = object_from_array(keyvalarr)
.propstructLen = length(propstruct)
. = merge(., propstruct, deep: false)
That is indeed surprising behavior, but I can confirm it in the VRL playground as well. It gets stranger too, as you can also fix the behavior by doing something like:
IOW assigning it to a field in the event and using that field instead of a variable makes it work. That suggests to me that it is not a problem with the operation of object_from_array itself but with something indirect to calling it.
That is indeed surprising behavior, but I can confirm it in the VRL playground as well. It gets stranger too, as you can also fix the behavior by doing something like:
.foobar = keyvalarr
propstruct = object_from_array(.foobar)
del(.foobar)
IOW assigning it to a field in the event and using that field instead of a variable makes it work. That suggests to me that it is not a problem with the operation of object_from_array itself but with something indirect to calling it.
FWIW the if inside the for_each is unnecessary to causing the failure, which points at the handling of for_each being at issue. Also, doing an unconditional pushbefore the for_each also makes it work.
A note for the community
A note for the community
Problem
VRL function object_from_array when used with a single parameter requires unnecessary push to that parameter to work properly. See VRL example in respective section.
What I expect:
What I get:
The function is also not fallible depsite the doc page.
Configuration
Version
vector 0.44.0 (aarch64-apple-darwin 3cdc7c3 2025-01-13 21:26:04.735691656)
Debug Output
Example Data
No response
Additional Context
No response
References
vectordotdev/vector#22294
The text was updated successfully, but these errors were encountered: