Skip to content

filter: add RegexMatch#37

Merged
arl merged 5 commits intomainfrom
add-regex-match-filter
Sep 18, 2020
Merged

filter: add RegexMatch#37
arl merged 5 commits intomainfrom
add-regex-match-filter

Conversation

@arl
Copy link
Copy Markdown
Collaborator

@arl arl commented Sep 16, 2020

❓ What

Add RegexMatch filter: discards records if one or more of the specified fields do not match a specified regular expression.

🔨 How to test

  1. List all steps necessary;
  2. To test this pull request.

✅ Checklists

This section contains a list of checklists for common uses, please delete the checklists that are useless for your current use case (or add another checklist if your use case isn't covered yet).

  • Is there unit/integration test coverage for all new and/or changed functionality added in this PR?
  • Have the changes in this PR been functionally tested?
  • Has make gofmt-write been run on the code?
  • Has make govet been run on the code? Has the code been fixed accordingly to the output?
  • Have the changes been added to the CHANGELOG.md file?
  • Have the steps in CONTRIBUTING.md been followed to update a Go module?

@arl arl requested a review from tommyblue September 16, 2020 13:51
Copy link
Copy Markdown
Contributor

@tommyblue tommyblue left a comment

Choose a reason for hiding this comment

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

lgtm, just minor comments

Comment thread filter/regex_match_test.go Outdated
Comment thread filter/regex_match.go Outdated
Comment on lines +20 to +21
Fields []string `help:"list of fields to match with the regular expression in Regexs" default:"[]"`
Regexs []string `help:"list of regular expression to match. Fields[0] must match Regexs[0], Fields[1] Regexs[1] and so on" default:"[]"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do you think it's acceptable to have those empty defaults? I mean, it doesn't hurt but also does nothing. I think we could remove defaults and require at least 1 field (and then 1 regexp)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

not handling is also less code to write/read/maintain and potential bugs. I think it's acceptable to do nothing in this case but I don't have a very strong opinion on this.
I just started to work on the required fields.
When it will land, it will be easy to remove the defaults and set those fields as required so as to have Baker directly handles these kinds of cases

Comment thread filter/regex_match.go Outdated
Comment thread filter/regex_match.go Outdated
},
}

fieldByName := func(name string) (baker.FieldIndex, bool) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just to clarify the reading of the test table (in particular the correspondance between fields and record values), you could call the fields something like "1st", "2nd", "3rd". And then also "foox" could be "unexistentField" to be immediately clear why that test has wantErr = true

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Rename foox into non-existent is a good idea but I think the foo bar baz idiom is well-known enough when names do not import. There's also the fieldByName function in the middle of the test that clearly shows what they are.

arl and others added 3 commits September 16, 2020 16:37
Co-authored-by: Tommaso Visconti <tommaso.visconti@adroll.com>
Co-authored-by: Tommaso Visconti <tommaso.visconti@adroll.com>
@arl arl merged commit 29a41d0 into main Sep 18, 2020
@arl arl deleted the add-regex-match-filter branch September 18, 2020 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants