Skip to content

Commit

Permalink
apply review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Sep 30, 2024
1 parent ead7f64 commit 72a7834
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setup() throws IOException {
);
includesSet = Set.of(fetchContext.includes());
excludesSet = Set.of(fetchContext.excludes());
parserConfig = XContentParserConfiguration.EMPTY.withFiltering(includesSet, excludesSet, false);
parserConfig = XContentParserConfiguration.EMPTY.withFiltering(null, includesSet, excludesSet, false);
}

private BytesReference read300BytesExample() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private XContentParserConfiguration buildParseConfig(boolean matchDotsInFieldNam
includes = null;
excludes = filters;
}
return XContentParserConfiguration.EMPTY.withFiltering(includes, excludes, matchDotsInFieldNames);
return XContentParserConfiguration.EMPTY.withFiltering(null, includes, excludes, matchDotsInFieldNames);
}

private BytesReference filter(XContentParserConfiguration contentParserConfiguration) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,27 @@ public RestApiVersion restApiVersion() {
}

public XContentParserConfiguration withFiltering(
String rootPath,
String prefixPath,
Set<String> includeStrings,
Set<String> excludeStrings,
boolean filtersMatchFieldNamesWithDots
) {
FilterPath[] includePaths = FilterPath.compile(includeStrings);
FilterPath[] excludePaths = FilterPath.compile(excludeStrings);

if (rootPath != null) {
if (prefixPath != null) {
if (includePaths != null) {
List<FilterPath> includeFilters = new ArrayList<>();
for (var incl : includePaths) {
incl.matches(rootPath, includeFilters, true);
incl.matches(prefixPath, includeFilters, true);
}
includePaths = includeFilters.isEmpty() ? null : includeFilters.toArray(FilterPath[]::new);
}

if (excludePaths != null) {
List<FilterPath> excludeFilters = new ArrayList<>();
for (var excl : excludePaths) {
excl.matches(rootPath, excludeFilters, true);
excl.matches(prefixPath, excludeFilters, true);
}
excludePaths = excludeFilters.isEmpty() ? null : excludeFilters.toArray(FilterPath[]::new);
}
Expand All @@ -139,14 +139,6 @@ public XContentParserConfiguration withFiltering(
);
}

public XContentParserConfiguration withFiltering(
Set<String> includeStrings,
Set<String> excludeStrings,
boolean filtersMatchFieldNamesWithDots
) {
return withFiltering(null, includeStrings, excludeStrings, filtersMatchFieldNamesWithDots);
}

public JsonParser filter(JsonParser parser) {
JsonParser filtered = parser;
if (excludes != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ public interface XContentParserConfiguration {

/**
* Replace the configured filtering.
*
* @param prefixPath The prefix path to be appended to each sub-path before applying the include/exclude rules.
* Specify {@code null} if parsing starts from the root.
* @param includeStrings A set of strings representing paths to include during filtering.
* If specified, only these paths will be included in parsing.
* @param excludeStrings A set of strings representing paths to exclude during filtering.
* If specified, these paths will be excluded from parsing.
* @param filtersMatchFieldNamesWithDots Indicates whether filters should match field names containing dots ('.')
* as part of the field name.
*/
XContentParserConfiguration withFiltering(
Set<String> includeStrings,
Set<String> excludeStrings,
boolean filtersMatchFieldNamesWithDots
);

XContentParserConfiguration withFiltering(
String rootPath,
String prefixPath,
Set<String> includeStrings,
Set<String> excludeStrings,
boolean filtersMatchFieldNamesWithDots
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ public DataStream getParentDataStream() {
}

public static final XContentParserConfiguration TS_EXTRACT_CONFIG = XContentParserConfiguration.EMPTY.withFiltering(
null,
Set.of(TIMESTAMP_FIELD_NAME),
null,
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static class ExtractFromSource extends IndexRouting {
trackTimeSeriesRoutingHash = metadata.getCreationVersion().onOrAfter(IndexVersions.TIME_SERIES_ROUTING_HASH_IN_ID);
List<String> routingPaths = metadata.getRoutingPaths();
isRoutingPath = Regex.simpleMatcher(routingPaths.toArray(String[]::new));
this.parserConfig = XContentParserConfiguration.EMPTY.withFiltering(Set.copyOf(routingPaths), null, true);
this.parserConfig = XContentParserConfiguration.EMPTY.withFiltering(null, Set.copyOf(routingPaths), null, true);
}

public boolean matchesField(String fieldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static Tuple<XContentType, Map<String, Object>> convertToMap(
) throws ElasticsearchParseException {
XContentParserConfiguration config = XContentParserConfiguration.EMPTY;
if (include != null || exclude != null) {
config = config.withFiltering(include, exclude, false);
config = config.withFiltering(null, include, exclude, false);
}
return parseToType(ordered ? XContentParser::mapOrdered : XContentParser::map, bytes, xContentType, config);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public static Map<String, Object> convertToMap(
@Nullable Set<String> exclude
) throws ElasticsearchParseException {
try (
XContentParser parser = xContent.createParser(XContentParserConfiguration.EMPTY.withFiltering(include, exclude, false), input)
XContentParser parser = xContent.createParser(XContentParserConfiguration.EMPTY.withFiltering(null, include, exclude, false), input)
) {
return ordered ? parser.mapOrdered() : parser.map();
} catch (IOException e) {
Expand Down Expand Up @@ -301,7 +301,7 @@ public static Map<String, Object> convertToMap(
) throws ElasticsearchParseException {
try (
XContentParser parser = xContent.createParser(
XContentParserConfiguration.EMPTY.withFiltering(include, exclude, false),
XContentParserConfiguration.EMPTY.withFiltering(null, include, exclude, false),
bytes,
offset,
length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private Function<Source, Source> buildBytesFilter() {
return this::filterMap;
}
final XContentParserConfiguration parserConfig = XContentParserConfiguration.EMPTY.withFiltering(
null,
Set.copyOf(Arrays.asList(includes)),
Set.copyOf(Arrays.asList(excludes)),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void testObjectWithFilter() throws IOException {

XContentParser p = createParser(JsonXContent.jsonXContent, object);
assertThat(p.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
XContentParserConfiguration parserConfig = XContentParserConfiguration.EMPTY.withFiltering(null, Set.of("path.filter.field"), true);
XContentParserConfiguration parserConfig = XContentParserConfiguration.EMPTY.withFiltering(null, null, Set.of("path.filter.field"), true);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.humanReadable(true);
XContentDataHelper.decodeAndWrite(parserConfig, builder, XContentDataHelper.encodeToken(p));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class TransportPutRollupJobAction extends AcknowledgedTransportMasterNode

private static final Logger LOGGER = LogManager.getLogger(TransportPutRollupJobAction.class);
private static final XContentParserConfiguration PARSER_CONFIGURATION = XContentParserConfiguration.EMPTY.withFiltering(
null,
Set.of("_doc._meta._rollup"),
null,
false
Expand Down

0 comments on commit 72a7834

Please sign in to comment.