-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOLR-17022: Support for glob patterns for fields in Export handler, Stream handler and with SelectStream streaming expression #1996
SOLR-17022: Support for glob patterns for fields in Export handler, Stream handler and with SelectStream streaming expression #1996
Conversation
solr/core/src/java/org/apache/solr/handler/export/ExportWriter.java
Outdated
Show resolved
Hide resolved
This seems like a very useful feature! I also like the establishing parity in how things work. Will you make sure to update ref guide? |
…rn matching, current implementation uses Java NIO path matching. Replaced uses of FilenameUtils.wildcardMatches to reduce commons-io usage.
SchemaField schemaField = searcher.getSchema().getField(fi.getName()); | ||
if (fieldsProcessed.add(fi.getName()) | ||
&& schemaField.hasDocValues() | ||
&& (!(schemaField.getType() instanceof SortableTextField) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanted to highlight this because @magibney and I were discussing this previously. The way this is implemented for the Export handler here actually deviates from how glob patterns work for the Select handler.
The Select handler will not match any fields where useDocValuesAsStored=false
for glob patterns, those fields must be explicitly provided in the field list.
For the purposes of Export I did not follow that pattern and instead will match any fields that have docvalues enabled with the exception of SortableTextField which require useDocValuesAsStored=true
to be used in Export in other places in the code.
My reasoning here is that there is a performance hit for getting non-stored, docvalues enabled fields in the Select handler that doesn't seem to be to be as impactful in the Export handler.
Open to other opinions on this topic, should we:
- Have glob patterns for fields in Export handler return any fields that are able to be exported
- Match the behavior in the Select handler and only return fields that match the pattern, have docvalues enabled AND have
useDocValuesAsStored=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for consistency if possible, since I think of both /select and /export as the same, just one is faster than the other ;-). If that isn't possible, then maybe if the ref guide makes it really clear "This is why you use /select and ramifications" and "THis is why you use /export and it's ramifications", then that might cover these differences. I can see the bug reports if we aren't clear ;-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @justinrsweeney foreshadowed, I am in favor of parity in how this is handled between select and export.
The purpose of udvas as I understand it is not simply to mitigate performance issues in select (and in fact, performance should be comparable between select and export as of #1938), but also as a config option to allow the configuration of docValues for a field without requiring that those values be returned when a field matches a glob pattern.
There are plenty of use cases where, e.g., a derivative string field is configured solely for the purpose of sort, faceting, [or other purpose that would make even less sense to return on export]. It should be possible to configure a field that's intended for one of the many other purposes docValues serve, without forcing it to be returned when the field name matches a glob pattern. Note also, if both stored=true
and useDocValuesAsStored=true
, stored fields will be used for select and docValues will be used for export.
I think what I'm missing is: how does this help usability? Are there cases where one would want docValues to be used for field value retrieval, but could not simply set that field to useDocValuesAsStored=true
? And udvas defaults to true anyway (for all fields except SortableTextField) iirc.
I'm curious to hear others' thoughts on this as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this PR to mimic the same behavior as the select handler, where useDocValuesAsStored=false
fields will not be returned unless specifically requested. I'm in agreement that consistency here is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @justinrsweeney looks much cleaner
solr/solrj/src/test/org/apache/solr/common/util/TestGlobPatternUtil.java
Show resolved
Hide resolved
Yup, I can update the ref guide before merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised to see that this isn't using SolrReturnFields, which is already doing field glob expansion. I know it's in solr-core and you seem to need something in solrj-streaming but we could move it.
public class GlobPatternUtil { | ||
|
||
public static boolean matches(String pattern, String input) { | ||
return FileSystems.getDefault().getPathMatcher("glob:" + pattern).matches(Paths.get(input)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is bizarre just for some field wildcard support. If there is a reason we use FileSystems then a comment is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
SolrReturnFields was using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is duplication of logic between SolrReturnFields. If you think it's not an issue or is impossible to reconcile, then I trust you.
public class GlobPatternUtil { | ||
|
||
public static boolean matches(String pattern, String input) { | ||
return FileSystems.getDefault().getPathMatcher("glob:" + pattern).matches(Paths.get(input)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
SolrIndexSearcher searcher, | ||
Set<String> fieldsProcessed, | ||
List<SchemaField> expandedFields) { | ||
for (FieldInfo fi : searcher.getFieldInfos()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
for (FieldInfo fi : searcher.getFieldInfos()) { | ||
if (GlobPatternUtil.matches(fieldPattern, fi.getName())) { | ||
SchemaField schemaField = searcher.getSchema().getField(fi.getName()); | ||
if (fieldsProcessed.add(fi.getName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line might add to fieldsProcessed, yet exclude the field because doesn't "hasDocValues". This looks suspicious to me.
I finally got back around to this. With the latest change, ExportWriter is using SolrReturnFields which in turn is using GlobPatternUtil so there is a consistent approach there. |
@risdenk Pinging for re-review when you have a chance |
@@ -308,6 +327,13 @@ public Tuple read() throws IOException { | |||
workingForEvaluators.put(fieldName, original.get(fieldName)); | |||
if (selectedFields.containsKey(fieldName)) { | |||
workingToReturn.put(selectedFields.get(fieldName), original.get(fieldName)); | |||
} else { | |||
for (String globPattern : selectedFieldGlobPatterns) { | |||
if (GlobPatternUtil.matches(globPattern, fieldName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't SelectStream also use SolrReturnFields and not use lower level GlobPattern stuff (it's something SRF can handle)?
Disclaimer: I haven't looked at this PR in a long time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solrj-streaming
does not currently have a dependency on core
, in fact currently I think core
depends on solrj-streaming
. I didn't want to refactor SolrReturnFields to live elsewhere given the scope of this PR so not using that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right; of course.
@@ -308,6 +327,13 @@ public Tuple read() throws IOException { | |||
workingForEvaluators.put(fieldName, original.get(fieldName)); | |||
if (selectedFields.containsKey(fieldName)) { | |||
workingToReturn.put(selectedFields.get(fieldName), original.get(fieldName)); | |||
} else { | |||
for (String globPattern : selectedFieldGlobPatterns) { | |||
if (GlobPatternUtil.matches(globPattern, fieldName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right; of course.
…tream handler and with SelectStream streaming expression (#1996) * Adding support for Glob patterns in Export handler and Select stream handler using the same logic to match glob patterns to fields as is used in select requests
@justinrsweeney, hello, I'm not sure, but it seems your change causes a significant performance hit with prefix wildcard fl https://lists.apache.org/thread/vbwnjxprl6s1qy0t1jzfcw8hprg1gvzh |
It's also possible this could be related to SOLR-16989 -- sorry I missed the mailing list thread, I'll follow up there. EDIT: on closer inspection it does look more likely related to the relative inefficiency of the new pattern matching approach (wrt previous commons-io FilenameUtils ...) |
https://issues.apache.org/jira/browse/SOLR-17022
Description
This PR provides support for using glob patterns for fields in Export handler, Stream handler and with the SelectStream streaming expression. This creates similar ease of use for these handlers as we already have for the Select handler. Given how Solr export handler works, the glob pattern will be applied to only match fields that support stream, which are fields with docvalues enabled.
Solution
This solution uses similar methods to the Select handler to part glob patterns into matching fields. We then create a FieldWriter for each matching field to return the necessary data.
Tests
Implemented tests to ensure that we create the correct set of fields as a results of glob pattern matching.
Checklist
Please review the following and check all that apply:
main
branch../gradlew check
.