mirror of https://github.com/apache/lucene.git
SOLR-11344: Fix copyOfRange Stream Evaluator so the end index parameter can be equal to the length array
This commit is contained in:
parent
0283d3e28a
commit
a4fc14baed
|
@ -79,8 +79,8 @@ public class CopyOfRangeEvaluator extends RecursiveNumericEvaluator implements M
|
|||
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - startIdx (%d) must be less than endIdx (%d)", toExpression(constructingFactory), startIdx, endIdx));
|
||||
}
|
||||
|
||||
if(endIdx >= sourceValues.size()){
|
||||
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - endIdx (%d) must be less than size of source array (%d)", toExpression(constructingFactory), endIdx, sourceValues.size()));
|
||||
if(endIdx > sourceValues.size()){
|
||||
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - endIdx (%d) must not be greater then size of source array (%d)", toExpression(constructingFactory), endIdx, sourceValues.size()));
|
||||
}
|
||||
|
||||
return Arrays.stream(Arrays.copyOfRange(sourceValues.toArray(), startIdx, endIdx)).collect(Collectors.toList());
|
||||
|
|
|
@ -5776,7 +5776,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
"field=\"test_dt\", " +
|
||||
"count(*), sum(price_f), max(price_f), min(price_f))";
|
||||
|
||||
String cexpr = "let(a="+expr+", c=col(a, max(price_f)), tuple(copy=copyOfRange(c, 1, 3)))";
|
||||
String cexpr = "let(a="+expr+", c=col(a, max(price_f)), tuple(copy=copyOfRange(c, 1, 3), copy2=copyOfRange(c, 2, 4), l=length(c)))";
|
||||
|
||||
ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
|
||||
paramsLoc.set("expr", cexpr);
|
||||
|
@ -5793,6 +5793,15 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
assertTrue(copy1.size() == 2);
|
||||
assertTrue(copy1.get(0).doubleValue() == 500D);
|
||||
assertTrue(copy1.get(1).doubleValue() == 300D);
|
||||
|
||||
List<Number> copy2 = (List<Number>)tuples.get(0).get("copy2");
|
||||
assertTrue(copy2.size() == 2);
|
||||
assertTrue(copy2.get(0).doubleValue() == 300D);
|
||||
assertTrue(copy2.get(1).doubleValue() == 400D);
|
||||
|
||||
long l = tuples.get(0).getLong("l");
|
||||
assertTrue(l == 4);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue