Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D99D6200D14 for ; Tue, 3 Oct 2017 15:38:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D86EE160BDB; Tue, 3 Oct 2017 13:38:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2D80B160BDA for ; Tue, 3 Oct 2017 15:38:50 +0200 (CEST) Received: (qmail 60709 invoked by uid 500); 3 Oct 2017 13:38:45 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 60447 invoked by uid 99); 3 Oct 2017 13:38:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Oct 2017 13:38:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E7568F5C75; Tue, 3 Oct 2017 13:38:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: noble@apache.org To: commits@lucene.apache.org Date: Tue, 03 Oct 2017 13:39:06 -0000 Message-Id: <1a934422788e4a8d86b497609ee4fe52@git.apache.org> In-Reply-To: <4a9e988249864512aa0354c01cc9c19d@git.apache.org> References: <4a9e988249864512aa0354c01cc9c19d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [25/50] [abbrv] lucene-solr:feature/autoscaling: SOLR-11418: Allow comments in Streaming Expressions archived-at: Tue, 03 Oct 2017 13:38:51 -0000 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 Authored: Thu Sep 28 21:36:13 2017 -0400 Committer: Joel Bernstein 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))," +