New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow accessing numeric fields in remap without quoting #6780
Comments
The reason for this limitation (and others) is simple: start with a conservative/limited syntax scope, and expand as needed. I don't have any real preference in this case, although it might be confusing for some that Also, if we do this, we lose the capability to use numeric fields for other use-cases in the future. I don't have one in mind, though. Rust uses it for tuple access, and there might be reasons to add tuples (e.g. |
True, I think that is a sensible strategy.
🤔 we could support it for both cases: if it is a tuple, it indexes into that, if it is a map, it treats it as a field name. |
There are ambiguities for cases:
Considering those cases, we can only support pure integer, so no fields that start with a number, and only as the last field in path. But that will be confusing and of limited use, so, without an acceptable solution for those cases, I'm for closing this issue. cc. @JeanMertz @jszwedko |
Thanks for writing this up @ktff . I'm not sure I completely follow. For your two cases:
I might be missing something here though. |
That's true but that isn't the problem, the
For this one we will parse it as an integer, so There are ways around this but all that I see are hacky and like a hydra, you take care of one case just for several new corner cases to pop up. Especially case |
Now, there are ways to solve this but it will require breaking changes to the language and I'm note sure that it's worth it. Most notably changing floats from |
🤔 I'm not super familiar with VRL's tokenizer and parser but it seems to handle path segments specifically: cc/ @JeanMertz I'm curious if you have thoughts here since you wrote most of the parser. I'm happy to defer to people closer to it. At the least, we should document the limitation on https://vector.dev/docs/reference/vrl/expressions/#path_segments. |
That path segment is partly an issue and it's manageable, but the tokenizer is responsible for parsing the |
@JeanMertz could you give us your thought's on this. Most notably this
|
It seems to me that, to support this, we'd have to do one of three things:
I'd say (1) is not ideal, as we want to keep as much contextual information out of the lexer. Doing (2) is a more favourable option to the first. Finally, (3) doesn't require us to change the lexer, but it'll still require a bit of fiddling with the path parsing rules to make that work as expected. I'm not sure which of (2) or (3) I'd prefer. It's a toss-up for me, really. Doing (2) seems to be the least hacky, although (3) allows us to keep the lexer as-is, at the cost of making the path parsing rules more complex. |
@JeanMertz thanks. (3) isn't doable because we can't distinguish So let's go with (2). |
If
This does still seem like the most sensible approach, I agree. |
It seems like you cannot access fields in an object that start with a number. This is common, for example, with
parse_regex
which returns numeric capture groups.For example, VRL REPL:
I might be missing something, but I don't see any reason to require bare keys to not start with a number.
The text was updated successfully, but these errors were encountered: