dsmiley commented on code in PR #1996: URL: https://github.com/apache/solr/pull/1996#discussion_r1358916494
########## solr/solrj/src/java/org/apache/solr/common/util/GlobPatternUtil.java: ########## @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.common.util; + +import java.nio.file.FileSystems; +import java.nio.file.Paths; + +public class GlobPatternUtil { + + public static boolean matches(String pattern, String input) { + return FileSystems.getDefault().getPathMatcher("glob:" + pattern).matches(Paths.get(input)); Review Comment: I took a look at how it's implemented. If only we could call ZipUtils.toRegexPattern but the class is package protected. It's a shame to recompile the glob on each call to matches! ########## solr/core/src/java/org/apache/solr/handler/export/ExportWriter.java: ########## @@ -844,4 +844,60 @@ public String getMessage() { return "Early Client Disconnect"; } } + + /** + * Creates a complete field list using the provided field list by expanding any glob patterns into + * field names + * + * @param fields the original set of fields provided + * @param searcher an index searcher to access schema info + * @return a complete list of fields included any fields matching glob patterns + * @throws IOException if a provided field does not exist or cannot be retrieved from the schema + * info + */ + private List<SchemaField> expandFieldList(String[] fields, SolrIndexSearcher searcher) + throws IOException { + List<SchemaField> expandedFields = new ArrayList<>(fields.length); + Set<String> fieldsProcessed = new HashSet<>(); + for (String field : fields) { + try { + if (field.contains("*")) { + getGlobFields(field, searcher, fieldsProcessed, expandedFields); + } else { + if (fieldsProcessed.add(field)) { + expandedFields.add(searcher.getSchema().getField(field)); + } + } + } catch (Exception e) { + throw new IOException(e); + } + } + + return expandedFields; + } + + /** + * Create a list of schema fields that match a given glob pattern + * + * @param fieldPattern the glob pattern to match + * @param searcher an index search to access schema info + * @param fieldsProcessed the set of field names already processed to avoid duplicating + * @param expandedFields the list of fields to add expanded field names into + */ + private void getGlobFields( + String fieldPattern, + SolrIndexSearcher searcher, + Set<String> fieldsProcessed, + List<SchemaField> expandedFields) { + for (FieldInfo fi : searcher.getFieldInfos()) { + if (GlobPatternUtil.matches(fieldPattern, fi.getName())) { + SchemaField schemaField = searcher.getSchema().getField(fi.getName()); + if (fieldsProcessed.add(fi.getName()) Review Comment: This line might add to fieldsProcessed, yet exclude the field because doesn't "hasDocValues". This looks suspicious to me. ########## solr/core/src/java/org/apache/solr/handler/export/ExportWriter.java: ########## @@ -844,4 +844,60 @@ public String getMessage() { return "Early Client Disconnect"; } } + + /** + * Creates a complete field list using the provided field list by expanding any glob patterns into + * field names + * + * @param fields the original set of fields provided + * @param searcher an index searcher to access schema info + * @return a complete list of fields included any fields matching glob patterns + * @throws IOException if a provided field does not exist or cannot be retrieved from the schema + * info + */ + private List<SchemaField> expandFieldList(String[] fields, SolrIndexSearcher searcher) + throws IOException { + List<SchemaField> expandedFields = new ArrayList<>(fields.length); + Set<String> fieldsProcessed = new HashSet<>(); + for (String field : fields) { + try { + if (field.contains("*")) { + getGlobFields(field, searcher, fieldsProcessed, expandedFields); + } else { + if (fieldsProcessed.add(field)) { + expandedFields.add(searcher.getSchema().getField(field)); + } + } + } catch (Exception e) { + throw new IOException(e); + } + } + + return expandedFields; + } + + /** + * Create a list of schema fields that match a given glob pattern + * + * @param fieldPattern the glob pattern to match + * @param searcher an index search to access schema info + * @param fieldsProcessed the set of field names already processed to avoid duplicating + * @param expandedFields the list of fields to add expanded field names into + */ + private void getGlobFields( + String fieldPattern, + SolrIndexSearcher searcher, + Set<String> fieldsProcessed, + List<SchemaField> expandedFields) { + for (FieldInfo fi : searcher.getFieldInfos()) { Review Comment: There can be many fieldInfo, and you're looping over a "matches" call that is going to internally build a regex each time. Maybe you should first do the hasDocValues etc. checks so we do this matches check last? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
