Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitris-athanasiou committed Nov 29, 2019
1 parent bc438eb commit 0866358
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
which fields will be included in the analysis. If `analyzed_fields` is not set,
only the relevant fields will be included. For example, all the numeric fields
for {oldetection}. For the supported field types, see <<ml-put-dfanalytics-supported-fields>>.
Also see {ref}/explain-dfanalytics.html[_explain API] which helps understand
field selection.
Also see the <<explain-dfanalytics>> which helps understand field selection.

`includes`:::
(Optional, array) An array of strings that defines the fields that will be included in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public boolean isFieldExcluded(String path) {

// First we check in the excludes as they are applied last
for (String exclude : sourceFiltering.excludes()) {
if (patternMatchesFieldPath(exclude, path)) {
if (pathMatchesSourcePattern(path, exclude)) {
return true;
}
}
Expand All @@ -203,25 +203,26 @@ public boolean isFieldExcluded(String path) {
}

for (String include : sourceFiltering.includes()) {
if (patternMatchesFieldPath(include, path)) {
if (pathMatchesSourcePattern(path, include)) {
return false;
}
}
return true;
}

private static boolean patternMatchesFieldPath(String pattern, String path) {
if (Regex.isSimpleMatchPattern(pattern)) {
return Regex.simpleMatch(pattern, path);
} else {
if (pattern.equals(path)) {
return true;
} else {
// include as a concrete field name.
// Let us take "foo" as an example.
// Fields that are "foo.*" will also be included.
return Regex.simpleMatch(pattern + ".*", path);
}
private static boolean pathMatchesSourcePattern(String path, String sourcePattern) {
if (sourcePattern.equals(path)) {
return true;
}

if (Regex.isSimpleMatchPattern(sourcePattern)) {
return Regex.simpleMatch(sourcePattern, path);
}

// At this stage sourcePattern is a concrete field name and path is not equal to it.
// We should check if path is a nested field of pattern.
// Let us take "foo" as an example.
// Fields that are "foo.*" should also be matched.
return Regex.simpleMatch(sourcePattern + ".*", path);
}
}
Loading

0 comments on commit 0866358

Please sign in to comment.