-
Notifications
You must be signed in to change notification settings - Fork 41
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
Create runtime fields #622
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7e28ca4
Create runtime fields
vim345 9ef7aa3
Change ValueSource to segment factory.
vim345 44e5cf2
Got the list and maps working.
vim345 a55d178
Applied spotless
vim345 86eda24
Added test for Runtime script
vim345 8a04251
Add tests for doc values
vim345 75c550f
Fix the spotless formatting
vim345 e9099ae
Use json util object converter and address other commends
vim345 5dd576a
Fix the failing test
vim345 d1dccd5
Do another spotlessApply
vim345 dda5a8b
Add support for runtime fields with parallel fetch by chunks of fields
vim345 0dd6e80
Move the common logic to a util class
vim345 9f47d1c
Fix spotless warnings
vim345 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/yelp/nrtsearch/server/luceneserver/field/RuntimeFieldDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2020 Yelp Inc. | ||
* | ||
* Licensed 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 com.yelp.nrtsearch.server.luceneserver.field; | ||
|
||
import com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef.FacetValueType; | ||
import com.yelp.nrtsearch.server.luceneserver.script.RuntimeScript; | ||
|
||
/** | ||
* Field definition for a runtime field. Runtime fields are able to produce a value for each given | ||
* index document. | ||
*/ | ||
public class RuntimeFieldDef extends FieldDef { | ||
private final RuntimeScript.SegmentFactory segmentFactory; | ||
private final IndexableFieldDef.FacetValueType facetValueType; | ||
|
||
/** | ||
* Field constructor. | ||
* | ||
* @param name name of field | ||
* @param segmentFactory lucene value source used to produce field value from documents | ||
*/ | ||
public RuntimeFieldDef(String name, RuntimeScript.SegmentFactory segmentFactory) { | ||
super(name); | ||
this.segmentFactory = segmentFactory; | ||
this.facetValueType = FacetValueType.NO_FACETS; | ||
} | ||
|
||
/** | ||
* Get value source for this field. | ||
* | ||
* @return Segment factory to create the expression. | ||
*/ | ||
public RuntimeScript.SegmentFactory getSegmentFactory() { | ||
return segmentFactory; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "RUNTIME"; | ||
} | ||
|
||
/** | ||
* Get the facet value type for this field. | ||
* | ||
* @return field facet value type | ||
*/ | ||
@Override | ||
public IndexableFieldDef.FacetValueType getFacetValueType() { | ||
return facetValueType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/main/java/com/yelp/nrtsearch/server/luceneserver/script/RuntimeScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2020 Yelp Inc. | ||
* | ||
* Licensed 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 com.yelp.nrtsearch.server.luceneserver.script; | ||
|
||
import com.yelp.nrtsearch.server.luceneserver.doc.DocLookup; | ||
import com.yelp.nrtsearch.server.luceneserver.doc.LoadedDocValues; | ||
import com.yelp.nrtsearch.server.luceneserver.doc.SegmentDocLookup; | ||
import com.yelp.nrtsearch.server.luceneserver.script.RuntimeScript.SegmentFactory; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import org.apache.lucene.index.LeafReaderContext; | ||
|
||
/** | ||
* Script to produce a value for a given document. Implementations must have an execute function. | ||
* This class conforms with the script compile contract, see {@link ScriptContext}. The script has | ||
* access to the query parameters, the document doc values through {@link SegmentDocLookup}. | ||
*/ | ||
public abstract class RuntimeScript { | ||
private final Map<String, Object> params; | ||
private final SegmentDocLookup segmentDocLookup; | ||
|
||
// names for parameters to execute | ||
public static final String[] PARAMETERS = new String[] {}; | ||
|
||
/** | ||
* ObjectScript constructor. | ||
* | ||
* @param params script parameters from {@link com.yelp.nrtsearch.server.grpc.Script} | ||
* @param docLookup index level doc values lookup | ||
* @param leafContext lucene segment context | ||
*/ | ||
public RuntimeScript( | ||
Map<String, Object> params, DocLookup docLookup, LeafReaderContext leafContext) { | ||
this.params = params; | ||
this.segmentDocLookup = docLookup.getSegmentLookup(leafContext); | ||
} | ||
|
||
/** | ||
* Main script function. | ||
* | ||
* @return object value computed for document | ||
*/ | ||
public abstract Object execute(); | ||
|
||
/** Set segment level id for the next document to score. * */ | ||
public void setDocId(int docId) { | ||
segmentDocLookup.setDocId(docId); | ||
} | ||
|
||
/** Get the script parameters provided in the request. */ | ||
public Map<String, Object> getParams() { | ||
return params; | ||
} | ||
|
||
/** Get doc values for the current document. */ | ||
public Map<String, LoadedDocValues<?>> getDoc() { | ||
return segmentDocLookup; | ||
} | ||
|
||
/** Factory interface for creating a RuntimeScript bound to a lucene segment. */ | ||
public interface SegmentFactory { | ||
|
||
/** | ||
* Create a RuntimeScript instance for a lucene segment. | ||
* | ||
* @param context lucene segment context | ||
* @return segment level RuntimeScript | ||
* @throws IOException | ||
*/ | ||
RuntimeScript newInstance(LeafReaderContext context) throws IOException; | ||
} | ||
|
||
/** | ||
* Factory required for the compilation of a RuntimeScript. Used to produce request level {@link | ||
* SegmentFactory}. See script compile contract {@link ScriptContext}. | ||
*/ | ||
public interface Factory { | ||
/** | ||
* Create request level {@link RuntimeScript.SegmentFactory}. | ||
* | ||
* @param params parameters from script request | ||
* @param docLookup index level doc value lookup provider | ||
* @return {@link RuntimeScript.SegmentFactory} to evaluate script | ||
*/ | ||
SegmentFactory newFactory(Map<String, Object> params, DocLookup docLookup); | ||
} | ||
|
||
// compile context for the RuntimeScript, contains script type info | ||
public static final ScriptContext<Factory> CONTEXT = | ||
new ScriptContext<>("runtime", Factory.class, SegmentFactory.class, RuntimeScript.class); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does the runtime field also need to be covered in this code path?
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.
Somehow the code never comes here when I put a breakpoint in this line. I assume it's not necessary to do that anymore. It doesn't stop here, even when I have a virtual field in the request.
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 code path is used for doing parallel fetch by chunks of fields, instead of documents. It should probably be supported.
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.
Do you know how I can test that locally?
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 the config used for the current testing https://github.com/Yelp/nrtsearch/blob/master/src/test/java/com/yelp/nrtsearch/server/grpc/MultiSegmentParallelFieldsFetchTest.java#L25
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. I was able to debug this part of the code with the above configs. It now returns the same object as the one with fetching docs.