From 61676188d7f592f697933b6051806c0bc55b406a Mon Sep 17 00:00:00 2001 From: Joel Bernstein Date: Fri, 30 Dec 2016 19:54:00 -0500 Subject: [PATCH] SOLR-9495: AIOBE with confusing message for incomplete sort spec in Streaming Expression --- .../solr/client/solrj/io/stream/CloudSolrStream.java | 4 ++++ .../client/solrj/io/stream/StreamExpressionTest.java | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java index 0580122bf38..f177585e2a3 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java @@ -332,6 +332,10 @@ public class CloudSolrStream extends TupleStream implements Expressible { String[] spec = s.trim().split("\\s+"); //This should take into account spaces in the sort spec. + if (spec.length != 2) { + throw new IOException("Invalid sort spec:" + s); + } + String fieldName = spec[0].trim(); String order = spec[1].trim(); 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.java index 3bfe12996ae..936d42fe34f 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 @@ -162,6 +162,16 @@ public class StreamExpressionTest extends SolrCloudTestCase { assertTrue(e.getMessage().contains("fl param expected for search function")); } + + try { + expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=\"blah\", fl=\"id, a_f\", sort=\"a_f\")"); + stream = new CloudSolrStream(expression, factory); + tuples = getTuples(stream); + throw new Exception("Should be an exception here"); + } catch(Exception e) { + assertTrue(e.getMessage().contains("Invalid sort spec")); + } + } @Test