Skip to content

enhancement(lua transform): Allow iterating over event fields#1111

Merged
1 commit merged intovectordotdev:masterfrom
steven-aerts:lua_pairs
Oct 30, 2019
Merged

enhancement(lua transform): Allow iterating over event fields#1111
1 commit merged intovectordotdev:masterfrom
steven-aerts:lua_pairs

Conversation

@steven-aerts
Copy link
Copy Markdown
Contributor

Make it possible to use pairs(event) to iterate over all fields of an event.

For example:

# Remove all fields where the value is "-"
for f,v in pairs(event) do
  if v == "-" then
    event[f] = nil
  end
end

This code will only compile after rlua takes in mlua-rs/rlua#152 as the __pairs meta-method is currently not exposed.

This commit fixes #528.

Make it possible to use `pairs(event)` to iterate over all fields of an
event.

Signed-off-by: Steven Aerts <steven.aerts@gmail.com>
@binarylogic binarylogic added this to the Improve data processing milestone Oct 29, 2019
@binarylogic binarylogic added transform: lua Anything `lua` transform related type: enhancement A value-adding code change that enhances its existing functionality. labels Oct 29, 2019
@binarylogic binarylogic changed the title feat(lua transform): iterate over fields enhancement(lua transform): iterate over fields Oct 29, 2019
@binarylogic binarylogic changed the title enhancement(lua transform): iterate over fields enhancement(lua transform): Allow iterating over event fields Oct 29, 2019
@binarylogic
Copy link
Copy Markdown
Contributor

Thanks @steven-aerts! We'll get this reviewed.

@binarylogic binarylogic requested a review from a user October 29, 2019 18:47
@ghost
Copy link
Copy Markdown

ghost commented Oct 30, 2019

Looks good to me.

This code will only compile after rlua takes in mlua-rs/rlua#152 as the __pairs meta-method is currently not exposed.

As it is still not merged, we can create a fork with changes from mlua-rs/rlua#152 and use rlua crate from it.

I also had troubles building Vector with master version rlua because it adds additional Into trait implementation for &str, which makes one of splunk_hec tests fail to compile. However, it can be fixed separately as part of switching to rlua crate from the fork.

@ghost ghost mentioned this pull request Oct 30, 2019
@ghost ghost merged commit 219b925 into vectordotdev:master Oct 30, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

transform: lua Anything `lua` transform related type: enhancement A value-adding code change that enhances its existing functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lua metamethods necessary for iterating over all fields in an event.

2 participants