vectordotdev / vector

A high-performance observability data pipeline.
https://vector.dev
Mozilla Public License 2.0
17.78k stars 1.57k forks source link

VRL: Document array.[] #9728

Open aroberts opened 3 years ago

aroberts commented 3 years ago

I'm writing my first transform, and after splitting a field, I am looking for documentation on what happens if I index into the resulting array using a too-large value. The documentation here doesn't mention [] as a function at all, let alone express anything about the failure modes.

lucperkins commented 3 years ago

@aroberts Could you possibly provide the function that you're trying to run and the output that you're getting?

JeanMertz commented 3 years ago

Hey @aroberts,

That's a good question. First off, indexing ([]) isn't implemented as a function, but its syntax is described in the expressions section of the documentation.

Having said that, I think there are two improvements we can make here:

  1. It would be nice if we could make references such as <array> as in your link clickable, to go to the relevant header in the expressions section.
  2. Second, for indexing, we should detail what happens, but the gist of it is that indexing into an array returns a value or null, depending on if a value exists at the given index. Assigning a value to an index pads the array with null values if the index goes beyond the number of populated indexes.
aroberts commented 3 years ago

@JeanMertz hey thanks- that answers all my questions, and I agree that these two things would be great to have spelled out in the doc.