Apache Solr open-source search software
SOLR-11344: Fix copyOfRange Stream Evaluator so the end index parameter can be equal to the length array
Joel Bernsteina4fc14baed32
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/CopyOfRangeEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/CopyOfRangeEvaluator.javaindex 685ef30f3d1..6688571f33f 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/CopyOfRangeEvaluator.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/CopyOfRangeEvaluator.java@@ -79,8 +79,8 @@ public class CopyOfRangeEvaluator extends RecursiveNumericEvaluator implements Mthrow 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());diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.javaindex 2ee881edbf3..9b2b18618b6 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java@@ -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);+}