Skip to content
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

Merged
merged 14 commits into from
Dec 22, 2023

Conversation

justinrsweeney
Copy link
Contributor

@justinrsweeney justinrsweeney commented Oct 10, 2023

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:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

@epugh
Copy link
Contributor

epugh commented Oct 10, 2023

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?

Justin Sweeney added 2 commits October 11, 2023 10:47
…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)
Copy link
Contributor Author

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:

  1. Have glob patterns for fields in Export handler return any fields that are able to be exported
  2. Match the behavior in the Select handler and only return fields that match the pattern, have docvalues enabled AND have useDocValuesAsStored=true

Copy link
Contributor

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 ;-).

Copy link
Contributor

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!

Copy link
Contributor Author

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.

Copy link
Contributor

@risdenk risdenk left a 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

@justinrsweeney
Copy link
Contributor Author

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?

Yup, I can update the ref guide before merging.

Copy link
Contributor

@dsmiley dsmiley left a 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));
Copy link
Contributor

@dsmiley dsmiley Oct 13, 2023

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.

Copy link
Contributor

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!

@justinrsweeney
Copy link
Contributor Author

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.

SolrReturnFields was using FilenameUtils.wildcardMatch() from commons-io and this just uses a very similar method but not requiring the third party library and allows solrj-streaming, SolrReturnFields, and ExportWriter to all use the same mechanism to match glob patterns.

Copy link
Contributor

@dsmiley dsmiley left a 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));
Copy link
Contributor

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()) {
Copy link
Contributor

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())
Copy link
Contributor

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.

@justinrsweeney
Copy link
Contributor Author

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.

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.

@justinrsweeney
Copy link
Contributor Author

@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)) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right; of course.

@justinrsweeney justinrsweeney merged commit 17f8ee4 into main Dec 22, 2023
3 checks passed
@justinrsweeney justinrsweeney deleted the SOLR-17022-glob-patterns-export-stream-handlers branch December 22, 2023 12:29
justinrsweeney pushed a commit that referenced this pull request Dec 22, 2023
…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
@LuckyFrost
Copy link

LuckyFrost commented Feb 23, 2024

@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

@magibney
Copy link
Contributor

magibney commented Feb 23, 2024

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 ...)

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.

6 participants