mirror of https://github.com/apache/lucene.git
SOLR-8485: SelectStream now properly handles non-lowercase and/or quoted select field names
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1723648 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
819c59169b
commit
ac754fcd59
|
@ -135,6 +135,7 @@ Bug Fixes
|
|||
* SOLR-8371: Try and prevent too many recovery requests from stacking up and clean up some faulty
|
||||
cancel recovery logic. (Mark Miller)
|
||||
|
||||
* SOLR-8485: SelectStream now properly handles non-lowercase and/or quoted select field names (Dennis Gove)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
|
|
@ -23,15 +23,12 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
import org.apache.solr.client.solrj.io.comp.FieldComparator;
|
||||
import org.apache.solr.client.solrj.io.comp.StreamComparator;
|
||||
import org.apache.solr.client.solrj.io.ops.StreamOperation;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.Expressible;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
|
||||
|
@ -89,9 +86,14 @@ public class SelectStream extends TupleStream implements Expressible {
|
|||
selectedFields = new HashMap<String,String>(selectFieldsExpressions.size());
|
||||
for(StreamExpressionParameter parameter : selectFieldsExpressions){
|
||||
StreamExpressionValue selectField = (StreamExpressionValue)parameter;
|
||||
String value = selectField.getValue().trim().toLowerCase(Locale.ROOT);
|
||||
if(value.contains(" as ")){
|
||||
String[] parts = value.split(" as ");
|
||||
String value = selectField.getValue().trim();
|
||||
|
||||
// remove possible wrapping quotes
|
||||
if(value.length() > 2 && value.startsWith("\"") && value.endsWith("\"")){
|
||||
value = value.substring(1, value.length() - 1);
|
||||
}
|
||||
if(value.toLowerCase(Locale.ROOT).contains(" as ")){
|
||||
String[] parts = value.split("(?i) as "); // ensure we are splitting in a case-insensitive way
|
||||
if(2 != parts.length){
|
||||
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting select field of form 'fieldA' or 'fieldA as alias' but found %s",expression, value));
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public class StreamExpressionToExpessionTest extends LuceneTestCase {
|
|||
.withCollectionZkHost("collection1", "testhost:1234")
|
||||
.withCollectionZkHost("collection2", "testhost:1234")
|
||||
.withFunctionName("search", CloudSolrStream.class)
|
||||
.withFunctionName("select", SelectStream.class)
|
||||
.withFunctionName("merge", MergeStream.class)
|
||||
.withFunctionName("unique", UniqueStream.class)
|
||||
.withFunctionName("top", RankStream.class)
|
||||
|
@ -59,8 +60,7 @@ public class StreamExpressionToExpessionTest extends LuceneTestCase {
|
|||
.withFunctionName("avg", MeanMetric.class)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCloudSolrStream() throws Exception {
|
||||
|
||||
|
@ -83,6 +83,23 @@ public class StreamExpressionToExpessionTest extends LuceneTestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectStream() throws Exception {
|
||||
|
||||
SelectStream stream;
|
||||
String expressionString;
|
||||
|
||||
// Basic test
|
||||
stream = new SelectStream(StreamExpressionParser.parse("select(\"a_s as fieldA\", search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"))"), factory);
|
||||
expressionString = stream.toExpression(factory).toString();
|
||||
assertTrue(expressionString.contains("select(search(collection1,"));
|
||||
assertTrue(expressionString.contains("q=\"*:*\""));
|
||||
assertTrue(expressionString.contains("fl=\"id,a_s,a_i,a_f\""));
|
||||
assertTrue(expressionString.contains("sort=\"a_f asc, a_i asc\""));
|
||||
assertTrue(expressionString.contains("a_s as fieldA"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatsStream() throws Exception {
|
||||
|
||||
|
|
Loading…
Reference in New Issue