lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject [25/50] [abbrv] lucene-solr:feature/autoscaling: SOLR-11418: Allow comments in Streaming Expressions
Date Tue, 03 Oct 2017 13:39:06 GMT
SOLR-11418: Allow comments in Streaming Expressions


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/86fa1cf1
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/86fa1cf1
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/86fa1cf1

Branch: refs/heads/feature/autoscaling
Commit: 86fa1cf11bf45e8ca4e78d653d2ef2ceeb584194
Parents: 3f94f2e
Author: Joel Bernstein <jbernste@apache.org>
Authored: Thu Sep 28 21:36:13 2017 -0400
Committer: Joel Bernstein <jbernste@apache.org>
Committed: Thu Sep 28 21:36:13 2017 -0400

----------------------------------------------------------------------
 .../io/stream/expr/StreamExpressionParser.java  | 29 ++++++++++++++++++++
 .../solrj/io/stream/StreamExpressionTest.java   |  3 +-
 2 files changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86fa1cf1/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java
index fd5c9d3..7ae797f 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java
@@ -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();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86fa1cf1/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
----------------------------------------------------------------------
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 6799371..6f11382 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
@@ -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))," +


Mime
View raw message