Skip to content
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

fix(parsers.xpath): Add array index when expanding names. #11781

Merged
merged 2 commits into from
Sep 15, 2022

Conversation

srebhan
Copy link
Member

@srebhan srebhan commented Sep 9, 2022

This PR fixes the name expansion for JSON arrays by adding the correct array index to the name.

@telegraf-tiger telegraf-tiger bot added fix pr to fix corresponding bug plugin/parser 1. Request for new parser plugins 2. Issues/PRs that are related to parser plugins labels Sep 9, 2022
@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Sep 9, 2022

switch reflect.TypeOf(n.Parent.Value()).Kind() {
case reflect.Slice, reflect.Array:
// Determine the index for array elements
names = append(names, d.index(n))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if people are going to want one-based indexes. I wouldn't be surprised if we eventually see a feature request to add a parser level setting for it. We don't need to add a setting for it in this PR.

I don't see anything here that would be a problem if we did add a setting for one-based indexes. In that case, zero-based indexes will be the default

@reimda reimda merged commit 97b4db8 into influxdata:master Sep 15, 2022
reimda pushed a commit that referenced this pull request Sep 19, 2022
dba-leshop pushed a commit to dba-leshop/telegraf that referenced this pull request Oct 30, 2022
@srebhan srebhan deleted the xpath_expand branch November 7, 2022 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix pr to fix corresponding bug plugin/parser 1. Request for new parser plugins 2. Issues/PRs that are related to parser plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants