mirror of https://github.com/apache/lucene.git
SOLR-11418: Allow comments in Streaming Expressions
This commit is contained in:
parent
3f94f2ed4c
commit
86fa1cf11b
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.solr.client.solrj.io.stream.expr;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -34,6 +36,7 @@ public class StreamExpressionParser {
|
|||
}
|
||||
|
||||
public static StreamExpression parse(String clause){
|
||||
clause = stripComments(clause);
|
||||
StreamExpressionParameter expr = generateStreamExpression(clause);
|
||||
if(null != expr && expr instanceof StreamExpression){
|
||||
return (StreamExpression)expr;
|
||||
|
@ -41,6 +44,32 @@ public class StreamExpressionParser {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static String stripComments(String clause) throws RuntimeException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
BufferedReader reader = null;
|
||||
|
||||
try {
|
||||
reader = new BufferedReader(new StringReader(clause));
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if(line.trim().startsWith("#")) {
|
||||
continue;
|
||||
} else {
|
||||
builder.append(line+'\n');
|
||||
}
|
||||
}
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally{
|
||||
try {
|
||||
reader.close();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static StreamExpressionParameter generateStreamExpression(String clause){
|
||||
String working = clause.trim();
|
||||
|
|
|
@ -6630,8 +6630,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
|
||||
@Test
|
||||
public void testGammaDistribution() throws Exception {
|
||||
String cexpr = "let(echo=true, " +
|
||||
String cexpr = "#comment\nlet(echo=true, " +
|
||||
"a=describe(sample(gammaDistribution(1, 10),10000)), " +
|
||||
"\n# commment\n"+
|
||||
"b=describe(sample(gammaDistribution(3, 10),10000)), " +
|
||||
"c=describe(sample(gammaDistribution(5, 10),10000))," +
|
||||
"d=describe(sample(gammaDistribution(7, 10),10000))," +
|
||||
|
|
Loading…
Reference in New Issue