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

formatter_csv: support nested fields. fix #2630 #2643

Merged
merged 1 commit into from
Oct 11, 2019

Conversation

repeatedly
Copy link
Member

Signed-off-by: Masahiro Nakagawa [email protected]

Which issue(s) this PR fixes:
Fixes #2630

What this PR does / why we need it:
Support nested fields via record_accessor.

Docs Changes:
Add note for nested fields to fields parameter.

Release Note:
same as title

@repeatedly repeatedly added the enhancement Feature request or improve operations label Oct 9, 2019
@repeatedly repeatedly self-assigned this Oct 9, 2019
Copy link
Member

@ganmacs ganmacs left a comment

Choose a reason for hiding this comment

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

with a comment

@@ -37,6 +41,14 @@ def configure(conf)
@fields = fields.select{|f| !f.empty? }
raise ConfigError, "empty value is specified in fields parameter" if @fields.empty?

if @fields.any? { |f| record_accessor_nested?(f) }
@accessors = @fields.map { |f| record_accessor_create(f) }
Copy link
Member

Choose a reason for hiding this comment

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

How about this? it can avoid the needless call of Accessor#call. Not nested fields don't need to be called this method, right?

nested = @fileds.select { |f| record_accessor_nested?(f) }
unless nested.empty?
  @accessors = nested.map { |f| record_accessor_create(f) }

   ...
end

Copy link
Member Author

@repeatedly repeatedly Oct 10, 2019

Choose a reason for hiding this comment

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

Your appoarch is bit complicated.
If fields are a,$.b.c,d, formatter_csv needs to remember the nested field position when separate fields into normal access and record_accessor.

@repeatedly repeatedly merged commit a72a0a4 into master Oct 11, 2019
@ganmacs ganmacs deleted the csv-formatter-nested-fields branch November 8, 2019 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or improve operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support nested flieds in CSV format
2 participants