Skip to content

Commit

Permalink
Rename ReplaceableConstDoubleValueSource class to PerThreadReplaceabl…
Browse files Browse the repository at this point in the history
…eConstDoubleValueSource

Signed-off-by: Sorabh Hamirwasia <[email protected]>
  • Loading branch information
sohami committed Nov 15, 2023
1 parent eab481b commit f1b39cd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class ExpressionAggregationScript implements AggregationScript.LeafFactory {
final SimpleBindings bindings;
final DoubleValuesSource source;
final boolean needsScore;
final ReplaceableConstDoubleValueSource specialValue; // _value
final PerThreadReplaceableConstDoubleValueSource specialValue; // _value

ExpressionAggregationScript(Expression e, SimpleBindings b, boolean n, ReplaceableConstDoubleValueSource v) {
ExpressionAggregationScript(Expression e, SimpleBindings b, boolean n, PerThreadReplaceableConstDoubleValueSource v) {

Check warning on line 58 in modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionAggregationScript.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionAggregationScript.java#L58

Added line #L58 was not covered by tests
exprScript = e;
bindings = b;
source = exprScript.getDoubleValuesSource(bindings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ private static AggregationScript.LeafFactory newAggregationScript(
// instead of complicating SimpleBindings (which should stay simple)
SimpleBindings bindings = new SimpleBindings();
boolean needsScores = false;
ReplaceableConstDoubleValueSource specialValue = null;
PerThreadReplaceableConstDoubleValueSource specialValue = null;

Check warning on line 319 in modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionScriptEngine.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionScriptEngine.java#L319

Added line #L319 was not covered by tests
for (String variable : expr.variables) {
try {
if (variable.equals("_score")) {
bindings.add("_score", DoubleValuesSource.SCORES);
needsScores = true;
} else if (variable.equals("_value")) {
specialValue = new ReplaceableConstDoubleValueSource();
specialValue = new PerThreadReplaceableConstDoubleValueSource();

Check warning on line 326 in modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionScriptEngine.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionScriptEngine.java#L326

Added line #L326 was not covered by tests
bindings.add("_value", specialValue);
// noop: _value is special for aggregations, and is handled in ExpressionScriptBindings
// TODO: if some uses it in a scoring expression, they will get a nasty failure when evaluating...need a
Expand Down Expand Up @@ -388,15 +388,15 @@ private static ScoreScript.LeafFactory newScoreScript(Expression expr, SearchLoo
// NOTE: if we need to do anything complicated with bindings in the future, we can just extend Bindings,
// instead of complicating SimpleBindings (which should stay simple)
SimpleBindings bindings = new SimpleBindings();
ReplaceableConstDoubleValueSource specialValue = null;
PerThreadReplaceableConstDoubleValueSource specialValue = null;

Check warning on line 391 in modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionScriptEngine.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionScriptEngine.java#L391

Added line #L391 was not covered by tests
boolean needsScores = false;
for (String variable : expr.variables) {
try {
if (variable.equals("_score")) {
bindings.add("_score", DoubleValuesSource.SCORES);
needsScores = true;
} else if (variable.equals("_value")) {
specialValue = new ReplaceableConstDoubleValueSource();
specialValue = new PerThreadReplaceableConstDoubleValueSource();

Check warning on line 399 in modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionScriptEngine.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/ExpressionScriptEngine.java#L399

Added line #L399 was not covered by tests
bindings.add("_value", specialValue);
// noop: _value is special for aggregations, and is handled in ExpressionScriptBindings
// TODO: if some uses it in a scoring expression, they will get a nasty failure when evaluating...need a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
* thread-safe for concurrent segment search use case by keeping the {@link DoubleValues} per thread. Any update to the value happens in
* thread specific {@link DoubleValuesSource} instance.
*/
final class ReplaceableConstDoubleValueSource extends DoubleValuesSource {
final class PerThreadReplaceableConstDoubleValueSource extends DoubleValuesSource {
// Multiple slices can be processed by same thread but that will be sequential, so keeping per thread is fine
final Map<Long, ReplaceableConstDoubleValues> perThreadDoubleValues;

ReplaceableConstDoubleValueSource() {
PerThreadReplaceableConstDoubleValueSource() {
perThreadDoubleValues = new ConcurrentHashMap<>();

Check warning on line 55 in modules/lang-expression/src/main/java/org/opensearch/script/expression/PerThreadReplaceableConstDoubleValueSource.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/PerThreadReplaceableConstDoubleValueSource.java#L54-L55

Added lines #L54 - L55 were not covered by tests
}

Expand Down

0 comments on commit f1b39cd

Please sign in to comment.