-
Notifications
You must be signed in to change notification settings - Fork 378
Modified Streaming and Generating Custom Search Command #407
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
Conversation
akaila-splunk
commented
Oct 27, 2021
- Fix field dropping issue for Streaming and Generating CSC
Description added for how to use add_field method to preserve conditionally added new fields and values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is really looking good, thanks for the documented examples and generating command test! Just one request to add a full fledged tests for the add_field
scenario to ensure that is working as intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is really looking good, thanks for the documented examples and generating command test! Just one request to add a full fledged tests for the add_field
scenario to ensure that is working as intended.
def add_field(self, current_record, field_name, field_value): | ||
self._record_writer.custom_fields.add(field_name) | ||
current_record[field_name] = field_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should return current_record or else the documentation is incorrect.
def add_field(self, current_record, field_name, field_value): | |
self._record_writer.custom_fields.add(field_name) | |
current_record[field_name] = field_value | |
def add_field(self, current_record, field_name, field_value): | |
self._record_writer.custom_fields.add(field_name) | |
current_record[field_name] = field_value | |
return current_record |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @Bre77 - I think in this case the documentation needs to be updated, the current_record
should be updated with the new field without the need to return since it's essentially pass-by-reference for this usage (I always go back to this article when I need to refresh my memory: https://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k-dick/).
So if you all agree can we fix the README.md above to the following?
class CustomStreamingCommand(StreamingCommand):
def stream(self, records):
for index, record in enumerate(records):
if index % 1 == 0:
self.add_field(record, "odd_record", "true")
yield record
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And to make sure that example we provide is working ^ that's probably a good implementation to add when adding tests for the StreamingCommand / add_field case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed my implementation to using pass by reference (as per the suggested doco update) and everything works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @Bre77
I've updated the README accordingly.
output_records = [i for i in output_iter.next().data] | ||
|
||
# Assert that count of records having "odd_field" is 0 | ||
assert len(list(filter(lambda r: "odd_field" in r, output_records))) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice demonstration of the issue!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking forward to getting this out to our eager users 🚀 nice work