gsmiller commented on code in PR #12560:
URL: https://github.com/apache/lucene/pull/12560#discussion_r1327828413
##########
lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionFunctionValues.java:
##########
@@ -39,21 +39,21 @@ class ExpressionFunctionValues extends DoubleValues {
}
@Override
- public boolean advanceExact(int doc) {
+ public boolean advanceExact(int doc) throws IOException {
if (currentDoc == doc) {
return true;
}
+ for (DoubleValues v : functionValues) {
+ v.advanceExact(doc);
Review Comment:
There's a bit of indirection here, so maybe this will help:
1. `ExpressionFunctionValues` represents a computed expression value for a
given doc. This comes from any instance of `Expression` (e.g., from
`JavascriptCompiler#compile`). `Expression#getDoubleValuesSource` provides an
instance of `ExpressionValueSource`, which in turn provides
`ExpressionFunctionValues` when you call `#getValues` for a specific segment
context. `ExpressionFunctionValues#advanceExact` always returns true
(expressions produce results for all docs), and
`ExpressionFunctionValues#doubleValue` computes the value for the doc.
2. In `ExpressionValueSource#getValues`, we take all the expression's
arguments (which are all instances of `DoubleValues`) and wrap them with an
anonymous class provided by `#zeroWhenUnpositioned`. The main purpose of this
wrapper is to provide a value of `0` for any expression argument that isn't
available for a doc (i.e., `advanceExact` returned false for the doc). This PR
extends the functionality of this wrapper to lazily advance until the point
when `doubleValues` is called.
3. So without this PR, `ExpressionFunctionValues#advanceExact` is lazy but
once `ExpressionFunctionValues#doubleValues` is called, it advances all of the
arguments (regardless of whether-or-not that argument is ever needed for a
given doc). With this change, the `advanceExact` also becomes lazy, so it gets
deferred until a value is actually needed.
--
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]