Apache Solr open-source search software
SOLR-16070: Enable spotless for solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/ (#717)
Kevin Risdenb218c177b8e3
diff --git a/gradle/validation/spotless.gradle b/gradle/validation/spotless.gradleindex 6ee640e267c..4047fc5c454 100644--- a/gradle/validation/spotless.gradle+++ b/gradle/validation/spotless.gradle@@ -53,9 +53,6 @@ configure(project(":solr").subprojects) { prj ->"src/java/org/apache/solr/parser/Token.java","src/java/org/apache/solr/parser/TokenMgrError.java"break- case ":solr:solrj":- targetExclude "src/test/org/apache/solr/client/solrj/io/stream/*.java"- breakcase ":solr:modules:hdfs":// Exclude Hadoop copied files to make upgrades easiertargetExclude "src/**/org/apache/hadoop/**"diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/CloudAuthStreamTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/CloudAuthStreamTest.javaindex 7e0f090600c..b39c8d1fa6c 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/CloudAuthStreamTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/CloudAuthStreamTest.java@@ -49,27 +49,27 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;/**- * tests various streaming expressions (via the SolrJ {@link SolrStream} API) against a SolrCloud cluster- * using both Authenticationand Role based Authorization+ * tests various streaming expressions (via the SolrJ {@link SolrStream} API) against a SolrCloud+ * cluster using both Authenticationand Role based Authorization*/public class CloudAuthStreamTest extends SolrCloudTestCase {-+private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());private static final String COLLECTION_X = "collection_x";private static final String COLLECTION_Y = "collection_y";-+private static final String READ_ONLY_USER = "read_only_user";private static final String WRITE_X_USER = "write_x_user";private static final String WRITE_Y_USER = "write_y_user";private static final String ADMIN_USER = "admin_user";-+private static String solrUrl = null;-+/**- * Helper that returns the original {@link SolrRequest} <em>with it's original type</em>- * so it can be chained. This menthod knows that for the purpose of this test, every user name- * is it's own password+ * Helper that returns the original {@link SolrRequest} <em>with it's original type</em> so it can+ * be chained. This menthod knows that for the purpose of this test, every user name is it's own+ * password** @see SolrRequest#setBasicAuthCredentials*/@@ -81,53 +81,54 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {@BeforeClasspublic static void setupCluster() throws Exception {- final List<String> users = Arrays.asList(READ_ONLY_USER, WRITE_X_USER, WRITE_Y_USER, ADMIN_USER);+ final List<String> users =+ Arrays.asList(READ_ONLY_USER, WRITE_X_USER, WRITE_Y_USER, ADMIN_USER);// For simplicity: every user uses a password the same as their name...- final Map<String,String> credentials = users.stream()- .collect(Collectors.toMap(Function.identity(), s -> getSaltedHashedValue(s)));-+ final Map<String, String> credentials =+ users.stream().collect(Collectors.toMap(Function.identity(), s -> getSaltedHashedValue(s)));+// For simplicity: Every user is their own role...- final Map<String,String> roles = users.stream()- .collect(Collectors.toMap(Function.identity(), Function.identity()));-- final String SECURITY_JSON = Utils.toJSONString- (Map.of("authorization",- Map.of("class", RuleBasedAuthorizationPlugin.class.getName(),- "user-role", roles,- // NOTE: permissions order matters!- "permissions", Arrays.asList(// any authn user can 'read' or hit /stream- Map.of("name","read",- "role","*"),- Map.of("name","stream",- "collection", "*",- "path", "/stream",- "role","*"),- // per collection write perms- Map.of("name","update",- "collection", COLLECTION_X,- "role", WRITE_X_USER),- Map.of("name","update",- "collection", COLLECTION_Y,- "role", WRITE_Y_USER),- Map.of("name","all",- "role",ADMIN_USER))),- "authentication",- Map.of("class", BasicAuthPlugin.class.getName(),- "blockUnknown",true,- "credentials", credentials)));-- // we want at most one core per node to force lots of network traffic to try and tickle distributed bugs- configureCluster(5)- .withSecurityJson(SECURITY_JSON)- .configure();+ final Map<String, String> roles =+ users.stream().collect(Collectors.toMap(Function.identity(), Function.identity()));++ final String SECURITY_JSON =+ Utils.toJSONString(+ Map.of(+ "authorization",+ Map.of(+ "class",+ RuleBasedAuthorizationPlugin.class.getName(),+ "user-role",+ roles,+ // NOTE: permissions order matters!+ "permissions",+ Arrays.asList( // any authn user can 'read' or hit /stream+ Map.of("name", "read", "role", "*"),+ Map.of("name", "stream", "collection", "*", "path", "/stream", "role", "*"),+ // per collection write perms+ Map.of("name", "update", "collection", COLLECTION_X, "role", WRITE_X_USER),+ Map.of("name", "update", "collection", COLLECTION_Y, "role", WRITE_Y_USER),+ Map.of("name", "all", "role", ADMIN_USER))),+ "authentication",+ Map.of(+ "class",+ BasicAuthPlugin.class.getName(),+ "blockUnknown",+ true,+ "credentials",+ credentials)));++ // we want at most one core per node to force lots of network traffic to try and tickle+ // distributed bugs+ configureCluster(5).withSecurityJson(SECURITY_JSON).configure();for (String collection : Arrays.asList(COLLECTION_X, COLLECTION_Y)) {CollectionAdminRequest.createCollection(collection, "_default", 2, 2).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).setBasicAuthCredentials(ADMIN_USER, ADMIN_USER)- .process(cluster.getSolrClient());+ .process(cluster.getSolrClient());}-+for (String collection : Arrays.asList(COLLECTION_X, COLLECTION_Y)) {cluster.getZkStateReader()@@ -139,118 +140,163 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {}solrUrl = cluster.getRandomJetty(random()).getProxyBaseUrl().toString();-+log.info("All stream requests will be sent to random solrUrl: {}", solrUrl);}-+@AfterClasspublic static void clearVariables() {solrUrl = null;}-+@Afterpublic void clearCollections() throws Exception {log.info("Clearing Collections @After test method...");- assertEquals(0,- setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTION_X).getStatus());- assertEquals(0,- setBasicAuthCredentials(new UpdateRequest(), WRITE_Y_USER)- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTION_Y).getStatus());+ assertEquals(+ 0,+ setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)+ .deleteByQuery("*:*")+ .commit(cluster.getSolrClient(), COLLECTION_X)+ .getStatus());+ assertEquals(+ 0,+ setBasicAuthCredentials(new UpdateRequest(), WRITE_Y_USER)+ .deleteByQuery("*:*")+ .commit(cluster.getSolrClient(), COLLECTION_Y)+ .getStatus());}-- /**- * Simple sanity checks that authentication is working the way the test expects- */++ /** Simple sanity checks that authentication is working the way the test expects */public void testSanityCheckAuth() throws Exception {-- assertEquals("sanity check of non authenticated query request",- 401,- expectThrows(SolrException.class, () -> {- final long ignored =- (new QueryRequest(params("q", "*:*",- "rows", "0",- "_trace", "no_auth_sanity_check")))- .process(cluster.getSolrClient(), COLLECTION_X).getResults().getNumFound();- }).code());-- assertEquals("sanity check of update to X from write_X user",- 0,- (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)- .add(sdoc("id", "1_from_write_X_user"))- .commit(cluster.getSolrClient(), COLLECTION_X)).getStatus());-- assertEquals("sanity check of update to X from read only user",- 500, // should be 403, but CloudSolrClient lies on updates for now: SOLR-14222- expectThrows(SolrException.class, () -> {- final int ignored = (setBasicAuthCredentials(new UpdateRequest(), READ_ONLY_USER)- .add(sdoc("id", "2_from_read_only_user"))- .commit(cluster.getSolrClient(), COLLECTION_X)).getStatus();- }).code());-- assertEquals("sanity check of update to X from write_Y user",- 500, // should be 403, but CloudSolrClient lies on updates for now: SOLR-14222- expectThrows(SolrException.class, () -> {- final int ignored = (setBasicAuthCredentials(new UpdateRequest(), WRITE_Y_USER)- .add(sdoc("id", "3_from_write_Y_user"))- .commit(cluster.getSolrClient(), COLLECTION_X)).getStatus();- }).code());-- assertEquals("sanity check of update to Y from write_Y user",- 0,- (setBasicAuthCredentials(new UpdateRequest(), WRITE_Y_USER)- .add(sdoc("id", "1_from_write_Y_user"))- .commit(cluster.getSolrClient(), COLLECTION_Y)).getStatus());-++ assertEquals(+ "sanity check of non authenticated query request",+ 401,+ expectThrows(+ SolrException.class,+ () -> {+ final long ignored =+ (new QueryRequest(+ params(+ "q", "*:*",+ "rows", "0",+ "_trace", "no_auth_sanity_check")))+ .process(cluster.getSolrClient(), COLLECTION_X)+ .getResults()+ .getNumFound();+ })+ .code());++ assertEquals(+ "sanity check of update to X from write_X user",+ 0,+ (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)+ .add(sdoc("id", "1_from_write_X_user"))+ .commit(cluster.getSolrClient(), COLLECTION_X))+ .getStatus());++ assertEquals(+ "sanity check of update to X from read only user",+ 500, // should be 403, but CloudSolrClient lies on updates for now: SOLR-14222+ expectThrows(+ SolrException.class,+ () -> {+ final int ignored =+ (setBasicAuthCredentials(new UpdateRequest(), READ_ONLY_USER)+ .add(sdoc("id", "2_from_read_only_user"))+ .commit(cluster.getSolrClient(), COLLECTION_X))+ .getStatus();+ })+ .code());++ assertEquals(+ "sanity check of update to X from write_Y user",+ 500, // should be 403, but CloudSolrClient lies on updates for now: SOLR-14222+ expectThrows(+ SolrException.class,+ () -> {+ final int ignored =+ (setBasicAuthCredentials(new UpdateRequest(), WRITE_Y_USER)+ .add(sdoc("id", "3_from_write_Y_user"))+ .commit(cluster.getSolrClient(), COLLECTION_X))+ .getStatus();+ })+ .code());++ assertEquals(+ "sanity check of update to Y from write_Y user",+ 0,+ (setBasicAuthCredentials(new UpdateRequest(), WRITE_Y_USER)+ .add(sdoc("id", "1_from_write_Y_user"))+ .commit(cluster.getSolrClient(), COLLECTION_Y))+ .getStatus());+for (String user : Arrays.asList(READ_ONLY_USER, WRITE_Y_USER, WRITE_X_USER)) {for (String collection : Arrays.asList(COLLECTION_X, COLLECTION_Y)) {- assertEquals("sanity check: query "+collection+" from user: "+user,- 1, countDocsInCollection(collection, user));+ assertEquals(+ "sanity check: query " + collection + " from user: " + user,+ 1,+ countDocsInCollection(collection, user));}}}public void testEchoStream() throws Exception {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream",- "expr", "echo(hello world)"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt", "/stream",+ "expr", "echo(hello world)"));solrStream.setCredentials(READ_ONLY_USER, READ_ONLY_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size());assertEquals("hello world", tuples.get(0).get("echo"));}-+public void testEchoStreamNoCredentials() throws Exception {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream",- "expr", "echo(hello world)"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt", "/stream",+ "expr", "echo(hello world)"));// NOTE: no credentials-+// NOTE: Can't make any assertions about Exception: SOLR-14226- expectThrows(Exception.class, () -> {- final List<Tuple> ignored = getTuples(solrStream);- });+ expectThrows(+ Exception.class,+ () -> {+ final List<Tuple> ignored = getTuples(solrStream);+ });}-+public void testEchoStreamInvalidCredentials() throws Exception {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream",- "expr", "echo(hello world)"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt", "/stream",+ "expr", "echo(hello world)"));solrStream.setCredentials(READ_ONLY_USER, "BOGUS_PASSWORD");-+// NOTE: Can't make any assertions about Exception: SOLR-14226- expectThrows(Exception.class, () -> {- final List<Tuple> ignored = getTuples(solrStream);- });+ expectThrows(+ Exception.class,+ () -> {+ final List<Tuple> ignored = getTuples(solrStream);+ });}-+public void testSimpleUpdateStream() throws Exception {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream", "expr",- "update("+COLLECTION_X+",batchSize=1," +- "tuple(id=42,a_i=1,b_i=5))"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt",+ "/stream",+ "expr",+ "update(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42,a_i=1,b_i=5))"));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size());@@ -258,77 +304,94 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}-+public void testSimpleUpdateStreamInvalidCredentials() throws Exception {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream", "expr",- "update("+COLLECTION_X+",batchSize=1," +- "tuple(id=42,a_i=1,b_i=5))"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt",+ "/stream",+ "expr",+ "update(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42,a_i=1,b_i=5))"));// "WRITE" credentials should be required for 'update(...)'solrStream.setCredentials(WRITE_X_USER, "BOGUS_PASSWORD");-+// NOTE: Can't make any assertions about Exception: SOLR-14226- expectThrows(Exception.class, () -> {- final List<Tuple> ignored = getTuples(solrStream);- });-+ expectThrows(+ Exception.class,+ () -> {+ final List<Tuple> ignored = getTuples(solrStream);+ });+assertEquals(0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}-+public void testSimpleUpdateStreamInsufficientCredentials() throws Exception {// both of these users have valid credentials and authz read COLLECTION_X, but neither has// authz to write to X...for (String user : Arrays.asList(READ_ONLY_USER, WRITE_Y_USER)) {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream", "expr",- "update("+COLLECTION_X+",batchSize=1," +- "tuple(id=42,a_i=1,b_i=5))"));-+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt",+ "/stream",+ "expr",+ "update(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42,a_i=1,b_i=5))"));+solrStream.setCredentials(user, user);-+// NOTE: Can't make any assertions about Exception: SOLR-14226- expectThrows(Exception.class, () -> {- final List<Tuple> ignored = getTuples(solrStream);- });+ expectThrows(+ Exception.class,+ () -> {+ final List<Tuple> ignored = getTuples(solrStream);+ });}-+assertEquals(0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}-+public void testIndirectUpdateStream() throws Exception {{ // WRITE_X user should be able to update X via a (dummy) stream from Y...- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_Y,- params("qt", "/stream", "expr",- "update("+COLLECTION_X+",batchSize=1," +- "tuple(id=42,a_i=1,b_i=5))"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_Y,+ params(+ "qt",+ "/stream",+ "expr",+ "update(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42,a_i=1,b_i=5))"));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size());assertEquals(1L, tuples.get(0).get("totalIndexed"));}-+{ // Now add some "real" docs directly to Y...final UpdateRequest update = setBasicAuthCredentials(new UpdateRequest(), WRITE_Y_USER);for (int i = 1; i <= 42; i++) {- update.add(sdoc("id",i+"y","foo_i",""+i));+ update.add(sdoc("id", i + "y", "foo_i", "" + i));}- assertEquals("initial docs in Y",- 0, update.commit(cluster.getSolrClient(), COLLECTION_Y).getStatus());+ assertEquals(+ "initial docs in Y", 0, update.commit(cluster.getSolrClient(), COLLECTION_Y).getStatus());}{ // WRITE_X user should be able to update X via a (search) stream from Y (routed via Y)- final String expr- = "update("+COLLECTION_X+", batchSize=50, " // note batch size- + " search("+COLLECTION_Y+", "- + " q=\"foo_i:[* TO 10]\", " // 10 matches = 1 batch- + " rows=100, "- + " fl=\"id,foo_i,_version_\", " // pruneVersionField default true- + " sort=\"foo_i desc\")) "- ;-- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_Y, // NOTE: Y route- params("qt", "/stream",- "expr", expr));+ // note batch size - 10 matches = 1 batch+ // pruneVersionField default true+ final String expr =+ "update("+ + COLLECTION_X+ + ", batchSize=50, search("+ + COLLECTION_Y+ + ", q=\"foo_i:[* TO 10]\", rows=100, fl=\"id,foo_i,_version_\", sort=\"foo_i desc\"))";++ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_Y, // NOTE: Y route+ params("qt", "/stream", "expr", expr));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size());@@ -337,65 +400,67 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {}{ // WRITE_X user should be able to update X via a (search) stream from Y (routed via X)...- final String expr- = "update("+COLLECTION_X+", batchSize=5, " // note batch size- + " search("+COLLECTION_Y+", "- + " q=\"foo_i:[30 TO *]\", " // 13 matches = 3 batches- + " rows=100, "- + " fl=\"id,foo_i\", "- + " sort=\"foo_i desc\")) "- ;-- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X, // NOTE: X route- params("qt", "/stream",- "expr", expr));+ // note batch size - 13 matches = 3 batches+ final String expr =+ "update("+ + COLLECTION_X+ + ", batchSize=5, search("+ + COLLECTION_Y+ + ", q=\"foo_i:[30 TO *]\", rows=100, fl=\"id,foo_i\", sort=\"foo_i desc\"))";++ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X, // NOTE: X route+ params("qt", "/stream", "expr", expr));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(3, tuples.size());-- assertEquals( 5L, tuples.get(0).get("batchIndexed"));- assertEquals( 5L, tuples.get(0).get("totalIndexed"));-- assertEquals( 5L, tuples.get(1).get("batchIndexed"));++ assertEquals(5L, tuples.get(0).get("batchIndexed"));+ assertEquals(5L, tuples.get(0).get("totalIndexed"));++ assertEquals(5L, tuples.get(1).get("batchIndexed"));assertEquals(10L, tuples.get(1).get("totalIndexed"));-- assertEquals( 3L, tuples.get(2).get("batchIndexed"));++ assertEquals(3L, tuples.get(2).get("batchIndexed"));assertEquals(13L, tuples.get(2).get("totalIndexed"));}assertEquals(1L + 10L + 13L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));-}-+public void testIndirectUpdateStreamInsufficientCredentials() throws Exception {-+// regardless of how it's routed, WRITE_Y should NOT have authz to stream updates to X...for (String path : Arrays.asList(COLLECTION_X, COLLECTION_Y)) {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + path,- params("qt", "/stream", "expr",- "update("+COLLECTION_X+",batchSize=1," +- "tuple(id=42,a_i=1,b_i=5))"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + path,+ params(+ "qt",+ "/stream",+ "expr",+ "update(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42,a_i=1,b_i=5))"));solrStream.setCredentials(WRITE_Y_USER, WRITE_Y_USER);-+// NOTE: Can't make any assertions about Exception: SOLR-14226- expectThrows(Exception.class, () -> {- final List<Tuple> ignored = getTuples(solrStream);- });+ expectThrows(+ Exception.class,+ () -> {+ final List<Tuple> ignored = getTuples(solrStream);+ });}assertEquals(0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}public void testExecutorUpdateStream() throws Exception {- final String expr- = "executor(threads=1, "- + " tuple(expr_s=\"update("+COLLECTION_X+", batchSize=5, "- + " tuple(id=42,a_i=1,b_i=5)) "- + " \")) "- ;- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream",- "expr", expr));+ final String expr =+ "executor(threads=1, tuple(expr_s=\"update("+ + COLLECTION_X+ + ", batchSize=5, tuple(id=42,a_i=1,b_i=5))\"))";+ final SolrStream solrStream =+ new SolrStream(solrUrl + "/" + COLLECTION_X, params("qt", "/stream", "expr", expr));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(0, tuples.size());@@ -411,49 +476,50 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {// ... regardless of how the request is routed...for (String path : Arrays.asList(COLLECTION_X, COLLECTION_Y)) {final String trace = user + ":" + path;- final String expr- = "executor(threads=1, "- + " tuple(expr_s=\"update("+COLLECTION_X+", batchSize=5, "- + " tuple(id='"+(++id)+"',foo_s='"+trace+"')) "- + " \")) "- ;- final SolrStream solrStream = new SolrStream(solrUrl + "/" + path,- params("qt", "/stream",- "_trace", "executor_via_" + trace,- "expr", expr));+ final String expr =+ "executor(threads=1,tuple(expr_s=\"update("+ + COLLECTION_X+ + ", batchSize=5,tuple(id='"+ + (++id)+ + "',foo_s='"+ + trace+ + "'))\"))";+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + path,+ params("qt", "/stream", "_trace", "executor_via_" + trace, "expr", expr));solrStream.setCredentials(user, user);// NOTE: Becaue of the backgroun threads, no failures will to be returned to client...final List<Tuple> tuples = getTuples(solrStream);assertEquals(0, tuples.size());-- // we have to assert that the updates failed solely based on the side effects...- assertEquals("doc count after execute update via " + trace,- 0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));+ // we have to assert that the updates failed solely based on the side effects...+ assertEquals(+ "doc count after execute update via " + trace,+ 0L,+ commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}}// sanity check- assertEquals("final doc count",- 0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));+ assertEquals("final doc count", 0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}public void testDaemonUpdateStream() throws Exception {final String daemonUrl = getRandomCoreUrl(COLLECTION_X);log.info("Using Daemon @ {}", daemonUrl);-+{- final String expr- // NOTE: inspite of what is implied by 'terminate=true', this daemon will- // NEVER terminate on it's own as long as the updates are successful- // (aparently that requires usage of anest topic() stream to set a "sleepMillis"?!?!?!)- = "daemon(id=daemonId,runInterval=1000,terminate=true, "- + " update("+COLLECTION_X+",tuple(id=42,a_i=1,b_i=5))) "- ;- final SolrStream solrStream = new SolrStream(daemonUrl,- params("qt", "/stream",- "expr", expr));+ // NOTE: in spite of what is implied by 'terminate=true', this daemon will NEVER terminate on+ // it's own as long as the updates are successful (apparently that requires usage of a topic()+ // stream to set a "sleepMillis"?!)+ final String expr =+ "daemon(id=daemonId,runInterval=1000,terminate=true,update("+ + COLLECTION_X+ + ",tuple(id=42,a_i=1,b_i=5)))";+ final SolrStream solrStream =+ new SolrStream(daemonUrl, params("qt", "/stream", "expr", expr));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size()); // daemon starting status@@ -462,10 +528,13 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {// We have to poll the daemon 'list' to know once it's run...long iterations = 0;final TimeOut timeout = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME);- while ( ! timeout.hasTimedOut() ) {- final SolrStream daemonCheck = new SolrStream(daemonUrl,- params("qt", "/stream",- "action", "list"));+ while (!timeout.hasTimedOut()) {+ final SolrStream daemonCheck =+ new SolrStream(+ daemonUrl,+ params(+ "qt", "/stream",+ "action", "list"));daemonCheck.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(daemonCheck);assertEquals(1, tuples.size()); // our daemon;@@ -476,39 +545,45 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {}Thread.sleep(Math.max(1, Math.min(5000, timeout.timeLeft(TimeUnit.MILLISECONDS))));}- assertTrue("Didn't see any iterations after waiting an excessive amount of time: " + iterations,- 0 < iterations);+ assertTrue(+ "Didn't see any iterations after waiting an excessive amount of time: " + iterations,+ 0 < iterations);} finally {// kill the damon...- final SolrStream daemonKiller = new SolrStream(daemonUrl,- params("qt", "/stream",- "action", "kill",- "id", "daemonId"));+ final SolrStream daemonKiller =+ new SolrStream(+ daemonUrl,+ params(+ "qt", "/stream",+ "action", "kill",+ "id", "daemonId"));daemonKiller.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(daemonKiller);assertEquals(1, tuples.size()); // daemon death status}-+assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}-+public void testDaemonUpdateStreamInsufficientCredentials() throws Exception {final String daemonUrl = getRandomCoreUrl(COLLECTION_X);log.info("Using Daemon @ {}", daemonUrl);-+// both of these users have valid credentials and authz read COLLECTION_X, but neither has// authz to write to X...for (String user : Arrays.asList(READ_ONLY_USER, WRITE_Y_USER)) {final String daemonId = "daemon_" + user;{- final String expr- = "daemon(id="+daemonId+",runInterval=1000,terminate=true, "- + " update("+COLLECTION_X+",tuple(id=42,a_i=1,b_i=5))) "- ;- final SolrStream solrStream = new SolrStream(daemonUrl,- params("qt", "/stream",- "_trace", "start_" + daemonId,- "expr", expr));+ final String expr =+ "daemon(id="+ + daemonId+ + ",runInterval=1000,terminate=true, "+ + " update("+ + COLLECTION_X+ + ",tuple(id=42,a_i=1,b_i=5))) ";+ final SolrStream solrStream =+ new SolrStream(+ daemonUrl, params("qt", "/stream", "_trace", "start_" + daemonId, "expr", expr));solrStream.setCredentials(user, user);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size()); // daemon starting status@@ -517,19 +592,24 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {// We have to poll the daemon 'list' to know once it's run / terminated...Object state = null;final TimeOut timeout = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME);- while ( ! timeout.hasTimedOut() ) {- final SolrStream daemonCheck = new SolrStream(daemonUrl,- params("qt", "/stream",- "_trace", "check_" + daemonId,- "action", "list"));+ while (!timeout.hasTimedOut()) {+ final SolrStream daemonCheck =+ new SolrStream(+ daemonUrl,+ params(+ "qt", "/stream",+ "_trace", "check_" + daemonId,+ "action", "list"));daemonCheck.setCredentials(user, user);final List<Tuple> tuples = getTuples(daemonCheck);assertEquals(1, tuples.size()); // our daemon;if (log.isInfoEnabled()) {log.info("Current daemon status: {}", tuples.get(0).getFields());}- assertEquals(daemonId + " should have never had a successful iteration",- Long.valueOf(0L), tuples.get(0).getLong("iterations"));+ assertEquals(+ daemonId + " should have never had a successful iteration",+ Long.valueOf(0L),+ tuples.get(0).getLong("iterations"));state = tuples.get(0).get("state");if ("TERMINATED".equals(state)) {// once the daemon has failed, break out of TimeOut@@ -537,48 +617,60 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {}Thread.sleep(Math.max(1, Math.min(5000, timeout.timeLeft(TimeUnit.MILLISECONDS))));}- assertEquals("Timed out w/o ever getting TERMINATED state from " + daemonId,- "TERMINATED", state);+ assertEquals(+ "Timed out w/o ever getting TERMINATED state from " + daemonId, "TERMINATED", state);} finally {// kill the damon...- final SolrStream daemonKiller = new SolrStream(daemonUrl,- params("qt", "/stream",- "_trace", "kill_" + daemonId,- "action", "kill",- "id", daemonId));+ final SolrStream daemonKiller =+ new SolrStream(+ daemonUrl,+ params(+ "qt",+ "/stream",+ "_trace",+ "kill_" + daemonId,+ "action",+ "kill",+ "id",+ daemonId));daemonKiller.setCredentials(user, user);final List<Tuple> tuples = getTuples(daemonKiller);assertEquals(1, tuples.size()); // daemon death status}-- assertEquals("doc count after daemon update for " + user,- 0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));++ assertEquals(+ "doc count after daemon update for " + user,+ 0L,+ commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}-+// sanity check- assertEquals("final doc count",- 0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));-+ assertEquals("final doc count", 0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}public void testSimpleDeleteStream() throws Exception {- assertEquals(0,- (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)- .add(sdoc("id", "42"))- .commit(cluster.getSolrClient(), COLLECTION_X)).getStatus());+ assertEquals(+ 0,+ (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)+ .add(sdoc("id", "42"))+ .commit(cluster.getSolrClient(), COLLECTION_X))+ .getStatus());assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));-- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream", "expr",- "delete("+COLLECTION_X+",batchSize=1," +- "tuple(id=42))"));++ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt",+ "/stream",+ "expr",+ "delete(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42))"));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size());assertEquals(1L, tuples.get(0).get("totalIndexed"));-- assertEquals(0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));+ assertEquals(0L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}/** A simple "Delete by Query" example */@@ -586,109 +678,131 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {{ // Put some "real" docs directly to both X...final UpdateRequest update = setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER);for (int i = 1; i <= 42; i++) {- update.add(sdoc("id",i+"x","foo_i",""+i));+ update.add(sdoc("id", i + "x", "foo_i", "" + i));}- assertEquals("initial docs in X",- 0, update.commit(cluster.getSolrClient(), COLLECTION_X).getStatus());+ assertEquals(+ "initial docs in X", 0, update.commit(cluster.getSolrClient(), COLLECTION_X).getStatus());}-+assertEquals(42L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));-+{ // WRITE_X user should be able to delete X via a query from X- final String expr- = "delete("+COLLECTION_X+", batchSize=5, " // note batch size- + " search("+COLLECTION_X+", "- + " q=\"foo_i:[* TO 10]\", " // 10 matches = 2 batches- + " rows=100, "- + " fl=\"id,foo_i,_version_\", " // foo_i should be ignored...- + " sort=\"foo_i desc\")) " // version constraint should be ok- ;-- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream",- "expr", expr));+ // note batch size - 10 matches = 2 batches+ // foo_i should be ignored...+ // version constraint should be ok+ final String expr =+ "delete("+ + COLLECTION_X+ + ", batchSize=5, search("+ + COLLECTION_X+ + ", q=\"foo_i:[* TO 10]\", rows=100, fl=\"id,foo_i,_version_\", sort=\"foo_i desc\"))";++ final SolrStream solrStream =+ new SolrStream(solrUrl + "/" + COLLECTION_X, params("qt", "/stream", "expr", expr));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(2, tuples.size());assertEquals(5L, tuples.get(0).get("totalIndexed"));assertEquals(10L, tuples.get(1).get("totalIndexed"));}-+assertEquals(42L - 10L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}-public void testSimpleDeleteStreamInvalidCredentials() throws Exception {- assertEquals(0,- (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)- .add(sdoc("id", "42"))- .commit(cluster.getSolrClient(), COLLECTION_X)).getStatus());+ assertEquals(+ 0,+ (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)+ .add(sdoc("id", "42"))+ .commit(cluster.getSolrClient(), COLLECTION_X))+ .getStatus());assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));-- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream", "expr",- "update("+COLLECTION_X+",batchSize=1," +- "tuple(id=42))"));++ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt",+ "/stream",+ "expr",+ "update(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42))"));// "WRITE" credentials should be required for 'update(...)'solrStream.setCredentials(WRITE_X_USER, "BOGUS_PASSWORD");-+// NOTE: Can't make any assertions about Exception: SOLR-14226- expectThrows(Exception.class, () -> {- final List<Tuple> ignored = getTuples(solrStream);- });-+ expectThrows(+ Exception.class,+ () -> {+ final List<Tuple> ignored = getTuples(solrStream);+ });+assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}-public void testSimpleDeleteStreamInsufficientCredentials() throws Exception {- assertEquals(0,- (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)- .add(sdoc("id", "42"))- .commit(cluster.getSolrClient(), COLLECTION_X)).getStatus());+ assertEquals(+ 0,+ (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)+ .add(sdoc("id", "42"))+ .commit(cluster.getSolrClient(), COLLECTION_X))+ .getStatus());assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));-+// both of these users have valid credentials and authz read COLLECTION_X, but neither has// authz to write to X...for (String user : Arrays.asList(READ_ONLY_USER, WRITE_Y_USER)) {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,- params("qt", "/stream", "expr",- "update("+COLLECTION_X+",batchSize=1," +- "tuple(id=42))"));-+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X,+ params(+ "qt",+ "/stream",+ "expr",+ "update(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42))"));+solrStream.setCredentials(user, user);-+// NOTE: Can't make any assertions about Exception: SOLR-14226- expectThrows(Exception.class, () -> {- final List<Tuple> ignored = getTuples(solrStream);- });+ expectThrows(+ Exception.class,+ () -> {+ final List<Tuple> ignored = getTuples(solrStream);+ });}-+assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}-+public void testIndirectDeleteStream() throws Exception {{ // Put some "real" docs directly to both X & Y...final UpdateRequest xxx_Update = setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER);final UpdateRequest yyy_Update = setBasicAuthCredentials(new UpdateRequest(), WRITE_Y_USER);for (int i = 1; i <= 42; i++) {- xxx_Update.add(sdoc("id",i+"z","foo_i",""+i));- yyy_Update.add(sdoc("id",i+"z","foo_i",""+i));+ xxx_Update.add(sdoc("id", i + "z", "foo_i", "" + i));+ yyy_Update.add(sdoc("id", i + "z", "foo_i", "" + i));}- assertEquals("initial docs in X",- 0, xxx_Update.commit(cluster.getSolrClient(), COLLECTION_X).getStatus());- assertEquals("initial docs in Y",- 0, yyy_Update.commit(cluster.getSolrClient(), COLLECTION_Y).getStatus());+ assertEquals(+ "initial docs in X",+ 0,+ xxx_Update.commit(cluster.getSolrClient(), COLLECTION_X).getStatus());+ assertEquals(+ "initial docs in Y",+ 0,+ yyy_Update.commit(cluster.getSolrClient(), COLLECTION_Y).getStatus());}-+assertEquals(42L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));assertEquals(42L, commitAndCountDocsInCollection(COLLECTION_Y, WRITE_Y_USER));-+{ // WRITE_X user should be able to delete X via a (dummy) stream from Y...- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_Y,- params("qt", "/stream", "expr",- "delete("+COLLECTION_X+",batchSize=1," +- "tuple(id=42z))"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_Y,+ params(+ "qt",+ "/stream",+ "expr",+ "delete(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42z))"));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size());@@ -697,115 +811,131 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {assertEquals(42L - 1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));assertEquals(42L, commitAndCountDocsInCollection(COLLECTION_Y, WRITE_Y_USER));-- { // WRITE_X user should be able to delete ids from X via a (search) stream from Y (routed via Y)- final String expr- = "delete("+COLLECTION_X+", batchSize=50, " // note batch size- + " pruneVersionField=true, " // NOTE: ignoring Y version to del X- + " search("+COLLECTION_Y+", "- + " q=\"foo_i:[* TO 10]\", " // 10 matches = 1 batch- + " rows=100, "- + " fl=\"id,foo_i,_version_\", " // foo_i & version should be ignored- + " sort=\"foo_i desc\")) "- ;-- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_Y, // NOTE: Y route- params("qt", "/stream",- "expr", expr));++ { // WRITE_X user should be able to delete ids from X via a stream from Y (routed via Y)+ // note batch size - 10 matches = 1 batch+ // NOTE: ignoring Y version to del X+ // foo_i & version should be ignored+ final String expr =+ "delete("+ + COLLECTION_X+ + ", batchSize=50, pruneVersionField=true, search("+ + COLLECTION_Y+ + ", q=\"foo_i:[* TO 10]\", rows=100, fl=\"id,foo_i,_version_\", sort=\"foo_i desc\"))";++ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_Y, // NOTE: Y route+ params("qt", "/stream", "expr", expr));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(1, tuples.size());assertEquals(10L, tuples.get(0).get("batchIndexed"));assertEquals(10L, tuples.get(0).get("totalIndexed"));-}assertEquals(42L - 1L - 10L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));assertEquals(42L, commitAndCountDocsInCollection(COLLECTION_Y, WRITE_Y_USER));-- { // WRITE_X user should be able to delete ids from X via a (search) stream from Y (routed via X)...- final String expr- = "delete("+COLLECTION_X+", batchSize=5, " // note batch size- + " search("+COLLECTION_Y+", "- + " q=\"foo_i:[30 TO *]\", " // 13 matches = 3 batches- + " rows=100, "- + " fl=\"id,foo_i\", " // foo_i should be ignored- + " sort=\"foo_i desc\")) "- ;-- final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X, // NOTE: X route- params("qt", "/stream",- "expr", expr));++ { // WRITE_X user should be able to delete ids from X via a stream from Y (routed via X)...+ // note batch size - 13 matches = 3 batches+ // foo_i should be ignored+ final String expr =+ "delete("+ + COLLECTION_X+ + ", batchSize=5, search("+ + COLLECTION_Y+ + ", q=\"foo_i:[30 TO *]\", rows=100, fl=\"id,foo_i\", sort=\"foo_i desc\")) ";++ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + COLLECTION_X, // NOTE: X route+ params("qt", "/stream", "expr", expr));solrStream.setCredentials(WRITE_X_USER, WRITE_X_USER);final List<Tuple> tuples = getTuples(solrStream);assertEquals(3, tuples.size());-- assertEquals( 5L, tuples.get(0).get("batchIndexed"));- assertEquals( 5L, tuples.get(0).get("totalIndexed"));-- assertEquals( 5L, tuples.get(1).get("batchIndexed"));++ assertEquals(5L, tuples.get(0).get("batchIndexed"));+ assertEquals(5L, tuples.get(0).get("totalIndexed"));++ assertEquals(5L, tuples.get(1).get("batchIndexed"));assertEquals(10L, tuples.get(1).get("totalIndexed"));-- assertEquals( 3L, tuples.get(2).get("batchIndexed"));++ assertEquals(3L, tuples.get(2).get("batchIndexed"));assertEquals(13L, tuples.get(2).get("totalIndexed"));}- assertEquals(42L - 1L - 10L - (13L - 1L), // '42' in last 13 deletes was already deleted from X- commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));+ assertEquals(+ 42L - 1L - 10L - (13L - 1L), // '42' in last 13 deletes was already deleted from X+ commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));assertEquals(42L, commitAndCountDocsInCollection(COLLECTION_Y, WRITE_Y_USER));-}public void testIndirectDeleteStreamInsufficientCredentials() throws Exception {- assertEquals(0,- (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)- .add(sdoc("id", "42"))- .commit(cluster.getSolrClient(), COLLECTION_X)).getStatus());+ assertEquals(+ 0,+ (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)+ .add(sdoc("id", "42"))+ .commit(cluster.getSolrClient(), COLLECTION_X))+ .getStatus());assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));-+// regardless of how it's routed, WRITE_Y should NOT have authz to delete from X...for (String path : Arrays.asList(COLLECTION_X, COLLECTION_Y)) {- final SolrStream solrStream = new SolrStream(solrUrl + "/" + path,- params("qt", "/stream", "expr",- "delete("+COLLECTION_X+",batchSize=1," +- "tuple(id=42))"));+ final SolrStream solrStream =+ new SolrStream(+ solrUrl + "/" + path,+ params(+ "qt",+ "/stream",+ "expr",+ "delete(" + COLLECTION_X + ",batchSize=1," + "tuple(id=42))"));solrStream.setCredentials(WRITE_Y_USER, WRITE_Y_USER);-+// NOTE: Can't make any assertions about Exception: SOLR-14226- expectThrows(Exception.class, () -> {- final List<Tuple> ignored = getTuples(solrStream);- });+ expectThrows(+ Exception.class,+ () -> {+ final List<Tuple> ignored = getTuples(solrStream);+ });}assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));}/**- * Helper method that uses the specified user to (first commit, and then) count the total- * number of documents in the collection+ * Helper method that uses the specified user to (first commit, and then) count the total number+ * of documents in the collection*/- protected static long commitAndCountDocsInCollection(final String collection,- final String user) throws Exception {- assertEquals(0, setBasicAuthCredentials(new UpdateRequest(), user).commit(cluster.getSolrClient(),- collection).getStatus());+ protected static long commitAndCountDocsInCollection(final String collection, final String user)+ throws Exception {+ assertEquals(+ 0,+ setBasicAuthCredentials(new UpdateRequest(), user)+ .commit(cluster.getSolrClient(), collection)+ .getStatus());return countDocsInCollection(collection, user);}-+/**- * Helper method that uses the specified user to count the total number of documents in the collection+ * Helper method that uses the specified user to count the total number of documents in the+ * collection*/- protected static long countDocsInCollection(final String collection,- final String user) throws Exception {- return setBasicAuthCredentials(new QueryRequest(params("q", "*:*",- "rows", "0",- "_trace", "count_via_" + user + ":" + collection)),- user)- .process(cluster.getSolrClient(), collection).getResults().getNumFound();+ protected static long countDocsInCollection(final String collection, final String user)+ throws Exception {+ return setBasicAuthCredentials(+ new QueryRequest(+ params(+ "q", "*:*",+ "rows", "0",+ "_trace", "count_via_" + user + ":" + collection)),+ user)+ .process(cluster.getSolrClient(), collection)+ .getResults()+ .getNumFound();}-- /**- * Slurps a stream into a List- */++ /** Slurps a stream into a List */protected static List<Tuple> getTuples(final TupleStream tupleStream) throws IOException {List<Tuple> tuples = new ArrayList<Tuple>();try {@@ -823,16 +953,18 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {return tuples;}- /**- * Sigh. DaemonStream requires polling the same core where the stream was exectured.- */+ /** Sigh. DaemonStream requires polling the same core where the stream was exectured. */protected static String getRandomCoreUrl(final String collection) throws Exception {- final List<String> replicaUrls =- cluster.getSolrClient().getClusterState()- .getCollectionOrNull(collection).getReplicas().stream()- .map(Replica::getCoreUrl).collect(Collectors.toList());+ final List<String> replicaUrls =+ cluster+ .getZkStateReader()+ .getClusterState()+ .getCollectionOrNull(collection)+ .getReplicas()+ .stream()+ .map(Replica::getCoreUrl)+ .collect(Collectors.toList());Collections.shuffle(replicaUrls, random());return replicaUrls.get(0);}-}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.javaindex b895cdd6490..0d918f125f7 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java@@ -48,11 +48,9 @@ import org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;-/**-*/--@SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-10960")[email protected]({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})+/** */+@SuppressPointFields(bugUrl = "https://issues.apache.org/jira/browse/SOLR-10960")[email protected]({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})@ThreadLeakLingering(linger = 0)public class JDBCStreamTest extends SolrCloudTestCase {@@ -65,7 +63,14 @@ public class JDBCStreamTest extends SolrCloudTestCase {@BeforeClasspublic static void setupCluster() throws Exception {configureCluster(4)- .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))+ .addConfig(+ "conf",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("streaming")+ .resolve("conf")).configure();boolean useAlias = random().nextBoolean();@@ -81,31 +86,37 @@ public class JDBCStreamTest extends SolrCloudTestCase {AbstractDistribZkTestBase.waitForRecoveriesToFinish(collection, cluster.getZkStateReader(), false, true, TIMEOUT);if (useAlias) {- CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());+ CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection)+ .process(cluster.getSolrClient());}}@BeforeClasspublic static void setupDatabase() throws Exception {-+// Initialize Database- // Ok, so.....hsqldb is doing something totally weird so I thought I'd take a moment to explain it.- // According to http://www.hsqldb.org/doc/1.8/guide/guide.html#N101EF, section "Components of SQL Expressions", clause "name",- // "When an SQL statement is issued, any lowercase characters in unquoted identifiers are converted to uppercase."- // :( Like seriously....- // So, for this reason and to simplify writing these tests I've decided that in all statements all table and column names- // will be in UPPERCASE. This is to ensure things look and behave consistently. Note that this is not a requirement of the- // JDBCStream and is only a carryover from the driver we are testing with.+ // Ok, so.....hsqldb is doing something totally weird so I thought I'd take a moment to explain+ // it.+ // According to http://www.hsqldb.org/doc/1.8/guide/guide.html#N101EF, section "Components of+ // SQL Expressions", clause "name", "When an SQL statement is issued, any lowercase characters+ // in unquoted identifiers are converted to uppercase." :( Like seriously....+ // So, for this reason and to simplify writing these tests I've decided that in all statements+ // all table and column names will be in UPPERCASE. This is to ensure things look and behave+ // consistently. Note that this is not a requirement of the JDBCStream and is only a carryover+ // from the driver we are testing with.Class.forName("org.hsqldb.jdbcDriver").getConstructor().newInstance();Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:.");- Statement statement = connection.createStatement();- statement.executeUpdate("create table COUNTRIES(CODE varchar(3) not null primary key, COUNTRY_NAME varchar(50), DELETED char(1) default 'N')");- statement.executeUpdate("create table PEOPLE(ID int not null primary key, NAME varchar(50), COUNTRY_CODE char(2), DELETED char(1) default 'N')");- statement.executeUpdate("create table PEOPLE_SPORTS(ID int not null primary key, PERSON_ID int, SPORT_NAME varchar(50), DELETED char(1) default 'N')");- statement.executeUpdate("create table UNSUPPORTED_COLUMNS(ID int not null primary key, UNSP binary)");+ Statement statement = connection.createStatement();+ statement.executeUpdate(+ "create table COUNTRIES(CODE varchar(3) not null primary key, COUNTRY_NAME varchar(50), DELETED char(1) default 'N')");+ statement.executeUpdate(+ "create table PEOPLE(ID int not null primary key, NAME varchar(50), COUNTRY_CODE char(2), DELETED char(1) default 'N')");+ statement.executeUpdate(+ "create table PEOPLE_SPORTS(ID int not null primary key, PERSON_ID int, SPORT_NAME varchar(50), DELETED char(1) default 'N')");+ statement.executeUpdate(+ "create table UNSUPPORTED_COLUMNS(ID int not null primary key, UNSP binary)");statement.executeUpdate("create table DUAL(ID int not null primary key)");statement.executeUpdate("insert into DUAL values(1)");-}@AfterClass@@ -117,16 +128,14 @@ public class JDBCStreamTest extends SolrCloudTestCase {@Beforepublic void cleanIndex() throws Exception {- new UpdateRequest()- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTIONORALIAS);}@Beforepublic void cleanDatabase() throws Exception {// Clear databasetry (Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:.");- Statement statement = connection.createStatement()) {+ Statement statement = connection.createStatement()) {statement.executeUpdate("delete from COUNTRIES WHERE 1=1");statement.executeUpdate("delete from PEOPLE WHERE 1=1");statement.executeUpdate("delete from PEOPLE_SPORTS WHERE 1=1");@@ -139,40 +148,51 @@ public class JDBCStreamTest extends SolrCloudTestCase {// Load Database Datatry (Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:.");- Statement statement = connection.createStatement()) {- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");+ Statement statement = connection.createStatement()) {+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NP', 'Nepal')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NO', 'Norway')");}-+TupleStream stream;List<Tuple> tuples;-+// Simple 1- stream = new JDBCStream("jdbc:hsqldb:mem:.", "select CODE,COUNTRY_NAME from COUNTRIES order by CODE",- new FieldComparator("CODE", ComparatorOrder.ASCENDING));+ stream =+ new JDBCStream(+ "jdbc:hsqldb:mem:.",+ "select CODE,COUNTRY_NAME from COUNTRIES order by CODE",+ new FieldComparator("CODE", ComparatorOrder.ASCENDING));tuples = getTuples(stream);-- assert(tuples.size() == 4);++ assert (tuples.size() == 4);assertOrderOf(tuples, "CODE", "NL", "NO", "NP", "US");assertOrderOf(tuples, "COUNTRY_NAME", "Netherlands", "Norway", "Nepal", "United States");-+// Simple 2- stream = new JDBCStream("jdbc:hsqldb:mem:.", "select CODE,COUNTRY_NAME from COUNTRIES order by COUNTRY_NAME",- new FieldComparator("COUNTRY_NAME", ComparatorOrder.ASCENDING));+ stream =+ new JDBCStream(+ "jdbc:hsqldb:mem:.",+ "select CODE,COUNTRY_NAME from COUNTRIES order by COUNTRY_NAME",+ new FieldComparator("COUNTRY_NAME", ComparatorOrder.ASCENDING));tuples = getTuples(stream);-+assertEquals(4, tuples.size());assertOrderOf(tuples, "CODE", "NP", "NL", "NO", "US");assertOrderOf(tuples, "COUNTRY_NAME", "Nepal", "Netherlands", "Norway", "United States");-+// Additional Types- String query = "select 1 as ID1, {ts '2017-02-18 12:34:56.789'} as TS1, {t '01:02:03'} as T1, "- + "{d '1593-03-14'} as D1, cast(12.34 AS DECIMAL(4,2)) as DEC4_2, "- + "cast(1234 AS DECIMAL(4,0)) as DEC4_0, cast('big stuff' as CLOB(100)) as CLOB1 "- + "from DUAL order by ID1";- stream = new JDBCStream("jdbc:hsqldb:mem:.", query, new FieldComparator("ID1", ComparatorOrder.ASCENDING));+ String query =+ "select 1 as ID1, {ts '2017-02-18 12:34:56.789'} as TS1, {t '01:02:03'} as T1, "+ + "{d '1593-03-14'} as D1, cast(12.34 AS DECIMAL(4,2)) as DEC4_2, "+ + "cast(1234 AS DECIMAL(4,0)) as DEC4_0, cast('big stuff' as CLOB(100)) as CLOB1 "+ + "from DUAL order by ID1";+ stream =+ new JDBCStream(+ "jdbc:hsqldb:mem:.", query, new FieldComparator("ID1", ComparatorOrder.ASCENDING));tuples = getTuples(stream);assertEquals(1, tuples.size());Tuple t;@@ -186,52 +206,69 @@ public class JDBCStreamTest extends SolrCloudTestCase {assertString(t, "T1", rs.getTime("T1").toString());assertString(t, "D1", rs.getDate("D1").toString());assertDouble(t, "DEC4_2", rs.getDouble("DEC4_2"));- assertLong(t, "DEC4_0", rs.getLong("DEC4_0"));- }+ assertLong(t, "DEC4_0", rs.getLong("DEC4_0"));+ }}-+@Testpublic void testJDBCJoin() throws Exception {-+// Load Database Datatry (Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:.");- Statement statement = connection.createStatement()) {- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");+ Statement statement = connection.createStatement()) {+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NP', 'Nepal')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NO', 'Norway')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (11,'Emma','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (12,'Grace','NI')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (13,'Hailey','NG')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (14,'Isabella','NF')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (15,'Lily','NE')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (16,'Madison','NC')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (11,'Emma','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (12,'Grace','NI')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (13,'Hailey','NG')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (14,'Isabella','NF')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (15,'Lily','NE')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (16,'Madison','NC')");statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (17,'Mia','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (18,'Natalie','NZ')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (19,'Olivia','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (20,'Samantha','NR')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (18,'Natalie','NZ')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (19,'Olivia','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (20,'Samantha','NR')");}-+TupleStream stream;List<Tuple> tuples;-+// Simple 1- stream = new JDBCStream("jdbc:hsqldb:mem:.", "select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE where COUNTRIES.CODE = 'NL' order by PEOPLE.ID", new FieldComparator("ID", ComparatorOrder.ASCENDING));+ stream =+ new JDBCStream(+ "jdbc:hsqldb:mem:.",+ "select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE where COUNTRIES.CODE = 'NL' order by PEOPLE.ID",+ new FieldComparator("ID", ComparatorOrder.ASCENDING));tuples = getTuples(stream);-+assertEquals(3, tuples.size());assertOrderOf(tuples, "ID", 11, 17, 19);- assertOrderOf(tuples, "NAME", "Emma", "Mia", "Olivia");+ assertOrderOf(tuples, "NAME", "Emma", "Mia", "Olivia");}@Testpublic void testJDBCSolrMerge() throws Exception {-+// Load Database Datatry (Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:.");- Statement statement = connection.createStatement()) {- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");+ Statement statement = connection.createStatement()) {+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NP', 'Nepal')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NO', 'Norway')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('AL', 'Algeria')");@@ -240,68 +277,106 @@ public class JDBCStreamTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-+// Load Solrnew UpdateRequest().add(id, "0", "code_s", "GB", "name_s", "Great Britian").add(id, "1", "code_s", "CA", "name_s", "Canada").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class);-++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class);+List<Tuple> tuples;try {// Simple 1- TupleStream jdbcStream = new JDBCStream("jdbc:hsqldb:mem:.", "select CODE,COUNTRY_NAME from COUNTRIES order by CODE", new FieldComparator("CODE", ComparatorOrder.ASCENDING));- TupleStream selectStream = new SelectStream(jdbcStream, new HashMap<String, String>() {{- put("CODE", "code_s");- put("COUNTRY_NAME", "name_s");- }});- TupleStream searchStream = factory.constructStream("search(" + COLLECTIONORALIAS + ", fl=\"code_s,name_s\",q=\"*:*\",sort=\"code_s asc\")");- TupleStream mergeStream = new MergeStream(new FieldComparator("code_s", ComparatorOrder.ASCENDING), new TupleStream[]{selectStream, searchStream});+ TupleStream jdbcStream =+ new JDBCStream(+ "jdbc:hsqldb:mem:.",+ "select CODE,COUNTRY_NAME from COUNTRIES order by CODE",+ new FieldComparator("CODE", ComparatorOrder.ASCENDING));+ TupleStream selectStream =+ new SelectStream(+ jdbcStream,+ new HashMap<String, String>() {+ {+ put("CODE", "code_s");+ put("COUNTRY_NAME", "name_s");+ }+ });+ TupleStream searchStream =+ factory.constructStream(+ "search("+ + COLLECTIONORALIAS+ + ", fl=\"code_s,name_s\",q=\"*:*\",sort=\"code_s asc\")");+ TupleStream mergeStream =+ new MergeStream(+ new FieldComparator("code_s", ComparatorOrder.ASCENDING),+ new TupleStream[] {selectStream, searchStream});mergeStream.setStreamContext(streamContext);tuples = getTuples(mergeStream);assertEquals(7, tuples.size());assertOrderOf(tuples, "code_s", "AL", "CA", "GB", "NL", "NO", "NP", "US");- assertOrderOf(tuples, "name_s", "Algeria", "Canada", "Great Britian", "Netherlands", "Norway", "Nepal", "United States");+ assertOrderOf(+ tuples,+ "name_s",+ "Algeria",+ "Canada",+ "Great Britian",+ "Netherlands",+ "Norway",+ "Nepal",+ "United States");} finally {solrClientCache.close();}}@Test- public void testJDBCSolrInnerJoinExpression() throws Exception{-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("select", SelectStream.class)- .withFunctionName("innerJoin", InnerJoinStream.class)- .withFunctionName("jdbc", JDBCStream.class);-+ public void testJDBCSolrInnerJoinExpression() throws Exception {++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("select", SelectStream.class)+ .withFunctionName("innerJoin", InnerJoinStream.class)+ .withFunctionName("jdbc", JDBCStream.class);+// Load Database Datatry (Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:.");- Statement statement = connection.createStatement()) {- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");+ Statement statement = connection.createStatement()) {+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NP', 'Nepal')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NO', 'Norway')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (11,'Emma','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (12,'Grace','US')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (13,'Hailey','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (14,'Isabella','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (15,'Lily','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (16,'Madison','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (11,'Emma','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (12,'Grace','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (13,'Hailey','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (14,'Isabella','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (15,'Lily','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (16,'Madison','US')");statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (17,'Mia','US')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (18,'Natalie','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (19,'Olivia','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (20,'Samantha','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (18,'Natalie','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (19,'Olivia','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (20,'Samantha','US')");}-+// Load solr datanew UpdateRequest().add(id, "1", "rating_f", "3.5", "personId_i", "11")@@ -328,7 +403,9 @@ public class JDBCStreamTest extends SolrCloudTestCase {expression ="innerJoin("+ " select("- + " search(" + COLLECTIONORALIAS + ", fl=\"personId_i,rating_f\", q=\"rating_f:*\", sort=\"personId_i asc\"),"+ + " search("+ + COLLECTIONORALIAS+ + ", fl=\"personId_i,rating_f\", q=\"rating_f:*\", sort=\"personId_i asc\"),"+ " personId_i as personId,"+ " rating_f as rating"+ " ),"@@ -341,9 +418,8 @@ public class JDBCStreamTest extends SolrCloudTestCase {+ " on=\"personId\""+ ")";-stream = factory.constructStream(expression);- String expr = ((Expressible)stream).toExpression(factory).toString();+ String expr = ((Expressible) stream).toExpression(factory).toString();assertTrue(expr.contains("fetchSize=300"));stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -351,42 +427,78 @@ public class JDBCStreamTest extends SolrCloudTestCase {assertEquals(10, tuples.size());assertOrderOf(tuples, "personId", 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);assertOrderOf(tuples, "rating", 3.5d, 5d, 2.2d, 4.3d, 3.5d, 3d, 3d, 4d, 4.1d, 4.8d);- assertOrderOf(tuples, "personName", "Emma", "Grace", "Hailey", "Isabella", "Lily", "Madison", "Mia", "Natalie", "Olivia", "Samantha");- assertOrderOf(tuples, "country", "Netherlands", "United States", "Netherlands", "Netherlands", "Netherlands", "United States", "United States", "Netherlands", "Netherlands", "United States");+ assertOrderOf(+ tuples,+ "personName",+ "Emma",+ "Grace",+ "Hailey",+ "Isabella",+ "Lily",+ "Madison",+ "Mia",+ "Natalie",+ "Olivia",+ "Samantha");+ assertOrderOf(+ tuples,+ "country",+ "Netherlands",+ "United States",+ "Netherlands",+ "Netherlands",+ "Netherlands",+ "United States",+ "United States",+ "Netherlands",+ "Netherlands",+ "United States");} finally {solrClientCache.close();}}@Test- public void testJDBCSolrInnerJoinExpressionWithProperties() throws Exception{-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("select", SelectStream.class)- .withFunctionName("innerJoin", InnerJoinStream.class)- .withFunctionName("jdbc", JDBCStream.class);-+ public void testJDBCSolrInnerJoinExpressionWithProperties() throws Exception {++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("select", SelectStream.class)+ .withFunctionName("innerJoin", InnerJoinStream.class)+ .withFunctionName("jdbc", JDBCStream.class);+// Load Database Datatry (Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:.");- Statement statement = connection.createStatement()) {- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");+ Statement statement = connection.createStatement()) {+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NP', 'Nepal')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NO', 'Norway')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (11,'Emma','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (12,'Grace','US')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (13,'Hailey','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (14,'Isabella','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (15,'Lily','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (16,'Madison','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (11,'Emma','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (12,'Grace','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (13,'Hailey','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (14,'Isabella','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (15,'Lily','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (16,'Madison','US')");statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (17,'Mia','US')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (18,'Natalie','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (19,'Olivia','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (20,'Samantha','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (18,'Natalie','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (19,'Olivia','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (20,'Samantha','US')");}-+// Load solr datanew UpdateRequest().add(id, "1", "rating_f", "3.5", "personId_i", "11")@@ -413,7 +525,9 @@ public class JDBCStreamTest extends SolrCloudTestCase {expression ="innerJoin("+ " select("- + " search(" + COLLECTIONORALIAS + ", fl=\"personId_i,rating_f\", q=\"rating_f:*\", sort=\"personId_i asc\"),"+ + " search("+ + COLLECTIONORALIAS+ + ", fl=\"personId_i,rating_f\", q=\"rating_f:*\", sort=\"personId_i asc\"),"+ " personId_i as personId,"+ " rating_f as rating"+ " ),"@@ -433,14 +547,40 @@ public class JDBCStreamTest extends SolrCloudTestCase {assertEquals(10, tuples.size());assertOrderOf(tuples, "personId", 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);assertOrderOf(tuples, "rating", 3.5d, 5d, 2.2d, 4.3d, 3.5d, 3d, 3d, 4d, 4.1d, 4.8d);- assertOrderOf(tuples, "personName", "Emma", "Grace", "Hailey", "Isabella", "Lily", "Madison", "Mia", "Natalie", "Olivia", "Samantha");- assertOrderOf(tuples, "country", "Netherlands", "United States", "Netherlands", "Netherlands", "Netherlands", "United States", "United States", "Netherlands", "Netherlands", "United States");+ assertOrderOf(+ tuples,+ "personName",+ "Emma",+ "Grace",+ "Hailey",+ "Isabella",+ "Lily",+ "Madison",+ "Mia",+ "Natalie",+ "Olivia",+ "Samantha");+ assertOrderOf(+ tuples,+ "country",+ "Netherlands",+ "United States",+ "Netherlands",+ "Netherlands",+ "Netherlands",+ "United States",+ "United States",+ "Netherlands",+ "Netherlands",+ "United States");// Basic test for aliasexpression ="innerJoin("+ " select("- + " search(" + COLLECTIONORALIAS + ", fl=\"personId_i,rating_f\", q=\"rating_f:*\", sort=\"personId_i asc\"),"+ + " search("+ + COLLECTIONORALIAS+ + ", fl=\"personId_i,rating_f\", q=\"rating_f:*\", sort=\"personId_i asc\"),"+ " personId_i as personId,"+ " rating_f as rating"+ " ),"@@ -460,46 +600,81 @@ public class JDBCStreamTest extends SolrCloudTestCase {assertEquals(10, tuples.size());assertOrderOf(tuples, "personId", 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);assertOrderOf(tuples, "rating", 3.5d, 5d, 2.2d, 4.3d, 3.5d, 3d, 3d, 4d, 4.1d, 4.8d);- assertOrderOf(tuples, "personName", "Emma", "Grace", "Hailey", "Isabella", "Lily", "Madison", "Mia", "Natalie", "Olivia", "Samantha");- assertOrderOf(tuples, "country", "Netherlands", "United States", "Netherlands", "Netherlands", "Netherlands", "United States", "United States", "Netherlands", "Netherlands", "United States");+ assertOrderOf(+ tuples,+ "personName",+ "Emma",+ "Grace",+ "Hailey",+ "Isabella",+ "Lily",+ "Madison",+ "Mia",+ "Natalie",+ "Olivia",+ "Samantha");+ assertOrderOf(+ tuples,+ "country",+ "Netherlands",+ "United States",+ "Netherlands",+ "Netherlands",+ "Netherlands",+ "United States",+ "United States",+ "Netherlands",+ "Netherlands",+ "United States");} finally {solrClientCache.close();}}@Test- public void testJDBCSolrInnerJoinRollupExpression() throws Exception{-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("select", SelectStream.class)- .withFunctionName("hashJoin", HashJoinStream.class)- .withFunctionName("rollup", RollupStream.class)- .withFunctionName("jdbc", JDBCStream.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("count", CountMetric.class)- ;-+ public void testJDBCSolrInnerJoinRollupExpression() throws Exception {++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("select", SelectStream.class)+ .withFunctionName("hashJoin", HashJoinStream.class)+ .withFunctionName("rollup", RollupStream.class)+ .withFunctionName("jdbc", JDBCStream.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("count", CountMetric.class);+// Load Database Datatry (Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:.");- Statement statement = connection.createStatement()) {- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");- statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");+ Statement statement = connection.createStatement()) {+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('US', 'United States')");+ statement.executeUpdate(+ "insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NL', 'Netherlands')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NP', 'Nepal')");statement.executeUpdate("insert into COUNTRIES (CODE,COUNTRY_NAME) values ('NO', 'Norway')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (11,'Emma','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (12,'Grace','US')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (13,'Hailey','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (14,'Isabella','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (15,'Lily','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (16,'Madison','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (11,'Emma','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (12,'Grace','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (13,'Hailey','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (14,'Isabella','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (15,'Lily','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (16,'Madison','US')");statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (17,'Mia','US')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (18,'Natalie','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (19,'Olivia','NL')");- statement.executeUpdate("insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (20,'Samantha','US')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (18,'Natalie','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (19,'Olivia','NL')");+ statement.executeUpdate(+ "insert into PEOPLE (ID, NAME, COUNTRY_CODE) values (20,'Samantha','US')");}// Load solr data@@ -530,7 +705,9 @@ public class JDBCStreamTest extends SolrCloudTestCase {"rollup("+ " hashJoin("+ " hashed=select("- + " search(" + COLLECTIONORALIAS + ", fl=\"personId_i,rating_f\", q=\"rating_f:*\", sort=\"personId_i asc\"),"+ + " search("+ + COLLECTIONORALIAS+ + ", fl=\"personId_i,rating_f\", q=\"rating_f:*\", sort=\"personId_i asc\"),"+ " personId_i as personId,"+ " rating_f as rating"+ " ),"@@ -557,84 +734,88 @@ public class JDBCStreamTest extends SolrCloudTestCase {Tuple tuple = tuples.get(0);assertEquals("Netherlands", tuple.getString("country"));- assertEquals(4.3D , tuple.getDouble("max(rating)") , 0.0001);- assertEquals(2.2D , tuple.getDouble("min(rating)"), 0.0001);+ assertEquals(4.3D, tuple.getDouble("max(rating)"), 0.0001);+ assertEquals(2.2D, tuple.getDouble("min(rating)"), 0.0001);assertEquals(3.6D, tuple.getDouble("avg(rating)"), 0.0001);- assertEquals(6D , tuple.getDouble("count(*)"), 0.0001);+ assertEquals(6D, tuple.getDouble("count(*)"), 0.0001);tuple = tuples.get(1);assertEquals("United States", tuple.getString("country"));- assertEquals(5D , tuple.getDouble("max(rating)"), 0.0001);- assertEquals(3D , tuple.getDouble("min(rating)"), 0.0001);- assertEquals(3.95D , tuple.getDouble("avg(rating)"),0.0001);- assertEquals(4D , tuple.getDouble("count(*)"), 0.0001);+ assertEquals(5D, tuple.getDouble("max(rating)"), 0.0001);+ assertEquals(3D, tuple.getDouble("min(rating)"), 0.0001);+ assertEquals(3.95D, tuple.getDouble("avg(rating)"), 0.0001);+ assertEquals(4D, tuple.getDouble("count(*)"), 0.0001);} finally {solrClientCache.close();}}-- @Test(expected=IOException.class)++ @Test(expected = IOException.class)public void testUnsupportedColumns() throws Exception {// No need to load table with any data-+TupleStream stream;-+// Simple 1- stream = new JDBCStream("jdbc:hsqldb:mem:.", "select ID,UNSP from UNSUPPORTED_COLUMNS",- new FieldComparator("CODE", ComparatorOrder.ASCENDING));+ stream =+ new JDBCStream(+ "jdbc:hsqldb:mem:.",+ "select ID,UNSP from UNSUPPORTED_COLUMNS",+ new FieldComparator("CODE", ComparatorOrder.ASCENDING));getTuples(stream);-}-+protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {tupleStream.open();List<Tuple> tuples = new ArrayList<Tuple>();- for(Tuple t = tupleStream.read(); !t.EOF; t = tupleStream.read()) {+ for (Tuple t = tupleStream.read(); !t.EOF; t = tupleStream.read()) {tuples.add(t);}tupleStream.close();return tuples;}- protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... values) throws Exception {+ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... values)+ throws Exception {int i = 0;- for(int val : values) {+ for (int val : values) {Tuple t = tuples.get(i);- Long tip = (Long)t.get(fieldName);- if(tip.intValue() != val) {- throw new Exception("Found value:"+tip.intValue()+" expecting:"+val);+ Long tip = (Long) t.get(fieldName);+ if (tip.intValue() != val) {+ throw new Exception("Found value:" + tip.intValue() + " expecting:" + val);}++i;}return true;}- protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, double... values) throws Exception {+ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, double... values)+ throws Exception {int i = 0;- for(double val : values) {+ for (double val : values) {Tuple t = tuples.get(i);- double tip = (double)t.get(fieldName);- assertEquals("Found value:"+tip+" expecting:"+val, val, tip, 0.00001);+ double tip = (double) t.get(fieldName);+ assertEquals("Found value:" + tip + " expecting:" + val, val, tip, 0.00001);++i;}return true;}- protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, String... values) throws Exception {+ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, String... values)+ throws Exception {int i = 0;- for(String val : values) {+ for (String val : values) {Tuple t = tuples.get(i);-- if(null == val){- if(null != t.get(fieldName)){- throw new Exception("Found value:"+(String)t.get(fieldName)+" expecting:null");++ if (null == val) {+ if (null != t.get(fieldName)) {+ throw new Exception("Found value:" + (String) t.get(fieldName) + " expecting:null");}- }- else{- String tip = (String)t.get(fieldName);- if(!tip.equals(val)) {- throw new Exception("Found value:"+tip+" expecting:"+val);+ } else {+ String tip = (String) t.get(fieldName);+ if (!tip.equals(val)) {+ throw new Exception("Found value:" + tip + " expecting:" + val);}}++i;@@ -642,10 +823,10 @@ public class JDBCStreamTest extends SolrCloudTestCase {return true;}- protected boolean assertFields(List<Tuple> tuples, String ... fields) throws Exception{- for(Tuple tuple : tuples){- for(String field : fields){- if(!tuple.getFields().containsKey(field)){+ protected boolean assertFields(List<Tuple> tuples, String... fields) throws Exception {+ for (Tuple tuple : tuples) {+ for (String field : fields) {+ if (!tuple.getFields().containsKey(field)) {throw new Exception(String.format(Locale.ROOT, "Expected field '%s' not found", field));}}@@ -653,44 +834,43 @@ public class JDBCStreamTest extends SolrCloudTestCase {return true;}- protected boolean assertNotFields(List<Tuple> tuples, String ... fields) throws Exception{- for(Tuple tuple : tuples){- for(String field : fields){- if(tuple.getFields().containsKey(field)){+ protected boolean assertNotFields(List<Tuple> tuples, String... fields) throws Exception {+ for (Tuple tuple : tuples) {+ for (String field : fields) {+ if (tuple.getFields().containsKey(field)) {throw new Exception(String.format(Locale.ROOT, "Unexpected field '%s' found", field));}}}return true;- }+ }public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {- long lv = (long)tuple.get(fieldName);- if(lv != l) {- throw new Exception("Longs not equal:"+l+" : "+lv);+ long lv = (long) tuple.get(fieldName);+ if (lv != l) {+ throw new Exception("Longs not equal:" + l + " : " + lv);}return true;}-+public boolean assertDouble(Tuple tuple, String fieldName, double d) throws Exception {- double dv = (double)tuple.get(fieldName);- if(dv != d) {- throw new Exception("Doubles not equal:"+d+" : "+dv);+ double dv = (double) tuple.get(fieldName);+ if (dv != d) {+ throw new Exception("Doubles not equal:" + d + " : " + dv);}return true;}-+public boolean assertString(Tuple tuple, String fieldName, String expected) throws Exception {- String actual = (String)tuple.get(fieldName);-- if( (null == expected && null != actual) ||- (null != expected && null == actual) ||- (null != expected && !expected.equals(actual))){- throw new Exception("Longs not equal:"+expected+" : "+actual);+ String actual = (String) tuple.get(fieldName);++ if ((null == expected && null != actual)+ || (null != expected && null == actual)+ || (null != expected && !expected.equals(actual))) {+ throw new Exception("Longs not equal:" + expected + " : " + actual);}return true;}-}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.javaindex 6535de7769a..a5e86dc9e79 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java@@ -42,7 +42,7 @@ import org.junit.BeforeClass;import org.junit.Test;@Slow[email protected]({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})[email protected]({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})public class MathExpressionTest extends SolrCloudTestCase {private static final String COLLECTIONORALIAS = "collection1";@@ -54,8 +54,22 @@ public class MathExpressionTest extends SolrCloudTestCase {@BeforeClasspublic static void setupCluster() throws Exception {configureCluster(4)- .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))- .addConfig("ml", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("ml").resolve("conf"))+ .addConfig(+ "conf",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("streaming")+ .resolve("conf"))+ .addConfig(+ "ml",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("ml")+ .resolve("conf")).configure();String collection;@@ -73,15 +87,14 @@ public class MathExpressionTest extends SolrCloudTestCase {AbstractDistribZkTestBase.waitForRecoveriesToFinish(collection, cluster.getZkStateReader(), false, true, TIMEOUT);if (useAlias) {- CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());+ CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection)+ .process(cluster.getSolrClient());}}@Beforepublic void cleanIndex() throws Exception {- new UpdateRequest()- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTIONORALIAS);}@Test@@ -91,15 +104,18 @@ public class MathExpressionTest extends SolrCloudTestCase {updateRequest.add(id, "1", "test_t", "l b c d c");updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);-SolrClientCache cache = new SolrClientCache();try {- String expr = "cartesianProduct(search("+COLLECTIONORALIAS+", q=\"*:*\", fl=\"id, test_t\", sort=\"id desc\"), analyze(test_t, test_t) as test_t)";+ String expr =+ "cartesianProduct(search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", fl=\"id, test_t\", sort=\"id desc\"), analyze(test_t, test_t) as test_t)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;SolrStream solrStream = new SolrStream(url, paramsLoc);@@ -116,12 +132,10 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(t.getString("test_t").equals("b"));assertTrue(t.getString("id").equals("1"));-t = tuples.get(2);assertTrue(t.getString("test_t").equals("c"));assertTrue(t.getString("id").equals("1"));-t = tuples.get(3);assertTrue(t.getString("test_t").equals("d"));assertTrue(t.getString("id").equals("1"));@@ -130,7 +144,6 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(t.getString("test_t").equals("c"));assertTrue(t.getString("id").equals("1"));-expr = "analyze(\"hello world\", test_t)";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);@@ -141,12 +154,15 @@ public class MathExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertEquals(tuples.size(), 1);- List<?> terms = (List<?>)tuples.get(0).get("return-value");+ List<?> terms = (List<?>) tuples.get(0).get("return-value");assertTrue(terms.get(0).equals("hello"));assertTrue(terms.get(1).equals("world"));- //Try with single param- expr = "cartesianProduct(search("+COLLECTIONORALIAS+", q=\"*:*\", fl=\"id, test_t\", sort=\"id desc\"), analyze(test_t) as test_t)";+ // Try with single param+ expr =+ "cartesianProduct(search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", fl=\"id, test_t\", sort=\"id desc\"), analyze(test_t) as test_t)";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -166,12 +182,10 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(t.getString("test_t").equals("b"));assertTrue(t.getString("id").equals("1"));-t = tuples.get(2);assertTrue(t.getString("test_t").equals("c"));assertTrue(t.getString("id").equals("1"));-t = tuples.get(3);assertTrue(t.getString("test_t").equals("d"));assertTrue(t.getString("id").equals("1"));@@ -180,8 +194,11 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(t.getString("test_t").equals("c"));assertTrue(t.getString("id").equals("1"));- //Try with null in the test_t field- expr = "cartesianProduct(search("+COLLECTIONORALIAS+", q=\"*:*\", fl=\"id\", sort=\"id desc\"), analyze(test_t, test_t) as test_t)";+ // Try with null in the test_t field+ expr =+ "cartesianProduct(search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", fl=\"id\", sort=\"id desc\"), analyze(test_t, test_t) as test_t)";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -193,8 +210,11 @@ public class MathExpressionTest extends SolrCloudTestCase {tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- //Test annotating tuple- expr = "select(search("+COLLECTIONORALIAS+", q=\"*:*\", fl=\"id, test_t\", sort=\"id desc\"), analyze(test_t, test_t) as test1_t)";+ // Test annotating tuple+ expr =+ "select(search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", fl=\"id, test_t\", sort=\"id desc\"), analyze(test_t, test_t) as test1_t)";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -205,7 +225,7 @@ public class MathExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<?> l = (List<?>)tuples.get(0).get("test1_t");+ List<?> l = (List<?>) tuples.get(0).get("test1_t");assertTrue(l.get(0).equals("l"));assertTrue(l.get(1).equals("b"));assertTrue(l.get(2).equals("c"));@@ -218,39 +238,42 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testConcat() throws Exception {- String expr = " select(list(tuple(field1=\"a\", field2=\"b\"), tuple(field1=\"c\", field2=\"d\")), concat(field1, field2, \"hello\", delim=\"-\") as field3)";+ String expr =+ " select(list(tuple(field1=\"a\", field2=\"b\"), tuple(field1=\"c\", field2=\"d\")), concat(field1, field2, \"hello\", delim=\"-\") as field3)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 2);- String s1= tuples.get(0).getString("field3");+ assertEquals(tuples.size(), 2);+ String s1 = tuples.get(0).getString("field3");assertEquals(s1, "a-b-hello");- String s2= tuples.get(1).getString("field3");+ String s2 = tuples.get(1).getString("field3");assertEquals(s2, "c-d-hello");}-@Testpublic void testTrunc() throws Exception {- String expr = " select(list(tuple(field1=\"abcde\", field2=\"012345\")), trunc(field1, 2) as field3, trunc(field2, 4) as field4)";+ String expr =+ " select(list(tuple(field1=\"abcde\", field2=\"012345\")), trunc(field1, 2) as field3, trunc(field2, 4) as field4)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);+ assertEquals(tuples.size(), 1);String s1 = tuples.get(0).getString("field3");assertEquals(s1, "ab");String s2 = tuples.get(0).getString("field4");@@ -259,75 +282,78 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testUpperLowerSingle() throws Exception {- String expr = " select(list(tuple(field1=\"a\", field2=\"C\")), upper(field1) as field3, lower(field2) as field4)";+ String expr =+ " select(list(tuple(field1=\"a\", field2=\"C\")), upper(field1) as field3, lower(field2) as field4)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);+ assertEquals(tuples.size(), 1);String s1 = tuples.get(0).getString("field3");assertEquals(s1, "A");String s2 = tuples.get(0).getString("field4");assertEquals(s2, "c");}-@Testpublic void testTruncArray() throws Exception {- String expr = " select(list(tuple(field1=array(\"aaaa\",\"bbbb\",\"cccc\"))), trunc(field1, 3) as field2)";+ String expr =+ " select(list(tuple(field1=array(\"aaaa\",\"bbbb\",\"cccc\"))), trunc(field1, 3) as field2)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);+ assertEquals(tuples.size(), 1);@SuppressWarnings({"unchecked"})- List<String> l1 = (List<String>)tuples.get(0).get("field2");+ List<String> l1 = (List<String>) tuples.get(0).get("field2");assertEquals(l1.get(0), "aaa");assertEquals(l1.get(1), "bbb");assertEquals(l1.get(2), "ccc");-}@Testpublic void testUpperLowerArray() throws Exception {- String expr = " select(list(tuple(field1=array(\"a\",\"b\",\"c\"), field2=array(\"X\",\"Y\",\"Z\"))), upper(field1) as field3, lower(field2) as field4)";+ String expr =+ " select(list(tuple(field1=array(\"a\",\"b\",\"c\"), field2=array(\"X\",\"Y\",\"Z\"))), upper(field1) as field3, lower(field2) as field4)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);+ assertEquals(tuples.size(), 1);@SuppressWarnings({"unchecked"})- List<String> l1 = (List<String>)tuples.get(0).get("field3");+ List<String> l1 = (List<String>) tuples.get(0).get("field3");assertEquals(l1.get(0), "A");assertEquals(l1.get(1), "B");assertEquals(l1.get(2), "C");@SuppressWarnings({"unchecked"})- List<String> l2 = (List<String>)tuples.get(0).get("field4");+ List<String> l2 = (List<String>) tuples.get(0).get("field4");assertEquals(l2.get(0), "x");assertEquals(l2.get(1), "y");assertEquals(l2.get(2), "z");}-@Testpublic void testSplitTrim() throws Exception {String expr = " select(list(tuple(field1=\"a, b, c\")), trim(split(field1, \",\")) as field2)";@@ -335,71 +361,75 @@ public class MathExpressionTest extends SolrCloudTestCase {paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);+ assertEquals(tuples.size(), 1);@SuppressWarnings({"unchecked"})- List<String> l1 = (List<String>)tuples.get(0).get("field2");+ List<String> l1 = (List<String>) tuples.get(0).get("field2");assertEquals(l1.get(0), "a");assertEquals(l1.get(1), "b");assertEquals(l1.get(2), "c");}-@Testpublic void testMemset() throws Exception {- String expr = "let(echo=\"b, c\"," +- " a=memset(list(tuple(field1=val(1), field2=val(10)), tuple(field1=val(2), field2=val(20))), " +- " cols=\"field1, field2\", " +- " vars=\"f1, f2\")," +- " b=add(f1)," +- " c=add(f2))";+ String expr =+ "let(echo=\"b, c\","+ + " a=memset(list(tuple(field1=val(1), field2=val(10)), tuple(field1=val(2), field2=val(20))), "+ + " cols=\"field1, field2\", "+ + " vars=\"f1, f2\"),"+ + " b=add(f1),"+ + " c=add(f2))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);- Number f1 = (Number)tuples.get(0).get("b");+ assertEquals(tuples.size(), 1);+ Number f1 = (Number) tuples.get(0).get("b");assertEquals(f1.doubleValue(), 3, 0.0);- Number f2 = (Number)tuples.get(0).get("c");+ Number f2 = (Number) tuples.get(0).get("c");assertEquals(f2.doubleValue(), 30, 0.0);}@Testpublic void testMemsetSize() throws Exception {- String expr = "let(echo=\"b, c\"," +- " a=memset(plist(tuple(field1=val(1), field2=val(10)), tuple(field1=val(2), field2=val(20))), " +- " cols=\"field1, field2\", " +- " vars=\"f1, f2\"," +- " size=1)," +- " b=add(f1)," +- " c=add(f2))";+ String expr =+ "let(echo=\"b, c\","+ + " a=memset(plist(tuple(field1=val(1), field2=val(10)), tuple(field1=val(2), field2=val(20))), "+ + " cols=\"field1, field2\", "+ + " vars=\"f1, f2\","+ + " size=1),"+ + " b=add(f1),"+ + " c=add(f2))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);- Number f1 = (Number)tuples.get(0).get("b");+ assertEquals(tuples.size(), 1);+ Number f1 = (Number) tuples.get(0).get("b");assertEquals(f1.doubleValue(), 1, 0.0);- Number f2 = (Number)tuples.get(0).get("c");+ Number f2 = (Number) tuples.get(0).get("c");assertEquals(f2.doubleValue(), 10, 0.0);}@@ -407,40 +437,48 @@ public class MathExpressionTest extends SolrCloudTestCase {public void testMemsetTimeSeries() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "memset(timeseries("+COLLECTIONORALIAS+", " +- " q=\"*:*\", " +- " start=\"2013-01-01T01:00:00.000Z\", " +- " end=\"2016-12-01T01:00:00.000Z\", " +- " gap=\"+1YEAR\", " +- " field=\"test_dt\", " +- " count(*)), " +- " cols=\"count(*)\"," +- " vars=\"a\")";+ String expr =+ "memset(timeseries("+ + COLLECTIONORALIAS+ + ", "+ + " q=\"*:*\", "+ + " start=\"2013-01-01T01:00:00.000Z\", "+ + " end=\"2016-12-01T01:00:00.000Z\", "+ + " gap=\"+1YEAR\", "+ + " field=\"test_dt\", "+ + " count(*)), "+ + " cols=\"count(*)\","+ + " vars=\"a\")";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -448,7 +486,7 @@ public class MathExpressionTest extends SolrCloudTestCase {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- Map<String, List<Number>> mem = (Map)tuples.get(0).get("return-value");+ Map<String, List<Number>> mem = (Map) tuples.get(0).get("return-value");List<Number> array = mem.get("a");assertEquals(array.get(0).intValue(), 100);assertEquals(array.get(1).intValue(), 50);@@ -460,26 +498,35 @@ public class MathExpressionTest extends SolrCloudTestCase {public void testLatlonFunctions() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<5) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"),- "price_i", Integer.toString(i), "loc_p", (42.906797030808235+i)+","+(76.69455762489834+i));+ int i = 0;+ while (i < 5) {+ updateRequest.add(+ id,+ "id_" + (++i),+ "test_dt",+ getDateString("2016", "5", "1"),+ "price_i",+ Integer.toString(i),+ "loc_p",+ (42.906797030808235 + i) + "," + (76.69455762489834 + i));}-updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "let(echo=true," +- " a=search("+COLLECTIONORALIAS+", q=*:*, fl=\"id, loc_p, price_i\",rows=100, sort=\"price_i asc\"),"+- " b=latlonVectors(a, field=loc_p)," +- " c=distance(array(40.7128, 74.0060), array(45.7128, 74.0060), haversineMeters()))";-+ String expr =+ "let(echo=true,"+ + " a=search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id, loc_p, price_i\",rows=100, sort=\"price_i asc\"),"+ + " b=latlonVectors(a, field=loc_p),"+ + " c=distance(array(40.7128, 74.0060), array(45.7128, 74.0060), haversineMeters()))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -487,21 +534,20 @@ public class MathExpressionTest extends SolrCloudTestCase {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>>locVectors = (List<List<Number>>)tuples.get(0).get("b");- int v=1;- for(List<Number> row : locVectors) {- double lat = row.get(0).doubleValue();- double lon = row.get(1).doubleValue();- assertEquals(lat, 42.906797030808235+v, 0);- assertEquals(lon, 76.69455762489834+v, 0);- ++v;+ List<List<Number>> locVectors = (List<List<Number>>) tuples.get(0).get("b");+ int v = 1;+ for (List<Number> row : locVectors) {+ double lat = row.get(0).doubleValue();+ double lon = row.get(1).doubleValue();+ assertEquals(lat, 42.906797030808235 + v, 0);+ assertEquals(lon, 76.69455762489834 + v, 0);+ ++v;}double distance = tuples.get(0).getDouble("c");assertEquals(distance, 555975.3986718428, 1.0);-}-+@Testpublic void testHist() throws Exception {String expr = "hist(sequence(100, 0, 1), 10)";@@ -509,19 +555,20 @@ public class MathExpressionTest extends SolrCloudTestCase {paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 10);- for(int i=0; i<tuples.size(); i++) {+ for (int i = 0; i < tuples.size(); i++) {Tuple stats = tuples.get(i);- assertTrue(((Number)stats.get("N")).intValue() == 10);- assertTrue(((Number)stats.get("min")).intValue() == 10*i);- assertTrue(((Number)stats.get("var")).doubleValue() == 9.166666666666666);- assertTrue(((Number)stats.get("stdev")).doubleValue() == 3.0276503540974917);+ assertTrue(((Number) stats.get("N")).intValue() == 10);+ assertTrue(((Number) stats.get("min")).intValue() == 10 * i);+ assertTrue(((Number) stats.get("var")).doubleValue() == 9.166666666666666);+ assertTrue(((Number) stats.get("stdev")).doubleValue() == 3.0276503540974917);}expr = "hist(sequence(100, 0, 1), 5)";@@ -534,32 +581,34 @@ public class MathExpressionTest extends SolrCloudTestCase {tuples = getTuples(solrStream);assertTrue(tuples.size() == 5);- for(int i=0; i<tuples.size(); i++) {+ for (int i = 0; i < tuples.size(); i++) {Tuple stats = tuples.get(i);- assertTrue(((Number)stats.get("N")).intValue() == 20);- assertTrue(((Number)stats.get("min")).intValue() == 20*i);- assertTrue(((Number)stats.get("var")).doubleValue() == 35);- assertTrue(((Number)stats.get("stdev")).doubleValue() == 5.916079783099616);+ assertTrue(((Number) stats.get("N")).intValue() == 20);+ assertTrue(((Number) stats.get("min")).intValue() == 20 * i);+ assertTrue(((Number) stats.get("var")).doubleValue() == 35);+ assertTrue(((Number) stats.get("stdev")).doubleValue() == 5.916079783099616);}}@Testpublic void testConvexHull() throws Exception {- String expr = "let(echo=true," +- " x=array(96.42894739701268, 99.11076410926444, 95.71563821370013,101.4356840561301, 96.17912865782684, 113.430677406492, 109.5927785287056, 87.26561260238425, 103.3122002816537, 100.4959815617706, 92.78972440872515, 92.98815024042877, 89.1448359089767, 104.9410622701036, 106.5546761317927, 102.0132643274808, 119.6726096270366, 97.61388415294184, 106.7928221374049, 94.31369945729962, 87.37098859879977, 82.8015657665458, 88.84342877874248, 94.58797342988339, 92.38720473619748)," +- " y=array(97.43395922838836, 109.5441846957560, 78.82698890096127, 96.67181538737611,95.52423701473863, 85.3391529394878, 87.01956497912255, 111.5289690656729,86.41034184809114, 84.11696923489203, 109.3874354244069, 102.3391063812790,109.0604436531823,102.7957014900897,114.4376483055848,107.4387578165579,106.2490201384653,103.4490197583837,93.8201540211101,101.6060721649409, 115.3512636715722,119.1046170610335,99.74910277836263,104.2116724112481, 86.02222520549304)," +- " c=transpose(matrix(x, y))," +- " d=convexHull(c)," +- " e=getVertices(d)," +- " f=getArea(d)," +- " g=getBoundarySize(d)," +- " h=getBaryCenter(d)," +- " i=projectToBorder(d, matrix(array(99.11076410926444, 109.5441846957560))))";+ String expr =+ "let(echo=true,"+ + " x=array(96.42894739701268, 99.11076410926444, 95.71563821370013,101.4356840561301, 96.17912865782684, 113.430677406492, 109.5927785287056, 87.26561260238425, 103.3122002816537, 100.4959815617706, 92.78972440872515, 92.98815024042877, 89.1448359089767, 104.9410622701036, 106.5546761317927, 102.0132643274808, 119.6726096270366, 97.61388415294184, 106.7928221374049, 94.31369945729962, 87.37098859879977, 82.8015657665458, 88.84342877874248, 94.58797342988339, 92.38720473619748),"+ + " y=array(97.43395922838836, 109.5441846957560, 78.82698890096127, 96.67181538737611,95.52423701473863, 85.3391529394878, 87.01956497912255, 111.5289690656729,86.41034184809114, 84.11696923489203, 109.3874354244069, 102.3391063812790,109.0604436531823,102.7957014900897,114.4376483055848,107.4387578165579,106.2490201384653,103.4490197583837,93.8201540211101,101.6060721649409, 115.3512636715722,119.1046170610335,99.74910277836263,104.2116724112481, 86.02222520549304),"+ + " c=transpose(matrix(x, y)),"+ + " d=convexHull(c),"+ + " e=getVertices(d),"+ + " f=getArea(d),"+ + " g=getBoundarySize(d),"+ + " h=getBaryCenter(d),"+ + " i=projectToBorder(d, matrix(array(99.11076410926444, 109.5441846957560))))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -567,7 +616,7 @@ public class MathExpressionTest extends SolrCloudTestCase {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> points = (List<List<Number>>)tuples.get(0).get("e");+ List<List<Number>> points = (List<List<Number>>) tuples.get(0).get("e");assertTrue(points.size() == 6);List<Number> point1 = points.get(0);assertEquals(point1.size(), 2);@@ -579,7 +628,6 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(point2.get(0).doubleValue(), 92.38720473619748, 0.0);assertEquals(point2.get(1).doubleValue(), 86.02222520549304, 0.0);-List<Number> point3 = points.get(2);assertEquals(point3.size(), 2);assertEquals(point3.get(0).doubleValue(), 95.71563821370013, 0.0);@@ -588,20 +636,17 @@ public class MathExpressionTest extends SolrCloudTestCase {List<Number> point4 = points.get(3);assertEquals(point4.size(), 2);assertEquals(point4.get(0).doubleValue(), 113.430677406492, 0.0);- assertEquals(point4.get(1).doubleValue(), 85.3391529394878, 0.0);-+ assertEquals(point4.get(1).doubleValue(), 85.3391529394878, 0.0);List<Number> point5 = points.get(4);assertEquals(point5.size(), 2);assertEquals(point5.get(0).doubleValue(), 119.6726096270366, 0.0);- assertEquals(point5.get(1).doubleValue(), 106.2490201384653, 0.0);-+ assertEquals(point5.get(1).doubleValue(), 106.2490201384653, 0.0);List<Number> point6 = points.get(5);assertEquals(point6.size(), 2);assertEquals(point6.get(0).doubleValue(), 106.5546761317927, 0.0);- assertEquals(point6.get(1).doubleValue(), 114.4376483055848, 0.0);-+ assertEquals(point6.get(1).doubleValue(), 114.4376483055848, 0.0);double area = tuples.get(0).getDouble("f");assertEquals(area, 911.6283603859929, 0.0);@@ -610,34 +655,34 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(boundarySize, 122.73784789223708, 0.0);@SuppressWarnings({"unchecked"})- List<Number> baryCenter = (List<Number>)tuples.get(0).get("h");+ List<Number> baryCenter = (List<Number>) tuples.get(0).get("h");assertEquals(baryCenter.size(), 2);assertEquals(baryCenter.get(0).doubleValue(), 101.3021125450865, 0.0);assertEquals(baryCenter.get(1).doubleValue(), 100.07343616615786, 0.0);@SuppressWarnings({"unchecked"})- List<List<Number>> borderPoints = (List<List<Number>>)tuples.get(0).get("i");+ List<List<Number>> borderPoints = (List<List<Number>>) tuples.get(0).get("i");assertEquals(borderPoints.get(0).get(0).doubleValue(), 100.31316833934775, 0);assertEquals(borderPoints.get(0).get(1).doubleValue(), 115.6639686234851, 0);--}@Testpublic void testEnclosingDisk() throws Exception {- String expr = "let(echo=true," +- " x=array(96.42894739701268, 99.11076410926444, 95.71563821370013,101.4356840561301, 96.17912865782684, 113.430677406492, 109.5927785287056, 87.26561260238425, 103.3122002816537, 100.4959815617706, 92.78972440872515, 92.98815024042877, 89.1448359089767, 104.9410622701036, 106.5546761317927, 102.0132643274808, 119.6726096270366, 97.61388415294184, 106.7928221374049, 94.31369945729962, 87.37098859879977, 82.8015657665458, 88.84342877874248, 94.58797342988339, 92.38720473619748)," +- " y=array(97.43395922838836, 109.5441846957560, 78.82698890096127, 96.67181538737611,95.52423701473863, 85.3391529394878, 87.01956497912255, 111.5289690656729,86.41034184809114, 84.11696923489203, 109.3874354244069, 102.3391063812790,109.0604436531823,102.7957014900897,114.4376483055848,107.4387578165579,106.2490201384653,103.4490197583837,93.8201540211101,101.6060721649409, 115.3512636715722,119.1046170610335,99.74910277836263,104.2116724112481, 86.02222520549304)," +- " c=transpose(matrix(x, y))," +- " d=enclosingDisk(c)," +- " e=getCenter(d)," +- " f=getRadius(d)," +- " g=getSupportPoints(d))";+ String expr =+ "let(echo=true,"+ + " x=array(96.42894739701268, 99.11076410926444, 95.71563821370013,101.4356840561301, 96.17912865782684, 113.430677406492, 109.5927785287056, 87.26561260238425, 103.3122002816537, 100.4959815617706, 92.78972440872515, 92.98815024042877, 89.1448359089767, 104.9410622701036, 106.5546761317927, 102.0132643274808, 119.6726096270366, 97.61388415294184, 106.7928221374049, 94.31369945729962, 87.37098859879977, 82.8015657665458, 88.84342877874248, 94.58797342988339, 92.38720473619748),"+ + " y=array(97.43395922838836, 109.5441846957560, 78.82698890096127, 96.67181538737611,95.52423701473863, 85.3391529394878, 87.01956497912255, 111.5289690656729,86.41034184809114, 84.11696923489203, 109.3874354244069, 102.3391063812790,109.0604436531823,102.7957014900897,114.4376483055848,107.4387578165579,106.2490201384653,103.4490197583837,93.8201540211101,101.6060721649409, 115.3512636715722,119.1046170610335,99.74910277836263,104.2116724112481, 86.02222520549304),"+ + " c=transpose(matrix(x, y)),"+ + " d=enclosingDisk(c),"+ + " e=getCenter(d),"+ + " f=getRadius(d),"+ + " g=getSupportPoints(d))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -646,15 +691,15 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> center = (List<Number>)tuples.get(0).get("e");+ List<Number> center = (List<Number>) tuples.get(0).get("e");assertEquals(center.get(0).doubleValue(), 97.40659699625388, 0.0);assertEquals(center.get(1).doubleValue(), 101.57826559647323, 0.0);- double radius =tuples.get(0).getDouble("f");+ double radius = tuples.get(0).getDouble("f");assertEquals(radius, 22.814029299535, 0.0);@SuppressWarnings({"unchecked"})- List<List<Number>> supportPoints = (List<List<Number>>)tuples.get(0).get("g");+ List<List<Number>> supportPoints = (List<List<Number>>) tuples.get(0).get("g");List<Number> support1 = supportPoints.get(0);assertEquals(support1.get(0).doubleValue(), 95.71563821370013, 0.0);assertEquals(support1.get(1).doubleValue(), 78.82698890096127, 0.0);@@ -675,58 +720,72 @@ public class MathExpressionTest extends SolrCloudTestCase {paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number number = (Number)tuples.get(0).get("return-value");+ Number number = (Number) tuples.get(0).get("return-value");assertTrue(number.doubleValue() == .5D);}private String getDateString(String year, String month, String day) {- return year+"-"+month+"-"+day+"T00:00:00Z";+ return year + "-" + month + "-" + day + "T00:00:00Z";}@Testpublic void testCorrelationStream() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";- String cexpr = "let(a="+expr+", b=select("+expr+",mult(-1, count(*)) as nvalue), c=col(a, count(*)), d=col(b, nvalue), " +- "tuple(corr=corr(c,d), scorr=corr(array(500, 50, 50, 50),d, type=spearmans), kcorr=corr(array(500, 50, 50, 50),d, type=kendalls), d=d))";+ String cexpr =+ "let(a="+ + expr+ + ", b=select("+ + expr+ + ",mult(-1, count(*)) as nvalue), c=col(a, count(*)), d=col(b, nvalue), "+ + "tuple(corr=corr(c,d), scorr=corr(array(500, 50, 50, 50),d, type=spearmans), kcorr=corr(array(500, 50, 50, 50),d, type=kendalls), d=d))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -742,38 +801,51 @@ public class MathExpressionTest extends SolrCloudTestCase {public void testCovariance() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";- String cexpr = "let(a="+expr+", b=select("+expr+",mult(-1, count(*)) as nvalue), c=col(a, count(*)), d=col(b, nvalue), tuple(colc=c, cold=d, cov=cov(c,d)))";+ String cexpr =+ "let(a="+ + expr+ + ", b=select("+ + expr+ + ",mult(-1, count(*)) as nvalue), c=col(a, count(*)), d=col(b, nvalue), tuple(colc=c, cold=d, cov=cov(c,d)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -785,16 +857,18 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testCosineDistance() throws Exception {- String cexpr = "let(echo=true, " +- "a=array(1,2,3,4)," +- "b=array(10, 20, 30, 45), " +- "c=distance(a, b, cosine()), " +- ")";+ String cexpr =+ "let(echo=true, "+ + "a=array(1,2,3,4),"+ + "b=array(10, 20, 30, 45), "+ + "c=distance(a, b, cosine()), "+ + ")";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -806,50 +880,52 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testDistance() throws Exception {- String cexpr = "let(echo=true, " +- "a=array(1,2,3,4)," +- "b=array(2,3,4,5), " +- "c=array(3,4,5,6), " +- "d=distance(a, b), " +- "e=distance(a, c)," +- "f=distance(b, c)," +- "g=transpose(matrix(a, b, c))," +- "h=distance(g)," +- "i=distance(a, b, manhattan()), " +- "j=distance(a, c, manhattan())," +- "k=distance(b, c, manhattan())," +- "l=transpose(matrix(a, b, c))," +- "m=distance(l, manhattan())," +- "n=distance(a, b, canberra()), " +- "o=distance(a, c, canberra())," +- "p=distance(b, c, canberra())," +- "q=transpose(matrix(a, b, c))," +- "r=distance(q, canberra())," +- "s=distance(a, b, earthMovers()), " +- "t=distance(a, c, earthMovers())," +- "u=distance(b, c, earthMovers())," +- "w=transpose(matrix(a, b, c))," +- "x=distance(w, earthMovers())," +- ")";+ String cexpr =+ "let(echo=true, "+ + "a=array(1,2,3,4),"+ + "b=array(2,3,4,5), "+ + "c=array(3,4,5,6), "+ + "d=distance(a, b), "+ + "e=distance(a, c),"+ + "f=distance(b, c),"+ + "g=transpose(matrix(a, b, c)),"+ + "h=distance(g),"+ + "i=distance(a, b, manhattan()), "+ + "j=distance(a, c, manhattan()),"+ + "k=distance(b, c, manhattan()),"+ + "l=transpose(matrix(a, b, c)),"+ + "m=distance(l, manhattan()),"+ + "n=distance(a, b, canberra()), "+ + "o=distance(a, c, canberra()),"+ + "p=distance(b, c, canberra()),"+ + "q=transpose(matrix(a, b, c)),"+ + "r=distance(q, canberra()),"+ + "s=distance(a, b, earthMovers()), "+ + "t=distance(a, c, earthMovers()),"+ + "u=distance(b, c, earthMovers()),"+ + "w=transpose(matrix(a, b, c)),"+ + "x=distance(w, earthMovers()),"+ + ")";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number d = (Number)tuples.get(0).get("d");+ Number d = (Number) tuples.get(0).get("d");assertEquals(d.doubleValue(), 2.0, 0.0);- Number e = (Number)tuples.get(0).get("e");+ Number e = (Number) tuples.get(0).get("e");assertEquals(e.doubleValue(), 4.0, 0.0);- Number f = (Number)tuples.get(0).get("f");+ Number f = (Number) tuples.get(0).get("f");assertEquals(f.doubleValue(), 2.0, 0.0);@SuppressWarnings({"unchecked"})- List<List<Number>> h = (List<List<Number>>)tuples.get(0).get("h");+ List<List<Number>> h = (List<List<Number>>) tuples.get(0).get("h");assertEquals(h.size(), 3);assertEquals(h.get(0).size(), 3);List<Number> row0 = h.get(0);@@ -867,15 +943,15 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(1).doubleValue(), 2, 0);assertEquals(row2.get(2).doubleValue(), 0, 0);- Number i = (Number)tuples.get(0).get("i");+ Number i = (Number) tuples.get(0).get("i");assertEquals(i.doubleValue(), 4.0, 0.0);- Number j = (Number)tuples.get(0).get("j");+ Number j = (Number) tuples.get(0).get("j");assertEquals(j.doubleValue(), 8.0, 0.0);- Number k = (Number)tuples.get(0).get("k");+ Number k = (Number) tuples.get(0).get("k");assertEquals(k.doubleValue(), 4.0, 0.0);@SuppressWarnings({"unchecked"})- List<List<Number>> m = (List<List<Number>>)tuples.get(0).get("m");+ List<List<Number>> m = (List<List<Number>>) tuples.get(0).get("m");assertEquals(m.size(), 3);assertEquals(m.get(0).size(), 3);row0 = m.get(0);@@ -893,15 +969,15 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(1).doubleValue(), 4, 0);assertEquals(row2.get(2).doubleValue(), 0, 0);- Number n = (Number)tuples.get(0).get("n");+ Number n = (Number) tuples.get(0).get("n");assertEquals(n.doubleValue(), 0.787302, 0.0001);- Number o = (Number)tuples.get(0).get("o");+ Number o = (Number) tuples.get(0).get("o");assertEquals(o.doubleValue(), 1.283333, 0.0001);- Number p = (Number)tuples.get(0).get("p");+ Number p = (Number) tuples.get(0).get("p");assertEquals(p.doubleValue(), 0.544877, 0.0001);@SuppressWarnings({"unchecked"})- List<List<Number>> r = (List<List<Number>>)tuples.get(0).get("r");+ List<List<Number>> r = (List<List<Number>>) tuples.get(0).get("r");assertEquals(r.size(), 3);assertEquals(r.get(0).size(), 3);row0 = r.get(0);@@ -919,16 +995,15 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(1).doubleValue(), 0.544877, .0001);assertEquals(row2.get(2).doubleValue(), 0, 0);-- Number s = (Number)tuples.get(0).get("s");+ Number s = (Number) tuples.get(0).get("s");assertEquals(s.doubleValue(), 10.0, 0);- Number t = (Number)tuples.get(0).get("t");+ Number t = (Number) tuples.get(0).get("t");assertEquals(t.doubleValue(), 20.0, 0);- Number u = (Number)tuples.get(0).get("u");+ Number u = (Number) tuples.get(0).get("u");assertEquals(u.doubleValue(), 10.0, 0);@SuppressWarnings({"unchecked"})- List<List<Number>> x = (List<List<Number>>)tuples.get(0).get("x");+ List<List<Number>> x = (List<List<Number>>) tuples.get(0).get("x");assertEquals(x.size(), 3);assertEquals(x.get(0).size(), 3);row0 = x.get(0);@@ -951,38 +1026,46 @@ public class MathExpressionTest extends SolrCloudTestCase {public void testReverse() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";- String cexpr = "let(a="+expr+", c=col(a, max(price_f)), tuple(reverse=rev(c)))";+ String cexpr = "let(a=" + expr + ", c=col(a, max(price_f)), tuple(reverse=rev(c)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -990,7 +1073,7 @@ public class MathExpressionTest extends SolrCloudTestCase {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> reverse = (List<Number>)tuples.get(0).get("reverse");+ List<Number> reverse = (List<Number>) tuples.get(0).get("reverse");assertTrue(reverse.size() == 4);assertTrue(reverse.get(0).doubleValue() == 400D);assertTrue(reverse.get(1).doubleValue() == 300D);@@ -1002,38 +1085,49 @@ public class MathExpressionTest extends SolrCloudTestCase {public void testCopyOf() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";- String cexpr = "let(a="+expr+", c=col(a, max(price_f)), tuple(copy1=copyOf(c, 10), copy2=copyOf(c), copy3=copyOf(c, 2) ))";+ String cexpr =+ "let(a="+ + expr+ + ", c=col(a, max(price_f)), tuple(copy1=copyOf(c, 10), copy2=copyOf(c), copy3=copyOf(c, 2) ))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -1041,7 +1135,7 @@ public class MathExpressionTest extends SolrCloudTestCase {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> copy1 = (List<Number>)tuples.get(0).get("copy1");+ List<Number> copy1 = (List<Number>) tuples.get(0).get("copy1");assertTrue(copy1.size() == 4);assertTrue(copy1.get(0).doubleValue() == 100D);assertTrue(copy1.get(1).doubleValue() == 500D);@@ -1049,7 +1143,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(copy1.get(3).doubleValue() == 400D);@SuppressWarnings({"unchecked"})- List<Number> copy2 = (List<Number>)tuples.get(0).get("copy2");+ List<Number> copy2 = (List<Number>) tuples.get(0).get("copy2");assertTrue(copy2.size() == 4);assertTrue(copy2.get(0).doubleValue() == 100D);assertTrue(copy2.get(1).doubleValue() == 500D);@@ -1057,7 +1151,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(copy2.get(3).doubleValue() == 400D);@SuppressWarnings({"unchecked"})- List<Number> copy3 = (List<Number>)tuples.get(0).get("copy3");+ List<Number> copy3 = (List<Number>) tuples.get(0).get("copy3");assertTrue(copy3.size() == 2);assertTrue(copy3.get(0).doubleValue() == 100D);assertTrue(copy3.get(1).doubleValue() == 500D);@@ -1067,38 +1161,49 @@ public class MathExpressionTest extends SolrCloudTestCase {public void testCopyOfRange() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";- String cexpr = "let(a="+expr+", c=col(a, max(price_f)), tuple(copy=copyOfRange(c, 1, 3), copy2=copyOfRange(c, 2, 4), l=length(c)))";+ String cexpr =+ "let(a="+ + expr+ + ", c=col(a, max(price_f)), tuple(copy=copyOfRange(c, 1, 3), copy2=copyOfRange(c, 2, 4), l=length(c)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -1106,20 +1211,19 @@ public class MathExpressionTest extends SolrCloudTestCase {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> copy1 = (List<Number>)tuples.get(0).get("copy");+ List<Number> copy1 = (List<Number>) tuples.get(0).get("copy");assertTrue(copy1.size() == 2);assertTrue(copy1.get(0).doubleValue() == 500D);assertTrue(copy1.get(1).doubleValue() == 300D);@SuppressWarnings({"unchecked"})- List<Number> copy2 = (List<Number>)tuples.get(0).get("copy2");+ List<Number> copy2 = (List<Number>) tuples.get(0).get("copy2");assertTrue(copy2.size() == 2);assertTrue(copy2.get(0).doubleValue() == 300D);assertTrue(copy2.get(1).doubleValue() == 400D);long l = tuples.get(0).getLong("l");assertTrue(l == 4);-}@Test@@ -1129,7 +1233,8 @@ public class MathExpressionTest extends SolrCloudTestCase {paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -1140,7 +1245,6 @@ public class MathExpressionTest extends SolrCloudTestCase {double p = tuple.getDouble("return-value");assertEquals(p, 6, 0.0);-cexpr = "percentile(array(11,10,3,4,5,6,7,8,9,2,1), 50)";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1171,7 +1275,6 @@ public class MathExpressionTest extends SolrCloudTestCase {p = tuple.getDouble("return-value");assertEquals(p, 2.4, 0.001);-cexpr = "percentile(array(11,10,3,4,5,6,7,8,9,2,1), array(20, 50))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1185,7 +1288,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(tuples.size() == 1);tuple = tuples.get(0);@SuppressWarnings({"unchecked"})- List<Number> percentiles = (List<Number>)tuple.get("return-value");+ List<Number> percentiles = (List<Number>) tuple.get("return-value");assertEquals(percentiles.get(0).doubleValue(), 2.4, 0.001);assertEquals(percentiles.get(1).doubleValue(), 6.0, 0.001);}@@ -1197,7 +1300,8 @@ public class MathExpressionTest extends SolrCloudTestCase {paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -1206,7 +1310,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(tuples.size() == 1);Tuple tuple = tuples.get(0);@SuppressWarnings({"unchecked"})- List<Number> asort = (List<Number>)tuple.get("return-value");+ List<Number> asort = (List<Number>) tuple.get("return-value");assertEquals(asort.size(), 10);assertEquals(asort.get(0).intValue(), 2);assertEquals(asort.get(1).intValue(), 3);@@ -1226,7 +1330,8 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -1244,7 +1349,8 @@ public class MathExpressionTest extends SolrCloudTestCase {paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -1253,7 +1359,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(tuples.size() == 1);Tuple tuple = tuples.get(0);@SuppressWarnings({"unchecked"})- List<Number> asort = (List<Number>)tuple.get("return-value");+ List<Number> asort = (List<Number>) tuple.get("return-value");assertEquals(asort.size(), 6);assertEquals(asort.get(0).doubleValue(), 0, 0.0);assertEquals(asort.get(1).doubleValue(), 1, 0.0);@@ -1267,38 +1373,47 @@ public class MathExpressionTest extends SolrCloudTestCase {public void testRankTransform() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";- String cexpr = "let(a="+expr+", c=col(a, max(price_f)), tuple(reverse=rev(c), ranked=rank(c)))";+ String cexpr =+ "let(a=" + expr + ", c=col(a, max(price_f)), tuple(reverse=rev(c), ranked=rank(c)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -1306,7 +1421,7 @@ public class MathExpressionTest extends SolrCloudTestCase {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> reverse = (List<Number>)tuples.get(0).get("reverse");+ List<Number> reverse = (List<Number>) tuples.get(0).get("reverse");assertTrue(reverse.size() == 4);assertTrue(reverse.get(0).doubleValue() == 400D);assertTrue(reverse.get(1).doubleValue() == 300D);@@ -1314,7 +1429,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(reverse.get(3).doubleValue() == 100D);@SuppressWarnings({"unchecked"})- List<Number> ranked = (List<Number>)tuples.get(0).get("ranked");+ List<Number> ranked = (List<Number>) tuples.get(0).get("ranked");assertTrue(ranked.size() == 4);assertTrue(ranked.get(0).doubleValue() == 1D);assertTrue(ranked.get(1).doubleValue() == 4D);@@ -1329,13 +1444,14 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 6);assertTrue(out.get(0).intValue() == 1);assertTrue(out.get(1).intValue() == 2);@@ -1352,7 +1468,7 @@ public class MathExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- out = (List<Number>)tuples.get(0).get("return-value");+ out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 6);assertTrue(out.get(0).doubleValue() == 1.122D);assertTrue(out.get(1).doubleValue() == 2.222D);@@ -1364,20 +1480,22 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testPairSort() throws Exception {- String cexpr = "let(a=array(4.5, 7.7, 2.1, 2.1, 6.3)," +- " b=array(1, 2, 3, 4, 5)," +- " c=pairSort(a, b))";+ String cexpr =+ "let(a=array(4.5, 7.7, 2.1, 2.1, 6.3),"+ + " b=array(1, 2, 3, 4, 5),"+ + " c=pairSort(a, b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> out = (List<List<Number>>)tuples.get(0).get("c");+ List<List<Number>> out = (List<List<Number>>) tuples.get(0).get("c");assertEquals(out.size(), 2);List<Number> row1 = out.get(0);assertEquals(row1.get(0).doubleValue(), 2.1, 0);@@ -1394,21 +1512,21 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(4).doubleValue(), 2, 0);}-@Testpublic void testOnes() throws Exception {String cexpr = "ones(6)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertEquals(out.size(), 6);assertEquals(out.get(0).intValue(), 1);assertEquals(out.get(1).intValue(), 1);@@ -1424,14 +1542,15 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertEquals(out.size(), 6);assertEquals(out.get(0).intValue(), 0);assertEquals(out.get(1).intValue(), 1);@@ -1441,21 +1560,21 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(out.get(5).intValue(), 5);}-@Testpublic void testRepeat() throws Exception {String cexpr = "repeat(6.5, 6)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertEquals(out.size(), 6);assertEquals(out.get(0).doubleValue(), 6.5, 0);assertEquals(out.get(1).doubleValue(), 6.5, 0);@@ -1465,21 +1584,21 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(out.get(5).doubleValue(), 6.5, 0);}-@Testpublic void testLtrim() throws Exception {String cexpr = "ltrim(array(1,2,3,4,5,6), 2)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertEquals(out.size(), 4);assertEquals(out.get(0).intValue(), 3);assertEquals(out.get(1).intValue(), 4);@@ -1493,14 +1612,15 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertEquals(out.size(), 4);assertEquals(out.get(0).intValue(), 1);assertEquals(out.get(1).intValue(), 2);@@ -1508,21 +1628,21 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(out.get(3).intValue(), 4);}-@Testpublic void testZeros() throws Exception {String cexpr = "zeros(6)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertEquals(out.size(), 6);assertEquals(out.get(0).intValue(), 0);assertEquals(out.get(1).intValue(), 0);@@ -1534,29 +1654,31 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testMatrix() throws Exception {- String cexpr = "let(echo=true," +- " a=setColumnLabels(matrix(array(1, 2, 3), " +- " rev(array(4,5,6)))," +- " array(\"col1\", \"col2\", \"col3\"))," +- " b=rowAt(a, 1)," +- " c=colAt(a, 2)," +- " d=getColumnLabels(a)," +- " e=topFeatures(a, 1)," +- " f=rowCount(a)," +- " g=columnCount(a)," +- " h=indexOf(d, \"col2\")," +- " i=indexOf(d, \"col3\"))";+ String cexpr =+ "let(echo=true,"+ + " a=setColumnLabels(matrix(array(1, 2, 3), "+ + " rev(array(4,5,6))),"+ + " array(\"col1\", \"col2\", \"col3\")),"+ + " b=rowAt(a, 1),"+ + " c=colAt(a, 2),"+ + " d=getColumnLabels(a),"+ + " e=topFeatures(a, 1),"+ + " f=rowCount(a),"+ + " g=columnCount(a),"+ + " h=indexOf(d, \"col2\"),"+ + " i=indexOf(d, \"col3\"))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> out = (List<List<Number>>)tuples.get(0).get("a");+ List<List<Number>> out = (List<List<Number>>) tuples.get(0).get("a");List<Number> array1 = out.get(0);assertEquals(array1.size(), 3);@@ -1571,7 +1693,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(array2.get(2).doubleValue(), 4.0, 0.0);@SuppressWarnings({"unchecked"})- List<Number> row = (List<Number>)tuples.get(0).get("b");+ List<Number> row = (List<Number>) tuples.get(0).get("b");assertEquals(row.size(), 3);assertEquals(array2.get(0).doubleValue(), 6.0, 0.0);@@ -1579,20 +1701,20 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(array2.get(2).doubleValue(), 4.0, 0.0);@SuppressWarnings({"unchecked"})- List<Number> col = (List<Number>)tuples.get(0).get("c");+ List<Number> col = (List<Number>) tuples.get(0).get("c");assertEquals(col.size(), 2);assertEquals(col.get(0).doubleValue(), 3.0, 0.0);assertEquals(col.get(1).doubleValue(), 4.0, 0.0);@SuppressWarnings({"unchecked"})- List<String> colLabels = (List<String>)tuples.get(0).get("d");+ List<String> colLabels = (List<String>) tuples.get(0).get("d");assertEquals(colLabels.size(), 3);assertEquals(colLabels.get(0), "col1");assertEquals(colLabels.get(1), "col2");assertEquals(colLabels.get(2), "col3");@SuppressWarnings({"unchecked"})- List<List<String>> features = (List<List<String>>)tuples.get(0).get("e");+ List<List<String>> features = (List<List<String>>) tuples.get(0).get("e");assertEquals(features.size(), 2);assertEquals(features.get(0).size(), 1);assertEquals(features.get(1).size(), 1);@@ -1600,23 +1722,20 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(features.get(1).get(0), "col1");assertTrue(tuples.get(0).getLong("f") == 2);- assertTrue(tuples.get(0).getLong("g")== 3);- assertTrue(tuples.get(0).getLong("h")== 1);- assertTrue(tuples.get(0).getLong("i")== 2);+ assertTrue(tuples.get(0).getLong("g") == 3);+ assertTrue(tuples.get(0).getLong("h") == 1);+ assertTrue(tuples.get(0).getLong("i") == 2);}-@Test@SuppressWarnings({"unchecked", "rawtypes"})public void testZplot() throws Exception {- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;--- String cexpr = "let(a=array(1,2,3,4)," +- " b=array(10,11,12,13),"+- " zplot(x=a, y=b))";+ String cexpr =+ "let(a=array(1,2,3,4)," + " b=array(10,11,12,13)," + " zplot(x=a, y=b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1646,9 +1765,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(out.getDouble("x").doubleValue(), 4.0, 0.0);assertEquals(out.getDouble("y").doubleValue(), 13.0, 0.0);-- cexpr = "let(b=array(10,11,12,13),"+- " zplot(y=b))";+ cexpr = "let(b=array(10,11,12,13)," + " zplot(y=b))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1687,25 +1804,25 @@ public class MathExpressionTest extends SolrCloudTestCase {context = new StreamContext();solrStream.setStreamContext(context);tuples = getTuples(solrStream);- assertEquals(tuples.size(),11);+ assertEquals(tuples.size(), 11);long x = tuples.get(5).getLong("x");double y = tuples.get(5).getDouble("y");assertEquals(x, 5);- assertEquals(y, 0.24609375000000003, 0);+ assertEquals(y, 0.24609375000000003, 0);- //Due to random errors (bugs) in Apache Commons Math EmpiricalDistribution- //there are times when tuples are discarded because- //they contain values with NaN values. This will occur- //only on the very end of the tails of the normal distribution or other- //real distributions and doesn't effect the visual quality of the curve very much.- //But it does effect the reliability of tests.- //For this reason the loop below is in place to run the test N times looking- //for the correct number of tuples before asserting the mean.+ // Due to random errors (bugs) in Apache Commons Math EmpiricalDistribution+ // there are times when tuples are discarded because+ // they contain values with NaN values. This will occur+ // only on the very end of the tails of the normal distribution or other+ // real distributions and doesn't effect the visual quality of the curve very much.+ // But it does effect the reliability of tests.+ // For this reason the loop below is in place to run the test N times looking+ // for the correct number of tuples before asserting the mean.int n = 0;int limit = 15;- while(true) {+ while (true) {cexpr = "zplot(dist=normalDistribution(100, 10))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1714,7 +1831,7 @@ public class MathExpressionTest extends SolrCloudTestCase {context = new StreamContext();solrStream.setStreamContext(context);tuples = getTuples(solrStream);- //Assert the mean+ // Assert the meanif (tuples.size() == 32) {double x1 = tuples.get(15).getDouble("x");double y1 = tuples.get(15).getDouble("y");@@ -1723,17 +1840,18 @@ public class MathExpressionTest extends SolrCloudTestCase {break;} else {++n;- if(n == limit) {+ if (n == limit) {throw new Exception("Reached iterations limit without correct tuple count.");}}}- cexpr = "let(a=sample(normalDistribution(40, 1.5), 700)," +- " b=sample(normalDistribution(40, 1.5), 700)," +- " c=transpose(matrix(a, b)),"+- " d=kmeans(c, 5),"+- " zplot(clusters=d))";+ cexpr =+ "let(a=sample(normalDistribution(40, 1.5), 700),"+ + " b=sample(normalDistribution(40, 1.5), 700),"+ + " c=transpose(matrix(a, b)),"+ + " d=kmeans(c, 5),"+ + " zplot(clusters=d))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1745,7 +1863,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(tuples.size() == 700);Set clusters = new HashSet();- for(Tuple tup : tuples) {+ for (Tuple tup : tuples) {assertNotNull(tup.get("x"));assertNotNull(tup.get("y"));clusters.add(tup.getString("cluster"));@@ -1758,8 +1876,9 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(clusters.contains("cluster4"));assertTrue(clusters.contains("cluster5"));- cexpr = "let(a=matrix(array(0,1,2,3,4,5,6,7,8,9,10,11), array(10,11,12,13,14,15,16,17,18,19,20,21))," +- " zplot(heat=a))";+ cexpr =+ "let(a=matrix(array(0,1,2,3,4,5,6,7,8,9,10,11), array(10,11,12,13,14,15,16,17,18,19,20,21)),"+ + " zplot(heat=a))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1805,10 +1924,10 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(yLabel, "row1");assertEquals(z.longValue(), 10L);-- cexpr = "let(a=transpose(matrix(array(0, 1, 2, 3, 4, 5, 6, 7,8,9,10,11), " +- " array(10,11,12,13,14,15,16,17,18,19,20,21)))," +- " zplot(heat=a))";+ cexpr =+ "let(a=transpose(matrix(array(0, 1, 2, 3, 4, 5, 6, 7,8,9,10,11), "+ + " array(10,11,12,13,14,15,16,17,18,19,20,21))),"+ + " zplot(heat=a))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1854,11 +1973,12 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(yLabel, "row06");assertEquals(z.longValue(), 6L);- cexpr = "let(a=matrix(array(0, 1, 2, 3, 4, 5, 6, 7,8,9,10,11), " +- " array(10,11,12,13,14,15,16,17,18,19,20,21))," +- " b=setRowLabels(a, array(\"blah1\", \"blah2\")),"+- " c=setColumnLabels(b, array(\"rah1\", \"rah2\", \"rah3\", \"rah4\", \"rah5\", \"rah6\", \"rah7\", \"rah8\", \"rah9\", \"rah10\", \"rah11\", \"rah12\")),"+- " zplot(heat=c))";+ cexpr =+ "let(a=matrix(array(0, 1, 2, 3, 4, 5, 6, 7,8,9,10,11), "+ + " array(10,11,12,13,14,15,16,17,18,19,20,21)),"+ + " b=setRowLabels(a, array(\"blah1\", \"blah2\")),"+ + " c=setColumnLabels(b, array(\"rah1\", \"rah2\", \"rah3\", \"rah4\", \"rah5\", \"rah6\", \"rah7\", \"rah8\", \"rah9\", \"rah10\", \"rah11\", \"rah12\")),"+ + " zplot(heat=c))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -1905,27 +2025,28 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(z.longValue(), 10L);}-@Test@SuppressWarnings({"unchecked"})public void testMatrixMath() throws Exception {- String cexpr = "let(echo=true, a=matrix(array(1.5, 2.5, 3.5), array(4.5,5.5,6.5)), " +- "b=grandSum(a), " +- "c=sumRows(a), " +- "d=sumColumns(a), " +- "e=scalarAdd(1, a)," +- "f=scalarSubtract(1, a)," +- "g=scalarMultiply(1.5, a)," +- "h=scalarDivide(1.5, a)," +- "i=scalarAdd(1.5, array(1.5, 2.5, 3.5))," +- "j=scalarSubtract(1.5, array(1.5, 2.5, 3.5))," +- "k=scalarMultiply(1.5, array(1.5, 2.5, 3.5))," +- "l=scalarDivide(1.5, array(1.5, 2.5, 3.5)))";+ String cexpr =+ "let(echo=true, a=matrix(array(1.5, 2.5, 3.5), array(4.5,5.5,6.5)), "+ + "b=grandSum(a), "+ + "c=sumRows(a), "+ + "d=sumColumns(a), "+ + "e=scalarAdd(1, a),"+ + "f=scalarSubtract(1, a),"+ + "g=scalarMultiply(1.5, a),"+ + "h=scalarDivide(1.5, a),"+ + "i=scalarAdd(1.5, array(1.5, 2.5, 3.5)),"+ + "j=scalarSubtract(1.5, array(1.5, 2.5, 3.5)),"+ + "k=scalarMultiply(1.5, array(1.5, 2.5, 3.5)),"+ + "l=scalarDivide(1.5, array(1.5, 2.5, 3.5)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -1935,18 +2056,18 @@ public class MathExpressionTest extends SolrCloudTestCase {double grandSum = tuples.get(0).getDouble("b");assertEquals(grandSum, 24, 0.0);- List<Number> sumRows = (List<Number>)tuples.get(0).get("c");+ List<Number> sumRows = (List<Number>) tuples.get(0).get("c");assertEquals(sumRows.size(), 2);assertEquals(sumRows.get(0).doubleValue(), 7.5, 0.0);assertEquals(sumRows.get(1).doubleValue(), 16.5, 0.0);- List<Number> sumCols = (List<Number>)tuples.get(0).get("d");+ List<Number> sumCols = (List<Number>) tuples.get(0).get("d");assertEquals(sumCols.size(), 3);assertEquals(sumCols.get(0).doubleValue(), 6.0, 0.0);assertEquals(sumCols.get(1).doubleValue(), 8.0, 0.0);assertEquals(sumCols.get(2).doubleValue(), 10, 0.0);- List<List<Number>> scalarAdd = (List<List<Number>>)tuples.get(0).get("e");+ List<List<Number>> scalarAdd = (List<List<Number>>) tuples.get(0).get("e");List<Number> row1 = scalarAdd.get(0);assertEquals(row1.size(), 3);assertEquals(row1.get(0).doubleValue(), 2.5, 0.0);@@ -1958,7 +2079,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(1).doubleValue(), 6.5, 0.0);assertEquals(row2.get(2).doubleValue(), 7.5, 0.0);- List<List<Number>> scalarSubtract = (List<List<Number>>)tuples.get(0).get("f");+ List<List<Number>> scalarSubtract = (List<List<Number>>) tuples.get(0).get("f");row1 = scalarSubtract.get(0);assertEquals(row1.size(), 3);assertEquals(row1.get(0).doubleValue(), 0.5, 0.0);@@ -1970,7 +2091,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(1).doubleValue(), 4.5, 0.0);assertEquals(row2.get(2).doubleValue(), 5.5, 0.0);- List<List<Number>> scalarMultiply = (List<List<Number>>)tuples.get(0).get("g");+ List<List<Number>> scalarMultiply = (List<List<Number>>) tuples.get(0).get("g");row1 = scalarMultiply.get(0);assertEquals(row1.size(), 3);assertEquals(row1.get(0).doubleValue(), 2.25, 0.0);@@ -1982,7 +2103,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(1).doubleValue(), 8.25, 0.0);assertEquals(row2.get(2).doubleValue(), 9.75, 0.0);- List<List<Number>> scalarDivide = (List<List<Number>>)tuples.get(0).get("h");+ List<List<Number>> scalarDivide = (List<List<Number>>) tuples.get(0).get("h");row1 = scalarDivide.get(0);assertEquals(row1.size(), 3);assertEquals(row1.get(0).doubleValue(), 1.0, 0.0);@@ -1994,25 +2115,25 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(1).doubleValue(), 3.66666666666667, 0.001);assertEquals(row2.get(2).doubleValue(), 4.33333333333333, 0.001);- List<Number> rowA = (List<Number>)tuples.get(0).get("i");+ List<Number> rowA = (List<Number>) tuples.get(0).get("i");assertEquals(rowA.size(), 3);assertEquals(rowA.get(0).doubleValue(), 3.0, 0.0);assertEquals(rowA.get(1).doubleValue(), 4.0, 0.0);assertEquals(rowA.get(2).doubleValue(), 5.0, 0.0);- rowA = (List<Number>)tuples.get(0).get("j");+ rowA = (List<Number>) tuples.get(0).get("j");assertEquals(rowA.size(), 3);assertEquals(rowA.get(0).doubleValue(), 0, 0.0);assertEquals(rowA.get(1).doubleValue(), 1.0, 0.0);assertEquals(rowA.get(2).doubleValue(), 2.0, 0.0);- rowA = (List<Number>)tuples.get(0).get("k");+ rowA = (List<Number>) tuples.get(0).get("k");assertEquals(rowA.size(), 3);assertEquals(rowA.get(0).doubleValue(), 2.25, 0.0);assertEquals(rowA.get(1).doubleValue(), 3.75, 0.0);assertEquals(rowA.get(2).doubleValue(), 5.25, 0.0);- rowA = (List<Number>)tuples.get(0).get("l");+ rowA = (List<Number>) tuples.get(0).get("l");assertEquals(rowA.size(), 3);assertEquals(rowA.get(0).doubleValue(), 1.0, 0.0);assertEquals(rowA.get(1).doubleValue(), 1.66666666666667, 0.001);@@ -2025,14 +2146,15 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> out = (List<List<Number>>)tuples.get(0).get("b");+ List<List<Number>> out = (List<List<Number>>) tuples.get(0).get("b");assertEquals(out.size(), 3);List<Number> array1 = out.get(0);assertEquals(array1.size(), 2);@@ -2052,18 +2174,20 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testUnitize() throws Exception {- String cexpr = "let(echo=true, a=unitize(matrix(array(1,2,3), array(4,5,6))), b=unitize(array(4,5,6)))";+ String cexpr =+ "let(echo=true, a=unitize(matrix(array(1,2,3), array(4,5,6))), b=unitize(array(4,5,6)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> out = (List<List<Number>>)tuples.get(0).get("a");+ List<List<Number>> out = (List<List<Number>>) tuples.get(0).get("a");assertEquals(out.size(), 2);List<Number> array1 = out.get(0);assertEquals(array1.size(), 3);@@ -2078,7 +2202,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(array2.get(2).doubleValue(), 0.6837634587578276, 0.0);@SuppressWarnings({"unchecked"})- List<Number> array3 = (List<Number>)tuples.get(0).get("b");+ List<Number> array3 = (List<Number>) tuples.get(0).get("b");assertEquals(array3.size(), 3);assertEquals(array3.get(0).doubleValue(), 0.4558423058385518, 0.0);assertEquals(array3.get(1).doubleValue(), 0.5698028822981898, 0.0);@@ -2087,21 +2211,23 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testNormalizeSum() throws Exception {- String cexpr = "let(echo=true, " +- "a=normalizeSum(matrix(array(1,2,3), array(4,5,6))), " +- "b=normalizeSum(array(1,2,3))," +- "c=normalizeSum(array(1,2,3), 100))";+ String cexpr =+ "let(echo=true, "+ + "a=normalizeSum(matrix(array(1,2,3), array(4,5,6))), "+ + "b=normalizeSum(array(1,2,3)),"+ + "c=normalizeSum(array(1,2,3), 100))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> out = (List<List<Number>>)tuples.get(0).get("a");+ List<List<Number>> out = (List<List<Number>>) tuples.get(0).get("a");assertEquals(out.size(), 2);List<Number> array1 = out.get(0);assertEquals(array1.size(), 3);@@ -2116,14 +2242,14 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(array2.get(2).doubleValue(), 0.4, 0.0001);@SuppressWarnings({"unchecked"})- List<Number> array3 = (List<Number>)tuples.get(0).get("b");+ List<Number> array3 = (List<Number>) tuples.get(0).get("b");assertEquals(array3.size(), 3);assertEquals(array3.get(0).doubleValue(), 0.16666666666666666, 0.0001);assertEquals(array3.get(1).doubleValue(), 0.3333333333333333, 0.0001);assertEquals(array3.get(2).doubleValue(), 0.5, 0.0001);@SuppressWarnings({"unchecked"})- List<Number> array4 = (List<Number>)tuples.get(0).get("c");+ List<Number> array4 = (List<Number>) tuples.get(0).get("c");assertEquals(array4.size(), 3);assertEquals(array4.get(0).doubleValue(), 16.666666666666666, 0.0001);assertEquals(array4.get(1).doubleValue(), 33.33333333333333, 0.00001);@@ -2132,18 +2258,20 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testStandardize() throws Exception {- String cexpr = "let(echo=true, a=standardize(matrix(array(1,2,3), array(4,5,6))), b=standardize(array(4,5,6)), c=zscores(array(4,5,6)))";+ String cexpr =+ "let(echo=true, a=standardize(matrix(array(1,2,3), array(4,5,6))), b=standardize(array(4,5,6)), c=zscores(array(4,5,6)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> out = (List<List<Number>>)tuples.get(0).get("a");+ List<List<Number>> out = (List<List<Number>>) tuples.get(0).get("a");assertEquals(out.size(), 2);List<Number> array1 = out.get(0);assertEquals(array1.size(), 3);@@ -2158,14 +2286,14 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(array2.get(2).doubleValue(), 1, 0.0);@SuppressWarnings({"unchecked"})- List<Number> array3 = (List<Number>)tuples.get(0).get("b");+ List<Number> array3 = (List<Number>) tuples.get(0).get("b");assertEquals(array3.size(), 3);assertEquals(array3.get(0).doubleValue(), -1, 0.0);assertEquals(array3.get(1).doubleValue(), 0, 0.0);assertEquals(array3.get(2).doubleValue(), 1, 0.0);@SuppressWarnings({"unchecked"})- List<Number> array4 = (List<Number>)tuples.get(0).get("c");+ List<Number> array4 = (List<Number>) tuples.get(0).get("c");assertEquals(array4.size(), 3);assertEquals(array4.get(0).doubleValue(), -1, 0.0);assertEquals(array4.get(1).doubleValue(), 0, 0.0);@@ -2174,16 +2302,18 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testMarkovChain() throws Exception {- String cexpr = "let(state0=array(.5,.5),\n" +- " state1=array(.5,.5),\n" +- " states=matrix(state0, state1),\n" +- " m=markovChain(states, 0),\n" +- " s=sample(m, 50000),\n" +- " f=freqTable(s))";+ String cexpr =+ "let(state0=array(.5,.5),\n"+ + " state1=array(.5,.5),\n"+ + " states=matrix(state0, state1),\n"+ + " m=markovChain(states, 0),\n"+ + " s=sample(m, 50000),\n"+ + " f=freqTable(s))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2204,14 +2334,15 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 9);assertTrue(out.get(0).intValue() == 1);assertTrue(out.get(1).intValue() == 2);@@ -2226,49 +2357,49 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testProbabilityRange() throws Exception {- String cexpr = "let(a=normalDistribution(500, 20), " +- "b=probability(a, 520, 530))";+ String cexpr = "let(a=normalDistribution(500, 20), " + "b=probability(a, 520, 530))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number prob = (Number)tuples.get(0).get("b");- assertEquals(prob.doubleValue(), 0.09184805266259899, 0.0);+ Number prob = (Number) tuples.get(0).get("b");+ assertEquals(prob.doubleValue(), 0.09184805266259899, 0.0);}@Test- // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028")- // commented out on: 24-Dec-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Jul-2018public void testDistributions() throws Exception {- String cexpr = "let(a=normalDistribution(10, 2), " +- "b=sample(a, 250), " +- "c=normalDistribution(100, 6), " +- "d=sample(c, 250), " +- "u=uniformDistribution(1, 6),"+- "t=sample(u, 250),"+- "e=empiricalDistribution(d),"+- "f=sample(e, 250),"+- "tuple(sample=b, ks=ks(a,b), ks2=ks(a, d), ks3=ks(u, t)))";+ String cexpr =+ "let(a=normalDistribution(10, 2), "+ + "b=sample(a, 250), "+ + "c=normalDistribution(100, 6), "+ + "d=sample(c, 250), "+ + "u=uniformDistribution(1, 6),"+ + "t=sample(u, 250),"+ + "e=empiricalDistribution(d),"+ + "f=sample(e, 250),"+ + "tuple(sample=b, ks=ks(a,b), ks2=ks(a, d), ks3=ks(u, t)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;try {sampleTest(paramsLoc, url);- } catch(AssertionError e) {- //This test will have random failures do to the random sampling. So if it fails try it again.+ } catch (AssertionError e) {+ // This test will have random failures do to the random sampling. So if it fails try it again.try {sampleTest(paramsLoc, url);- } catch(AssertionError e2) {+ } catch (AssertionError e2) {try {sampleTest(paramsLoc, url);- } catch(AssertionError e3) {- //If it fails a lot in a row, we probably broke some code. (TODO: bad test)+ } catch (AssertionError e3) {+ // If it fails a lot in a row, we probably broke some code. (TODO: bad test)sampleTest(paramsLoc, url);}}@@ -2307,7 +2438,8 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2323,7 +2455,8 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2335,14 +2468,16 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testSelectWithSequentialEvaluators() throws Exception {- String cexpr = "select(list(tuple(a=add(1,2)), tuple(a=add(2,2))), " +- " add(1, a) as blah, " +- " add(1, blah) as blah1," +- " recNum() as recNum)";+ String cexpr =+ "select(list(tuple(a=add(1,2)), tuple(a=add(2,2))), "+ + " add(1, a) as blah, "+ + " add(1, blah) as blah1,"+ + " recNum() as recNum)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2357,17 +2492,17 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(tuple1.getLong("blah").longValue(), 5L);assertEquals(tuple1.getLong("blah1").longValue(), 6L);assertEquals(tuple1.getLong("recNum").longValue(), 1);-}-@Testpublic void testMatches() throws Exception {- String cexpr = "having(list(tuple(a=\"Hello World\"), tuple(a=\"Good bye\")), matches(a, \"Hello\"))";+ String cexpr =+ "having(list(tuple(a=\"Hello World\"), tuple(a=\"Good bye\")), matches(a, \"Hello\"))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2376,11 +2511,12 @@ public class MathExpressionTest extends SolrCloudTestCase {Tuple tuple0 = tuples.get(0);assertEquals(tuple0.getString("a"), "Hello World");- cexpr = "having(list(tuple(a=\"Hello World\"), tuple(a=\"Good bye\")), matches(a, \"(?i)good\"))";+ cexpr =+ "having(list(tuple(a=\"Hello World\"), tuple(a=\"Good bye\")), matches(a, \"(?i)good\"))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;solrStream = new SolrStream(url, paramsLoc);context = new StreamContext();solrStream.setStreamContext(context);@@ -2390,14 +2526,14 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(tuple0.getString("a"), "Good bye");}-@Testpublic void testNotNullHaving() throws Exception {String cexpr = "having(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), notNull(b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2413,7 +2549,8 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2423,14 +2560,15 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(tuple0.getLong("a").longValue(), 2L);}-@Testpublic void testNotNullSelect() throws Exception {- String cexpr = "select(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), if(notNull(a),a, 0) as out)";+ String cexpr =+ "select(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), if(notNull(a),a, 0) as out)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2441,17 +2579,17 @@ public class MathExpressionTest extends SolrCloudTestCase {Tuple tuple1 = tuples.get(1);assertEquals(tuple1.getLong("out").longValue(), 0L);-}-@Testpublic void testIsNullSelect() throws Exception {- String cexpr = "select(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), if(isNull(a), 0, a) as out)";+ String cexpr =+ "select(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), if(isNull(a), 0, a) as out)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2462,7 +2600,6 @@ public class MathExpressionTest extends SolrCloudTestCase {Tuple tuple1 = tuples.get(1);assertEquals(tuple1.getLong("out").longValue(), 0L);-}@Test@@ -2471,7 +2608,8 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2488,7 +2626,8 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2496,24 +2635,24 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(tuples.size(), 1);Tuple tuple = tuples.get(0);@SuppressWarnings({"unchecked"})- List<Number> logs = (List<Number>)tuple.get("b");+ List<Number> logs = (List<Number>) tuple.get("b");assertEquals(logs.size(), 3);assertEquals(logs.get(0).doubleValue(), 1, 0.0);assertEquals(logs.get(1).doubleValue(), 1.3010299956639813, 0.0);assertEquals(logs.get(2).doubleValue(), 1.4771212547196624, 0.0);- Number log = (Number)tuple.get("c");+ Number log = (Number) tuple.get("c");assertEquals(log.doubleValue(), 1.4842998393467859, 0.0);}-@Testpublic void testRecip() throws Exception {String cexpr = "let(echo=true, a=array(10, 20, 30), b=recip(a), c=recip(30.5))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -2521,38 +2660,39 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(tuples.size(), 1);Tuple tuple = tuples.get(0);@SuppressWarnings({"unchecked"})- List<Number> logs = (List<Number>)tuple.get("b");+ List<Number> logs = (List<Number>) tuple.get("b");assertEquals(logs.size(), 3);assertEquals(logs.get(0).doubleValue(), .1, 0.0);assertEquals(logs.get(1).doubleValue(), .05, 0.0);assertEquals(logs.get(2).doubleValue(), 0.03333333333333333, 0.0);- Number log = (Number)tuple.get("c");+ Number log = (Number) tuple.get("c");assertEquals(log.doubleValue(), 0.03278688524590164, 0.0);}-@Test@SuppressWarnings({"unchecked"})public void testPow() throws Exception {- String cexpr = "let(echo=true, a=array(10, 20, 30), b=pow(a, 2), c=pow(2, a), d=pow(10, 3), e=pow(a, array(1, 2, 3)))";+ String cexpr =+ "let(echo=true, a=array(10, 20, 30), b=pow(a, 2), c=pow(2, a), d=pow(10, 3), e=pow(a, array(1, 2, 3)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertEquals(tuples.size(), 1);Tuple tuple = tuples.get(0);- List<Number> pows = (List<Number>)tuple.get("b");+ List<Number> pows = (List<Number>) tuple.get("b");assertEquals(pows.size(), 3);assertEquals(pows.get(0).doubleValue(), 100, 0.0);assertEquals(pows.get(1).doubleValue(), 400, 0.0);assertEquals(pows.get(2).doubleValue(), 900, 0.0);- pows = (List<Number>)tuple.get("c");+ pows = (List<Number>) tuple.get("c");assertEquals(pows.size(), 3);assertEquals(pows.get(0).doubleValue(), 1024, 0.0);assertEquals(pows.get(1).doubleValue(), 1048576, 0.0);@@ -2561,37 +2701,38 @@ public class MathExpressionTest extends SolrCloudTestCase {double p = tuple.getDouble("d");assertEquals(p, 1000, 0.0);- pows = (List<Number>)tuple.get("e");+ pows = (List<Number>) tuple.get("e");assertEquals(pows.size(), 3);assertEquals(pows.get(0).doubleValue(), 10, 0.0);assertEquals(pows.get(1).doubleValue(), 400, 0.0);assertEquals(pows.get(2).doubleValue(), 27000, 0.0);-}@Test@SuppressWarnings({"unchecked"})public void testTermVectors() throws Exception {// Test termVectors with only documents and default termVector settings- String cexpr = "let(echo=true," +- "a=select(list(tuple(id=\"1\", text=\"hello world\"), " +- "tuple(id=\"2\", text=\"hello steve\"), " +- "tuple(id=\"3\", text=\"hello jim jim\"), " +- "tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms)," +- " b=termVectors(a, minDocFreq=0, maxDocFreq=1)," +- " c=getRowLabels(b)," +- " d=getColumnLabels(b)," +- " e=getAttribute(b, \"docFreqs\"))";+ String cexpr =+ "let(echo=true,"+ + "a=select(list(tuple(id=\"1\", text=\"hello world\"), "+ + "tuple(id=\"2\", text=\"hello steve\"), "+ + "tuple(id=\"3\", text=\"hello jim jim\"), "+ + "tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms),"+ + " b=termVectors(a, minDocFreq=0, maxDocFreq=1),"+ + " c=getRowLabels(b),"+ + " d=getColumnLabels(b),"+ + " e=getAttribute(b, \"docFreqs\"))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<List<Number>> termVectors = (List<List<Number>>)tuples.get(0).get("b");+ List<List<Number>> termVectors = (List<List<Number>>) tuples.get(0).get("b");assertEquals(termVectors.size(), 4);List<Number> termVector = termVectors.get(0);@@ -2626,14 +2767,14 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(termVector.get(3).doubleValue(), 0.0, 0.0);assertEquals(termVector.get(4).doubleValue(), 0.0, 0.0);- List<String> rowLabels = (List<String>)tuples.get(0).get("c");+ List<String> rowLabels = (List<String>) tuples.get(0).get("c");assertEquals(rowLabels.size(), 4);assertEquals(rowLabels.get(0), "1");assertEquals(rowLabels.get(1), "2");assertEquals(rowLabels.get(2), "3");assertEquals(rowLabels.get(3), "4");- List<String> columnLabels = (List<String>)tuples.get(0).get("d");+ List<String> columnLabels = (List<String>) tuples.get(0).get("d");assertEquals(columnLabels.size(), 5);assertEquals(columnLabels.get(0), "hello");assertEquals(columnLabels.get(1), "jack");@@ -2641,7 +2782,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(columnLabels.get(3), "steve");assertEquals(columnLabels.get(4), "world");- Map<String, Number> docFreqs = (Map<String, Number>)tuples.get(0).get("e");+ Map<String, Number> docFreqs = (Map<String, Number>) tuples.get(0).get("e");assertEquals(docFreqs.size(), 5);assertEquals(docFreqs.get("hello").intValue(), 4);@@ -2650,17 +2791,18 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(docFreqs.get("steve").intValue(), 1);assertEquals(docFreqs.get("world").intValue(), 1);- //Test minTermLength. This should drop off the term jim-- cexpr = "let(echo=true," +- "a=select(list(tuple(id=\"1\", text=\"hello world\"), " +- "tuple(id=\"2\", text=\"hello steve\"), " +- "tuple(id=\"3\", text=\"hello jim jim\"), " +- "tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms)," +- " b=termVectors(a, minTermLength=4, minDocFreq=0, maxDocFreq=1)," +- " c=getRowLabels(b)," +- " d=getColumnLabels(b)," +- " e=getAttribute(b, \"docFreqs\"))";+ // Test minTermLength. This should drop off the term jim++ cexpr =+ "let(echo=true,"+ + "a=select(list(tuple(id=\"1\", text=\"hello world\"), "+ + "tuple(id=\"2\", text=\"hello steve\"), "+ + "tuple(id=\"3\", text=\"hello jim jim\"), "+ + "tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms),"+ + " b=termVectors(a, minTermLength=4, minDocFreq=0, maxDocFreq=1),"+ + " c=getRowLabels(b),"+ + " d=getColumnLabels(b),"+ + " e=getAttribute(b, \"docFreqs\"))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");@@ -2669,7 +2811,7 @@ public class MathExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- termVectors = (List<List<Number>>)tuples.get(0).get("b");+ termVectors = (List<List<Number>>) tuples.get(0).get("b");assertEquals(termVectors.size(), 4);termVector = termVectors.get(0);assertEquals(termVector.size(), 4);@@ -2699,21 +2841,21 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(termVector.get(2).doubleValue(), 0.0, 0.0);assertEquals(termVector.get(3).doubleValue(), 0.0, 0.0);- rowLabels = (List<String>)tuples.get(0).get("c");+ rowLabels = (List<String>) tuples.get(0).get("c");assertEquals(rowLabels.size(), 4);assertEquals(rowLabels.get(0), "1");assertEquals(rowLabels.get(1), "2");assertEquals(rowLabels.get(2), "3");assertEquals(rowLabels.get(3), "4");- columnLabels = (List<String>)tuples.get(0).get("d");+ columnLabels = (List<String>) tuples.get(0).get("d");assertEquals(columnLabels.size(), 4);assertEquals(columnLabels.get(0), "hello");assertEquals(columnLabels.get(1), "jack");assertEquals(columnLabels.get(2), "steve");assertEquals(columnLabels.get(3), "world");- docFreqs = (Map<String, Number>)tuples.get(0).get("e");+ docFreqs = (Map<String, Number>) tuples.get(0).get("e");assertEquals(docFreqs.size(), 4);assertEquals(docFreqs.get("hello").intValue(), 4);@@ -2721,18 +2863,18 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(docFreqs.get("steve").intValue(), 1);assertEquals(docFreqs.get("world").intValue(), 1);+ // Test exclude. This should drop off the term jim- //Test exclude. This should drop off the term jim-- cexpr = "let(echo=true," +- " a=select(plist(tuple(id=\"1\", text=\"hello world\"), " +- " tuple(id=\"2\", text=\"hello steve\"), " +- " tuple(id=\"3\", text=\"hello jim jim\"), " +- " tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms)," +- " b=termVectors(a, exclude=jim, minDocFreq=0, maxDocFreq=1)," +- " c=getRowLabels(b)," +- " d=getColumnLabels(b)," +- " e=getAttribute(b, \"docFreqs\"))";+ cexpr =+ "let(echo=true,"+ + " a=select(plist(tuple(id=\"1\", text=\"hello world\"), "+ + " tuple(id=\"2\", text=\"hello steve\"), "+ + " tuple(id=\"3\", text=\"hello jim jim\"), "+ + " tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms),"+ + " b=termVectors(a, exclude=jim, minDocFreq=0, maxDocFreq=1),"+ + " c=getRowLabels(b),"+ + " d=getColumnLabels(b),"+ + " e=getAttribute(b, \"docFreqs\"))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -2742,7 +2884,7 @@ public class MathExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- termVectors = (List<List<Number>>)tuples.get(0).get("b");+ termVectors = (List<List<Number>>) tuples.get(0).get("b");assertEquals(termVectors.size(), 4);termVector = termVectors.get(0);assertEquals(termVector.size(), 4);@@ -2772,21 +2914,21 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(termVector.get(2).doubleValue(), 0.0, 0.0);assertEquals(termVector.get(3).doubleValue(), 0.0, 0.0);- rowLabels = (List<String>)tuples.get(0).get("c");+ rowLabels = (List<String>) tuples.get(0).get("c");assertEquals(rowLabels.size(), 4);assertEquals(rowLabels.get(0), "1");assertEquals(rowLabels.get(1), "2");assertEquals(rowLabels.get(2), "3");assertEquals(rowLabels.get(3), "4");- columnLabels = (List<String>)tuples.get(0).get("d");+ columnLabels = (List<String>) tuples.get(0).get("d");assertEquals(columnLabels.size(), 4);assertEquals(columnLabels.get(0), "hello");assertEquals(columnLabels.get(1), "jack");assertEquals(columnLabels.get(2), "steve");assertEquals(columnLabels.get(3), "world");- docFreqs = (Map<String, Number>)tuples.get(0).get("e");+ docFreqs = (Map<String, Number>) tuples.get(0).get("e");assertEquals(docFreqs.size(), 4);assertEquals(docFreqs.get("hello").intValue(), 4);@@ -2794,17 +2936,18 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(docFreqs.get("steve").intValue(), 1);assertEquals(docFreqs.get("world").intValue(), 1);- //Test minDocFreq attribute at .5. This should eliminate all but the term hello-- cexpr = "let(echo=true," +- "a=select(plist(tuple(id=\"1\", text=\"hello world\"), " +- "tuple(id=\"2\", text=\"hello steve\"), " +- "tuple(id=\"3\", text=\"hello jim jim\"), " +- "tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms)," +- " b=termVectors(a, minDocFreq=.5, maxDocFreq=1)," +- " c=getRowLabels(b)," +- " d=getColumnLabels(b)," +- " e=getAttribute(b, \"docFreqs\"))";+ // Test minDocFreq attribute at .5. This should eliminate all but the term hello++ cexpr =+ "let(echo=true,"+ + "a=select(plist(tuple(id=\"1\", text=\"hello world\"), "+ + "tuple(id=\"2\", text=\"hello steve\"), "+ + "tuple(id=\"3\", text=\"hello jim jim\"), "+ + "tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms),"+ + " b=termVectors(a, minDocFreq=.5, maxDocFreq=1),"+ + " c=getRowLabels(b),"+ + " d=getColumnLabels(b),"+ + " e=getAttribute(b, \"docFreqs\"))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");@@ -2813,7 +2956,7 @@ public class MathExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- termVectors = (List<List<Number>>)tuples.get(0).get("b");+ termVectors = (List<List<Number>>) tuples.get(0).get("b");assertEquals(termVectors.size(), 4);termVector = termVectors.get(0);@@ -2832,33 +2975,34 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(termVector.size(), 1);assertEquals(termVector.get(0).doubleValue(), 1.0, 0.0);- rowLabels = (List<String>)tuples.get(0).get("c");+ rowLabels = (List<String>) tuples.get(0).get("c");assertEquals(rowLabels.size(), 4);assertEquals(rowLabels.get(0), "1");assertEquals(rowLabels.get(1), "2");assertEquals(rowLabels.get(2), "3");assertEquals(rowLabels.get(3), "4");- columnLabels = (List<String>)tuples.get(0).get("d");+ columnLabels = (List<String>) tuples.get(0).get("d");assertEquals(columnLabels.size(), 1);assertEquals(columnLabels.get(0), "hello");- docFreqs = (Map<String, Number>)tuples.get(0).get("e");+ docFreqs = (Map<String, Number>) tuples.get(0).get("e");assertEquals(docFreqs.size(), 1);assertEquals(docFreqs.get("hello").intValue(), 4);- //Test maxDocFreq attribute at 0. This should eliminate all terms-- cexpr = "let(echo=true," +- "a=select(plist(tuple(id=\"1\", text=\"hello world\"), " +- "tuple(id=\"2\", text=\"hello steve\"), " +- "tuple(id=\"3\", text=\"hello jim jim\"), " +- "tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms)," +- " b=termVectors(a, maxDocFreq=0)," +- " c=getRowLabels(b)," +- " d=getColumnLabels(b)," +- " e=getAttribute(b, \"docFreqs\"))";+ // Test maxDocFreq attribute at 0. This should eliminate all terms++ cexpr =+ "let(echo=true,"+ + "a=select(plist(tuple(id=\"1\", text=\"hello world\"), "+ + "tuple(id=\"2\", text=\"hello steve\"), "+ + "tuple(id=\"3\", text=\"hello jim jim\"), "+ + "tuple(id=\"4\", text=\"hello jack\")), id, analyze(text, test_t) as terms),"+ + " b=termVectors(a, maxDocFreq=0),"+ + " c=getRowLabels(b),"+ + " d=getColumnLabels(b),"+ + " e=getAttribute(b, \"docFreqs\"))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");@@ -2867,53 +3011,55 @@ public class MathExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- termVectors = (List<List<Number>>)tuples.get(0).get("b");+ termVectors = (List<List<Number>>) tuples.get(0).get("b");assertEquals(termVectors.size(), 4);assertEquals(termVectors.get(0).size(), 0);}@Testpublic void testPivot() throws Exception {- String cexpr = "let(echo=true," +- " a=list(tuple(fx=x1, fy=f1, fv=add(1,1)), " +- " tuple(fx=x1, fy=f2, fv=add(1,3)), " +- " tuple(fx=x2, fy=f1, fv=add(1,7)), " +- " tuple(fx=x3, fy=f1, fv=add(1,4))," +- " tuple(fx=x3, fy=f3, fv=add(1,7)))," +- " b=pivot(a, \"fx\", \"fy\", \"fv\")," +- " c=getRowLabels(b)," +- " d=getColumnLabels(b))";+ String cexpr =+ "let(echo=true,"+ + " a=list(tuple(fx=x1, fy=f1, fv=add(1,1)), "+ + " tuple(fx=x1, fy=f2, fv=add(1,3)), "+ + " tuple(fx=x2, fy=f1, fv=add(1,7)), "+ + " tuple(fx=x3, fy=f1, fv=add(1,4)),"+ + " tuple(fx=x3, fy=f3, fv=add(1,7))),"+ + " b=pivot(a, \"fx\", \"fy\", \"fv\"),"+ + " c=getRowLabels(b),"+ + " d=getColumnLabels(b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertEquals(tuples.size(), 1);@SuppressWarnings({"unchecked"})- List<List<Number>> matrix = (List<List<Number>>)tuples.get(0).get("b");+ List<List<Number>> matrix = (List<List<Number>>) tuples.get(0).get("b");List<Number> row1 = matrix.get(0);- assertEquals(row1.get(0).doubleValue(), 2.0,0);- assertEquals(row1.get(1).doubleValue(), 4.0,0);- assertEquals(row1.get(2).doubleValue(), 0,0);+ assertEquals(row1.get(0).doubleValue(), 2.0, 0);+ assertEquals(row1.get(1).doubleValue(), 4.0, 0);+ assertEquals(row1.get(2).doubleValue(), 0, 0);List<Number> row2 = matrix.get(1);- assertEquals(row2.get(0).doubleValue(), 8.0,0);- assertEquals(row2.get(1).doubleValue(), 0,0);- assertEquals(row2.get(2).doubleValue(), 0,0);+ assertEquals(row2.get(0).doubleValue(), 8.0, 0);+ assertEquals(row2.get(1).doubleValue(), 0, 0);+ assertEquals(row2.get(2).doubleValue(), 0, 0);List<Number> row3 = matrix.get(2);- assertEquals(row3.get(0).doubleValue(), 5.0,0);- assertEquals(row3.get(1).doubleValue(), 0,0);- assertEquals(row3.get(2).doubleValue(), 8.0,0);+ assertEquals(row3.get(0).doubleValue(), 5.0, 0);+ assertEquals(row3.get(1).doubleValue(), 0, 0);+ assertEquals(row3.get(2).doubleValue(), 8.0, 0);@SuppressWarnings({"unchecked"})- List<String> rowLabels = (List<String>)tuples.get(0).get("c");+ List<String> rowLabels = (List<String>) tuples.get(0).get("c");assertEquals(rowLabels.get(0), "x1");assertEquals(rowLabels.get(1), "x2");assertEquals(rowLabels.get(2), "x3");@SuppressWarnings({"unchecked"})- List<String> columnLabels = (List<String>)tuples.get(0).get("d");+ List<String> columnLabels = (List<String>) tuples.get(0).get("d");assertEquals(columnLabels.get(0), "f1");assertEquals(columnLabels.get(1), "f2");assertEquals(columnLabels.get(2), "f3");@@ -2921,26 +3067,28 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testEbeSubtract() throws Exception {- String cexpr = "let(echo=true," +- " a=array(2, 4, 6, 8, 10, 12)," +- " b=array(1, 2, 3, 4, 5, 6)," +- " c=ebeSubtract(a,b)," +- " d=array(10, 11, 12, 13, 14, 15)," +- " e=array(100, 200, 300, 400, 500, 600)," +- " f=matrix(a, b)," +- " g=matrix(d, e)," +- " h=ebeSubtract(f, g))";+ String cexpr =+ "let(echo=true,"+ + " a=array(2, 4, 6, 8, 10, 12),"+ + " b=array(1, 2, 3, 4, 5, 6),"+ + " c=ebeSubtract(a,b),"+ + " d=array(10, 11, 12, 13, 14, 15),"+ + " e=array(100, 200, 300, 400, 500, 600),"+ + " f=matrix(a, b),"+ + " g=matrix(d, e),"+ + " h=ebeSubtract(f, g))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("c");+ List<Number> out = (List<Number>) tuples.get(0).get("c");assertEquals(out.size(), 6);assertEquals(out.get(0).doubleValue(), 1.0, 0.0);assertEquals(out.get(1).doubleValue(), 2.0, 0.0);@@ -2950,7 +3098,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(out.get(5).doubleValue(), 6.0, 0.0);@SuppressWarnings({"unchecked"})- List<List<Number>> mout = (List<List<Number>>)tuples.get(0).get("h");+ List<List<Number>> mout = (List<List<Number>>) tuples.get(0).get("h");assertEquals(mout.size(), 2);List<Number> row1 = mout.get(0);assertEquals(row1.size(), 6);@@ -2974,39 +3122,41 @@ public class MathExpressionTest extends SolrCloudTestCase {@Test@SuppressWarnings({"unchecked"})public void testMatrixMult() throws Exception {- String cexpr = "let(echo=true," +- " a=array(1,2,3)," +- " b=matrix(array(4), array(5), array(6))," +- " c=matrixMult(a, b)," +- " d=matrix(array(3, 4), array(10,11), array(30, 40))," +- " e=matrixMult(a, d)," +- " f=array(4,8,10)," +- " g=matrix(a, f)," +- " h=matrixMult(d, g)," +- " i=matrixMult(b, a))";+ String cexpr =+ "let(echo=true,"+ + " a=array(1,2,3),"+ + " b=matrix(array(4), array(5), array(6)),"+ + " c=matrixMult(a, b),"+ + " d=matrix(array(3, 4), array(10,11), array(30, 40)),"+ + " e=matrixMult(a, d),"+ + " f=array(4,8,10),"+ + " g=matrix(a, f),"+ + " h=matrixMult(d, g),"+ + " i=matrixMult(b, a))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<List<Number>> matrix = (List<List<Number>>)tuples.get(0).get("c");+ List<List<Number>> matrix = (List<List<Number>>) tuples.get(0).get("c");assertEquals(matrix.size(), 1);List<Number> row = matrix.get(0);assertEquals(row.size(), 1);assertEquals(row.get(0).doubleValue(), 32.0, 0.0);- matrix = (List<List<Number>>)tuples.get(0).get("e");+ matrix = (List<List<Number>>) tuples.get(0).get("e");assertEquals(matrix.size(), 1);row = matrix.get(0);assertEquals(row.size(), 2);assertEquals(row.get(0).doubleValue(), 113.0, 0.0);assertEquals(row.get(1).doubleValue(), 146.0, 0.0);- matrix = (List<List<Number>>)tuples.get(0).get("h");+ matrix = (List<List<Number>>) tuples.get(0).get("h");assertEquals(matrix.size(), 3);row = matrix.get(0);assertEquals(row.size(), 3);@@ -3026,7 +3176,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row.get(1).doubleValue(), 380.0, 0.0);assertEquals(row.get(2).doubleValue(), 490.0, 0.0);- matrix = (List<List<Number>>)tuples.get(0).get("i");+ matrix = (List<List<Number>>) tuples.get(0).get("i");assertEquals(matrix.size(), 3);row = matrix.get(0);@@ -3048,63 +3198,64 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row.get(2).doubleValue(), 18.0, 0.0);}---@Testpublic void testKmeans() throws Exception {- String cexpr = "let(echo=true," +- " a=array(1,1,1,0,0,0)," +- " b=array(1,1,1,0,0,0)," +- " c=array(0,0,0,1,1,1)," +- " d=array(0,0,0,1,1,1)," +- " e=setRowLabels(matrix(a,b,c,d), " +- " array(\"doc1\", \"doc2\", \"doc3\", \"doc4\"))," +- " f=kmeans(e, 2)," +- " g=getCluster(f, 0)," +- " h=getCluster(f, 1)," +- " i=getCentroids(f)," +- " j=getRowLabels(g)," +- " k=getRowLabels(h))";+ String cexpr =+ "let(echo=true,"+ + " a=array(1,1,1,0,0,0),"+ + " b=array(1,1,1,0,0,0),"+ + " c=array(0,0,0,1,1,1),"+ + " d=array(0,0,0,1,1,1),"+ + " e=setRowLabels(matrix(a,b,c,d), "+ + " array(\"doc1\", \"doc2\", \"doc3\", \"doc4\")),"+ + " f=kmeans(e, 2),"+ + " g=getCluster(f, 0),"+ + " h=getCluster(f, 1),"+ + " i=getCentroids(f),"+ + " j=getRowLabels(g),"+ + " k=getRowLabels(h))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> cluster1 = (List<List<Number>>)tuples.get(0).get("g");+ List<List<Number>> cluster1 = (List<List<Number>>) tuples.get(0).get("g");@SuppressWarnings({"unchecked"})- List<List<Number>> cluster2 = (List<List<Number>>)tuples.get(0).get("h");+ List<List<Number>> cluster2 = (List<List<Number>>) tuples.get(0).get("h");@SuppressWarnings({"unchecked"})- List<List<Number>> centroids = (List<List<Number>>)tuples.get(0).get("i");+ List<List<Number>> centroids = (List<List<Number>>) tuples.get(0).get("i");@SuppressWarnings({"unchecked"})- List<String> labels1 = (List<String>)tuples.get(0).get("j");+ List<String> labels1 = (List<String>) tuples.get(0).get("j");@SuppressWarnings({"unchecked"})- List<String> labels2 = (List<String>)tuples.get(0).get("k");+ List<String> labels2 = (List<String>) tuples.get(0).get("k");assertEquals(cluster1.size(), 2);assertEquals(cluster2.size(), 2);assertEquals(centroids.size(), 2);- //Assert that the docs are not in both clusters+ // Assert that the docs are not in both clustersassertTrue(!(labels1.contains("doc1") && labels2.contains("doc1")));assertTrue(!(labels1.contains("doc2") && labels2.contains("doc2")));assertTrue(!(labels1.contains("doc3") && labels2.contains("doc3")));assertTrue(!(labels1.contains("doc4") && labels2.contains("doc4")));- //Assert that (doc1 and doc2) or (doc3 and doc4) are in labels1- assertTrue((labels1.contains("doc1") && labels1.contains("doc2")) ||- ((labels1.contains("doc3") && labels1.contains("doc4"))));+ // Assert that (doc1 and doc2) or (doc3 and doc4) are in labels1+ assertTrue(+ (labels1.contains("doc1") && labels1.contains("doc2"))+ || ((labels1.contains("doc3") && labels1.contains("doc4"))));- //Assert that (doc1 and doc2) or (doc3 and doc4) are in labels2- assertTrue((labels2.contains("doc1") && labels2.contains("doc2")) ||- ((labels2.contains("doc3") && labels2.contains("doc4"))));+ // Assert that (doc1 and doc2) or (doc3 and doc4) are in labels2+ assertTrue(+ (labels2.contains("doc1") && labels2.contains("doc2"))+ || ((labels2.contains("doc3") && labels2.contains("doc4"))));- if(labels1.contains("doc1")) {+ if (labels1.contains("doc1")) {assertEquals(centroids.get(0).get(0).doubleValue(), 1.0, 0.0);assertEquals(centroids.get(0).get(1).doubleValue(), 1.0, 0.0);assertEquals(centroids.get(0).get(2).doubleValue(), 1.0, 0.0);@@ -3135,19 +3286,19 @@ public class MathExpressionTest extends SolrCloudTestCase {}}--@Testpublic void testDbscanBasic() throws Exception {- String cexpr = "let(echo=true," +- " a=array(5,4,5,1,1,1)," +- " b=array(5,5,5,1,2,1)," +- " f=dbscan(transpose(matrix(a,b)), 2, 2)," +- " zplot(clusters=f))";+ String cexpr =+ "let(echo=true,"+ + " a=array(5,4,5,1,1,1),"+ + " b=array(5,5,5,1,2,1),"+ + " f=dbscan(transpose(matrix(a,b)), 2, 2),"+ + " zplot(clusters=f))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -3171,15 +3322,17 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testDbscanDistance() throws Exception {- String cexpr = "let(echo=true," +- " a=array(5,4,5,1,1,1)," +- " b=array(5,5,5,1,2,1)," +- " f=dbscan(transpose(matrix(a,b)), 500000, 2, haversineMeters())," +- " zplot(clusters=f))";+ String cexpr =+ "let(echo=true,"+ + " a=array(5,4,5,1,1,1),"+ + " b=array(5,5,5,1,2,1),"+ + " f=dbscan(transpose(matrix(a,b)), 500000, 2, haversineMeters()),"+ + " zplot(clusters=f))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -3203,15 +3356,17 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testDbscanNoClusters() throws Exception {- String cexpr = "let(echo=true," +- " a=array(5,4,5,1,1,1)," +- " b=array(5,5,5,1,2,1)," +- " f=dbscan(transpose(matrix(a,b)), 5000, 2, haversineMeters())," +- " zplot(clusters=f))";+ String cexpr =+ "let(echo=true,"+ + " a=array(5,4,5,1,1,1),"+ + " b=array(5,5,5,1,2,1),"+ + " f=dbscan(transpose(matrix(a,b)), 5000, 2, haversineMeters()),"+ + " zplot(clusters=f))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -3221,58 +3376,62 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testMultiKmeans() throws Exception {- String cexpr = "let(echo=true," +- " a=array(1,1,1,0,0,0)," +- " b=array(1,1,1,0,0,0)," +- " c=array(0,0,0,1,1,1)," +- " d=array(0,0,0,1,1,1)," +- " e=setRowLabels(matrix(a,b,c,d), " +- " array(\"doc1\", \"doc2\", \"doc3\", \"doc4\"))," +- " f=multiKmeans(e, 2, 5)," +- " g=getCluster(f, 0)," +- " h=getCluster(f, 1)," +- " i=getCentroids(f)," +- " j=getRowLabels(g)," +- " k=getRowLabels(h))";+ String cexpr =+ "let(echo=true,"+ + " a=array(1,1,1,0,0,0),"+ + " b=array(1,1,1,0,0,0),"+ + " c=array(0,0,0,1,1,1),"+ + " d=array(0,0,0,1,1,1),"+ + " e=setRowLabels(matrix(a,b,c,d), "+ + " array(\"doc1\", \"doc2\", \"doc3\", \"doc4\")),"+ + " f=multiKmeans(e, 2, 5),"+ + " g=getCluster(f, 0),"+ + " h=getCluster(f, 1),"+ + " i=getCentroids(f),"+ + " j=getRowLabels(g),"+ + " k=getRowLabels(h))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> cluster1 = (List<List<Number>>)tuples.get(0).get("g");+ List<List<Number>> cluster1 = (List<List<Number>>) tuples.get(0).get("g");@SuppressWarnings({"unchecked"})- List<List<Number>> cluster2 = (List<List<Number>>)tuples.get(0).get("h");+ List<List<Number>> cluster2 = (List<List<Number>>) tuples.get(0).get("h");@SuppressWarnings({"unchecked"})- List<List<Number>> centroids = (List<List<Number>>)tuples.get(0).get("i");+ List<List<Number>> centroids = (List<List<Number>>) tuples.get(0).get("i");@SuppressWarnings({"unchecked"})- List<String> labels1 = (List<String>)tuples.get(0).get("j");+ List<String> labels1 = (List<String>) tuples.get(0).get("j");@SuppressWarnings({"unchecked"})- List<String> labels2 = (List<String>)tuples.get(0).get("k");+ List<String> labels2 = (List<String>) tuples.get(0).get("k");assertEquals(cluster1.size(), 2);assertEquals(cluster2.size(), 2);assertEquals(centroids.size(), 2);- //Assert that the docs are not in both clusters+ // Assert that the docs are not in both clustersassertTrue(!(labels1.contains("doc1") && labels2.contains("doc1")));assertTrue(!(labels1.contains("doc2") && labels2.contains("doc2")));assertTrue(!(labels1.contains("doc3") && labels2.contains("doc3")));assertTrue(!(labels1.contains("doc4") && labels2.contains("doc4")));- //Assert that (doc1 and doc2) or (doc3 and doc4) are in labels1- assertTrue((labels1.contains("doc1") && labels1.contains("doc2")) ||- ((labels1.contains("doc3") && labels1.contains("doc4"))));+ // Assert that (doc1 and doc2) or (doc3 and doc4) are in labels1+ assertTrue(+ (labels1.contains("doc1") && labels1.contains("doc2"))+ || ((labels1.contains("doc3") && labels1.contains("doc4"))));- //Assert that (doc1 and doc2) or (doc3 and doc4) are in labels2- assertTrue((labels2.contains("doc1") && labels2.contains("doc2")) ||- ((labels2.contains("doc3") && labels2.contains("doc4"))));+ // Assert that (doc1 and doc2) or (doc3 and doc4) are in labels2+ assertTrue(+ (labels2.contains("doc1") && labels2.contains("doc2"))+ || ((labels2.contains("doc3") && labels2.contains("doc4"))));- if(labels1.contains("doc1")) {+ if (labels1.contains("doc1")) {assertEquals(centroids.get(0).get(0).doubleValue(), 1.0, 0.0);assertEquals(centroids.get(0).get(1).doubleValue(), 1.0, 0.0);assertEquals(centroids.get(0).get(2).doubleValue(), 1.0, 0.0);@@ -3305,63 +3464,66 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testFuzzyKmeans() throws Exception {- String cexpr = "let(echo=true," +- " a=array(1,1,1,0,0,0)," +- " b=array(1,1,1,0,0,0)," +- " c=array(0,0,0,1,1,1)," +- " d=array(0,0,0,1,1,1)," +- " e=setRowLabels(matrix(a,b,c,d), " +- " array(\"doc1\", \"doc2\", \"doc3\", \"doc4\"))," +- " f=fuzzyKmeans(e, 2)," +- " g=getCluster(f, 0)," +- " h=getCluster(f, 1)," +- " i=getCentroids(f)," +- " j=getRowLabels(g)," +- " k=getRowLabels(h)," +- " l=getMembershipMatrix(f))";+ String cexpr =+ "let(echo=true,"+ + " a=array(1,1,1,0,0,0),"+ + " b=array(1,1,1,0,0,0),"+ + " c=array(0,0,0,1,1,1),"+ + " d=array(0,0,0,1,1,1),"+ + " e=setRowLabels(matrix(a,b,c,d), "+ + " array(\"doc1\", \"doc2\", \"doc3\", \"doc4\")),"+ + " f=fuzzyKmeans(e, 2),"+ + " g=getCluster(f, 0),"+ + " h=getCluster(f, 1),"+ + " i=getCentroids(f),"+ + " j=getRowLabels(g),"+ + " k=getRowLabels(h),"+ + " l=getMembershipMatrix(f))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> cluster1 = (List<List<Number>>)tuples.get(0).get("g");+ List<List<Number>> cluster1 = (List<List<Number>>) tuples.get(0).get("g");@SuppressWarnings({"unchecked"})- List<List<Number>> cluster2 = (List<List<Number>>)tuples.get(0).get("h");+ List<List<Number>> cluster2 = (List<List<Number>>) tuples.get(0).get("h");@SuppressWarnings({"unchecked"})- List<List<Number>> centroids = (List<List<Number>>)tuples.get(0).get("i");+ List<List<Number>> centroids = (List<List<Number>>) tuples.get(0).get("i");@SuppressWarnings({"unchecked"})- List<List<Number>> membership = (List<List<Number>>)tuples.get(0).get("l");+ List<List<Number>> membership = (List<List<Number>>) tuples.get(0).get("l");@SuppressWarnings({"unchecked"})- List<String> labels1 = (List<String>)tuples.get(0).get("j");+ List<String> labels1 = (List<String>) tuples.get(0).get("j");@SuppressWarnings({"unchecked"})- List<String> labels2 = (List<String>)tuples.get(0).get("k");+ List<String> labels2 = (List<String>) tuples.get(0).get("k");assertEquals(cluster1.size(), 2);assertEquals(cluster2.size(), 2);assertEquals(centroids.size(), 2);- //Assert that the docs are not in both clusters+ // Assert that the docs are not in both clustersassertTrue(!(labels1.contains("doc1") && labels2.contains("doc1")));assertTrue(!(labels1.contains("doc2") && labels2.contains("doc2")));assertTrue(!(labels1.contains("doc3") && labels2.contains("doc3")));assertTrue(!(labels1.contains("doc4") && labels2.contains("doc4")));- //Assert that (doc1 and doc2) or (doc3 and doc4) are in labels1- assertTrue((labels1.contains("doc1") && labels1.contains("doc2")) ||- ((labels1.contains("doc3") && labels1.contains("doc4"))));+ // Assert that (doc1 and doc2) or (doc3 and doc4) are in labels1+ assertTrue(+ (labels1.contains("doc1") && labels1.contains("doc2"))+ || ((labels1.contains("doc3") && labels1.contains("doc4"))));- //Assert that (doc1 and doc2) or (doc3 and doc4) are in labels2- assertTrue((labels2.contains("doc1") && labels2.contains("doc2")) ||- ((labels2.contains("doc3") && labels2.contains("doc4"))));+ // Assert that (doc1 and doc2) or (doc3 and doc4) are in labels2+ assertTrue(+ (labels2.contains("doc1") && labels2.contains("doc2"))+ || ((labels2.contains("doc3") && labels2.contains("doc4"))));-- if(labels1.contains("doc1")) {+ if (labels1.contains("doc1")) {assertEquals(centroids.get(0).get(0).doubleValue(), 1.0, 0.001);assertEquals(centroids.get(0).get(1).doubleValue(), 1.0, 0.001);assertEquals(centroids.get(0).get(2).doubleValue(), 1.0, 0.001);@@ -3376,7 +3538,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(centroids.get(1).get(4).doubleValue(), 1.0, 0.001);assertEquals(centroids.get(1).get(5).doubleValue(), 1.0, 0.001);- //Assert the membership matrix+ // Assert the membership matrixassertEquals(membership.get(0).get(0).doubleValue(), 1.0, 0.001);assertEquals(membership.get(0).get(1).doubleValue(), 0.0, 0.001);assertEquals(membership.get(1).get(0).doubleValue(), 1.0, 0.001);@@ -3401,7 +3563,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(centroids.get(1).get(4).doubleValue(), 0.0, 0.001);assertEquals(centroids.get(1).get(5).doubleValue(), 0.0, 0.001);- //Assert the membership matrix+ // Assert the membership matrixassertEquals(membership.get(0).get(0).doubleValue(), 0.0, 0.001);assertEquals(membership.get(0).get(1).doubleValue(), 1.0, 0.001);assertEquals(membership.get(1).get(0).doubleValue(), 0.0, 0.001);@@ -3419,14 +3581,15 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 6);assertTrue(out.get(0).intValue() == 2);assertTrue(out.get(1).intValue() == 8);@@ -3438,47 +3601,49 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testOscillate() throws Exception {- String cexpr = "let(echo=true," +- " a=oscillate(10, .3, 2.9)," +- " b=describe(a)," +- " c=getValue(b, \"min\")," +- " d=getValue(b, \"max\")," +- " e=harmfit(a)," +- " f=getAmplitude(e)," +- " g=getAngularFrequency(e)," +- " h=getPhase(e)," +- " i=derivative(a))";+ String cexpr =+ "let(echo=true,"+ + " a=oscillate(10, .3, 2.9),"+ + " b=describe(a),"+ + " c=getValue(b, \"min\"),"+ + " d=getValue(b, \"max\"),"+ + " e=harmfit(a),"+ + " f=getAmplitude(e),"+ + " g=getAngularFrequency(e),"+ + " h=getPhase(e),"+ + " i=derivative(a))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> wave = (List<Number>)tuples.get(0).get("a");+ List<Number> wave = (List<Number>) tuples.get(0).get("a");assertEquals(wave.size(), 128);- Number min = (Number)tuples.get(0).get("c");- Number max = (Number)tuples.get(0).get("d");+ Number min = (Number) tuples.get(0).get("c");+ Number max = (Number) tuples.get(0).get("d");assertEquals(min.doubleValue(), -9.9, .1);assertEquals(max.doubleValue(), 9.9, .1);@SuppressWarnings({"unchecked"})- List<Number> wave1 = (List<Number>)tuples.get(0).get("e");+ List<Number> wave1 = (List<Number>) tuples.get(0).get("e");assertEquals(wave1.size(), 128);- Number amp = (Number)tuples.get(0).get("f");- Number freq = (Number)tuples.get(0).get("g");- Number pha = (Number)tuples.get(0).get("h");+ Number amp = (Number) tuples.get(0).get("f");+ Number freq = (Number) tuples.get(0).get("g");+ Number pha = (Number) tuples.get(0).get("h");assertEquals(amp.doubleValue(), 10, .1);assertEquals(freq.doubleValue(), .3, .1);assertEquals(pha.doubleValue(), 2.9, .1);@SuppressWarnings({"unchecked"})- List<Number> der = (List<Number>)tuples.get(0).get("i");+ List<Number> der = (List<Number>) tuples.get(0).get("i");assertEquals(der.size(), 128);assertEquals(der.get(0).doubleValue(), -0.7177479876419472, 0);assertEquals(der.get(127).doubleValue(), 0.47586800641412696, 0);@@ -3486,26 +3651,28 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testEbeAdd() throws Exception {- String cexpr = "let(echo=true," +- " a=array(2, 4, 6, 8, 10, 12)," +- " b=array(1, 2, 3, 4, 5, 6)," +- " c=ebeAdd(a,b)," +- " d=array(10, 11, 12, 13, 14, 15)," +- " e=array(100, 200, 300, 400, 500, 600)," +- " f=matrix(a, b)," +- " g=matrix(d, e)," +- " h=ebeAdd(f, g))";+ String cexpr =+ "let(echo=true,"+ + " a=array(2, 4, 6, 8, 10, 12),"+ + " b=array(1, 2, 3, 4, 5, 6),"+ + " c=ebeAdd(a,b),"+ + " d=array(10, 11, 12, 13, 14, 15),"+ + " e=array(100, 200, 300, 400, 500, 600),"+ + " f=matrix(a, b),"+ + " g=matrix(d, e),"+ + " h=ebeAdd(f, g))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("c");+ List<Number> out = (List<Number>) tuples.get(0).get("c");assertEquals(out.size(), 6);assertEquals(out.get(0).doubleValue(), 3.0, 0.0);assertEquals(out.get(1).doubleValue(), 6.0, 0.0);@@ -3515,7 +3682,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(out.get(5).doubleValue(), 18.0, 0.0);@SuppressWarnings({"unchecked"})- List<List<Number>> mout = (List<List<Number>>)tuples.get(0).get("h");+ List<List<Number>> mout = (List<List<Number>>) tuples.get(0).get("h");assertEquals(mout.size(), 2);List<Number> row1 = mout.get(0);assertEquals(row1.size(), 6);@@ -3536,53 +3703,53 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(row2.get(5).doubleValue(), 606.0, 0.0);}--@Testpublic void testSetAndGetValue() throws Exception {- String cexpr = "let(echo=true," +- " a=describe(array(1,2,3,4,5,6,7))," +- " b=getValue(a, \"geometricMean\")," +- " c=setValue(a, \"test\", add(b, 1))," +- " d=getValue(c, \"test\")," +- " e=setValue(c, \"blah\", array(8.11,9.55,10.1))," +- " f=getValue(e, \"blah\"))";+ String cexpr =+ "let(echo=true,"+ + " a=describe(array(1,2,3,4,5,6,7)),"+ + " b=getValue(a, \"geometricMean\"),"+ + " c=setValue(a, \"test\", add(b, 1)),"+ + " d=getValue(c, \"test\"),"+ + " e=setValue(c, \"blah\", array(8.11,9.55,10.1)),"+ + " f=getValue(e, \"blah\"))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number mean = (Number)tuples.get(0).get("b");+ Number mean = (Number) tuples.get(0).get("b");assertEquals(mean.doubleValue(), 3.3800151591412964, 0.0);- Number mean1 = (Number)tuples.get(0).get("d");+ Number mean1 = (Number) tuples.get(0).get("d");assertEquals(mean1.doubleValue(), 4.3800151591412964, 0.0);@SuppressWarnings({"unchecked"})- List<Number> vals = (List<Number>)tuples.get(0).get("f");+ List<Number> vals = (List<Number>) tuples.get(0).get("f");assertEquals(vals.size(), 3);assertEquals(vals.get(0).doubleValue(), 8.11, 0);assertEquals(vals.get(1).doubleValue(), 9.55, 0);assertEquals(vals.get(2).doubleValue(), 10.1, 0);}-@Testpublic void testEbeDivide() throws Exception {String cexpr = "ebeDivide(array(2,4,6,8,10,12),array(1,2,3,4,5,6))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 6);assertTrue(out.get(0).intValue() == 2);assertTrue(out.get(1).intValue() == 2);@@ -3598,7 +3765,8 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -3631,13 +3799,15 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testFFT() throws Exception {- String cexpr = "let(echo=true," +- " a=fft(array(1, 4, 8, 4, 1, 4, 8, 4, 1, 4, 8, 4, 1, 4, 8, 4))," +- " b=ifft(a))";+ String cexpr =+ "let(echo=true,"+ + " a=fft(array(1, 4, 8, 4, 1, 4, 8, 4, 1, 4, 8, 4, 1, 4, 8, 4)),"+ + " b=ifft(a))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -3645,7 +3815,7 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(tuples.size(), 1);@SuppressWarnings({"unchecked"})- List<List<Number>> fft = (List<List<Number>>)tuples.get(0).get("a");+ List<List<Number>> fft = (List<List<Number>>) tuples.get(0).get("a");assertEquals(fft.size(), 2);List<Number> reals = fft.get(0);assertEquals(reals.get(0).doubleValue(), 68, 0.0);@@ -3666,12 +3836,12 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(reals.get(15).doubleValue(), 0, 0.0);List<Number> imaginary = fft.get(1);- for(int i=0; i<imaginary.size(); i++) {+ for (int i = 0; i < imaginary.size(); i++) {assertEquals(imaginary.get(i).doubleValue(), 0.0, 0.0);}@SuppressWarnings({"unchecked"})- List<Number> ifft = (List<Number>)tuples.get(0).get("b");+ List<Number> ifft = (List<Number>) tuples.get(0).get("b");assertEquals(ifft.get(0).doubleValue(), 1, 0.0);assertEquals(ifft.get(1).doubleValue(), 4, 0.0);assertEquals(ifft.get(2).doubleValue(), 8, 0.0);@@ -3696,25 +3866,28 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number cs = (Number)tuples.get(0).get("return-value");- assertEquals(cs.doubleValue(),0.9838197164968291, .00000001);+ Number cs = (Number) tuples.get(0).get("return-value");+ assertEquals(cs.doubleValue(), 0.9838197164968291, .00000001);}@Testpublic void testCosineSimilaritySort() throws Exception {- String cexpr = "sort(select(list(tuple(id=\"1\", f=array(1,2,3,4)), tuple(id=\"2\",f=array(10,2,3,4)))," +- " cosineSimilarity(f, array(1,2,3,4)) as sim, id)," +- " by=\"sim desc\")";+ String cexpr =+ "sort(select(list(tuple(id=\"1\", f=array(1,2,3,4)), tuple(id=\"2\",f=array(10,2,3,4))),"+ + " cosineSimilarity(f, array(1,2,3,4)) as sim, id),"+ + " by=\"sim desc\")";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -3723,53 +3896,56 @@ public class MathExpressionTest extends SolrCloudTestCase {assertEquals(tuples.get(0).getString("id"), "1");}-@Testpublic void testPoissonDistribution() throws Exception {- String cexpr = "let(a=poissonDistribution(100)," +- " b=sample(a, 10000)," +- " tuple(d=describe(b), " +- " p=probability(a, 100), " +- " c=cumulativeProbability(a, 100)))";+ String cexpr =+ "let(a=poissonDistribution(100),"+ + " b=sample(a, 10000),"+ + " tuple(d=describe(b), "+ + " p=probability(a, 100), "+ + " c=cumulativeProbability(a, 100)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map map = (Map)tuples.get(0).get("d");- Number mean = (Number)map.get("mean");- Number var = (Number)map.get("var");- //The mean and variance should be almost the same for poisson distribution+ Map map = (Map) tuples.get(0).get("d");+ Number mean = (Number) map.get("mean");+ Number var = (Number) map.get("var");+ // The mean and variance should be almost the same for poisson distributionassertEquals(mean.doubleValue(), var.doubleValue(), 7.0);- Number prob = (Number)tuples.get(0).get("p");+ Number prob = (Number) tuples.get(0).get("p");assertEquals(prob.doubleValue(), 0.03986099680914713, 0.0);- Number cprob = (Number)tuples.get(0).get("c");+ Number cprob = (Number) tuples.get(0).get("c");assertEquals(cprob.doubleValue(), 0.5265621985303708, 0.0);}@Testpublic void testGeometricDistribution() throws Exception {- String cexpr = "let(a=geometricDistribution(.2)," +- " b=geometricDistribution(.5)," +- " c=geometricDistribution(.8)," +- " d=sample(a, 10000)," +- " e=sample(b, 10000)," +- " f=sample(c, 10000)," +- " g=freqTable(d)," +- " h=freqTable(e)," +- " i=freqTable(f)," +- " tuple(g=g, h=h, i=i))";+ String cexpr =+ "let(a=geometricDistribution(.2),"+ + " b=geometricDistribution(.5),"+ + " c=geometricDistribution(.8),"+ + " d=sample(a, 10000),"+ + " e=sample(b, 10000),"+ + " f=sample(c, 10000),"+ + " g=freqTable(d),"+ + " h=freqTable(e),"+ + " i=freqTable(f),"+ + " tuple(g=g, h=h, i=i))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -3777,74 +3953,78 @@ public class MathExpressionTest extends SolrCloudTestCase {assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked", "rawtypes"})- List<Map> listg = (List<Map>)tuples.get(0).get("g");+ List<Map> listg = (List<Map>) tuples.get(0).get("g");@SuppressWarnings({"rawtypes"})Map mapg = listg.get(0);double pctg = (double) mapg.get("pct");assertEquals(pctg, .2, .02);@SuppressWarnings({"unchecked", "rawtypes"})- List<Map> listh = (List<Map>)tuples.get(0).get("h");+ List<Map> listh = (List<Map>) tuples.get(0).get("h");@SuppressWarnings({"rawtypes"})Map maph = listh.get(0);- double pcth = (double)maph.get("pct");+ double pcth = (double) maph.get("pct");assertEquals(pcth, .5, .02);@SuppressWarnings({"unchecked", "rawtypes"})- List<Map> listi = (List<Map>)tuples.get(0).get("i");+ List<Map> listi = (List<Map>) tuples.get(0).get("i");@SuppressWarnings({"rawtypes"})Map mapi = listi.get(0);- double pcti = (double)mapi.get("pct");+ double pcti = (double) mapi.get("pct");assertEquals(pcti, .8, .02);}@Testpublic void testBinomialDistribution() throws Exception {- String cexpr = "let(a=binomialDistribution(100, .50)," +- " b=sample(a, 10000)," +- " tuple(d=describe(b), " +- " p=probability(a, 50), " +- " c=cumulativeProbability(a, 50)))";+ String cexpr =+ "let(a=binomialDistribution(100, .50),"+ + " b=sample(a, 10000),"+ + " tuple(d=describe(b), "+ + " p=probability(a, 50), "+ + " c=cumulativeProbability(a, 50)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number prob = (Number)tuples.get(0).get("p");- assertEquals(prob.doubleValue(),0.07958923738717877, 0.0);- Number cprob = (Number)tuples.get(0).get("c");+ Number prob = (Number) tuples.get(0).get("p");+ assertEquals(prob.doubleValue(), 0.07958923738717877, 0.0);+ Number cprob = (Number) tuples.get(0).get("c");assertEquals(cprob.doubleValue(), 0.5397946186935851, 0.0);}@Testpublic void testUniformIntegerDistribution() throws Exception {- String cexpr = "let(a=uniformIntegerDistribution(1, 10)," +- " b=sample(a, 10000)," +- " tuple(d=describe(b), " +- " p=probability(a, 5), " +- " c=cumulativeProbability(a, 5)))";+ String cexpr =+ "let(a=uniformIntegerDistribution(1, 10),"+ + " b=sample(a, 10000),"+ + " tuple(d=describe(b), "+ + " p=probability(a, 5), "+ + " c=cumulativeProbability(a, 5)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map map = (Map)tuples.get(0).get("d");- Number N = (Number)map.get("N");+ Map map = (Map) tuples.get(0).get("d");+ Number N = (Number) map.get("N");assertEquals(N.intValue(), 10000);- Number prob = (Number)tuples.get(0).get("p");+ Number prob = (Number) tuples.get(0).get("p");assertEquals(prob.doubleValue(), 0.1, 0.0);- Number cprob = (Number)tuples.get(0).get("c");+ Number cprob = (Number) tuples.get(0).get("c");assertEquals(cprob.doubleValue(), 0.5, 0.0);}@@ -3854,21 +4034,22 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> counts = (List<Number>)tuples.get(0).get("c");+ List<Number> counts = (List<Number>) tuples.get(0).get("c");assertTrue(counts.size() == 10);int lastCount = Integer.MAX_VALUE;- for(Number number : counts) {+ for (Number number : counts) {int current = number.intValue();- if(current > lastCount) {+ if (current > lastCount) {throw new Exception("Zipf distribution not descending!!!");} else {lastCount = current;@@ -3876,31 +4057,31 @@ public class MathExpressionTest extends SolrCloudTestCase {}}-@Testpublic void testValueAt() throws Exception {- String cexpr = "let(echo=true, " +- " b=array(1,2,3,4), " +- " c=matrix(array(5,6,7), " +- " array(8,9,10)), " +- " d=valueAt(b, 3)," +- " e=valueAt(c, 1, 0))";+ String cexpr =+ "let(echo=true, "+ + " b=array(1,2,3,4), "+ + " c=matrix(array(5,6,7), "+ + " array(8,9,10)), "+ + " d=valueAt(b, 3),"+ + " e=valueAt(c, 1, 0))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number value1 = (Number)tuples.get(0).get("d");- Number value2 = (Number)tuples.get(0).get("e");+ Number value1 = (Number) tuples.get(0).get("d");+ Number value2 = (Number) tuples.get(0).get("e");assertEquals(value1.intValue(), 4);assertEquals(value2.intValue(), 8);}-@Test@SuppressWarnings({"unchecked"})public void testBetaDistribution() throws Exception {@@ -3908,18 +4089,19 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<Number> counts = (List<Number>)tuples.get(0).get("c");+ List<Number> counts = (List<Number>) tuples.get(0).get("c");int lastCount = Integer.MAX_VALUE;- for(Number number : counts) {+ for (Number number : counts) {int current = number.intValue();- if(current > lastCount) {+ if (current > lastCount) {throw new Exception("This beta distribution should be descending");} else {lastCount = current;@@ -3935,12 +4117,12 @@ public class MathExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- counts = (List<Number>)tuples.get(0).get("c");+ counts = (List<Number>) tuples.get(0).get("c");lastCount = Integer.MIN_VALUE;- for(Number number : counts) {+ for (Number number : counts) {int current = number.intValue();- if(current < lastCount) {+ if (current < lastCount) {throw new Exception("This beta distribution should be ascending");} else {lastCount = current;@@ -3950,47 +4132,49 @@ public class MathExpressionTest extends SolrCloudTestCase {@Testpublic void testEnumeratedDistribution() throws Exception {- String cexpr = "let(a=uniformIntegerDistribution(1, 10)," +- " b=sample(a, 10000)," +- " c=enumeratedDistribution(b),"+- " tuple(d=describe(b), " +- " p=probability(c, 5), " +- " c=cumulativeProbability(c, 5)))";+ String cexpr =+ "let(a=uniformIntegerDistribution(1, 10),"+ + " b=sample(a, 10000),"+ + " c=enumeratedDistribution(b),"+ + " tuple(d=describe(b), "+ + " p=probability(c, 5), "+ + " c=cumulativeProbability(c, 5)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map map = (Map)tuples.get(0).get("d");- Number N = (Number)map.get("N");+ Map map = (Map) tuples.get(0).get("d");+ Number N = (Number) map.get("N");assertEquals(N.intValue(), 10000);- Number prob = (Number)tuples.get(0).get("p");+ Number prob = (Number) tuples.get(0).get("p");assertEquals(prob.doubleValue(), 0.1, 0.07);- Number cprob = (Number)tuples.get(0).get("c");+ Number cprob = (Number) tuples.get(0).get("c");assertEquals(cprob.doubleValue(), 0.5, 0.07);-- cexpr = "let(a=sample(enumeratedDistribution(array(1,2,3,4), array(40, 30, 20, 10)), 50000),"+- "b=freqTable(a),"+- "y=col(b, pct))";+ cexpr =+ "let(a=sample(enumeratedDistribution(array(1,2,3,4), array(40, 30, 20, 10)), 50000),"+ + "b=freqTable(a),"+ + "y=col(b, pct))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;solrStream = new SolrStream(url, paramsLoc);context = new StreamContext();solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> freqs = (List<Number>)tuples.get(0).get("y");+ List<Number> freqs = (List<Number>) tuples.get(0).get("y");assertEquals(freqs.get(0).doubleValue(), .40, .03);assertEquals(freqs.get(1).doubleValue(), .30, .03);assertEquals(freqs.get(2).doubleValue(), .20, .03);@@ -4003,13 +4187,14 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number dotProduct = (Number)tuples.get(0).get("return-value");+ Number dotProduct = (Number) tuples.get(0).get("return-value");assertTrue(dotProduct.doubleValue() == 182);}@@ -4019,15 +4204,16 @@ public class MathExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number variance = (Number)tuples.get(0).get("a");+ Number variance = (Number) tuples.get(0).get("a");assertTrue(variance.doubleValue() == 2.5);- Number stddev = (Number)tuples.get(0).get("b");+ Number stddev = (Number) tuples.get(0).get("b");assertTrue(stddev.doubleValue() == 0);}@@ -4036,8 +4222,9 @@ public class MathExpressionTest extends SolrCloudTestCase {// the stream is located@Test@SuppressWarnings({"unchecked"})-public void testCache() throws Exception {- String cexpr = "putCache(\"space1\", \"key1\", dotProduct(array(2,4,6,8,10,12),array(1,2,3,4,5,6)))";+ public void testCache() throws Exception {+ String cexpr =+ "putCache(\"space1\", \"key1\", dotProduct(array(2,4,6,8,10,12),array(1,2,3,4,5,6)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");@@ -4049,7 +4236,7 @@ public void testCache() throws Exception {String url = null;for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {if (jetty.getNodeName().equals(node)) {- url = jetty.getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ url = jetty.getBaseUrl().toString() + "/" + COLLECTIONORALIAS;break;}}@@ -4061,10 +4248,9 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number dotProduct = (Number)tuples.get(0).get("return-value");+ Number dotProduct = (Number) tuples.get(0).get("return-value");assertTrue(dotProduct.doubleValue() == 182);-cexpr = "getCache(\"space1\", \"key1\")";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -4074,7 +4260,7 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- dotProduct = (Number)tuples.get(0).get("return-value");+ dotProduct = (Number) tuples.get(0).get("return-value");assertTrue(dotProduct.doubleValue() == 182);cexpr = "listCache(\"space1\")";@@ -4086,7 +4272,7 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<String> keys = (List<String>)tuples.get(0).get("return-value");+ List<String> keys = (List<String>) tuples.get(0).get("return-value");assertEquals(keys.size(), 1);assertEquals(keys.get(0), "key1");@@ -4099,7 +4285,7 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- keys = (List<String>)tuples.get(0).get("return-value");+ keys = (List<String>) tuples.get(0).get("return-value");assertEquals(keys.size(), 1);assertEquals(keys.get(0), "space1");@@ -4112,10 +4298,9 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- dotProduct = (Number)tuples.get(0).get("return-value");+ dotProduct = (Number) tuples.get(0).get("return-value");assertTrue(dotProduct.doubleValue() == 182);-cexpr = "listCache(\"space1\")";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -4125,72 +4310,75 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- keys = (List<String>)tuples.get(0).get("return-value");+ keys = (List<String>) tuples.get(0).get("return-value");assertEquals(keys.size(), 0);}@Testpublic void testExponentialMovingAverage() throws Exception {- String cexpr = "expMovingAvg(array(22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29, " +- "22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63, 23.82, 23.87, 23.65, 23.19,"+- "23.10, 23.33, 22.68, 23.10, 22.40, 22.17), 10)";+ String cexpr =+ "expMovingAvg(array(22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29, "+ + "22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63, 23.82, 23.87, 23.65, 23.19,"+ + "23.10, 23.33, 22.68, 23.10, 22.40, 22.17), 10)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 21);assertEquals((double) out.get(0), 22.22, 0.009);assertEquals((double) out.get(1), 22.21, 0.009);- assertEquals((double)out.get(2), 22.24, 0.009);- assertEquals((double)out.get(3), 22.27, 0.009);- assertEquals((double)out.get(4), 22.33, 0.009);- assertEquals((double)out.get(5), 22.52, 0.009);- assertEquals((double)out.get(6), 22.80, 0.009);- assertEquals((double)out.get(7), 22.97, 0.009);- assertEquals((double)out.get(8), 23.13, 0.009);- assertEquals((double)out.get(9), 23.28, 0.009);- assertEquals((double)out.get(10), 23.34, 0.009);- assertEquals((double)out.get(11), 23.43, 0.009);- assertEquals((double)out.get(12), 23.51, 0.009);- assertEquals((double)out.get(13), 23.54, 0.009);- assertEquals((double)out.get(14), 23.47, 0.009);- assertEquals((double)out.get(15), 23.40, 0.009);- assertEquals((double)out.get(16), 23.39, 0.009);- assertEquals((double)out.get(17), 23.26, 0.009);- assertEquals((double)out.get(18), 23.23, 0.009);- assertEquals((double)out.get(19), 23.08, 0.009);- assertEquals((double)out.get(20), 22.92, 0.009);+ assertEquals((double) out.get(2), 22.24, 0.009);+ assertEquals((double) out.get(3), 22.27, 0.009);+ assertEquals((double) out.get(4), 22.33, 0.009);+ assertEquals((double) out.get(5), 22.52, 0.009);+ assertEquals((double) out.get(6), 22.80, 0.009);+ assertEquals((double) out.get(7), 22.97, 0.009);+ assertEquals((double) out.get(8), 23.13, 0.009);+ assertEquals((double) out.get(9), 23.28, 0.009);+ assertEquals((double) out.get(10), 23.34, 0.009);+ assertEquals((double) out.get(11), 23.43, 0.009);+ assertEquals((double) out.get(12), 23.51, 0.009);+ assertEquals((double) out.get(13), 23.54, 0.009);+ assertEquals((double) out.get(14), 23.47, 0.009);+ assertEquals((double) out.get(15), 23.40, 0.009);+ assertEquals((double) out.get(16), 23.39, 0.009);+ assertEquals((double) out.get(17), 23.26, 0.009);+ assertEquals((double) out.get(18), 23.23, 0.009);+ assertEquals((double) out.get(19), 23.08, 0.009);+ assertEquals((double) out.get(20), 22.92, 0.009);}-@Testpublic void testTimeDifferencingMatrix() throws Exception {- String cexpr = "let(echo=\"c, d\",\n" +- " a=matrix(array(1,2,3,4,5),array(7.5,9,11,15.5,50.2)),\n" +- " b=setColumnLabels(a, array(\"a\",\"b\",\"c\",\"d\",\"e\")),\n" +- " c=diff(b, 2),\n" +- " d=getColumnLabels(c))";+ String cexpr =+ "let(echo=\"c, d\",\n"+ + " a=matrix(array(1,2,3,4,5),array(7.5,9,11,15.5,50.2)),\n"+ + " b=setColumnLabels(a, array(\"a\",\"b\",\"c\",\"d\",\"e\")),\n"+ + " c=diff(b, 2),\n"+ + " d=getColumnLabels(c))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> matrix = (List<List<Number>>)tuples.get(0).get("c");+ List<List<Number>> matrix = (List<List<Number>>) tuples.get(0).get("c");@SuppressWarnings({"unchecked"})- List<String> columnsLabels = (List<String>)tuples.get(0).get("d");+ List<String> columnsLabels = (List<String>) tuples.get(0).get("d");assertEquals(columnsLabels.size(), 3);assertEquals(columnsLabels.get(0), "c");assertEquals(columnsLabels.get(1), "d");@@ -4202,7 +4390,7 @@ public void testCache() throws Exception {assertEquals(row1.get(0).doubleValue(), 2.0, 0);assertEquals(row1.get(1).doubleValue(), 2.0, 0);assertEquals(row1.get(2).doubleValue(), 2.0, 0);- assertEquals(row2.size(), 3 );+ assertEquals(row2.size(), 3);assertEquals(row2.get(0).doubleValue(), 3.5, 0);assertEquals(row2.get(1).doubleValue(), 6.5, 0);assertEquals(row2.get(2).doubleValue(), 39.2, 0);@@ -4210,79 +4398,85 @@ public void testCache() throws Exception {@Testpublic void testTimeDifferencingDefaultLag() throws Exception {- String cexpr = "diff(array(1709.0, 1621.0, 1973.0, 1812.0, 1975.0, 1862.0, 1940.0, 2013.0, 1596.0, 1725.0, 1676.0, 1814.0, 1615.0, 1557.0, 1891.0, 1956.0, 1885.0, 1623.0, 1903.0, 1997.0))";+ String cexpr =+ "diff(array(1709.0, 1621.0, 1973.0, 1812.0, 1975.0, 1862.0, 1940.0, 2013.0, 1596.0, 1725.0, 1676.0, 1814.0, 1615.0, 1557.0, 1891.0, 1956.0, 1885.0, 1623.0, 1903.0, 1997.0))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 19);- assertEquals(out.get(0).doubleValue(),-88.0, 0.01);- assertEquals(out.get(1).doubleValue(),352.0, 0.01);- assertEquals(out.get(2).doubleValue(),-161.0, 0.01);- assertEquals(out.get(3).doubleValue(),163.0, 0.01);- assertEquals(out.get(4).doubleValue(),-113.0, 0.01);- assertEquals(out.get(5).doubleValue(),78.0, 0.01);- assertEquals(out.get(6).doubleValue(),73.0, 0.01);- assertEquals(out.get(7).doubleValue(),-417.0, 0.01);- assertEquals(out.get(8).doubleValue(),129.0, 0.01);- assertEquals(out.get(9).doubleValue(),-49.0, 0.01);- assertEquals(out.get(10).doubleValue(),138.0, 0.01);- assertEquals(out.get(11).doubleValue(),-199.0, 0.01);- assertEquals(out.get(12).doubleValue(),-58.0, 0.01);- assertEquals(out.get(13).doubleValue(),334.0, 0.01);- assertEquals(out.get(14).doubleValue(),65.0, 0.01);- assertEquals(out.get(15).doubleValue(),-71.0, 0.01);- assertEquals(out.get(16).doubleValue(),-262.0, 0.01);- assertEquals(out.get(17).doubleValue(),280.0, 0.01);- assertEquals(out.get(18).doubleValue(),94.0, 0.01);+ assertEquals(out.get(0).doubleValue(), -88.0, 0.01);+ assertEquals(out.get(1).doubleValue(), 352.0, 0.01);+ assertEquals(out.get(2).doubleValue(), -161.0, 0.01);+ assertEquals(out.get(3).doubleValue(), 163.0, 0.01);+ assertEquals(out.get(4).doubleValue(), -113.0, 0.01);+ assertEquals(out.get(5).doubleValue(), 78.0, 0.01);+ assertEquals(out.get(6).doubleValue(), 73.0, 0.01);+ assertEquals(out.get(7).doubleValue(), -417.0, 0.01);+ assertEquals(out.get(8).doubleValue(), 129.0, 0.01);+ assertEquals(out.get(9).doubleValue(), -49.0, 0.01);+ assertEquals(out.get(10).doubleValue(), 138.0, 0.01);+ assertEquals(out.get(11).doubleValue(), -199.0, 0.01);+ assertEquals(out.get(12).doubleValue(), -58.0, 0.01);+ assertEquals(out.get(13).doubleValue(), 334.0, 0.01);+ assertEquals(out.get(14).doubleValue(), 65.0, 0.01);+ assertEquals(out.get(15).doubleValue(), -71.0, 0.01);+ assertEquals(out.get(16).doubleValue(), -262.0, 0.01);+ assertEquals(out.get(17).doubleValue(), 280.0, 0.01);+ assertEquals(out.get(18).doubleValue(), 94.0, 0.01);}@Testpublic void testTimeDifferencingDefinedLag() throws Exception {- String cexpr = "diff(array(1709.0, 1621.0, 1973.0, 1812.0, 1975.0, 1862.0, 1940.0, 2013.0, 1596.0, 1725.0, 1676.0, 1814.0, 1615.0, 1557.0, 1891.0, 1956.0, 1885.0, 1623.0, 1903.0, 1997.0), 12)";+ String cexpr =+ "diff(array(1709.0, 1621.0, 1973.0, 1812.0, 1975.0, 1862.0, 1940.0, 2013.0, 1596.0, 1725.0, 1676.0, 1814.0, 1615.0, 1557.0, 1891.0, 1956.0, 1885.0, 1623.0, 1903.0, 1997.0), 12)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 8);assertEquals(out.get(0).doubleValue(), -94.0, 0.01);- assertEquals(out.get(1).doubleValue(),-64.0, 0.01);- assertEquals(out.get(2).doubleValue(),-82.0, 0.01);- assertEquals(out.get(3).doubleValue(),144.0, 0.01);- assertEquals(out.get(4).doubleValue(),-90.0, 0.01);- assertEquals(out.get(5).doubleValue(),-239.0, 0.01);- assertEquals(out.get(6).doubleValue(),-37.0, 0.01);- assertEquals(out.get(7).doubleValue(),-16.0, 0.01);+ assertEquals(out.get(1).doubleValue(), -64.0, 0.01);+ assertEquals(out.get(2).doubleValue(), -82.0, 0.01);+ assertEquals(out.get(3).doubleValue(), 144.0, 0.01);+ assertEquals(out.get(4).doubleValue(), -90.0, 0.01);+ assertEquals(out.get(5).doubleValue(), -239.0, 0.01);+ assertEquals(out.get(6).doubleValue(), -37.0, 0.01);+ assertEquals(out.get(7).doubleValue(), -16.0, 0.01);}@Testpublic void testNestedDoubleTimeDifference() throws Exception {- String cexpr = "diff(diff(array(1709.0, 1621.0, 1973.0, 1812.0, 1975.0, 1862.0, 1940.0, 2013.0, 1596.0, 1725.0, 1676.0, 1814.0, 1615.0, 1557.0, 1891.0, 1956.0, 1885.0, 1623.0, 1903.0, 1997.0)), 12)";+ String cexpr =+ "diff(diff(array(1709.0, 1621.0, 1973.0, 1812.0, 1975.0, 1862.0, 1940.0, 2013.0, 1596.0, 1725.0, 1676.0, 1814.0, 1615.0, 1557.0, 1891.0, 1956.0, 1885.0, 1623.0, 1903.0, 1997.0)), 12)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 7);assertEquals(out.get(0).doubleValue(), 30.0, 0.01);assertEquals(out.get(1).doubleValue(), -18.0, 0.01);@@ -4296,20 +4490,22 @@ public void testCache() throws Exception {@Test@SuppressWarnings({"unchecked"})public void testPolyfit() throws Exception {- String cexpr = "let(echo=true," +- " a=array(0,1,2,3,4,5,6,7)," +- " fit=polyfit(a, 1)," +- " predictions=predict(fit, a))";+ String cexpr =+ "let(echo=true,"+ + " a=array(0,1,2,3,4,5,6,7),"+ + " fit=polyfit(a, 1),"+ + " predictions=predict(fit, a))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<Number> out = (List<Number>)tuples.get(0).get("fit");+ List<Number> out = (List<Number>) tuples.get(0).get("fit");assertTrue(out.size() == 8);assertTrue(out.get(0).intValue() == 0);assertTrue(out.get(1).intValue() == 1);@@ -4320,8 +4516,7 @@ public void testCache() throws Exception {assertTrue(out.get(6).intValue() == 6);assertTrue(out.get(7).intValue() == 7);-- out = (List<Number>)tuples.get(0).get("predictions");+ out = (List<Number>) tuples.get(0).get("predictions");assertTrue(out.size() == 8);assertTrue(out.get(0).intValue() == 0);assertTrue(out.get(1).intValue() == 1);@@ -4335,119 +4530,125 @@ public void testCache() throws Exception {@Testpublic void testTtest() throws Exception {- String cexpr = "let(echo=true," +- "a=array(0,1,2,3,4,5,6,7,9,10,11,12), " +- "b=array(0,1,2,3,4,5,6,7,1,1,1,1), " +- "ttest=ttest(a, b)," +- "sample2Mean=mean(b),"+- "onesamplettest=ttest(sample2Mean, b)," +- "pairedttest=pairedTtest(a,b))";+ String cexpr =+ "let(echo=true,"+ + "a=array(0,1,2,3,4,5,6,7,9,10,11,12), "+ + "b=array(0,1,2,3,4,5,6,7,1,1,1,1), "+ + "ttest=ttest(a, b),"+ + "sample2Mean=mean(b),"+ + "onesamplettest=ttest(sample2Mean, b),"+ + "pairedttest=pairedTtest(a,b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map testResult = (Map)tuples.get(0).get("ttest");- Number tstat = (Number)testResult.get("t-statistic");- Number pval = (Number)testResult.get("p-value");+ Map testResult = (Map) tuples.get(0).get("ttest");+ Number tstat = (Number) testResult.get("t-statistic");+ Number pval = (Number) testResult.get("p-value");assertEquals(tstat.doubleValue(), 2.3666107120397575, .0001);assertEquals(pval.doubleValue(), 0.029680704317867967, .0001);@SuppressWarnings({"rawtypes"})- Map testResult2 = (Map)tuples.get(0).get("onesamplettest");- Number tstat2 = (Number)testResult2.get("t-statistic");- Number pval2 = (Number)testResult2.get("p-value");+ Map testResult2 = (Map) tuples.get(0).get("onesamplettest");+ Number tstat2 = (Number) testResult2.get("t-statistic");+ Number pval2 = (Number) testResult2.get("p-value");assertEquals(tstat2.doubleValue(), 0, .0001);assertEquals(pval2.doubleValue(), 1, .0001);@SuppressWarnings({"rawtypes"})- Map testResult3 = (Map)tuples.get(0).get("pairedttest");- Number tstat3 = (Number)testResult3.get("t-statistic");- Number pval3 = (Number)testResult3.get("p-value");+ Map testResult3 = (Map) tuples.get(0).get("pairedttest");+ Number tstat3 = (Number) testResult3.get("t-statistic");+ Number pval3 = (Number) testResult3.get("p-value");assertEquals(tstat3.doubleValue(), 2.321219442769799, .0001);assertEquals(pval3.doubleValue(), 0.0404907407662755, .0001);}@Testpublic void testChiSquareDataSet() throws Exception {- String cexpr = "let(echo=true," +- " a=array(1,1,2,3,4,5,6,7,9,10,11,12), " +- " b=array(1,1,2,3,4,5,6,7,1,1,1,1), " +- " chisquare=chiSquareDataSet(a, b))";+ String cexpr =+ "let(echo=true,"+ + " a=array(1,1,2,3,4,5,6,7,9,10,11,12), "+ + " b=array(1,1,2,3,4,5,6,7,1,1,1,1), "+ + " chisquare=chiSquareDataSet(a, b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map testResult = (Map)tuples.get(0).get("chisquare");- Number tstat = (Number)testResult.get("chisquare-statistic");- Number pval = (Number)testResult.get("p-value");+ Map testResult = (Map) tuples.get(0).get("chisquare");+ Number tstat = (Number) testResult.get("chisquare-statistic");+ Number pval = (Number) testResult.get("p-value");assertEquals(tstat.doubleValue(), 20.219464814599252, .0001);assertEquals(pval.doubleValue(), 0.04242018685334226, .0001);}@Testpublic void testGtestDataSet() throws Exception {- String cexpr = "let(echo=true," +- " a=array(1,1,2,3,4,5,6,7,9,10,11,12), " +- " b=array(1,1,2,3,4,5,6,7,1,1,1,1), " +- " gtest=gtestDataSet(a, b))";+ String cexpr =+ "let(echo=true,"+ + " a=array(1,1,2,3,4,5,6,7,9,10,11,12), "+ + " b=array(1,1,2,3,4,5,6,7,1,1,1,1), "+ + " gtest=gtestDataSet(a, b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map testResult = (Map)tuples.get(0).get("gtest");- Number gstat = (Number)testResult.get("G-statistic");- Number pval = (Number)testResult.get("p-value");+ Map testResult = (Map) tuples.get(0).get("gtest");+ Number gstat = (Number) testResult.get("G-statistic");+ Number pval = (Number) testResult.get("p-value");assertEquals(gstat.doubleValue(), 22.41955157784917, .0001);assertEquals(pval.doubleValue(), 0.021317102314826752, .0001);}@Test- // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") //2018-03-10- // commented out on: 17-Feb-2019 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018public void testMultiVariateNormalDistribution() throws Exception {- String cexpr = "let(echo=true," +- " a=array(1,2,3,4,5,6,7)," +- " b=array(100, 110, 120, 130,140,150,180)," +- " c=transpose(matrix(a, b))," +- " d=array(mean(a), mean(b))," +- " e=cov(c)," +- " f=multiVariateNormalDistribution(d, e)," +- " g=sample(f, 10000)," +- " h=cov(g)," +- " i=sample(f)," +- " j=density(f, array(4.016093243274465, 138.7283428008585)))";+ String cexpr =+ "let(echo=true,"+ + " a=array(1,2,3,4,5,6,7),"+ + " b=array(100, 110, 120, 130,140,150,180),"+ + " c=transpose(matrix(a, b)),"+ + " d=array(mean(a), mean(b)),"+ + " e=cov(c),"+ + " f=multiVariateNormalDistribution(d, e),"+ + " g=sample(f, 10000),"+ + " h=cov(g),"+ + " i=sample(f),"+ + " j=density(f, array(4.016093243274465, 138.7283428008585)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> cov = (List<List<Number>>)tuples.get(0).get("h");+ List<List<Number>> cov = (List<List<Number>>) tuples.get(0).get("h");assertEquals(cov.size(), 2);List<Number> row1 = cov.get(0);assertEquals(row1.size(), 2);@@ -4465,41 +4666,43 @@ public void testCache() throws Exception {assertEquals(d, 723.8095238095239, 50);@SuppressWarnings({"unchecked"})- List<Number> sample = (List<Number>)tuples.get(0).get("i");+ List<Number> sample = (List<Number>) tuples.get(0).get("i");assertEquals(sample.size(), 2);Number sample1 = sample.get(0);Number sample2 = sample.get(1);assertTrue(sample.toString(), sample1.doubleValue() > -30 && sample1.doubleValue() < 30);assertTrue(sample.toString(), sample2.doubleValue() > 30 && sample2.doubleValue() < 251);- Number density = (Number)tuples.get(0).get("j");+ Number density = (Number) tuples.get(0).get("j");assertEquals(density.doubleValue(), 0.007852638121596995, .00001);}@Test@SuppressWarnings({"unchecked"})public void testKnn() throws Exception {- String cexpr = "let(echo=true," +- " a=setRowLabels(matrix(array(1,1,1,0,0,0),"+- " array(1,0,0,0,1,1),"+- " array(0,0,0,1,1,1)), array(\"row1\",\"row2\",\"row3\")),"+- " b=array(0,0,0,1,1,1),"+- " c=knn(a, b, 2),"+- " d=getRowLabels(c),"+- " e=getAttributes(c)," +- " f=knn(a, b, 2, manhattan())," +- " g=getAttributes(f))";+ String cexpr =+ "let(echo=true,"+ + " a=setRowLabels(matrix(array(1,1,1,0,0,0),"+ + " array(1,0,0,0,1,1),"+ + " array(0,0,0,1,1,1)), array(\"row1\",\"row2\",\"row3\")),"+ + " b=array(0,0,0,1,1,1),"+ + " c=knn(a, b, 2),"+ + " d=getRowLabels(c),"+ + " e=getAttributes(c),"+ + " f=knn(a, b, 2, manhattan()),"+ + " g=getAttributes(f))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<List<Number>> knnMatrix = (List<List<Number>>)tuples.get(0).get("c");+ List<List<Number>> knnMatrix = (List<List<Number>>) tuples.get(0).get("c");assertEquals(knnMatrix.size(), 2);List<Number> row1 = knnMatrix.get(0);@@ -4522,19 +4725,19 @@ public void testCache() throws Exception {assertEquals(row2.get(5).doubleValue(), 1.0, 0.0);@SuppressWarnings({"rawtypes"})- Map atts = (Map)tuples.get(0).get("e");- List<Number> dists = (List<Number>)atts.get("distances");+ Map atts = (Map) tuples.get(0).get("e");+ List<Number> dists = (List<Number>) atts.get("distances");assertEquals(dists.size(), 2);assertEquals(dists.get(0).doubleValue(), 0.0, 0.0);assertEquals(dists.get(1).doubleValue(), 1.4142135623730951, 0.0);- List<String> rowLabels = (List<String>)tuples.get(0).get("d");+ List<String> rowLabels = (List<String>) tuples.get(0).get("d");assertEquals(rowLabels.size(), 2);assertEquals(rowLabels.get(0), "row3");assertEquals(rowLabels.get(1), "row2");- atts = (Map)tuples.get(0).get("g");- dists = (List<Number>)atts.get("distances");+ atts = (Map) tuples.get(0).get("g");+ dists = (List<Number>) atts.get("distances");assertEquals(dists.size(), 2);assertEquals(dists.get(0).doubleValue(), 0.0, 0.0);assertEquals(dists.get(1).doubleValue(), 2.0, 0.0);@@ -4542,52 +4745,56 @@ public void testCache() throws Exception {@Testpublic void testIntegrate() throws Exception {- String cexpr = "let(echo=true, " +- "a=sequence(50, 1, 0), " +- "b=spline(a), " +- "c=integral(b, 0, 49), " +- "d=integral(b, 0, 20), " +- "e=integral(b, 20, 49)," +- "f=integral(b))";+ String cexpr =+ "let(echo=true, "+ + "a=sequence(50, 1, 0), "+ + "b=spline(a), "+ + "c=integral(b, 0, 49), "+ + "d=integral(b, 0, 20), "+ + "e=integral(b, 20, 49),"+ + "f=integral(b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number integral = (Number)tuples.get(0).get("c");+ Number integral = (Number) tuples.get(0).get("c");assertEquals(integral.doubleValue(), 49, 0.0);- integral = (Number)tuples.get(0).get("d");+ integral = (Number) tuples.get(0).get("d");assertEquals(integral.doubleValue(), 20, 0.0);- integral = (Number)tuples.get(0).get("e");+ integral = (Number) tuples.get(0).get("e");assertEquals(integral.doubleValue(), 29, 0.0);@SuppressWarnings({"unchecked"})- List<Number> integrals = (List<Number>)tuples.get(0).get("f");+ List<Number> integrals = (List<Number>) tuples.get(0).get("f");assertEquals(integrals.size(), 50);assertEquals(integrals.get(49).intValue(), 49);}@Testpublic void testLoess() throws Exception {- String cexpr = "let(echo=true," +- " a=array(0,1,2,3,4,5,6,7)," +- " fit=loess(a), " +- " der=derivative(fit))";+ String cexpr =+ "let(echo=true,"+ + " a=array(0,1,2,3,4,5,6,7),"+ + " fit=loess(a), "+ + " der=derivative(fit))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("fit");+ List<Number> out = (List<Number>) tuples.get(0).get("fit");assertTrue(out.size() == 8);assertEquals(out.get(0).doubleValue(), 0.0, 0.0);assertEquals(out.get(1).doubleValue(), 1.0, 0.0);@@ -4599,7 +4806,7 @@ public void testCache() throws Exception {assertEquals(out.get(7).doubleValue(), 7.0, 0.0);@SuppressWarnings({"unchecked"})- List<Number> out1 = (List<Number>)tuples.get(0).get("der");+ List<Number> out1 = (List<Number>) tuples.get(0).get("der");assertTrue(out1.size() == 8);assertEquals(out1.get(0).doubleValue(), 1.0, 0.0);assertEquals(out1.get(1).doubleValue(), 1.0, 0.0);@@ -4609,28 +4816,29 @@ public void testCache() throws Exception {assertEquals(out1.get(5).doubleValue(), 1.0, 0.0);assertEquals(out1.get(6).doubleValue(), 1.0, 0.0);assertEquals(out1.get(7).doubleValue(), 1.0, 0.0);-}@Testpublic void testSpline() throws Exception {- String cexpr = "let(echo=true," +- " a=array(0,1,2,3,4,5,6,7), " +- " b=array(1,70,90,10,78, 100, 1, 9)," +- " fit=spline(a, b), " +- " der=derivative(fit))";+ String cexpr =+ "let(echo=true,"+ + " a=array(0,1,2,3,4,5,6,7), "+ + " b=array(1,70,90,10,78, 100, 1, 9),"+ + " fit=spline(a, b), "+ + " der=derivative(fit))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("fit");+ List<Number> out = (List<Number>) tuples.get(0).get("fit");assertTrue(out.size() == 8);assertEquals(out.get(0).doubleValue(), 1.0, 0.0001);assertEquals(out.get(1).doubleValue(), 70.0, 0.0001);@@ -4642,12 +4850,12 @@ public void testCache() throws Exception {assertEquals(out.get(7).doubleValue(), 9.0, 0.0001);@SuppressWarnings({"unchecked"})- List<Number> out1 = (List<Number>)tuples.get(0).get("der");+ List<Number> out1 = (List<Number>) tuples.get(0).get("der");assertTrue(out1.size() == 8);assertEquals(out1.get(0).doubleValue(), 72.06870491240123, 0.0001);assertEquals(out1.get(1).doubleValue(), 62.86259017519753, 0.0001);- assertEquals(out1.get(2).doubleValue(),-56.519065613191344, 0.0001);+ assertEquals(out1.get(2).doubleValue(), -56.519065613191344, 0.0001);assertEquals(out1.get(3).doubleValue(), -16.786327722432148, 0.0001);assertEquals(out1.get(4).doubleValue(), 87.66437650291996, 0.0001);assertEquals(out1.get(5).doubleValue(), -63.87117828924769, 0.0001);@@ -4657,38 +4865,40 @@ public void testCache() throws Exception {@Testpublic void testBicubicSpline() throws Exception {- String cexpr = "let(echo=true," +- " a=array(300, 400, 500, 600, 700), " +- " b=array(340, 410, 495, 590, 640)," +- " c=array(600, 395, 550, 510, 705),"+- " d=array(500, 420, 510, 601, 690),"+- " e=array(420, 411, 511, 611, 711),"+- " f=matrix(a, b, c, d, e),"+- " x=array(1,2,3,4,5),"+- " y=array(100, 200, 300, 400, 500),"+- " bspline=bicubicSpline(x, y, f), " +- " p1=predict(bspline, 1.5, 250)," +- " p2=predict(bspline, 3.5, 350)," +- " p3=predict(bspline, 4.5, 450)," +- " p4=predict(bspline,matrix(array(1.5, 250), array(3.5, 350), array(4.5, 450))))";+ String cexpr =+ "let(echo=true,"+ + " a=array(300, 400, 500, 600, 700), "+ + " b=array(340, 410, 495, 590, 640),"+ + " c=array(600, 395, 550, 510, 705),"+ + " d=array(500, 420, 510, 601, 690),"+ + " e=array(420, 411, 511, 611, 711),"+ + " f=matrix(a, b, c, d, e),"+ + " x=array(1,2,3,4,5),"+ + " y=array(100, 200, 300, 400, 500),"+ + " bspline=bicubicSpline(x, y, f), "+ + " p1=predict(bspline, 1.5, 250),"+ + " p2=predict(bspline, 3.5, 350),"+ + " p3=predict(bspline, 4.5, 450),"+ + " p4=predict(bspline,matrix(array(1.5, 250), array(3.5, 350), array(4.5, 450))))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number p1 = (Number)tuples.get(0).get("p1");+ Number p1 = (Number) tuples.get(0).get("p1");assertEquals(p1.doubleValue(), 449.7837701612903, 0.0);- Number p2 = (Number)tuples.get(0).get("p2");+ Number p2 = (Number) tuples.get(0).get("p2");assertEquals(p2.doubleValue(), 536.8916383774491, 0.0);- Number p3 = (Number)tuples.get(0).get("p3");+ Number p3 = (Number) tuples.get(0).get("p3");assertEquals(p3.doubleValue(), 659.921875, 0.0);@SuppressWarnings({"unchecked"})- List<Number> p4 = (List<Number>)tuples.get(0).get("p4");+ List<Number> p4 = (List<Number>) tuples.get(0).get("p4");assertEquals(p4.get(0).doubleValue(), 449.7837701612903, 0.0);assertEquals(p4.get(1).doubleValue(), 536.8916383774491, 0.0);assertEquals(p4.get(2).doubleValue(), 659.921875, 0.0);@@ -4696,23 +4906,25 @@ public void testCache() throws Exception {@Testpublic void testAkima() throws Exception {- String cexpr = "let(echo=true," +- " a=array(0,1,2,3,4,5,6,7), " +- " b=array(1,70,90,10,78, 100, 1, 9)," +- " fit=akima(a, b), " +- " der=derivative(fit))";+ String cexpr =+ "let(echo=true,"+ + " a=array(0,1,2,3,4,5,6,7), "+ + " b=array(1,70,90,10,78, 100, 1, 9),"+ + " fit=akima(a, b), "+ + " der=derivative(fit))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("fit");+ List<Number> out = (List<Number>) tuples.get(0).get("fit");assertTrue(out.size() == 8);assertEquals(out.get(0).doubleValue(), 1.0, 0.0001);assertEquals(out.get(1).doubleValue(), 70.0, 0.0001);@@ -4724,7 +4936,7 @@ public void testCache() throws Exception {assertEquals(out.get(7).doubleValue(), 9.0, 0.0001);@SuppressWarnings({"unchecked"})- List<Number> out1 = (List<Number>)tuples.get(0).get("der");+ List<Number> out1 = (List<Number>) tuples.get(0).get("der");assertTrue(out1.size() == 8);assertEquals(out1.get(0).doubleValue(), 93.5, 0.0001);assertEquals(out1.get(1).doubleValue(), 44.5, 0.0001);@@ -4736,81 +4948,83 @@ public void testCache() throws Exception {assertEquals(out1.get(7).doubleValue(), 61.5, 0.0001);}-@Testpublic void testOutliers() throws Exception {- String cexpr = "let(echo=true," +- " a=list(tuple(id=0.0), tuple(id=1), tuple(id=2), tuple(id=3)), " +- " b=normalDistribution(100, 5)," +- " d=array(100, 110, 90, 99), " +- " e=outliers(b, d, .05, .95, a)," +- " f=outliers(b, d, .05, .95))";+ String cexpr =+ "let(echo=true,"+ + " a=list(tuple(id=0.0), tuple(id=1), tuple(id=2), tuple(id=3)), "+ + " b=normalDistribution(100, 5),"+ + " d=array(100, 110, 90, 99), "+ + " e=outliers(b, d, .05, .95, a),"+ + " f=outliers(b, d, .05, .95))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked", "rawtypes"})- List<Map> out = (List<Map>)tuples.get(0).get("e");+ List<Map> out = (List<Map>) tuples.get(0).get("e");assertEquals(out.size(), 2);@SuppressWarnings({"rawtypes"})Map high = out.get(0);- assertEquals(((String)high.get("id")), "1");-- assertEquals(((Number)high.get("cumulativeProbablity_d")).doubleValue(), 0.9772498680518208, 0.0 );- assertEquals(((Number)high.get("highOutlierValue_d")).doubleValue(), 110.0, 0.0);+ assertEquals(((String) high.get("id")), "1");+ assertEquals(+ ((Number) high.get("cumulativeProbablity_d")).doubleValue(), 0.9772498680518208, 0.0);+ assertEquals(((Number) high.get("highOutlierValue_d")).doubleValue(), 110.0, 0.0);@SuppressWarnings({"rawtypes"})Map low = out.get(1);- assertEquals(((String)low.get("id")), "2");- assertEquals(((Number)low.get("cumulativeProbablity_d")).doubleValue(), 0.022750131948179167, 0.0 );- assertEquals(((Number)low.get("lowOutlierValue_d")).doubleValue(), 90, 0.0);-+ assertEquals(((String) low.get("id")), "2");+ assertEquals(+ ((Number) low.get("cumulativeProbablity_d")).doubleValue(), 0.022750131948179167, 0.0);+ assertEquals(((Number) low.get("lowOutlierValue_d")).doubleValue(), 90, 0.0);@SuppressWarnings({"unchecked", "rawtypes"})- List<Map> out1 = (List<Map>)tuples.get(0).get("f");+ List<Map> out1 = (List<Map>) tuples.get(0).get("f");assertEquals(out1.size(), 2);@SuppressWarnings({"rawtypes"})Map high1 = out1.get(0);- assert(high1.get("id") == null);- assertEquals(((Number)high1.get("cumulativeProbablity_d")).doubleValue(), 0.9772498680518208, 0.0 );- assertEquals(((Number)high1.get("highOutlierValue_d")).doubleValue(), 110.0, 0.0);-+ assert (high1.get("id") == null);+ assertEquals(+ ((Number) high1.get("cumulativeProbablity_d")).doubleValue(), 0.9772498680518208, 0.0);+ assertEquals(((Number) high1.get("highOutlierValue_d")).doubleValue(), 110.0, 0.0);@SuppressWarnings({"rawtypes"})Map low1 = out1.get(1);- assert(low1.get("id") == null);- assertEquals(((Number)low1.get("cumulativeProbablity_d")).doubleValue(), 0.022750131948179167, 0.0 );- assertEquals(((Number)low1.get("lowOutlierValue_d")).doubleValue(), 90, 0.0);-+ assert (low1.get("id") == null);+ assertEquals(+ ((Number) low1.get("cumulativeProbablity_d")).doubleValue(), 0.022750131948179167, 0.0);+ assertEquals(((Number) low1.get("lowOutlierValue_d")).doubleValue(), 90, 0.0);}-- @Test+ @Testpublic void testLerp() throws Exception {- String cexpr = "let(echo=true," +- " a=array(0,1,2,3,4,5,6,7), " +- " b=array(1,70,90,10,78, 100, 1, 9)," +- " fit=lerp(a, b), " +- " der=derivative(fit))";+ String cexpr =+ "let(echo=true,"+ + " a=array(0,1,2,3,4,5,6,7), "+ + " b=array(1,70,90,10,78, 100, 1, 9),"+ + " fit=lerp(a, b), "+ + " der=derivative(fit))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("fit");+ List<Number> out = (List<Number>) tuples.get(0).get("fit");assertTrue(out.size() == 8);assertEquals(out.get(0).doubleValue(), 1.0, 0.0001);assertEquals(out.get(1).doubleValue(), 70.0, 0.0001);@@ -4822,14 +5036,14 @@ public void testCache() throws Exception {assertEquals(out.get(7).doubleValue(), 9.0, 0.0001);@SuppressWarnings({"unchecked"})- List<Number> out1 = (List<Number>)tuples.get(0).get("der");+ List<Number> out1 = (List<Number>) tuples.get(0).get("der");assertTrue(out1.size() == 8);assertEquals(out1.get(0).doubleValue(), 69.0, 0.0001);assertEquals(out1.get(1).doubleValue(), 20.0, 0.0001);- assertEquals(out1.get(2).doubleValue(),-80.0, 0.0001);+ assertEquals(out1.get(2).doubleValue(), -80.0, 0.0001);assertEquals(out1.get(3).doubleValue(), 68, 0.0001);assertEquals(out1.get(4).doubleValue(), 22.0, 0.0001);- assertEquals(out1.get(5).doubleValue(),-99.0, 0.0001);+ assertEquals(out1.get(5).doubleValue(), -99.0, 0.0001);assertEquals(out1.get(6).doubleValue(), 8.0, 0.0001);assertEquals(out1.get(7).doubleValue(), 8.0, 0.0001);}@@ -4841,16 +5055,17 @@ public void testCache() throws Exception {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("s");+ List<Number> out = (List<Number>) tuples.get(0).get("s");assertTrue(out.size() == 100);- for(Number n : out) {+ for (Number n : out) {assertEquals(n.doubleValue(), 0.0, .01);}}@@ -4861,7 +5076,8 @@ public void testCache() throws Exception {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -4874,31 +5090,33 @@ public void testCache() throws Exception {@Testpublic void testOlsRegress() throws Exception {- String cexpr = "let(echo=true, a=array(8.5, 12.89999962, 5.199999809, 10.69999981, 3.099999905, 3.5, 9.199999809, 9, 15.10000038, 10.19999981), " +- "b=array(5.099999905, 5.800000191, 2.099999905, 8.399998665, 2.900000095, 1.200000048, 3.700000048, 7.599999905, 7.699999809, 4.5)," +- "c=array(4.699999809, 8.800000191, 15.10000038, 12.19999981, 10.60000038, 3.5, 9.699999809, 5.900000095, 20.79999924, 7.900000095)," +- "d=array(85.09999847, 106.3000031, 50.20000076, 130.6000061, 54.79999924, 30.29999924, 79.40000153, 91, 135.3999939, 89.30000305)," +- "e=transpose(matrix(a, b, c))," +- "f=olsRegress(e, d)," +- "g=predict(f, e))";+ String cexpr =+ "let(echo=true, a=array(8.5, 12.89999962, 5.199999809, 10.69999981, 3.099999905, 3.5, 9.199999809, 9, 15.10000038, 10.19999981), "+ + "b=array(5.099999905, 5.800000191, 2.099999905, 8.399998665, 2.900000095, 1.200000048, 3.700000048, 7.599999905, 7.699999809, 4.5),"+ + "c=array(4.699999809, 8.800000191, 15.10000038, 12.19999981, 10.60000038, 3.5, 9.699999809, 5.900000095, 20.79999924, 7.900000095),"+ + "d=array(85.09999847, 106.3000031, 50.20000076, 130.6000061, 54.79999924, 30.29999924, 79.40000153, 91, 135.3999939, 89.30000305),"+ + "e=transpose(matrix(a, b, c)),"+ + "f=olsRegress(e, d),"+ + "g=predict(f, e))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map regression = (Map)tuples.get(0).get("f");+ Map regression = (Map) tuples.get(0).get("f");- Number rsquared = (Number)regression.get("RSquared");+ Number rsquared = (Number) regression.get("RSquared");assertEquals(rsquared.doubleValue(), 0.9667887860584002, .000001);@SuppressWarnings({"unchecked"})- List<Number> regressionParameters = (List<Number>)regression.get("regressionParameters");+ List<Number> regressionParameters = (List<Number>) regression.get("regressionParameters");assertEquals(regressionParameters.get(0).doubleValue(), 7.676028542255028, .0001);assertEquals(regressionParameters.get(1).doubleValue(), 3.661604009261836, .0001);@@ -4906,7 +5124,7 @@ public void testCache() throws Exception {assertEquals(regressionParameters.get(3).doubleValue(), 0.8284680662898674, .0001);@SuppressWarnings({"unchecked"})- List<Number> predictions = (List<Number>)tuples.get(0).get("g");+ List<Number> predictions = (List<Number>) tuples.get(0).get("g");assertEquals(predictions.get(0).doubleValue(), 81.56082305847914, .0001);assertEquals(predictions.get(1).doubleValue(), 106.40333675525883, .0001);@@ -4923,25 +5141,27 @@ public void testCache() throws Exception {@Test@SuppressWarnings({"unchecked"})public void testKnnRegress() throws Exception {- String cexpr = "let(echo=true, a=array(8.5, 12.89999962, 5.199999809, 10.69999981, 3.099999905, 3.5, 9.199999809, 9, 15.10000038, 10.19999981), " +- "b=array(5.099999905, 5.800000191, 2.099999905, 8.399998665, 2.900000095, 1.200000048, 3.700000048, 7.599999905, 7.699999809, 4.5)," +- "c=array(4.699999809, 8.800000191, 15.10000038, 12.19999981, 10.60000038, 3.5, 9.699999809, 5.900000095, 20.79999924, 7.900000095)," +- "d=array(85.09999847, 106.3000031, 50.20000076, 130.6000061, 54.79999924, 30.29999924, 79.40000153, 91, 135.3999939, 89.30000305)," +- "e=transpose(matrix(a, b, c))," +- "f=knnRegress(e, d, 1, scale=true)," +- "g=predict(f, e))";+ String cexpr =+ "let(echo=true, a=array(8.5, 12.89999962, 5.199999809, 10.69999981, 3.099999905, 3.5, 9.199999809, 9, 15.10000038, 10.19999981), "+ + "b=array(5.099999905, 5.800000191, 2.099999905, 8.399998665, 2.900000095, 1.200000048, 3.700000048, 7.599999905, 7.699999809, 4.5),"+ + "c=array(4.699999809, 8.800000191, 15.10000038, 12.19999981, 10.60000038, 3.5, 9.699999809, 5.900000095, 20.79999924, 7.900000095),"+ + "d=array(85.09999847, 106.3000031, 50.20000076, 130.6000061, 54.79999924, 30.29999924, 79.40000153, 91, 135.3999939, 89.30000305),"+ + "e=transpose(matrix(a, b, c)),"+ + "f=knnRegress(e, d, 1, scale=true),"+ + "g=predict(f, e))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<Number> predictions = (List<Number>)tuples.get(0).get("g");+ List<Number> predictions = (List<Number>) tuples.get(0).get("g");assertEquals(predictions.size(), 10);- //k=1 should bring back only one prediction for the exact match in the training set+ // k=1 should bring back only one prediction for the exact match in the training setassertEquals(predictions.get(0).doubleValue(), 85.09999847, 0);assertEquals(predictions.get(1).doubleValue(), 106.3000031, 0);assertEquals(predictions.get(2).doubleValue(), 50.20000076, 0);@@ -4953,77 +5173,77 @@ public void testCache() throws Exception {assertEquals(predictions.get(8).doubleValue(), 135.3999939, 0);assertEquals(predictions.get(9).doubleValue(), 89.30000305, 0);- cexpr = "let(echo=true, a=array(8.5, 12.89999962, 5.199999809, 10.69999981, 3.099999905, 3.5, 9.199999809, 9, 15.10000038, 10.19999981), " +- "b=array(5.099999905, 5.800000191, 2.099999905, 8.399998665, 2.900000095, 1.200000048, 3.700000048, 7.599999905, 7.699999809, 4.5)," +- "c=array(4.699999809, 8.800000191, 15.10000038, 12.19999981, 10.60000038, 3.5, 9.699999809, 5.900000095, 20.79999924, 7.900000095)," +- "d=array(85.09999847, 106.3000031, 50.20000076, 130.6000061, 54.79999924, 30.29999924, 79.40000153, 91, 135.3999939, 89.30000305)," +- "e=transpose(matrix(a, b, c))," +- "f=knnRegress(e, d, 1, scale=true)," +- "g=predict(f, array(8, 5, 4)))";+ cexpr =+ "let(echo=true, a=array(8.5, 12.89999962, 5.199999809, 10.69999981, 3.099999905, 3.5, 9.199999809, 9, 15.10000038, 10.19999981), "+ + "b=array(5.099999905, 5.800000191, 2.099999905, 8.399998665, 2.900000095, 1.200000048, 3.700000048, 7.599999905, 7.699999809, 4.5),"+ + "c=array(4.699999809, 8.800000191, 15.10000038, 12.19999981, 10.60000038, 3.5, 9.699999809, 5.900000095, 20.79999924, 7.900000095),"+ + "d=array(85.09999847, 106.3000031, 50.20000076, 130.6000061, 54.79999924, 30.29999924, 79.40000153, 91, 135.3999939, 89.30000305),"+ + "e=transpose(matrix(a, b, c)),"+ + "f=knnRegress(e, d, 1, scale=true),"+ + "g=predict(f, array(8, 5, 4)))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;solrStream = new SolrStream(url, paramsLoc);context = new StreamContext();solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number prediction = (Number)tuples.get(0).get("g");+ Number prediction = (Number) tuples.get(0).get("g");assertEquals(prediction.doubleValue(), 85.09999847, 0);- //Test robust. Take the median rather then average+ // Test robust. Take the median rather then average- cexpr = "let(echo=true, a=array(8.5, 12.89999962, 5.199999809, 10.69999981, 3.099999905, 3.5, 9.199999809, 9, 8.10000038, 8.19999981), " +- "b=array(5.099999905, 5.800000191, 2.099999905, 8.399998665, 2.900000095, 1.200000048, 3.700000048, 5.599999905, 5.699999809, 4.5)," +- "c=array(4.699999809, 8.800000191, 15.10000038, 12.19999981, 10.60000038, 3.5, 9.699999809, 5.900000095, 4.79999924, 4.900000095)," +- "d=array(85.09999847, 106.3000031, 50.20000076, 130.6000061, 54.79999924, 30.29999924, 79.40000153, 91, 135.3999939, 89.30000305)," +- "e=transpose(matrix(a, b, c))," +- "f=knnRegress(e, d, 3, scale=true, robust=true)," +- "g=predict(f, array(8, 5, 4)))";+ cexpr =+ "let(echo=true, a=array(8.5, 12.89999962, 5.199999809, 10.69999981, 3.099999905, 3.5, 9.199999809, 9, 8.10000038, 8.19999981), "+ + "b=array(5.099999905, 5.800000191, 2.099999905, 8.399998665, 2.900000095, 1.200000048, 3.700000048, 5.599999905, 5.699999809, 4.5),"+ + "c=array(4.699999809, 8.800000191, 15.10000038, 12.19999981, 10.60000038, 3.5, 9.699999809, 5.900000095, 4.79999924, 4.900000095),"+ + "d=array(85.09999847, 106.3000031, 50.20000076, 130.6000061, 54.79999924, 30.29999924, 79.40000153, 91, 135.3999939, 89.30000305),"+ + "e=transpose(matrix(a, b, c)),"+ + "f=knnRegress(e, d, 3, scale=true, robust=true),"+ + "g=predict(f, array(8, 5, 4)))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;solrStream = new SolrStream(url, paramsLoc);context = new StreamContext();solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- prediction = (Number)tuples.get(0).get("g");+ prediction = (Number) tuples.get(0).get("g");assertEquals(prediction.doubleValue(), 89.30000305, 0);+ // Test univariate regression with scaling off- //Test univariate regression with scaling off-- cexpr = "let(echo=true, a=sequence(10, 0, 1), " +- "c=knnRegress(a, a, 3)," +- "d=predict(c, 3))";+ cexpr = "let(echo=true, a=sequence(10, 0, 1), " + "c=knnRegress(a, a, 3)," + "d=predict(c, 3))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;solrStream = new SolrStream(url, paramsLoc);context = new StreamContext();solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- prediction = (Number)tuples.get(0).get("d");+ prediction = (Number) tuples.get(0).get("d");assertEquals(prediction.doubleValue(), 3, 0);- cexpr = "let(echo=true, a=sequence(10, 0, 1), " +- "c=knnRegress(a, a, 3)," +- "d=predict(c, array(3,4)))";+ cexpr =+ "let(echo=true, a=sequence(10, 0, 1), "+ + "c=knnRegress(a, a, 3),"+ + "d=predict(c, array(3,4)))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;solrStream = new SolrStream(url, paramsLoc);context = new StreamContext();solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- predictions = (List<Number>)tuples.get(0).get("d");+ predictions = (List<Number>) tuples.get(0).get("d");assertEquals(predictions.size(), 2);assertEquals(predictions.get(0).doubleValue(), 3, 0);assertEquals(predictions.get(1).doubleValue(), 4, 0);@@ -5031,56 +5251,57 @@ public void testCache() throws Exception {@Testpublic void testDateTime() throws Exception {- String expr = "select(list(tuple(a=20001011:10:11:01), tuple(a=20071011:14:30:20)), dateTime(a, \"yyyyMMdd:kk:mm:ss\") as date)";+ String expr =+ "select(list(tuple(a=20001011:10:11:01), tuple(a=20071011:14:30:20)), dateTime(a, \"yyyyMMdd:kk:mm:ss\") as date)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- String date = (String)tuples.get(0).get("date");+ String date = (String) tuples.get(0).get("date");assertEquals(date, "2000-10-11T10:11:01Z");- date = (String)tuples.get(1).get("date");+ date = (String) tuples.get(1).get("date");assertEquals(date, "2007-10-11T14:30:20Z");}@Testpublic void testDateTimeTZ() throws Exception {- String expr = "select(list(tuple(a=20001011), tuple(a=20071011)), dateTime(a, \"yyyyMMdd\", \"UTC\") as date, dateTime(a, \"yyyyMMdd\", \"EST\") as date1, dateTime(a, \"yyyyMMdd\") as date2)";+ String expr =+ "select(list(tuple(a=20001011), tuple(a=20071011)), dateTime(a, \"yyyyMMdd\", \"UTC\") as date, dateTime(a, \"yyyyMMdd\", \"EST\") as date1, dateTime(a, \"yyyyMMdd\") as date2)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- String date = (String)tuples.get(0).get("date");- String date1 = (String)tuples.get(0).get("date1");- String date2 = (String)tuples.get(0).get("date2");+ String date = (String) tuples.get(0).get("date");+ String date1 = (String) tuples.get(0).get("date1");+ String date2 = (String) tuples.get(0).get("date2");assertEquals(date, "2000-10-11T00:00:00Z");assertEquals(date1, "2000-10-11T05:00:00Z");assertEquals(date2, "2000-10-11T00:00:00Z");-- date = (String)tuples.get(1).get("date");- date1 = (String)tuples.get(1).get("date1");- date2 = (String)tuples.get(1).get("date2");+ date = (String) tuples.get(1).get("date");+ date1 = (String) tuples.get(1).get("date1");+ date2 = (String) tuples.get(1).get("date2");assertEquals(date, "2007-10-11T00:00:00Z");assertEquals(date1, "2007-10-11T05:00:00Z");assertEquals(date2, "2007-10-11T00:00:00Z");}--@Testpublic void testDoubleLong() throws Exception {String expr = "select(tuple(d=\"1.1\", l=\"5000\"), double(d) as d, long(l) as l)";@@ -5088,63 +5309,65 @@ public void testCache() throws Exception {paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);+ assertEquals(tuples.size(), 1);assertTrue(tuples.get(0).get("d") instanceof Double);assertTrue(tuples.get(0).get("l") instanceof Long);assertEquals(tuples.get(0).getDouble("d"), 1.1D, 0);assertEquals(tuples.get(0).getLong("l").longValue(), 5000L);-}-public void testDoubleArray() throws Exception {- String expr = "let(a=list(tuple(d=\"1.1\", l=\"5000\"), tuple(d=\"1.3\", l=\"7000\"))," +- " b=col(a, d)," +- " tuple(doubles=double(b)))";+ String expr =+ "let(a=list(tuple(d=\"1.1\", l=\"5000\"), tuple(d=\"1.3\", l=\"7000\")),"+ + " b=col(a, d),"+ + " tuple(doubles=double(b)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 1);+ assertEquals(tuples.size(), 1);@SuppressWarnings({"unchecked"})- List<Double> doubles = (List<Double>)tuples.get(0).get("doubles");+ List<Double> doubles = (List<Double>) tuples.get(0).get("doubles");assertEquals(doubles.get(0), 1.1, 0);assertEquals(doubles.get(1), 1.3, 0);-}@Testpublic void testGaussfit() throws Exception {- String cexpr = "let(echo=true, " +- "x=array(79.56,81.32,82.82,84.64,86.18,87.89,89.53,91.14,92.8,94.43,96.08,97.72,99.37,101,102.66,104.3,105.94,107.59,109.23,110.87,112.52,114.13,115.82,117.44,119.27), " +- "y=array(3, 3, 26, 54, 139, 344, 685, 1289, 2337, 3593, 4781, 5964, 6538, 6357, 5705, 4548, 3280, 2058, 1191, 649, 285, 112, 34, 18, 7)," +- "g=gaussfit(x,y))";+ String cexpr =+ "let(echo=true, "+ + "x=array(79.56,81.32,82.82,84.64,86.18,87.89,89.53,91.14,92.8,94.43,96.08,97.72,99.37,101,102.66,104.3,105.94,107.59,109.23,110.87,112.52,114.13,115.82,117.44,119.27), "+ + "y=array(3, 3, 26, 54, 139, 344, 685, 1289, 2337, 3593, 4781, 5964, 6538, 6357, 5705, 4548, 3280, 2058, 1191, 649, 285, 112, 34, 18, 7),"+ + "g=gaussfit(x,y))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> predictions = (List<Number>)tuples.get(0).get("g");+ List<Number> predictions = (List<Number>) tuples.get(0).get("g");assertEquals(predictions.size(), 25);assertEquals(predictions.get(0).doubleValue(), 1.5217511259930976, 0);assertEquals(predictions.get(1).doubleValue(), 6.043059526517849, 0);@@ -5158,7 +5381,7 @@ public void testCache() throws Exception {assertEquals(predictions.get(9).doubleValue(), 3524.6949840829216, 0);assertEquals(predictions.get(10).doubleValue(), 4824.273031596218, 0);assertEquals(predictions.get(11).doubleValue(), 5915.519574509397, 0);- assertEquals(predictions.get(12).doubleValue(), 6514.552728035438, 0);+ assertEquals(predictions.get(12).doubleValue(), 6514.552728035438, 0);assertEquals(predictions.get(13).doubleValue(), 6438.3295998729845, 0);assertEquals(predictions.get(14).doubleValue(), 5702.59200814961, 0);assertEquals(predictions.get(15).doubleValue(), 4538.7945530007, 0);@@ -5173,14 +5396,14 @@ public void testCache() throws Exception {assertEquals(predictions.get(24).doubleValue(), 3.887269101204326, 0);}-@Testpublic void testPlot() throws Exception {String cexpr = "let(a=array(3,2,3), plot(type=scatter, x=a, y=array(5,6,3)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -5189,7 +5412,7 @@ public void testCache() throws Exception {String plot = tuples.get(0).getString("plot");assertTrue(plot.equals("scatter"));@SuppressWarnings({"unchecked"})- List<List<Number>> data = (List<List<Number>>)tuples.get(0).get("data");+ List<List<Number>> data = (List<List<Number>>) tuples.get(0).get("data");assertTrue(data.size() == 3);List<Number> pair1 = data.get(0);assertTrue(pair1.get(0).intValue() == 3);@@ -5208,15 +5431,16 @@ public void testCache() throws Exception {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");- assertTrue(out.size()==4);+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");+ assertTrue(out.size() == 4);assertEquals((double) out.get(0), 2.5, .0);assertEquals((double) out.get(1), 3.5, .0);assertEquals((double) out.get(2), 4.5, .0);@@ -5229,16 +5453,17 @@ public void testCache() throws Exception {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");- assertTrue(out.size()==4);- System.out.println("MAD:"+out);+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");+ assertTrue(out.size() == 4);+ System.out.println("MAD:" + out);assertEquals(out.get(0).doubleValue(), 1, .0);assertEquals(out.get(1).doubleValue(), 1, .0);assertEquals(out.get(2).doubleValue(), 1, .0);@@ -5247,12 +5472,14 @@ public void testCache() throws Exception {@Testpublic void testMannWhitney() throws Exception {- String cexpr = "mannWhitney(array(0.15,0.10,0.11,0.24,0.08,0.08,0.10,0.10,0.10,0.12,0.04,0.07), " +- "array(0.10,0.20,0.30,0.10,0.10,0.02,0.05,0.07))";+ String cexpr =+ "mannWhitney(array(0.15,0.10,0.11,0.24,0.08,0.08,0.10,0.10,0.10,0.12,0.04,0.07), "+ + "array(0.10,0.20,0.30,0.10,0.10,0.02,0.05,0.07))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -5269,14 +5496,15 @@ public void testCache() throws Exception {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("return-value");+ List<Number> out = (List<Number>) tuples.get(0).get("return-value");assertTrue(out.size() == 3);assertEquals(out.get(0).doubleValue(), 6.0, .0);assertEquals(out.get(1).doubleValue(), 9.0, .0);@@ -5289,31 +5517,34 @@ public void testCache() throws Exception {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number sumSq = (Number)tuples.get(0).get("return-value");+ Number sumSq = (Number) tuples.get(0).get("return-value");assertEquals(sumSq.doubleValue(), 115.25D, 0.0D);}@Testpublic void testMonteCarlo() throws Exception {- String cexpr = "let(a=constantDistribution(10), b=constantDistribution(20), c=monteCarlo(add(sample(a), sample(b)), 10))";+ String cexpr =+ "let(a=constantDistribution(10), b=constantDistribution(20), c=monteCarlo(add(sample(a), sample(b)), 10))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("c");- assertTrue(out.size()==10);+ List<Number> out = (List<Number>) tuples.get(0).get("c");+ assertTrue(out.size() == 10);assertEquals(out.get(0).doubleValue(), 30.0, .0);assertEquals(out.get(1).doubleValue(), 30.0, .0);assertEquals(out.get(2).doubleValue(), 30.0, .0);@@ -5328,24 +5559,26 @@ public void testCache() throws Exception {@Testpublic void testMonteCarloWithVariables() throws Exception {- String cexpr = "let(a=constantDistribution(10), " +- " b=constantDistribution(20), " +- " c=monteCarlo(d=sample(a),"+- " e=sample(b),"+- " add(d, add(e, 10)), " +- " 10))";+ String cexpr =+ "let(a=constantDistribution(10), "+ + " b=constantDistribution(20), "+ + " c=monteCarlo(d=sample(a),"+ + " e=sample(b),"+ + " add(d, add(e, 10)), "+ + " 10))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> out = (List<Number>)tuples.get(0).get("c");- assertTrue(out.size()==10);+ List<Number> out = (List<Number>) tuples.get(0).get("c");+ assertTrue(out.size() == 10);assertEquals(out.get(0).doubleValue(), 40.0, .0);assertEquals(out.get(1).doubleValue(), 40.0, .0);assertEquals(out.get(2).doubleValue(), 40.0, .0);@@ -5360,147 +5593,153 @@ public void testCache() throws Exception {@Testpublic void testWeibullDistribution() throws Exception {- String cexpr = "let(echo=true, " +- "a=describe(sample(weibullDistribution(.1, 10),10000)), " +- "b=describe(sample(weibullDistribution(.5, 10),10000)), " +- "c=describe(sample(weibullDistribution(1, 10),10000))," +- "d=describe(sample(weibullDistribution(6, 10),10000))," +- "e=mean(sample(weibullDistribution(1, 10),10000))," +- "f=mean(sample(weibullDistribution(1, 20),10000))," +- "g=mean(sample(weibullDistribution(1, 30),10000)))";+ String cexpr =+ "let(echo=true, "+ + "a=describe(sample(weibullDistribution(.1, 10),10000)), "+ + "b=describe(sample(weibullDistribution(.5, 10),10000)), "+ + "c=describe(sample(weibullDistribution(1, 10),10000)),"+ + "d=describe(sample(weibullDistribution(6, 10),10000)),"+ + "e=mean(sample(weibullDistribution(1, 10),10000)),"+ + "f=mean(sample(weibullDistribution(1, 20),10000)),"+ + "g=mean(sample(weibullDistribution(1, 30),10000)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map a = (Map)tuples.get(0).get("a");+ Map a = (Map) tuples.get(0).get("a");@SuppressWarnings({"rawtypes"})- Map b = (Map)tuples.get(0).get("b");+ Map b = (Map) tuples.get(0).get("b");@SuppressWarnings({"rawtypes"})- Map c = (Map)tuples.get(0).get("c");+ Map c = (Map) tuples.get(0).get("c");@SuppressWarnings({"rawtypes"})- Map d = (Map)tuples.get(0).get("d");+ Map d = (Map) tuples.get(0).get("d");- Number sa = (Number)a.get("skewness");- Number sb = (Number)b.get("skewness");- Number sc = (Number)c.get("skewness");- Number sd = (Number)d.get("skewness");+ Number sa = (Number) a.get("skewness");+ Number sb = (Number) b.get("skewness");+ Number sc = (Number) c.get("skewness");+ Number sd = (Number) d.get("skewness");- //Test shape change+ // Test shape changeassertTrue(sa.doubleValue() > sb.doubleValue());assertTrue(sb.doubleValue() > sc.doubleValue());assertTrue(sc.doubleValue() > sd.doubleValue());assertTrue(sd.doubleValue() < 0.0);- //Test scale change+ // Test scale change- Number e = (Number)tuples.get(0).get("e");- Number f = (Number)tuples.get(0).get("f");- Number g = (Number)tuples.get(0).get("g");+ Number e = (Number) tuples.get(0).get("e");+ Number f = (Number) tuples.get(0).get("f");+ Number g = (Number) tuples.get(0).get("g");assertTrue(e.doubleValue() < f.doubleValue());assertTrue(f.doubleValue() < g.doubleValue());}@Test- // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 04-May-2018public void testGammaDistribution() throws Exception {- String cexpr = "#comment\nlet(echo=true, " +- "a=gammaDistribution(1, 10)," +- "b=sample(a, 10)," +- "c=cumulativeProbability(a, 5.10)," +- "d=probability(a, 5, 6))";+ String cexpr =+ "#comment\nlet(echo=true, "+ + "a=gammaDistribution(1, 10),"+ + "b=sample(a, 10),"+ + "c=cumulativeProbability(a, 5.10),"+ + "d=probability(a, 5, 6))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertEquals(tuples.size(), 1);@SuppressWarnings({"unchecked"})- List<Number> b = (List<Number>)tuples.get(0).get("b");+ List<Number> b = (List<Number>) tuples.get(0).get("b");assertEquals(10, b.size());- Number c = (Number)tuples.get(0).get("c");+ Number c = (Number) tuples.get(0).get("c");assertEquals(c.doubleValue(), 0.39950442118773394D, 0);- Number d = (Number)tuples.get(0).get("d");+ Number d = (Number) tuples.get(0).get("d");assertEquals(d.doubleValue(), 0.05771902361860709D, 0);}@Testpublic void testLogNormalDistribution() throws Exception {- String cexpr = "let(echo=true, " +- "a=describe(sample(logNormalDistribution(.1, 0),10000)), " +- "b=describe(sample(logNormalDistribution(.3, 0),10000)), " +- "c=describe(sample(logNormalDistribution(.6, 0),10000))," +- "d=mean(sample(logNormalDistribution(.3, 0),10000)), " +- "e=mean(sample(logNormalDistribution(.3, 2),10000)), " +- ")";+ String cexpr =+ "let(echo=true, "+ + "a=describe(sample(logNormalDistribution(.1, 0),10000)), "+ + "b=describe(sample(logNormalDistribution(.3, 0),10000)), "+ + "c=describe(sample(logNormalDistribution(.6, 0),10000)),"+ + "d=mean(sample(logNormalDistribution(.3, 0),10000)), "+ + "e=mean(sample(logNormalDistribution(.3, 2),10000)), "+ + ")";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map a = (Map)tuples.get(0).get("a");+ Map a = (Map) tuples.get(0).get("a");@SuppressWarnings({"rawtypes"})- Map b = (Map)tuples.get(0).get("b");+ Map b = (Map) tuples.get(0).get("b");@SuppressWarnings({"rawtypes"})- Map c = (Map)tuples.get(0).get("c");+ Map c = (Map) tuples.get(0).get("c");- Number sa = (Number)a.get("skewness");- Number sb = (Number)b.get("skewness");- Number sc = (Number)c.get("skewness");+ Number sa = (Number) a.get("skewness");+ Number sb = (Number) b.get("skewness");+ Number sc = (Number) c.get("skewness");assertTrue(sa.doubleValue() < sb.doubleValue());assertTrue(sb.doubleValue() < sc.doubleValue());- Number d = (Number)tuples.get(0).get("d");- Number e = (Number)tuples.get(0).get("e");+ Number d = (Number) tuples.get(0).get("d");+ Number e = (Number) tuples.get(0).get("e");assertTrue(d.doubleValue() < e.doubleValue());-}@Testpublic void testTriangularDistribution() throws Exception {- String cexpr = "let(echo=true, " +- "a=describe(sample(triangularDistribution(10, 15, 30),10000)), " +- "b=describe(sample(triangularDistribution(10, 25, 30),10000)), " +- ")";+ String cexpr =+ "let(echo=true, "+ + "a=describe(sample(triangularDistribution(10, 15, 30),10000)), "+ + "b=describe(sample(triangularDistribution(10, 25, 30),10000)), "+ + ")";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"rawtypes"})- Map a = (Map)tuples.get(0).get("a");+ Map a = (Map) tuples.get(0).get("a");@SuppressWarnings({"rawtypes"})- Map b = (Map)tuples.get(0).get("b");+ Map b = (Map) tuples.get(0).get("b");- Number sa = (Number)a.get("skewness");- Number sb = (Number)b.get("skewness");+ Number sa = (Number) a.get("skewness");+ Number sb = (Number) b.get("skewness");- Number mina = (Number)a.get("min");- Number maxa = (Number)a.get("max");+ Number mina = (Number) a.get("min");+ Number maxa = (Number) a.get("max");assertTrue(sa.doubleValue() > 0);assertTrue(sb.doubleValue() < 0);@@ -5510,18 +5749,20 @@ public void testCache() throws Exception {@Testpublic void testCovMatrix() throws Exception {- String cexpr = "let(a=array(1,2,3), b=array(2,4,6), c=array(4, 8, 12), d=transpose(matrix(a, b, c)), f=cov(d))";+ String cexpr =+ "let(a=array(1,2,3), b=array(2,4,6), c=array(4, 8, 12), d=transpose(matrix(a, b, c)), f=cov(d))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> cm = (List<List<Number>>)tuples.get(0).get("f");+ List<List<Number>> cm = (List<List<Number>>) tuples.get(0).get("f");assertEquals(cm.size(), 3);List<Number> row1 = cm.get(0);assertEquals(row1.size(), 3);@@ -5545,27 +5786,29 @@ public void testCache() throws Exception {@Test@SuppressWarnings({"unchecked"})public void testCorrMatrix() throws Exception {- String cexpr = "let(echo=true," +- "a=array(1,2,3), " +- "b=array(2,4,6), " +- "c=array(4, 8, 52), " +- "d=transpose(matrix(a, b, c)), " +- "f=corr(d), " +- "g=corr(d, type=kendalls), " +- "h=corr(d, type=spearmans)," +- "i=corrPValues(f)," +- " j=getRowLabels(f)," +- " k=getColumnLabels(f))";+ String cexpr =+ "let(echo=true,"+ + "a=array(1,2,3), "+ + "b=array(2,4,6), "+ + "c=array(4, 8, 52), "+ + "d=transpose(matrix(a, b, c)), "+ + "f=corr(d), "+ + "g=corr(d, type=kendalls), "+ + "h=corr(d, type=spearmans),"+ + "i=corrPValues(f),"+ + " j=getRowLabels(f),"+ + " k=getColumnLabels(f))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<List<Number>> cm = (List<List<Number>>)tuples.get(0).get("f");+ List<List<Number>> cm = (List<List<Number>>) tuples.get(0).get("f");assertEquals(cm.size(), 3);List<Number> row1 = cm.get(0);assertEquals(row1.size(), 3);@@ -5585,7 +5828,7 @@ public void testCache() throws Exception {assertEquals(row3.get(1).doubleValue(), 0.901127113779166, 0);assertEquals(row3.get(2).doubleValue(), 1, 0);- cm = (List<List<Number>>)tuples.get(0).get("g");+ cm = (List<List<Number>>) tuples.get(0).get("g");assertEquals(cm.size(), 3);row1 = cm.get(0);assertEquals(row1.size(), 3);@@ -5605,7 +5848,7 @@ public void testCache() throws Exception {assertEquals(row3.get(1).doubleValue(), 1, 0);assertEquals(row3.get(2).doubleValue(), 1, 0);- cm = (List<List<Number>>)tuples.get(0).get("h");+ cm = (List<List<Number>>) tuples.get(0).get("h");assertEquals(cm.size(), 3);row1 = cm.get(0);assertEquals(row1.size(), 3);@@ -5625,7 +5868,7 @@ public void testCache() throws Exception {assertEquals(row3.get(1).doubleValue(), 1, 0);assertEquals(row3.get(2).doubleValue(), 1, 0);- cm = (List<List<Number>>)tuples.get(0).get("i");+ cm = (List<List<Number>>) tuples.get(0).get("i");assertEquals(cm.size(), 3);row1 = cm.get(0);assertEquals(row1.size(), 3);@@ -5645,28 +5888,28 @@ public void testCache() throws Exception {assertEquals(row3.get(1).doubleValue(), 0.28548201004998375, 0);assertEquals(row3.get(2).doubleValue(), 0, 0);- List<String> rowLabels = (List<String>)tuples.get(0).get("j");+ List<String> rowLabels = (List<String>) tuples.get(0).get("j");assertEquals(rowLabels.size(), 3);assertEquals(rowLabels.get(0), "col0");assertEquals(rowLabels.get(1), "col1");assertEquals(rowLabels.get(2), "col2");- List<String> colLabels = (List<String>)tuples.get(0).get("k");+ List<String> colLabels = (List<String>) tuples.get(0).get("k");assertEquals(colLabels.size(), 3);assertEquals(colLabels.get(0), "col0");assertEquals(colLabels.get(1), "col1");assertEquals(colLabels.get(2), "col2");--}@Testpublic void testPrecision() throws Exception {- String cexpr = "let(echo=true, a=precision(array(1.44445, 1, 2.00006), 4), b=precision(1.44445, 4))";+ String cexpr =+ "let(echo=true, a=precision(array(1.44445, 1, 2.00006), 4), b=precision(1.44445, 4))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -5674,7 +5917,7 @@ public void testCache() throws Exception {assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> nums = (List<Number>)tuples.get(0).get("a");+ List<Number> nums = (List<Number>) tuples.get(0).get("a");assertTrue(nums.size() == 3);assertEquals(nums.get(0).doubleValue(), 1.4445, 0.0);assertEquals(nums.get(1).doubleValue(), 1, 0.0);@@ -5686,11 +5929,13 @@ public void testCache() throws Exception {@Testpublic void testPrecisionMatrix() throws Exception {- String cexpr = "let(a=matrix(array(1.3333999, 2.4444445), array(2.333333, 10.10009)), b=precision(a, 4))";+ String cexpr =+ "let(a=matrix(array(1.3333999, 2.4444445), array(2.333333, 10.10009)), b=precision(a, 4))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);@@ -5698,79 +5943,81 @@ public void testCache() throws Exception {assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<List<Number>> rows = (List<List<Number>>)tuples.get(0).get("b");+ List<List<Number>> rows = (List<List<Number>>) tuples.get(0).get("b");assertTrue(rows.size() == 2);List<Number> row1 = rows.get(0);assertTrue(row1.size() == 2);assertEquals(row1.get(0).doubleValue(), 1.3334, 0);- assertEquals(row1.get(1).doubleValue(), 2.4444, 0);+ assertEquals(row1.get(1).doubleValue(), 2.4444, 0);List<Number> row2 = rows.get(1);assertTrue(row2.size() == 2);assertEquals(row2.get(0).doubleValue(), 2.3333, 0);- assertEquals(row2.get(1).doubleValue(), 10.1001, 0);+ assertEquals(row2.get(1).doubleValue(), 10.1001, 0);}@Test@SuppressWarnings({"unchecked"})public void testMinMaxScale() throws Exception {- String cexpr = "let(echo=true, a=minMaxScale(matrix(array(1,2,3,4,5), array(10,20,30,40,50))), " +- "b=minMaxScale(matrix(array(1,2,3,4,5), array(10,20,30,40,50)), 0, 100)," +- "c=minMaxScale(array(1,2,3,4,5))," +- "d=minMaxScale(array(1,2,3,4,5), 0, 100))";+ String cexpr =+ "let(echo=true, a=minMaxScale(matrix(array(1,2,3,4,5), array(10,20,30,40,50))), "+ + "b=minMaxScale(matrix(array(1,2,3,4,5), array(10,20,30,40,50)), 0, 100),"+ + "c=minMaxScale(array(1,2,3,4,5)),"+ + "d=minMaxScale(array(1,2,3,4,5), 0, 100))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- List<List<Number>> matrix = (List<List<Number>>)tuples.get(0).get("a");+ List<List<Number>> matrix = (List<List<Number>>) tuples.get(0).get("a");List<Number> row1 = matrix.get(0);- assertEquals(row1.get(0).doubleValue(), 0,0);- assertEquals(row1.get(1).doubleValue(), .25,0);- assertEquals(row1.get(2).doubleValue(), .5,0);+ assertEquals(row1.get(0).doubleValue(), 0, 0);+ assertEquals(row1.get(1).doubleValue(), .25, 0);+ assertEquals(row1.get(2).doubleValue(), .5, 0);assertEquals(row1.get(3).doubleValue(), .75, 0);assertEquals(row1.get(4).doubleValue(), 1, 0);List<Number> row2 = matrix.get(1);- assertEquals(row2.get(0).doubleValue(), 0,0);- assertEquals(row2.get(1).doubleValue(), .25,0);- assertEquals(row2.get(2).doubleValue(), .5,0);- assertEquals(row2.get(3).doubleValue(), .75,0);- assertEquals(row2.get(4).doubleValue(), 1,0);+ assertEquals(row2.get(0).doubleValue(), 0, 0);+ assertEquals(row2.get(1).doubleValue(), .25, 0);+ assertEquals(row2.get(2).doubleValue(), .5, 0);+ assertEquals(row2.get(3).doubleValue(), .75, 0);+ assertEquals(row2.get(4).doubleValue(), 1, 0);- matrix = (List<List<Number>>)tuples.get(0).get("b");+ matrix = (List<List<Number>>) tuples.get(0).get("b");row1 = matrix.get(0);- assertEquals(row1.get(0).doubleValue(), 0,0);- assertEquals(row1.get(1).doubleValue(), 25,0);- assertEquals(row1.get(2).doubleValue(), 50,0);- assertEquals(row1.get(3).doubleValue(), 75,0);- assertEquals(row1.get(4).doubleValue(), 100,0);+ assertEquals(row1.get(0).doubleValue(), 0, 0);+ assertEquals(row1.get(1).doubleValue(), 25, 0);+ assertEquals(row1.get(2).doubleValue(), 50, 0);+ assertEquals(row1.get(3).doubleValue(), 75, 0);+ assertEquals(row1.get(4).doubleValue(), 100, 0);row2 = matrix.get(1);- assertEquals(row2.get(0).doubleValue(), 0,0);- assertEquals(row2.get(1).doubleValue(), 25,0);- assertEquals(row2.get(2).doubleValue(), 50,0);- assertEquals(row2.get(3).doubleValue(), 75,0);- assertEquals(row2.get(4).doubleValue(), 100,0);+ assertEquals(row2.get(0).doubleValue(), 0, 0);+ assertEquals(row2.get(1).doubleValue(), 25, 0);+ assertEquals(row2.get(2).doubleValue(), 50, 0);+ assertEquals(row2.get(3).doubleValue(), 75, 0);+ assertEquals(row2.get(4).doubleValue(), 100, 0);- List<Number> row3= (List<Number>)tuples.get(0).get("c");- assertEquals(row3.get(0).doubleValue(), 0,0);- assertEquals(row3.get(1).doubleValue(), .25,0);- assertEquals(row3.get(2).doubleValue(), .5,0);- assertEquals(row3.get(3).doubleValue(), .75,0);- assertEquals(row3.get(4).doubleValue(), 1,0);+ List<Number> row3 = (List<Number>) tuples.get(0).get("c");+ assertEquals(row3.get(0).doubleValue(), 0, 0);+ assertEquals(row3.get(1).doubleValue(), .25, 0);+ assertEquals(row3.get(2).doubleValue(), .5, 0);+ assertEquals(row3.get(3).doubleValue(), .75, 0);+ assertEquals(row3.get(4).doubleValue(), 1, 0);- List<Number> row4= (List<Number>)tuples.get(0).get("d");- assertEquals(row4.get(0).doubleValue(), 0,0);- assertEquals(row4.get(1).doubleValue(), 25,0);- assertEquals(row4.get(2).doubleValue(), 50,0);- assertEquals(row4.get(3).doubleValue(), 75,0);- assertEquals(row4.get(4).doubleValue(), 100,0);+ List<Number> row4 = (List<Number>) tuples.get(0).get("d");+ assertEquals(row4.get(0).doubleValue(), 0, 0);+ assertEquals(row4.get(1).doubleValue(), 25, 0);+ assertEquals(row4.get(2).doubleValue(), 50, 0);+ assertEquals(row4.get(3).doubleValue(), 75, 0);+ assertEquals(row4.get(4).doubleValue(), 100, 0);}@Test@@ -5779,47 +6026,50 @@ public void testCache() throws Exception {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number mean = (Number)tuples.get(0).get("return-value");+ Number mean = (Number) tuples.get(0).get("return-value");assertEquals(mean.doubleValue(), 3.0D, 0.0D);}@Testpublic void testNorms() throws Exception {- String cexpr = "let(echo=true, " +- " a=array(1,2,3,4,5,6), " +- " b=l1norm(a), " +- " c=l2norm(a), " +- " d=linfnorm(a), " +- " e=sqrt(add(pow(a, 2)))," +- " f=add(abs(a)))";+ String cexpr =+ "let(echo=true, "+ + " a=array(1,2,3,4,5,6), "+ + " b=l1norm(a), "+ + " c=l2norm(a), "+ + " d=linfnorm(a), "+ + " e=sqrt(add(pow(a, 2))),"+ + " f=add(abs(a)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- Number l1norm = (Number)tuples.get(0).get("b");+ Number l1norm = (Number) tuples.get(0).get("b");assertEquals(l1norm.doubleValue(), 21.0D, 0.0D);- Number norm = (Number)tuples.get(0).get("c");+ Number norm = (Number) tuples.get(0).get("c");assertEquals(norm.doubleValue(), 9.5393920141695, 0.0001D);- Number inorm = (Number)tuples.get(0).get("d");+ Number inorm = (Number) tuples.get(0).get("d");assertEquals(inorm.doubleValue(), 6.0, 0.0);- Number norm2 = (Number)tuples.get(0).get("e");+ Number norm2 = (Number) tuples.get(0).get("e");assertEquals(norm.doubleValue(), norm2.doubleValue(), 0.0);- Number l1norm2 = (Number)tuples.get(0).get("f");+ Number l1norm2 = (Number) tuples.get(0).get("f");assertEquals(l1norm.doubleValue(), l1norm2.doubleValue(), 0.0);}@@ -5827,38 +6077,47 @@ public void testCache() throws Exception {public void testScale() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";- String cexpr = "let(a="+expr+", c=col(a, max(price_f)), tuple(reverse=rev(c), scaled=scale(2, c)))";+ String cexpr =+ "let(a=" + expr + ", c=col(a, max(price_f)), tuple(reverse=rev(c), scaled=scale(2, c)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -5866,7 +6125,7 @@ public void testCache() throws Exception {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> reverse = (List<Number>)tuples.get(0).get("reverse");+ List<Number> reverse = (List<Number>) tuples.get(0).get("reverse");assertTrue(reverse.size() == 4);assertTrue(reverse.get(0).doubleValue() == 400D);assertTrue(reverse.get(1).doubleValue() == 300D);@@ -5874,7 +6133,7 @@ public void testCache() throws Exception {assertTrue(reverse.get(3).doubleValue() == 100D);@SuppressWarnings({"unchecked"})- List<Number> ranked = (List<Number>)tuples.get(0).get("scaled");+ List<Number> ranked = (List<Number>) tuples.get(0).get("scaled");assertTrue(ranked.size() == 4);assertTrue(ranked.get(0).doubleValue() == 200D);assertTrue(ranked.get(1).doubleValue() == 1000D);@@ -5886,38 +6145,51 @@ public void testCache() throws Exception {public void testConvolution() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");+ while (i < 100) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2015", "5", "1"), "price_f", "300.0");}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");+ while (i < 150) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2014", "5", "1"), "price_f", "500.0");}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");+ while (i < 250) {+ updateRequest.add(+ id, "id_" + (++i), "test_dt", getDateString("2013", "5", "1"), "price_f", "100.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";- String cexpr = "let(a="+expr+", b=select("+expr+",mult(2, count(*)) as nvalue), c=col(a, count(*)), d=col(b, nvalue), tuple(colc=c, cold=d, conv=conv(c,d)))";+ String cexpr =+ "let(a="+ + expr+ + ", b=select("+ + expr+ + ",mult(2, count(*)) as nvalue), c=col(a, count(*)), d=col(b, nvalue), tuple(colc=c, cold=d, conv=conv(c,d)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -5925,7 +6197,7 @@ public void testCache() throws Exception {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked"})- List<Number> convolution = (List<Number>)(tuples.get(0)).get("conv");+ List<Number> convolution = (List<Number>) (tuples.get(0)).get("conv");assertTrue(convolution.size() == 7);assertTrue(convolution.get(0).equals(20000D));assertTrue(convolution.get(1).equals(20000D));@@ -5957,16 +6229,28 @@ public void testCache() throws Exception {updateRequest.add(id, "14", "price_f", "1200.0", "col_s", "b", "order_i", "7");updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr1 = "search("+COLLECTIONORALIAS+", q=\"col_s:a\", fl=\"price_f, order_i\", sort=\"order_i asc\")";- String expr2 = "search("+COLLECTIONORALIAS+", q=\"col_s:b\", fl=\"price_f, order_i\", sort=\"order_i asc\")";+ String expr1 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:a\", fl=\"price_f, order_i\", sort=\"order_i asc\")";+ String expr2 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:b\", fl=\"price_f, order_i\", sort=\"order_i asc\")";- String cexpr = "let(a="+expr1+", b="+expr2+", c=col(a, price_f), d=col(b, price_f), e=regress(c, d), tuple(regress=e, p=predict(e, 300), pl=predict(e, c)))";+ String cexpr =+ "let(a="+ + expr1+ + ", b="+ + expr2+ + ", c=col(a, price_f), d=col(b, price_f), e=regress(c, d), tuple(regress=e, p=predict(e, 300), pl=predict(e, c)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -5975,17 +6259,17 @@ public void testCache() throws Exception {assertTrue(tuples.size() == 1);Tuple tuple = tuples.get(0);@SuppressWarnings({"rawtypes"})- Map regression = (Map)tuple.get("regress");- double slope = (double)regression.get("slope");- double intercept= (double) regression.get("intercept");- double rSquare= (double) regression.get("RSquared");+ Map regression = (Map) tuple.get("regress");+ double slope = (double) regression.get("slope");+ double intercept = (double) regression.get("intercept");+ double rSquare = (double) regression.get("RSquared");assertTrue(slope == 2.0D);assertTrue(intercept == 0.0D);assertTrue(rSquare == 1.0D);double prediction = tuple.getDouble("p");assertTrue(prediction == 600.0D);@SuppressWarnings({"unchecked"})- List<Number> predictions = (List<Number>)tuple.get("pl");+ List<Number> predictions = (List<Number>) tuple.get("pl");assertList(predictions, 200D, 400D, 600D, 200D, 400D, 800D, 1200D);}@@ -5993,7 +6277,7 @@ public void testCache() throws Exception {public void testFinddelay() throws Exception {UpdateRequest updateRequest = new UpdateRequest();- //Pad column 1 with three zeros.+ // Pad column 1 with three zeros.updateRequest.add(id, "10", "price_f", "0.0", "col_s", "a", "order_i", "0");updateRequest.add(id, "11", "price_f", "0.0", "col_s", "a", "order_i", "0");updateRequest.add(id, "12", "price_f", "0.0", "col_s", "a", "order_i", "0");@@ -6013,7 +6297,6 @@ public void testCache() throws Exception {updateRequest.add(id, "105", "price_f", "800.0", "col_s", "b", "order_i", "6");updateRequest.add(id, "106", "price_f", "1200.0", "col_s", "b", "order_i", "7");-updateRequest.add(id, "200", "price_f", "-200.0", "col_s", "c", "order_i", "1");updateRequest.add(id, "301", "price_f", "-400.0", "col_s", "c", "order_i", "2");updateRequest.add(id, "402", "price_f", "-600.0", "col_s", "c", "order_i", "3");@@ -6023,16 +6306,28 @@ public void testCache() throws Exception {updateRequest.add(id, "806", "price_f", "-1200.0", "col_s", "c", "order_i", "7");updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr1 = "search("+COLLECTIONORALIAS+", q=\"col_s:a\", fl=\"price_f, order_i\", sort=\"order_i asc\")";- String expr2 = "search("+COLLECTIONORALIAS+", q=\"col_s:b\", fl=\"price_f, order_i\", sort=\"order_i asc\")";+ String expr1 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:a\", fl=\"price_f, order_i\", sort=\"order_i asc\")";+ String expr2 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:b\", fl=\"price_f, order_i\", sort=\"order_i asc\")";- String cexpr = "let(a="+expr1+", b="+expr2+", c=col(a, price_f), d=col(b, price_f), tuple(delay=finddelay(c, d)))";+ String cexpr =+ "let(a="+ + expr1+ + ", b="+ + expr2+ + ", c=col(a, price_f), d=col(b, price_f), tuple(delay=finddelay(c, d)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -6041,12 +6336,23 @@ public void testCache() throws Exception {assertTrue(tuples.size() == 1);Tuple tuple = tuples.get(0);long delay = tuple.getLong("delay");- assert(delay == 3);-- expr1 = "search("+COLLECTIONORALIAS+", q=\"col_s:a\", fq=\"id:(1 2 3 4 5 6 7)\", fl=\"price_f, order_i\", sort=\"order_i asc\")";- expr2 = "search("+COLLECTIONORALIAS+", q=\"col_s:b\", fl=\"price_f, order_i\", sort=\"order_i asc\")";-- cexpr = "let(a="+expr1+", b="+expr2+", c=col(a, price_f), d=col(b, price_f), tuple(delay=finddelay(c, d)))";+ assert (delay == 3);++ expr1 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:a\", fq=\"id:(1 2 3 4 5 6 7)\", fl=\"price_f, order_i\", sort=\"order_i asc\")";+ expr2 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:b\", fl=\"price_f, order_i\", sort=\"order_i asc\")";++ cexpr =+ "let(a="+ + expr1+ + ", b="+ + expr2+ + ", c=col(a, price_f), d=col(b, price_f), tuple(delay=finddelay(c, d)))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -6059,13 +6365,24 @@ public void testCache() throws Exception {assertTrue(tuples.size() == 1);tuple = tuples.get(0);delay = tuple.getLong("delay");- assert(delay == 0);-- //Test negative correlation.- expr1 = "search("+COLLECTIONORALIAS+", q=\"col_s:a\", fq=\"id:(1 2 3 4 5 6 7 11 12)\",fl=\"price_f, order_i\", sort=\"order_i asc\")";- expr2 = "search("+COLLECTIONORALIAS+", q=\"col_s:c\", fl=\"price_f, order_i\", sort=\"order_i asc\")";-- cexpr = "let(a="+expr1+", b="+expr2+", c=col(a, price_f), d=col(b, price_f), tuple(delay=finddelay(c, d)))";+ assert (delay == 0);++ // Test negative correlation.+ expr1 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:a\", fq=\"id:(1 2 3 4 5 6 7 11 12)\",fl=\"price_f, order_i\", sort=\"order_i asc\")";+ expr2 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:c\", fl=\"price_f, order_i\", sort=\"order_i asc\")";++ cexpr =+ "let(a="+ + expr1+ + ", b="+ + expr2+ + ", c=col(a, price_f), d=col(b, price_f), tuple(delay=finddelay(c, d)))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);@@ -6078,7 +6395,7 @@ public void testCache() throws Exception {assertTrue(tuples.size() == 1);tuple = tuples.get(0);delay = tuple.getLong("delay");- assert(delay == 2);+ assert (delay == 2);}@Test@@ -6095,15 +6412,19 @@ public void testCache() throws Exception {updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr1 = "search("+COLLECTIONORALIAS+", q=\"col_s:a\", fl=\"price_f, order_i\", sort=\"order_i asc\")";+ String expr1 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:a\", fl=\"price_f, order_i\", sort=\"order_i asc\")";- String cexpr = "let(a="+expr1+", b=col(a, price_f), stats=describe(b))";+ String cexpr = "let(a=" + expr1 + ", b=col(a, price_f), stats=describe(b))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -6111,16 +6432,16 @@ public void testCache() throws Exception {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);Tuple stats = tuples.get(0);- Number min = (Number)stats.get("min");- Number max = (Number)stats.get("max");- Number mean = (Number)stats.get("mean");- Number stdev = (Number)stats.get("stdev");- Number popVar = (Number)stats.get("popVar");- Number skewness = (Number)stats.get("skewness");- Number kurtosis = (Number)stats.get("kurtosis");- Number var = (Number)stats.get("var");- Number geometricMean = (Number)stats.get("geometricMean");- Number N = (Number)stats.get("N");+ Number min = (Number) stats.get("min");+ Number max = (Number) stats.get("max");+ Number mean = (Number) stats.get("mean");+ Number stdev = (Number) stats.get("stdev");+ Number popVar = (Number) stats.get("popVar");+ Number skewness = (Number) stats.get("skewness");+ Number kurtosis = (Number) stats.get("kurtosis");+ Number var = (Number) stats.get("var");+ Number geometricMean = (Number) stats.get("geometricMean");+ Number N = (Number) stats.get("N");assertEquals(min.doubleValue(), 100.0D, 0.0);assertEquals(max.doubleValue(), 600.0D, 0.0);assertEquals(N.doubleValue(), 7.0D, 0.0);@@ -6153,16 +6474,28 @@ public void testCache() throws Exception {updateRequest.add(id, "14", "price_f", "1200.0", "col_s", "b", "order_i", "7");updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr1 = "search("+COLLECTIONORALIAS+", q=\"col_s:a\", fl=\"price_f, order_i\", sort=\"order_i asc\")";- String expr2 = "search("+COLLECTIONORALIAS+", q=\"col_s:b\", fl=\"price_f, order_i\", sort=\"order_i asc\")";+ String expr1 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:a\", fl=\"price_f, order_i\", sort=\"order_i asc\")";+ String expr2 =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"col_s:b\", fl=\"price_f, order_i\", sort=\"order_i asc\")";- String cexpr = "let(a="+expr1+", b="+expr2+", c=col(a, price_f), d=col(b, price_f), e=regress(c, d), tuple(regress=e, p=predict(e, 300), l=length(d)))";+ String cexpr =+ "let(a="+ + expr1+ + ", b="+ + expr2+ + ", c=col(a, price_f), d=col(b, price_f), e=regress(c, d), tuple(regress=e, p=predict(e, 300), l=length(d)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -6171,9 +6504,9 @@ public void testCache() throws Exception {assertTrue(tuples.size() == 1);Tuple tuple = tuples.get(0);@SuppressWarnings({"rawtypes"})- Map regression = (Map)tuple.get("regress");- double slope = (double)regression.get("slope");- double intercept= (double) regression.get("intercept");+ Map regression = (Map) tuple.get("regress");+ double slope = (double) regression.get("slope");+ double intercept = (double) regression.get("intercept");double length = tuple.getDouble("l");assertTrue(slope == 2.0D);@@ -6192,24 +6525,27 @@ public void testCache() throws Exception {updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- //Test annotating tuple+ // Test annotating tupleString expr = "select(calc(), convert(miles, kilometers, 10) as kilometers)";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- double d = (double)tuples.get(0).get("kilometers");- assertTrue(d == (10*1.61));-+ double d = (double) tuples.get(0).get("kilometers");+ assertTrue(d == (10 * 1.61));- expr = "select(search("+COLLECTIONORALIAS+", q=\"*:*\", sort=\"miles_i asc\", fl=\"miles_i\"), convert(miles, kilometers, miles_i) as kilometers)";+ expr =+ "select(search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", sort=\"miles_i asc\", fl=\"miles_i\"), convert(miles, kilometers, miles_i) as kilometers)";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -6219,12 +6555,17 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 2);- d = (double)tuples.get(0).get("kilometers");- assertTrue(d == (50*1.61));- d = (double)tuples.get(1).get("kilometers");- assertTrue(d == (70*1.61));-- expr = "parallel("+COLLECTIONORALIAS+", workers=2, sort=\"miles_i asc\", select(search("+COLLECTIONORALIAS+", q=\"*:*\", partitionKeys=miles_i, sort=\"miles_i asc\", fl=\"miles_i\", qt=\"/export\"), convert(miles, kilometers, miles_i) as kilometers))";+ d = (double) tuples.get(0).get("kilometers");+ assertTrue(d == (50 * 1.61));+ d = (double) tuples.get(1).get("kilometers");+ assertTrue(d == (70 * 1.61));++ expr =+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"miles_i asc\", select(search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", partitionKeys=miles_i, sort=\"miles_i asc\", fl=\"miles_i\", qt=\"/export\"), convert(miles, kilometers, miles_i) as kilometers))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -6233,12 +6574,15 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 2);- d = (double)tuples.get(0).get("kilometers");- assertTrue(d == (50*1.61));- d = (double)tuples.get(1).get("kilometers");- assertTrue(d == (70*1.61));-- expr = "select(stats("+COLLECTIONORALIAS+", q=\"*:*\", sum(miles_i)), convert(miles, kilometers, sum(miles_i)) as kilometers)";+ d = (double) tuples.get(0).get("kilometers");+ assertTrue(d == (50 * 1.61));+ d = (double) tuples.get(1).get("kilometers");+ assertTrue(d == (70 * 1.61));++ expr =+ "select(stats("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", sum(miles_i)), convert(miles, kilometers, sum(miles_i)) as kilometers)";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -6247,8 +6591,8 @@ public void testCache() throws Exception {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- d = (double)tuples.get(0).get("kilometers");- assertTrue(d == (120*1.61));+ d = (double) tuples.get(0).get("kilometers");+ assertTrue(d == (120 * 1.61));}protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {@@ -6266,21 +6610,21 @@ public void testCache() throws Exception {}public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {- long lv = (long)tuple.get(fieldName);- if(lv != l) {- throw new Exception("Longs not equal:"+l+" : "+lv);+ long lv = (long) tuple.get(fieldName);+ if (lv != l) {+ throw new Exception("Longs not equal:" + l + " : " + lv);}return true;}-+public boolean assertString(Tuple tuple, String fieldName, String expected) throws Exception {- String actual = (String)tuple.get(fieldName);-- if( (null == expected && null != actual) ||- (null != expected && null == actual) ||- (null != expected && !expected.equals(actual))){- throw new Exception("Longs not equal:"+expected+" : "+actual);+ String actual = (String) tuple.get(fieldName);++ if ((null == expected && null != actual)+ || (null != expected && null == actual)+ || (null != expected && !expected.equals(actual))) {+ throw new Exception("Longs not equal:" + expected + " : " + actual);}return true;diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.javaindex 639929fa215..6f07960af5c 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java@@ -17,6 +17,8 @@package org.apache.solr.client.solrj.io.stream;+import static org.apache.solr.client.solrj.io.stream.FacetStream.TIERED_PARAM;+import java.io.IOException;import java.util.ArrayList;import java.util.LinkedList;@@ -29,7 +31,6 @@ import java.util.TreeMap;import java.util.UUID;import java.util.stream.Collectors;import java.util.stream.Stream;-import org.apache.commons.math3.distribution.NormalDistribution;import org.apache.commons.math3.random.JDKRandomGenerator;import org.apache.commons.math3.random.RandomGenerator;@@ -57,10 +58,9 @@ import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;-import static org.apache.solr.client.solrj.io.stream.FacetStream.TIERED_PARAM;-/**- * Verify auto-plist with rollup over a facet expression when using collection alias over multiple collections.+ * Verify auto-plist with rollup over a facet expression when using collection alias over multiple+ * collections.*/@SolrTestCaseJ4.SuppressSSL@LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})@@ -69,7 +69,8 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {private static final String ALIAS_NAME = "SOME_ALIAS_WITH_MANY_COLLS";private static final String id = "id";- private static final int NUM_COLLECTIONS = 2; // this test requires at least 2 collections, each with multiple shards+ // this test requires at least 2 collections, each with multiple shards+ private static final int NUM_COLLECTIONS = 2;private static final int NUM_DOCS_PER_COLLECTION = 40;private static final int NUM_SHARDS_PER_COLLECTION = 4;private static final int CARDINALITY = 10;@@ -83,8 +84,16 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {public static void setupCluster() throws Exception {System.setProperty("solr.tests.numeric.dv", "true");- configureCluster(NUM_COLLECTIONS).withMetrics(false)- .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))+ configureCluster(NUM_COLLECTIONS)+ .withMetrics(false)+ .addConfig(+ "conf",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("streaming")+ .resolve("conf")).configure();cleanup();setupCollectionsAndAlias();@@ -92,9 +101,7 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {solrClientCache = new SolrClientCache();}- /**- * setup the testbed with necessary collections, documents, and alias- */+ /** setup the testbed with necessary collections, documents, and alias */public static void setupCollectionsAndAlias() throws Exception {final NormalDistribution[] dists = new NormalDistribution[CARDINALITY];@@ -104,28 +111,45 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {List<String> collections = new ArrayList<>(NUM_COLLECTIONS);final List<Exception> errors = new LinkedList<>();- Stream.iterate(1, n -> n + 1).limit(NUM_COLLECTIONS).forEach(colIdx -> {- final String collectionName = "coll" + colIdx;- collections.add(collectionName);- try {- CollectionAdminRequest.createCollection(collectionName, "conf", NUM_SHARDS_PER_COLLECTION, 1).process(cluster.getSolrClient());- cluster.waitForActiveCollection(collectionName, NUM_SHARDS_PER_COLLECTION, NUM_SHARDS_PER_COLLECTION);-- // want a variable num of docs per collection so that avg of avg does not work ;-)- final int numDocsInColl = colIdx % 2 == 0 ? NUM_DOCS_PER_COLLECTION / 2 : NUM_DOCS_PER_COLLECTION;- final int limit = NUM_COLLECTIONS == 1 ? NUM_DOCS_PER_COLLECTION * 2 : numDocsInColl;- UpdateRequest ur = new UpdateRequest();- Stream.iterate(0, n -> n + 1).limit(limit)- .forEach(docId -> ur.add(id, UUID.randomUUID().toString(),- "a_s", "hello" + docId,- "a_i", String.valueOf(docId % CARDINALITY),- "b_i", rand.nextBoolean() ? "1" : "0",- "a_d", String.valueOf(dists[docId % dists.length].sample())));- ur.commit(cluster.getSolrClient(), collectionName);- } catch (SolrServerException | IOException e) {- errors.add(e);- }- });+ Stream.iterate(1, n -> n + 1)+ .limit(NUM_COLLECTIONS)+ .forEach(+ colIdx -> {+ final String collectionName = "coll" + colIdx;+ collections.add(collectionName);+ try {+ CollectionAdminRequest.createCollection(+ collectionName, "conf", NUM_SHARDS_PER_COLLECTION, 1)+ .process(cluster.getSolrClient());+ cluster.waitForActiveCollection(+ collectionName, NUM_SHARDS_PER_COLLECTION, NUM_SHARDS_PER_COLLECTION);++ // want a variable num of docs per collection so that avg of avg does not work ;-)+ final int numDocsInColl =+ colIdx % 2 == 0 ? NUM_DOCS_PER_COLLECTION / 2 : NUM_DOCS_PER_COLLECTION;+ final int limit =+ NUM_COLLECTIONS == 1 ? NUM_DOCS_PER_COLLECTION * 2 : numDocsInColl;+ UpdateRequest ur = new UpdateRequest();+ Stream.iterate(0, n -> n + 1)+ .limit(limit)+ .forEach(+ docId ->+ ur.add(+ id,+ UUID.randomUUID().toString(),+ "a_s",+ "hello" + docId,+ "a_i",+ String.valueOf(docId % CARDINALITY),+ "b_i",+ rand.nextBoolean() ? "1" : "0",+ "a_d",+ String.valueOf(dists[docId % dists.length].sample())));+ ur.commit(cluster.getSolrClient(), collectionName);+ } catch (SolrServerException | IOException e) {+ errors.add(e);+ }+ });if (!errors.isEmpty()) {throw errors.get(0);@@ -133,7 +157,8 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {listOfCollections = collections;String aliasedCollectionString = String.join(",", collections);- CollectionAdminRequest.createAlias(ALIAS_NAME, aliasedCollectionString).process(cluster.getSolrClient());+ CollectionAdminRequest.createAlias(ALIAS_NAME, aliasedCollectionString)+ .process(cluster.getSolrClient());}public static void cleanup() throws Exception {@@ -142,13 +167,16 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {CollectionAdminRequest.deleteAlias(ALIAS_NAME).process(cluster.getSolrClient());if (listOfCollections != null) {final List<Exception> errors = new LinkedList<>();- listOfCollections.stream().map(CollectionAdminRequest::deleteCollection).forEach(c -> {- try {- c.process(cluster.getSolrClient());- } catch (SolrServerException | IOException e) {- errors.add(e);- }- });+ listOfCollections.stream()+ .map(CollectionAdminRequest::deleteCollection)+ .forEach(+ c -> {+ try {+ c.process(cluster.getSolrClient());+ } catch (SolrServerException | IOException e) {+ errors.add(e);+ }+ });if (!errors.isEmpty()) {throw errors.get(0);}@@ -165,76 +193,87 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {}}- /**- * Test parallelized calls to facet expression, one for each collection in the alias- */+ /** Test parallelized calls to facet expression, one for each collection in the alias */@Testpublic void testParallelFacetOverAlias() throws Exception {- String facetExprTmpl = "" +- "facet(\n" +- " %s,\n" +- " tiered=%s,\n" +- " q=\"*:*\", \n" +- " buckets=\"a_i\", \n" +- " bucketSorts=\"a_i asc\", \n" +- " bucketSizeLimit=" + BUCKET_SIZE_LIMIT + ", \n" +- " sum(a_d), avg(a_d), min(a_d), max(a_d), count(*)\n" +- ")\n";+ String facetExprTmpl =+ ""+ + "facet(\n"+ + " %s,\n"+ + " tiered=%s,\n"+ + " q=\"*:*\", \n"+ + " buckets=\"a_i\", \n"+ + " bucketSorts=\"a_i asc\", \n"+ + " bucketSizeLimit="+ + BUCKET_SIZE_LIMIT+ + ", \n"+ + " sum(a_d), avg(a_d), min(a_d), max(a_d), count(*)\n"+ + ")\n";compareTieredStreamWithNonTiered(facetExprTmpl, 1);}/**- * Test parallelized calls to facet expression with multiple dimensions, one for each collection in the alias+ * Test parallelized calls to facet expression with multiple dimensions, one for each collection+ * in the alias*/@Testpublic void testParallelFacetMultipleDimensionsOverAlias() throws Exception {- // notice we're sorting the stream by a metric, but internally, that doesn't work for parallelization- // so the rollup has to sort by dimensions and then apply a final re-sort once the parallel streams are merged- String facetExprTmpl = "" +- "facet(\n" +- " %s,\n" +- " tiered=%s,\n" +- " q=\"*:*\", \n" +- " buckets=\"a_i,b_i\", \n" + /* two dimensions here ~ doubles the number of tuples */- " bucketSorts=\"sum(a_d) desc\", \n" +- " bucketSizeLimit=" + BUCKET_SIZE_LIMIT + ", \n" +- " sum(a_d), avg(a_d), min(a_d), max(a_d), count(*)\n" +- ")\n";+ // notice we're sorting the stream by a metric, but internally, that doesn't work for+ // parallelization so the rollup has to sort by dimensions and then apply a final re-sort once+ // the parallel streams are merged+ String facetExprTmpl =+ ""+ + "facet(\n"+ + " %s,\n"+ + " tiered=%s,\n"+ + " q=\"*:*\", \n"+ + " buckets=\"a_i,b_i\", \n"+ + /* two dimensions here ~ doubles the number of tuples */ " bucketSorts=\"sum(a_d) desc\", \n"+ + " bucketSizeLimit="+ + BUCKET_SIZE_LIMIT+ + ", \n"+ + " sum(a_d), avg(a_d), min(a_d), max(a_d), count(*)\n"+ + ")\n";compareTieredStreamWithNonTiered(facetExprTmpl, 2);}@Testpublic void testParallelFacetSortByDimensions() throws Exception {- // notice we're sorting the stream by a metric, but internally, that doesn't work for parallelization- // so the rollup has to sort by dimensions and then apply a final re-sort once the parallel streams are merged- String facetExprTmpl = "" +- "facet(\n" +- " %s,\n" +- " tiered=%s,\n" +- " q=\"*:*\", \n" +- " buckets=\"a_i,b_i\", \n" +- " bucketSorts=\"a_i asc, b_i asc\", \n" +- " bucketSizeLimit=" + BUCKET_SIZE_LIMIT + ", \n" +- " sum(a_d), avg(a_d), min(a_d), max(a_d), count(*)\n" +- ")\n";+ // notice we're sorting the stream by a metric, but internally, that doesn't work for+ // parallelization so the rollup has to sort by dimensions and then apply a final re-sort once+ // the parallel streams are merged+ String facetExprTmpl =+ ""+ + "facet(\n"+ + " %s,\n"+ + " tiered=%s,\n"+ + " q=\"*:*\", \n"+ + " buckets=\"a_i,b_i\", \n"+ + " bucketSorts=\"a_i asc, b_i asc\", \n"+ + " bucketSizeLimit="+ + BUCKET_SIZE_LIMIT+ + ", \n"+ + " sum(a_d), avg(a_d), min(a_d), max(a_d), count(*)\n"+ + ")\n";compareTieredStreamWithNonTiered(facetExprTmpl, 2);}@Testpublic void testParallelStats() throws Exception {- Metric[] metrics = new Metric[]{- new CountMetric(),- new CountDistinctMetric("a_i"),- new SumMetric("b_i"),- new MinMetric("a_i"),- new MaxMetric("a_i"),- new MeanMetric("a_d")- };+ Metric[] metrics =+ new Metric[] {+ new CountMetric(),+ new CountDistinctMetric("a_i"),+ new SumMetric("b_i"),+ new MinMetric("a_i"),+ new MaxMetric("a_i"),+ new MeanMetric("a_d")+ };String zkHost = cluster.getZkServer().getZkAddress();StreamContext streamContext = new StreamContext();@@ -267,7 +306,8 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new SolrDefaultStreamFactory().withDefaultZkHost(cluster.getZkServer().getZkAddress());+ StreamFactory factory =+ new SolrDefaultStreamFactory().withDefaultZkHost(cluster.getZkServer().getZkAddress());TupleStream stream = factory.constructStream(facetExpr);stream.setStreamContext(streamContext);@@ -296,7 +336,8 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {assertEquals(NUM_COLLECTIONS, parallelStreams.length);assertTrue(parallelStreams[0] instanceof FacetStream);- Optional<Metric[]> rollupMetrics = facetStream.getRollupMetrics(facetStream.getMetrics().toArray(new Metric[0]));+ Optional<Metric[]> rollupMetrics =+ facetStream.getRollupMetrics(facetStream.getMetrics().toArray(new Metric[0]));assertTrue(rollupMetrics.isPresent());assertEquals(5, rollupMetrics.get().length);Map<String, String> selectFields = facetStream.getRollupSelectFields(rollupMetrics.get());@@ -315,8 +356,10 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {// assert results are the same, with some sorting and rounding of floating point valuesprivate void assertListOfTuplesEquals(List<Tuple> exp, List<Tuple> act) {- List<SortedMap<Object, Object>> expList = exp.stream().map(this::toComparableMap).collect(Collectors.toList());- List<SortedMap<Object, Object>> actList = act.stream().map(this::toComparableMap).collect(Collectors.toList());+ List<SortedMap<Object, Object>> expList =+ exp.stream().map(this::toComparableMap).collect(Collectors.toList());+ List<SortedMap<Object, Object>> actList =+ act.stream().map(this::toComparableMap).collect(Collectors.toList());assertEquals(expList, actList);}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/RecordCountStream.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/RecordCountStream.javaindex f1974bd5606..35137e0ca99 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/RecordCountStream.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/RecordCountStream.java@@ -21,15 +21,14 @@ import java.io.Serializable;import java.util.ArrayList;import java.util.List;import java.util.Locale;-import org.apache.solr.client.solrj.io.Tuple;import org.apache.solr.client.solrj.io.comp.StreamComparator;import org.apache.solr.client.solrj.io.stream.expr.Explanation;+import org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType;import org.apache.solr.client.solrj.io.stream.expr.Expressible;import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;-import org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType;public class RecordCountStream extends TupleStream implements Expressible, Serializable {@@ -39,59 +38,64 @@ public class RecordCountStream extends TupleStream implements Expressible, Seriapublic RecordCountStream(TupleStream stream) {this.stream = stream;}-- public RecordCountStream(StreamExpression expression, StreamFactory factory) throws IOException{- List<StreamExpression> streamExpressions = factory.getExpressionOperandsRepresentingTypes(expression, Expressible.class, TupleStream.class);-++ public RecordCountStream(StreamExpression expression, StreamFactory factory) throws IOException {+ List<StreamExpression> streamExpressions =+ factory.getExpressionOperandsRepresentingTypes(+ expression, Expressible.class, TupleStream.class);+// validate expression contains only what we want.- if(expression.getParameters().size() != streamExpressions.size()){- throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - unknown operands found", expression));+ if (expression.getParameters().size() != streamExpressions.size()) {+ throw new IOException(+ String.format(Locale.ROOT, "Invalid expression %s - unknown operands found", expression));}-- if(1 != streamExpressions.size()){- throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting a single stream but found %d",expression, streamExpressions.size()));++ if (1 != streamExpressions.size()) {+ throw new IOException(+ String.format(+ Locale.ROOT,+ "Invalid expression %s - expecting a single stream but found %d",+ expression,+ streamExpressions.size()));}-+stream = factory.constructStream(streamExpressions.get(0));}-+@Override- public StreamExpression toExpression(StreamFactory factory) throws IOException{+ public StreamExpression toExpression(StreamFactory factory) throws IOException {return toExpression(factory, true);}-- private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {++ private StreamExpression toExpression(StreamFactory factory, boolean includeStreams)+ throws IOException {// function nameStreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));-- if(includeStreams){++ if (includeStreams) {// stream- if(stream instanceof Expressible){- expression.addParameter(((Expressible)stream).toExpression(factory));+ if (stream instanceof Expressible) {+ expression.addParameter(((Expressible) stream).toExpression(factory));+ } else {+ throw new IOException(+ "This RecordCountStream contains a non-expressible TupleStream - it cannot be converted to an expression");}- else{- throw new IOException("This RecordCountStream contains a non-expressible TupleStream - it cannot be converted to an expression");- }- }- else{+ } else {expression.addParameter("<stream>");}-+return expression;}-+@Overridepublic Explanation toExplanation(StreamFactory factory) throws IOException {return new StreamExplanation(getStreamNodeId().toString())- .withChildren(new Explanation[]{- stream.toExplanation(factory)- })- .withFunctionName(factory.getFunctionName(this.getClass()))- .withImplementingClass(this.getClass().getName())- .withExpressionType(ExpressionType.STREAM_DECORATOR)- .withExpression(toExpression(factory, false).toString())- ;+ .withChildren(new Explanation[] {stream.toExplanation(factory)})+ .withFunctionName(factory.getFunctionName(this.getClass()))+ .withImplementingClass(this.getClass().getName())+ .withExpressionType(ExpressionType.STREAM_DECORATOR)+ .withExpression(toExpression(factory, false).toString());}public void close() throws IOException {@@ -114,7 +118,7 @@ public class RecordCountStream extends TupleStream implements Expressible, Seriapublic Tuple read() throws IOException {Tuple t = stream.read();- if(t.EOF) {+ if (t.EOF) {t.put("count", count);return t;} else {@@ -127,4 +131,4 @@ public class RecordCountStream extends TupleStream implements Expressible, Seriapublic StreamComparator getStreamSort() {return null;}-}\ No newline at end of file+}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.javaindex ec2c197a1cf..279a3b06fc0 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java@@ -38,13 +38,11 @@ import org.junit.BeforeClass;import org.junit.Test;/**- * All base tests will be done with CloudSolrStream. Under the covers CloudSolrStream uses SolrStream so- * SolrStream will get fully exercised through these tests.- *- **/-+ * All base tests will be done with CloudSolrStream. Under the covers CloudSolrStream uses+ * SolrStream so SolrStream will get fully exercised through these tests.+ */@Slow[email protected]({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})[email protected]({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})public class SelectWithEvaluatorsTest extends SolrCloudTestCase {private static final String COLLECTIONORALIAS = "collection1";@@ -56,10 +54,24 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {@BeforeClasspublic static void setupCluster() throws Exception {configureCluster(4)- .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))- .addConfig("ml", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("ml").resolve("conf"))+ .addConfig(+ "conf",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("streaming")+ .resolve("conf"))+ .addConfig(+ "ml",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("ml")+ .resolve("conf")).configure();-+String collection;useAlias = random().nextBoolean();if (useAlias) {@@ -73,15 +85,14 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {AbstractDistribZkTestBase.waitForRecoveriesToFinish(collection, cluster.getZkStateReader(), false, true, TIMEOUT);if (useAlias) {- CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());+ CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection)+ .process(cluster.getSolrClient());}}@Beforepublic void cleanIndex() throws Exception {- new UpdateRequest()- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTIONORALIAS);}@Test@@ -97,22 +108,23 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("select", SelectStream.class)- .withFunctionName("add", AddEvaluator.class)- .withFunctionName("if", IfThenElseEvaluator.class)- .withFunctionName("gt", GreaterThanEvaluator.class)- ;++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("select", SelectStream.class)+ .withFunctionName("add", AddEvaluator.class)+ .withFunctionName("if", IfThenElseEvaluator.class)+ .withFunctionName("gt", GreaterThanEvaluator.class);try {// Basic test- clause = "select("- + "id,"- + "add(b_i,c_d) as result,"- + "search(collection1, q=*:*, fl=\"id,a_s,b_i,c_d,d_b\", sort=\"id asc\")"- + ")";+ clause =+ "select("+ + "id,"+ + "add(b_i,c_d) as result,"+ + "search(collection1, q=*:*, fl=\"id,a_s,b_i,c_d,d_b\", sort=\"id asc\")"+ + ")";stream = factory.constructStream(clause);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -125,26 +137,29 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {solrClientCache.close();}}-+protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {tupleStream.open();List<Tuple> tuples = new ArrayList<Tuple>();- for(Tuple t = tupleStream.read(); !t.EOF; t = tupleStream.read()) {+ for (Tuple t = tupleStream.read(); !t.EOF; t = tupleStream.read()) {tuples.add(t);}tupleStream.close();return tuples;}+protected boolean assertOrder(List<Tuple> tuples, int... ids) throws Exception {return assertOrderOf(tuples, "id", ids);}- protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids) throws Exception {++ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids)+ throws Exception {int i = 0;- for(int val : ids) {+ for (int val : ids) {Tuple t = tuples.get(i);String tip = t.getString(fieldName);- if(!tip.equals(Integer.toString(val))) {- throw new Exception("Found value:"+tip+" expecting:"+val);+ if (!tip.equals(Integer.toString(val))) {+ throw new Exception("Found value:" + tip + " expecting:" + val);}++i;}@@ -153,47 +168,48 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {protected boolean assertMapOrder(List<Tuple> tuples, int... ids) throws Exception {int i = 0;- for(int val : ids) {+ for (int val : ids) {Tuple t = tuples.get(i);- List<Map<?,?>> tip = t.getMaps("group");- int id = (int)tip.get(0).get("id");- if(id != val) {- throw new Exception("Found value:"+id+" expecting:"+val);+ List<Map<?, ?>> tip = t.getMaps("group");+ int id = (int) tip.get(0).get("id");+ if (id != val) {+ throw new Exception("Found value:" + id + " expecting:" + val);}++i;}return true;}- protected boolean assertFields(List<Tuple> tuples, String ... fields) throws Exception{- for(Tuple tuple : tuples){- for(String field : fields){- if(!tuple.getFields().containsKey(field)){+ protected boolean assertFields(List<Tuple> tuples, String... fields) throws Exception {+ for (Tuple tuple : tuples) {+ for (String field : fields) {+ if (!tuple.getFields().containsKey(field)) {throw new Exception(String.format(Locale.ROOT, "Expected field '%s' not found", field));}}}return true;}- protected boolean assertNotFields(List<Tuple> tuples, String ... fields) throws Exception{- for(Tuple tuple : tuples){- for(String field : fields){- if(tuple.getFields().containsKey(field)){++ protected boolean assertNotFields(List<Tuple> tuples, String... fields) throws Exception {+ for (Tuple tuple : tuples) {+ for (String field : fields) {+ if (tuple.getFields().containsKey(field)) {throw new Exception(String.format(Locale.ROOT, "Unexpected field '%s' found", field));}}}return true;- }+ }protected boolean assertGroupOrder(Tuple tuple, int... ids) throws Exception {- List<?> group = (List<?>)tuple.get("tuples");- int i=0;- for(int val : ids) {- Map<?,?> t = (Map<?,?>)group.get(i);- Long tip = (Long)t.get("id");- if(tip.intValue() != val) {- throw new Exception("Found value:"+tip.intValue()+" expecting:"+val);+ List<?> group = (List<?>) tuple.get("tuples");+ int i = 0;+ for (int val : ids) {+ Map<?, ?> t = (Map<?, ?>) group.get(i);+ Long tip = (Long) t.get("id");+ if (tip.intValue() != val) {+ throw new Exception("Found value:" + tip.intValue() + " expecting:" + val);}++i;}@@ -201,30 +217,31 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {}public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {- long lv = (long)tuple.get(fieldName);- if(lv != l) {- throw new Exception("Longs not equal:"+l+" : "+lv);+ long lv = (long) tuple.get(fieldName);+ if (lv != l) {+ throw new Exception("Longs not equal:" + l + " : " + lv);}return true;}-- public boolean assertDouble(Tuple tuple, String fieldName, double expectedValue) throws Exception {- double value = (double)tuple.get(fieldName);- if(expectedValue != value) {- throw new Exception("Doubles not equal:"+value+" : "+expectedValue);++ public boolean assertDouble(Tuple tuple, String fieldName, double expectedValue)+ throws Exception {+ double value = (double) tuple.get(fieldName);+ if (expectedValue != value) {+ throw new Exception("Doubles not equal:" + value + " : " + expectedValue);}return true;}-+public boolean assertString(Tuple tuple, String fieldName, String expected) throws Exception {- String actual = (String)tuple.get(fieldName);-- if( (null == expected && null != actual) ||- (null != expected && null == actual) ||- (null != expected && !expected.equals(actual))){- throw new Exception("Longs not equal:"+expected+" : "+actual);+ String actual = (String) tuple.get(fieldName);++ if ((null == expected && null != actual)+ || (null != expected && null == actual)+ || (null != expected && !expected.equals(actual))) {+ throw new Exception("Longs not equal:" + expected + " : " + actual);}return true;diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamAssert.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamAssert.javaindex 308da53569b..cf4c95424a2 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamAssert.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamAssert.java@@ -21,16 +21,17 @@ import java.util.Map;class StreamAssert {static boolean assertMaps(List<Map<?, ?>> maps, int... ids) throws Exception {- if(maps.size() != ids.length) {- throw new Exception("Expected id count != actual map count:"+ids.length+":"+maps.size());+ if (maps.size() != ids.length) {+ throw new Exception(+ "Expected id count != actual map count:" + ids.length + ":" + maps.size());}- int i=0;- for(int val : ids) {- Map<?,?> t = maps.get(i);- String tip = (String)t.get("id");- if(!tip.equals(Integer.toString(val))) {- throw new Exception("Found value:"+tip+" expecting:"+val);+ int i = 0;+ for (int val : ids) {+ Map<?, ?> t = maps.get(i);+ String tip = (String) t.get("id");+ if (!tip.equals(Integer.toString(val))) {+ throw new Exception("Found value:" + tip + " expecting:" + val);}++i;}@@ -38,15 +39,15 @@ class StreamAssert {}static boolean assertList(List<?> list, Object... vals) throws Exception {- if(list.size() != vals.length) {- throw new Exception("Lists are not the same size:"+list.size() +" : "+vals.length);+ if (list.size() != vals.length) {+ throw new Exception("Lists are not the same size:" + list.size() + " : " + vals.length);}- for(int i=0; i<list.size(); i++) {+ for (int i = 0; i < list.size(); i++) {Object a = list.get(i);Object b = vals[i];- if(!a.equals(b)) {- throw new Exception("List items not equals:"+a+" : "+b);+ if (!a.equals(b)) {+ throw new Exception("List items not equals:" + a + " : " + b);}}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.javaindex f38ec2facee..9e569adc8f3 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java@@ -74,7 +74,7 @@ import org.junit.Test;@Slow@SolrTestCaseJ4.SuppressSSL[email protected]({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})[email protected]({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})public class StreamDecoratorTest extends SolrCloudTestCase {private static final String COLLECTIONORALIAS = "collection1";@@ -86,8 +86,22 @@ public class StreamDecoratorTest extends SolrCloudTestCase {@BeforeClasspublic static void setupCluster() throws Exception {configureCluster(4)- .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))- .addConfig("ml", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("ml").resolve("conf"))+ .addConfig(+ "conf",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("streaming")+ .resolve("conf"))+ .addConfig(+ "ml",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("ml")+ .resolve("conf")).configure();String collection;@@ -98,23 +112,23 @@ public class StreamDecoratorTest extends SolrCloudTestCase {collection = COLLECTIONORALIAS;}- CollectionAdminRequest.createCollection(collection, "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection(collection, "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());-+cluster.waitForActiveCollection(collection, 2, 2);AbstractDistribZkTestBase.waitForRecoveriesToFinish(collection, cluster.getZkStateReader(), false, true, TIMEOUT);if (useAlias) {- CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());+ CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection)+ .process(cluster.getSolrClient());}}@Beforepublic void cleanIndex() throws Exception {- new UpdateRequest()- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTIONORALIAS);}@Test@@ -135,14 +149,19 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("unique", UniqueStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("unique", UniqueStream.class);try {// Basic test- expression = StreamExpressionParser.parse("unique(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f\")");+ expression =+ StreamExpressionParser.parse(+ "unique(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f\")");stream = new UniqueStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -151,7 +170,11 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 0, 1, 3, 4);// Basic test desc- expression = StreamExpressionParser.parse("unique(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc, a_i desc\"), over=\"a_f\")");+ expression =+ StreamExpressionParser.parse(+ "unique(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc, a_i desc\"), over=\"a_f\")");stream = new UniqueStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -160,7 +183,11 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 4, 3, 1, 2);// Basic w/multi comp- expression = StreamExpressionParser.parse("unique(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f, a_i\")");+ expression =+ StreamExpressionParser.parse(+ "unique(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f, a_i\")");stream = new UniqueStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -169,7 +196,11 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 0, 2, 1, 3, 4);// full factory w/multi comp- stream = factory.constructStream("unique(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f, a_i\")");+ stream =+ factory.constructStream(+ "unique(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f, a_i\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -199,27 +230,40 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);try {- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("sort", SortStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("sort", SortStream.class);// Basic test- stream = factory.constructStream("sort(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i asc\")");+ stream =+ factory.constructStream(+ "sort(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i asc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);assert (tuples.size() == 6);assertOrder(tuples, 0, 1, 5, 2, 3, 4);// Basic test desc- stream = factory.constructStream("sort(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i desc\")");+ stream =+ factory.constructStream(+ "sort(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i desc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);assert (tuples.size() == 6);assertOrder(tuples, 4, 3, 2, 1, 5, 0);// Basic w/multi comp- stream = factory.constructStream("sort(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i asc, a_f desc\")");+ stream =+ factory.constructStream(+ "sort(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i asc, a_f desc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);assert (tuples.size() == 6);@@ -247,14 +291,19 @@ public class StreamDecoratorTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("null", NullStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("null", NullStream.class);try {// Basic test- stream = factory.constructStream("null(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i asc\")");+ stream =+ factory.constructStream(+ "null(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i asc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);assertTrue(tuples.size() == 1);@@ -283,16 +332,23 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("null", NullStream.class)- .withFunctionName("parallel", ParallelStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("null", NullStream.class)+ .withFunctionName("parallel", ParallelStream.class);try {// Basic test- stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"nullCount desc\", null(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), by=\"a_i asc\"))");+ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"nullCount desc\", null(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), by=\"a_i asc\"))");stream.setStreamContext(streamContext);tuples = getTuples(stream);assertTrue(tuples.size() == 2);@@ -321,18 +377,25 @@ public class StreamDecoratorTest extends SolrCloudTestCase {StreamExpression expression;TupleStream stream;List<Tuple> tuples;-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("unique", UniqueStream.class)- .withFunctionName("merge", MergeStream.class);-++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("unique", UniqueStream.class)+ .withFunctionName("merge", MergeStream.class);+// Basic test- expression = StreamExpressionParser.parse("merge("- + "search(" + COLLECTIONORALIAS + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"id:(1)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"),"- + "on=\"a_f asc\")");+ expression =+ StreamExpressionParser.parse(+ "merge("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(1)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"),"+ + "on=\"a_f asc\")");stream = new MergeStream(expression, factory);StreamContext streamContext = new StreamContext();@@ -346,10 +409,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 0, 1, 3, 4);// Basic test desc- expression = StreamExpressionParser.parse("merge("- + "search(" + COLLECTIONORALIAS + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"id:(1)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc\"),"- + "on=\"a_f desc\")");+ expression =+ StreamExpressionParser.parse(+ "merge("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(1)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc\"),"+ + "on=\"a_f desc\")");stream = new MergeStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -358,10 +427,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 4, 3, 1, 0);// Basic w/multi comp- expression = StreamExpressionParser.parse("merge("- + "search(" + COLLECTIONORALIAS + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f asc, a_s asc\")");+ expression =+ StreamExpressionParser.parse(+ "merge("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f asc, a_s asc\")");stream = new MergeStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -370,10 +445,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 0, 2, 1, 3, 4);// full factory w/multi comp- stream = factory.constructStream("merge("- + "search(" + COLLECTIONORALIAS + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f asc, a_s asc\")");+ stream =+ factory.constructStream(+ "merge("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f asc, a_s asc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -381,11 +462,19 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 0, 2, 1, 3, 4);// full factory w/multi streams- stream = factory.constructStream("merge("- + "search(" + COLLECTIONORALIAS + ", q=\"id:(0 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"id:(1)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"id:(2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f asc\")");+ stream =+ factory.constructStream(+ "merge("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(1)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f asc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -414,17 +503,22 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("unique", UniqueStream.class)- .withFunctionName("top", RankStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("unique", UniqueStream.class)+ .withFunctionName("top", RankStream.class);try {// Basic test- expression = StreamExpressionParser.parse("top("- + "n=3,"- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"),"- + "sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "top("+ + "n=3,"+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"),"+ + "sort=\"a_f asc, a_i asc\")");stream = new RankStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -433,12 +527,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 0, 2, 1);// Basic test desc- expression = StreamExpressionParser.parse("top("- + "n=2,"- + "unique("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc\"),"- + "over=\"a_f\"),"- + "sort=\"a_f desc\")");+ expression =+ StreamExpressionParser.parse(+ "top("+ + "n=2,"+ + "unique("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc\"),"+ + "over=\"a_f\"),"+ + "sort=\"a_f desc\")");stream = new RankStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -447,12 +545,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 4, 3);// full factory- stream = factory.constructStream("top("- + "n=4,"- + "unique("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"),"- + "over=\"a_f\"),"- + "sort=\"a_f asc\")");+ stream =+ factory.constructStream(+ "top("+ + "n=4,"+ + "unique("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"),"+ + "over=\"a_f\"),"+ + "sort=\"a_f asc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -460,12 +562,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 0, 1, 3, 4);// full factory, switch order- stream = factory.constructStream("top("- + "n=4,"- + "unique("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc, a_i desc\"),"- + "over=\"a_f\"),"- + "sort=\"a_f asc\")");+ stream =+ factory.constructStream(+ "top("+ + "n=4,"+ + "unique("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f desc, a_i desc\"),"+ + "over=\"a_f\"),"+ + "sort=\"a_f asc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -491,28 +597,33 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9").add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-+StreamExpression expression;TupleStream stream;List<Tuple> tuples;Tuple t0, t1, t2;- List<Map<?,?>> maps0, maps1, maps2;+ List<Map<?, ?>> maps0, maps1, maps2;StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("reduce", ReducerStream.class)- .withFunctionName("group", GroupOperation.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("reduce", ReducerStream.class)+ .withFunctionName("group", GroupOperation.class);try {// basic- expression = StreamExpressionParser.parse("reduce("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s asc, a_f asc\"),"- + "by=\"a_s\","- + "group(sort=\"a_f desc\", n=\"4\"))");+ expression =+ StreamExpressionParser.parse(+ "reduce("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s asc, a_f asc\"),"+ + "by=\"a_s\","+ + "group(sort=\"a_f desc\", n=\"4\"))");stream = factory.constructStream(expression);stream.setStreamContext(streamContext);@@ -528,16 +639,19 @@ public class StreamDecoratorTest extends SolrCloudTestCase {maps1 = t1.getMaps("group");assertMaps(maps1, 8, 7, 5, 3);-t2 = tuples.get(2);maps2 = t2.getMaps("group");assertMaps(maps2, 6, 4);// basic w/spaces- expression = StreamExpressionParser.parse("reduce("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s asc, a_f asc\"),"- + "by=\"a_s\"," +- "group(sort=\"a_i asc\", n=\"2\"))");+ expression =+ StreamExpressionParser.parse(+ "reduce("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s asc, a_f asc\"),"+ + "by=\"a_s\","+ + "group(sort=\"a_i asc\", n=\"2\"))");stream = factory.constructStream(expression);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -583,70 +697,90 @@ public class StreamDecoratorTest extends SolrCloudTestCase {TupleStream stream;List<Tuple> tuples;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("having", HavingStream.class)- .withFunctionName("rollup", RollupStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("and", AndEvaluator.class)- .withFunctionName("or", OrEvaluator.class)- .withFunctionName("not", NotEvaluator.class)- .withFunctionName("gt", GreaterThanEvaluator.class)- .withFunctionName("lt", LessThanEvaluator.class)- .withFunctionName("eq", EqualToEvaluator.class)- .withFunctionName("lteq", LessThanEqualToEvaluator.class)- .withFunctionName("gteq", GreaterThanEqualToEvaluator.class);-- stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), eq(a_i, 9))");+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("having", HavingStream.class)+ .withFunctionName("rollup", RollupStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("and", AndEvaluator.class)+ .withFunctionName("or", OrEvaluator.class)+ .withFunctionName("not", NotEvaluator.class)+ .withFunctionName("gt", GreaterThanEvaluator.class)+ .withFunctionName("lt", LessThanEvaluator.class)+ .withFunctionName("eq", EqualToEvaluator.class)+ .withFunctionName("lteq", LessThanEqualToEvaluator.class)+ .withFunctionName("gteq", GreaterThanEqualToEvaluator.class);++ stream =+ factory.constructStream(+ "having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), eq(a_i, 9))");StreamContext context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 1);+ assert (tuples.size() == 1);Tuple t = tuples.get(0);assertTrue(t.getString("id").equals("9"));- stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(eq(a_i, 9),lt(a_i, 10)))");+ stream =+ factory.constructStream(+ "having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(eq(a_i, 9),lt(a_i, 10)))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 1);+ assert (tuples.size() == 1);t = tuples.get(0);assertTrue(t.getString("id").equals("9"));- stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), or(eq(a_i, 9),eq(a_i, 8)))");+ stream =+ factory.constructStream(+ "having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), or(eq(a_i, 9),eq(a_i, 8)))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 2);+ assert (tuples.size() == 2);t = tuples.get(0);assertTrue(t.getString("id").equals("8"));t = tuples.get(1);assertTrue(t.getString("id").equals("9"));-- stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(eq(a_i, 9),not(eq(a_i, 9))))");+ stream =+ factory.constructStream(+ "having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(eq(a_i, 9),not(eq(a_i, 9))))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 0);+ assert (tuples.size() == 0);- stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(lteq(a_i, 9), gteq(a_i, 8)))");+ stream =+ factory.constructStream(+ "having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(lteq(a_i, 9), gteq(a_i, 8)))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 2);+ assert (tuples.size() == 2);t = tuples.get(0);assertTrue(t.getString("id").equals("8"));@@ -654,13 +788,17 @@ public class StreamDecoratorTest extends SolrCloudTestCase {t = tuples.get(1);assertTrue(t.getString("id").equals("9"));- stream = factory.constructStream("having(rollup(over=a_f, sum(a_i), search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\")), and(eq(sum(a_i), 9),eq(sum(a_i), 9)))");+ stream =+ factory.constructStream(+ "having(rollup(over=a_f, sum(a_i), search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\")), and(eq(sum(a_i), 9),eq(sum(a_i), 9)))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 1);+ assert (tuples.size() == 1);t = tuples.get(0);assertTrue(t.getDouble("a_f") == 10.0D);@@ -688,73 +826,102 @@ public class StreamDecoratorTest extends SolrCloudTestCase {TupleStream stream;List<Tuple> tuples;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("having", HavingStream.class)- .withFunctionName("rollup", RollupStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("and", AndEvaluator.class)- .withFunctionName("or", OrEvaluator.class)- .withFunctionName("not", NotEvaluator.class)- .withFunctionName("gt", GreaterThanEvaluator.class)- .withFunctionName("lt", LessThanEvaluator.class)- .withFunctionName("eq", EqualToEvaluator.class)- .withFunctionName("lteq", LessThanEqualToEvaluator.class)- .withFunctionName("gteq", GreaterThanEqualToEvaluator.class)- .withFunctionName("val", RawValueEvaluator.class)- .withFunctionName("parallel", ParallelStream.class);-- stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\", having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), eq(a_i, 9)))");+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("having", HavingStream.class)+ .withFunctionName("rollup", RollupStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("and", AndEvaluator.class)+ .withFunctionName("or", OrEvaluator.class)+ .withFunctionName("not", NotEvaluator.class)+ .withFunctionName("gt", GreaterThanEvaluator.class)+ .withFunctionName("lt", LessThanEvaluator.class)+ .withFunctionName("eq", EqualToEvaluator.class)+ .withFunctionName("lteq", LessThanEqualToEvaluator.class)+ .withFunctionName("gteq", GreaterThanEqualToEvaluator.class)+ .withFunctionName("val", RawValueEvaluator.class)+ .withFunctionName("parallel", ParallelStream.class);++ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"a_f asc\", having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), eq(a_i, 9)))");StreamContext context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 1);+ assert (tuples.size() == 1);Tuple t = tuples.get(0);assertTrue(t.getString("id").equals("9"));- stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\", having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), and(eq(a_i, 9),lt(a_i, 10))))");+ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"a_f asc\", having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), and(eq(a_i, 9),lt(a_i, 10))))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 1);+ assert (tuples.size() == 1);t = tuples.get(0);assertTrue(t.getString("id").equals("9"));- stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\",having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), or(eq(a_i, 9),eq(a_i, 8))))");+ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"a_f asc\",having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), or(eq(a_i, 9),eq(a_i, 8))))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 2);+ assert (tuples.size() == 2);t = tuples.get(0);assertTrue(t.getString("id").equals("8"));t = tuples.get(1);assertTrue(t.getString("id").equals("9"));-- stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\", having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), and(eq(a_i, 9),not(eq(a_i, 9)))))");+ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"a_f asc\", having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), and(eq(a_i, 9),not(eq(a_i, 9)))))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 0);-+ assert (tuples.size() == 0);- stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\",having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), and(lteq(a_i, 9), gteq(a_i, 8))))");+ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"a_f asc\",having(search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id, qt=\"/export\"), and(lteq(a_i, 9), gteq(a_i, 8))))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 2);+ assert (tuples.size() == 2);t = tuples.get(0);assertTrue(t.getString("id").equals("8"));@@ -762,13 +929,19 @@ public class StreamDecoratorTest extends SolrCloudTestCase {t = tuples.get(1);assertTrue(t.getString("id").equals("9"));- stream = factory.constructStream("parallel("+COLLECTIONORALIAS+", workers=2, sort=\"a_f asc\", having(rollup(over=a_f, sum(a_i), search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=a_f, qt=\"/export\")), and(eq(sum(a_i), 9),eq(sum(a_i),9))))");+ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"a_f asc\", having(rollup(over=a_f, sum(a_i), search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=a_f, qt=\"/export\")), and(eq(sum(a_i), 9),eq(sum(a_i),9))))");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 1);+ assert (tuples.size() == 1);t = tuples.get(0);assertTrue(t.getDouble("a_f") == 10.0D);@@ -779,7 +952,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {@Testpublic void testFetchStream() throws Exception {- SolrClientCache solrClientCache = new SolrClientCache();//TODO share in @Before ; close in @After ?+ SolrClientCache solrClientCache =+ new SolrClientCache(); // TODO share in @Before ; close in @After ?new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1", "subject", "blah blah blah 0")@@ -797,18 +971,25 @@ public class StreamDecoratorTest extends SolrCloudTestCase {TupleStream stream;List<Tuple> tuples;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("fetch", FetchStream.class);-- stream = factory.constructStream("fetch("+ COLLECTIONORALIAS +", search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), on=\"id=a_i\", batchSize=\"2\", fl=\"subject\")");+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("fetch", FetchStream.class);++ stream =+ factory.constructStream(+ "fetch("+ + COLLECTIONORALIAS+ + ", search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), on=\"id=a_i\", batchSize=\"2\", fl=\"subject\")");StreamContext context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 10);+ assert (tuples.size() == 10);Tuple t = tuples.get(0);assertTrue("blah blah blah 0".equals(t.getString("subject")));t = tuples.get(1);@@ -830,14 +1011,20 @@ public class StreamDecoratorTest extends SolrCloudTestCase {t = tuples.get(9);assertTrue("blah blah blah 9".equals(t.getString("subject")));- //Change the batch size- stream = factory.constructStream("fetch(" + COLLECTIONORALIAS + ", search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), on=\"id=a_i\", batchSize=\"3\", fl=\"subject\")");+ // Change the batch size+ stream =+ factory.constructStream(+ "fetch("+ + COLLECTIONORALIAS+ + ", search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), on=\"id=a_i\", batchSize=\"3\", fl=\"subject\")");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);tuples = getTuples(stream);- assert(tuples.size() == 10);+ assert (tuples.size() == 10);t = tuples.get(0);assertTrue("blah blah blah 0".equals(t.getString("subject")));t = tuples.get(1);@@ -864,7 +1051,15 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "99", "a1_s", "hello 99", "a2_s", "hello 99", "subject", "blah blah blah 99").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- stream = factory.constructStream("fetch("+ COLLECTIONORALIAS +", search(" + COLLECTIONORALIAS + ", q=" + id + ":99, fl=\"id,a1_s\", sort=\"id asc\"), on=\"a1_s=a2_s\", fl=\"subject\")");+ stream =+ factory.constructStream(+ "fetch("+ + COLLECTIONORALIAS+ + ", search("+ + COLLECTIONORALIAS+ + ", q="+ + id+ + ":99, fl=\"id,a1_s\", sort=\"id asc\"), on=\"a1_s=a2_s\", fl=\"subject\")");context = new StreamContext();context.setSolrClientCache(solrClientCache);stream.setStreamContext(context);@@ -900,15 +1095,24 @@ public class StreamDecoratorTest extends SolrCloudTestCase {TupleStream stream;List<Tuple> tuples;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("fetch", FetchStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("fetch", FetchStream.class);try {- stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\", fetch(" + COLLECTIONORALIAS + ", search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=\"id\", qt=\"/export\"), on=\"id=a_i\", batchSize=\"2\", fl=\"subject\"))");+ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"a_f asc\", fetch("+ + COLLECTIONORALIAS+ + ", search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=\"id\", qt=\"/export\"), on=\"id=a_i\", batchSize=\"2\", fl=\"subject\"))");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -934,8 +1138,15 @@ public class StreamDecoratorTest extends SolrCloudTestCase {t = tuples.get(9);assertTrue("blah blah blah 9".equals(t.getString("subject")));-- stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\", fetch(" + COLLECTIONORALIAS + ", search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=\"id\", qt=\"/export\"), on=\"id=a_i\", batchSize=\"3\", fl=\"subject\"))");+ stream =+ factory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"a_f asc\", fetch("+ + COLLECTIONORALIAS+ + ", search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=\"id\", qt=\"/export\"), on=\"id=a_i\", batchSize=\"3\", fl=\"subject\"))");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -981,32 +1192,37 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("rollup", RollupStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("count", CountMetric.class)- .withFunctionName("daemon", DaemonStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("rollup", RollupStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("count", CountMetric.class)+ .withFunctionName("daemon", DaemonStream.class);StreamExpression expression;DaemonStream daemonStream;- expression = StreamExpressionParser.parse("daemon(rollup("- + "search(" + COLLECTIONORALIAS + ", q=\"*:*\", fl=\"a_i,a_s\", sort=\"a_s asc\"),"- + "over=\"a_s\","- + "sum(a_i)"- + "), id=\"test\", runInterval=\"1000\", queueSize=\"9\")");- daemonStream = (DaemonStream)factory.constructStream(expression);+ expression =+ StreamExpressionParser.parse(+ "daemon(rollup("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", fl=\"a_i,a_s\", sort=\"a_s asc\"),"+ + "over=\"a_s\","+ + "sum(a_i)"+ + "), id=\"test\", runInterval=\"1000\", queueSize=\"9\")");+ daemonStream = (DaemonStream) factory.constructStream(expression);StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);daemonStream.setStreamContext(streamContext);try {- //Test Long and Double Sums+ // Test Long and Double SumsdaemonStream.open(); // This will start the daemon thread@@ -1015,7 +1231,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {String bucket = tuple.getString("a_s");Double sumi = tuple.getDouble("sum(a_i)");- //System.out.println("#################################### Bucket 1:"+bucket);+ // System.out.println("#################################### Bucket 1:"+bucket);assertTrue(bucket.equals("hello0"));assertTrue(sumi.doubleValue() == 17.0D);@@ -1023,19 +1239,19 @@ public class StreamDecoratorTest extends SolrCloudTestCase {bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");- //System.out.println("#################################### Bucket 2:"+bucket);+ // System.out.println("#################################### Bucket 2:"+bucket);assertTrue(bucket.equals("hello3"));assertTrue(sumi.doubleValue() == 38.0D);tuple = daemonStream.read();bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");- //System.out.println("#################################### Bucket 3:"+bucket);+ // System.out.println("#################################### Bucket 3:"+bucket);assertTrue(bucket.equals("hello4"));assertTrue(sumi.longValue() == 15);}- //Now lets wait until the internal queue fills up+ // Now lets wait until the internal queue fills upwhile (daemonStream.remainingCapacity() > 0) {try {@@ -1045,19 +1261,20 @@ public class StreamDecoratorTest extends SolrCloudTestCase {}}- //OK capacity is full, let's index a new doc+ // OK capacity is full, let's index a new docnew UpdateRequest().add(id, "10", "a_s", "hello0", "a_i", "1", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- //Now lets clear the existing docs in the queue 9, plus 3 more to get passed the run that was blocked. The next run should- //have the tuples with the updated count.+ // Now lets clear the existing docs in the queue 9, plus 3 more to get passed the run that was+ // blocked. The next run should+ // have the tuples with the updated count.for (int i = 0; i < 12; i++) {daemonStream.read();}- //And rerun the loop. It should have a new count for hello0+ // And rerun the loop. It should have a new count for hello0for (int i = 0; i < 4; i++) {Tuple tuple = daemonStream.read(); // Reads from the queueString bucket = tuple.getString("a_s");@@ -1080,7 +1297,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertTrue(sumi.longValue() == 15);}} finally {- daemonStream.close(); //This should stop the daemon thread+ daemonStream.close(); // This should stop the daemon threadsolrClientCache.close();}}@@ -1102,10 +1319,11 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("topic", TopicStream.class)- .withFunctionName("daemon", DaemonStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("topic", TopicStream.class)+ .withFunctionName("daemon", DaemonStream.class);StreamExpression expression;DaemonStream daemonStream;@@ -1113,9 +1331,15 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache cache = new SolrClientCache();StreamContext context = new StreamContext();context.setSolrClientCache(cache);- expression = StreamExpressionParser.parse("daemon(topic("+ COLLECTIONORALIAS +","+ COLLECTIONORALIAS +", q=\"a_s:hello\", initialCheckpoint=0, id=\"topic1\", rows=2, fl=\"id\""- + "), id=test, runInterval=1000, terminate=true, queueSize=50)");- daemonStream = (DaemonStream)factory.constructStream(expression);+ expression =+ StreamExpressionParser.parse(+ "daemon(topic("+ + COLLECTIONORALIAS+ + ","+ + COLLECTIONORALIAS+ + ", q=\"a_s:hello\", initialCheckpoint=0, id=\"topic1\", rows=2, fl=\"id\""+ + "), id=test, runInterval=1000, terminate=true, queueSize=50)");+ daemonStream = (DaemonStream) factory.constructStream(expression);daemonStream.setStreamContext(context);List<Tuple> tuples = getTuples(daemonStream);@@ -1139,16 +1363,17 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("rollup", RollupStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("count", CountMetric.class);-+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("rollup", RollupStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("count", CountMetric.class);+StreamExpression expression;TupleStream stream;List<Tuple> tuples;@@ -1156,26 +1381,30 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);try {- expression = StreamExpressionParser.parse("rollup("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\"),"- + "over=\"a_s\","- + "sum(a_i),"- + "sum(a_f),"- + "min(a_i),"- + "min(a_f),"- + "max(a_i),"- + "max(a_f),"- + "avg(a_i),"- + "avg(a_f),"- + "count(*),"- + ")");+ expression =+ StreamExpressionParser.parse(+ "rollup("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\"),"+ + "over=\"a_s\","+ + "sum(a_i),"+ + "sum(a_f),"+ + "min(a_i),"+ + "min(a_f),"+ + "max(a_i),"+ + "max(a_f),"+ + "avg(a_i),"+ + "avg(a_f),"+ + "count(*),"+ + ")");stream = factory.constructStream(expression);stream.setStreamContext(streamContext);tuples = getTuples(stream);assert (tuples.size() == 3);- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);String bucket = tuple.getString("a_s");@@ -1267,16 +1496,17 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("hashRollup", HashRollupStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("count", CountMetric.class)- .withFunctionName("sort", SortStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("hashRollup", HashRollupStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("count", CountMetric.class)+ .withFunctionName("sort", SortStream.class);StreamExpression expression;TupleStream stream;@@ -1285,26 +1515,30 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);try {- expression = StreamExpressionParser.parse("sort(hashRollup("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\"),"- + "over=\"a_s\","- + "sum(a_i),"- + "sum(a_f),"- + "min(a_i),"- + "min(a_f),"- + "max(a_i),"- + "max(a_f),"- + "avg(a_i),"- + "avg(a_f),"- + "count(*),"- + "), by=\"avg(a_f) asc\")");+ expression =+ StreamExpressionParser.parse(+ "sort(hashRollup("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\"),"+ + "over=\"a_s\","+ + "sum(a_i),"+ + "sum(a_f),"+ + "min(a_i),"+ + "min(a_f),"+ + "max(a_i),"+ + "max(a_f),"+ + "avg(a_i),"+ + "avg(a_f),"+ + "count(*),"+ + "), by=\"avg(a_f) asc\")");stream = factory.constructStream(expression);stream.setStreamContext(streamContext);tuples = getTuples(stream);assert (tuples.size() == 3);- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);String bucket = tuple.getString("a_s");@@ -1341,9 +1575,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {avgf = tuple.getDouble("avg(a_f)");count = tuple.getDouble("count(*)");-- System.out.println("################:bucket"+bucket);-+ System.out.println("################:bucket" + bucket);assertTrue(bucket.equals("hello4"));assertTrue(sumi.longValue() == 15);@@ -1379,8 +1611,6 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertTrue(avgf.doubleValue() == 6.5D);assertTrue(count.doubleValue() == 4);--} finally {solrClientCache.close();}@@ -1402,30 +1632,37 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.commit(cluster.getSolrClient(), COLLECTIONORALIAS);String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory streamFactory = new StreamFactory().withCollectionZkHost(COLLECTIONORALIAS, zkHost)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("unique", UniqueStream.class)- .withFunctionName("top", RankStream.class)- .withFunctionName("group", ReducerStream.class)- .withFunctionName("parallel", ParallelStream.class);+ StreamFactory streamFactory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, zkHost)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("unique", UniqueStream.class)+ .withFunctionName("top", RankStream.class)+ .withFunctionName("group", ReducerStream.class)+ .withFunctionName("parallel", ParallelStream.class);StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);--try {- ParallelStream pstream = (ParallelStream) streamFactory.constructStream("parallel(" + COLLECTIONORALIAS + ", unique(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"), over=\"a_f\"), workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_f asc\")");+ ParallelStream pstream =+ (ParallelStream)+ streamFactory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", unique(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"), over=\"a_f\"), workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_f asc\")");pstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(pstream);assert (tuples.size() == 5);assertOrder(tuples, 0, 1, 3, 4, 6);- //Test the eofTuples+ // Test the eofTuplesMap<String, Tuple> eofTuples = pstream.getEofTuples();- assert (eofTuples.size() == 2); //There should be an EOF tuple for each worker.+ assert (eofTuples.size() == 2); // There should be an EOF tuple for each worker.} finally {solrClientCache.close();}@@ -1492,7 +1729,6 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "54", "a_s", "hello1", "a_i", "13", "a_f", "4").add(id, "55", "a_s", "hello1", "a_i", "13", "a_f", "4").add(id, "56", "a_s", "hello1", "a_i", "13", "a_f", "1000")-.commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamContext streamContext = new StreamContext();@@ -1500,23 +1736,32 @@ public class StreamDecoratorTest extends SolrCloudTestCase {streamContext.setSolrClientCache(solrClientCache);String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory streamFactory = new StreamFactory().withCollectionZkHost(COLLECTIONORALIAS, zkHost)- .withFunctionName("shuffle", ShuffleStream.class)- .withFunctionName("unique", UniqueStream.class)- .withFunctionName("parallel", ParallelStream.class);+ StreamFactory streamFactory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, zkHost)+ .withFunctionName("shuffle", ShuffleStream.class)+ .withFunctionName("unique", UniqueStream.class)+ .withFunctionName("parallel", ParallelStream.class);try {- ParallelStream pstream = (ParallelStream) streamFactory.constructStream("parallel(" + COLLECTIONORALIAS + ", unique(shuffle(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\"), over=\"a_f\"), workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_f asc\")");+ ParallelStream pstream =+ (ParallelStream)+ streamFactory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", unique(shuffle(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\"), over=\"a_f\"), workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_f asc\")");pstream.setStreamFactory(streamFactory);pstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(pstream);assert (tuples.size() == 6);assertOrder(tuples, 0, 1, 3, 4, 6, 56);- //Test the eofTuples+ // Test the eofTuplesMap<String, Tuple> eofTuples = pstream.getEofTuples();- assert (eofTuples.size() == 2); //There should be an EOF tuple for each worker.+ assert (eofTuples.size() == 2); // There should be an EOF tuple for each worker.assert (pstream.toExpression(streamFactory).toString().contains("shuffle"));} finally {solrClientCache.close();@@ -1543,22 +1788,31 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory streamFactory = new StreamFactory().withCollectionZkHost(COLLECTIONORALIAS, zkHost)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("group", GroupOperation.class)- .withFunctionName("reduce", ReducerStream.class)- .withFunctionName("parallel", ParallelStream.class);-+ StreamFactory streamFactory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, zkHost)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("group", GroupOperation.class)+ .withFunctionName("reduce", ReducerStream.class)+ .withFunctionName("parallel", ParallelStream.class);try {- ParallelStream pstream = (ParallelStream) streamFactory.constructStream("parallel(" + COLLECTIONORALIAS + ", " +- "reduce(" +- "search(" + COLLECTIONORALIAS + ", q=\"*:*\", fl=\"id,a_s,a_i,a_f\", sort=\"a_s asc,a_f asc\", partitionKeys=\"a_s\", qt=\"/export\"), " +- "by=\"a_s\"," +- "group(sort=\"a_i asc\", n=\"5\")), " +- "workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_s asc\")");+ ParallelStream pstream =+ (ParallelStream)+ streamFactory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", "+ + "reduce("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", fl=\"id,a_s,a_i,a_f\", sort=\"a_s asc,a_f asc\", partitionKeys=\"a_s\", qt=\"/export\"), "+ + "by=\"a_s\","+ + "group(sort=\"a_i asc\", n=\"5\")), "+ + "workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_s asc\")");pstream.setStreamContext(streamContext);@@ -1567,24 +1821,32 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assert (tuples.size() == 3);Tuple t0 = tuples.get(0);- List<Map<?,?>> maps0 = t0.getMaps("group");+ List<Map<?, ?>> maps0 = t0.getMaps("group");assertMaps(maps0, 0, 1, 2, 9);Tuple t1 = tuples.get(1);- List<Map<?,?>> maps1 = t1.getMaps("group");+ List<Map<?, ?>> maps1 = t1.getMaps("group");assertMaps(maps1, 3, 5, 7, 8);Tuple t2 = tuples.get(2);- List<Map<?,?>> maps2 = t2.getMaps("group");+ List<Map<?, ?>> maps2 = t2.getMaps("group");assertMaps(maps2, 4, 6);-- pstream = (ParallelStream) streamFactory.constructStream("parallel(" + COLLECTIONORALIAS + ", " +- "reduce(" +- "search(" + COLLECTIONORALIAS + ", q=\"*:*\", fl=\"id,a_s,a_i,a_f\", sort=\"a_s desc,a_f asc\", partitionKeys=\"a_s\", qt=\"/export\"), " +- "by=\"a_s\", " +- "group(sort=\"a_i desc\", n=\"5\"))," +- "workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_s desc\")");+ pstream =+ (ParallelStream)+ streamFactory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", "+ + "reduce("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", fl=\"id,a_s,a_i,a_f\", sort=\"a_s desc,a_f asc\", partitionKeys=\"a_s\", qt=\"/export\"), "+ + "by=\"a_s\", "+ + "group(sort=\"a_i desc\", n=\"5\")),"+ + "workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_s desc\")");pstream.setStreamContext(streamContext);tuples = getTuples(pstream);@@ -1595,19 +1857,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {maps0 = t0.getMaps("group");assertMaps(maps0, 6, 4);-t1 = tuples.get(1);maps1 = t1.getMaps("group");assertMaps(maps1, 8, 7, 5, 3);-t2 = tuples.get(2);maps2 = t2.getMaps("group");assertMaps(maps2, 9, 2, 1, 0);} finally {solrClientCache.close();}-}@Test@@ -1627,23 +1886,33 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.commit(cluster.getSolrClient(), COLLECTIONORALIAS);String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory streamFactory = new StreamFactory().withCollectionZkHost(COLLECTIONORALIAS, zkHost)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("unique", UniqueStream.class)- .withFunctionName("top", RankStream.class)- .withFunctionName("group", ReducerStream.class)- .withFunctionName("parallel", ParallelStream.class);+ StreamFactory streamFactory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, zkHost)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("unique", UniqueStream.class)+ .withFunctionName("top", RankStream.class)+ .withFunctionName("group", ReducerStream.class)+ .withFunctionName("parallel", ParallelStream.class);StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);try {- ParallelStream pstream = (ParallelStream) streamFactory.constructStream("parallel("- + COLLECTIONORALIAS + ", "- + "top("- + "search(" + COLLECTIONORALIAS + ", q=\"*:*\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), "- + "n=\"11\", "- + "sort=\"a_i desc\"), workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_i desc\")");+ ParallelStream pstream =+ (ParallelStream)+ streamFactory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", "+ + "top("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), "+ + "n=\"11\", "+ + "sort=\"a_i desc\"), workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_i desc\")");pstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(pstream);@@ -1652,7 +1921,6 @@ public class StreamDecoratorTest extends SolrCloudTestCase {} finally {solrClientCache.close();}-}@Test@@ -1672,29 +1940,53 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.commit(cluster.getSolrClient(), COLLECTIONORALIAS);String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory streamFactory = new StreamFactory().withCollectionZkHost(COLLECTIONORALIAS, zkHost)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("unique", UniqueStream.class)- .withFunctionName("top", RankStream.class)- .withFunctionName("group", ReducerStream.class)- .withFunctionName("merge", MergeStream.class)- .withFunctionName("parallel", ParallelStream.class);+ StreamFactory streamFactory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, zkHost)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("unique", UniqueStream.class)+ .withFunctionName("top", RankStream.class)+ .withFunctionName("group", ReducerStream.class)+ .withFunctionName("merge", MergeStream.class)+ .withFunctionName("parallel", ParallelStream.class);StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);try {- //Test ascending- ParallelStream pstream = (ParallelStream) streamFactory.constructStream("parallel(" + COLLECTIONORALIAS + ", merge(search(" + COLLECTIONORALIAS + ", q=\"id:(4 1 8 7 9)\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), search(" + COLLECTIONORALIAS + ", q=\"id:(0 2 3 6)\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), on=\"a_i asc\"), workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_i asc\")");+ // Test ascending+ ParallelStream pstream =+ (ParallelStream)+ streamFactory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", merge(search("+ + COLLECTIONORALIAS+ + ", q=\"id:(4 1 8 7 9)\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 2 3 6)\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), on=\"a_i asc\"), workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_i asc\")");pstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(pstream);assert (tuples.size() == 9);assertOrder(tuples, 0, 1, 2, 3, 4, 7, 6, 8, 9);- //Test descending-- pstream = (ParallelStream) streamFactory.constructStream("parallel(" + COLLECTIONORALIAS + ", merge(search(" + COLLECTIONORALIAS + ", q=\"id:(4 1 8 9)\", fl=\"id,a_s,a_i\", sort=\"a_i desc\", partitionKeys=\"a_i\", qt=\"/export\"), search(" + COLLECTIONORALIAS + ", q=\"id:(0 2 3 6)\", fl=\"id,a_s,a_i\", sort=\"a_i desc\", partitionKeys=\"a_i\", qt=\"/export\"), on=\"a_i desc\"), workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_i desc\")");+ // Test descending++ pstream =+ (ParallelStream)+ streamFactory.constructStream(+ "parallel("+ + COLLECTIONORALIAS+ + ", merge(search("+ + COLLECTIONORALIAS+ + ", q=\"id:(4 1 8 9)\", fl=\"id,a_s,a_i\", sort=\"a_i desc\", partitionKeys=\"a_i\", qt=\"/export\"), search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 2 3 6)\", fl=\"id,a_s,a_i\", sort=\"a_i desc\", partitionKeys=\"a_i\", qt=\"/export\"), on=\"a_i desc\"), workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_i desc\")");pstream.setStreamContext(streamContext);tuples = getTuples(pstream);@@ -1703,7 +1995,6 @@ public class StreamDecoratorTest extends SolrCloudTestCase {} finally {solrClientCache.close();}-}@Test@@ -1722,17 +2013,17 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("rollup", RollupStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("count", CountMetric.class);-+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("rollup", RollupStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("count", CountMetric.class);StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();@@ -1743,23 +2034,29 @@ public class StreamDecoratorTest extends SolrCloudTestCase {List<Tuple> tuples;try {- expression = StreamExpressionParser.parse("parallel(" + COLLECTIONORALIAS + ","- + "rollup("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\", partitionKeys=\"a_s\", qt=\"/export\"),"- + "over=\"a_s\","- + "sum(a_i),"- + "sum(a_f),"- + "min(a_i),"- + "min(a_f),"- + "max(a_i),"- + "max(a_f),"- + "avg(a_i),"- + "avg(a_f),"- + "count(*)"- + "),"- + "workers=\"2\", zkHost=\"" + cluster.getZkServer().getZkAddress() + "\", sort=\"a_s asc\")"- );-+ expression =+ StreamExpressionParser.parse(+ "parallel("+ + COLLECTIONORALIAS+ + ","+ + "rollup("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\", partitionKeys=\"a_s\", qt=\"/export\"),"+ + "over=\"a_s\","+ + "sum(a_i),"+ + "sum(a_f),"+ + "min(a_i),"+ + "min(a_f),"+ + "max(a_i),"+ + "max(a_f),"+ + "avg(a_i),"+ + "avg(a_f),"+ + "count(*)"+ + "),"+ + "workers=\"2\", zkHost=\""+ + cluster.getZkServer().getZkAddress()+ + "\", sort=\"a_s asc\")");stream = factory.constructStream(expression);stream.setStreamContext(streamContext);@@ -1767,7 +2064,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assert (tuples.size() == 3);- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);String bucket = tuple.getString("a_s");@@ -1858,18 +2155,18 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("hashRollup", HashRollupStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("count", CountMetric.class)- .withFunctionName("sort", SortStream.class);-+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("hashRollup", HashRollupStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("count", CountMetric.class)+ .withFunctionName("sort", SortStream.class);StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();@@ -1880,23 +2177,29 @@ public class StreamDecoratorTest extends SolrCloudTestCase {List<Tuple> tuples;try {- expression = StreamExpressionParser.parse("sort(parallel(" + COLLECTIONORALIAS + ","- + "hashRollup("- + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\", partitionKeys=\"a_s\", qt=\"/export\"),"- + "over=\"a_s\","- + "sum(a_i),"- + "sum(a_f),"- + "min(a_i),"- + "min(a_f),"- + "max(a_i),"- + "max(a_f),"- + "avg(a_i),"- + "avg(a_f),"- + "count(*)"- + "),"- + "workers=\"2\", zkHost=\"" + cluster.getZkServer().getZkAddress() + "\", sort=\"a_s asc\"), by=\"avg(a_f) asc\")"- );-+ expression =+ StreamExpressionParser.parse(+ "sort(parallel("+ + COLLECTIONORALIAS+ + ","+ + "hashRollup("+ + "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\", partitionKeys=\"a_s\", qt=\"/export\"),"+ + "over=\"a_s\","+ + "sum(a_i),"+ + "sum(a_f),"+ + "min(a_i),"+ + "min(a_f),"+ + "max(a_i),"+ + "max(a_f),"+ + "avg(a_i),"+ + "avg(a_f),"+ + "count(*)"+ + "),"+ + "workers=\"2\", zkHost=\""+ + cluster.getZkServer().getZkAddress()+ + "\", sort=\"a_s asc\"), by=\"avg(a_f) asc\")");stream = factory.constructStream(expression);stream.setStreamContext(streamContext);@@ -1904,7 +2207,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assert (tuples.size() == 3);- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);String bucket = tuple.getString("a_s");@@ -1952,7 +2255,6 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertTrue(avgf.doubleValue() == 5.5D);assertTrue(count.doubleValue() == 2);-tuple = tuples.get(2);bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");@@ -1965,7 +2267,6 @@ public class StreamDecoratorTest extends SolrCloudTestCase {avgf = tuple.getDouble("avg(a_f)");count = tuple.getDouble("count(*)");-assertTrue(bucket.equals("hello3"));assertTrue(sumi.doubleValue() == 38.0D);assertTrue(sumf.doubleValue() == 26.0D);@@ -1986,21 +2287,35 @@ public class StreamDecoratorTest extends SolrCloudTestCase {new UpdateRequest().add(id, "1", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9- .add(id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9+ .add(+ id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9.add(id, "2", "side_s", "left", "join1_i", "0", "join2_s", "b", "ident_s", "left_2").add(id, "3", "side_s", "left", "join1_i", "1", "join2_s", "a", "ident_s", "left_3") // 10.add(id, "4", "side_s", "left", "join1_i", "1", "join2_s", "b", "ident_s", "left_4") // 11.add(id, "5", "side_s", "left", "join1_i", "1", "join2_s", "c", "ident_s", "left_5") // 12.add(id, "6", "side_s", "left", "join1_i", "2", "join2_s", "d", "ident_s", "left_6").add(id, "7", "side_s", "left", "join1_i", "3", "join2_s", "e", "ident_s", "left_7") // 14-- .add(id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1", "join3_i", "0") // 1,15- .add(id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2", "join3_i", "0") // 1,15- .add(id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3", "join3_i", "1") // 3- .add(id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4", "join3_i", "1") // 4- .add(id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5", "join3_i", "1") // 5- .add(id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6", "join3_i", "2")- .add(id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7", "join3_i", "3") // 7+ .add(+ id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1",+ "join3_i", "0") // 1,15+ .add(+ id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2",+ "join3_i", "0") // 1,15+ .add(+ id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3",+ "join3_i", "1") // 3+ .add(+ id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4",+ "join3_i", "1") // 4+ .add(+ id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5",+ "join3_i", "1") // 5+ .add(+ id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6",+ "join3_i", "2")+ .add(+ id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7",+ "join3_i", "3") // 7.commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamExpression expression;@@ -2009,18 +2324,25 @@ public class StreamDecoratorTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("innerJoin", InnerJoinStream.class);++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("innerJoin", InnerJoinStream.class);try {// Basic test- expression = StreamExpressionParser.parse("innerJoin("- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc\"),"- + "on=\"join1_i=join1_i, join2_s=join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "innerJoin("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc\"),"+ + "on=\"join1_i=join1_i, join2_s=join2_s\")");stream = new InnerJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2028,10 +2350,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 1, 1, 15, 15, 3, 4, 5, 7);// Basic desc- expression = StreamExpressionParser.parse("innerJoin("- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"- + "on=\"join1_i=join1_i, join2_s=join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "innerJoin("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"+ + "on=\"join1_i=join1_i, join2_s=join2_s\")");stream = new InnerJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2039,20 +2367,32 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 7, 3, 4, 5, 1, 1, 15, 15);// Results in both searches, no join matches- expression = StreamExpressionParser.parse("innerJoin("- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:right\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\", aliases=\"id=right.id, join1_i=right.join1_i, join2_s=right.join2_s, ident_s=right.ident_s\"),"- + "on=\"ident_s=right.ident_s\")");+ expression =+ StreamExpressionParser.parse(+ "innerJoin("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:right\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\", aliases=\"id=right.id, join1_i=right.join1_i, join2_s=right.join2_s, ident_s=right.ident_s\"),"+ + "on=\"ident_s=right.ident_s\")");stream = new InnerJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);assert (tuples.size() == 0);// Differing field names- expression = StreamExpressionParser.parse("innerJoin("- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join3_i asc, join2_s asc\", aliases=\"join3_i=aliasesField\"),"- + "on=\"join1_i=aliasesField, join2_s=join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "innerJoin("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join3_i asc, join2_s asc\", aliases=\"join3_i=aliasesField\"),"+ + "on=\"join1_i=aliasesField, join2_s=join2_s\")");stream = new InnerJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2069,21 +2409,35 @@ public class StreamDecoratorTest extends SolrCloudTestCase {new UpdateRequest().add(id, "1", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9- .add(id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9+ .add(+ id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9.add(id, "2", "side_s", "left", "join1_i", "0", "join2_s", "b", "ident_s", "left_2").add(id, "3", "side_s", "left", "join1_i", "1", "join2_s", "a", "ident_s", "left_3") // 10.add(id, "4", "side_s", "left", "join1_i", "1", "join2_s", "b", "ident_s", "left_4") // 11.add(id, "5", "side_s", "left", "join1_i", "1", "join2_s", "c", "ident_s", "left_5") // 12.add(id, "6", "side_s", "left", "join1_i", "2", "join2_s", "d", "ident_s", "left_6").add(id, "7", "side_s", "left", "join1_i", "3", "join2_s", "e", "ident_s", "left_7") // 14-- .add(id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1", "join3_i", "0") // 1,15- .add(id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2", "join3_i", "0") // 1,15- .add(id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3", "join3_i", "1") // 3- .add(id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4", "join3_i", "1") // 4- .add(id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5", "join3_i", "1") // 5- .add(id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6", "join3_i", "2")- .add(id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7", "join3_i", "3") // 7+ .add(+ id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1",+ "join3_i", "0") // 1,15+ .add(+ id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2",+ "join3_i", "0") // 1,15+ .add(+ id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3",+ "join3_i", "1") // 3+ .add(+ id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4",+ "join3_i", "1") // 4+ .add(+ id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5",+ "join3_i", "1") // 5+ .add(+ id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6",+ "join3_i", "2")+ .add(+ id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7",+ "join3_i", "3") // 7.commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamExpression expression;@@ -2092,18 +2446,25 @@ public class StreamDecoratorTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("leftOuterJoin", LeftOuterJoinStream.class);-++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("leftOuterJoin", LeftOuterJoinStream.class);+// Basic testtry {- expression = StreamExpressionParser.parse("leftOuterJoin("- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc\"),"- + "on=\"join1_i=join1_i, join2_s=join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "leftOuterJoin("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc\"),"+ + "on=\"join1_i=join1_i, join2_s=join2_s\")");stream = new LeftOuterJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2111,10 +2472,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 1, 1, 15, 15, 2, 3, 4, 5, 6, 7);// Basic desc- expression = StreamExpressionParser.parse("leftOuterJoin("- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"- + "on=\"join1_i=join1_i, join2_s=join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "leftOuterJoin("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"+ + "on=\"join1_i=join1_i, join2_s=join2_s\")");stream = new LeftOuterJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2122,10 +2489,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 7, 6, 3, 4, 5, 1, 1, 15, 15, 2);// Results in both searches, no join matches- expression = StreamExpressionParser.parse("leftOuterJoin("- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:right\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\", aliases=\"id=right.id, join1_i=right.join1_i, join2_s=right.join2_s, ident_s=right.ident_s\"),"- + "on=\"ident_s=right.ident_s\")");+ expression =+ StreamExpressionParser.parse(+ "leftOuterJoin("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:right\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\", aliases=\"id=right.id, join1_i=right.join1_i, join2_s=right.join2_s, ident_s=right.ident_s\"),"+ + "on=\"ident_s=right.ident_s\")");stream = new LeftOuterJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2133,10 +2506,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 1, 15, 2, 3, 4, 5, 6, 7);// Differing field names- expression = StreamExpressionParser.parse("leftOuterJoin("- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"- + "search(" + COLLECTIONORALIAS + ", q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join3_i asc, join2_s asc\", aliases=\"join3_i=aliasesField\"),"- + "on=\"join1_i=aliasesField, join2_s=join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "leftOuterJoin("+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"+ + "search("+ + COLLECTIONORALIAS+ + ", q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join3_i asc, join2_s asc\", aliases=\"join3_i=aliasesField\"),"+ + "on=\"join1_i=aliasesField, join2_s=join2_s\")");stream = new LeftOuterJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2152,21 +2531,35 @@ public class StreamDecoratorTest extends SolrCloudTestCase {new UpdateRequest().add(id, "1", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9- .add(id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9+ .add(+ id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9.add(id, "2", "side_s", "left", "join1_i", "0", "join2_s", "b", "ident_s", "left_2").add(id, "3", "side_s", "left", "join1_i", "1", "join2_s", "a", "ident_s", "left_3") // 10.add(id, "4", "side_s", "left", "join1_i", "1", "join2_s", "b", "ident_s", "left_4") // 11.add(id, "5", "side_s", "left", "join1_i", "1", "join2_s", "c", "ident_s", "left_5") // 12.add(id, "6", "side_s", "left", "join1_i", "2", "join2_s", "d", "ident_s", "left_6").add(id, "7", "side_s", "left", "join1_i", "3", "join2_s", "e", "ident_s", "left_7") // 14-- .add(id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1", "join3_i", "0") // 1,15- .add(id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2", "join3_i", "0") // 1,15- .add(id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3", "join3_i", "1") // 3- .add(id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4", "join3_i", "1") // 4- .add(id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5", "join3_i", "1") // 5- .add(id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6", "join3_i", "2")- .add(id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7", "join3_i", "3") // 7+ .add(+ id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1",+ "join3_i", "0") // 1,15+ .add(+ id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2",+ "join3_i", "0") // 1,15+ .add(+ id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3",+ "join3_i", "1") // 3+ .add(+ id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4",+ "join3_i", "1") // 4+ .add(+ id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5",+ "join3_i", "1") // 5+ .add(+ id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6",+ "join3_i", "2")+ .add(+ id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7",+ "join3_i", "3") // 7.commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamExpression expression;@@ -2175,17 +2568,20 @@ public class StreamDecoratorTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("hashJoin", HashJoinStream.class);++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("hashJoin", HashJoinStream.class);try {// Basic test- expression = StreamExpressionParser.parse("hashJoin("- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"- + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc\"),"- + "on=\"join1_i, join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "hashJoin("+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"+ + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc\"),"+ + "on=\"join1_i, join2_s\")");stream = new HashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2193,10 +2589,12 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 1, 1, 15, 15, 3, 4, 5, 7);// Basic desc- expression = StreamExpressionParser.parse("hashJoin("- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"- + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"- + "on=\"join1_i, join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "hashJoin("+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"+ + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"+ + "on=\"join1_i, join2_s\")");stream = new HashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2204,65 +2602,71 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 7, 3, 4, 5, 1, 1, 15, 15);// Results in both searches, no join matches- expression = StreamExpressionParser.parse("hashJoin("- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"- + "hashed=search(collection1, q=\"side_s:right\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"- + "on=\"ident_s\")");+ expression =+ StreamExpressionParser.parse(+ "hashJoin("+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"+ + "hashed=search(collection1, q=\"side_s:right\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"+ + "on=\"ident_s\")");stream = new HashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);assert (tuples.size() == 0);// Basic test with "on" mapping- expression = StreamExpressionParser.parse("hashJoin("- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join3_i,ident_s\", sort=\"join1_i asc, join3_i asc, id asc\"),"- + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join3_i,ident_s\", sort=\"join1_i asc, join3_i asc\"),"- + "on=\"join1_i=join3_i\")");+ expression =+ StreamExpressionParser.parse(+ "hashJoin("+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join3_i,ident_s\", sort=\"join1_i asc, join3_i asc, id asc\"),"+ + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join3_i,ident_s\", sort=\"join1_i asc, join3_i asc\"),"+ + "on=\"join1_i=join3_i\")");stream = new HashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);assertEquals(17, tuples.size());- //Does a lexical sort+ // Does a lexical sortassertOrder(tuples, 1, 1, 15, 15, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 7);} finally {solrClientCache.close();}}-+@Testpublic void testHashJoinStreamWithKnownConflict() throws Exception {new UpdateRequest()- .add(id, "1", "type_s","left", "bbid_s", "MG!!00TNH1", "ykey_s", "Mtge")- .add(id, "2", "type_s","right", "bbid_s", "MG!!00TNGP", "ykey_s", "Mtge")+ .add(id, "1", "type_s", "left", "bbid_s", "MG!!00TNH1", "ykey_s", "Mtge")+ .add(id, "2", "type_s", "right", "bbid_s", "MG!!00TNGP", "ykey_s", "Mtge").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-+StreamExpression expression;TupleStream stream;List<Tuple> tuples;StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("hashJoin", HashJoinStream.class);++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("hashJoin", HashJoinStream.class);try {// Basic test- expression = StreamExpressionParser.parse("hashJoin("- + " search(collection1, q=*:*, fl=\"bbid_s,ykey_s\", fq=\"type_s:left\", sort=\"bbid_s asc, ykey_s asc\"),"- + " hashed=search(collection1, q=*:*, fl=\"bbid_s,ykey_s\", fq=\"type_s:right\", sort=\"bbid_s asc, ykey_s asc\"),"- + " on=\"bbid_s,ykey_s\""- + ")");+ expression =+ StreamExpressionParser.parse(+ "hashJoin("+ + " search(collection1, q=*:*, fl=\"bbid_s,ykey_s\", fq=\"type_s:left\", sort=\"bbid_s asc, ykey_s asc\"),"+ + " hashed=search(collection1, q=*:*, fl=\"bbid_s,ykey_s\", fq=\"type_s:right\", sort=\"bbid_s asc, ykey_s asc\"),"+ + " on=\"bbid_s,ykey_s\""+ + ")");stream = new HashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);-+assertEquals(0, tuples.size());--+} finally {solrClientCache.close();}@@ -2272,35 +2676,38 @@ public class StreamDecoratorTest extends SolrCloudTestCase {public void testOuterHashJoinStreamWithKnownConflict() throws Exception {new UpdateRequest()- .add(id, "1", "type_s","left", "bbid_s", "MG!!00TNH1", "ykey_s", "Mtge")- .add(id, "2", "type_s","right", "bbid_s", "MG!!00TNGP", "ykey_s", "Mtge", "extra_s", "foo")+ .add(id, "1", "type_s", "left", "bbid_s", "MG!!00TNH1", "ykey_s", "Mtge")+ .add(id, "2", "type_s", "right", "bbid_s", "MG!!00TNGP", "ykey_s", "Mtge", "extra_s", "foo").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-+StreamExpression expression;TupleStream stream;List<Tuple> tuples;StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("outerHashJoin", OuterHashJoinStream.class);++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("outerHashJoin", OuterHashJoinStream.class);try {// Basic test- expression = StreamExpressionParser.parse("outerHashJoin("- + " search(collection1, q=*:*, fl=\"bbid_s,ykey_s\", fq=\"type_s:left\", sort=\"bbid_s asc, ykey_s asc\"),"- + " hashed=search(collection1, q=*:*, fl=\"bbid_s,ykey_s,extra_s\", fq=\"type_s:right\", sort=\"bbid_s asc, ykey_s asc\"),"- + " on=\"bbid_s,ykey_s\""- + ")");+ expression =+ StreamExpressionParser.parse(+ "outerHashJoin("+ + " search(collection1, q=*:*, fl=\"bbid_s,ykey_s\", fq=\"type_s:left\", sort=\"bbid_s asc, ykey_s asc\"),"+ + " hashed=search(collection1, q=*:*, fl=\"bbid_s,ykey_s,extra_s\", fq=\"type_s:right\", sort=\"bbid_s asc, ykey_s asc\"),"+ + " on=\"bbid_s,ykey_s\""+ + ")");stream = new OuterHashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);-+assertEquals(1, tuples.size());assertFalse(tuples.get(0).getFields().containsKey("extra_s"));-+} finally {solrClientCache.close();}@@ -2311,21 +2718,35 @@ public class StreamDecoratorTest extends SolrCloudTestCase {new UpdateRequest().add(id, "1", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9- .add(id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9+ .add(+ id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9.add(id, "2", "side_s", "left", "join1_i", "0", "join2_s", "b", "ident_s", "left_2").add(id, "3", "side_s", "left", "join1_i", "1", "join2_s", "a", "ident_s", "left_3") // 10.add(id, "4", "side_s", "left", "join1_i", "1", "join2_s", "b", "ident_s", "left_4") // 11.add(id, "5", "side_s", "left", "join1_i", "1", "join2_s", "c", "ident_s", "left_5") // 12.add(id, "6", "side_s", "left", "join1_i", "2", "join2_s", "d", "ident_s", "left_6").add(id, "7", "side_s", "left", "join1_i", "3", "join2_s", "e", "ident_s", "left_7") // 14-- .add(id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1", "join3_i", "0") // 1,15- .add(id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2", "join3_i", "0") // 1,15- .add(id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3", "join3_i", "1") // 3- .add(id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4", "join3_i", "1") // 4- .add(id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5", "join3_i", "1") // 5- .add(id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6", "join3_i", "2")- .add(id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7", "join3_i", "3") // 7+ .add(+ id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1",+ "join3_i", "0") // 1,15+ .add(+ id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2",+ "join3_i", "0") // 1,15+ .add(+ id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3",+ "join3_i", "1") // 3+ .add(+ id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4",+ "join3_i", "1") // 4+ .add(+ id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5",+ "join3_i", "1") // 5+ .add(+ id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6",+ "join3_i", "2")+ .add(+ id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7",+ "join3_i", "3") // 7.commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamExpression expression;@@ -2334,17 +2755,20 @@ public class StreamDecoratorTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("outerHashJoin", OuterHashJoinStream.class);++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("outerHashJoin", OuterHashJoinStream.class);try {// Basic test- expression = StreamExpressionParser.parse("outerHashJoin("- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"- + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc\"),"- + "on=\"join1_i, join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "outerHashJoin("+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"+ + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc\"),"+ + "on=\"join1_i, join2_s\")");stream = new OuterHashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2352,10 +2776,12 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 1, 1, 15, 15, 2, 3, 4, 5, 6, 7);// Basic desc- expression = StreamExpressionParser.parse("outerHashJoin("- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"- + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"- + "on=\"join1_i, join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "outerHashJoin("+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"+ + "hashed=search(collection1, q=\"side_s:right\", fl=\"join1_i,join2_s,ident_s\", sort=\"join1_i desc, join2_s asc\"),"+ + "on=\"join1_i, join2_s\")");stream = new OuterHashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2363,10 +2789,12 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 7, 6, 3, 4, 5, 1, 1, 15, 15, 2);// Results in both searches, no join matches- expression = StreamExpressionParser.parse("outerHashJoin("- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"- + "hashed=search(collection1, q=\"side_s:right\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"- + "on=\"ident_s\")");+ expression =+ StreamExpressionParser.parse(+ "outerHashJoin("+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"+ + "hashed=search(collection1, q=\"side_s:right\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"ident_s asc\"),"+ + "on=\"ident_s\")");stream = new OuterHashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2374,10 +2802,12 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertOrder(tuples, 1, 15, 2, 3, 4, 5, 6, 7);// Basic test- expression = StreamExpressionParser.parse("outerHashJoin("- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"- + "hashed=search(collection1, q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join2_s asc\"),"- + "on=\"join1_i=join3_i, join2_s\")");+ expression =+ StreamExpressionParser.parse(+ "outerHashJoin("+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\"),"+ + "hashed=search(collection1, q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join2_s asc\"),"+ + "on=\"join1_i=join3_i, join2_s\")");stream = new OuterHashJoinStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2393,21 +2823,35 @@ public class StreamDecoratorTest extends SolrCloudTestCase {new UpdateRequest().add(id, "1", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9- .add(id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9+ .add(+ id, "15", "side_s", "left", "join1_i", "0", "join2_s", "a", "ident_s", "left_1") // 8, 9.add(id, "2", "side_s", "left", "join1_i", "0", "join2_s", "b", "ident_s", "left_2").add(id, "3", "side_s", "left", "join1_i", "1", "join2_s", "a", "ident_s", "left_3") // 10.add(id, "4", "side_s", "left", "join1_i", "1", "join2_s", "b", "ident_s", "left_4") // 11.add(id, "5", "side_s", "left", "join1_i", "1", "join2_s", "c", "ident_s", "left_5") // 12.add(id, "6", "side_s", "left", "join1_i", "2", "join2_s", "d", "ident_s", "left_6").add(id, "7", "side_s", "left", "join1_i", "3", "join2_s", "e", "ident_s", "left_7") // 14-- .add(id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1", "join3_i", "0") // 1,15- .add(id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2", "join3_i", "0") // 1,15- .add(id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3", "join3_i", "1") // 3- .add(id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4", "join3_i", "1") // 4- .add(id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5", "join3_i", "1") // 5- .add(id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6", "join3_i", "2")- .add(id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7", "join3_i", "3") // 7+ .add(+ id, "8", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_1",+ "join3_i", "0") // 1,15+ .add(+ id, "9", "side_s", "right", "join1_i", "0", "join2_s", "a", "ident_s", "right_2",+ "join3_i", "0") // 1,15+ .add(+ id, "10", "side_s", "right", "join1_i", "1", "join2_s", "a", "ident_s", "right_3",+ "join3_i", "1") // 3+ .add(+ id, "11", "side_s", "right", "join1_i", "1", "join2_s", "b", "ident_s", "right_4",+ "join3_i", "1") // 4+ .add(+ id, "12", "side_s", "right", "join1_i", "1", "join2_s", "c", "ident_s", "right_5",+ "join3_i", "1") // 5+ .add(+ id, "13", "side_s", "right", "join1_i", "2", "join2_s", "dad", "ident_s", "right_6",+ "join3_i", "2")+ .add(+ id, "14", "side_s", "right", "join1_i", "3", "join2_s", "e", "ident_s", "right_7",+ "join3_i", "3") // 7.commit(cluster.getSolrClient(), COLLECTIONORALIAS);String clause;@@ -2418,24 +2862,25 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("innerJoin", InnerJoinStream.class)- .withFunctionName("select", SelectStream.class)- .withFunctionName("replace", ReplaceOperation.class)- .withFunctionName("concat", ConcatOperation.class)- .withFunctionName("add", AddEvaluator.class)- .withFunctionName("if", IfThenElseEvaluator.class)- .withFunctionName("gt", GreaterThanEvaluator.class)- ;+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("innerJoin", InnerJoinStream.class)+ .withFunctionName("select", SelectStream.class)+ .withFunctionName("replace", ReplaceOperation.class)+ .withFunctionName("concat", ConcatOperation.class)+ .withFunctionName("add", AddEvaluator.class)+ .withFunctionName("if", IfThenElseEvaluator.class)+ .withFunctionName("gt", GreaterThanEvaluator.class);try {// Basic test- clause = "select("- + "id, join1_i as join1, join2_s as join2, ident_s as identity,"- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"- + ")";+ clause =+ "select("+ + "id, join1_i as join1, join2_s as join2, ident_s as identity,"+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"+ + ")";stream = factory.constructStream(clause);stream.setStreamContext(streamContext);@@ -2444,11 +2889,12 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertNotFields(tuples, "join1_i", "join2_s", "ident_s");// Basic with replacements test- clause = "select("- + "id, join1_i as join1, join2_s as join2, ident_s as identity,"- + "replace(join1, 0, withValue=12), replace(join1, 3, withValue=12), replace(join1, 2, withField=join2),"- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"- + ")";+ clause =+ "select("+ + "id, join1_i as join1, join2_s as join2, ident_s as identity,"+ + "replace(join1, 0, withValue=12), replace(join1, 3, withValue=12), replace(join1, 2, withField=join2),"+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"+ + ")";stream = factory.constructStream(clause);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2460,14 +2906,14 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertLong(tuples.get(7), "join1", 12);assertString(tuples.get(6), "join1", "d");-// Basic with replacements and concat test- clause = "select("- + "id, join1_i as join1, join2_s as join2, ident_s as identity,"- + "replace(join1, 0, withValue=12), replace(join1, 3, withValue=12), replace(join1, 2, withField=join2),"- + "concat(fields=\"identity,join1\", as=\"newIdentity\",delim=\"-\"),"- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"- + ")";+ clause =+ "select("+ + "id, join1_i as join1, join2_s as join2, ident_s as identity,"+ + "replace(join1, 0, withValue=12), replace(join1, 3, withValue=12), replace(join1, 2, withField=join2),"+ + "concat(fields=\"identity,join1\", as=\"newIdentity\",delim=\"-\"),"+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"+ + ")";stream = factory.constructStream(clause);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2485,37 +2931,47 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertString(tuples.get(6), "newIdentity", "left_6-d");// Inner stream test- clause = "innerJoin("- + "select("- + "id, join1_i as left.join1, join2_s as left.join2, ident_s as left.ident,"- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"- + "),"- + "select("- + "join3_i as right.join1, join2_s as right.join2, ident_s as right.ident,"- + "search(collection1, q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join3_i asc, join2_s asc\"),"- + "),"- + "on=\"left.join1=right.join1, left.join2=right.join2\""- + ")";+ clause =+ "innerJoin("+ + "select("+ + "id, join1_i as left.join1, join2_s as left.join2, ident_s as left.ident,"+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"+ + "),"+ + "select("+ + "join3_i as right.join1, join2_s as right.join2, ident_s as right.ident,"+ + "search(collection1, q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join3_i asc, join2_s asc\"),"+ + "),"+ + "on=\"left.join1=right.join1, left.join2=right.join2\""+ + ")";stream = factory.constructStream(clause);stream.setStreamContext(streamContext);tuples = getTuples(stream);- assertFields(tuples, "id", "left.join1", "left.join2", "left.ident", "right.join1", "right.join2", "right.ident");+ assertFields(+ tuples,+ "id",+ "left.join1",+ "left.join2",+ "left.ident",+ "right.join1",+ "right.join2",+ "right.ident");// Wrapped select test- clause = "select("- + "id, left.ident, right.ident,"- + "innerJoin("- + "select("- + "id, join1_i as left.join1, join2_s as left.join2, ident_s as left.ident,"- + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"- + "),"- + "select("- + "join3_i as right.join1, join2_s as right.join2, ident_s as right.ident,"- + "search(collection1, q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join3_i asc, join2_s asc\"),"- + "),"- + "on=\"left.join1=right.join1, left.join2=right.join2\""- + ")"- + ")";+ clause =+ "select("+ + "id, left.ident, right.ident,"+ + "innerJoin("+ + "select("+ + "id, join1_i as left.join1, join2_s as left.join2, ident_s as left.ident,"+ + "search(collection1, q=\"side_s:left\", fl=\"id,join1_i,join2_s,ident_s\", sort=\"join1_i asc, join2_s asc, id asc\")"+ + "),"+ + "select("+ + "join3_i as right.join1, join2_s as right.join2, ident_s as right.ident,"+ + "search(collection1, q=\"side_s:right\", fl=\"join3_i,join2_s,ident_s\", sort=\"join3_i asc, join2_s asc\"),"+ + "),"+ + "on=\"left.join1=right.join1, left.join2=right.join2\""+ + ")"+ + ")";stream = factory.constructStream(clause);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2543,10 +2999,11 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello1", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("topic", TopicStream.class)- .withFunctionName("priority", PriorityStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("topic", TopicStream.class)+ .withFunctionName("priority", PriorityStream.class);StreamExpression expression;TupleStream stream;@@ -2557,8 +3014,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {try {FieldComparator comp = new FieldComparator("a_i", ComparatorOrder.ASCENDING);- expression = StreamExpressionParser.parse("priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0)," +- "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0))");+ expression =+ StreamExpressionParser.parse(+ "priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0),"+ + "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0))");stream = factory.constructStream(expression);StreamContext context = new StreamContext();context.setSolrClientCache(cache);@@ -2566,13 +3025,15 @@ public class StreamDecoratorTest extends SolrCloudTestCase {tuples = getTuples(stream);Collections.sort(tuples, comp);- //The tuples from the first topic (high priority) should be returned.+ // The tuples from the first topic (high priority) should be returned.assertEquals(tuples.size(), 4);assertOrder(tuples, 5, 6, 7, 8);- expression = StreamExpressionParser.parse("priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0)," +- "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0))");+ expression =+ StreamExpressionParser.parse(+ "priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0),"+ + "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0))");stream = factory.constructStream(expression);context = new StreamContext();context.setSolrClientCache(cache);@@ -2580,19 +3041,21 @@ public class StreamDecoratorTest extends SolrCloudTestCase {tuples = getTuples(stream);Collections.sort(tuples, comp);- //The Tuples from the second topic (Low priority) should be returned.+ // The Tuples from the second topic (Low priority) should be returned.assertEquals(tuples.size(), 6);assertOrder(tuples, 0, 1, 2, 3, 4, 9);- expression = StreamExpressionParser.parse("priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0)," +- "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0))");+ expression =+ StreamExpressionParser.parse(+ "priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0),"+ + "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0))");stream = factory.constructStream(expression);context = new StreamContext();context.setSolrClientCache(cache);stream.setStreamContext(context);tuples = getTuples(stream);- //Both queus are empty.+ // Both queus are empty.assertEquals(tuples.size(), 0);} finally {@@ -2617,11 +3080,12 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello1", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("topic", TopicStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("priority", PriorityStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("topic", TopicStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("priority", PriorityStream.class);StreamExpression expression;TupleStream stream;@@ -2632,8 +3096,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {try {FieldComparator comp = new FieldComparator("a_i", ComparatorOrder.ASCENDING);- expression = StreamExpressionParser.parse("parallel(collection1, workers=2, sort=\"_version_ asc\", priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0, partitionKeys=id)," +- "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0, partitionKeys=id)))");+ expression =+ StreamExpressionParser.parse(+ "parallel(collection1, workers=2, sort=\"_version_ asc\", priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0, partitionKeys=id),"+ + "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0, partitionKeys=id)))");stream = factory.constructStream(expression);StreamContext context = new StreamContext();context.setSolrClientCache(cache);@@ -2641,13 +3107,15 @@ public class StreamDecoratorTest extends SolrCloudTestCase {tuples = getTuples(stream);Collections.sort(tuples, comp);- //The tuples from the first topic (high priority) should be returned.+ // The tuples from the first topic (high priority) should be returned.assertEquals(tuples.size(), 4);assertOrder(tuples, 5, 6, 7, 8);- expression = StreamExpressionParser.parse("parallel(collection1, workers=2, sort=\"_version_ asc\", priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0, partitionKeys=id)," +- "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0, partitionKeys=id)))");+ expression =+ StreamExpressionParser.parse(+ "parallel(collection1, workers=2, sort=\"_version_ asc\", priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0, partitionKeys=id),"+ + "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0, partitionKeys=id)))");stream = factory.constructStream(expression);context = new StreamContext();context.setSolrClientCache(cache);@@ -2655,19 +3123,21 @@ public class StreamDecoratorTest extends SolrCloudTestCase {tuples = getTuples(stream);Collections.sort(tuples, comp);- //The Tuples from the second topic (Low priority) should be returned.+ // The Tuples from the second topic (Low priority) should be returned.assertEquals(tuples.size(), 6);assertOrder(tuples, 0, 1, 2, 3, 4, 9);- expression = StreamExpressionParser.parse("parallel(collection1, workers=2, sort=\"_version_ asc\", priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0, partitionKeys=id)," +- "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0, partitionKeys=id)))");+ expression =+ StreamExpressionParser.parse(+ "parallel(collection1, workers=2, sort=\"_version_ asc\", priority(topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_i\", id=1000000, initialCheckpoint=0, partitionKeys=id),"+ + "topic(collection1, collection1, q=\"a_s:hello1\", fl=\"id,a_i\", id=2000000, initialCheckpoint=0, partitionKeys=id)))");stream = factory.constructStream(expression);context = new StreamContext();context.setSolrClientCache(cache);stream.setStreamContext(context);tuples = getTuples(stream);- //Both queus are empty.+ // Both queus are empty.assertEquals(tuples.size(), 0);} finally {@@ -2678,18 +3148,29 @@ public class StreamDecoratorTest extends SolrCloudTestCase {@Testpublic void testUpdateStream() throws Exception {- CollectionAdminRequest.createCollection("destinationCollection", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("destinationCollection", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("destinationCollection", 2, 2);new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb", "i_multi", "4", "i_multi", "7")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi", "bbbb1", "i_multi", "44", "i_multi", "77")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi", "bbbb2", "i_multi", "444", "i_multi", "777")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi", "bbbb3", "i_multi", "4444", "i_multi", "7777")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi", "bbbb4", "i_multi", "44444", "i_multi", "77777")+ .add(+ id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb",+ "i_multi", "4", "i_multi", "7")+ .add(+ id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi",+ "bbbb1", "i_multi", "44", "i_multi", "77")+ .add(+ id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi",+ "bbbb2", "i_multi", "444", "i_multi", "777")+ .add(+ id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi",+ "bbbb3", "i_multi", "4444", "i_multi", "7777")+ .add(+ id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi",+ "bbbb4", "i_multi", "44444", "i_multi", "77777").commit(cluster.getSolrClient(), "collection1");-+StreamExpression expression;TupleStream stream;Tuple t;@@ -2697,29 +3178,34 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class);try {- //Copy all docs to destinationCollection+ // Copy all docs to destinationCollection// confirm update() stream defaults to ignoring _version_ field in tuples- expression = StreamExpressionParser.parse("update(destinationCollection, batchSize=5, search(collection1, q=*:*, fl=\"id,_version_,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\"))");+ expression =+ StreamExpressionParser.parse(+ "update(destinationCollection, batchSize=5, search(collection1, q=*:*, fl=\"id,_version_,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\"))");stream = new UpdateStream(expression, factory);stream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(stream);cluster.getSolrClient().commit("destinationCollection");- //Ensure that all UpdateStream tuples indicate the correct number of copied/indexed docs+ // Ensure that all UpdateStream tuples indicate the correct number of copied/indexed docsassert (tuples.size() == 1);t = tuples.get(0);assert (t.EOF == false);assertEquals(5, t.get("batchIndexed"));- //Ensure that destinationCollection actually has the new docs.- expression = StreamExpressionParser.parse("search(destinationCollection, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");+ // Ensure that destinationCollection actually has the new docs.+ expression =+ StreamExpressionParser.parse(+ "search(destinationCollection, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2765,7 +3251,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertList(tuple.getStrings("s_multi"), "aaaa3", "bbbb3");assertList(tuple.getLongs("i_multi"), Long.parseLong("4444"), Long.parseLong("7777"));} finally {- CollectionAdminRequest.deleteCollection("destinationCollection").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("destinationCollection")+ .process(cluster.getSolrClient());solrClientCache.close();}}@@ -2773,42 +3260,62 @@ public class StreamDecoratorTest extends SolrCloudTestCase {@Testpublic void testParallelUpdateStream() throws Exception {- CollectionAdminRequest.createCollection("parallelDestinationCollection", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("parallelDestinationCollection", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("parallelDestinationCollection", 2, 2);new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb", "i_multi", "4", "i_multi", "7")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi", "bbbb1", "i_multi", "44", "i_multi", "77")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi", "bbbb2", "i_multi", "444", "i_multi", "777")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi", "bbbb3", "i_multi", "4444", "i_multi", "7777")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi", "bbbb4", "i_multi", "44444", "i_multi", "77777")+ .add(+ id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb",+ "i_multi", "4", "i_multi", "7")+ .add(+ id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi",+ "bbbb1", "i_multi", "44", "i_multi", "77")+ .add(+ id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi",+ "bbbb2", "i_multi", "444", "i_multi", "777")+ .add(+ id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi",+ "bbbb3", "i_multi", "4444", "i_multi", "7777")+ .add(+ id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi",+ "bbbb4", "i_multi", "44444", "i_multi", "77777").commit(cluster.getSolrClient(), "collection1");-+StreamExpression expression;TupleStream stream;Tuple t;StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-+String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("parallelDestinationCollection", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class)- .withFunctionName("parallel", ParallelStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost(+ "parallelDestinationCollection", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class)+ .withFunctionName("parallel", ParallelStream.class);try {- //Copy all docs to destinationCollection- String updateExpression = "update(parallelDestinationCollection, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"))";- TupleStream parallelUpdateStream = factory.constructStream("parallel(collection1, " + updateExpression + ", workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"batchNumber asc\")");+ // Copy all docs to destinationCollection+ String updateExpression =+ "update(parallelDestinationCollection, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"))";+ TupleStream parallelUpdateStream =+ factory.constructStream(+ "parallel(collection1, "+ + updateExpression+ + ", workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"batchNumber asc\")");parallelUpdateStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(parallelUpdateStream);cluster.getSolrClient().commit("parallelDestinationCollection");- //Ensure that all UpdateStream tuples indicate the correct number of copied/indexed docs+ // Ensure that all UpdateStream tuples indicate the correct number of copied/indexed docslong count = 0;for (Tuple tuple : tuples) {@@ -2817,8 +3324,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assert (count == 5);- //Ensure that destinationCollection actually has the new docs.- expression = StreamExpressionParser.parse("search(parallelDestinationCollection, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");+ // Ensure that destinationCollection actually has the new docs.+ expression =+ StreamExpressionParser.parse(+ "search(parallelDestinationCollection, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -2864,7 +3373,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertList(tuple.getStrings("s_multi"), "aaaa3", "bbbb3");assertList(tuple.getLongs("i_multi"), Long.parseLong("4444"), Long.parseLong("7777"));} finally {- CollectionAdminRequest.deleteCollection("parallelDestinationCollection").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("parallelDestinationCollection")+ .process(cluster.getSolrClient());solrClientCache.close();}}@@ -2872,16 +3382,27 @@ public class StreamDecoratorTest extends SolrCloudTestCase {@Testpublic void testParallelDaemonUpdateStream() throws Exception {- CollectionAdminRequest.createCollection("parallelDestinationCollection1", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("parallelDestinationCollection1", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("parallelDestinationCollection1", 2, 2);new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb", "i_multi", "4", "i_multi", "7")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi", "bbbb1", "i_multi", "44", "i_multi", "77")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi", "bbbb2", "i_multi", "444", "i_multi", "777")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi", "bbbb3", "i_multi", "4444", "i_multi", "7777")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi", "bbbb4", "i_multi", "44444", "i_multi", "77777")+ .add(+ id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb",+ "i_multi", "4", "i_multi", "7")+ .add(+ id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi",+ "bbbb1", "i_multi", "44", "i_multi", "77")+ .add(+ id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi",+ "bbbb2", "i_multi", "444", "i_multi", "777")+ .add(+ id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi",+ "bbbb3", "i_multi", "4444", "i_multi", "7777")+ .add(+ id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi",+ "bbbb4", "i_multi", "44444", "i_multi", "77777").commit(cluster.getSolrClient(), "collection1");StreamExpression expression;@@ -2892,32 +3413,43 @@ public class StreamDecoratorTest extends SolrCloudTestCase {streamContext.setSolrClientCache(solrClientCache);String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("parallelDestinationCollection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("daemon", DaemonStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost(+ "parallelDestinationCollection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("daemon", DaemonStream.class);try {- //Copy all docs to destinationCollection- String updateExpression = "daemon(update(parallelDestinationCollection1, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\")), runInterval=\"1000\", id=\"test\")";- TupleStream parallelUpdateStream = factory.constructStream("parallel(collection1, " + updateExpression + ", workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"batchNumber asc\")");+ // Copy all docs to destinationCollection+ String updateExpression =+ "daemon(update(parallelDestinationCollection1, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\")), runInterval=\"1000\", id=\"test\")";+ TupleStream parallelUpdateStream =+ factory.constructStream(+ "parallel(collection1, "+ + updateExpression+ + ", workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"batchNumber asc\")");parallelUpdateStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(parallelUpdateStream);assert (tuples.size() == 2);- //Lets sleep long enough for daemon updates to run.- //Lets stop the daemons- ModifiableSolrParams sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream", "action", "list"));+ // Lets sleep long enough for daemon updates to run.+ // Lets stop the daemons+ ModifiableSolrParams sParams =+ new ModifiableSolrParams(params(CommonParams.QT, "/stream", "action", "list"));int workersComplete = 0;for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {int iterations = 0;INNER:while (iterations == 0) {- SolrStream solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);+ SolrStream solrStream =+ new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);solrStream.setStreamContext(streamContext);solrStream.open();Tuple tupleResponse = solrStream.read();@@ -2945,7 +3477,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {cluster.getSolrClient().commit("parallelDestinationCollection1");- //Lets stop the daemons+ // Lets stop the daemonssParams = new ModifiableSolrParams();sParams.set(CommonParams.QT, "/stream");sParams.set("action", "stop");@@ -2991,8 +3523,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {}assertEquals(cluster.getJettySolrRunners().size(), workersComplete);- //Ensure that destinationCollection actually has the new docs.- expression = StreamExpressionParser.parse("search(parallelDestinationCollection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");+ // Ensure that destinationCollection actually has the new docs.+ expression =+ StreamExpressionParser.parse(+ "search(parallelDestinationCollection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3038,7 +3572,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertList(tuple.getStrings("s_multi"), "aaaa3", "bbbb3");assertList(tuple.getLongs("i_multi"), Long.parseLong("4444"), Long.parseLong("7777"));} finally {- CollectionAdminRequest.deleteCollection("parallelDestinationCollection1").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("parallelDestinationCollection1")+ .process(cluster.getSolrClient());solrClientCache.close();}}@@ -3047,16 +3582,27 @@ public class StreamDecoratorTest extends SolrCloudTestCase {public void testParallelTerminatingDaemonUpdateStream() throws Exception {Assume.assumeTrue(!useAlias);- CollectionAdminRequest.createCollection("parallelDestinationCollection1", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("parallelDestinationCollection1", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("parallelDestinationCollection1", 2, 2);new UpdateRequest()- .add(id, "0", "a_s", "hello", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb", "i_multi", "4", "i_multi", "7")- .add(id, "2", "a_s", "hello", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi", "bbbb1", "i_multi", "44", "i_multi", "77")- .add(id, "3", "a_s", "hello", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi", "bbbb2", "i_multi", "444", "i_multi", "777")- .add(id, "4", "a_s", "hello", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi", "bbbb3", "i_multi", "4444", "i_multi", "7777")- .add(id, "1", "a_s", "hello", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi", "bbbb4", "i_multi", "44444", "i_multi", "77777")+ .add(+ id, "0", "a_s", "hello", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb",+ "i_multi", "4", "i_multi", "7")+ .add(+ id, "2", "a_s", "hello", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi", "bbbb1",+ "i_multi", "44", "i_multi", "77")+ .add(+ id, "3", "a_s", "hello", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi", "bbbb2",+ "i_multi", "444", "i_multi", "777")+ .add(+ id, "4", "a_s", "hello", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi", "bbbb3",+ "i_multi", "4444", "i_multi", "7777")+ .add(+ id, "1", "a_s", "hello", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi", "bbbb4",+ "i_multi", "44444", "i_multi", "77777").commit(cluster.getSolrClient(), "collection1");StreamExpression expression;@@ -3067,33 +3613,43 @@ public class StreamDecoratorTest extends SolrCloudTestCase {streamContext.setSolrClientCache(solrClientCache);String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("parallelDestinationCollection1", cluster.getZkServer().getZkAddress())- .withFunctionName("topic", TopicStream.class)- .withFunctionName("update", UpdateStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("daemon", DaemonStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost(+ "parallelDestinationCollection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("topic", TopicStream.class)+ .withFunctionName("update", UpdateStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("daemon", DaemonStream.class);try {- //Copy all docs to destinationCollection- String updateExpression = "daemon(update(parallelDestinationCollection1, batchSize=2, topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", partitionKeys=\"a_f\", initialCheckpoint=0, id=\"topic1\")), terminate=true, runInterval=\"1000\", id=\"test\")";- TupleStream parallelUpdateStream = factory.constructStream("parallel(collection1, " + updateExpression + ", workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"batchNumber asc\")");+ // Copy all docs to destinationCollection+ String updateExpression =+ "daemon(update(parallelDestinationCollection1, batchSize=2, topic(collection1, collection1, q=\"a_s:hello\", fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", partitionKeys=\"a_f\", initialCheckpoint=0, id=\"topic1\")), terminate=true, runInterval=\"1000\", id=\"test\")";+ TupleStream parallelUpdateStream =+ factory.constructStream(+ "parallel(collection1, "+ + updateExpression+ + ", workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"batchNumber asc\")");parallelUpdateStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(parallelUpdateStream);assert (tuples.size() == 2);-- ModifiableSolrParams sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream", "action", "list"));+ ModifiableSolrParams sParams =+ new ModifiableSolrParams(params(CommonParams.QT, "/stream", "action", "list"));int workersComplete = 0;- //Daemons should terminate after the topic is completed- //Loop through all shards and wait for the daemons to be gone from the listing.+ // Daemons should terminate after the topic is completed+ // Loop through all shards and wait for the daemons to be gone from the listing.for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {INNER:while (true) {- SolrStream solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);+ SolrStream solrStream =+ new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);solrStream.setStreamContext(streamContext);solrStream.open();Tuple tupleResponse = solrStream.read();@@ -3112,8 +3668,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {cluster.getSolrClient().commit("parallelDestinationCollection1");- //Ensure that destinationCollection actually has the new docs.- expression = StreamExpressionParser.parse("search(parallelDestinationCollection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");+ // Ensure that destinationCollection actually has the new docs.+ expression =+ StreamExpressionParser.parse(+ "search(parallelDestinationCollection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3159,30 +3717,32 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertList(tuple.getStrings("s_multi"), "aaaa3", "bbbb3");assertList(tuple.getLongs("i_multi"), Long.parseLong("4444"), Long.parseLong("7777"));} finally {- CollectionAdminRequest.deleteCollection("parallelDestinationCollection1").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("parallelDestinationCollection1")+ .process(cluster.getSolrClient());solrClientCache.close();}}-@Testpublic void testParseCSV() throws Exception {- String expr = "parseCSV(list(tuple(file=\"file1\", line=\"a,b,c\"), " +- " tuple(file=\"file1\", line=\"1,2,3\")," +- " tuple(file=\"file1\", line=\"\\\"hello, world\\\",9000,20\")," +- " tuple(file=\"file2\", line=\"field_1,field_2,field_3\"), "+- " tuple(file=\"file2\", line=\"8,9,\")))";+ String expr =+ "parseCSV(list(tuple(file=\"file1\", line=\"a,b,c\"), "+ + " tuple(file=\"file1\", line=\"1,2,3\"),"+ + " tuple(file=\"file1\", line=\"\\\"hello, world\\\",9000,20\"),"+ + " tuple(file=\"file2\", line=\"field_1,field_2,field_3\"), "+ + " tuple(file=\"file2\", line=\"8,9,\")))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 3);+ assertEquals(tuples.size(), 3);assertEquals(tuples.get(0).getString("a"), "1");assertEquals(tuples.get(0).getString("b"), "2");assertEquals(tuples.get(0).getString("c"), "3");@@ -3196,25 +3756,26 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertNull(tuples.get(2).get("field_3"));}-@Testpublic void testParseTSV() throws Exception {- String expr = "parseTSV(list(tuple(file=\"file1\", line=\"a\tb\tc\"), " +- " tuple(file=\"file1\", line=\"1\t2\t3\")," +- " tuple(file=\"file1\", line=\"hello, world\t9000\t20\")," +- " tuple(file=\"file2\", line=\"field_1\tfield_2\tfield_3\"), "+- " tuple(file=\"file2\", line=\"8\t\t9\")))";+ String expr =+ "parseTSV(list(tuple(file=\"file1\", line=\"a\tb\tc\"), "+ + " tuple(file=\"file1\", line=\"1\t2\t3\"),"+ + " tuple(file=\"file1\", line=\"hello, world\t9000\t20\"),"+ + " tuple(file=\"file2\", line=\"field_1\tfield_2\tfield_3\"), "+ + " tuple(file=\"file2\", line=\"8\t\t9\")))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);- assertEquals(tuples.size(), 3);+ assertEquals(tuples.size(), 3);assertEquals(tuples.get(0).getString("a"), "1");assertEquals(tuples.get(0).getString("b"), "2");assertEquals(tuples.get(0).getString("c"), "3");@@ -3226,55 +3787,68 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertEquals(tuples.get(2).getString("field_1"), "8");assertNull(tuples.get(2).get("field_2"));assertEquals(tuples.get(2).getString("field_3"), "9");-}--@Testpublic void testCommitStream() throws Exception {- CollectionAdminRequest.createCollection("destinationCollection", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("destinationCollection", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("destinationCollection", 2, 2);new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb", "i_multi", "4", "i_multi", "7")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi", "bbbb1", "i_multi", "44", "i_multi", "77")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi", "bbbb2", "i_multi", "444", "i_multi", "777")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi", "bbbb3", "i_multi", "4444", "i_multi", "7777")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi", "bbbb4", "i_multi", "44444", "i_multi", "77777")+ .add(+ id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb",+ "i_multi", "4", "i_multi", "7")+ .add(+ id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi",+ "bbbb1", "i_multi", "44", "i_multi", "77")+ .add(+ id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi",+ "bbbb2", "i_multi", "444", "i_multi", "777")+ .add(+ id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi",+ "bbbb3", "i_multi", "4444", "i_multi", "7777")+ .add(+ id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi",+ "bbbb4", "i_multi", "44444", "i_multi", "77777").commit(cluster.getSolrClient(), "collection1");-+StreamExpression expression;TupleStream stream;Tuple t;StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class)- .withFunctionName("commit", CommitStream.class);++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class)+ .withFunctionName("commit", CommitStream.class);try {- //Copy all docs to destinationCollection- expression = StreamExpressionParser.parse("commit(destinationCollection, batchSize=2, update(destinationCollection, batchSize=5, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\")))");+ // Copy all docs to destinationCollection+ expression =+ StreamExpressionParser.parse(+ "commit(destinationCollection, batchSize=2, update(destinationCollection, batchSize=5, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\")))");stream = factory.constructStream(expression);stream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(stream);- //Ensure that all CommitStream tuples indicate the correct number of copied/indexed docs+ // Ensure that all CommitStream tuples indicate the correct number of copied/indexed docsassert (tuples.size() == 1);t = tuples.get(0);assert (t.EOF == false);assertEquals(5, t.get("batchIndexed"));- //Ensure that destinationCollection actually has the new docs.- expression = StreamExpressionParser.parse("search(destinationCollection, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");+ // Ensure that destinationCollection actually has the new docs.+ expression =+ StreamExpressionParser.parse(+ "search(destinationCollection, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3320,7 +3894,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertList(tuple.getStrings("s_multi"), "aaaa3", "bbbb3");assertList(tuple.getLongs("i_multi"), Long.parseLong("4444"), Long.parseLong("7777"));} finally {- CollectionAdminRequest.deleteCollection("destinationCollection").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("destinationCollection")+ .process(cluster.getSolrClient());solrClientCache.close();}}@@ -3328,42 +3903,64 @@ public class StreamDecoratorTest extends SolrCloudTestCase {@Testpublic void testParallelCommitStream() throws Exception {- CollectionAdminRequest.createCollection("parallelDestinationCollection", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("parallelDestinationCollection", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("parallelDestinationCollection", 2, 2);new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb", "i_multi", "4", "i_multi", "7")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi", "bbbb1", "i_multi", "44", "i_multi", "77")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi", "bbbb2", "i_multi", "444", "i_multi", "777")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi", "bbbb3", "i_multi", "4444", "i_multi", "7777")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi", "bbbb4", "i_multi", "44444", "i_multi", "77777")+ .add(+ id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb",+ "i_multi", "4", "i_multi", "7")+ .add(+ id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi",+ "bbbb1", "i_multi", "44", "i_multi", "77")+ .add(+ id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi",+ "bbbb2", "i_multi", "444", "i_multi", "777")+ .add(+ id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi",+ "bbbb3", "i_multi", "4444", "i_multi", "7777")+ .add(+ id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi",+ "bbbb4", "i_multi", "44444", "i_multi", "77777").commit(cluster.getSolrClient(), "collection1");-+StreamExpression expression;TupleStream stream;Tuple t;StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-+String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("parallelDestinationCollection", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class)- .withFunctionName("commit", CommitStream.class)- .withFunctionName("parallel", ParallelStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost(+ "parallelDestinationCollection", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class)+ .withFunctionName("commit", CommitStream.class)+ .withFunctionName("parallel", ParallelStream.class);try {- //Copy all docs to destinationCollection- String updateExpression = "commit(parallelDestinationCollection, batchSize=0, zkHost=\"" + cluster.getZkServer().getZkAddress() + "\", update(parallelDestinationCollection, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\")))";- TupleStream parallelUpdateStream = factory.constructStream("parallel(collection1, " + updateExpression + ", workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"batchNumber asc\")");+ // Copy all docs to destinationCollection+ String updateExpression =+ "commit(parallelDestinationCollection, batchSize=0, zkHost=\""+ + cluster.getZkServer().getZkAddress()+ + "\", update(parallelDestinationCollection, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\")))";+ TupleStream parallelUpdateStream =+ factory.constructStream(+ "parallel(collection1, "+ + updateExpression+ + ", workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"batchNumber asc\")");parallelUpdateStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(parallelUpdateStream);- //Ensure that all UpdateStream tuples indicate the correct number of copied/indexed docs+ // Ensure that all UpdateStream tuples indicate the correct number of copied/indexed docslong count = 0;for (Tuple tuple : tuples) {@@ -3372,8 +3969,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assert (count == 5);- //Ensure that destinationCollection actually has the new docs.- expression = StreamExpressionParser.parse("search(parallelDestinationCollection, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");+ // Ensure that destinationCollection actually has the new docs.+ expression =+ StreamExpressionParser.parse(+ "search(parallelDestinationCollection, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3419,7 +4018,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertList(tuple.getStrings("s_multi"), "aaaa3", "bbbb3");assertList(tuple.getLongs("i_multi"), Long.parseLong("4444"), Long.parseLong("7777"));} finally {- CollectionAdminRequest.deleteCollection("parallelDestinationCollection").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("parallelDestinationCollection")+ .process(cluster.getSolrClient());solrClientCache.close();}}@@ -3427,16 +4027,27 @@ public class StreamDecoratorTest extends SolrCloudTestCase {@Testpublic void testParallelDaemonCommitStream() throws Exception {- CollectionAdminRequest.createCollection("parallelDestinationCollection1", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("parallelDestinationCollection1", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("parallelDestinationCollection1", 2, 2);new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb", "i_multi", "4", "i_multi", "7")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi", "bbbb1", "i_multi", "44", "i_multi", "77")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi", "bbbb2", "i_multi", "444", "i_multi", "777")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi", "bbbb3", "i_multi", "4444", "i_multi", "7777")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi", "bbbb4", "i_multi", "44444", "i_multi", "77777")+ .add(+ id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "s_multi", "bbbb",+ "i_multi", "4", "i_multi", "7")+ .add(+ id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "s_multi",+ "bbbb1", "i_multi", "44", "i_multi", "77")+ .add(+ id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "s_multi",+ "bbbb2", "i_multi", "444", "i_multi", "777")+ .add(+ id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "s_multi",+ "bbbb3", "i_multi", "4444", "i_multi", "7777")+ .add(+ id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "s_multi",+ "bbbb4", "i_multi", "44444", "i_multi", "77777").commit(cluster.getSolrClient(), "collection1");StreamExpression expression;@@ -3447,33 +4058,46 @@ public class StreamDecoratorTest extends SolrCloudTestCase {streamContext.setSolrClientCache(solrClientCache);String zkHost = cluster.getZkServer().getZkAddress();- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("parallelDestinationCollection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class)- .withFunctionName("commit", CommitStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("daemon", DaemonStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost(+ "parallelDestinationCollection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class)+ .withFunctionName("commit", CommitStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("daemon", DaemonStream.class);try {- //Copy all docs to destinationCollection- String updateExpression = "daemon(commit(parallelDestinationCollection1, batchSize=0, zkHost=\"" + cluster.getZkServer().getZkAddress() + "\", update(parallelDestinationCollection1, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"))), runInterval=\"1000\", id=\"test\")";- TupleStream parallelUpdateStream = factory.constructStream("parallel(collection1, " + updateExpression + ", workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"batchNumber asc\")");+ // Copy all docs to destinationCollection+ String updateExpression =+ "daemon(commit(parallelDestinationCollection1, batchSize=0, zkHost=\""+ + cluster.getZkServer().getZkAddress()+ + "\", update(parallelDestinationCollection1, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"))), runInterval=\"1000\", id=\"test\")";+ TupleStream parallelUpdateStream =+ factory.constructStream(+ "parallel(collection1, "+ + updateExpression+ + ", workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"batchNumber asc\")");parallelUpdateStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(parallelUpdateStream);assert (tuples.size() == 2);- //Lets sleep long enough for daemon updates to run.- //Lets stop the daemons- ModifiableSolrParams sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream", "action", "list"));+ // Lets sleep long enough for daemon updates to run.+ // Lets stop the daemons+ ModifiableSolrParams sParams =+ new ModifiableSolrParams(params(CommonParams.QT, "/stream", "action", "list"));int workersComplete = 0;for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {int iterations = 0;INNER:while (iterations == 0) {- SolrStream solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);+ SolrStream solrStream =+ new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);solrStream.setStreamContext(streamContext);solrStream.open();Tuple tupleResponse = solrStream.read();@@ -3498,7 +4122,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertEquals(cluster.getJettySolrRunners().size(), workersComplete);- //Lets stop the daemons+ // Lets stop the daemonssParams = new ModifiableSolrParams();sParams.set(CommonParams.QT, "/stream");sParams.set("action", "stop");@@ -3544,8 +4168,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {}assertEquals(cluster.getJettySolrRunners().size(), workersComplete);- //Ensure that destinationCollection actually has the new docs.- expression = StreamExpressionParser.parse("search(parallelDestinationCollection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");+ // Ensure that destinationCollection actually has the new docs.+ expression =+ StreamExpressionParser.parse(+ "search(parallelDestinationCollection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3591,7 +4217,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertList(tuple.getStrings("s_multi"), "aaaa3", "bbbb3");assertList(tuple.getLongs("i_multi"), Long.parseLong("4444"), Long.parseLong("7777"));} finally {- CollectionAdminRequest.deleteCollection("parallelDestinationCollection1").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("parallelDestinationCollection1")+ .process(cluster.getSolrClient());solrClientCache.close();}}@@ -3604,14 +4231,12 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "2", "a_s", "setA", "a_i", "1").add(id, "3", "a_s", "setA", "a_i", "2").add(id, "4", "a_s", "setA", "a_i", "3")-.add(id, "5", "a_s", "setB", "a_i", "2").add(id, "6", "a_s", "setB", "a_i", "3")-.add(id, "7", "a_s", "setAB", "a_i", "0").add(id, "8", "a_s", "setAB", "a_i", "6").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-+StreamExpression expression;TupleStream stream;List<Tuple> tuples;@@ -3619,17 +4244,20 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("intersect", IntersectStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("intersect", IntersectStream.class);try {// basic- expression = StreamExpressionParser.parse("intersect("- + "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\"),"- + "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\"),"- + "on=\"a_i\")");+ expression =+ StreamExpressionParser.parse(+ "intersect("+ + "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\"),"+ + "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\"),"+ + "on=\"a_i\")");stream = new IntersectStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3645,21 +4273,24 @@ public class StreamDecoratorTest extends SolrCloudTestCase {public void testClassifyStream() throws Exception {Assume.assumeTrue(!useAlias);- CollectionAdminRequest.createCollection("modelCollection", "ml", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("modelCollection", "ml", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("modelCollection", 2, 2);- CollectionAdminRequest.createCollection("uknownCollection", "ml", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("uknownCollection", "ml", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("uknownCollection", 2, 2);- CollectionAdminRequest.createCollection("checkpointCollection", "ml", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("checkpointCollection", "ml", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).process(cluster.getSolrClient());cluster.waitForActiveCollection("checkpointCollection", 2, 2);UpdateRequest updateRequest = new UpdateRequest();- for (int i = 0; i < 500; i+=2) {+ for (int i = 0; i < 500; i += 2) {updateRequest.add(id, String.valueOf(i), "tv_text", "a b c c d", "out_i", "1");- updateRequest.add(id, String.valueOf(i+1), "tv_text", "a b e e f", "out_i", "0");+ updateRequest.add(id, String.valueOf(i + 1), "tv_text", "a b e e f", "out_i", "0");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);@@ -3676,7 +4307,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {String url = null;for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {if (jetty.getNodeName().equals(node)) {- url = jetty.getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ url = jetty.getBaseUrl().toString() + "/" + COLLECTIONORALIAS;break;}}@@ -3686,37 +4317,43 @@ public class StreamDecoratorTest extends SolrCloudTestCase {TupleStream updateTrainModelStream;ModifiableSolrParams paramsLoc;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("modelCollection", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("uknownCollection", cluster.getZkServer().getZkAddress())- .withFunctionName("features", FeaturesSelectionStream.class)- .withFunctionName("train", TextLogitStream.class)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("modelCollection", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("uknownCollection", cluster.getZkServer().getZkAddress())+ .withFunctionName("features", FeaturesSelectionStream.class)+ .withFunctionName("train", TextLogitStream.class)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class);// train the model- String textLogitExpression = "train(" +- "collection1, " +- "features(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4),"+- "q=\"*:*\", " +- "name=\"model\", " +- "field=\"tv_text\", " +- "outcome=\"out_i\", " +- "maxIterations=100)";- updateTrainModelStream = factory.constructStream("update(modelCollection, batchSize=5, "+textLogitExpression+")");+ String textLogitExpression =+ "train("+ + "collection1, "+ + "features(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4),"+ + "q=\"*:*\", "+ + "name=\"model\", "+ + "field=\"tv_text\", "+ + "outcome=\"out_i\", "+ + "maxIterations=100)";+ updateTrainModelStream =+ factory.constructStream(+ "update(modelCollection, batchSize=5, " + textLogitExpression + ")");getTuples(updateTrainModelStream);cluster.getSolrClient().commit("modelCollection");// classify unknown documents- String expr = "classify(" +- // use cacheMillis=0 to prevent cached results. it doesn't matter on the first run,- // but we want to ensure that when we re-use this expression later after- // training another model, we'll still get accurate results.- "model(modelCollection, id=\"model\", cacheMillis=0)," +- "topic(checkpointCollection, uknownCollection, q=\"*:*\", fl=\"text_s, id\", id=\"1000000\", initialCheckpoint=\"0\")," +- "field=\"text_s\"," +- "analyzerField=\"tv_text\")";+ String expr =+ "classify("+ ++ // use cacheMillis=0 to prevent cached results. it doesn't matter on the first run,+ // but we want to ensure that when we re-use this expression later after+ // training another model, we'll still get accurate results.+ "model(modelCollection, id=\"model\", cacheMillis=0),"+ + "topic(checkpointCollection, uknownCollection, q=\"*:*\", fl=\"text_s, id\", id=\"1000000\", initialCheckpoint=\"0\"),"+ + "field=\"text_s\","+ + "analyzerField=\"tv_text\")";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);@@ -3739,19 +4376,20 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertEquals(1.0, idToLabel.get("2"), 0.001);assertEquals(0, idToLabel.get("3"), 0.001);-// Train another modelupdateRequest = new UpdateRequest();updateRequest.deleteByQuery("*:*");updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);updateRequest = new UpdateRequest();- for (int i = 0; i < 500; i+=2) {+ for (int i = 0; i < 500; i += 2) {updateRequest.add(id, String.valueOf(i), "tv_text", "a b c c d", "out_i", "0");- updateRequest.add(id, String.valueOf(i+1), "tv_text", "a b e e f", "out_i", "1");+ updateRequest.add(id, String.valueOf(i + 1), "tv_text", "a b e e f", "out_i", "1");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- updateTrainModelStream = factory.constructStream("update(modelCollection, batchSize=5, "+textLogitExpression+")");+ updateTrainModelStream =+ factory.constructStream(+ "update(modelCollection, batchSize=5, " + textLogitExpression + ")");getTuples(updateTrainModelStream);cluster.getSolrClient().commit("modelCollection");@@ -3767,15 +4405,16 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertEquals(0, idToLabel.get("4"), 0.001);assertEquals(1.0, idToLabel.get("5"), 0.001);- //Classify in parallel+ // Classify in parallel// classify unknown documents- expr = "parallel(collection1, workers=2, sort=\"_version_ asc\", classify(" +- "model(modelCollection, id=\"model\")," +- "topic(checkpointCollection, uknownCollection, q=\"id:(4 5)\", fl=\"text_s, id, _version_\", id=\"2000000\", partitionKeys=\"id\", initialCheckpoint=\"0\")," +- "field=\"text_s\"," +- "analyzerField=\"tv_text\"))";+ expr =+ "parallel(collection1, workers=2, sort=\"_version_ asc\", classify("+ + "model(modelCollection, id=\"model\"),"+ + "topic(checkpointCollection, uknownCollection, q=\"id:(4 5)\", fl=\"text_s, id, _version_\", id=\"2000000\", partitionKeys=\"id\", initialCheckpoint=\"0\"),"+ + "field=\"text_s\","+ + "analyzerField=\"tv_text\"))";paramsLoc.set("expr", expr);classifyStream = new SolrStream(url, paramsLoc);@@ -3786,7 +4425,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {CollectionAdminRequest.deleteCollection("modelCollection").process(cluster.getSolrClient());CollectionAdminRequest.deleteCollection("uknownCollection").process(cluster.getSolrClient());- CollectionAdminRequest.deleteCollection("checkpointCollection").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("checkpointCollection")+ .process(cluster.getSolrClient());}@Test@@ -3797,13 +4437,18 @@ public class StreamDecoratorTest extends SolrCloudTestCase {updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "search("+COLLECTIONORALIAS+", q=\"*:*\", fl=\"id,test_t, test_i\", sort=\"id desc\")";- String cat = "let(d ="+expr+", b = add(1,3), c=col(d, test_i), tuple(test = add(1,1), test1=b, results=d, test2=add(c)))";+ String expr =+ "search(" + COLLECTIONORALIAS + ", q=\"*:*\", fl=\"id,test_t, test_i\", sort=\"id desc\")";+ String cat =+ "let(d ="+ + expr+ + ", b = add(1,3), c=col(d, test_i), tuple(test = add(1,1), test1=b, results=d, test2=add(c)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cat);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -3812,7 +4457,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertTrue(tuples.size() == 1);Tuple tuple1 = tuples.get(0);@SuppressWarnings({"unchecked", "rawtypes"})- List<Map> results = (List<Map>)tuple1.get("results");+ List<Map> results = (List<Map>) tuple1.get("results");assertTrue(results.size() == 2);assertTrue(results.get(0).get("id").equals("hello1"));assertTrue(results.get(0).get("test_t").equals("l b c d c"));@@ -3823,7 +4468,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertTrue(tuple1.getLong("test1").equals(4L));assertTrue(tuple1.getLong("test2").equals(9L));}-+@Testpublic void testGetStreamForEOFTuple() throws Exception {UpdateRequest updateRequest = new UpdateRequest();@@ -3832,21 +4477,23 @@ public class StreamDecoratorTest extends SolrCloudTestCase {updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "search("+COLLECTIONORALIAS+", q=\"id:hello2\", fl=\"id,test_t, test_i\", sort=\"id desc\")";- String cat = "let(a ="+expr+",get(a))";+ String expr =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"id:hello2\", fl=\"id,test_t, test_i\", sort=\"id desc\")";+ String cat = "let(a =" + expr + ",get(a))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cat);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 0);--}@Test@@ -3857,42 +4504,53 @@ public class StreamDecoratorTest extends SolrCloudTestCase {updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "search("+COLLECTIONORALIAS+", q=\"id:hello1\", fl=\"id,test_t, test_i\", sort=\"id desc\")";- String cat = "let(a ="+expr+",stream(a))";+ String expr =+ "search("+ + COLLECTIONORALIAS+ + ", q=\"id:hello1\", fl=\"id,test_t, test_i\", sort=\"id desc\")";+ String cat = "let(a =" + expr + ",stream(a))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cat);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);--}@Testpublic void testExecutorStream() throws Exception {- CollectionAdminRequest.createCollection("workQueue", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("workQueue", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);cluster.waitForActiveCollection("workQueue", 2, 2);- CollectionAdminRequest.createCollection("mainCorpus", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("mainCorpus", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);cluster.waitForActiveCollection("mainCorpus", 2, 2);- CollectionAdminRequest.createCollection("destination", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("destination", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);cluster.waitForActiveCollection("destination", 2, 2);UpdateRequest workRequest = new UpdateRequest();UpdateRequest dataRequest = new UpdateRequest();-for (int i = 0; i < 500; i++) {- workRequest.add(id, String.valueOf(i), "expr_s", "update(destination, batchSize=50, search(mainCorpus, q=id:"+i+", rows=1, sort=\"id asc\", fl=\"id, body_t, field_i\"))");- dataRequest.add(id, String.valueOf(i), "body_t", "hello world "+i, "field_i", Integer.toString(i));+ workRequest.add(+ id,+ String.valueOf(i),+ "expr_s",+ "update(destination, batchSize=50, search(mainCorpus, q=id:"+ + i+ + ", rows=1, sort=\"id asc\", fl=\"id, body_t, field_i\"))");+ dataRequest.add(+ id, String.valueOf(i), "body_t", "hello world " + i, "field_i", Integer.toString(i));}workRequest.commit(cluster.getSolrClient(), "workQueue");@@ -3902,15 +4560,17 @@ public class StreamDecoratorTest extends SolrCloudTestCase {TupleStream executorStream;ModifiableSolrParams paramsLoc;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("workQueue", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("mainCorpus", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("destination", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("executor", ExecutorStream.class)- .withFunctionName("update", UpdateStream.class);-- String executorExpression = "executor(threads=3, search(workQueue, q=\"*:*\", fl=\"id, expr_s\", rows=1000, sort=\"id desc\"))";+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("workQueue", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("mainCorpus", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("destination", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("executor", ExecutorStream.class)+ .withFunctionName("update", UpdateStream.class);++ String executorExpression =+ "executor(threads=3, search(workQueue, q=\"*:*\", fl=\"id, expr_s\", rows=1000, sort=\"id desc\"))";executorStream = factory.constructStream(executorExpression);StreamContext context = new StreamContext();@@ -3918,21 +4578,23 @@ public class StreamDecoratorTest extends SolrCloudTestCase {context.setSolrClientCache(clientCache);executorStream.setStreamContext(context);getTuples(executorStream);- //Destination collection should now contain all the records in the main corpus.+ // Destination collection should now contain all the records in the main corpus.cluster.getSolrClient().commit("destination");paramsLoc = new ModifiableSolrParams();- paramsLoc.set("expr", "search(destination, q=\"*:*\", fl=\"id, body_t, field_i\", rows=1000, sort=\"field_i asc\")");- paramsLoc.set("qt","/stream");+ paramsLoc.set(+ "expr",+ "search(destination, q=\"*:*\", fl=\"id, body_t, field_i\", rows=1000, sort=\"field_i asc\")");+ paramsLoc.set("qt", "/stream");SolrStream solrStream = new SolrStream(url, paramsLoc);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 500);- for(int i=0; i<500; i++) {+ for (int i = 0; i < 500; i++) {Tuple tuple = tuples.get(i);long ivalue = tuple.getLong("field_i");String body = tuple.getString("body_t");assertTrue(ivalue == i);- assertTrue(body.equals("hello world "+i));+ assertTrue(body.equals("hello world " + i));}solrStream.close();@@ -3942,16 +4604,18 @@ public class StreamDecoratorTest extends SolrCloudTestCase {CollectionAdminRequest.deleteCollection("destination").process(cluster.getSolrClient());}-@Testpublic void testParallelExecutorStream() throws Exception {- CollectionAdminRequest.createCollection("workQueue1", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)- .processAndWait(cluster.getSolrClient(),DEFAULT_TIMEOUT);+ CollectionAdminRequest.createCollection("workQueue1", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);- CollectionAdminRequest.createCollection("mainCorpus1", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("mainCorpus1", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);- CollectionAdminRequest.createCollection("destination1", "conf", 2, 1).setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE)+ CollectionAdminRequest.createCollection("destination1", "conf", 2, 1)+ .setPerReplicaState(SolrCloudTestCase.USE_PER_REPLICA_STATE).processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);cluster.waitForActiveCollection("workQueue1", 2, 2);@@ -3963,8 +4627,15 @@ public class StreamDecoratorTest extends SolrCloudTestCase {int cnt = TEST_NIGHTLY ? 500 : 100;for (int i = 0; i < cnt; i++) {- workRequest.add(id, String.valueOf(i), "expr_s", "update(destination1, batchSize=50, search(mainCorpus1, q=id:"+i+", rows=1, sort=\"id asc\", fl=\"id, body_t, field_i\"))");- dataRequest.add(id, String.valueOf(i), "body_t", "hello world "+i, "field_i", Integer.toString(i));+ workRequest.add(+ id,+ String.valueOf(i),+ "expr_s",+ "update(destination1, batchSize=50, search(mainCorpus1, q=id:"+ + i+ + ", rows=1, sort=\"id asc\", fl=\"id, body_t, field_i\"))");+ dataRequest.add(+ id, String.valueOf(i), "body_t", "hello world " + i, "field_i", Integer.toString(i));}workRequest.commit(cluster.getSolrClient(), "workQueue1");@@ -3974,16 +4645,18 @@ public class StreamDecoratorTest extends SolrCloudTestCase {TupleStream executorStream;ModifiableSolrParams paramsLoc;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("workQueue1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("mainCorpus1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("destination1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("executor", ExecutorStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("update", UpdateStream.class);-- String executorExpression = "parallel(workQueue1, workers=2, sort=\"EOF asc\", executor(threads=3, queueSize=100, search(workQueue1, q=\"*:*\", fl=\"id, expr_s\", rows=1000, partitionKeys=id, sort=\"id desc\", qt=\"/export\")))";+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("workQueue1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("mainCorpus1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("destination1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("executor", ExecutorStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("update", UpdateStream.class);++ String executorExpression =+ "parallel(workQueue1, workers=2, sort=\"EOF asc\", executor(threads=3, queueSize=100, search(workQueue1, q=\"*:*\", fl=\"id, expr_s\", rows=1000, partitionKeys=id, sort=\"id desc\", qt=\"/export\")))";executorStream = factory.constructStream(executorExpression);StreamContext context = new StreamContext();@@ -3991,16 +4664,18 @@ public class StreamDecoratorTest extends SolrCloudTestCase {context.setSolrClientCache(clientCache);executorStream.setStreamContext(context);getTuples(executorStream);- //Destination collection should now contain all the records in the main corpus.+ // Destination collection should now contain all the records in the main corpus.cluster.getSolrClient().commit("destination1");paramsLoc = new ModifiableSolrParams();- paramsLoc.set("expr", "search(destination1, q=\"*:*\", fl=\"id, body_t, field_i\", rows=1000, sort=\"field_i asc\")");+ paramsLoc.set(+ "expr",+ "search(destination1, q=\"*:*\", fl=\"id, body_t, field_i\", rows=1000, sort=\"field_i asc\")");paramsLoc.set("qt", "/stream");SolrStream solrStream = new SolrStream(url, paramsLoc);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == cnt);- for(int i=0; i<cnt; i++) {+ for (int i = 0; i < cnt; i++) {Tuple tuple = tuples.get(i);long ivalue = tuple.getLong("field_i");String body = tuple.getString("body_t");@@ -4015,7 +4690,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {CollectionAdminRequest.deleteCollection("destination1").process(cluster.getSolrClient());}- private Map<String,Double> getIdToLabel(TupleStream stream, String outField) throws IOException {+ private Map<String, Double> getIdToLabel(TupleStream stream, String outField) throws IOException {Map<String, Double> idToLabel = new HashMap<>();List<Tuple> tuples = getTuples(stream);for (Tuple tuple : tuples) {@@ -4032,19 +4707,18 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "2", "a_s", "setA", "a_i", "1").add(id, "3", "a_s", "setA", "a_i", "2").add(id, "4", "a_s", "setA", "a_i", "3")-.add(id, "5", "a_s", "setB", "a_i", "2").add(id, "6", "a_s", "setB", "a_i", "3")-.add(id, "7", "a_s", "setAB", "a_i", "0").add(id, "8", "a_s", "setAB", "a_i", "6").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-- StreamFactory streamFactory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("intersect", IntersectStream.class)- .withFunctionName("parallel", ParallelStream.class);++ StreamFactory streamFactory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("intersect", IntersectStream.class)+ .withFunctionName("parallel", ParallelStream.class);// basicStreamContext streamContext = new StreamContext();@@ -4053,13 +4727,17 @@ public class StreamDecoratorTest extends SolrCloudTestCase {try {String zkHost = cluster.getZkServer().getZkAddress();- final TupleStream stream = streamFactory.constructStream("parallel("- + "collection1, "- + "intersect("- + "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\", partitionKeys=\"a_i\", qt=\"/export\"),"- + "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"),"- + "on=\"a_i\"),"- + "workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_i asc\")");+ final TupleStream stream =+ streamFactory.constructStream(+ "parallel("+ + "collection1, "+ + "intersect("+ + "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\", partitionKeys=\"a_i\", qt=\"/export\"),"+ + "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"),"+ + "on=\"a_i\"),"+ + "workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_i asc\")");stream.setStreamContext(streamContext);@@ -4080,15 +4758,13 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "2", "a_s", "setA", "a_i", "1").add(id, "3", "a_s", "setA", "a_i", "2").add(id, "4", "a_s", "setA", "a_i", "3")-.add(id, "5", "a_s", "setB", "a_i", "2").add(id, "6", "a_s", "setB", "a_i", "3").add(id, "9", "a_s", "setB", "a_i", "5")-.add(id, "7", "a_s", "setAB", "a_i", "0").add(id, "8", "a_s", "setAB", "a_i", "6").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-+StreamExpression expression;TupleStream stream;List<Tuple> tuples;@@ -4096,17 +4772,20 @@ public class StreamDecoratorTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("complement", ComplementStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("complement", ComplementStream.class);try {// basic- expression = StreamExpressionParser.parse("complement("- + "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\"),"- + "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\"),"- + "on=\"a_i\")");+ expression =+ StreamExpressionParser.parse(+ "complement("+ + "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\"),"+ + "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\"),"+ + "on=\"a_i\")");stream = new ComplementStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -4122,28 +4801,33 @@ public class StreamDecoratorTest extends SolrCloudTestCase {public void testCartesianProductStream() throws Exception {new UpdateRequest()- .add(id, "0", "a_ss", "a", "a_ss", "b", "a_ss", "c", "a_ss", "d", "a_ss", "e", "b_ls", "1", "b_ls", "2", "b_ls", "3")+ .add(+ id, "0", "a_ss", "a", "a_ss", "b", "a_ss", "c", "a_ss", "d", "a_ss", "e", "b_ls", "1",+ "b_ls", "2", "b_ls", "3").add(id, "1", "a_ss", "a", "a_ss", "b", "a_ss", "c", "a_ss", "d", "a_ss", "e").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-+StreamExpression expression;TupleStream stream;List<Tuple> tuples;StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);-- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("cartesian", CartesianProductStream.class);-++ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("cartesian", CartesianProductStream.class);+// single selection, no sorttry {- stream = factory.constructStream("cartesian("- + "search(collection1, q=*:*, fl=\"id,a_ss\", sort=\"id asc\"),"- + "a_ss"- + ")");+ stream =+ factory.constructStream(+ "cartesian("+ + "search(collection1, q=*:*, fl=\"id,a_ss\", sort=\"id asc\"),"+ + "a_ss"+ + ")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -4155,11 +4839,13 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertEquals("c", tuples.get(7).get("a_ss"));// single selection, sort- stream = factory.constructStream("cartesian("- + "search(collection1, q=*:*, fl=\"id,a_ss\", sort=\"id asc\"),"- + "a_ss,"- + "productSort=\"a_ss DESC\""- + ")");+ stream =+ factory.constructStream(+ "cartesian("+ + "search(collection1, q=*:*, fl=\"id,a_ss\", sort=\"id asc\"),"+ + "a_ss,"+ + "productSort=\"a_ss DESC\""+ + ")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -4171,12 +4857,14 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertEquals("c", tuples.get(7).get("a_ss"));// multi selection, sort- stream = factory.constructStream("cartesian("- + "search(collection1, q=*:*, fl=\"id,a_ss,b_ls\", sort=\"id asc\"),"- + "a_ss,"- + "b_ls,"- + "productSort=\"a_ss ASC\""- + ")");+ stream =+ factory.constructStream(+ "cartesian("+ + "search(collection1, q=*:*, fl=\"id,a_ss,b_ls\", sort=\"id asc\"),"+ + "a_ss,"+ + "b_ls,"+ + "productSort=\"a_ss ASC\""+ + ")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -4197,12 +4885,14 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertEquals(3L, tuples.get(5).get("b_ls"));// multi selection, sort- stream = factory.constructStream("cartesian("- + "search(collection1, q=*:*, fl=\"id,a_ss,b_ls\", sort=\"id asc\"),"- + "a_ss,"- + "b_ls,"- + "productSort=\"a_ss ASC, b_ls DESC\""- + ")");+ stream =+ factory.constructStream(+ "cartesian("+ + "search(collection1, q=*:*, fl=\"id,a_ss,b_ls\", sort=\"id asc\"),"+ + "a_ss,"+ + "b_ls,"+ + "productSort=\"a_ss ASC, b_ls DESC\""+ + ")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -4223,12 +4913,14 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertEquals(1L, tuples.get(5).get("b_ls"));// multi selection, sort- stream = factory.constructStream("cartesian("- + "search(collection1, q=*:*, fl=\"id,a_ss,b_ls\", sort=\"id asc\"),"- + "a_ss,"- + "b_ls,"- + "productSort=\"b_ls DESC\""- + ")");+ stream =+ factory.constructStream(+ "cartesian("+ + "search(collection1, q=*:*, fl=\"id,a_ss,b_ls\", sort=\"id asc\"),"+ + "a_ss,"+ + "b_ls,"+ + "productSort=\"b_ls DESC\""+ + ")");stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -4268,20 +4960,19 @@ public class StreamDecoratorTest extends SolrCloudTestCase {.add(id, "2", "a_s", "setA", "a_i", "1").add(id, "3", "a_s", "setA", "a_i", "2").add(id, "4", "a_s", "setA", "a_i", "3")-.add(id, "5", "a_s", "setB", "a_i", "2").add(id, "6", "a_s", "setB", "a_i", "3").add(id, "9", "a_s", "setB", "a_i", "5")-.add(id, "7", "a_s", "setAB", "a_i", "0").add(id, "8", "a_s", "setAB", "a_i", "6").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-- StreamFactory streamFactory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("complement", ComplementStream.class)- .withFunctionName("parallel", ParallelStream.class);++ StreamFactory streamFactory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("complement", ComplementStream.class)+ .withFunctionName("parallel", ParallelStream.class);StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();@@ -4289,13 +4980,17 @@ public class StreamDecoratorTest extends SolrCloudTestCase {try {final String zkHost = cluster.getZkServer().getZkAddress();- final TupleStream stream = streamFactory.constructStream("parallel("- + "collection1, "- + "complement("- + "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\", partitionKeys=\"a_i\", qt=\"/export\"),"- + "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"),"- + "on=\"a_i\"),"- + "workers=\"2\", zkHost=\"" + zkHost + "\", sort=\"a_i asc\")");+ final TupleStream stream =+ streamFactory.constructStream(+ "parallel("+ + "collection1, "+ + "complement("+ + "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\", partitionKeys=\"a_i\", qt=\"/export\"),"+ + "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"),"+ + "on=\"a_i\"),"+ + "workers=\"2\", zkHost=\""+ + zkHost+ + "\", sort=\"a_i asc\")");stream.setStreamContext(streamContext);final List<Tuple> tuples = getTuples(stream);@@ -4307,154 +5002,195 @@ public class StreamDecoratorTest extends SolrCloudTestCase {}public void testDeleteStream() throws Exception {- final String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ final String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;final SolrClient client = cluster.getSolrClient();-- { final UpdateRequest req = new UpdateRequest();++ {+ final UpdateRequest req = new UpdateRequest();for (int i = 0; i < 20; i++) {- req.add(id, "doc_"+i, "deletable_s", "yup");+ req.add(id, "doc_" + i, "deletable_s", "yup");}assertEquals(0, req.commit(cluster.getSolrClient(), COLLECTIONORALIAS).getStatus());}// fetch the _version_ param assigned each doc to test optimistic concurrency later...- final Map<String,Long> versions = new HashMap<>();- { final QueryResponse allDocs = client.query(COLLECTIONORALIAS, params("q","deletable_s:yup",- "rows","100"));+ final Map<String, Long> versions = new HashMap<>();+ {+ final QueryResponse allDocs =+ client.query(+ COLLECTIONORALIAS,+ params(+ "q", "deletable_s:yup",+ "rows", "100"));assertEquals(20L, allDocs.getResults().getNumFound());for (SolrDocument doc : allDocs.getResults()) {versions.put(doc.getFirstValue("id").toString(), (Long) doc.getFirstValue("_version_"));}}-+{ // trivially delete 1 doc- final String expr- = "commit("+COLLECTIONORALIAS+",waitSearcher=true, "- + " delete("+COLLECTIONORALIAS+",batchSize=10, "- + " tuple(id=doc_2))) "- ;+ final String expr =+ "commit("+ + COLLECTIONORALIAS+ + ",waitSearcher=true, "+ + " delete("+ + COLLECTIONORALIAS+ + ",batchSize=10, "+ + " tuple(id=doc_2))) ";final SolrStream stream = new SolrStream(url, params("qt", "/stream", "expr", expr));-+final List<Tuple> tuples = getTuples(stream);assertEquals(1, tuples.size());assertEquals(1L, tuples.get(0).get("totalIndexed"));-- assertEquals(20L - 1L,- client.query(COLLECTIONORALIAS,- params("q","deletable_s:yup")).getResults().getNumFound());++ assertEquals(+ 20L - 1L,+ client+ .query(COLLECTIONORALIAS, params("q", "deletable_s:yup"))+ .getResults()+ .getNumFound());}{ // delete 5 docs, spread across 3 batches (2 + 2 + 1)- final String expr- = "commit("+COLLECTIONORALIAS+",waitSearcher=true, "- + " delete("+COLLECTIONORALIAS+",batchSize=2,list( " // NOTE: batch size- + " tuple(id=doc_3), "- + " tuple(id=doc_11), "- + " tuple(id=doc_7), "- + " tuple(id=doc_17), "- + " tuple(id=doc_15), "- + " ) ) ) "- ;+ final String expr =+ "commit("+ + COLLECTIONORALIAS+ + ",waitSearcher=true, "+ + " delete("+ + COLLECTIONORALIAS+ + ",batchSize=2,list( " // NOTE: batch size+ + " tuple(id=doc_3), "+ + " tuple(id=doc_11), "+ + " tuple(id=doc_7), "+ + " tuple(id=doc_17), "+ + " tuple(id=doc_15), "+ + " ) ) ) ";final SolrStream stream = new SolrStream(url, params("qt", "/stream", "expr", expr));-+final List<Tuple> tuples = getTuples(stream);assertEquals(3, tuples.size());assertEquals(2L, tuples.get(0).get("totalIndexed"));assertEquals(4L, tuples.get(1).get("totalIndexed"));assertEquals(5L, tuples.get(2).get("totalIndexed"));-- assertEquals(20L - 1L - 5L,- client.query(COLLECTIONORALIAS,- params("q","deletable_s:yup")).getResults().getNumFound());++ assertEquals(+ 20L - 1L - 5L,+ client+ .query(COLLECTIONORALIAS, params("q", "deletable_s:yup"))+ .getResults()+ .getNumFound());}- { // attempt to delete 2 docs, one with correct version, one with "stale" version that should fail- // but config uses TolerantUpdateProcessorFactory so batch should still be ok...+ { // attempt to delete 2 docs, one with correct version, one with "stale" version that should+ // fail but config uses TolerantUpdateProcessorFactory so batch should still be ok...//- // It would be nice it there was a more explicit, targetted, option for update() and delete() to- // ensure that even if one "batch" fails it continues with other batches.+ // It would be nice it there was a more explicit, targetted, option for update() and delete()+ // to ensure that even if one "batch" fails it continues with other batches.// See TODO in UpdateStreamfinal long v13_ok = versions.get("doc_13").longValue();final long v10_bad = versions.get("doc_10").longValue() - 42L;- final String expr- = "commit("+COLLECTIONORALIAS+",waitSearcher=true, "- + " delete("+COLLECTIONORALIAS+",batchSize=10,list( "- + " tuple(id=doc_10,_version_="+v10_bad+"), "- + " tuple(id=doc_13,_version_="+v13_ok+"), "- + " ) ) ) "- ;+ final String expr =+ "commit("+ + COLLECTIONORALIAS+ + ",waitSearcher=true, "+ + " delete("+ + COLLECTIONORALIAS+ + ",batchSize=10,list( "+ + " tuple(id=doc_10,_version_="+ + v10_bad+ + "), "+ + " tuple(id=doc_13,_version_="+ + v13_ok+ + "), "+ + " ) ) ) ";final SolrStream stream = new SolrStream(url, params("qt", "/stream", "expr", expr));-+final List<Tuple> tuples = getTuples(stream);assertEquals(1, tuples.size());assertEquals(2L, tuples.get(0).get("totalIndexed"));// should still be in the index due to version conflict...- assertEquals(1L, client.query(COLLECTIONORALIAS,- params("q","id:doc_10")).getResults().getNumFound());+ assertEquals(+ 1L, client.query(COLLECTIONORALIAS, params("q", "id:doc_10")).getResults().getNumFound());// should not be in the index due to successful delete...- assertEquals(0L, client.query(COLLECTIONORALIAS,- params("q","id:doc_13")).getResults().getNumFound());-- assertEquals(20L - 1L - 5L - 1L,- client.query(COLLECTIONORALIAS,- params("q","deletable_s:yup")).getResults().getNumFound());+ assertEquals(+ 0L, client.query(COLLECTIONORALIAS, params("q", "id:doc_13")).getResults().getNumFound());++ assertEquals(+ 20L - 1L - 5L - 1L,+ client+ .query(COLLECTIONORALIAS, params("q", "deletable_s:yup"))+ .getResults()+ .getNumFound());}- { // by using pruneVersionField=true we should be able to ignore optimistic concurrency constraints,+ { // by using pruneVersionField=true we should be able to ignore optimistic concurrency+ // constraints,// and delete docs even if the stream we are wrapping returns _version_ values that are no// longer valid...final long v10_bad = versions.get("doc_10").longValue() - 42L;- final String expr- = "commit("+COLLECTIONORALIAS+",waitSearcher=true, "- + " delete("+COLLECTIONORALIAS+",batchSize=10, "- + " pruneVersionField=true, list( "- + " tuple(id=doc_10,_version_="+v10_bad+"), "- + " ) ) ) "- ;+ final String expr =+ "commit("+ + COLLECTIONORALIAS+ + ",waitSearcher=true, "+ + " delete("+ + COLLECTIONORALIAS+ + ",batchSize=10, "+ + " pruneVersionField=true, list( "+ + " tuple(id=doc_10,_version_="+ + v10_bad+ + "), "+ + " ) ) ) ";final SolrStream stream = new SolrStream(url, params("qt", "/stream", "expr", expr));-+final List<Tuple> tuples = getTuples(stream);assertEquals(1, tuples.size());assertEquals(1L, tuples.get(0).get("totalIndexed"));// _version_should have been ignored and doc deleted anyway...- assertEquals(0L, client.query(COLLECTIONORALIAS,- params("q","id:doc_10")).getResults().getNumFound());-- assertEquals(20L - 1L - 5L - 1L - 1L,- client.query(COLLECTIONORALIAS,- params("q","deletable_s:yup")).getResults().getNumFound());+ assertEquals(+ 0L, client.query(COLLECTIONORALIAS, params("q", "id:doc_10")).getResults().getNumFound());++ assertEquals(+ 20L - 1L - 5L - 1L - 1L,+ client+ .query(COLLECTIONORALIAS, params("q", "deletable_s:yup"))+ .getResults()+ .getNumFound());}{ // now test a "realistic" DBQ type situation, confirm all (remaining) matching docs deleted...- final String expr- = "commit("+COLLECTIONORALIAS+",waitSearcher=true, "- + " delete("+COLLECTIONORALIAS+",batchSize=99, "- + " search("+COLLECTIONORALIAS+",qt=\"/export\", "- + " q=\"deletable_s:yup\", "- + " sort=\"id asc\",fl=\"id,_version_\" "- + " ) ) ) "- ;+ final String expr =+ "commit("+ + COLLECTIONORALIAS+ + ",waitSearcher=true, "+ + " delete("+ + COLLECTIONORALIAS+ + ",batchSize=99, "+ + " search("+ + COLLECTIONORALIAS+ + ",qt=\"/export\", "+ + " q=\"deletable_s:yup\", "+ + " sort=\"id asc\",fl=\"id,_version_\" "+ + " ) ) ) ";final SolrStream stream = new SolrStream(url, params("qt", "/stream", "expr", expr));-+final List<Tuple> tuples = getTuples(stream);assertEquals(1, tuples.size());- assertEquals(20L - 1L - 5L - 1L - 1L,- tuples.get(0).get("totalIndexed"));+ assertEquals(20L - 1L - 5L - 1L - 1L, tuples.get(0).get("totalIndexed"));// shouldn't be anything left...- assertEquals(0L,- client.query(COLLECTIONORALIAS,- params("q","deletable_s:yup")).getResults().getNumFound());-+ assertEquals(+ 0L,+ client+ .query(COLLECTIONORALIAS, params("q", "deletable_s:yup"))+ .getResults()+ .getNumFound());}-}--protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {List<Tuple> tuples = new ArrayList<Tuple>();@@ -4468,51 +5204,55 @@ public class StreamDecoratorTest extends SolrCloudTestCase {}return tuples;}+protected boolean assertOrder(List<Tuple> tuples, int... ids) throws Exception {return assertOrderOf(tuples, "id", ids);}- protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids) throws Exception {++ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids)+ throws Exception {int i = 0;- for(int val : ids) {+ for (int val : ids) {Tuple t = tuples.get(i);String tip = t.getString(fieldName);- if(!tip.equals(Integer.toString(val))) {- throw new Exception("Found value:"+tip+" expecting:"+val);+ if (!tip.equals(Integer.toString(val))) {+ throw new Exception("Found value:" + tip + " expecting:" + val);}++i;}return true;}- protected boolean assertFields(List<Tuple> tuples, String ... fields) throws Exception{- for(Tuple tuple : tuples){- for(String field : fields){- if(!tuple.getFields().containsKey(field)){+ protected boolean assertFields(List<Tuple> tuples, String... fields) throws Exception {+ for (Tuple tuple : tuples) {+ for (String field : fields) {+ if (!tuple.getFields().containsKey(field)) {throw new Exception(String.format(Locale.ROOT, "Expected field '%s' not found", field));}}}return true;}- protected boolean assertNotFields(List<Tuple> tuples, String ... fields) throws Exception{- for(Tuple tuple : tuples){- for(String field : fields){- if(tuple.getFields().containsKey(field)){++ protected boolean assertNotFields(List<Tuple> tuples, String... fields) throws Exception {+ for (Tuple tuple : tuples) {+ for (String field : fields) {+ if (tuple.getFields().containsKey(field)) {throw new Exception(String.format(Locale.ROOT, "Unexpected field '%s' found", field));}}}return true;- }+ }protected boolean assertGroupOrder(Tuple tuple, int... ids) throws Exception {- List<?> group = (List<?>)tuple.get("tuples");- int i=0;- for(int val : ids) {- Map<?,?> t = (Map<?,?>)group.get(i);- Long tip = (Long)t.get("id");- if(tip.intValue() != val) {- throw new Exception("Found value:"+tip.intValue()+" expecting:"+val);+ List<?> group = (List<?>) tuple.get("tuples");+ int i = 0;+ for (int val : ids) {+ Map<?, ?> t = (Map<?, ?>) group.get(i);+ Long tip = (Long) t.get("id");+ if (tip.intValue() != val) {+ throw new Exception("Found value:" + tip.intValue() + " expecting:" + val);}++i;}@@ -4520,24 +5260,23 @@ public class StreamDecoratorTest extends SolrCloudTestCase {}public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {- long lv = (long)tuple.get(fieldName);- if(lv != l) {- throw new Exception("Longs not equal:"+l+" : "+lv);+ long lv = (long) tuple.get(fieldName);+ if (lv != l) {+ throw new Exception("Longs not equal:" + l + " : " + lv);}return true;}-+public boolean assertString(Tuple tuple, String fieldName, String expected) throws Exception {- String actual = (String)tuple.get(fieldName);-- if( (null == expected && null != actual) ||- (null != expected && null == actual) ||- (null != expected && !expected.equals(actual))){- throw new Exception("Longs not equal:"+expected+" : "+actual);+ String actual = (String) tuple.get(fieldName);++ if ((null == expected && null != actual)+ || (null != expected && null == actual)+ || (null != expected && !expected.equals(actual))) {+ throw new Exception("Longs not equal:" + expected + " : " + actual);}return true;}-}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.javaindex 38c09023ef4..ac56e575103 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@@ -30,7 +30,6 @@ import java.util.Map;import java.util.stream.Collectors;import java.util.stream.IntStream;import java.util.zip.GZIPOutputStream;-import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.SolrTestCaseJ4;@@ -58,7 +57,7 @@ import org.junit.Test;@Slow@SolrTestCaseJ4.SuppressSSL[email protected]({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})[email protected]({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})@ThreadLeakLingering(linger = 0)public class StreamExpressionTest extends SolrCloudTestCase {@@ -72,8 +71,22 @@ public class StreamExpressionTest extends SolrCloudTestCase {@BeforeClasspublic static void setupCluster() throws Exception {configureCluster(4)- .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))- .addConfig("ml", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("ml").resolve("conf"))+ .addConfig(+ "conf",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("streaming")+ .resolve("conf"))+ .addConfig(+ "ml",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("ml")+ .resolve("conf")).configure();String collection;@@ -84,14 +97,18 @@ public class StreamExpressionTest extends SolrCloudTestCase {collection = COLLECTIONORALIAS;}- CollectionAdminRequest.createCollection(collection, "conf", 2, 1).process(cluster.getSolrClient());+ CollectionAdminRequest.createCollection(collection, "conf", 2, 1)+ .process(cluster.getSolrClient());cluster.waitForActiveCollection(collection, 2, 2);if (useAlias) {- CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());+ CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection)+ .process(cluster.getSolrClient());}- // Create a collection for use by the filestream() expression, and place some files there for it to read.- CollectionAdminRequest.createCollection(FILESTREAM_COLLECTION, "conf", 1, 1).process(cluster.getSolrClient());+ // Create a collection for use by the filestream() expression, and place some files there for it+ // to read.+ CollectionAdminRequest.createCollection(FILESTREAM_COLLECTION, "conf", 1, 1)+ .process(cluster.getSolrClient());cluster.waitForActiveCollection(FILESTREAM_COLLECTION, 1, 1);final Path dataDir = findUserFilesDataDir();populateFileStreamData(dataDir);@@ -99,9 +116,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {@Beforepublic void cleanIndex() throws Exception {- new UpdateRequest()- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTIONORALIAS);}@Test@@ -115,7 +130,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {.add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory().withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress());+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress());StreamExpression expression;CloudSolrStream stream;List<Tuple> tuples;@@ -125,7 +142,11 @@ public class StreamExpressionTest extends SolrCloudTestCase {try {// Basic test- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -135,7 +156,11 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertLong(tuples.get(0), "a_i", 0);// Basic w/aliases- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", aliases=\"a_i=alias.a_i, a_s=name\")");+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", aliases=\"a_i=alias.a_i, a_s=name\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -146,7 +171,11 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertString(tuples.get(0), "name", "hello0");// Basic filtered test- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -156,7 +185,11 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertLong(tuples.get(1), "a_i", 3);try {- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -166,7 +199,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {}try {- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=\"blah\", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search(" + COLLECTIONORALIAS + ", q=\"blah\", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -176,7 +211,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {}try {- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=\"blah\", fl=\"id, a_f\", sort=\"a_f\")");+ expression =+ StreamExpressionParser.parse(+ "search(" + COLLECTIONORALIAS + ", q=\"blah\", fl=\"id, a_f\", sort=\"a_f\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -187,7 +224,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {// Test with shards param- List<String> shardUrls = TupleStream.getShards(cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);+ List<String> shardUrls =+ TupleStream.getShards(+ cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);Map<String, List<String>> shardsMap = new HashMap<>();shardsMap.put("myCollection", shardUrls);@@ -196,7 +235,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {context.setSolrClientCache(solrClientCache);// Basic test- expression = StreamExpressionParser.parse("search(myCollection, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search(myCollection, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(context);tuples = getTuples(stream);@@ -205,10 +246,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertOrder(tuples, 0, 2, 1, 3, 4);assertLong(tuples.get(0), "a_i", 0);+ // Execersise the /stream hander- //Execersise the /stream hander-- //Add the shards http parameter for the myCollection+ // Add the shards http parameter for the myCollectionStringBuilder buf = new StringBuilder();for (String shardUrl : shardUrls) {if (buf.length() > 0) {@@ -219,7 +259,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams solrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");- solrParams.add("expr", "search(myCollection, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");+ solrParams.add(+ "expr", "search(myCollection, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");solrParams.add("myCollection.shards", buf.toString());stream.setStreamContext(context);tuples = getTuples(stream);@@ -248,7 +289,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- List<String> shardUrls = TupleStream.getShards(cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);+ List<String> shardUrls =+ TupleStream.getShards(+ cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);try {StringBuilder buf = new StringBuilder();@@ -261,7 +304,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams solrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");- solrParams.add("expr", "sort(search("+COLLECTIONORALIAS+"), by=\"a_i asc\")");+ solrParams.add("expr", "sort(search(" + COLLECTIONORALIAS + "), by=\"a_i asc\")");SolrStream solrStream = new SolrStream(shardUrls.get(0), solrParams);solrStream.setStreamContext(streamContext);tuples = getTuples(solrStream);@@ -292,7 +335,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {}}-@Testpublic void testSqlStream() throws Exception {@@ -308,7 +350,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- List<String> shardUrls = TupleStream.getShards(cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);+ List<String> shardUrls =+ TupleStream.getShards(+ cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);try {StringBuilder buf = new StringBuilder();@@ -321,14 +365,16 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams solrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");- solrParams.add("expr", "sql("+COLLECTIONORALIAS+", stmt=\"select id from collection1 order by a_i asc\")");+ solrParams.add(+ "expr",+ "sql(" + COLLECTIONORALIAS + ", stmt=\"select id from collection1 order by a_i asc\")");SolrStream solrStream = new SolrStream(shardUrls.get(0), solrParams);solrStream.setStreamContext(streamContext);tuples = getTuples(solrStream);assert (tuples.size() == 5);assertOrder(tuples, 0, 1, 2, 3, 4);- //Test with using the default collection+ // Test with using the default collectionsolrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");solrParams.add("expr", "sql(stmt=\"select id from collection1 order by a_i asc\")");@@ -364,7 +410,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {try {// Basic test- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", zkHost=" + cluster.getZkServer().getZkAddress() + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", zkHost="+ + cluster.getZkServer().getZkAddress()+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -374,7 +426,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertLong(tuples.get(0), "a_i", 0);// Basic w/aliases- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", aliases=\"a_i=alias.a_i, a_s=name\", zkHost=" + cluster.getZkServer().getZkAddress() + ")");+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", aliases=\"a_i=alias.a_i, a_s=name\", zkHost="+ + cluster.getZkServer().getZkAddress()+ + ")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -385,8 +443,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertString(tuples.get(0), "name", "hello0");// Basic filtered test- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", zkHost="- + cluster.getZkServer().getZkAddress() + ", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", zkHost="+ + cluster.getZkServer().getZkAddress()+ + ", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -395,19 +458,25 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertOrder(tuples, 0, 3, 4);assertLong(tuples.get(1), "a_i", 3);-// Test a couple of multile field lists.- expression = StreamExpressionParser.parse("search(collection1, fq=\"a_s:hello0\", fq=\"a_s:hello1\", q=\"id:(*)\", " +- "zkHost=" + cluster.getZkServer().getZkAddress() + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search(collection1, fq=\"a_s:hello0\", fq=\"a_s:hello1\", q=\"id:(*)\", "+ + "zkHost="+ + cluster.getZkServer().getZkAddress()+ + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);assertEquals("fq clauses should have prevented any docs from coming back", tuples.size(), 0);-- expression = StreamExpressionParser.parse("search(collection1, fq=\"a_s:(hello0 OR hello1)\", q=\"id:(*)\", " +- "zkHost=" + cluster.getZkServer().getZkAddress() + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search(collection1, fq=\"a_s:(hello0 OR hello1)\", q=\"id:(*)\", "+ + "zkHost="+ + cluster.getZkServer().getZkAddress()+ + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -417,7 +486,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {} finally {solrClientCache.close();}-}@Test@@ -433,19 +501,23 @@ public class StreamExpressionTest extends SolrCloudTestCase {.add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;List<Tuple> tuples;TupleStream stream;// Basic testModifiableSolrParams sParams = new ModifiableSolrParams();- sParams.set("expr", "merge("- + "${q1},"- + "${q2},"- + "on=${mySort})");+ sParams.set("expr", "merge(" + "${q1}," + "${q2}," + "on=${mySort})");sParams.set(CommonParams.QT, "/stream");- sParams.set("q1", "search(" + COLLECTIONORALIAS + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=${mySort})");- sParams.set("q2", "search(" + COLLECTIONORALIAS + ", q=\"id:(1)\", fl=\"id,a_s,a_i,a_f\", sort=${mySort})");+ sParams.set(+ "q1",+ "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=${mySort})");+ sParams.set(+ "q2",+ "search(" + COLLECTIONORALIAS + ", q=\"id:(1)\", fl=\"id,a_s,a_i,a_f\", sort=${mySort})");sParams.set("mySort", "a_f asc");stream = new SolrStream(url, sParams);tuples = getTuples(stream);@@ -462,7 +534,11 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertOrder(tuples, 4, 3, 1, 0);// Basic w/ multi comp- sParams.set("q2", "search(" + COLLECTIONORALIAS + ", q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=${mySort})");+ sParams.set(+ "q2",+ "search("+ + COLLECTIONORALIAS+ + ", q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=${mySort})");sParams.set("mySort", "\"a_f asc, a_s asc\"");stream = new SolrStream(url, sParams);tuples = getTuples(stream);@@ -474,12 +550,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {}}-@Testpublic void testNulls() throws Exception {new UpdateRequest()- .add(id, "0", "a_i", "1", "a_f", "0", "s_multi", "aaa", "s_multi", "bbb", "i_multi", "100", "i_multi", "200")+ .add(+ id, "0", "a_i", "1", "a_f", "0", "s_multi", "aaa", "s_multi", "bbb", "i_multi", "100",+ "i_multi", "200").add(id, "2", "a_s", "hello2", "a_i", "3", "a_f", "0").add(id, "3", "a_s", "hello3", "a_i", "4", "a_f", "3").add(id, "4", "a_s", "hello4", "a_f", "4")@@ -494,12 +571,17 @@ public class StreamExpressionTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("search", CloudSolrStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("search", CloudSolrStream.class);try {// Basic test- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f, s_multi, i_multi\", qt=\"/export\", sort=\"a_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f, s_multi, i_multi\", qt=\"/export\", sort=\"a_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -513,7 +595,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertNull(tuple.get("i_multi"));assertNull(tuple.getLong("a_i"));-tuple = tuples.get(1);assertNull(tuple.get("a_s"));List<String> strings = tuple.getStrings("s_multi");@@ -523,8 +604,12 @@ public class StreamExpressionTest extends SolrCloudTestCase {List<Long> longs = tuple.getLongs("i_multi");assertNotNull(longs);- //test sort (asc) with null string field. Null should sort to the top.- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f, s_multi, i_multi\", qt=\"/export\", sort=\"a_s asc\")");+ // test sort (asc) with null string field. Null should sort to the top.+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f, s_multi, i_multi\", qt=\"/export\", sort=\"a_s asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -532,8 +617,12 @@ public class StreamExpressionTest extends SolrCloudTestCase {assert (tuples.size() == 5);assertOrder(tuples, 0, 1, 2, 3, 4);- //test sort(desc) with null string field. Null should sort to the bottom.- expression = StreamExpressionParser.parse("search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f, s_multi, i_multi\", qt=\"/export\", sort=\"a_s desc\")");+ // test sort(desc) with null string field. Null should sort to the bottom.+ expression =+ StreamExpressionParser.parse(+ "search("+ + COLLECTIONORALIAS+ + ", q=*:*, fl=\"id,a_s,a_i,a_f, s_multi, i_multi\", qt=\"/export\", sort=\"a_s desc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -545,44 +634,45 @@ public class StreamExpressionTest extends SolrCloudTestCase {}}--@Testpublic void testRandomStream() throws Exception {UpdateRequest update = new UpdateRequest();- for(int idx = 0; idx < 1000; ++idx){+ for (int idx = 0; idx < 1000; ++idx) {String idxString = Integer.toString(idx);- update.add(id,idxString, "a_s", "hello" + idxString, "a_i", idxString, "a_f", idxString);+ update.add(id, idxString, "a_s", "hello" + idxString, "a_i", idxString, "a_f", idxString);}update.commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamExpression expression;TupleStream stream;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("random", RandomFacadeStream.class);-+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("random", RandomFacadeStream.class);StreamContext context = new StreamContext();SolrClientCache cache = new SolrClientCache();try {context.setSolrClientCache(cache);- expression = StreamExpressionParser.parse("random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"1000\", fl=\"id, a_i\")");+ expression =+ StreamExpressionParser.parse(+ "random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"1000\", fl=\"id, a_i\")");stream = factory.constructStream(expression);stream.setStreamContext(context);List<Tuple> tuples1 = getTuples(stream);assert (tuples1.size() == 1000);- expression = StreamExpressionParser.parse("random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"1000\", fl=\"id, a_i\")");+ expression =+ StreamExpressionParser.parse(+ "random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"1000\", fl=\"id, a_i\")");stream = factory.constructStream(expression);stream.setStreamContext(context);List<Tuple> tuples2 = getTuples(stream);assert (tuples2.size() == 1000);-boolean different = false;for (int i = 0; i < tuples1.size(); i++) {Tuple tuple1 = tuples1.get(i);@@ -602,25 +692,31 @@ public class StreamExpressionTest extends SolrCloudTestCase {Tuple tuple1 = tuples1.get(i);Tuple tuple2 = tuples2.get(i);if (!tuple1.get("id").equals(tuple2.get(id))) {- assert(tuple1.getLong("id").equals(tuple2.get("a_i")));+ assert (tuple1.getLong("id").equals(tuple2.get("a_i")));}}- expression = StreamExpressionParser.parse("random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"1\", fl=\"id, a_i\")");+ expression =+ StreamExpressionParser.parse(+ "random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"1\", fl=\"id, a_i\")");stream = factory.constructStream(expression);stream.setStreamContext(context);List<Tuple> tuples3 = getTuples(stream);assert (tuples3.size() == 1);- //Exercise the DeepRandomStream with higher rows+ // Exercise the DeepRandomStream with higher rows- expression = StreamExpressionParser.parse("random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"10001\", fl=\"id, a_i\")");+ expression =+ StreamExpressionParser.parse(+ "random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"10001\", fl=\"id, a_i\")");stream = factory.constructStream(expression);stream.setStreamContext(context);List<Tuple> tuples10 = getTuples(stream);assert (tuples10.size() == 1000);- expression = StreamExpressionParser.parse("random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"10001\", fl=\"id, a_i\")");+ expression =+ StreamExpressionParser.parse(+ "random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"10001\", fl=\"id, a_i\")");stream = factory.constructStream(expression);stream.setStreamContext(context);List<Tuple> tuples11 = getTuples(stream);@@ -645,37 +741,36 @@ public class StreamExpressionTest extends SolrCloudTestCase {Tuple tuple1 = tuples10.get(i);Tuple tuple2 = tuples11.get(i);if (!tuple1.get("id").equals(tuple2.get(id))) {- assert(tuple1.getLong("id").equals(tuple2.get("a_i")));+ assert (tuple1.getLong("id").equals(tuple2.get("a_i")));}}--- //Exercise the /stream handler+ // Exercise the /stream handlerModifiableSolrParams sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream"));- sParams.add("expr", "random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"1\", fl=\"id, a_i\")");+ sParams.add(+ "expr", "random(" + COLLECTIONORALIAS + ", q=\"*:*\", rows=\"1\", fl=\"id, a_i\")");JettySolrRunner jetty = cluster.getJettySolrRunner(0);- SolrStream solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);+ SolrStream solrStream =+ new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);List<Tuple> tuples4 = getTuples(solrStream);assert (tuples4.size() == 1);- //Assert no x-axis+ // Assert no x-axisassertNull(tuples4.get(0).get("x"));-sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream"));sParams.add("expr", "random(" + COLLECTIONORALIAS + ")");jetty = cluster.getJettySolrRunner(0);solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);tuples4 = getTuples(solrStream);- assert(tuples4.size() == 500);+ assert (tuples4.size() == 500);@SuppressWarnings({"rawtypes"})Map fields = tuples4.get(0).getFields();- assert(fields.containsKey("id"));- assert(fields.containsKey("a_f"));- assert(fields.containsKey("a_i"));- assert(fields.containsKey("a_s"));- //Assert the x-axis:- for(int i=0; i<tuples4.size(); i++) {+ assert (fields.containsKey("id"));+ assert (fields.containsKey("a_f"));+ assert (fields.containsKey("a_i"));+ assert (fields.containsKey("a_s"));+ // Assert the x-axis:+ for (int i = 0; i < tuples4.size(); i++) {assertEquals(tuples4.get(i).getLong("x").longValue(), i);}@@ -699,34 +794,55 @@ public class StreamExpressionTest extends SolrCloudTestCase {try {context.setSolrClientCache(cache);ModifiableSolrParams sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream"));- sParams.add("expr", "knnSearch(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", rows=\"4\", fl=\"id, score\", mintf=\"1\")");+ sParams.add(+ "expr",+ "knnSearch("+ + COLLECTIONORALIAS+ + ", id=\"1\", qf=\"a_t\", rows=\"4\", fl=\"id, score\", mintf=\"1\")");JettySolrRunner jetty = cluster.getJettySolrRunner(0);- SolrStream solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);+ SolrStream solrStream =+ new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 3);assertOrder(tuples, 2, 3, 4);sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream"));- sParams.add("expr", "knnSearch(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", k=\"2\", fl=\"id, score\", mintf=\"1\")");+ sParams.add(+ "expr",+ "knnSearch("+ + COLLECTIONORALIAS+ + ", id=\"1\", qf=\"a_t\", k=\"2\", fl=\"id, score\", mintf=\"1\")");solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);tuples = getTuples(solrStream);assertTrue(tuples.size() == 2);assertOrder(tuples, 2, 3);sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream"));- sParams.add("expr", "knnSearch(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", rows=\"4\", fl=\"id, score\", mintf=\"1\", maxdf=\"0\")");+ sParams.add(+ "expr",+ "knnSearch("+ + COLLECTIONORALIAS+ + ", id=\"1\", qf=\"a_t\", rows=\"4\", fl=\"id, score\", mintf=\"1\", maxdf=\"0\")");solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);tuples = getTuples(solrStream);assertTrue(tuples.size() == 0);sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream"));- sParams.add("expr", "knnSearch(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", rows=\"4\", fl=\"id, score\", mintf=\"1\", maxwl=\"1\")");+ sParams.add(+ "expr",+ "knnSearch("+ + COLLECTIONORALIAS+ + ", id=\"1\", qf=\"a_t\", rows=\"4\", fl=\"id, score\", mintf=\"1\", maxwl=\"1\")");solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);tuples = getTuples(solrStream);assertTrue(tuples.size() == 0);sParams = new ModifiableSolrParams(params(CommonParams.QT, "/stream"));- sParams.add("expr", "knnSearch(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", rows=\"2\", fl=\"id, score\", mintf=\"1\", minwl=\"20\")");+ sParams.add(+ "expr",+ "knnSearch("+ + COLLECTIONORALIAS+ + ", id=\"1\", qf=\"a_t\", rows=\"2\", fl=\"id, score\", mintf=\"1\", minwl=\"20\")");solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);tuples = getTuples(solrStream);assertTrue(tuples.size() == 0);@@ -752,17 +868,18 @@ public class StreamExpressionTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())- .withFunctionName("stats", StatsStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("count", CountMetric.class)- .withFunctionName("std", StdMetric.class)- .withFunctionName("per", PercentileMetric.class)- .withFunctionName("countDist", CountDistinctMetric.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())+ .withFunctionName("stats", StatsStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("count", CountMetric.class)+ .withFunctionName("std", StdMetric.class)+ .withFunctionName("per", PercentileMetric.class)+ .withFunctionName("countDist", CountDistinctMetric.class);StreamExpression expression;TupleStream stream;@@ -771,7 +888,10 @@ public class StreamExpressionTest extends SolrCloudTestCase {SolrClientCache cache = new SolrClientCache();try {streamContext.setSolrClientCache(cache);- String expr = "stats(" + COLLECTIONORALIAS + ", q=*:*, sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), std(a_i), std(a_f), per(a_i, 50), per(a_f, 50), countDist(a_s), count(*))";+ String expr =+ "stats("+ + COLLECTIONORALIAS+ + ", q=*:*, sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), std(a_i), std(a_f), per(a_i, 50), per(a_f, 50), countDist(a_s), count(*))";expression = StreamExpressionParser.parse(expr);stream = factory.constructStream(expression);stream.setStreamContext(streamContext);@@ -780,7 +900,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assert (tuples.size() == 1);- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);@@ -799,7 +919,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {Double count = tuple.getDouble("count(*)");Long countDist = tuple.getLong("countDist(a_s)");-assertTrue(sumi.longValue() == 70);assertTrue(sumf.doubleValue() == 55.0D);assertTrue(mini.doubleValue() == 0.0D);@@ -815,11 +934,12 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(count.doubleValue() == 10);assertEquals(countDist.longValue(), 3L);+ // Test without query-- //Test without query-- expr = "stats(" + COLLECTIONORALIAS + ", sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), std(a_i), std(a_f), per(a_i, 50), per(a_f, 50), count(*))";+ expr =+ "stats("+ + COLLECTIONORALIAS+ + ", sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), std(a_i), std(a_f), per(a_i, 50), per(a_f, 50), count(*))";expression = StreamExpressionParser.parse(expr);stream = factory.constructStream(expression);stream.setStreamContext(streamContext);@@ -828,7 +948,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assert (tuples.size() == 1);- //Test Long and Double Sums+ // Test Long and Double Sumstuple = tuples.get(0);@@ -860,9 +980,12 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(perf.doubleValue() == 5.5D);assertTrue(count.doubleValue() == 10);- //Test with shards parameter- List<String> shardUrls = TupleStream.getShards(cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);- expr = "stats(myCollection, q=*:*, sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), std(a_i), std(a_f), per(a_i, 50), per(a_f, 50), count(*))";+ // Test with shards parameter+ List<String> shardUrls =+ TupleStream.getShards(+ cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);+ expr =+ "stats(myCollection, q=*:*, sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), std(a_i), std(a_f), per(a_i, 50), per(a_f, 50), count(*))";Map<String, List<String>> shardsMap = new HashMap<>();shardsMap.put("myCollection", shardUrls);StreamContext context = new StreamContext();@@ -875,7 +998,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assert (tuples.size() == 1);- //Test Long and Double Sums+ // Test Long and Double Sumstuple = tuples.get(0);@@ -907,9 +1030,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(perf.doubleValue() == 5.5D);assertTrue(count.doubleValue() == 10);- //Execersise the /stream hander+ // Execersise the /stream hander- //Add the shards http parameter for the myCollection+ // Add the shards http parameter for the myCollectionStringBuilder buf = new StringBuilder();for (String shardUrl : shardUrls) {if (buf.length() > 0) {@@ -926,7 +1049,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {tuples = getTuples(solrStream);assert (tuples.size() == 1);- tuple =tuples.get(0);+ tuple = tuples.get(0);sumi = tuple.getDouble("sum(a_i)");sumf = tuple.getDouble("sum(a_f)");@@ -947,7 +1070,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(avgi.doubleValue() == 7.0D);assertTrue(avgf.doubleValue() == 5.5D);assertTrue(count.doubleValue() == 10);- //Add a negative test to prove that it cannot find slices if shards parameter is removed+ // Add a negative test to prove that it cannot find slices if shards parameter is removedtry {ModifiableSolrParams solrParamsBad = new ModifiableSolrParams();@@ -967,16 +1090,16 @@ public class StreamExpressionTest extends SolrCloudTestCase {@Testpublic void testFacet2DStream() throws Exception {new UpdateRequest()- .add(id, "0", "diseases_s", "stroke", "symptoms_s", "confusion", "cases_i", "10")- .add(id, "1", "diseases_s", "cancer", "symptoms_s", "indigestion","cases_i", "5" )- .add(id, "2", "diseases_s", "diabetes", "symptoms_s", "thirsty", "cases_i", "20")- .add(id, "3", "diseases_s", "stroke", "symptoms_s", "confusion", "cases_i", "10")- .add(id, "4", "diseases_s", "bronchus", "symptoms_s", "nausea", "cases_i", "25")- .add(id, "5", "diseases_s", "bronchus", "symptoms_s", "cough", "cases_i", "10")- .add(id, "6", "diseases_s", "bronchus", "symptoms_s", "cough", "cases_i", "10")- .add(id, "7", "diseases_s", "heart attack", "symptoms_s", "indigestion", "cases_i", "5")- .add(id, "8", "diseases_s", "diabetes", "symptoms_s", "urination", "cases_i", "10")- .add(id, "9", "diseases_s", "diabetes", "symptoms_s", "thirsty", "cases_i", "20")+ .add(id, "0", "diseases_s", "stroke", "symptoms_s", "confusion", "cases_i", "10")+ .add(id, "1", "diseases_s", "cancer", "symptoms_s", "indigestion", "cases_i", "5")+ .add(id, "2", "diseases_s", "diabetes", "symptoms_s", "thirsty", "cases_i", "20")+ .add(id, "3", "diseases_s", "stroke", "symptoms_s", "confusion", "cases_i", "10")+ .add(id, "4", "diseases_s", "bronchus", "symptoms_s", "nausea", "cases_i", "25")+ .add(id, "5", "diseases_s", "bronchus", "symptoms_s", "cough", "cases_i", "10")+ .add(id, "6", "diseases_s", "bronchus", "symptoms_s", "cough", "cases_i", "10")+ .add(id, "7", "diseases_s", "heart attack", "symptoms_s", "indigestion", "cases_i", "5")+ .add(id, "8", "diseases_s", "diabetes", "symptoms_s", "urination", "cases_i", "10")+ .add(id, "9", "diseases_s", "diabetes", "symptoms_s", "thirsty", "cases_i", "20").add(id, "10", "diseases_s", "diabetes", "symptoms_s", "thirsty", "cases_i", "20").commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamExpression expression;@@ -984,11 +1107,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {List<Tuple> tuples;ModifiableSolrParams paramsLoc = new ModifiableSolrParams();- String expr = "facet2D(collection1, q=\"*:*\", x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"3,1\", count(*))";+ String expr =+ "facet2D(collection1, q=\"*:*\", x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"3,1\", count(*))";paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -1012,7 +1137,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuple3.getString("symptoms_s"), "confusion");assertEquals(tuple3.getLong("count(*)").longValue(), 2);-paramsLoc = new ModifiableSolrParams();expr = "facet2D(collection1, x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"3,1\")";paramsLoc.set("expr", expr);@@ -1042,7 +1166,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuple3.getString("count(*)"), "2");paramsLoc = new ModifiableSolrParams();- expr = "facet2D(collection1, q=\"*:*\", x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"3,1\", sum(cases_i))";+ expr =+ "facet2D(collection1, q=\"*:*\", x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"3,1\", sum(cases_i))";paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -1054,7 +1179,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuples.size(), 3);-tuple1 = tuples.get(0);assertEquals(tuple1.getString("diseases_s"), "diabetes");assertEquals(tuple1.getString("symptoms_s"), "thirsty");@@ -1065,15 +1189,14 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuple2.getString("symptoms_s"), "nausea");assertEquals(tuple2.getLong("sum(cases_i)").longValue(), 25L);-tuple3 = tuples.get(2);assertEquals(tuple3.getString("diseases_s"), "stroke");assertEquals(tuple3.getString("symptoms_s"), "confusion");assertEquals(tuple3.getLong("sum(cases_i)").longValue(), 20L);-paramsLoc = new ModifiableSolrParams();- expr = "facet2D(collection1, q=\"*:*\", x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"3,1\", avg(cases_i))";+ expr =+ "facet2D(collection1, q=\"*:*\", x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"3,1\", avg(cases_i))";paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -1101,7 +1224,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuple3.getLong("avg(cases_i)").longValue(), 10);paramsLoc = new ModifiableSolrParams();- expr = "facet2D(collection1, q=\"*:*\", x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"2,2\")";+ expr =+ "facet2D(collection1, q=\"*:*\", x=\"diseases_s\", y=\"symptoms_s\", dimensions=\"2,2\")";paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -1123,7 +1247,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuple2.getString("symptoms_s"), "urination");assertEquals(tuple2.getLong("count(*)").longValue(), 1);-tuple3 = tuples.get(2);assertEquals(tuple3.getString("diseases_s"), "bronchus");assertEquals(tuple3.getString("symptoms_s"), "cough");@@ -1135,7 +1258,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuple4.getLong("count(*)").longValue(), 1);}-@Testpublic void testDrillStream() throws Exception {@@ -1155,20 +1277,22 @@ public class StreamExpressionTest extends SolrCloudTestCase {List<Tuple> tuples;ModifiableSolrParams paramsLoc = new ModifiableSolrParams();- String expr = "rollup(select(drill("- + " collection1, "- + " q=\"*:*\", "- + " fl=\"a_s, a_f\", "- + " sort=\"a_s desc\", "- + " rollup(input(), over=\"a_s\", count(*), sum(a_f)))," +- " a_s, count(*) as cnt, sum(a_f) as saf)," +- " over=\"a_s\"," +- " sum(cnt), sum(saf)"- + ")";+ String expr =+ "rollup(select(drill("+ + " collection1, "+ + " q=\"*:*\", "+ + " fl=\"a_s, a_f\", "+ + " sort=\"a_s desc\", "+ + " rollup(input(), over=\"a_s\", count(*), sum(a_f))),"+ + " a_s, count(*) as cnt, sum(a_f) as saf),"+ + " over=\"a_s\","+ + " sum(cnt), sum(saf)"+ + ")";paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -1202,10 +1326,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(bucket.equals("hello0"));assertTrue(count.doubleValue() == 4);assertEquals(saf.doubleValue(), 18, 0);-}- @Test+ @Testpublic void testFacetStream() throws Exception {new UpdateRequest()@@ -1225,41 +1348,42 @@ public class StreamExpressionTest extends SolrCloudTestCase {TupleStream stream;List<Tuple> tuples;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("facet", FacetStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("std", StdMetric.class)- .withFunctionName("per", PercentileMetric.class)- .withFunctionName("count", CountMetric.class)- .withFunctionName("countDist", CountDistinctMetric.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("facet", FacetStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("std", StdMetric.class)+ .withFunctionName("per", PercentileMetric.class)+ .withFunctionName("count", CountMetric.class)+ .withFunctionName("countDist", CountDistinctMetric.class);// Basic test- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "fl=\"a_s,a_i,a_f\", "- + "sort=\"a_s asc\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) asc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "std(a_i), std(a_f),"- + "per(a_i, 50), per(a_f, 50),"- + "count(*), countDist(a_i)"- + ")";+ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "fl=\"a_s,a_i,a_f\", "+ + "sort=\"a_s asc\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) asc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "std(a_i), std(a_f),"+ + "per(a_i, 50), per(a_f, 50),"+ + "count(*), countDist(a_i)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);- assert(tuples.size() == 3);-+ assert (tuples.size() == 3);Tuple tuple = tuples.get(0);String bucket = tuple.getString("a_s");@@ -1291,10 +1415,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 4.949747468305833D);assertTrue(stdf.doubleValue() == 2.1213203435596424D);assertTrue(peri.doubleValue() == 7.5D);- assertTrue(perf.doubleValue() == 5.5D);+ assertTrue(perf.doubleValue() == 5.5D);assertEquals(countDist.longValue(), 2);-tuple = tuples.get(1);bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");@@ -1312,7 +1435,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {perf = tuple.getDouble("per(a_f,50)");countDist = tuple.getLong("countDist(a_i)");-assertTrue(bucket.equals("hello0"));assertTrue(sumi.doubleValue() == 17.0D);assertTrue(sumf.doubleValue() == 18.0D);@@ -1326,10 +1448,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 6.551081335677848D);assertTrue(stdf.doubleValue() == 4.041451884327381D);assertTrue(peri.doubleValue() == 1.5D);- assertTrue(perf.doubleValue() == 3.5D);+ assertTrue(perf.doubleValue() == 3.5D);assertEquals(countDist.longValue(), 4);-tuple = tuples.get(2);bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");@@ -1347,7 +1468,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {perf = tuple.getDouble("per(a_f,50)");countDist = tuple.getLong("countDist(a_i)");-assertTrue(bucket.equals("hello3"));assertTrue(sumi.doubleValue() == 38.0D);assertTrue(sumf.doubleValue() == 26.0D);@@ -1361,33 +1481,33 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 4.509249752822894D);assertTrue(stdf.doubleValue() == 2.6457513110645907D);assertTrue(peri.doubleValue() == 11.0D);- assertTrue(perf.doubleValue() == 7.0D);+ assertTrue(perf.doubleValue() == 7.0D);assertEquals(countDist.longValue(), 4);- //Reverse the Sort.-- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "fl=\"a_s,a_i,a_f\", "- + "sort=\"a_s asc\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) desc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "std(a_i), std(a_f),"- + "per(a_i, 50), per(a_f, 50),"- + "count(*)"- + ")";+ // Reverse the Sort.++ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "fl=\"a_s,a_i,a_f\", "+ + "sort=\"a_s asc\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) desc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "std(a_i), std(a_f),"+ + "per(a_i, 50), per(a_f, 50),"+ + "count(*)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);-- //Test Long and Double Sums+ // Test Long and Double Sumstuple = tuples.get(0);bucket = tuple.getString("a_s");@@ -1418,8 +1538,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 4.509249752822894D);assertTrue(stdf.doubleValue() == 2.6457513110645907D);assertTrue(peri.doubleValue() == 11.0D);- assertTrue(perf.doubleValue() == 7.0D);-+ assertTrue(perf.doubleValue() == 7.0D);tuple = tuples.get(1);bucket = tuple.getString("a_s");@@ -1450,7 +1569,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 6.551081335677848D);assertTrue(stdf.doubleValue() == 4.041451884327381D);assertTrue(peri.doubleValue() == 1.5D);- assertTrue(perf.doubleValue() == 3.5D);+ assertTrue(perf.doubleValue() == 3.5D);tuple = tuples.get(2);bucket = tuple.getString("a_s");@@ -1481,29 +1600,28 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 4.949747468305833D);assertTrue(stdf.doubleValue() == 2.1213203435596424D);assertTrue(peri.doubleValue() == 7.5D);- assertTrue(perf.doubleValue() == 5.5D);--- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "fl=\"a_s,a_i,a_f\", "- + "sort=\"a_s asc\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) desc\", "- + "rows=2, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")";+ assertTrue(perf.doubleValue() == 5.5D);++ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "fl=\"a_s,a_i,a_f\", "+ + "sort=\"a_s asc\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) desc\", "+ + "rows=2, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);-- //Test rows+ // Test rowstuple = tuples.get(0);assertEquals(tuples.size(), 2);@@ -1553,27 +1671,26 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(avgf.doubleValue() == 4.5D);assertTrue(count.doubleValue() == 4);-- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "fl=\"a_s,a_i,a_f\", "- + "sort=\"a_s asc\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) desc\", "- + "rows=2, offset=1, method=dvhash, refine=true,"- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")";+ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "fl=\"a_s,a_i,a_f\", "+ + "sort=\"a_s asc\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) desc\", "+ + "rows=2, offset=1, method=dvhash, refine=true,"+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);-- //Test offset+ // Test offsettuple = tuples.get(0);assertEquals(tuples.size(), 2);@@ -1624,30 +1741,29 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(avgf.doubleValue() == 5.5D);assertTrue(count.doubleValue() == 2);-- //Test index sort- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "fl=\"a_s,a_i,a_f\", "- + "sort=\"a_s asc\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"a_s desc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "std(a_i), std(a_f),"- + "per(a_i, 50), per(a_f, 50),"- + "count(*)"- + ")";+ // Test index sort+ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "fl=\"a_s,a_i,a_f\", "+ + "sort=\"a_s asc\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"a_s desc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "std(a_i), std(a_f),"+ + "per(a_i, 50), per(a_f, 50),"+ + "count(*)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);- assert(tuples.size() == 3);-+ assert (tuples.size() == 3);tuple = tuples.get(0);bucket = tuple.getString("a_s");@@ -1678,7 +1794,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 4.949747468305833D);assertTrue(stdf.doubleValue() == 2.1213203435596424D);assertTrue(peri.doubleValue() == 7.5D);- assertTrue(perf.doubleValue() == 5.5D);+ assertTrue(perf.doubleValue() == 5.5D);tuple = tuples.get(1);bucket = tuple.getString("a_s");@@ -1709,8 +1825,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 4.509249752822894D);assertTrue(stdf.doubleValue() == 2.6457513110645907D);assertTrue(peri.doubleValue() == 11.0D);- assertTrue(perf.doubleValue() == 7.0D);-+ assertTrue(perf.doubleValue() == 7.0D);tuple = tuples.get(2);bucket = tuple.getString("a_s");@@ -1741,31 +1856,30 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(stdi.doubleValue() == 6.551081335677848D);assertTrue(stdf.doubleValue() == 4.041451884327381D);assertTrue(peri.doubleValue() == 1.5D);- assertTrue(perf.doubleValue() == 3.5D);--- //Test index sort-- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "fl=\"a_s,a_i,a_f\", "- + "sort=\"a_s asc\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"a_s asc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")";+ assertTrue(perf.doubleValue() == 3.5D);++ // Test index sort++ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "fl=\"a_s,a_i,a_f\", "+ + "sort=\"a_s asc\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"a_s asc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);- assert(tuples.size() == 3);-+ assert (tuples.size() == 3);tuple = tuples.get(0);bucket = tuple.getString("a_s");@@ -1790,7 +1904,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(avgf.doubleValue() == 4.5D);assertTrue(count.doubleValue() == 4);-tuple = tuples.get(1);bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");@@ -1814,7 +1927,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(avgf.doubleValue() == 6.5D);assertTrue(count.doubleValue() == 4);-tuple = tuples.get(2);bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");@@ -1838,57 +1950,219 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(avgf.doubleValue() == 5.5D);assertTrue(count.doubleValue() == 2);- //Test zero result facets- clause = "facet("- + "collection1, "- + "q=\"blahhh\", "- + "fl=\"a_s,a_i,a_f\", "- + "sort=\"a_s asc\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"a_s asc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")";+ // Test zero result facets+ clause =+ "facet("+ + "collection1, "+ + "q=\"blahhh\", "+ + "fl=\"a_s,a_i,a_f\", "+ + "sort=\"a_s asc\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"a_s asc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);- assert(tuples.size() == 0);-+ assert (tuples.size() == 0);}@Testpublic void testMultiCollection() throws Exception {- CollectionAdminRequest.createCollection("collection2", "conf", 2, 1).process(cluster.getSolrClient());+ CollectionAdminRequest.createCollection("collection2", "conf", 2, 1)+ .process(cluster.getSolrClient());cluster.waitForActiveCollection("collection2", 2, 2);new UpdateRequest()- .add(id, "0", "a_s", "hello", "a_i", "0", "a_f", "0", "s_multi", "aaaa", "test_dt", getDateString("2016", "5", "1"), "i_multi", "4", "i_multi", "7")- .add(id, "2", "a_s", "hello", "a_i", "2", "a_f", "0", "s_multi", "aaaa1", "test_dt", getDateString("2016", "5", "1"), "i_multi", "44", "i_multi", "77")- .add(id, "3", "a_s", "hello", "a_i", "3", "a_f", "3", "s_multi", "aaaa2", "test_dt", getDateString("2016", "5", "1"), "i_multi", "444", "i_multi", "777")- .add(id, "4", "a_s", "hello", "a_i", "4", "a_f", "4", "s_multi", "aaaa3", "test_dt", getDateString("2016", "5", "1"), "i_multi", "4444", "i_multi", "7777")- .add(id, "1", "a_s", "hello", "a_i", "1", "a_f", "1", "s_multi", "aaaa4", "test_dt", getDateString("2016", "5", "1"), "i_multi", "44444", "i_multi", "77777")+ .add(+ id,+ "0",+ "a_s",+ "hello",+ "a_i",+ "0",+ "a_f",+ "0",+ "s_multi",+ "aaaa",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "4",+ "i_multi",+ "7")+ .add(+ id,+ "2",+ "a_s",+ "hello",+ "a_i",+ "2",+ "a_f",+ "0",+ "s_multi",+ "aaaa1",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "44",+ "i_multi",+ "77")+ .add(+ id,+ "3",+ "a_s",+ "hello",+ "a_i",+ "3",+ "a_f",+ "3",+ "s_multi",+ "aaaa2",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "444",+ "i_multi",+ "777")+ .add(+ id,+ "4",+ "a_s",+ "hello",+ "a_i",+ "4",+ "a_f",+ "4",+ "s_multi",+ "aaaa3",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "4444",+ "i_multi",+ "7777")+ .add(+ id,+ "1",+ "a_s",+ "hello",+ "a_i",+ "1",+ "a_f",+ "1",+ "s_multi",+ "aaaa4",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "44444",+ "i_multi",+ "77777").commit(cluster.getSolrClient(), "collection1");new UpdateRequest()- .add(id, "10", "a_s", "hello", "a_i", "10", "a_f", "0", "s_multi", "aaaa", "test_dt", getDateString("2016", "5", "1"), "i_multi", "4", "i_multi", "7")- .add(id, "12", "a_s", "hello", "a_i", "12", "a_f", "0", "s_multi", "aaaa1", "test_dt", getDateString("2016", "5", "1"), "i_multi", "44", "i_multi", "77")- .add(id, "13", "a_s", "hello", "a_i", "13", "a_f", "3", "s_multi", "aaaa2", "test_dt", getDateString("2016", "5", "1"), "i_multi", "444", "i_multi", "777")- .add(id, "14", "a_s", "hello", "a_i", "14", "a_f", "4", "s_multi", "aaaa3", "test_dt", getDateString("2016", "5", "1"), "i_multi", "4444", "i_multi", "7777")- .add(id, "11", "a_s", "hello", "a_i", "11", "a_f", "1", "s_multi", "aaaa4", "test_dt", getDateString("2016", "5", "1"), "i_multi", "44444", "i_multi", "77777")+ .add(+ id,+ "10",+ "a_s",+ "hello",+ "a_i",+ "10",+ "a_f",+ "0",+ "s_multi",+ "aaaa",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "4",+ "i_multi",+ "7")+ .add(+ id,+ "12",+ "a_s",+ "hello",+ "a_i",+ "12",+ "a_f",+ "0",+ "s_multi",+ "aaaa1",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "44",+ "i_multi",+ "77")+ .add(+ id,+ "13",+ "a_s",+ "hello",+ "a_i",+ "13",+ "a_f",+ "3",+ "s_multi",+ "aaaa2",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "444",+ "i_multi",+ "777")+ .add(+ id,+ "14",+ "a_s",+ "hello",+ "a_i",+ "14",+ "a_f",+ "4",+ "s_multi",+ "aaaa3",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "4444",+ "i_multi",+ "7777")+ .add(+ id,+ "11",+ "a_s",+ "hello",+ "a_i",+ "11",+ "a_f",+ "1",+ "s_multi",+ "aaaa4",+ "test_dt",+ getDateString("2016", "5", "1"),+ "i_multi",+ "44444",+ "i_multi",+ "77777").commit(cluster.getSolrClient(), "collection2");-List<Tuple> tuples;StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- List<String> shardUrls = TupleStream.getShards(cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);+ List<String> shardUrls =+ TupleStream.getShards(+ cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);try {StringBuilder buf = new StringBuilder();@@ -1901,28 +2175,33 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams solrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");- solrParams.add("expr", "search(\"collection1, collection2\", q=\"*:*\", fl=\"id, a_i\", rows=50, sort=\"a_i asc\")");+ solrParams.add(+ "expr",+ "search(\"collection1, collection2\", q=\"*:*\", fl=\"id, a_i\", rows=50, sort=\"a_i asc\")");SolrStream solrStream = new SolrStream(shardUrls.get(0), solrParams);solrStream.setStreamContext(streamContext);tuples = getTuples(solrStream);assert (tuples.size() == 10);- assertOrder(tuples, 0, 1, 2, 3, 4,10,11,12,13,14);+ assertOrder(tuples, 0, 1, 2, 3, 4, 10, 11, 12, 13, 14);- //Test with export handler, different code path.+ // Test with export handler, different code path.solrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");- solrParams.add("expr", "search(\"collection1, collection2\", q=\"*:*\", fl=\"id, a_i\", sort=\"a_i asc\", qt=\"/export\")");+ solrParams.add(+ "expr",+ "search(\"collection1, collection2\", q=\"*:*\", fl=\"id, a_i\", sort=\"a_i asc\", qt=\"/export\")");solrStream = new SolrStream(shardUrls.get(0), solrParams);solrStream.setStreamContext(streamContext);tuples = getTuples(solrStream);assert (tuples.size() == 10);- assertOrder(tuples, 0, 1, 2, 3, 4,10,11,12,13,14);-+ assertOrder(tuples, 0, 1, 2, 3, 4, 10, 11, 12, 13, 14);solrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");- solrParams.add("expr", "facet(\"collection1, collection2\", q=\"*:*\", buckets=\"a_s\", bucketSorts=\"count(*) asc\", count(*))");+ solrParams.add(+ "expr",+ "facet(\"collection1, collection2\", q=\"*:*\", buckets=\"a_s\", bucketSorts=\"count(*) asc\", count(*))");solrStream = new SolrStream(shardUrls.get(0), solrParams);solrStream.setStreamContext(streamContext);tuples = getTuples(solrStream);@@ -1931,13 +2210,14 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuple.getString("a_s"), "hello");assertEquals(tuple.getLong("count(*)").longValue(), 10);- String expr = "timeseries(\"collection1, collection2\", q=\"*:*\", " +- "start=\"2016-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "format=\"yyyy\","+- "count(*))";+ String expr =+ "timeseries(\"collection1, collection2\", q=\"*:*\", "+ + "start=\"2016-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "format=\"yyyy\","+ + "count(*))";solrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");@@ -1950,23 +2230,23 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(tuple.getString("test_dt"), "2016");assertEquals(tuple.getLong("count(*)").longValue(), 10);- //Test parallel+ // Test parallelsolrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");- solrParams.add("expr", "parallel(collection1, sort=\"a_i asc\", workers=2, search(\"collection1, collection2\", q=\"*:*\", fl=\"id, a_i\", sort=\"a_i asc\", qt=\"/export\", partitionKeys=\"a_s\"))");+ solrParams.add(+ "expr",+ "parallel(collection1, sort=\"a_i asc\", workers=2, search(\"collection1, collection2\", q=\"*:*\", fl=\"id, a_i\", sort=\"a_i asc\", qt=\"/export\", partitionKeys=\"a_s\"))");solrStream = new SolrStream(shardUrls.get(0), solrParams);solrStream.setStreamContext(streamContext);tuples = getTuples(solrStream);assert (tuples.size() == 10);- assertOrder(tuples, 0, 1, 2, 3, 4,10,11,12,13,14);+ assertOrder(tuples, 0, 1, 2, 3, 4, 10, 11, 12, 13, 14);} finally {CollectionAdminRequest.deleteCollection("collection2").process(cluster.getSolrClient());solrClientCache.close();}--}@Test@@ -1989,31 +2269,33 @@ public class StreamExpressionTest extends SolrCloudTestCase {TupleStream stream;List<Tuple> tuples;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("facet", FacetStream.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("count", CountMetric.class)- .withFunctionName("std", StdMetric.class)- .withFunctionName("per", PercentileMetric.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("facet", FacetStream.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("count", CountMetric.class)+ .withFunctionName("std", StdMetric.class)+ .withFunctionName("per", PercentileMetric.class);// Basic test- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"level1_s, level2_s\", "- + "bucketSorts=\"sum(a_i) desc, sum(a_i) desc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), count(*)"- + ")";+ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"level1_s, level2_s\", "+ + "bucketSorts=\"sum(a_i) desc, sum(a_i) desc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), count(*)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);- assert(tuples.size() == 6);+ assert (tuples.size() == 6);Tuple tuple = tuples.get(0);String bucket1 = tuple.getString("level1_s");@@ -2081,19 +2363,20 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(sumi.longValue() == 2);assertTrue(count.doubleValue() == 2);- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"level1_s, level2_s\", "- + "bucketSorts=\"level1_s desc, level2_s desc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), count(*)"- + ")";+ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"level1_s, level2_s\", "+ + "bucketSorts=\"level1_s desc, level2_s desc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), count(*)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);- assert(tuples.size() == 6);+ assert (tuples.size() == 6);tuple = tuples.get(0);bucket1 = tuple.getString("level1_s");@@ -2161,21 +2444,22 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(sumi.longValue() == 2);assertTrue(count.doubleValue() == 2);- //Add sorts for percentile+ // Add sorts for percentile- clause = "facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"level1_s, level2_s\", "- + "bucketSorts=\"per(a_i, 50) desc, std(a_i) desc\", "- + "bucketSizeLimit=100, "- + "std(a_i), per(a_i,50)"- + ")";+ clause =+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"level1_s, level2_s\", "+ + "bucketSorts=\"per(a_i, 50) desc, std(a_i) desc\", "+ + "bucketSizeLimit=100, "+ + "std(a_i), per(a_i,50)"+ + ")";stream = factory.constructStream(clause);tuples = getTuples(stream);- assert(tuples.size() == 6);+ assert (tuples.size() == 6);tuple = tuples.get(0);bucket1 = tuple.getString("level1_s");@@ -2185,7 +2469,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(bucket1.equals("hello3"));assertTrue(bucket2.equals("b"));- assertTrue(stdi == 1.5275252316519468D);+ assertTrue(stdi == 1.5275252316519468D);assertTrue(peri == 12.0D);tuple = tuples.get(1);@@ -2196,7 +2480,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(bucket1.equals("hello4"));assertTrue(bucket2.equals("b"));- assertTrue(stdi == 0.0D);+ assertTrue(stdi == 0.0D);assertTrue(peri == 11.0);tuple = tuples.get(2);@@ -2207,7 +2491,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(bucket1.equals("hello0"));assertTrue(bucket2.equals("b"));- assertTrue(stdi == 9.192388155425117D);+ assertTrue(stdi == 9.192388155425117D);assertTrue(peri == 7.5D);tuple = tuples.get(3);@@ -2218,7 +2502,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(bucket1.equals("hello4"));assertTrue(bucket2.equals("a"));- assertTrue(stdi == 0.0D);+ assertTrue(stdi == 0.0D);assertTrue(peri == 4.0D);tuple = tuples.get(4);@@ -2229,7 +2513,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(bucket1.equals("hello3"));assertTrue(bucket2.equals("a"));- assertTrue(stdi == 0.0D);+ assertTrue(stdi == 0.0D);assertTrue(peri == 3.0D);tuple = tuples.get(5);@@ -2240,9 +2524,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(bucket1.equals("hello0"));assertTrue(bucket2.equals("a"));- assertTrue(stdi == 1.4142135623730951D);+ assertTrue(stdi == 1.4142135623730951D);assertTrue(peri == 1.0D);-}@Test@@ -2262,11 +2545,12 @@ public class StreamExpressionTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("topic", TopicStream.class)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("daemon", DaemonStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("topic", TopicStream.class)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("daemon", DaemonStream.class);StreamExpression expression;TupleStream stream;@@ -2275,8 +2559,10 @@ public class StreamExpressionTest extends SolrCloudTestCase {SolrClientCache cache = new SolrClientCache();try {- //Store checkpoints in the same index as the main documents. This perfectly valid- expression = StreamExpressionParser.parse("topic(collection1, collection1, q=\"a_s:hello\", fl=\"id\", id=\"1000000\", checkpointEvery=3)");+ // Store checkpoints in the same index as the main documents. This perfectly valid+ expression =+ StreamExpressionParser.parse(+ "topic(collection1, collection1, q=\"a_s:hello\", fl=\"id\", id=\"1000000\", checkpointEvery=3)");stream = factory.constructStream(expression);StreamContext context = new StreamContext();@@ -2284,30 +2570,34 @@ public class StreamExpressionTest extends SolrCloudTestCase {stream.setStreamContext(context);tuples = getTuples(stream);- //Should be zero because the checkpoints will be set to the highest vesion on the shards.+ // Should be zero because the checkpoints will be set to the highest vesion on the shards.assertEquals(tuples.size(), 0);cluster.getSolrClient().commit("collection1");- //Now check to see if the checkpoints are present-- expression = StreamExpressionParser.parse("search(collection1, q=\"id:1000000\", fl=\"id, checkpoint_ss, _version_\", sort=\"id asc\")");- stream = factory.constructStream(expression);- context = new StreamContext();- context.setSolrClientCache(cache);- stream.setStreamContext(context);- tuples = getTuples(stream);- assertEquals(tuples.size(), 1);- List<String> checkpoints = tuples.get(0).getStrings("checkpoint_ss");- assertEquals(checkpoints.size(), 2);- Long version1 = tuples.get(0).getLong("_version_");-- //Index a few more documents+ // Now check to see if the checkpoints are present++ expression =+ StreamExpressionParser.parse(+ "search(collection1, q=\"id:1000000\", fl=\"id, checkpoint_ss, _version_\", sort=\"id asc\")");+ stream = factory.constructStream(expression);+ context = new StreamContext();+ context.setSolrClientCache(cache);+ stream.setStreamContext(context);+ tuples = getTuples(stream);+ assertEquals(tuples.size(), 1);+ List<String> checkpoints = tuples.get(0).getStrings("checkpoint_ss");+ assertEquals(checkpoints.size(), 2);+ Long version1 = tuples.get(0).getLong("_version_");++ // Index a few more documentsnew UpdateRequest().add(id, "10", "a_s", "hello", "a_i", "13", "a_f", "9").add(id, "11", "a_s", "hello", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- expression = StreamExpressionParser.parse("topic(collection1, collection1, fl=\"id\", q=\"a_s:hello\", id=\"1000000\", checkpointEvery=2)");+ expression =+ StreamExpressionParser.parse(+ "topic(collection1, collection1, fl=\"id\", q=\"a_s:hello\", id=\"1000000\", checkpointEvery=2)");stream = factory.constructStream(expression);context = new StreamContext();@@ -2320,37 +2610,41 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals((long) tuple1.getLong("id"), 10l);cluster.getSolrClient().commit("collection1");- // Checkpoint should not have changed.- expression = StreamExpressionParser.parse("search(collection1, q=\"id:1000000\", fl=\"id, checkpoint_ss, _version_\", sort=\"id asc\")");- TupleStream cstream = factory.constructStream(expression);- context = new StreamContext();- context.setSolrClientCache(cache);- cstream.setStreamContext(context);- tuples = getTuples(cstream);+ // Checkpoint should not have changed.+ expression =+ StreamExpressionParser.parse(+ "search(collection1, q=\"id:1000000\", fl=\"id, checkpoint_ss, _version_\", sort=\"id asc\")");+ TupleStream cstream = factory.constructStream(expression);+ context = new StreamContext();+ context.setSolrClientCache(cache);+ cstream.setStreamContext(context);+ tuples = getTuples(cstream);- assertEquals(tuples.size(), 1);- checkpoints = tuples.get(0).getStrings("checkpoint_ss");- assertEquals(checkpoints.size(), 2);- Long version2 = tuples.get(0).getLong("_version_");- assertEquals(version1, version2);+ assertEquals(tuples.size(), 1);+ checkpoints = tuples.get(0).getStrings("checkpoint_ss");+ assertEquals(checkpoints.size(), 2);+ Long version2 = tuples.get(0).getLong("_version_");+ assertEquals(version1, version2);Tuple tuple2 = stream.read();cluster.getSolrClient().commit("collection1");assertEquals((long) tuple2.getLong("id"), 11l);- //Checkpoint should have changed.- expression = StreamExpressionParser.parse("search(collection1, q=\"id:1000000\", fl=\"id, checkpoint_ss, _version_\", sort=\"id asc\")");- cstream = factory.constructStream(expression);- context = new StreamContext();- context.setSolrClientCache(cache);- cstream.setStreamContext(context);- tuples = getTuples(cstream);+ // Checkpoint should have changed.+ expression =+ StreamExpressionParser.parse(+ "search(collection1, q=\"id:1000000\", fl=\"id, checkpoint_ss, _version_\", sort=\"id asc\")");+ cstream = factory.constructStream(expression);+ context = new StreamContext();+ context.setSolrClientCache(cache);+ cstream.setStreamContext(context);+ tuples = getTuples(cstream);- assertEquals(tuples.size(), 1);- checkpoints = tuples.get(0).getStrings("checkpoint_ss");- assertEquals(checkpoints.size(), 2);- Long version3 = tuples.get(0).getLong("_version_");- assertTrue(version3 > version2);+ assertEquals(tuples.size(), 1);+ checkpoints = tuples.get(0).getStrings("checkpoint_ss");+ assertEquals(checkpoints.size(), 2);+ Long version3 = tuples.get(0).getLong("_version_");+ assertTrue(version3 > version2);Tuple tuple3 = stream.read();assertTrue(tuple3.EOF);@@ -2358,23 +2652,25 @@ public class StreamExpressionTest extends SolrCloudTestCase {stream.close();}- //Test with the DaemonStream+ // Test with the DaemonStreamDaemonStream dstream = null;try {- expression = StreamExpressionParser.parse("daemon(topic(collection1, collection1, fl=\"id\", q=\"a_s:hello\", id=\"1000000\", checkpointEvery=2), id=\"test\", runInterval=\"1000\", queueSize=\"9\")");+ expression =+ StreamExpressionParser.parse(+ "daemon(topic(collection1, collection1, fl=\"id\", q=\"a_s:hello\", id=\"1000000\", checkpointEvery=2), id=\"test\", runInterval=\"1000\", queueSize=\"9\")");dstream = (DaemonStream) factory.constructStream(expression);context = new StreamContext();context.setSolrClientCache(cache);dstream.setStreamContext(context);- //Index a few more documents+ // Index a few more documentsnew UpdateRequest().add(id, "12", "a_s", "hello", "a_i", "13", "a_f", "9").add(id, "13", "a_s", "hello", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- //Start reading from the DaemonStream+ // Start reading from the DaemonStreamTuple tuple = null;dstream.open();@@ -2382,19 +2678,21 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertEquals(12, (long) tuple.getLong(id));tuple = dstream.read();assertEquals(13, (long) tuple.getLong(id));- cluster.getSolrClient().commit("collection1"); // We want to see if the version has been updated after reading two tuples+ // We want to see if the version has been updated after reading two tuples+ cluster.getSolrClient().commit("collection1");- //Index a few more documents+ // Index a few more documentsnew UpdateRequest().add(id, "14", "a_s", "hello", "a_i", "13", "a_f", "9").add(id, "15", "a_s", "hello", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- //Read from the same DaemonStream stream+ // Read from the same DaemonStream streamtuple = dstream.read();assertEquals(14, (long) tuple.getLong(id));- tuple = dstream.read(); // This should trigger a checkpoint as it's the 4th read from the stream.+ // This should trigger a checkpoint as it's the 4th read from the stream.+ tuple = dstream.read();assertEquals(15, (long) tuple.getLong(id));dstream.shutdown();@@ -2408,9 +2706,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {}}-@Test- // commented 4-Sep-2018 @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 2-Aug-2018public void testParallelTopicStream() throws Exception {Assume.assumeTrue(!useAlias);@@ -2428,12 +2724,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {.add(id, "9", "a_s", "hello", "a_i", "14", "a_f", "10", "subject", "ha ha bla blah10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withFunctionName("topic", TopicStream.class)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("parallel", ParallelStream.class)- .withFunctionName("daemon", DaemonStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withFunctionName("topic", TopicStream.class)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("parallel", ParallelStream.class)+ .withFunctionName("daemon", DaemonStream.class);StreamExpression expression;TupleStream stream;@@ -2442,16 +2739,18 @@ public class StreamExpressionTest extends SolrCloudTestCase {SolrClientCache cache = new SolrClientCache();try {- //Store checkpoints in the same index as the main documents. This is perfectly valid- expression = StreamExpressionParser.parse("parallel(collection1, " +- "workers=\"2\", " +- "sort=\"_version_ asc\"," +- "topic(collection1, " +- "collection1, " +- "q=\"a_s:hello\", " +- "fl=\"id\", " +- "id=\"1000000\", " +- "partitionKeys=\"id\"))");+ // Store checkpoints in the same index as the main documents. This is perfectly valid+ expression =+ StreamExpressionParser.parse(+ "parallel(collection1, "+ + "workers=\"2\", "+ + "sort=\"_version_ asc\","+ + "topic(collection1, "+ + "collection1, "+ + "q=\"a_s:hello\", "+ + "fl=\"id\", "+ + "id=\"1000000\", "+ + "partitionKeys=\"id\"))");stream = factory.constructStream(expression);StreamContext context = new StreamContext();@@ -2459,13 +2758,15 @@ public class StreamExpressionTest extends SolrCloudTestCase {stream.setStreamContext(context);tuples = getTuples(stream);- //Should be zero because the checkpoints will be set to the highest version on the shards.+ // Should be zero because the checkpoints will be set to the highest version on the shards.assertEquals(tuples.size(), 0);cluster.getSolrClient().commit("collection1");- //Now check to see if the checkpoints are present+ // Now check to see if the checkpoints are present- expression = StreamExpressionParser.parse("search(collection1, q=\"id:1000000*\", fl=\"id, checkpoint_ss, _version_\", sort=\"id asc\")");+ expression =+ StreamExpressionParser.parse(+ "search(collection1, q=\"id:1000000*\", fl=\"id, checkpoint_ss, _version_\", sort=\"id asc\")");stream = factory.constructStream(expression);context = new StreamContext();@@ -2480,21 +2781,23 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(id1.equals("1000000_0"));assertTrue(id2.equals("1000000_1"));- //Index a few more documents+ // Index a few more documentsnew UpdateRequest().add(id, "10", "a_s", "hello", "a_i", "13", "a_f", "9").add(id, "11", "a_s", "hello", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- expression = StreamExpressionParser.parse("parallel(collection1, " +- "workers=\"2\", " +- "sort=\"_version_ asc\"," +- "topic(collection1, " +- "collection1, " +- "q=\"a_s:hello\", " +- "fl=\"id\", " +- "id=\"1000000\", " +- "partitionKeys=\"id\"))");+ expression =+ StreamExpressionParser.parse(+ "parallel(collection1, "+ + "workers=\"2\", "+ + "sort=\"_version_ asc\","+ + "topic(collection1, "+ + "collection1, "+ + "q=\"a_s:hello\", "+ + "fl=\"id\", "+ + "id=\"1000000\", "+ + "partitionKeys=\"id\"))");stream = factory.constructStream(expression);context = new StreamContext();@@ -2503,18 +2806,20 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTopicRun(stream, "10", "11");- //Test will initial checkpoint. This should pull all-- expression = StreamExpressionParser.parse("parallel(collection1, " +- "workers=\"2\", " +- "sort=\"_version_ asc\"," +- "topic(collection1, " +- "collection1, " +- "q=\"a_s:hello\", " +- "fl=\"id\", " +- "id=\"2000000\", " +- "initialCheckpoint=\"0\", " +- "partitionKeys=\"id\"))");+ // Test will initial checkpoint. This should pull all++ expression =+ StreamExpressionParser.parse(+ "parallel(collection1, "+ + "workers=\"2\", "+ + "sort=\"_version_ asc\","+ + "topic(collection1, "+ + "collection1, "+ + "q=\"a_s:hello\", "+ + "fl=\"id\", "+ + "id=\"2000000\", "+ + "initialCheckpoint=\"0\", "+ + "partitionKeys=\"id\"))");stream = factory.constructStream(expression);context = new StreamContext();@@ -2522,40 +2827,44 @@ public class StreamExpressionTest extends SolrCloudTestCase {stream.setStreamContext(context);assertTopicRun(stream, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");- //Add more documents- //Index a few more documents+ // Add more documents+ // Index a few more documentsnew UpdateRequest().add(id, "12", "a_s", "hello", "a_i", "13", "a_f", "9").add(id, "13", "a_s", "hello", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);- //Run the same topic again including the initialCheckpoint. It should start where it left off.- //initialCheckpoint should be ignored for all but the first run.+ // Run the same topic again including the initialCheckpoint. It should start where it left+ // off. initialCheckpoint should be ignored for all but the first run.stream = factory.constructStream(expression);context = new StreamContext();context.setSolrClientCache(cache);stream.setStreamContext(context);assertTopicRun(stream, "12", "13");- //Test text extraction-- expression = StreamExpressionParser.parse("parallel(collection1, " +- "workers=\"2\", " +- "sort=\"_version_ asc\"," +- "topic(collection1, " +- "collection1, " +- "q=\"subject:bla\", " +- "fl=\"subject\", " +- "id=\"3000000\", " +- "initialCheckpoint=\"0\", " +- "partitionKeys=\"id\"))");+ // Test text extraction++ expression =+ StreamExpressionParser.parse(+ "parallel(collection1, "+ + "workers=\"2\", "+ + "sort=\"_version_ asc\","+ + "topic(collection1, "+ + "collection1, "+ + "q=\"subject:bla\", "+ + "fl=\"subject\", "+ + "id=\"3000000\", "+ + "initialCheckpoint=\"0\", "+ + "partitionKeys=\"id\"))");stream = factory.constructStream(expression);context = new StreamContext();context.setSolrClientCache(cache);stream.setStreamContext(context);- assertTopicSubject(stream, "ha ha bla blah0",+ assertTopicSubject(+ stream,+ "ha ha bla blah0","ha ha bla blah1","ha ha bla blah2","ha ha bla blah3",@@ -2572,10 +2881,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {}}----@Testpublic void testEchoStream() throws Exception {String expr = "echo(hello world)";@@ -2583,14 +2888,15 @@ public class StreamExpressionTest extends SolrCloudTestCase {paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- String s = (String)tuples.get(0).get("echo");+ String s = (String) tuples.get(0).get("echo");assertTrue(s.equals("hello world"));expr = "echo(\"hello world\")";@@ -2603,7 +2909,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- s = (String)tuples.get(0).get("echo");+ s = (String) tuples.get(0).get("echo");assertTrue(s.equals("hello world"));expr = "echo(\"hello, world\")";@@ -2616,7 +2922,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- s = (String)tuples.get(0).get("echo");+ s = (String) tuples.get(0).get("echo");assertTrue(s.equals("hello, world"));expr = "echo(\"hello, \\\"t\\\" world\")";@@ -2629,11 +2935,14 @@ public class StreamExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- s = (String)tuples.get(0).get("echo");+ s = (String) tuples.get(0).get("echo");assertTrue(s.equals("hello, \"t\" world"));- expr = "parallel("+COLLECTIONORALIAS+", workers=2, sort=\"echo asc\", echo(\"hello, \\\"t\\\" world\"))";+ expr =+ "parallel("+ + COLLECTIONORALIAS+ + ", workers=2, sort=\"echo asc\", echo(\"hello, \\\"t\\\" world\"))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -2643,13 +2952,14 @@ public class StreamExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 2);- s = (String)tuples.get(0).get("echo");+ s = (String) tuples.get(0).get("echo");assertTrue(s.equals("hello, \"t\" world"));- s = (String)tuples.get(1).get("echo");+ s = (String) tuples.get(1).get("echo");assertTrue(s.equals("hello, \"t\" world"));- expr = "echo(\"tuytuy iuyiuyi iuyiuyiu iuyiuyiuyiu iuyi iuyiyiuy iuyiuyiu iyiuyiu iyiuyiuyyiyiu yiuyiuyi" +- " yiuyiuyi yiuyiuuyiu yiyiuyiyiu iyiuyiuyiuiuyiu yiuyiuyi yiuyiy yiuiyiuiuy\")";+ expr =+ "echo(\"tuytuy iuyiuyi iuyiuyiu iuyiuyiuyiu iuyi iuyiyiuy iuyiuyiu iyiuyiu iyiuyiuyyiyiu yiuyiuyi"+ + " yiuyiuyi yiuyiuuyiu yiyiuyiyiu iyiuyiuyiuiuyiu yiuyiuyi yiuyiy yiuiyiuiuy\")";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -2659,10 +2969,12 @@ public class StreamExpressionTest extends SolrCloudTestCase {solrStream.setStreamContext(context);tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- s = (String)tuples.get(0).get("echo");+ s = (String) tuples.get(0).get("echo");- assertTrue(s.equals("tuytuy iuyiuyi iuyiuyiu iuyiuyiuyiu iuyi iuyiyiuy iuyiuyiu iyiuyiu iyiuyiuyyiyiu yiuyiuyi yiuyiuyi " +- "yiuyiuuyiu yiyiuyiyiu iyiuyiuyiuiuyiu yiuyiuyi yiuyiy yiuiyiuiuy"));+ assertTrue(+ s.equals(+ "tuytuy iuyiuyi iuyiuyiu iuyiuyiuyiu iuyi iuyiyiuy iuyiuyiu iyiuyiu iyiuyiuyyiyiu yiuyiuyi yiuyiuyi "+ + "yiuyiuuyiu yiyiuyiyiu iyiuyiuyiuiuyiu yiuyiuyi yiuyiy yiuiyiuiuy"));}@Test@@ -2671,39 +2983,44 @@ public class StreamExpressionTest extends SolrCloudTestCase {updateRequest.add(id, "hello", "test_t", "l b c d c");updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "eval(select(echo(\"search("+COLLECTIONORALIAS+", q=\\\"*:*\\\", fl=id, sort=\\\"id desc\\\")\"), echo as expr_s))";+ String expr =+ "eval(select(echo(\"search("+ + COLLECTIONORALIAS+ + ", q=\\\"*:*\\\", fl=id, sort=\\\"id desc\\\")\"), echo as expr_s))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);- String s = (String)tuples.get(0).get("id");+ String s = (String) tuples.get(0).get("id");assertTrue(s.equals("hello"));}private String getDateString(String year, String month, String day) {- return year+"-"+month+"-"+day+"T00:00:00Z";+ return year + "-" + month + "-" + day + "T00:00:00Z";}private String getSplit(int seed, int index) {String[] splits = {"one", "two", "three"};- int splitIndex = ((Integer.toString(index)+Integer.toString(seed)).hashCode()*index) % splits.length;+ int splitIndex =+ ((Integer.toString(index) + Integer.toString(seed)).hashCode() * index) % splits.length;return splits[Math.abs(splitIndex)];}private void incrementSplit(Map<String, Integer> map, String year, String split) {- String key = year+"_"+split;+ String key = year + "_" + split;Integer count = map.get(key);- if(count == null) {+ if (count == null) {map.put(key, 1);} else {- map.put(key,++count);+ map.put(key, ++count);}}@@ -2713,39 +3030,75 @@ public class StreamExpressionTest extends SolrCloudTestCase {Map<String, Integer> counts = new HashMap<>();- int i=0;- while(i<50) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00", "split_s", getSplit(7723423, i));- incrementSplit(counts,"2016", getSplit(7723423, i));+ int i = 0;+ while (i < 50) {+ updateRequest.add(+ id,+ "id_" + (++i),+ "test_dt",+ getDateString("2016", "5", "1"),+ "price_f",+ "400.00",+ "split_s",+ getSplit(7723423, i));+ incrementSplit(counts, "2016", getSplit(7723423, i));}- while(i<100) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2015", "5", "1"), "price_f", "300.0", "split_s", getSplit(123274234, i));- incrementSplit(counts,"2015", getSplit(123274234, i));+ while (i < 100) {+ updateRequest.add(+ id,+ "id_" + (++i),+ "test_dt",+ getDateString("2015", "5", "1"),+ "price_f",+ "300.0",+ "split_s",+ getSplit(123274234, i));+ incrementSplit(counts, "2015", getSplit(123274234, i));}- while(i<150) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2014", "5", "1"), "price_f", "500.0", "split_s", getSplit(1242317, i));- incrementSplit(counts,"2014", getSplit(1242317, i));+ while (i < 150) {+ updateRequest.add(+ id,+ "id_" + (++i),+ "test_dt",+ getDateString("2014", "5", "1"),+ "price_f",+ "500.0",+ "split_s",+ getSplit(1242317, i));+ incrementSplit(counts, "2014", getSplit(1242317, i));}- while(i<250) {- updateRequest.add(id, "id_"+(++i),"test_dt", getDateString("2013", "5", "1"), "price_f", "100.00", "split_s", getSplit(1234233887, i));- incrementSplit(counts,"2013", getSplit(1234233887, i));+ while (i < 250) {+ updateRequest.add(+ id,+ "id_" + (++i),+ "test_dt",+ getDateString("2013", "5", "1"),+ "price_f",+ "100.00",+ "split_s",+ getSplit(1234233887, i));+ incrementSplit(counts, "2013", getSplit(1234233887, i));}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2017-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50), countDist(id))";+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2017-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50), countDist(id))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -2764,7 +3117,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(0).getDouble("per(price_f,50)").equals(100D));assertTrue(tuples.get(0).getLong("countDist(id)").equals(100L));-assertTrue(tuples.get(1).get("test_dt").equals("2014-01-01T01:00:00Z"));assertTrue(tuples.get(1).getLong("count(*)").equals(50L));assertTrue(tuples.get(1).getDouble("sum(price_f)").equals(25000D));@@ -2775,7 +3127,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(1).getDouble("per(price_f,50)").equals(500D));assertTrue(tuples.get(1).getLong("countDist(id)").equals(50L));-assertTrue(tuples.get(2).get("test_dt").equals("2015-01-01T01:00:00Z"));assertTrue(tuples.get(2).getLong("count(*)").equals(50L));assertTrue(tuples.get(2).getDouble("sum(price_f)").equals(15000D));@@ -2786,7 +3137,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(2).getDouble("per(price_f,50)").equals(300D));assertTrue(tuples.get(2).getLong("countDist(id)").equals(50L));-assertTrue(tuples.get(3).get("test_dt").equals("2016-01-01T01:00:00Z"));assertTrue(tuples.get(3).getLong("count(*)").equals(50L));assertTrue(tuples.get(3).getDouble("sum(price_f)").equals(20000D));@@ -2797,23 +3147,25 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(3).getDouble("per(price_f,50)").equals(400D));assertTrue(tuples.get(3).getLong("countDist(id)").equals(50L));-assertTrue(tuples.get(4).get("test_dt").equals("2017-01-01T01:00:00Z"));- assertEquals((long)tuples.get(4).getLong("count(*)"), 0L);+ assertEquals((long) tuples.get(4).getLong("count(*)"), 0L);assertEquals(tuples.get(4).getDouble("sum(price_f)"), 0D, 0);- assertEquals(tuples.get(4).getDouble("max(price_f)"),0D, 0);+ assertEquals(tuples.get(4).getDouble("max(price_f)"), 0D, 0);assertEquals(tuples.get(4).getDouble("min(price_f)"), 0D, 0);assertTrue(tuples.get(4).getDouble("avg(price_f)").equals(0D));assertTrue(tuples.get(4).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(4).getDouble("per(price_f,50)").equals(0D));assertTrue(tuples.get(4).getLong("countDist(id)").equals(0L));- expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "format=\"yyyy\", " +- "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";+ expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "format=\"yyyy\", "+ + "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -2842,7 +3194,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(1).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(1).getDouble("per(price_f,50)").equals(500D));-assertTrue(tuples.get(2).get("test_dt").equals("2015"));assertTrue(tuples.get(2).getLong("count(*)").equals(50L));assertTrue(tuples.get(2).getDouble("sum(price_f)").equals(15000D));@@ -2861,13 +3212,15 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(3).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(3).getDouble("per(price_f,50)").equals(400D));-- expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "format=\"yyyy-MM\", " +- "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";+ expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "format=\"yyyy-MM\", "+ + "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -2914,13 +3267,15 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(3).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(3).getDouble("per(price_f,50)").equals(400D));-- expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2012-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "format=\"yyyy-MM\", " +- "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";+ expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2012-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "format=\"yyyy-MM\", "+ + "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -2975,14 +3330,16 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(4).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(4).getDouble("per(price_f,50)").equals(400D));-- expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2012-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "split=\"split_s\", " +- "format=\"yyyy\", " +- "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";+ expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2012-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "split=\"split_s\", "+ + "format=\"yyyy\", "+ + "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -2994,28 +3351,27 @@ public class StreamExpressionTest extends SolrCloudTestCase {String year = tuples.get(0).getString("test_dt");String split = tuples.get(0).getString("split_s");- long splitCount = counts.get(year+"_"+split);+ long splitCount = counts.get(year + "_" + split);assertEquals(tuples.size(), 12);assertTrue(tuples.get(0).get("test_dt").equals("2013"));assertTrue(tuples.get(0).get("split_s").equals("three"));assertTrue(tuples.get(0).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(0).getDouble("sum(price_f)").equals(splitCount*100D));+ assertTrue(tuples.get(0).getDouble("sum(price_f)").equals(splitCount * 100D));assertTrue(tuples.get(0).getDouble("max(price_f)").equals(100D));assertTrue(tuples.get(0).getDouble("min(price_f)").equals(100D));assertTrue(tuples.get(0).getDouble("avg(price_f)").equals(100D));assertTrue(tuples.get(0).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(0).getDouble("per(price_f,50)").equals(100D));-year = tuples.get(1).getString("test_dt");split = tuples.get(1).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(1).get("test_dt").equals("2013"));assertTrue(tuples.get(1).get("split_s").equals("two"));assertTrue(tuples.get(1).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(1).getDouble("sum(price_f)").equals(splitCount*100D));+ assertTrue(tuples.get(1).getDouble("sum(price_f)").equals(splitCount * 100D));assertTrue(tuples.get(1).getDouble("max(price_f)").equals(100D));assertTrue(tuples.get(1).getDouble("min(price_f)").equals(100D));assertTrue(tuples.get(1).getDouble("avg(price_f)").equals(100D));@@ -3024,11 +3380,11 @@ public class StreamExpressionTest extends SolrCloudTestCase {year = tuples.get(2).getString("test_dt");split = tuples.get(2).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(2).get("test_dt").equals("2013"));assertTrue(tuples.get(2).get("split_s").equals("one"));assertTrue(tuples.get(2).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(2).getDouble("sum(price_f)").equals(splitCount*100D));+ assertTrue(tuples.get(2).getDouble("sum(price_f)").equals(splitCount * 100D));assertTrue(tuples.get(2).getDouble("max(price_f)").equals(100D));assertTrue(tuples.get(2).getDouble("min(price_f)").equals(100D));assertTrue(tuples.get(2).getDouble("avg(price_f)").equals(100D));@@ -3037,25 +3393,24 @@ public class StreamExpressionTest extends SolrCloudTestCase {year = tuples.get(3).getString("test_dt");split = tuples.get(3).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(3).get("test_dt").equals("2014"));assertTrue(tuples.get(3).get("split_s").equals("two"));assertTrue(tuples.get(3).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(3).getDouble("sum(price_f)").equals(splitCount*500D));+ assertTrue(tuples.get(3).getDouble("sum(price_f)").equals(splitCount * 500D));assertTrue(tuples.get(3).getDouble("max(price_f)").equals(500D));assertTrue(tuples.get(3).getDouble("min(price_f)").equals(500D));assertTrue(tuples.get(3).getDouble("avg(price_f)").equals(500D));assertTrue(tuples.get(3).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(3).getDouble("per(price_f,50)").equals(500D));-year = tuples.get(4).getString("test_dt");split = tuples.get(4).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(4).get("test_dt").equals("2014"));- assertTrue(tuples.get(4).get("split_s").equals("three") );+ assertTrue(tuples.get(4).get("split_s").equals("three"));assertTrue(tuples.get(4).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(4).getDouble("sum(price_f)").equals(splitCount*500D));+ assertTrue(tuples.get(4).getDouble("sum(price_f)").equals(splitCount * 500D));assertTrue(tuples.get(4).getDouble("max(price_f)").equals(500D));assertTrue(tuples.get(4).getDouble("min(price_f)").equals(500D));assertTrue(tuples.get(4).getDouble("avg(price_f)").equals(500D));@@ -3064,25 +3419,24 @@ public class StreamExpressionTest extends SolrCloudTestCase {year = tuples.get(5).getString("test_dt");split = tuples.get(5).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(5).get("test_dt").equals("2014"));assertTrue(tuples.get(5).get("split_s").equals("one"));assertTrue(tuples.get(5).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(5).getDouble("sum(price_f)").equals(splitCount*500D));+ assertTrue(tuples.get(5).getDouble("sum(price_f)").equals(splitCount * 500D));assertTrue(tuples.get(5).getDouble("max(price_f)").equals(500D));assertTrue(tuples.get(5).getDouble("min(price_f)").equals(500D));assertTrue(tuples.get(5).getDouble("avg(price_f)").equals(500D));assertTrue(tuples.get(5).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(5).getDouble("per(price_f,50)").equals(500D));-year = tuples.get(6).getString("test_dt");split = tuples.get(6).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(6).get("test_dt").equals("2015"));assertTrue(tuples.get(6).get("split_s").equals("three"));assertTrue(tuples.get(6).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(6).getDouble("sum(price_f)").equals(splitCount*300D));+ assertTrue(tuples.get(6).getDouble("sum(price_f)").equals(splitCount * 300D));assertTrue(tuples.get(6).getDouble("max(price_f)").equals(300D));assertTrue(tuples.get(6).getDouble("min(price_f)").equals(300D));assertTrue(tuples.get(6).getDouble("avg(price_f)").equals(300D));@@ -3091,39 +3445,37 @@ public class StreamExpressionTest extends SolrCloudTestCase {year = tuples.get(7).getString("test_dt");split = tuples.get(7).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(7).get("test_dt").equals("2015"));assertTrue(tuples.get(7).get("split_s").equals("two"));assertTrue(tuples.get(7).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(7).getDouble("sum(price_f)").equals(splitCount*300D));+ assertTrue(tuples.get(7).getDouble("sum(price_f)").equals(splitCount * 300D));assertTrue(tuples.get(7).getDouble("max(price_f)").equals(300D));assertTrue(tuples.get(7).getDouble("min(price_f)").equals(300D));assertTrue(tuples.get(7).getDouble("avg(price_f)").equals(300D));assertTrue(tuples.get(7).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(7).getDouble("per(price_f,50)").equals(300D));-year = tuples.get(8).getString("test_dt");split = tuples.get(8).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(8).get("test_dt").equals("2015"));assertTrue(tuples.get(8).get("split_s").equals("one"));assertTrue(tuples.get(8).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(8).getDouble("sum(price_f)").equals(splitCount*300D));+ assertTrue(tuples.get(8).getDouble("sum(price_f)").equals(splitCount * 300D));assertTrue(tuples.get(8).getDouble("max(price_f)").equals(300D));assertTrue(tuples.get(8).getDouble("min(price_f)").equals(300D));assertTrue(tuples.get(8).getDouble("avg(price_f)").equals(300D));assertTrue(tuples.get(8).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(8).getDouble("per(price_f,50)").equals(300D));-year = tuples.get(9).getString("test_dt");split = tuples.get(9).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(9).get("test_dt").equals("2016"));assertTrue(tuples.get(9).get("split_s").equals("two"));assertTrue(tuples.get(9).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(9).getDouble("sum(price_f)").equals(splitCount*400D));+ assertTrue(tuples.get(9).getDouble("sum(price_f)").equals(splitCount * 400D));assertTrue(tuples.get(9).getDouble("max(price_f)").equals(400D));assertTrue(tuples.get(9).getDouble("min(price_f)").equals(400D));assertTrue(tuples.get(9).getDouble("avg(price_f)").equals(400D));@@ -3132,11 +3484,11 @@ public class StreamExpressionTest extends SolrCloudTestCase {year = tuples.get(10).getString("test_dt");split = tuples.get(10).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(10).get("test_dt").equals("2016"));assertTrue(tuples.get(10).get("split_s").equals("one"));assertTrue(tuples.get(10).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(10).getDouble("sum(price_f)").equals(splitCount*400D));+ assertTrue(tuples.get(10).getDouble("sum(price_f)").equals(splitCount * 400D));assertTrue(tuples.get(10).getDouble("max(price_f)").equals(400D));assertTrue(tuples.get(10).getDouble("min(price_f)").equals(400D));assertTrue(tuples.get(10).getDouble("avg(price_f)").equals(400D));@@ -3145,26 +3497,28 @@ public class StreamExpressionTest extends SolrCloudTestCase {year = tuples.get(11).getString("test_dt");split = tuples.get(11).getString("split_s");- splitCount = counts.get(year+"_"+split);+ splitCount = counts.get(year + "_" + split);assertTrue(tuples.get(11).get("test_dt").equals("2016"));assertTrue(tuples.get(11).get("split_s").equals("three"));assertTrue(tuples.get(11).getLong("count(*)").equals(splitCount));- assertTrue(tuples.get(11).getDouble("sum(price_f)").equals(splitCount*400D));+ assertTrue(tuples.get(11).getDouble("sum(price_f)").equals(splitCount * 400D));assertTrue(tuples.get(11).getDouble("max(price_f)").equals(400D));assertTrue(tuples.get(11).getDouble("min(price_f)").equals(400D));assertTrue(tuples.get(11).getDouble("avg(price_f)").equals(400D));assertTrue(tuples.get(11).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(11).getDouble("per(price_f,50)").equals(400D));-- expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2012-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "split=\"split_s\", " +- "limit=\"1\", "+- "format=\"yyyy\", " +- "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";+ expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q=\"*:*\", start=\"2012-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "split=\"split_s\", "+ + "limit=\"1\", "+ + "format=\"yyyy\", "+ + "count(*), sum(price_f), max(price_f), min(price_f), avg(price_f), std(price_f), per(price_f, 50))";paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");@@ -3185,7 +3539,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(0).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(0).getDouble("per(price_f,50)").equals(100D));-assertTrue(tuples.get(1).get("test_dt").equals("2014"));assertTrue(tuples.get(1).get("split_s").equals("two"));assertTrue(tuples.get(1).getLong("count(*)").equals(20L));@@ -3196,7 +3549,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(1).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(1).getDouble("per(price_f,50)").equals(500D));-assertTrue(tuples.get(2).get("test_dt").equals("2015"));assertTrue(tuples.get(2).get("split_s").equals("three"));assertTrue(tuples.get(2).getLong("count(*)").equals(22L));@@ -3216,7 +3568,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(3).getDouble("avg(price_f)").equals(400D));assertTrue(tuples.get(3).getDouble("std(price_f)").equals(0D));assertTrue(tuples.get(3).getDouble("per(price_f,50)").equals(400D));-}@Test@@ -3226,15 +3577,17 @@ public class StreamExpressionTest extends SolrCloudTestCase {updateRequest.add(id, "hello1", "test_t", "l b c d c");updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "search("+COLLECTIONORALIAS+", q=\"`c d c`\", fl=\"id,test_t\", sort=\"id desc\")";+ String expr =+ "search(" + COLLECTIONORALIAS + ", q=\"`c d c`\", fl=\"id,test_t\", sort=\"id desc\")";- //Add a Stream and an Evaluator to the Tuple.- String cat = "tuple(results="+expr+", sum=add(1,1))";+ // Add a Stream and an Evaluator to the Tuple.+ String cat = "tuple(results=" + expr + ", sum=add(1,1))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cat);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -3242,14 +3595,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {List<Tuple> tuples = getTuples(solrStream);assertTrue(tuples.size() == 1);@SuppressWarnings({"unchecked", "rawtypes"})- List<Map> results = (List<Map>)tuples.get(0).get("results");+ List<Map> results = (List<Map>) tuples.get(0).get("results");assertTrue(results.get(0).get("id").equals("hello1"));assertTrue(results.get(0).get("test_t").equals("l b c d c"));assertTrue(results.get(1).get("id").equals("hello"));assertTrue(results.get(1).get("test_t").equals("l b c d c e"));assertTrue(tuples.get(0).getLong("sum").equals(2L));-}@Test@@ -3259,13 +3611,15 @@ public class StreamExpressionTest extends SolrCloudTestCase {updateRequest.add(id, "hello1", "test_t", "l b c d c");updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);- String expr = "search("+COLLECTIONORALIAS+", q=\"`c d c e`\", fl=\"id,test_t\", sort=\"id desc\")";+ String expr =+ "search(" + COLLECTIONORALIAS + ", q=\"`c d c e`\", fl=\"id,test_t\", sort=\"id desc\")";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);StreamContext context = new StreamContext();@@ -3277,9 +3631,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuple.get("test_t").equals("l b c d c e"));}--- private Map<String,Double> getIdToLabel(TupleStream stream, String outField) throws IOException {+ private Map<String, Double> getIdToLabel(TupleStream stream, String outField) throws IOException {Map<String, Double> idToLabel = new HashMap<>();List<Tuple> tuples = getTuples(stream);for (Tuple tuple : tuples) {@@ -3288,18 +3640,18 @@ public class StreamExpressionTest extends SolrCloudTestCase {return idToLabel;}-@Testpublic void testBasicTextLogitStream() throws Exception {Assume.assumeTrue(!useAlias);- CollectionAdminRequest.createCollection("destinationCollection", "ml", 2, 1).process(cluster.getSolrClient());+ CollectionAdminRequest.createCollection("destinationCollection", "ml", 2, 1)+ .process(cluster.getSolrClient());cluster.waitForActiveCollection("destinationCollection", 2, 2);UpdateRequest updateRequest = new UpdateRequest();- for (int i = 0; i < 5000; i+=2) {+ for (int i = 0; i < 5000; i += 2) {updateRequest.add(id, String.valueOf(i), "tv_text", "a b c c d", "out_i", "1");- updateRequest.add(id, String.valueOf(i+1), "tv_text", "a b e e f", "out_i", "0");+ updateRequest.add(id, String.valueOf(i + 1), "tv_text", "a b e e f", "out_i", "0");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);@@ -3310,15 +3662,18 @@ public class StreamExpressionTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())- .withFunctionName("features", FeaturesSelectionStream.class)- .withFunctionName("train", TextLogitStream.class)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())+ .withFunctionName("features", FeaturesSelectionStream.class)+ .withFunctionName("train", TextLogitStream.class)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class);try {- expression = StreamExpressionParser.parse("features(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4)");+ expression =+ StreamExpressionParser.parse(+ "features(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4)");stream = new FeaturesSelectionStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3333,14 +3688,15 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(terms.contains("e"));assertTrue(terms.contains("f"));- String textLogitExpression = "train(" +- "collection1, " +- "features(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4)," +- "q=\"*:*\", " +- "name=\"model\", " +- "field=\"tv_text\", " +- "outcome=\"out_i\", " +- "maxIterations=100)";+ String textLogitExpression =+ "train("+ + "collection1, "+ + "features(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4),"+ + "q=\"*:*\", "+ + "name=\"model\", "+ + "field=\"tv_text\", "+ + "outcome=\"out_i\", "+ + "maxIterations=100)";stream = factory.constructStream(textLogitExpression);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3360,15 +3716,19 @@ public class StreamExpressionTest extends SolrCloudTestCase {prob = sigmoid(d);assertEquals(prob, 0, 0.1);- stream = factory.constructStream("update(destinationCollection, batchSize=5, " + textLogitExpression + ")");+ stream =+ factory.constructStream(+ "update(destinationCollection, batchSize=5, " + textLogitExpression + ")");getTuples(stream);cluster.getSolrClient().commit("destinationCollection");- stream = factory.constructStream("search(destinationCollection, " +- "q=*:*, " +- "fl=\"iteration_i,* \", " +- "rows=100, " +- "sort=\"iteration_i desc\")");+ stream =+ factory.constructStream(+ "search(destinationCollection, "+ + "q=*:*, "+ + "fl=\"iteration_i,* \", "+ + "rows=100, "+ + "sort=\"iteration_i desc\")");stream.setStreamContext(streamContext);tuples = getTuples(stream);assertEquals(100, tuples.size());@@ -3380,21 +3740,22 @@ public class StreamExpressionTest extends SolrCloudTestCase {Tuple firstTuple = tuples.get(99);assertEquals(1L, (long) firstTuple.getLong("iteration_i"));} finally {- CollectionAdminRequest.deleteCollection("destinationCollection").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("destinationCollection")+ .process(cluster.getSolrClient());solrClientCache.close();}}private double sigmoid(double in) {- double d = 1.0 / (1+Math.exp(-in));+ double d = 1.0 / (1 + Math.exp(-in));return d;}private double[] multiply(Double[] vec1, Double[] vec2) {double[] working = new double[vec1.length];- for(int i=0; i<vec1.length; i++) {- working[i]= vec1[i]*vec2[i];+ for (int i = 0; i < vec1.length; i++) {+ working[i] = vec1[i] * vec2[i];}return working;@@ -3403,7 +3764,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {private double sum(double[] vec) {double d = 0.0;- for(double v : vec) {+ for (double v : vec) {d += v;}@@ -3414,13 +3775,14 @@ public class StreamExpressionTest extends SolrCloudTestCase {public void testFeaturesSelectionStream() throws Exception {Assume.assumeTrue(!useAlias);- CollectionAdminRequest.createCollection("destinationCollection", "ml", 2, 1).process(cluster.getSolrClient());+ CollectionAdminRequest.createCollection("destinationCollection", "ml", 2, 1)+ .process(cluster.getSolrClient());cluster.waitForActiveCollection("destinationCollection", 2, 2);UpdateRequest updateRequest = new UpdateRequest();- for (int i = 0; i < 5000; i+=2) {+ for (int i = 0; i < 5000; i += 2) {updateRequest.add(id, String.valueOf(i), "whitetok", "a b c d", "out_i", "1");- updateRequest.add(id, String.valueOf(i+1), "whitetok", "a b e f", "out_i", "0");+ updateRequest.add(id, String.valueOf(i + 1), "whitetok", "a b e f", "out_i", "0");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);@@ -3431,16 +3793,17 @@ public class StreamExpressionTest extends SolrCloudTestCase {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())- .withFunctionName("featuresSelection", FeaturesSelectionStream.class)- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("update", UpdateStream.class);-+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())+ .withFunctionName("featuresSelection", FeaturesSelectionStream.class)+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("update", UpdateStream.class);try {- String featuresExpression = "featuresSelection(collection1, q=\"*:*\", featureSet=\"first\", field=\"whitetok\", outcome=\"out_i\", numTerms=4)";+ String featuresExpression =+ "featuresSelection(collection1, q=\"*:*\", featureSet=\"first\", field=\"whitetok\", outcome=\"out_i\", numTerms=4)";// basicexpression = StreamExpressionParser.parse(featuresExpression);stream = new FeaturesSelectionStream(expression, factory);@@ -3455,13 +3818,16 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(3).get("term_s").equals("f"));// update- expression = StreamExpressionParser.parse("update(destinationCollection, " + featuresExpression + ")");+ expression =+ StreamExpressionParser.parse("update(destinationCollection, " + featuresExpression + ")");stream = new UpdateStream(expression, factory);stream.setStreamContext(streamContext);getTuples(stream);cluster.getSolrClient().commit("destinationCollection");- expression = StreamExpressionParser.parse("search(destinationCollection, q=featureSet_s:first, fl=\"index_i, term_s\", sort=\"index_i asc\")");+ expression =+ StreamExpressionParser.parse(+ "search(destinationCollection, q=featureSet_s:first, fl=\"index_i, term_s\", sort=\"index_i asc\")");stream = new CloudSolrStream(expression, factory);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3471,34 +3837,34 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(2).get("term_s").equals("e"));assertTrue(tuples.get(3).get("term_s").equals("f"));} finally {- CollectionAdminRequest.deleteCollection("destinationCollection").process(cluster.getSolrClient());+ CollectionAdminRequest.deleteCollection("destinationCollection")+ .process(cluster.getSolrClient());solrClientCache.close();}}-@Testpublic void testSignificantTermsStream() throws Exception {UpdateRequest updateRequest = new UpdateRequest();for (int i = 0; i < 5000; i++) {- updateRequest.add(id, "a"+i, "test_t", "a b c d m l");+ updateRequest.add(id, "a" + i, "test_t", "a b c d m l");}for (int i = 0; i < 5000; i++) {- updateRequest.add(id, "b"+i, "test_t", "a b e f");+ updateRequest.add(id, "b" + i, "test_t", "a b e f");}for (int i = 0; i < 900; i++) {- updateRequest.add(id, "c"+i, "test_t", "c");+ updateRequest.add(id, "c" + i, "test_t", "c");}for (int i = 0; i < 600; i++) {- updateRequest.add(id, "d"+i, "test_t", "d");+ updateRequest.add(id, "d" + i, "test_t", "d");}for (int i = 0; i < 500; i++) {- updateRequest.add(id, "e"+i, "test_t", "m");+ updateRequest.add(id, "e" + i, "test_t", "m");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);@@ -3506,17 +3872,19 @@ public class StreamExpressionTest extends SolrCloudTestCase {TupleStream stream;List<Tuple> tuples;- StreamFactory factory = new StreamFactory()- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())- .withDefaultZkHost(cluster.getZkServer().getZkAddress())- .withFunctionName("significantTerms", SignificantTermsStream.class);+ StreamFactory factory =+ new StreamFactory()+ .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())+ .withDefaultZkHost(cluster.getZkServer().getZkAddress())+ .withFunctionName("significantTerms", SignificantTermsStream.class);StreamContext streamContext = new StreamContext();SolrClientCache cache = new SolrClientCache();streamContext.setSolrClientCache(cache);try {- String significantTerms = "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, minTermLength=1, maxDocFreq=\".5\")";+ String significantTerms =+ "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, minTermLength=1, maxDocFreq=\".5\")";stream = factory.constructStream(significantTerms);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3526,7 +3894,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(0).getLong("background") == 5000);assertTrue(tuples.get(0).getLong("foreground") == 5000);-assertTrue(tuples.get(1).get("term").equals("m"));assertTrue(tuples.get(1).getLong("background") == 5500);assertTrue(tuples.get(1).getLong("foreground") == 5000);@@ -3535,8 +3902,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(2).getLong("background") == 5600);assertTrue(tuples.get(2).getLong("foreground") == 5000);- //Test maxDocFreq- significantTerms = "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, maxDocFreq=2650, minTermLength=1)";+ // Test maxDocFreq+ significantTerms =+ "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, maxDocFreq=2650, minTermLength=1)";stream = factory.constructStream(significantTerms);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3546,9 +3914,10 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(0).getLong("background") == 5000);assertTrue(tuples.get(0).getLong("foreground") == 5000);- //Test maxDocFreq percentage+ // Test maxDocFreq percentage- significantTerms = "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, maxDocFreq=\".45\", minTermLength=1)";+ significantTerms =+ "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, maxDocFreq=\".45\", minTermLength=1)";stream = factory.constructStream(significantTerms);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3557,9 +3926,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(0).getLong("background") == 5000);assertTrue(tuples.get(0).getLong("foreground") == 5000);-- //Test min doc freq- significantTerms = "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, minDocFreq=\"2700\", minTermLength=1, maxDocFreq=\".5\")";+ // Test min doc freq+ significantTerms =+ "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, minDocFreq=\"2700\", minTermLength=1, maxDocFreq=\".5\")";stream = factory.constructStream(significantTerms);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3578,9 +3947,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(2).getLong("background") == 5900);assertTrue(tuples.get(2).getLong("foreground") == 5000);-- //Test min doc freq percent- significantTerms = "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, minDocFreq=\".478\", minTermLength=1, maxDocFreq=\".5\")";+ // Test min doc freq percent+ significantTerms =+ "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=3, minDocFreq=\".478\", minTermLength=1, maxDocFreq=\".5\")";stream = factory.constructStream(significantTerms);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3591,9 +3960,10 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(0).getLong("background") == 5900);assertTrue(tuples.get(0).getLong("foreground") == 5000);- //Test limit+ // Test limit- significantTerms = "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=2, minDocFreq=\"2700\", minTermLength=1, maxDocFreq=\".5\")";+ significantTerms =+ "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=2, minDocFreq=\"2700\", minTermLength=1, maxDocFreq=\".5\")";stream = factory.constructStream(significantTerms);stream.setStreamContext(streamContext);tuples = getTuples(stream);@@ -3608,24 +3978,27 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(1).getLong("background") == 5600);assertTrue(tuples.get(1).getLong("foreground") == 5000);- //Test term length+ // Test term length- significantTerms = "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=2, minDocFreq=\"2700\", minTermLength=2)";+ significantTerms =+ "significantTerms(collection1, q=\"id:a*\", field=\"test_t\", limit=2, minDocFreq=\"2700\", minTermLength=2)";stream = factory.constructStream(significantTerms);stream.setStreamContext(streamContext);tuples = getTuples(stream);assert (tuples.size() == 0);-- //Test with shards parameter- List<String> shardUrls = TupleStream.getShards(cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);+ // Test with shards parameter+ List<String> shardUrls =+ TupleStream.getShards(+ cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);Map<String, List<String>> shardsMap = new HashMap<>();shardsMap.put("myCollection", shardUrls);StreamContext context = new StreamContext();context.put("shards", shardsMap);context.setSolrClientCache(cache);- significantTerms = "significantTerms(myCollection, q=\"id:a*\", field=\"test_t\", limit=2, minDocFreq=\"2700\", minTermLength=1, maxDocFreq=\".5\")";+ significantTerms =+ "significantTerms(myCollection, q=\"id:a*\", field=\"test_t\", limit=2, minDocFreq=\"2700\", minTermLength=1, maxDocFreq=\".5\")";stream = factory.constructStream(significantTerms);stream.setStreamContext(context);tuples = getTuples(stream);@@ -3640,9 +4013,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(1).getLong("background") == 5600);assertTrue(tuples.get(1).getLong("foreground") == 5000);- //Execersise the /stream hander+ // Execersise the /stream hander- //Add the shards http parameter for the myCollection+ // Add the shards http parameter for the myCollectionStringBuilder buf = new StringBuilder();for (String shardUrl : shardUrls) {if (buf.length() > 0) {@@ -3667,7 +4040,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {assertTrue(tuples.get(1).getLong("background") == 5600);assertTrue(tuples.get(1).getLong("foreground") == 5000);- //Add a negative test to prove that it cannot find slices if shards parameter is removed+ // Add a negative test to prove that it cannot find slices if shards parameter is removedtry {ModifiableSolrParams solrParamsBad = new ModifiableSolrParams();@@ -3689,49 +4062,78 @@ public class StreamExpressionTest extends SolrCloudTestCase {// Test expressions which are larger than GET can handleUpdateRequest updateRequest = new UpdateRequest();for (int i = 0; i < 10; i++) {- updateRequest.add(id, "a"+i, "test_t", "a b c d m l");+ updateRequest.add(id, "a" + i, "test_t", "a b c d m l");}- for(int i=1; i<=50; i++) {- updateRequest.add(id, "id_"+(i),"test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");+ for (int i = 1; i <= 50; i++) {+ updateRequest.add(+ id, "id_" + (i), "test_dt", getDateString("2016", "5", "1"), "price_f", "400.00");}updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);SolrClientCache cache = new SolrClientCache();StreamContext streamContext = new StreamContext();streamContext.setSolrClientCache(cache);- // use filter() to allow being parsed as 'terms in set' query instead of a (weighted/scored) BooleanQuery- // so we don't trip too many boolean clauses- String longQuery = "\"filter(id:(" + IntStream.range(0, 4000).mapToObj(i -> "a").collect(Collectors.joining(" ", "", "")) + "))\"";+ // use filter() to allow being parsed as 'terms in set' query instead of a (weighted/scored)+ // BooleanQuery so we don't trip too many boolean clauses+ String longQuery =+ "\"filter(id:("+ + IntStream.range(0, 4000).mapToObj(i -> "a").collect(Collectors.joining(" ", "", ""))+ + "))\"";try {- assertSuccess("significantTerms("+COLLECTIONORALIAS+", q="+longQuery+", field=\"test_t\", limit=3, minTermLength=1, maxDocFreq=\".5\")", streamContext);- String expr = "timeseries("+COLLECTIONORALIAS+", q="+longQuery+", start=\"2013-01-01T01:00:00.000Z\", " +- "end=\"2016-12-01T01:00:00.000Z\", " +- "gap=\"+1YEAR\", " +- "field=\"test_dt\", " +- "format=\"yyyy\", " +- "count(*), sum(price_f), max(price_f), min(price_f))";+ assertSuccess(+ "significantTerms("+ + COLLECTIONORALIAS+ + ", q="+ + longQuery+ + ", field=\"test_t\", limit=3, minTermLength=1, maxDocFreq=\".5\")",+ streamContext);+ String expr =+ "timeseries("+ + COLLECTIONORALIAS+ + ", q="+ + longQuery+ + ", start=\"2013-01-01T01:00:00.000Z\", "+ + "end=\"2016-12-01T01:00:00.000Z\", "+ + "gap=\"+1YEAR\", "+ + "field=\"test_dt\", "+ + "format=\"yyyy\", "+ + "count(*), sum(price_f), max(price_f), min(price_f))";assertSuccess(expr, streamContext);- expr = "facet("- + "collection1, "- + "q="+longQuery+", "- + "fl=\"a_s,a_i,a_f\", "- + "sort=\"a_s asc\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) asc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")";+ expr =+ "facet("+ + "collection1, "+ + "q="+ + longQuery+ + ", "+ + "fl=\"a_s,a_i,a_f\", "+ + "sort=\"a_s asc\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) asc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")";assertSuccess(expr, streamContext);- expr = "stats(" + COLLECTIONORALIAS + ", q="+longQuery+", sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), count(*))";+ expr =+ "stats("+ + COLLECTIONORALIAS+ + ", q="+ + longQuery+ + ", sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), count(*))";assertSuccess(expr, streamContext);- expr = "search(" + COLLECTIONORALIAS + ", q="+longQuery+", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")";+ expr =+ "search("+ + COLLECTIONORALIAS+ + ", q="+ + longQuery+ + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")";assertSuccess(expr, streamContext);- expr = "random(" + COLLECTIONORALIAS + ", q="+longQuery+", rows=\"1000\", fl=\"id, a_i\")";+ expr =+ "random(" + COLLECTIONORALIAS + ", q=" + longQuery + ", rows=\"1000\", fl=\"id, a_i\")";assertSuccess(expr, streamContext);} finally {cache.close();@@ -3744,7 +4146,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", catStream);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+FILESTREAM_COLLECTION;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + FILESTREAM_COLLECTION;SolrStream solrStream = new SolrStream(url, paramsLoc);@@ -3755,7 +4158,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {for (int i = 0; i < 4; i++) {Tuple t = tuples.get(i);- assertEquals("topLevel1.txt line " + String.valueOf(i+1), t.get("line"));+ assertEquals("topLevel1.txt line " + String.valueOf(i + 1), t.get("line"));assertEquals("topLevel1.txt", t.get("file"));}}@@ -3766,7 +4169,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", catStream);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+FILESTREAM_COLLECTION;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + FILESTREAM_COLLECTION;SolrStream solrStream = new SolrStream(url, paramsLoc);@@ -3777,7 +4181,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {for (int i = 0; i < 4; i++) {Tuple t = tuples.get(i);- assertEquals("topLevel1.txt.gz line " + String.valueOf(i+1), t.get("line"));+ assertEquals("topLevel1.txt.gz line " + String.valueOf(i + 1), t.get("line"));assertEquals("topLevel1.txt.gz", t.get("file"));}}@@ -3788,7 +4192,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", catStream);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+FILESTREAM_COLLECTION;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + FILESTREAM_COLLECTION;SolrStream solrStream = new SolrStream(url, paramsLoc);@@ -3805,7 +4210,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", catStream);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+FILESTREAM_COLLECTION;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + FILESTREAM_COLLECTION;SolrStream solrStream = new SolrStream(url, paramsLoc);@@ -3817,7 +4223,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {for (int i = 0; i < 4; i++) {Tuple t = tuples.get(i);- assertEquals("topLevel1.txt line " + String.valueOf(i+1), t.get("line"));+ assertEquals("topLevel1.txt line " + String.valueOf(i + 1), t.get("line"));assertEquals("topLevel1.txt", t.get("file"));}}@@ -3828,7 +4234,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", catStream);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+FILESTREAM_COLLECTION;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + FILESTREAM_COLLECTION;SolrStream solrStream = new SolrStream(url, paramsLoc);@@ -3839,7 +4246,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {for (int i = 0; i < 2; i++) {Tuple t = tuples.get(i);- assertEquals("topLevel1.txt line " + String.valueOf(i+1), t.get("line"));+ assertEquals("topLevel1.txt line " + String.valueOf(i + 1), t.get("line"));assertEquals("topLevel1.txt", t.get("file"));}}@@ -3850,7 +4257,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", catStream);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+FILESTREAM_COLLECTION;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + FILESTREAM_COLLECTION;SolrStream solrStream = new SolrStream(url, paramsLoc);@@ -3862,7 +4270,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {final String expectedSecondLevel1Path = "directory1" + File.separator + "secondLevel1.txt";for (int i = 0; i < 4; i++) {Tuple t = tuples.get(i);- assertEquals("secondLevel1.txt line " + String.valueOf(i+1), t.get("line"));+ assertEquals("secondLevel1.txt line " + String.valueOf(i + 1), t.get("line"));assertEquals(expectedSecondLevel1Path, t.get("file"));}@@ -3876,11 +4284,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {@Testpublic void testCatStreamMultipleExplicitFiles() throws Exception {- final String catStream = "cat(\"topLevel1.txt,directory1" + File.separator + "secondLevel2.txt\")";+ final String catStream =+ "cat(\"topLevel1.txt,directory1" + File.separator + "secondLevel2.txt\")";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", catStream);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+FILESTREAM_COLLECTION;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + FILESTREAM_COLLECTION;SolrStream solrStream = new SolrStream(url, paramsLoc);@@ -3891,7 +4301,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {for (int i = 0; i < 4; i++) {Tuple t = tuples.get(i);- assertEquals("topLevel1.txt line " + String.valueOf(i+1), t.get("line"));+ assertEquals("topLevel1.txt line " + String.valueOf(i + 1), t.get("line"));assertEquals("topLevel1.txt", t.get("file"));}@@ -3908,13 +4318,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {paramsLoc.set("expr", expr);paramsLoc.set("qt", "/stream");- String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;+ String url =+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;TupleStream solrStream = new SolrStream(url, paramsLoc);solrStream.setStreamContext(streamContext);getTuples(solrStream);}-private static Path findUserFilesDataDir() {for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {for (CoreDescriptor coreDescriptor : jetty.getCoreContainer().getCoreDescriptors()) {@@ -3924,14 +4334,15 @@ public class StreamExpressionTest extends SolrCloudTestCase {}}- throw new IllegalStateException("Unable to determine data-dir for: "+ FILESTREAM_COLLECTION);+ throw new IllegalStateException("Unable to determine data-dir for: " + FILESTREAM_COLLECTION);}/*** Creates a tree of files underneath a provided data-directory.*- * The filetree created looks like:+ * <p>The filetree created looks like:*+ * <pre>* dataDir* |- topLevel1.txt* |- topLevel2.txt@@ -3939,8 +4350,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {* |- directory1* |- secondLevel1.txt* |- secondLevel2.txt+ * </pre>*- * Each file contains 4 lines. Each line looks like: "<filename> line <linenumber>"+ * Each file contains 4 lines. Each line looks like: "<filename> line <linenumber>"*/private static void populateFileStreamData(Path dataDir) throws Exception {Files.createDirectories(dataDir);@@ -3957,7 +4369,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {private static void populateFileWithData(Path dataFile) throws Exception {Files.createFile(dataFile);try (final BufferedWriter writer = Files.newBufferedWriter(dataFile, StandardCharsets.UTF_8)) {- for (int i = 1; i <=4; i++) {+ for (int i = 1; i <= 4; i++) {writer.write(dataFile.getFileName() + " line " + i);writer.newLine();}@@ -3966,8 +4378,12 @@ public class StreamExpressionTest extends SolrCloudTestCase {private static void populateFileWithGzipData(Path dataFile) throws Exception {Files.createFile(dataFile);- try (final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(dataFile.toFile())), StandardCharsets.UTF_8))) {- for (int i = 1; i <=4; i++) {+ try (final BufferedWriter writer =+ new BufferedWriter(+ new OutputStreamWriter(+ new GZIPOutputStream(new FileOutputStream(dataFile.toFile())),+ StandardCharsets.UTF_8))) {+ for (int i = 1; i <= 4; i++) {writer.write(dataFile.getFileName() + " line " + i);writer.newLine();}@@ -3987,16 +4403,19 @@ public class StreamExpressionTest extends SolrCloudTestCase {}return tuples;}+protected boolean assertOrder(List<Tuple> tuples, int... ids) throws Exception {return assertOrderOf(tuples, "id", ids);}- protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids) throws Exception {++ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids)+ throws Exception {int i = 0;- for(int val : ids) {+ for (int val : ids) {Tuple t = tuples.get(i);String tip = t.getString(fieldName);- if(!tip.equals(Integer.toString(val))) {- throw new Exception("Found value:"+tip+" expecting:"+val);+ if (!tip.equals(Integer.toString(val))) {+ throw new Exception("Found value:" + tip + " expecting:" + val);}++i;}@@ -4004,21 +4423,21 @@ public class StreamExpressionTest extends SolrCloudTestCase {}public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {- long lv = (long)tuple.get(fieldName);- if(lv != l) {- throw new Exception("Longs not equal:"+l+" : "+lv);+ long lv = (long) tuple.get(fieldName);+ if (lv != l) {+ throw new Exception("Longs not equal:" + l + " : " + lv);}return true;}public boolean assertString(Tuple tuple, String fieldName, String expected) throws Exception {- String actual = (String)tuple.get(fieldName);+ String actual = (String) tuple.get(fieldName);- if( (null == expected && null != actual) ||- (null != expected && null == actual) ||- (null != expected && !expected.equals(actual))){- throw new Exception("Longs not equal:"+expected+" : "+actual);+ if ((null == expected && null != actual)+ || (null != expected && null == actual)+ || (null != expected && !expected.equals(actual))) {+ throw new Exception("Longs not equal:" + expected + " : " + actual);}return true;@@ -4026,8 +4445,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {public boolean assertDouble(Tuple tuple, String fieldName, double d) throws Exception {double dv = tuple.getDouble(fieldName);- if(dv != d) {- throw new Exception("Doubles not equal:"+d+" : "+dv);+ if (dv != d) {+ throw new Exception("Doubles not equal:" + d + " : " + dv);}return true;@@ -4037,7 +4456,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {long version = -1;int count = 0;List<String> ids = new ArrayList<>();- for(String id : idArray) {+ for (String id : idArray) {ids.add(id);}@@ -4064,8 +4483,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {stream.close();}- if(count != ids.size()) {- throw new Exception("Wrong count in topic run:"+count);+ if (count != ids.size()) {+ throw new Exception("Wrong count in topic run:" + count);}}@@ -4073,7 +4492,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {long version = -1;int count = 0;List<String> texts = new ArrayList<>();- for(String text : textArray) {+ for (String text : textArray) {texts.add(text);}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExpessionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExpessionTest.javaindex d69047caf6a..81565ace967 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExpessionTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExpessionTest.java@@ -29,51 +29,53 @@ import org.apache.solr.client.solrj.io.stream.metrics.MinMetric;import org.apache.solr.client.solrj.io.stream.metrics.SumMetric;import org.junit.Test;-/**- **/-+/** */public class StreamExpressionToExpessionTest extends SolrTestCase {private StreamFactory factory;-+public StreamExpressionToExpessionTest() {super();-- factory = new StreamFactory()- .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)- .withFunctionName("reduce", ReducerStream.class)- .withFunctionName("group", GroupOperation.class)- .withFunctionName("update", UpdateStream.class)- .withFunctionName("stats", StatsStream.class)- .withFunctionName("facet", FacetStream.class)- .withFunctionName("jdbc", JDBCStream.class)- .withFunctionName("intersect", IntersectStream.class)- .withFunctionName("complement", ComplementStream.class)- .withFunctionName("count", CountMetric.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("daemon", DaemonStream.class)- .withFunctionName("topic", TopicStream.class)- .withFunctionName("tlogit", TextLogitStream.class)- .withFunctionName("featuresSelection", FeaturesSelectionStream.class)- ;++ factory =+ new StreamFactory()+ .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)+ .withFunctionName("reduce", ReducerStream.class)+ .withFunctionName("group", GroupOperation.class)+ .withFunctionName("update", UpdateStream.class)+ .withFunctionName("stats", StatsStream.class)+ .withFunctionName("facet", FacetStream.class)+ .withFunctionName("jdbc", JDBCStream.class)+ .withFunctionName("intersect", IntersectStream.class)+ .withFunctionName("complement", ComplementStream.class)+ .withFunctionName("count", CountMetric.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("daemon", DaemonStream.class)+ .withFunctionName("topic", TopicStream.class)+ .withFunctionName("tlogit", TextLogitStream.class)+ .withFunctionName("featuresSelection", FeaturesSelectionStream.class);}-+@Testpublic void testCloudSolrStream() throws Exception {String expressionString;-+// Basic test- try (CloudSolrStream stream = new CloudSolrStream(StreamExpressionParser.parse("search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", fq=\"a_s:one\", fq=\"a_s:two\")"), factory)) {+ try (CloudSolrStream stream =+ new CloudSolrStream(+ StreamExpressionParser.parse(+ "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", fq=\"a_s:one\", fq=\"a_s:two\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();System.out.println("ExpressionString: " + expressionString.toString());assertTrue(expressionString.contains("search(collection1,"));@@ -84,19 +86,27 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {assertTrue(expressionString.contains("fq=\"a_s:two\""));}// Basic w/aliases- try (CloudSolrStream stream = new CloudSolrStream(StreamExpressionParser.parse("search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", aliases=\"id=izzy,a_s=kayden\")"), factory)) {+ try (CloudSolrStream stream =+ new CloudSolrStream(+ StreamExpressionParser.parse(+ "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", aliases=\"id=izzy,a_s=kayden\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("id=izzy"));assertTrue(expressionString.contains("a_s=kayden"));}}-+@Testpublic void testSelectStream() throws Exception {String expressionString;-+// Basic test- try (SelectStream 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)) {+ try (SelectStream 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=\"*:*\""));@@ -107,12 +117,15 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {}@Test- // commented out on: 24-Dec-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018public void testDaemonStream() throws Exception {String expressionString;// Basic test- try (DaemonStream stream = new DaemonStream(StreamExpressionParser.parse("daemon(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), id=\"blah\", runInterval=\"1000\", queueSize=\"100\")"), factory)) {+ try (DaemonStream stream =+ new DaemonStream(+ StreamExpressionParser.parse(+ "daemon(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), id=\"blah\", runInterval=\"1000\", queueSize=\"100\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("daemon(search(collection1,"));assertTrue(expressionString.contains("q=\"*:*\""));@@ -130,7 +143,11 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {String expressionString;// Basic test- try (TopicStream stream = new TopicStream(StreamExpressionParser.parse("topic(collection2, collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", id=\"blah\", checkpointEvery=1000)"), factory)) {+ try (TopicStream stream =+ new TopicStream(+ StreamExpressionParser.parse(+ "topic(collection2, collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", id=\"blah\", checkpointEvery=1000)"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("topic(collection2,collection1"));assertTrue(expressionString.contains("q=\"*:*\""));@@ -143,9 +160,13 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {@Testpublic void testStatsStream() throws Exception {String expressionString;-+// Basic test- try (StatsStream stream = new StatsStream(StreamExpressionParser.parse("stats(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", sum(a_i), avg(a_i), count(*), min(a_i), max(a_i))"), factory)) {+ try (StatsStream stream =+ new StatsStream(+ StreamExpressionParser.parse(+ "stats(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", sum(a_i), avg(a_i), count(*), min(a_i), max(a_i))"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("stats(collection1,"));assertTrue(expressionString.contains("q=\"*:*\""));@@ -162,75 +183,95 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {@Testpublic void testUniqueStream() throws Exception {String expressionString;-+// Basic test- try (UniqueStream stream = new UniqueStream(StreamExpressionParser.parse("unique(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f\")"), factory)) {+ try (UniqueStream stream =+ new UniqueStream(+ StreamExpressionParser.parse(+ "unique(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("unique(search(collection1"));assertTrue(expressionString.contains("over=a_f"));}}-+@Testpublic void testMergeStream() throws Exception {String expressionString;-+// Basic test- try (MergeStream stream = new MergeStream(StreamExpressionParser.parse("merge("- + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f asc, a_s asc\")"), factory)) {+ try (MergeStream stream =+ new MergeStream(+ StreamExpressionParser.parse(+ "merge("+ + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f asc, a_s asc\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("q=\"id:(0 3 4)\""));assertTrue(expressionString.contains("q=\"id:(1 2)\""));assertTrue(expressionString.contains("on=\"a_f asc,a_s asc\""));}}-+@Testpublic void testRankStream() throws Exception {String expressionString;-+// Basic test- try (RankStream stream = new RankStream(StreamExpressionParser.parse("top("- + "n=3,"- + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc,a_i asc\"),"- + "sort=\"a_f asc, a_i asc\")"), factory)) {+ try (RankStream stream =+ new RankStream(+ StreamExpressionParser.parse(+ "top("+ + "n=3,"+ + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc,a_i asc\"),"+ + "sort=\"a_f asc, a_i asc\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("top(n=3,search(collection1"));assertTrue(expressionString.contains("sort=\"a_f asc,a_i asc\""));// find 2nd instance of sort- assertTrue(expressionString.substring(expressionString.indexOf("sort=\"a_f asc,a_i asc\"") + 1).contains("sort=\"a_f asc,a_i asc\""));+ assertTrue(+ expressionString+ .substring(expressionString.indexOf("sort=\"a_f asc,a_i asc\"") + 1)+ .contains("sort=\"a_f asc,a_i asc\""));}}@Testpublic void testReducerStream() throws Exception {String expressionString;-+// Basic test- try (ReducerStream stream = new ReducerStream(StreamExpressionParser.parse("reduce("- + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s desc, a_f asc\"),"- + "by=\"a_s\", group(sort=\"a_i desc\", n=\"5\"))"), factory)) {+ try (ReducerStream stream =+ new ReducerStream(+ StreamExpressionParser.parse(+ "reduce("+ + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s desc, a_f asc\"),"+ + "by=\"a_s\", group(sort=\"a_i desc\", n=\"5\"))"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("reduce(search(collection1"));assertTrue(expressionString.contains("by=a_s"));}}-+@Test- // commented out on: 24-Dec-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018public void testUpdateStream() throws Exception {- StreamExpression expression = StreamExpressionParser.parse("update("- + "collection2, "- + "batchSize=5, "- + "search("- + "collection1, "- + "q=*:*, "- + "fl=\"id,a_s,a_i,a_f\", "- + "sort=\"a_f asc, a_i asc\"))");-+ StreamExpression expression =+ StreamExpressionParser.parse(+ "update("+ + "collection2, "+ + "batchSize=5, "+ + "search("+ + "collection1, "+ + "q=*:*, "+ + "fl=\"id,a_s,a_i,a_f\", "+ + "sort=\"a_f asc, a_i asc\"))");+try (UpdateStream updateStream = new UpdateStream(expression, factory)) {String expressionString = updateStream.toExpression(factory).toString();@@ -239,25 +280,29 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {assertTrue(expressionString.contains("search(collection1"));}}-+@Testpublic void testFacetStream() throws Exception {String expressionString;-+// Basic test- try (FacetStream stream = new FacetStream(StreamExpressionParser.parse("facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) asc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")"), factory)){+ try (FacetStream stream =+ new FacetStream(+ StreamExpressionParser.parse(+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) asc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("facet(collection1"));assertTrue(expressionString.contains("q=\"*:*\""));@@ -278,17 +323,21 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {assertEquals(stream.getOffset(), 0);}- try (FacetStream stream = new FacetStream(StreamExpressionParser.parse("facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) asc\", "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")"), factory)){+ try (FacetStream stream =+ new FacetStream(+ StreamExpressionParser.parse(+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) asc\", "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("facet(collection1"));assertTrue(expressionString.contains("q=\"*:*\""));@@ -312,18 +361,22 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {assertEquals(stream.getOffset(), 0);}- try (FacetStream stream = new FacetStream(StreamExpressionParser.parse("facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) asc\", "- + "rows=10, method=dvhash, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")"), factory)){+ try (FacetStream stream =+ new FacetStream(+ StreamExpressionParser.parse(+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) asc\", "+ + "rows=10, method=dvhash, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("facet(collection1"));assertTrue(expressionString.contains("q=\"*:*\""));@@ -347,21 +400,24 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {assertEquals(stream.getRows(), 10);assertEquals(stream.getOffset(), 0);assertEquals(stream.getOverfetch(), 250);-}- try (FacetStream stream = new FacetStream(StreamExpressionParser.parse("facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) asc\", "- + "rows=10, offset=100, overfetch=30, method=dvhash, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")"), factory)){+ try (FacetStream stream =+ new FacetStream(+ StreamExpressionParser.parse(+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) asc\", "+ + "rows=10, offset=100, overfetch=30, method=dvhash, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("facet(collection1"));assertTrue(expressionString.contains("q=\"*:*\""));@@ -385,21 +441,24 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {assertEquals(stream.getRows(), 10);assertEquals(stream.getOffset(), 100);assertEquals(stream.getOverfetch(), 30);-}- try (FacetStream stream = new FacetStream(StreamExpressionParser.parse("facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) asc\", "- + "rows=-1, offset=100, overfetch=-1, method=dvhash, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")"), factory)){+ try (FacetStream stream =+ new FacetStream(+ StreamExpressionParser.parse(+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) asc\", "+ + "rows=-1, offset=100, overfetch=-1, method=dvhash, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("facet(collection1"));assertTrue(expressionString.contains("q=\"*:*\""));@@ -424,31 +483,40 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {assertEquals(stream.getOffset(), 100);assertEquals(stream.getOverfetch(), -1);}-}-+@Testpublic void testJDBCStream() throws Exception {String expressionString;-+// Basic test- try (JDBCStream stream = new JDBCStream(StreamExpressionParser.parse("jdbc(connection=\"jdbc:hsqldb:mem:.\", sql=\"select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE order by PEOPLE.ID\", sort=\"ID asc\")"), factory)) {+ try (JDBCStream stream =+ new JDBCStream(+ StreamExpressionParser.parse(+ "jdbc(connection=\"jdbc:hsqldb:mem:.\", sql=\"select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE order by PEOPLE.ID\", sort=\"ID asc\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("jdbc(connection=\"jdbc:hsqldb:mem:.\","));- assertTrue(expressionString.contains("sql=\"select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE order by PEOPLE.ID\""));+ assertTrue(+ expressionString.contains(+ "sql=\"select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE order by PEOPLE.ID\""));assertTrue(expressionString.contains("sort=\"ID asc\""));}}- @Test+ @Testpublic void testIntersectStream() throws Exception {String expressionString;-+// Basic test- try (IntersectStream stream = new IntersectStream(StreamExpressionParser.parse("intersect("- + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f, a_s\")"), factory)) {+ try (IntersectStream stream =+ new IntersectStream(+ StreamExpressionParser.parse(+ "intersect("+ + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f, a_s\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("q=\"id:(0 3 4)\""));assertTrue(expressionString.contains("q=\"id:(1 2)\""));@@ -456,47 +524,61 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {}}- @Test+ @Testpublic void testComplementStream() throws Exception {String expressionString;-+// Basic test- try (ComplementStream stream = new ComplementStream(StreamExpressionParser.parse("complement("- + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f, a_s\")"), factory)) {+ try (ComplementStream stream =+ new ComplementStream(+ StreamExpressionParser.parse(+ "complement("+ + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f, a_s\")"),+ factory)) {expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("q=\"id:(0 3 4)\""));assertTrue(expressionString.contains("q=\"id:(1 2)\""));assertTrue(expressionString.contains("on=\"a_f,a_s\""));}}-+@Testpublic void testCloudSolrStreamWithEscapedQuote() throws Exception {- // The purpose of this test is to ensure that a parameter with a contained " character is properly- // escaped when it is turned back into an expression. This is important when an expression is passed- // to a worker (parallel stream) or even for other reasons when an expression is string-ified.-+ // The purpose of this test is to ensure that a parameter with a contained " character is+ // properly escaped when it is turned back into an expression. This is important when an+ // expression is passedto a worker (parallel stream) or even for other reasons when an+ // expression is string-ified.+// Basic test- String originalExpressionString = "search(collection1,fl=\"id,first\",sort=\"first asc\",q=\"presentTitles:\\\"chief, executive officer\\\" AND age:[36 TO *]\")";- try (CloudSolrStream firstStream = new CloudSolrStream(StreamExpressionParser.parse(originalExpressionString), factory)) {+ String originalExpressionString =+ "search(collection1,fl=\"id,first\",sort=\"first asc\",q=\"presentTitles:\\\"chief, executive officer\\\" AND age:[36 TO *]\")";+ try (CloudSolrStream firstStream =+ new CloudSolrStream(StreamExpressionParser.parse(originalExpressionString), factory)) {String firstExpressionString = firstStream.toExpression(factory).toString();- try (CloudSolrStream secondStream = new CloudSolrStream(StreamExpressionParser.parse(firstExpressionString), factory)) {+ try (CloudSolrStream secondStream =+ new CloudSolrStream(StreamExpressionParser.parse(firstExpressionString), factory)) {String secondExpressionString = secondStream.toExpression(factory).toString();- assertTrue(firstExpressionString.contains("q=\"presentTitles:\\\"chief, executive officer\\\" AND age:[36 TO *]\""));- assertTrue(secondExpressionString.contains("q=\"presentTitles:\\\"chief, executive officer\\\" AND age:[36 TO *]\""));+ assertTrue(+ firstExpressionString.contains(+ "q=\"presentTitles:\\\"chief, executive officer\\\" AND age:[36 TO *]\""));+ assertTrue(+ secondExpressionString.contains(+ "q=\"presentTitles:\\\"chief, executive officer\\\" AND age:[36 TO *]\""));}}}@Testpublic void testFeaturesSelectionStream() throws Exception {- String expr = "featuresSelection(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4, positiveLabel=2)";- try (FeaturesSelectionStream stream = new FeaturesSelectionStream(StreamExpressionParser.parse(expr), factory)) {+ String expr =+ "featuresSelection(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4, positiveLabel=2)";+ try (FeaturesSelectionStream stream =+ new FeaturesSelectionStream(StreamExpressionParser.parse(expr), factory)) {String expressionString = stream.toExpression(factory).toString();assertTrue(expressionString.contains("q=\"*:*\""));assertTrue(expressionString.contains("featureSet=first"));@@ -509,15 +591,17 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {@Testpublic void testTextLogitStreamWithFeaturesSelection() throws Exception {- String expr = "tlogit(" +- "collection1, " +- "q=\"*:*\", " +- "name=\"model\", " +- "featuresSelection(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4), " +- "field=\"tv_text\", " +- "outcome=\"out_i\", " +- "maxIterations=100)";- try (TextLogitStream logitStream = new TextLogitStream(StreamExpressionParser.parse(expr), factory)) {+ String expr =+ "tlogit("+ + "collection1, "+ + "q=\"*:*\", "+ + "name=\"model\", "+ + "featuresSelection(collection1, q=\"*:*\", featureSet=\"first\", field=\"tv_text\", outcome=\"out_i\", numTerms=4), "+ + "field=\"tv_text\", "+ + "outcome=\"out_i\", "+ + "maxIterations=100)";+ try (TextLogitStream logitStream =+ new TextLogitStream(StreamExpressionParser.parse(expr), factory)) {String expressionString = logitStream.toExpression(factory).toString();assertTrue(expressionString.contains("q=\"*:*\""));assertTrue(expressionString.contains("name=model"));@@ -528,43 +612,43 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {assertTrue(expressionString.contains("maxIterations=100"));}}-+@Testpublic void testCountMetric() throws Exception {Metric metric;String expressionString;-+// Basic testmetric = new CountMetric(StreamExpressionParser.parse("count(*)"), factory);expressionString = metric.toExpression(factory).toString();-+assertEquals("count(*)", expressionString);}-+@Testpublic void testMaxMetric() throws Exception {Metric metric;String expressionString;-+// Basic testmetric = new MaxMetric(StreamExpressionParser.parse("max(foo)"), factory);expressionString = metric.toExpression(factory).toString();-+assertEquals("max(foo)", expressionString);}-+@Testpublic void testMinMetric() throws Exception {Metric metric;String expressionString;-+// Basic testmetric = new MinMetric(StreamExpressionParser.parse("min(foo)"), factory);expressionString = metric.toExpression(factory).toString();-+assertEquals("min(foo)", expressionString);}@@ -573,24 +657,24 @@ public class StreamExpressionToExpessionTest extends SolrTestCase {Metric metric;String expressionString;-+// Basic testmetric = new MeanMetric(StreamExpressionParser.parse("avg(foo)"), factory);expressionString = metric.toExpression(factory).toString();-+assertEquals("avg(foo,false)", expressionString);}-+@Testpublic void testSumMetric() throws Exception {Metric metric;String expressionString;-+// Basic testmetric = new SumMetric(StreamExpressionParser.parse("sum(foo)"), factory);expressionString = metric.toExpression(factory).toString();-+assertEquals("sum(foo)", expressionString);}}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExplanationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExplanationTest.javaindex 48f6f32a562..cc1e77b0d93 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExplanationTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExplanationTest.java@@ -31,56 +31,62 @@ import org.apache.solr.client.solrj.io.stream.metrics.MinMetric;import org.apache.solr.client.solrj.io.stream.metrics.SumMetric;import org.junit.Test;-/**- **/-+/** */public class StreamExpressionToExplanationTest extends SolrTestCase {private StreamFactory factory;-+public StreamExpressionToExplanationTest() {super();-- factory = new StreamFactory()- .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)- .withFunctionName("reduce", ReducerStream.class)- .withFunctionName("group", GroupOperation.class)- .withFunctionName("update", UpdateStream.class)- .withFunctionName("stats", StatsStream.class)- .withFunctionName("facet", FacetStream.class)- .withFunctionName("jdbc", JDBCStream.class)- .withFunctionName("intersect", IntersectStream.class)- .withFunctionName("complement", ComplementStream.class)- .withFunctionName("count", CountMetric.class)- .withFunctionName("sum", SumMetric.class)- .withFunctionName("min", MinMetric.class)- .withFunctionName("max", MaxMetric.class)- .withFunctionName("avg", MeanMetric.class)- .withFunctionName("daemon", DaemonStream.class)- .withFunctionName("topic", TopicStream.class)- ;++ factory =+ new StreamFactory()+ .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)+ .withFunctionName("reduce", ReducerStream.class)+ .withFunctionName("group", GroupOperation.class)+ .withFunctionName("update", UpdateStream.class)+ .withFunctionName("stats", StatsStream.class)+ .withFunctionName("facet", FacetStream.class)+ .withFunctionName("jdbc", JDBCStream.class)+ .withFunctionName("intersect", IntersectStream.class)+ .withFunctionName("complement", ComplementStream.class)+ .withFunctionName("count", CountMetric.class)+ .withFunctionName("sum", SumMetric.class)+ .withFunctionName("min", MinMetric.class)+ .withFunctionName("max", MaxMetric.class)+ .withFunctionName("avg", MeanMetric.class)+ .withFunctionName("daemon", DaemonStream.class)+ .withFunctionName("topic", TopicStream.class);}-+@Testpublic void testCloudSolrStream() throws Exception {// Basic test- try (CloudSolrStream stream = new CloudSolrStream(StreamExpressionParser.parse("search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")"), factory)) {+ try (CloudSolrStream stream =+ new CloudSolrStream(+ StreamExpressionParser.parse(+ "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("search", explanation.getFunctionName());Assert.assertEquals(CloudSolrStream.class.getName(), explanation.getImplementingClass());}}-+@Testpublic void testSelectStream() throws Exception {// Basic test- try (SelectStream 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)) {+ try (SelectStream 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)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("select", explanation.getFunctionName());Assert.assertEquals(SelectStream.class.getName(), explanation.getImplementingClass());@@ -88,10 +94,13 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {}@Test- // commented out on: 24-Dec-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018public void testDaemonStream() throws Exception {// Basic test- try (DaemonStream stream = new DaemonStream(StreamExpressionParser.parse("daemon(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), id=\"blah\", runInterval=\"1000\", queueSize=\"100\")"), factory)) {+ try (DaemonStream stream =+ new DaemonStream(+ StreamExpressionParser.parse(+ "daemon(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), id=\"blah\", runInterval=\"1000\", queueSize=\"100\")"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("daemon", explanation.getFunctionName());Assert.assertEquals(DaemonStream.class.getName(), explanation.getImplementingClass());@@ -101,18 +110,25 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {@Testpublic void testTopicStream() throws Exception {// Basic test- try (TopicStream stream = new TopicStream(StreamExpressionParser.parse("topic(collection2, collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", id=\"blah\", checkpointEvery=1000)"), factory)) {+ try (TopicStream stream =+ new TopicStream(+ StreamExpressionParser.parse(+ "topic(collection2, collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", id=\"blah\", checkpointEvery=1000)"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("topic", explanation.getFunctionName());Assert.assertEquals(TopicStream.class.getName(), explanation.getImplementingClass());}}-@Testpublic void testStatsStream() throws Exception {// Basic test- try (StatsStream stream = new StatsStream(StreamExpressionParser.parse("stats(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", sum(a_i), avg(a_i), count(*), min(a_i), max(a_i))"), factory)) {+ try (StatsStream stream =+ new StatsStream(+ StreamExpressionParser.parse(+ "stats(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", sum(a_i), avg(a_i), count(*), min(a_i), max(a_i))"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("stats", explanation.getFunctionName());Assert.assertEquals(StatsStream.class.getName(), explanation.getImplementingClass());@@ -122,36 +138,48 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {@Testpublic void testUniqueStream() throws Exception {// Basic test- try (UniqueStream stream = new UniqueStream(StreamExpressionParser.parse("unique(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f\")"), factory)) {+ try (UniqueStream stream =+ new UniqueStream(+ StreamExpressionParser.parse(+ "unique(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\"), over=\"a_f\")"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("unique", explanation.getFunctionName());Assert.assertEquals(UniqueStream.class.getName(), explanation.getImplementingClass());}}-+@Testpublic void testMergeStream() throws Exception {// Basic test- try (MergeStream stream = new MergeStream(StreamExpressionParser.parse("merge("- + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f asc, a_s asc\")"), factory)) {+ try (MergeStream stream =+ new MergeStream(+ StreamExpressionParser.parse(+ "merge("+ + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f asc, a_s asc\")"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("merge", explanation.getFunctionName());Assert.assertEquals(MergeStream.class.getName(), explanation.getImplementingClass());Assert.assertEquals(2, ((StreamExplanation) explanation).getChildren().size());}}-+@Testpublic void testRankStream() throws Exception {String expressionString;-+// Basic test- try (RankStream stream = new RankStream(StreamExpressionParser.parse("top("- + "n=3,"- + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc,a_i asc\"),"- + "sort=\"a_f asc, a_i asc\")"), factory)) {+ try (RankStream stream =+ new RankStream(+ StreamExpressionParser.parse(+ "top("+ + "n=3,"+ + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc,a_i asc\"),"+ + "sort=\"a_f asc, a_i asc\")"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("top", explanation.getFunctionName());Assert.assertEquals(RankStream.class.getName(), explanation.getImplementingClass());@@ -162,30 +190,35 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {@Testpublic void testReducerStream() throws Exception {String expressionString;-+// Basic test- try (ReducerStream stream = new ReducerStream(StreamExpressionParser.parse("reduce("- + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s desc, a_f asc\"),"- + "by=\"a_s\", group(sort=\"a_i desc\", n=\"5\"))"), factory)) {+ try (ReducerStream stream =+ new ReducerStream(+ StreamExpressionParser.parse(+ "reduce("+ + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s desc, a_f asc\"),"+ + "by=\"a_s\", group(sort=\"a_i desc\", n=\"5\"))"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("reduce", explanation.getFunctionName());Assert.assertEquals(ReducerStream.class.getName(), explanation.getImplementingClass());Assert.assertEquals(1, ((StreamExplanation) explanation).getChildren().size());}}-+@Test- // commented out on: 24-Dec-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018public void testUpdateStream() throws Exception {- StreamExpression expression = StreamExpressionParser.parse("update("- + "collection2, "- + "batchSize=5, "- + "search("- + "collection1, "- + "q=*:*, "- + "fl=\"id,a_s,a_i,a_f\", "- + "sort=\"a_f asc, a_i asc\"))");-+ StreamExpression expression =+ StreamExpressionParser.parse(+ "update("+ + "collection2, "+ + "batchSize=5, "+ + "search("+ + "collection1, "+ + "q=*:*, "+ + "fl=\"id,a_s,a_i,a_f\", "+ + "sort=\"a_f asc, a_i asc\"))");+try (UpdateStream updateStream = new UpdateStream(expression, factory)) {Explanation explanation = updateStream.toExplanation(factory);Assert.assertEquals("solr (collection2)", explanation.getFunctionName());@@ -194,28 +227,33 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {StreamExplanation updateExplanation = (StreamExplanation) explanation;Assert.assertEquals(1, updateExplanation.getChildren().size());Assert.assertEquals("update", updateExplanation.getChildren().get(0).getFunctionName());- Assert.assertEquals(UpdateStream.class.getName(), updateExplanation.getChildren().get(0).getImplementingClass());+ Assert.assertEquals(+ UpdateStream.class.getName(),+ updateExplanation.getChildren().get(0).getImplementingClass());}-}-+@Testpublic void testFacetStream() throws Exception {String expressionString;-+// Basic test- try (FacetStream stream = new FacetStream(StreamExpressionParser.parse("facet("- + "collection1, "- + "q=\"*:*\", "- + "buckets=\"a_s\", "- + "bucketSorts=\"sum(a_i) asc\", "- + "bucketSizeLimit=100, "- + "sum(a_i), sum(a_f), "- + "min(a_i), min(a_f), "- + "max(a_i), max(a_f), "- + "avg(a_i), avg(a_f), "- + "count(*)"- + ")"), factory)) {+ try (FacetStream stream =+ new FacetStream(+ StreamExpressionParser.parse(+ "facet("+ + "collection1, "+ + "q=\"*:*\", "+ + "buckets=\"a_s\", "+ + "bucketSorts=\"sum(a_i) asc\", "+ + "bucketSizeLimit=100, "+ + "sum(a_i), sum(a_f), "+ + "min(a_i), min(a_f), "+ + "max(a_i), max(a_f), "+ + "avg(a_i), avg(a_f), "+ + "count(*)"+ + ")"),+ factory)) {expressionString = stream.toExpression(factory).toString();Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("facet", explanation.getFunctionName());@@ -223,13 +261,17 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {Assert.assertEquals(1, ((StreamExplanation) explanation).getChildren().size());}}-+@Testpublic void testJDBCStream() throws Exception {String expressionString;-+// Basic test- try (JDBCStream stream = new JDBCStream(StreamExpressionParser.parse("jdbc(connection=\"jdbc:hsqldb:mem:.\", sql=\"select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE order by PEOPLE.ID\", sort=\"ID asc\")"), factory)) {+ try (JDBCStream stream =+ new JDBCStream(+ StreamExpressionParser.parse(+ "jdbc(connection=\"jdbc:hsqldb:mem:.\", sql=\"select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE order by PEOPLE.ID\", sort=\"ID asc\")"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("jdbc", explanation.getFunctionName());Assert.assertEquals(JDBCStream.class.getName(), explanation.getImplementingClass());@@ -237,15 +279,19 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {}}- @Test+ @Testpublic void testIntersectStream() throws Exception {String expressionString;-+// Basic test- try (IntersectStream stream = new IntersectStream(StreamExpressionParser.parse("intersect("- + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f, a_s\")"), factory)) {+ try (IntersectStream stream =+ new IntersectStream(+ StreamExpressionParser.parse(+ "intersect("+ + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f, a_s\")"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("intersect", explanation.getFunctionName());Assert.assertEquals(IntersectStream.class.getName(), explanation.getImplementingClass());@@ -253,15 +299,19 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {}}- @Test+ @Testpublic void testComplementStream() throws Exception {String expressionString;-+// Basic test- try (ComplementStream stream = new ComplementStream(StreamExpressionParser.parse("complement("- + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"- + "on=\"a_f, a_s\")"), factory)) {+ try (ComplementStream stream =+ new ComplementStream(+ StreamExpressionParser.parse(+ "complement("+ + "search(collection1, q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "search(collection1, q=\"id:(1 2)\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_s asc\"),"+ + "on=\"a_f, a_s\")"),+ factory)) {Explanation explanation = stream.toExplanation(factory);Assert.assertEquals("complement", explanation.getFunctionName());Assert.assertEquals(ComplementStream.class.getName(), explanation.getImplementingClass());diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.javaindex 50b60c5c3bb..1f2f45812cb 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java@@ -67,318 +67,373 @@ import org.junit.Ignore;import org.junit.Test;/**-* All base tests will be done with CloudSolrStream. Under the covers CloudSolrStream uses SolrStream so-* SolrStream will get fully exercised through these tests.-*-**/-+ * All base tests will be done with CloudSolrStream. Under the covers CloudSolrStream uses+ * SolrStream so SolrStream will get fully exercised through these tests.+ */@SolrTestCaseJ4.SuppressSSL[email protected]({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})[email protected]({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})public class StreamingTest extends SolrCloudTestCase {-public static final String COLLECTIONORALIAS = "streams";-public static final String MULTI_REPLICA_COLLECTIONORALIAS = "streams-multi-replica";--private static final StreamFactory streamFactory = new StreamFactory()- .withFunctionName("search", CloudSolrStream.class)- .withFunctionName("merge", MergeStream.class)- .withFunctionName("unique", UniqueStream.class)- .withFunctionName("top", RankStream.class)- .withFunctionName("reduce", ReducerStream.class)- .withFunctionName("group", GroupOperation.class)- .withFunctionName("rollup", RollupStream.class)- .withFunctionName("parallel", ParallelStream.class);--private static String zkHost;--private static int numShards;-private static int numWorkers;-private static boolean useAlias;--@BeforeClass-public static void configureCluster() throws Exception {- numShards = random().nextInt(2) + 1; //1 - 3- numWorkers = numShards > 2 ? random().nextInt(numShards - 1) + 1 : numShards;- configureCluster(numShards)- .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))- .configure();-- String collection;- useAlias = random().nextBoolean();- if (useAlias) {- collection = COLLECTIONORALIAS + "_collection";- } else {- collection = COLLECTIONORALIAS;+ public static final String COLLECTIONORALIAS = "streams";+ public static final String MULTI_REPLICA_COLLECTIONORALIAS = "streams-multi-replica";++ private static final StreamFactory streamFactory =+ new StreamFactory()+ .withFunctionName("search", CloudSolrStream.class)+ .withFunctionName("merge", MergeStream.class)+ .withFunctionName("unique", UniqueStream.class)+ .withFunctionName("top", RankStream.class)+ .withFunctionName("reduce", ReducerStream.class)+ .withFunctionName("group", GroupOperation.class)+ .withFunctionName("rollup", RollupStream.class)+ .withFunctionName("parallel", ParallelStream.class);++ private static String zkHost;++ private static int numShards;+ private static int numWorkers;+ private static boolean useAlias;++ @BeforeClass+ public static void configureCluster() throws Exception {+ numShards = random().nextInt(2) + 1; // 1 - 3+ numWorkers = numShards > 2 ? random().nextInt(numShards - 1) + 1 : numShards;+ configureCluster(numShards)+ .addConfig(+ "conf",+ getFile("solrj")+ .toPath()+ .resolve("solr")+ .resolve("configsets")+ .resolve("streaming")+ .resolve("conf"))+ .configure();++ String collection;+ useAlias = random().nextBoolean();+ if (useAlias) {+ collection = COLLECTIONORALIAS + "_collection";+ } else {+ collection = COLLECTIONORALIAS;+ }+ CollectionAdminRequest.createCollection(collection, "conf", numShards, 1)+ .process(cluster.getSolrClient());+ cluster.waitForActiveCollection(collection, numShards, numShards);+ if (useAlias) {+ CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection)+ .process(cluster.getSolrClient());+ }++ zkHost = cluster.getZkServer().getZkAddress();+ streamFactory.withCollectionZkHost(COLLECTIONORALIAS, zkHost);++ // Set up multi-replica collection+ if (useAlias) {+ collection = MULTI_REPLICA_COLLECTIONORALIAS + "_collection";+ } else {+ collection = MULTI_REPLICA_COLLECTIONORALIAS;+ }+ CollectionAdminRequest.createCollection(collection, "conf", numShards, 1, 1, 1)+ .process(cluster.getSolrClient());+ cluster.waitForActiveCollection(collection, numShards, numShards * 3);+ if (useAlias) {+ CollectionAdminRequest.createAlias(MULTI_REPLICA_COLLECTIONORALIAS, collection)+ .process(cluster.getSolrClient());+ }+ streamFactory.withCollectionZkHost(MULTI_REPLICA_COLLECTIONORALIAS, zkHost);}- CollectionAdminRequest.createCollection(collection, "conf", numShards, 1)- .process(cluster.getSolrClient());- cluster.waitForActiveCollection(collection, numShards, numShards);- if (useAlias) {- CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());++ private static final String id = "id";++ @Before+ public void clearCollection() throws Exception {+ new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTIONORALIAS);}- zkHost = cluster.getZkServer().getZkAddress();- streamFactory.withCollectionZkHost(COLLECTIONORALIAS, zkHost);+ @Test+ public void testUniqueStream() throws Exception {++ // Test CloudSolrStream and UniqueStream+ new UpdateRequest()+ .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")+ .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")+ .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")+ .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")+ .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);- // Set up multi-replica collection- if (useAlias) {- collection = MULTI_REPLICA_COLLECTIONORALIAS + "_collection";- } else {- collection = MULTI_REPLICA_COLLECTIONORALIAS;+ StreamContext streamContext = new StreamContext();+ SolrClientCache solrClientCache = new SolrClientCache();+ streamContext.setSolrClientCache(solrClientCache);+ try {+ SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");+ CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);+ UniqueStream ustream = new UniqueStream(stream, new FieldEqualitor("a_f"));+ ustream.setStreamContext(streamContext);+ List<Tuple> tuples = getTuples(ustream);+ assertEquals(4, tuples.size());+ assertOrder(tuples, 0, 1, 3, 4);+ } finally {+ solrClientCache.close();+ }}- CollectionAdminRequest.createCollection(collection, "conf", numShards, 1, 1, 1)- .process(cluster.getSolrClient());- cluster.waitForActiveCollection(collection, numShards, numShards * 3);- if (useAlias) {- CollectionAdminRequest.createAlias(MULTI_REPLICA_COLLECTIONORALIAS, collection).process(cluster.getSolrClient());++ @Test+ public void testSpacesInParams() throws Exception {++ SolrParams sParams =+ params("q", "*:*", "fl", "id , a_s , a_i , a_f", "sort", "a_f asc , a_i asc");++ // CloudSolrStream compares the values of the sort with the fl field.+ // The constructor will throw an exception if the sort fields do not the+ // a value in the field list.++ CloudSolrStream stream = new CloudSolrStream("", "collection1", sParams);+ stream.close();}- streamFactory.withCollectionZkHost(MULTI_REPLICA_COLLECTIONORALIAS, zkHost);-}-private static final String id = "id";+ @Test+ public void testNonePartitionKeys() throws Exception {-@Before-public void clearCollection() throws Exception {- new UpdateRequest()- .deleteByQuery("*:*")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);-}+ new UpdateRequest()+ .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1")+ .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2")+ .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")+ .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")+ .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5")+ .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6")+ .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7")+ .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8")+ .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9")+ .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ StreamContext streamContext = new StreamContext();+ SolrClientCache solrClientCache = new SolrClientCache();+ streamContext.setSolrClientCache(solrClientCache);+ try {-@Test-public void testUniqueStream() throws Exception {-- //Test CloudSolrStream and UniqueStream- new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);-- StreamContext streamContext = new StreamContext();- SolrClientCache solrClientCache = new SolrClientCache();- streamContext.setSolrClientCache(solrClientCache);- try {- SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);- UniqueStream ustream = new UniqueStream(stream, new FieldEqualitor("a_f"));- ustream.setStreamContext(streamContext);- List<Tuple> tuples = getTuples(ustream);- assertEquals(4, tuples.size());- assertOrder(tuples, 0, 1, 3, 4);- } finally {- solrClientCache.close();+ SolrParams sParamsA =+ params(+ "q",+ "*:*",+ "fl",+ "id,a_s,a_i,a_f",+ "sort",+ "a_s asc,a_f asc",+ "partitionKeys",+ "none",+ "qt",+ "/export");+ CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);+ ParallelStream pstream =+ parallelStream(stream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));+ attachStreamFactory(pstream);+ pstream.setStreamContext(streamContext);+ List<Tuple> tuples = getTuples(pstream);++ assert (tuples.size() == (10 * numWorkers)); // Each tuple will be double counted.+ } finally {+ solrClientCache.close();+ }}-}-@Test-public void testSpacesInParams() throws Exception {+ @Test+ public void testParallelUniqueStream() throws Exception {- SolrParams sParams = params("q", "*:*", "fl", "id , a_s , a_i , a_f", "sort", "a_f asc , a_i asc");+ new UpdateRequest()+ .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")+ .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")+ .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")+ .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")+ .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1")+ .add(id, "5", "a_s", "hello1", "a_i", "10", "a_f", "1")+ .add(id, "6", "a_s", "hello1", "a_i", "11", "a_f", "5")+ .add(id, "7", "a_s", "hello1", "a_i", "12", "a_f", "5")+ .add(id, "8", "a_s", "hello1", "a_i", "13", "a_f", "4")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);- //CloudSolrStream compares the values of the sort with the fl field.- //The constructor will throw an exception if the sort fields do not the- //a value in the field list.+ StreamContext streamContext = new StreamContext();+ SolrClientCache solrClientCache = new SolrClientCache();+ streamContext.setSolrClientCache(solrClientCache);- CloudSolrStream stream = new CloudSolrStream("", "collection1", sParams);- stream.close();-}+ try {-@Test-public void testNonePartitionKeys() throws Exception {-- new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1")- .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")- .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5")- .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6")- .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7")- .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8")- .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9")- .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamContext streamContext = new StreamContext();- SolrClientCache solrClientCache = new SolrClientCache();- streamContext.setSolrClientCache(solrClientCache);- try {-- SolrParams sParamsA = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_s asc,a_f asc", "partitionKeys", "none", "qt", "/export");- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- ParallelStream pstream = parallelStream(stream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));- attachStreamFactory(pstream);- pstream.setStreamContext(streamContext);- List<Tuple> tuples = getTuples(pstream);-- assert (tuples.size() == (10 * numWorkers)); // Each tuple will be double counted.- } finally {- solrClientCache.close();+ SolrParams sParams =+ params(+ "q",+ "*:*",+ "fl",+ "id,a_s,a_i,a_f",+ "sort",+ "a_f asc,a_i asc",+ "partitionKeys",+ "a_f",+ "qt",+ "/export");+ CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);+ UniqueStream ustream = new UniqueStream(stream, new FieldEqualitor("a_f"));+ ParallelStream pstream =+ parallelStream(ustream, new FieldComparator("a_f", ComparatorOrder.ASCENDING));+ attachStreamFactory(pstream);+ pstream.setStreamContext(streamContext);+ List<Tuple> tuples = getTuples(pstream);+ assertEquals(5, tuples.size());+ assertOrder(tuples, 0, 1, 3, 4, 6);++ // Test the eofTuples++ Map<String, Tuple> eofTuples = pstream.getEofTuples();+ assertEquals(numWorkers, eofTuples.size()); // There should be an EOF tuple for each worker.+ } finally {+ solrClientCache.close();+ }}-}-@Test-public void testParallelUniqueStream() throws Exception {+ @Test+ public void testMultipleFqClauses() throws Exception {- new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1")- .add(id, "5", "a_s", "hello1", "a_i", "10", "a_f", "1")- .add(id, "6", "a_s", "hello1", "a_i", "11", "a_f", "5")- .add(id, "7", "a_s", "hello1", "a_i", "12", "a_f", "5")- .add(id, "8", "a_s", "hello1", "a_i", "13", "a_f", "4")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ new UpdateRequest()+ .add(id, "0", "a_ss", "hello0", "a_ss", "hello1", "a_i", "0", "a_f", "0")+ .add(id, "2", "a_ss", "hello2", "a_i", "2", "a_f", "0")+ .add(id, "3", "a_ss", "hello3", "a_i", "3", "a_f", "3")+ .add(id, "4", "a_ss", "hello4", "a_i", "4", "a_f", "4")+ .add(id, "1", "a_ss", "hello1", "a_i", "1", "a_f", "1")+ .add(id, "5", "a_ss", "hello1", "a_i", "10", "a_f", "1")+ .add(id, "6", "a_ss", "hello1", "a_i", "11", "a_f", "5")+ .add(id, "7", "a_ss", "hello1", "a_i", "12", "a_f", "5")+ .add(id, "8", "a_ss", "hello1", "a_i", "13", "a_f", "4")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);- StreamContext streamContext = new StreamContext();- SolrClientCache solrClientCache = new SolrClientCache();- streamContext.setSolrClientCache(solrClientCache);+ streamFactory.withCollectionZkHost(COLLECTIONORALIAS, zkHost);- try {+ StreamContext streamContext = new StreamContext();+ SolrClientCache solrClientCache = new SolrClientCache();+ streamContext.setSolrClientCache(solrClientCache);- SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc", "partitionKeys", "a_f", "qt", "/export");- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);- UniqueStream ustream = new UniqueStream(stream, new FieldEqualitor("a_f"));- ParallelStream pstream = parallelStream(ustream, new FieldComparator("a_f", ComparatorOrder.ASCENDING));- attachStreamFactory(pstream);- pstream.setStreamContext(streamContext);- List<Tuple> tuples = getTuples(pstream);- assertEquals(5, tuples.size());- assertOrder(tuples, 0, 1, 3, 4, 6);-- //Test the eofTuples-- Map<String, Tuple> eofTuples = pstream.getEofTuples();- assertEquals(numWorkers, eofTuples.size()); //There should be an EOF tuple for each worker.- }finally {- solrClientCache.close();+ try {+ ModifiableSolrParams params =+ new ModifiableSolrParams(+ params(+ "q",+ "*:*",+ "fl",+ "id,a_i",+ "sort",+ "a_i asc",+ "fq",+ "a_ss:hello0",+ "fq",+ "a_ss:hello1"));+ CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, params);+ stream.setStreamContext(streamContext);+ List<Tuple> tuples = getTuples(stream);+ assertEquals("Multiple fq clauses should have been honored", 1, tuples.size());+ assertEquals("should only have gotten back document 0", "0", tuples.get(0).getString("id"));+ } finally {+ solrClientCache.close();+ }}-}+ @Test+ public void testRankStream() throws Exception {-@Test-public void testMultipleFqClauses() throws Exception {-- new UpdateRequest()- .add(id, "0", "a_ss", "hello0", "a_ss", "hello1", "a_i", "0", "a_f", "0")- .add(id, "2", "a_ss", "hello2", "a_i", "2", "a_f", "0")- .add(id, "3", "a_ss", "hello3", "a_i", "3", "a_f", "3")- .add(id, "4", "a_ss", "hello4", "a_i", "4", "a_f", "4")- .add(id, "1", "a_ss", "hello1", "a_i", "1", "a_f", "1")- .add(id, "5", "a_ss", "hello1", "a_i", "10", "a_f", "1")- .add(id, "6", "a_ss", "hello1", "a_i", "11", "a_f", "5")- .add(id, "7", "a_ss", "hello1", "a_i", "12", "a_f", "5")- .add(id, "8", "a_ss", "hello1", "a_i", "13", "a_f", "4")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);-- streamFactory.withCollectionZkHost(COLLECTIONORALIAS, zkHost);-- StreamContext streamContext = new StreamContext();- SolrClientCache solrClientCache = new SolrClientCache();- streamContext.setSolrClientCache(solrClientCache);-- try {- ModifiableSolrParams params = new ModifiableSolrParams(params("q", "*:*", "fl", "id,a_i",- "sort", "a_i asc", "fq", "a_ss:hello0", "fq", "a_ss:hello1"));- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, params);- stream.setStreamContext(streamContext);- List<Tuple> tuples = getTuples(stream);- assertEquals("Multiple fq clauses should have been honored", 1, tuples.size());- assertEquals("should only have gotten back document 0", "0", tuples.get(0).getString("id"));- } finally {- solrClientCache.close();- }-}+ new UpdateRequest()+ .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")+ .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")+ .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")+ .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")+ .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);-@Test-public void testRankStream() throws Exception {-- new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")- .add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);-- StreamContext streamContext = new StreamContext();- SolrClientCache solrClientCache = new SolrClientCache();- streamContext.setSolrClientCache(solrClientCache);- try {- SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i asc");- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);- RankStream rstream = new RankStream(stream, 3, new FieldComparator("a_i", ComparatorOrder.DESCENDING));- rstream.setStreamContext(streamContext);- List<Tuple> tuples = getTuples(rstream);- assertEquals(3, tuples.size());- assertOrder(tuples, 4, 3, 2);- } finally {- solrClientCache.close();+ StreamContext streamContext = new StreamContext();+ SolrClientCache solrClientCache = new SolrClientCache();+ streamContext.setSolrClientCache(solrClientCache);+ try {+ SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i asc");+ CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);+ RankStream rstream =+ new RankStream(stream, 3, new FieldComparator("a_i", ComparatorOrder.DESCENDING));+ rstream.setStreamContext(streamContext);+ List<Tuple> tuples = getTuples(rstream);+ assertEquals(3, tuples.size());+ assertOrder(tuples, 4, 3, 2);+ } finally {+ solrClientCache.close();+ }}-}-@Test-public void testParallelRankStream() throws Exception {-- new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")- .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")- .add(id, "5", "a_s", "hello1", "a_i", "5", "a_f", "1")- .add(id, "6", "a_s", "hello1", "a_i", "6", "a_f", "1")- .add(id, "7", "a_s", "hello1", "a_i", "7", "a_f", "1")- .add(id, "8", "a_s", "hello1", "a_i", "8", "a_f", "1")- .add(id, "9", "a_s", "hello1", "a_i", "9", "a_f", "1")- .add(id, "10", "a_s", "hello1", "a_i", "10", "a_f", "1")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);-- StreamContext streamContext = new StreamContext();- SolrClientCache solrClientCache = new SolrClientCache();- streamContext.setSolrClientCache(solrClientCache);- try {- SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i asc", "partitionKeys", "a_i", "qt", "/export");- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);- RankStream rstream = new RankStream(stream, 11, new FieldComparator("a_i", ComparatorOrder.DESCENDING));- ParallelStream pstream = parallelStream(rstream, new FieldComparator("a_i", ComparatorOrder.DESCENDING));- attachStreamFactory(pstream);- pstream.setStreamContext(streamContext);- List<Tuple> tuples = getTuples(pstream);-- assertEquals(10, tuples.size());- assertOrder(tuples, 10, 9, 8, 7, 6, 5, 4, 3, 2, 0);- } finally {- solrClientCache.close();- }+ @Test+ public void testParallelRankStream() throws Exception {-}+ new UpdateRequest()+ .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")+ .add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")+ .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")+ .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")+ .add(id, "5", "a_s", "hello1", "a_i", "5", "a_f", "1")+ .add(id, "6", "a_s", "hello1", "a_i", "6", "a_f", "1")+ .add(id, "7", "a_s", "hello1", "a_i", "7", "a_f", "1")+ .add(id, "8", "a_s", "hello1", "a_i", "8", "a_f", "1")+ .add(id, "9", "a_s", "hello1", "a_i", "9", "a_f", "1")+ .add(id, "10", "a_s", "hello1", "a_i", "10", "a_f", "1")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);-@Test+ StreamContext streamContext = new StreamContext();+ SolrClientCache solrClientCache = new SolrClientCache();+ streamContext.setSolrClientCache(solrClientCache);+ try {+ SolrParams sParams =+ params(+ "q",+ "*:*",+ "fl",+ "id,a_s,a_i",+ "sort",+ "a_i asc",+ "partitionKeys",+ "a_i",+ "qt",+ "/export");+ CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);+ RankStream rstream =+ new RankStream(stream, 11, new FieldComparator("a_i", ComparatorOrder.DESCENDING));+ ParallelStream pstream =+ parallelStream(rstream, new FieldComparator("a_i", ComparatorOrder.DESCENDING));+ attachStreamFactory(pstream);+ pstream.setStreamContext(streamContext);+ List<Tuple> tuples = getTuples(pstream);++ assertEquals(10, tuples.size());+ assertOrder(tuples, 10, 9, 8, 7, 6, 5, 4, 3, 2, 0);+ } finally {+ solrClientCache.close();+ }+ }++ @Testpublic void testTrace() throws Exception {new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1")- .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2")- .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")- .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")- .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5")- .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6")- .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7")- .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8")- .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9")- .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10")- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);+ .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1")+ .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2")+ .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")+ .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")+ .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5")+ .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6")+ .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7")+ .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8")+ .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9")+ .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10")+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);try {- //Test with spaces in the parameter lists.- SolrParams sParamsA = params("q", "*:*", "fl", "id,a_s, a_i,a_f", "sort", "a_s asc,a_f asc");+ // Test with spaces in the parameter lists.+ SolrParams sParamsA =+ params("q", "*:*", "fl", "id,a_s, a_i,a_f", "sort", "a_s asc,a_f asc");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);stream.setTrace(true);stream.setStreamContext(streamContext);@@ -413,12 +468,15 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- //Test with spaces in the parameter lists.- SolrParams sParamsA = params("q", "*:*", "fl", "id,a_s, a_i, a_f", "sort", "a_s asc , a_f asc");+ // Test with spaces in the parameter lists.+ SolrParams sParamsA =+ params("q", "*:*", "fl", "id,a_s, a_i, a_f", "sort", "a_s asc , a_f asc");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- ReducerStream rstream = new ReducerStream(stream,- new FieldEqualitor("a_s"),- new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 5));+ ReducerStream rstream =+ new ReducerStream(+ stream,+ new FieldEqualitor("a_s"),+ new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 5));rstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(rstream);@@ -426,23 +484,25 @@ public void testParallelRankStream() throws Exception {assertEquals(3, tuples.size());Tuple t0 = tuples.get(0);- List<Map<?,?>> maps0 = t0.getMaps("group");+ List<Map<?, ?>> maps0 = t0.getMaps("group");assertMaps(maps0, 0, 2, 1, 9);Tuple t1 = tuples.get(1);- List<Map<?,?>> maps1 = t1.getMaps("group");+ List<Map<?, ?>> maps1 = t1.getMaps("group");assertMaps(maps1, 3, 5, 7, 8);Tuple t2 = tuples.get(2);- List<Map<?,?>> maps2 = t2.getMaps("group");+ List<Map<?, ?>> maps2 = t2.getMaps("group");assertMaps(maps2, 4, 6);- //Test with spaces in the parameter lists using a comparator+ // Test with spaces in the parameter lists using a comparatorsParamsA = params("q", "*:*", "fl", "id,a_s, a_i, a_f", "sort", "a_s asc , a_f asc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- rstream = new ReducerStream(stream,- new FieldComparator("a_s", ComparatorOrder.ASCENDING),- new GroupOperation(new FieldComparator("a_f", ComparatorOrder.DESCENDING), 5));+ rstream =+ new ReducerStream(+ stream,+ new FieldComparator("a_s", ComparatorOrder.ASCENDING),+ new GroupOperation(new FieldComparator("a_f", ComparatorOrder.DESCENDING), 5));rstream.setStreamContext(streamContext);tuples = getTuples(rstream);@@ -467,7 +527,7 @@ public void testParallelRankStream() throws Exception {@Testpublic void testZeroReducerStream() throws Exception {- //Gracefully handle zero results+ // Gracefully handle zero resultsnew UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1").add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2")@@ -486,12 +546,15 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- //Test with spaces in the parameter lists.- SolrParams sParamsA = params("q", "blah", "fl", "id,a_s, a_i, a_f", "sort", "a_s asc , a_f asc");+ // Test with spaces in the parameter lists.+ SolrParams sParamsA =+ params("q", "blah", "fl", "id,a_s, a_i, a_f", "sort", "a_s asc , a_f asc");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- ReducerStream rstream = new ReducerStream(stream,- new FieldEqualitor("a_s"),- new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 5));+ ReducerStream rstream =+ new ReducerStream(+ stream,+ new FieldEqualitor("a_s"),+ new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 5));rstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(rstream);@@ -522,13 +585,27 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- SolrParams sParamsA = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_s asc,a_f asc", "partitionKeys", "a_s", "qt", "/export");+ SolrParams sParamsA =+ params(+ "q",+ "*:*",+ "fl",+ "id,a_s,a_i,a_f",+ "sort",+ "a_s asc,a_f asc",+ "partitionKeys",+ "a_s",+ "qt",+ "/export");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- ReducerStream rstream = new ReducerStream(stream,- new FieldEqualitor("a_s"),- new GroupOperation(new FieldComparator("a_f", ComparatorOrder.DESCENDING), 5));- ParallelStream pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));+ ReducerStream rstream =+ new ReducerStream(+ stream,+ new FieldEqualitor("a_s"),+ new GroupOperation(new FieldComparator("a_f", ComparatorOrder.DESCENDING), 5));+ ParallelStream pstream =+ parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));attachStreamFactory(pstream);pstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(pstream);@@ -536,25 +613,38 @@ public void testParallelRankStream() throws Exception {assertEquals(3, tuples.size());Tuple t0 = tuples.get(0);- List<Map<?,?>> maps0 = t0.getMaps("group");+ List<Map<?, ?>> maps0 = t0.getMaps("group");assertMaps(maps0, 9, 1, 2, 0);Tuple t1 = tuples.get(1);- List<Map<?,?>> maps1 = t1.getMaps("group");+ List<Map<?, ?>> maps1 = t1.getMaps("group");assertMaps(maps1, 8, 7, 5, 3);Tuple t2 = tuples.get(2);- List<Map<?,?>> maps2 = t2.getMaps("group");+ List<Map<?, ?>> maps2 = t2.getMaps("group");assertMaps(maps2, 6, 4);- //Test Descending with Ascending subsort-- sParamsA = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_s desc,a_f asc", "partitionKeys", "a_s", "qt", "/export");+ // Test Descending with Ascending subsort++ sParamsA =+ params(+ "q",+ "*:*",+ "fl",+ "id,a_s,a_i,a_f",+ "sort",+ "a_s desc,a_f asc",+ "partitionKeys",+ "a_s",+ "qt",+ "/export");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- rstream = new ReducerStream(stream,- new FieldEqualitor("a_s"),- new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 3));+ rstream =+ new ReducerStream(+ stream,+ new FieldEqualitor("a_s"),+ new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 3));pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.DESCENDING));attachStreamFactory(pstream);pstream.setStreamContext(streamContext);@@ -598,7 +688,7 @@ public void testParallelRankStream() throws Exception {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- //Test an error that comes originates from the /select handler+ // Test an error that comes originates from the /select handlertry {SolrParams sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,blah", "sort", "blah asc");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);@@ -609,7 +699,7 @@ public void testParallelRankStream() throws Exception {assertTrue(t.EXCEPTION);assertTrue(t.getException().contains("sort param field can't be found: blah"));- //Test an error that comes originates from the /export handler+ // Test an error that comes originates from the /export handlersParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,score", "sort", "a_s asc", "qt", "/export");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);estream = new ExceptionStream(stream);@@ -617,7 +707,7 @@ public void testParallelRankStream() throws Exception {t = getTuple(estream);assertTrue(t.EOF);assertTrue(t.EXCEPTION);- //The /export handler will pass through a real exception.+ // The /export handler will pass through a real exception.assertTrue(t.getException().contains("undefined field:"));} finally {solrClientCache.close();@@ -643,35 +733,73 @@ public void testParallelRankStream() throws Exception {SolrParams sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,blah", "sort", "blah asc");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- ParallelStream pstream = new ParallelStream(zkHost, COLLECTIONORALIAS, stream, 2, new FieldComparator("blah", ComparatorOrder.ASCENDING));+ ParallelStream pstream =+ new ParallelStream(+ zkHost,+ COLLECTIONORALIAS,+ stream,+ 2,+ new FieldComparator("blah", ComparatorOrder.ASCENDING));ExceptionStream estream = new ExceptionStream(pstream);Tuple t = getTuple(estream);assertTrue(t.EOF);assertTrue(t.EXCEPTION);- //ParallelStream requires that partitionKeys be set.+ // ParallelStream requires that partitionKeys be set.assertTrue(t.getException().contains("When numWorkers > 1 partitionKeys must be set."));-- //Test an error that originates from the /select handler- sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,blah", "sort", "blah asc", "partitionKeys", "a_s", "qt", "/export");+ // Test an error that originates from the /select handler+ sParamsA =+ params(+ "q",+ "*:*",+ "fl",+ "a_s,a_i,a_f,blah",+ "sort",+ "blah asc",+ "partitionKeys",+ "a_s",+ "qt",+ "/export");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- pstream = new ParallelStream(zkHost, COLLECTIONORALIAS, stream, 2, new FieldComparator("blah", ComparatorOrder.ASCENDING));+ pstream =+ new ParallelStream(+ zkHost,+ COLLECTIONORALIAS,+ stream,+ 2,+ new FieldComparator("blah", ComparatorOrder.ASCENDING));estream = new ExceptionStream(pstream);t = getTuple(estream);assertTrue(t.EOF);assertTrue(t.EXCEPTION);assertTrue(t.getException().contains("sort param field can't be found: blah"));-- //Test an error that originates from the /export handler- sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,score", "sort", "a_s asc", "qt", "/export", "partitionKeys", "a_s");+ // Test an error that originates from the /export handler+ sParamsA =+ params(+ "q",+ "*:*",+ "fl",+ "a_s,a_i,a_f,score",+ "sort",+ "a_s asc",+ "qt",+ "/export",+ "partitionKeys",+ "a_s");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- pstream = new ParallelStream(zkHost, COLLECTIONORALIAS, stream, 2, new FieldComparator("a_s", ComparatorOrder.ASCENDING));+ pstream =+ new ParallelStream(+ zkHost,+ COLLECTIONORALIAS,+ stream,+ 2,+ new FieldComparator("a_s", ComparatorOrder.ASCENDING));estream = new ExceptionStream(pstream);t = getTuple(estream);assertTrue(t.EOF);assertTrue(t.EXCEPTION);- //The /export handler will pass through a real exception.+ // The /export handler will pass through a real exception.assertTrue(t.getException().contains("undefined field:"));}@@ -698,15 +826,17 @@ public void testParallelRankStream() throws Exception {try {SolrParams sParamsA = params("q", "*:*");- Metric[] metrics = {new SumMetric("a_i"),- new SumMetric("a_f"),- new MinMetric("a_i"),- new MinMetric("a_f"),- new MaxMetric("a_i"),- new MaxMetric("a_f"),- new MeanMetric("a_i"),- new MeanMetric("a_f"),- new CountMetric()};+ Metric[] metrics = {+ new SumMetric("a_i"),+ new SumMetric("a_f"),+ new MinMetric("a_i"),+ new MinMetric("a_f"),+ new MaxMetric("a_i"),+ new MaxMetric("a_f"),+ new MeanMetric("a_i"),+ new MeanMetric("a_f"),+ new CountMetric()+ };StatsStream statsStream = new StatsStream(zkHost, COLLECTIONORALIAS, sParamsA, metrics);statsStream.setStreamContext(streamContext);@@ -714,7 +844,7 @@ public void testParallelRankStream() throws Exception {assertEquals(1, tuples.size());- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);@@ -767,26 +897,28 @@ public void testParallelRankStream() throws Exception {Bucket[] buckets = {new Bucket("a_s")};- Metric[] metrics = {new SumMetric("a_i"),- new SumMetric("a_f"),- new MinMetric("a_i"),- new MinMetric("a_f"),- new MaxMetric("a_i"),- new MaxMetric("a_f"),- new MeanMetric("a_i"),- new MeanMetric("a_f"),- new CountMetric()};+ Metric[] metrics = {+ new SumMetric("a_i"),+ new SumMetric("a_f"),+ new MinMetric("a_i"),+ new MinMetric("a_f"),+ new MaxMetric("a_i"),+ new MaxMetric("a_f"),+ new MeanMetric("a_i"),+ new MeanMetric("a_f"),+ new CountMetric()+ };- FieldComparator[] sorts = {new FieldComparator("sum(a_i)",- ComparatorOrder.ASCENDING)};+ FieldComparator[] sorts = {new FieldComparator("sum(a_i)", ComparatorOrder.ASCENDING)};- FacetStream facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);+ FacetStream facetStream =+ new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);List<Tuple> tuples = getTuples(facetStream);assert (tuples.size() == 3);- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);String bucket = tuple.getString("a_s");@@ -857,18 +989,18 @@ public void testParallelRankStream() throws Exception {assertEquals(6.5, avgf.doubleValue(), 0.01);assertEquals(4, count.doubleValue(), 0.01);-- //Reverse the Sort.+ // Reverse the Sort.sorts[0] = new FieldComparator("sum(a_i)", ComparatorOrder.DESCENDING);- facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);+ facetStream =+ new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);tuples = getTuples(facetStream);assertEquals(3, tuples.size());- //Test Long and Double Sums+ // Test Long and Double Sumstuple = tuples.get(0);bucket = tuple.getString("a_s");@@ -939,20 +1071,18 @@ public void testParallelRankStream() throws Exception {assertEquals(5.5, avgf.doubleValue(), 0.01);assertEquals(2, count.doubleValue(), 0.01);-- //Test index sort+ // Test index sortsorts[0] = new FieldComparator("a_s", ComparatorOrder.DESCENDING);-- facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);+ facetStream =+ new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);facetStream.setStreamContext(streamContext);tuples = getTuples(facetStream);assertEquals(3, tuples.size());-tuple = tuples.get(0);bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");@@ -965,7 +1095,6 @@ public void testParallelRankStream() throws Exception {avgf = tuple.getDouble("avg(a_f)");count = tuple.getDouble("count(*)");-assertEquals("hello4", bucket);assertEquals(15, sumi.longValue());assertEquals(11, sumf.doubleValue(), 0.01);@@ -1023,11 +1152,12 @@ public void testParallelRankStream() throws Exception {assertEquals(4.5, avgf.doubleValue(), 0.01);assertEquals(4, count.doubleValue(), 0.01);- //Test index sort+ // Test index sortsorts[0] = new FieldComparator("a_s", ComparatorOrder.ASCENDING);- facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);+ facetStream =+ new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);facetStream.setStreamContext(streamContext);tuples = getTuples(facetStream);@@ -1104,7 +1234,8 @@ public void testParallelRankStream() throws Exception {sorts[0] = new FieldComparator("a_s", ComparatorOrder.ASCENDING);- facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, -1);+ facetStream =+ new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, -1);facetStream.setStreamContext(streamContext);tuples = getTuples(facetStream);@@ -1115,7 +1246,6 @@ public void testParallelRankStream() throws Exception {}}-String[] docPairs(int base, String sSeq) {List<String> pairs = new ArrayList<>();final int iSeq = base * 100;@@ -1132,7 +1262,8 @@ public void testParallelRankStream() throws Exception {pairs.add("d_sing");pairs.add(Double.toString(iSeq + 5)); // 105pairs.add("dt_sing");- pairs.add(String.format(Locale.ROOT, "2000-01-01T%02d:00:00Z", base)); // Works as long as we add fewer than 60 docs+ // Works as long as we add fewer than 60 docs+ pairs.add(String.format(Locale.ROOT, "2000-01-01T%02d:00:00Z", base));pairs.add("b_sing");pairs.add((base % 2) == 0 ? "T" : "F"); // Tricky@@ -1141,79 +1272,103 @@ public void testParallelRankStream() throws Exception {}// Select and export should be identical sort orders I think.- private void checkSort(JettySolrRunner jetty, String field, String sortDir, String[] fields) throws IOException, SolrServerException {+ private void checkSort(JettySolrRunner jetty, String field, String sortDir, String[] fields)+ throws IOException, SolrServerException {// Comes back after after LUCENE-7548-// SolrQuery query = new SolrQuery("*:*");-// query.addSort(field, ("asc".equals(sortDir) ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc));-// query.addSort("id", SolrQuery.ORDER.asc);-// query.addField("id");-// query.addField(field);-// query.setRequestHandler("standard");-// query.setRows(100);-//-// List<String> selectOrder = new ArrayList<>();-//-// String url = jetty.getBaseUrl() + "/" + COLLECTION;-//-// try (HttpSolrClient client = getHttpSolrClient(url)) {-// client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);-// QueryResponse rsp = client.query(query);-// for (SolrDocument doc : rsp.getResults()) {-// selectOrder.add((String) doc.getFieldValue("id"));-// }-// }-// SolrParams exportParams = params("q", "*:*", "qt", "/export", "fl", "id," + field, "sort", field + " " + sortDir + ",id asc");-// try (CloudSolrStream solrStream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, exportParams)) {-// List<Tuple> tuples = getTuples(solrStream);-// assertEquals("There should be exactly 32 responses returned", 32, tuples.size());-// // Since the getTuples method doesn't return the EOF tuple, these two entries should be the same size.-// assertEquals("Tuple count should exactly match sort array size for field " + field + " sort order " + sortDir, selectOrder.size(), tuples.size());-//-// for (int idx = 0; idx < selectOrder.size(); ++idx) { // Tuples should be in lock step with the orders from select.-// assertEquals("Order for missing docValues fields wrong for field '" + field + "' sort direction '" + sortDir,-// tuples.get(idx).getString("id"), selectOrder.get(idx));-// }-// }+ // SolrQuery query = new SolrQuery("*:*");+ // query.addSort(field, ("asc".equals(sortDir) ? SolrQuery.ORDER.asc :+ // SolrQuery.ORDER.desc));+ // query.addSort("id", SolrQuery.ORDER.asc);+ // query.addField("id");+ // query.addField(field);+ // query.setRequestHandler("standard");+ // query.setRows(100);+ //+ // List<String> selectOrder = new ArrayList<>();+ //+ // String url = jetty.getBaseUrl() + "/" + COLLECTION;+ //+ // try (HttpSolrClient client = getHttpSolrClient(url)) {+ // client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);+ // QueryResponse rsp = client.query(query);+ // for (SolrDocument doc : rsp.getResults()) {+ // selectOrder.add((String) doc.getFieldValue("id"));+ // }+ // }+ // SolrParams exportParams = params("q", "*:*", "qt", "/export", "fl", "id," + field, "sort",+ // field + " " + sortDir + ",id asc");+ // try (CloudSolrStream solrStream = new CloudSolrStream(zkHost, COLLECTIONORALIAS,+ // exportParams)) {+ // List<Tuple> tuples = getTuples(solrStream);+ // assertEquals("There should be exactly 32 responses returned", 32, tuples.size());+ // // Since the getTuples method doesn't return the EOF tuple, these two entries should be+ // the same size.+ // assertEquals("Tuple count should exactly match sort array size for field " + field + "+ // sort order " + sortDir, selectOrder.size(), tuples.size());+ //+ // for (int idx = 0; idx < selectOrder.size(); ++idx) { // Tuples should be in lock step+ // with the orders from select.+ // assertEquals("Order for missing docValues fields wrong for field '" + field + "' sort+ // direction '" + sortDir,+ // tuples.get(idx).getString("id"), selectOrder.get(idx));+ // }+ // }// Remove below and uncomment above after LUCENE-7548- List<String> selectOrder = ("asc".equals(sortDir)) ? Arrays.asList(ascOrder) : Arrays.asList(descOrder);- List<String> selectOrderBool = ("asc".equals(sortDir)) ? Arrays.asList(ascOrderBool) : Arrays.asList(descOrderBool);- SolrParams exportParams = params("q", "*:*", "qt", "/export", "fl", "id," + field, "sort", field + " " + sortDir + ",id asc");+ List<String> selectOrder =+ ("asc".equals(sortDir)) ? Arrays.asList(ascOrder) : Arrays.asList(descOrder);+ List<String> selectOrderBool =+ ("asc".equals(sortDir)) ? Arrays.asList(ascOrderBool) : Arrays.asList(descOrderBool);+ SolrParams exportParams =+ params(+ "q",+ "*:*",+ "qt",+ "/export",+ "fl",+ "id," + field,+ "sort",+ field + " " + sortDir + ",id asc");StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- try (CloudSolrStream solrStream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, exportParams)) {+ try (CloudSolrStream solrStream =+ new CloudSolrStream(zkHost, COLLECTIONORALIAS, exportParams)) {solrStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(solrStream);assertEquals("There should be exactly 32 responses returned", 32, tuples.size());- // Since the getTuples method doesn't return the EOF tuple, these two entries should be the same size.- assertEquals("Tuple count should exactly match sort array size for field " + field + " sort order " + sortDir, selectOrder.size(), tuples.size());-- for (int idx = 0; idx < selectOrder.size(); ++idx) { // Tuples should be in lock step with the orders passed in.- assertEquals("Order for missing docValues fields wrong for field '" + field + "' sort direction '" + sortDir +- "' RESTORE GETTING selectOrder from select statement after LUCENE-7548",- tuples.get(idx).getString("id"), (field.startsWith("b_") ? selectOrderBool.get(idx) : selectOrder.get(idx)));+ // Since the getTuples method doesn't return the EOF tuple, these two entries should be the+ // same size.+ assertEquals(+ "Tuple count should exactly match sort array size for field "+ + field+ + " sort order "+ + sortDir,+ selectOrder.size(),+ tuples.size());++ // Tuples should be in lock step with the orders passed in.+ for (int idx = 0; idx < selectOrder.size(); ++idx) {+ assertEquals(+ "Order for missing docValues fields wrong for field '"+ + field+ + "' sort direction '"+ + sortDir+ + "' RESTORE GETTING selectOrder from select statement after LUCENE-7548",+ tuples.get(idx).getString("id"),+ (field.startsWith("b_") ? selectOrderBool.get(idx) : selectOrder.get(idx)));}} finally {solrClientCache.close();}}- static final String[] voidIds = new String[]{- "iii1",- "eee1",- "aaa1",- "ooo1",- "iii2",- "eee2",- "aaa2",- "ooo2",- "iii3",- "eee3",- "aaa3",- "ooo3"- };+ static final String[] voidIds =+ new String[] {+ "iii1", "eee1", "aaa1", "ooo1", "iii2", "eee2", "aaa2", "ooo2", "iii3", "eee3", "aaa3",+ "ooo3"+ };private void checkReturnValsForEmpty(String[] fields) throws IOException {@@ -1242,7 +1397,8 @@ public void testParallelRankStream() throws Exception {}} else {for (String f : fields) {- assertNotNull("Should have returned a value for field " + f + " doc " + id, tuple.get(f));+ assertNotNull(+ "Should have returned a value for field " + f + " doc " + id, tuple.get(f));}}}@@ -1252,53 +1408,56 @@ public void testParallelRankStream() throws Exception {}// Goes away after after LUCENE-7548- final static String[] ascOrder = new String[]{- "aaa1", "aaa2", "aaa3", "eee1",- "eee2", "eee3", "iii1", "iii2",- "iii3", "ooo1", "ooo2", "ooo3",- "aaa4", "eee4", "iii4", "ooo4",- "aaa5", "eee5", "iii5", "ooo5",- "aaa6", "eee6", "iii6", "ooo6",- "aaa7", "eee7", "iii7", "ooo7",- "aaa8", "eee8", "iii8", "ooo8"- };+ static final String[] ascOrder =+ new String[] {+ "aaa1", "aaa2", "aaa3", "eee1",+ "eee2", "eee3", "iii1", "iii2",+ "iii3", "ooo1", "ooo2", "ooo3",+ "aaa4", "eee4", "iii4", "ooo4",+ "aaa5", "eee5", "iii5", "ooo5",+ "aaa6", "eee6", "iii6", "ooo6",+ "aaa7", "eee7", "iii7", "ooo7",+ "aaa8", "eee8", "iii8", "ooo8"+ };// Goes away after after LUCENE-7548- final static String[] descOrder = new String[]{- "aaa8", "eee8", "iii8", "ooo8",- "aaa7", "eee7", "iii7", "ooo7",- "aaa6", "eee6", "iii6", "ooo6",- "aaa5", "eee5", "iii5", "ooo5",- "aaa4", "eee4", "iii4", "ooo4",- "aaa1", "aaa2", "aaa3", "eee1",- "eee2", "eee3", "iii1", "iii2",- "iii3", "ooo1", "ooo2", "ooo3"- };-+ static final String[] descOrder =+ new String[] {+ "aaa8", "eee8", "iii8", "ooo8",+ "aaa7", "eee7", "iii7", "ooo7",+ "aaa6", "eee6", "iii6", "ooo6",+ "aaa5", "eee5", "iii5", "ooo5",+ "aaa4", "eee4", "iii4", "ooo4",+ "aaa1", "aaa2", "aaa3", "eee1",+ "eee2", "eee3", "iii1", "iii2",+ "iii3", "ooo1", "ooo2", "ooo3"+ };// Goes away after after LUCENE-7548- final static String[] ascOrderBool = new String[]{- "aaa1", "aaa2", "aaa3", "eee1",- "eee2", "eee3", "iii1", "iii2",- "iii3", "ooo1", "ooo2", "ooo3",- "aaa5", "aaa7", "eee5", "eee7",- "iii5", "iii7", "ooo5", "ooo7",- "aaa4", "aaa6", "aaa8", "eee4",- "eee6", "eee8", "iii4", "iii6",- "iii8", "ooo4", "ooo6", "ooo8"- };+ static final String[] ascOrderBool =+ new String[] {+ "aaa1", "aaa2", "aaa3", "eee1",+ "eee2", "eee3", "iii1", "iii2",+ "iii3", "ooo1", "ooo2", "ooo3",+ "aaa5", "aaa7", "eee5", "eee7",+ "iii5", "iii7", "ooo5", "ooo7",+ "aaa4", "aaa6", "aaa8", "eee4",+ "eee6", "eee8", "iii4", "iii6",+ "iii8", "ooo4", "ooo6", "ooo8"+ };// Goes away after after LUCENE-7548- final static String[] descOrderBool = new String[]{- "aaa4", "aaa6", "aaa8", "eee4",- "eee6", "eee8", "iii4", "iii6",- "iii8", "ooo4", "ooo6", "ooo8",- "aaa5", "aaa7", "eee5", "eee7",- "iii5", "iii7", "ooo5", "ooo7",- "aaa1", "aaa2", "aaa3", "eee1",- "eee2", "eee3", "iii1", "iii2",- "iii3", "ooo1", "ooo2", "ooo3",- };+ static final String[] descOrderBool =+ new String[] {+ "aaa4", "aaa6", "aaa8", "eee4",+ "eee6", "eee8", "iii4", "iii6",+ "iii8", "ooo4", "ooo6", "ooo8",+ "aaa5", "aaa7", "eee5", "eee7",+ "iii5", "iii7", "ooo5", "ooo7",+ "aaa1", "aaa2", "aaa3", "eee1",+ "eee2", "eee3", "iii1", "iii2",+ "iii3", "ooo1", "ooo2", "ooo3",+ };@Testpublic void testMissingFields() throws Exception {@@ -1309,12 +1468,10 @@ public void testParallelRankStream() throws Exception {.add(id, "eee1").add(id, "aaa1").add(id, "ooo1")-.add(id, "iii2").add(id, "eee2").add(id, "aaa2").add(id, "ooo2")-.add(id, "iii3").add(id, "eee3").add(id, "aaa3")@@ -1326,34 +1483,28 @@ public void testParallelRankStream() throws Exception {.add(docPairs(4, "eee")).add(docPairs(4, "aaa")).add(docPairs(4, "ooo"))-.add(docPairs(5, "iii")).add(docPairs(5, "eee")).add(docPairs(5, "aaa")).add(docPairs(5, "ooo"))-.add(docPairs(6, "iii")).add(docPairs(6, "eee")).add(docPairs(6, "aaa")).add(docPairs(6, "ooo"))-.add(docPairs(7, "iii")).add(docPairs(7, "eee")).add(docPairs(7, "aaa")).add(docPairs(7, "ooo"))-.add(docPairs(8, "iii")).add(docPairs(8, "eee")).add(docPairs(8, "aaa")).add(docPairs(8, "ooo"))-.commit(cluster.getSolrClient(), COLLECTIONORALIAS);JettySolrRunner jetty = cluster.getJettySolrRunners().get(0);-- String[] fields = new String[]{"s_sing", "i_sing", "f_sing", "l_sing", "d_sing", "dt_sing", "b_sing" };-+ String[] fields =+ new String[] {"s_sing", "i_sing", "f_sing", "l_sing", "d_sing", "dt_sing", "b_sing"};for (String f : fields) {checkSort(jetty, f, "asc", fields);@@ -1361,7 +1512,6 @@ public void testParallelRankStream() throws Exception {}checkReturnValsForEmpty(fields);-}@Test@@ -1390,19 +1540,15 @@ public void testParallelRankStream() throws Exception {Bucket[] buckets = {new Bucket("level1_s"), new Bucket("level2_s")};- Metric[] metrics = {new SumMetric("a_i"),- new CountMetric()};+ Metric[] metrics = {new SumMetric("a_i"), new CountMetric()};- FieldComparator[] sorts = {new FieldComparator("sum(a_i)", ComparatorOrder.DESCENDING), new FieldComparator("sum(a_i)", ComparatorOrder.DESCENDING)};+ FieldComparator[] sorts = {+ new FieldComparator("sum(a_i)", ComparatorOrder.DESCENDING),+ new FieldComparator("sum(a_i)", ComparatorOrder.DESCENDING)+ };- FacetStream facetStream = new FacetStream(- zkHost,- COLLECTIONORALIAS,- sParamsA,- buckets,- metrics,- sorts,- 100);+ FacetStream facetStream =+ new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);facetStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(facetStream);assertEquals(6, tuples.size());@@ -1475,14 +1621,8 @@ public void testParallelRankStream() throws Exception {sorts[0] = new FieldComparator("level1_s", ComparatorOrder.DESCENDING);sorts[1] = new FieldComparator("level2_s", ComparatorOrder.DESCENDING);- facetStream = new FacetStream(- zkHost,- COLLECTIONORALIAS,- sParamsA,- buckets,- metrics,- sorts,- 100);+ facetStream =+ new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);facetStream.setStreamContext(streamContext);tuples = getTuples(facetStream);assertEquals(6, tuples.size());@@ -1582,15 +1722,17 @@ public void testParallelRankStream() throws Exception {Bucket[] buckets = {new Bucket("a_s")};- Metric[] metrics = {new SumMetric("a_i"),- new SumMetric("a_f"),- new MinMetric("a_i"),- new MinMetric("a_f"),- new MaxMetric("a_i"),- new MaxMetric("a_f"),- new MeanMetric("a_i"),- new MeanMetric("a_f"),- new CountMetric()};+ Metric[] metrics = {+ new SumMetric("a_i"),+ new SumMetric("a_f"),+ new MinMetric("a_i"),+ new MinMetric("a_f"),+ new MaxMetric("a_i"),+ new MaxMetric("a_f"),+ new MeanMetric("a_i"),+ new MeanMetric("a_f"),+ new CountMetric()+ };RollupStream rollupStream = new RollupStream(stream, buckets, metrics);rollupStream.setStreamContext(streamContext);@@ -1598,7 +1740,7 @@ public void testParallelRankStream() throws Exception {assert (tuples.size() == 3);- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);String bucket = tuple.getString("a_s");@@ -1612,7 +1754,6 @@ public void testParallelRankStream() throws Exception {Double avgf = tuple.getDouble("avg(a_f)");Double count = tuple.getDouble("count(*)");-assertEquals("hello0", bucket);assertEquals(17, sumi.doubleValue(), 0.001);assertEquals(18, sumf.doubleValue(), 0.001);@@ -1624,7 +1765,6 @@ public void testParallelRankStream() throws Exception {assertEquals(4.5, avgf.doubleValue(), 0.001);assertEquals(4, count.doubleValue(), 0.001);-tuple = tuples.get(1);bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");@@ -1648,7 +1788,6 @@ public void testParallelRankStream() throws Exception {assertEquals(6.5, avgf.doubleValue(), 0.001);assertEquals(4, count.doubleValue(), 0.001);-tuple = tuples.get(2);bucket = tuple.getString("a_s");sumi = tuple.getDouble("sum(a_i)");@@ -1690,8 +1829,7 @@ public void testParallelRankStream() throws Exception {bucket = tuple.getString("a_s");assertTrue(bucket.equals("hello4"));-- //Test will null value in the grouping field+ // Test will null value in the grouping fieldnew UpdateRequest().add(id, "12", "a_s", null, "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);@@ -1700,20 +1838,22 @@ public void testParallelRankStream() throws Exception {stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);Bucket[] buckets1 = {new Bucket("a_s")};- Metric[] metrics1 = {new SumMetric("a_i"),- new SumMetric("a_f"),- new MinMetric("a_i"),- new MinMetric("a_f"),- new MaxMetric("a_i"),- new MaxMetric("a_f"),- new MeanMetric("a_i"),- new MeanMetric("a_f"),- new CountMetric()};+ Metric[] metrics1 = {+ new SumMetric("a_i"),+ new SumMetric("a_f"),+ new MinMetric("a_i"),+ new MinMetric("a_f"),+ new MaxMetric("a_i"),+ new MaxMetric("a_f"),+ new MeanMetric("a_i"),+ new MeanMetric("a_f"),+ new CountMetric()+ };rollupStream = new RollupStream(stream, buckets1, metrics1);rollupStream.setStreamContext(streamContext);tuples = getTuples(rollupStream);- //Check that we've got the extra NULL bucket+ // Check that we've got the extra NULL bucketassertEquals(4, tuples.size());tuple = tuples.get(0);assertEquals("NULL", tuple.getString("a_s"));@@ -1753,12 +1893,9 @@ public void testParallelRankStream() throws Exception {try {SolrParams sParams = params("q", "a_s:hello0", "rows", "500", "fl", "id");- TopicStream topicStream = new TopicStream(zkHost,- COLLECTIONORALIAS,- COLLECTIONORALIAS,- "50000000",- -1,- 1000000, sParams);+ TopicStream topicStream =+ new TopicStream(+ zkHost, COLLECTIONORALIAS, COLLECTIONORALIAS, "50000000", -1, 1000000, sParams);DaemonStream daemonStream = new DaemonStream(topicStream, "daemon1", 1000, 500);daemonStream.setStreamContext(context);@@ -1767,10 +1904,16 @@ public void testParallelRankStream() throws Exception {CheckDaemonStream(context, daemonStream);// We should get an error if we try to open an already-open stream.- final IOException ex = expectThrows(IOException.class, () -> {- daemonStream.open();- });- assertEquals("Should have an intelligible exception message", ex.getMessage(), "There is already an open daemon named 'daemon1', no action taken.");+ final IOException ex =+ expectThrows(+ IOException.class,+ () -> {+ daemonStream.open();+ });+ assertEquals(+ "Should have an intelligible exception message",+ ex.getMessage(),+ "There is already an open daemon named 'daemon1', no action taken.");daemonStream.close();// We should be able to close then re-open the stream, then close it again, see SOLR-13408@@ -1782,14 +1925,16 @@ public void testParallelRankStream() throws Exception {}}- private void CheckDaemonStream(StreamContext context, DaemonStream daemonStream) throws IOException, SolrServerException {+ private void CheckDaemonStream(StreamContext context, DaemonStream daemonStream)+ throws IOException, SolrServerException {// Wait for the checkpointJettySolrRunner jetty = cluster.getJettySolrRunners().get(0);SolrParams sParams1 = params("qt", "/get", "ids", "50000000", "fl", "id");int count = 0;while (count == 0) {- SolrStream solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/" + COLLECTIONORALIAS, sParams1);+ SolrStream solrStream =+ new SolrStream(jetty.getBaseUrl().toString() + "/" + COLLECTIONORALIAS, sParams1);solrStream.setStreamContext(context);List<Tuple> tuples = getTuples(solrStream);count = tuples.size();@@ -1850,32 +1995,50 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- //Intentionally adding partitionKeys to trigger SOLR-12674- SolrParams sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f", "sort", "a_s asc", "partitionKeys", "a_s", "qt", "/export" );+ // Intentionally adding partitionKeys to trigger SOLR-12674+ SolrParams sParamsA =+ params(+ "q",+ "*:*",+ "fl",+ "a_s,a_i,a_f",+ "sort",+ "a_s asc",+ "partitionKeys",+ "a_s",+ "qt",+ "/export");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);Bucket[] buckets = {new Bucket("a_s")};- Metric[] metrics = {new SumMetric("a_i"),- new SumMetric("a_f"),- new MinMetric("a_i"),- new MinMetric("a_f"),- new MaxMetric("a_i"),- new MaxMetric("a_f"),- new MeanMetric("a_i"),- new MeanMetric("a_f"),- new CountMetric()};+ Metric[] metrics = {+ new SumMetric("a_i"),+ new SumMetric("a_f"),+ new MinMetric("a_i"),+ new MinMetric("a_f"),+ new MaxMetric("a_i"),+ new MaxMetric("a_f"),+ new MeanMetric("a_i"),+ new MeanMetric("a_f"),+ new CountMetric()+ };RollupStream rollupStream = new RollupStream(stream, buckets, metrics);rollupStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(rollupStream);assertEquals(3, tuples.size());-- List<String> shardUrls = TupleStream.getShards(cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);+ List<String> shardUrls =+ TupleStream.getShards(+ cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);ModifiableSolrParams solrParams = new ModifiableSolrParams();solrParams.add("qt", "/stream");- solrParams.add("expr", "rollup(search(" + COLLECTIONORALIAS + ",q=\"*:*\",fl=\"a_s,a_i,a_f\",sort=\"a_s desc\",partitionKeys=\"a_s\", qt=\"/export\"),over=\"a_s\")\n");+ solrParams.add(+ "expr",+ "rollup(search("+ + COLLECTIONORALIAS+ + ",q=\"*:*\",fl=\"a_s,a_i,a_f\",sort=\"a_s desc\",partitionKeys=\"a_s\", qt=\"/export\"),over=\"a_s\")\n");SolrStream solrStream = new SolrStream(shardUrls.get(0), solrParams);streamContext = new StreamContext();solrStream.setStreamContext(streamContext);@@ -1907,30 +2070,44 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- SolrParams sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f", "sort", "a_s asc", "partitionKeys", "a_s", "qt", "/export");+ SolrParams sParamsA =+ params(+ "q",+ "*:*",+ "fl",+ "a_s,a_i,a_f",+ "sort",+ "a_s asc",+ "partitionKeys",+ "a_s",+ "qt",+ "/export");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);Bucket[] buckets = {new Bucket("a_s")};- Metric[] metrics = {new SumMetric("a_i"),- new SumMetric("a_f"),- new MinMetric("a_i"),- new MinMetric("a_f"),- new MaxMetric("a_i"),- new MaxMetric("a_f"),- new MeanMetric("a_i"),- new MeanMetric("a_f"),- new CountMetric()};+ Metric[] metrics = {+ new SumMetric("a_i"),+ new SumMetric("a_f"),+ new MinMetric("a_i"),+ new MinMetric("a_f"),+ new MaxMetric("a_i"),+ new MaxMetric("a_f"),+ new MeanMetric("a_i"),+ new MeanMetric("a_f"),+ new CountMetric()+ };RollupStream rollupStream = new RollupStream(stream, buckets, metrics);- ParallelStream parallelStream = parallelStream(rollupStream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));+ ParallelStream parallelStream =+ parallelStream(rollupStream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));attachStreamFactory(parallelStream);parallelStream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(parallelStream);assertEquals(3, tuples.size());- //Test Long and Double Sums+ // Test Long and Double SumsTuple tuple = tuples.get(0);String bucket = tuple.getString("a_s");@@ -2006,7 +2183,6 @@ public void testParallelRankStream() throws Exception {}@Test- // commented out on: 17-Feb-2019 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 6-Sep-2018public void testZeroParallelReducerStream() throws Exception {new UpdateRequest()@@ -2026,12 +2202,26 @@ public void testParallelRankStream() throws Exception {SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);try {- SolrParams sParamsA = params("q", "a_s:blah", "fl", "id,a_s,a_i,a_f", "sort", "a_s asc,a_f asc", "partitionKeys", "a_s", "qt", "/export");+ SolrParams sParamsA =+ params(+ "q",+ "a_s:blah",+ "fl",+ "id,a_s,a_i,a_f",+ "sort",+ "a_s asc,a_f asc",+ "partitionKeys",+ "a_s",+ "qt",+ "/export");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- ReducerStream rstream = new ReducerStream(stream,- new FieldEqualitor("a_s"),- new GroupOperation(new FieldComparator("a_s", ComparatorOrder.ASCENDING), 2));- ParallelStream pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));+ ReducerStream rstream =+ new ReducerStream(+ stream,+ new FieldEqualitor("a_s"),+ new GroupOperation(new FieldComparator("a_s", ComparatorOrder.ASCENDING), 2));+ ParallelStream pstream =+ parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));attachStreamFactory(pstream);pstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(pstream);@@ -2039,15 +2229,15 @@ public void testParallelRankStream() throws Exception {} finally {solrClientCache.close();}-}@Testpublic void testTuple() throws Exception {new UpdateRequest()- .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "5.1", "s_multi", "a", "s_multi", "b", "i_multi",- "1", "i_multi", "2", "f_multi", "1.2", "f_multi", "1.3")+ .add(+ id, "0", "a_s", "hello0", "a_i", "0", "a_f", "5.1", "s_multi", "a", "s_multi", "b",+ "i_multi", "1", "i_multi", "2", "f_multi", "1.2", "f_multi", "1.3").commit(cluster.getSolrClient(), COLLECTIONORALIAS);StreamContext streamContext = new StreamContext();@@ -2055,7 +2245,8 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f,s_multi,i_multi,f_multi", "sort", "a_s asc");+ SolrParams sParams =+ params("q", "*:*", "fl", "id,a_s,a_i,a_f,s_multi,i_multi,f_multi", "sort", "a_s asc");CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(stream);@@ -2064,14 +2255,12 @@ public void testParallelRankStream() throws Exception {String s = tuple.getString("a_s");assertEquals("hello0", s);-long l = tuple.getLong("a_i");assertEquals(0, l);double d = tuple.getDouble("a_f");assertEquals(5.1, d, 0.001);-List<String> stringList = tuple.getStrings("s_multi");assertEquals("a", stringList.get(0));assertEquals("b", stringList.get(1));@@ -2104,35 +2293,37 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- //Test ascending+ // Test ascendingSolrParams sParamsA = params("q", "id:(4 1)", "fl", "id,a_s,a_i", "sort", "a_i asc");CloudSolrStream streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);SolrParams sParamsB = params("q", "id:(0 2 3)", "fl", "id,a_s,a_i", "sort", "a_i asc");CloudSolrStream streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);- MergeStream mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));+ MergeStream mstream =+ new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));mstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(mstream);assertEquals(5, tuples.size());assertOrder(tuples, 0, 1, 2, 3, 4);- //Test descending+ // Test descendingsParamsA = params("q", "id:(4 1)", "fl", "id,a_s,a_i", "sort", "a_i desc");streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);sParamsB = params("q", "id:(0 2 3)", "fl", "id,a_s,a_i", "sort", "a_i desc");streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);- mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.DESCENDING));+ mstream =+ new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.DESCENDING));mstream.setStreamContext(streamContext);tuples = getTuples(mstream);assertEquals(5, tuples.size());assertOrder(tuples, 4, 3, 2, 1, 0);- //Test compound sort+ // Test compound sortsParamsA = params("q", "id:(2 4 1)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);@@ -2140,7 +2331,13 @@ public void testParallelRankStream() throws Exception {sParamsB = params("q", "id:(0 3)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);- mstream = new MergeStream(streamA, streamB, new MultipleFieldComparator(new FieldComparator("a_f", ComparatorOrder.ASCENDING), new FieldComparator("a_i", ComparatorOrder.ASCENDING)));+ mstream =+ new MergeStream(+ streamA,+ streamB,+ new MultipleFieldComparator(+ new FieldComparator("a_f", ComparatorOrder.ASCENDING),+ new FieldComparator("a_i", ComparatorOrder.ASCENDING)));mstream.setStreamContext(streamContext);tuples = getTuples(mstream);@@ -2153,7 +2350,13 @@ public void testParallelRankStream() throws Exception {sParamsB = params("q", "id:(0 3)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);- mstream = new MergeStream(streamA, streamB, new MultipleFieldComparator(new FieldComparator("a_f", ComparatorOrder.ASCENDING), new FieldComparator("a_i", ComparatorOrder.DESCENDING)));+ mstream =+ new MergeStream(+ streamA,+ streamB,+ new MultipleFieldComparator(+ new FieldComparator("a_f", ComparatorOrder.ASCENDING),+ new FieldComparator("a_i", ComparatorOrder.DESCENDING)));mstream.setStreamContext(streamContext);tuples = getTuples(mstream);@@ -2165,7 +2368,6 @@ public void testParallelRankStream() throws Exception {}@Test- // commented out on: 17-Feb-2019 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 6-Sep-2018public void testParallelMergeStream() throws Exception {new UpdateRequest()@@ -2186,15 +2388,39 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- //Test ascending- SolrParams sParamsA = params("q", "id:(4 1 8 7 9)", "fl", "id,a_s,a_i", "sort", "a_i asc", "partitionKeys", "a_i", "qt", "/export");+ // Test ascending+ SolrParams sParamsA =+ params(+ "q",+ "id:(4 1 8 7 9)",+ "fl",+ "id,a_s,a_i",+ "sort",+ "a_i asc",+ "partitionKeys",+ "a_i",+ "qt",+ "/export");CloudSolrStream streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- SolrParams sParamsB = params("q", "id:(0 2 3 6)", "fl", "id,a_s,a_i", "sort", "a_i asc", "partitionKeys", "a_i", "qt", "/export");+ SolrParams sParamsB =+ params(+ "q",+ "id:(0 2 3 6)",+ "fl",+ "id,a_s,a_i",+ "sort",+ "a_i asc",+ "partitionKeys",+ "a_i",+ "qt",+ "/export");CloudSolrStream streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);- MergeStream mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));- ParallelStream pstream = parallelStream(mstream, new FieldComparator("a_i", ComparatorOrder.ASCENDING));+ MergeStream mstream =+ new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));+ ParallelStream pstream =+ parallelStream(mstream, new FieldComparator("a_i", ComparatorOrder.ASCENDING));attachStreamFactory(pstream);pstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(pstream);@@ -2202,14 +2428,37 @@ public void testParallelRankStream() throws Exception {assertEquals(9, tuples.size());assertOrder(tuples, 0, 1, 2, 3, 4, 7, 6, 8, 9);- //Test descending- sParamsA = params("q", "id:(4 1 8 9)", "fl", "id,a_s,a_i", "sort", "a_i desc", "partitionKeys", "a_i", "qt", "/export");+ // Test descending+ sParamsA =+ params(+ "q",+ "id:(4 1 8 9)",+ "fl",+ "id,a_s,a_i",+ "sort",+ "a_i desc",+ "partitionKeys",+ "a_i",+ "qt",+ "/export");streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- sParamsB = params("q", "id:(0 2 3 6)", "fl", "id,a_s,a_i", "sort", "a_i desc", "partitionKeys", "a_i", "qt", "/export");+ sParamsB =+ params(+ "q",+ "id:(0 2 3 6)",+ "fl",+ "id,a_s,a_i",+ "sort",+ "a_i desc",+ "partitionKeys",+ "a_i",+ "qt",+ "/export");streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);- mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.DESCENDING));+ mstream =+ new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.DESCENDING));pstream = parallelStream(mstream, new FieldComparator("a_i", ComparatorOrder.DESCENDING));attachStreamFactory(pstream);pstream.setStreamContext(streamContext);@@ -2243,15 +2492,39 @@ public void testParallelRankStream() throws Exception {streamContext.setSolrClientCache(solrClientCache);try {- //Test ascending- SolrParams sParamsA = params("q", "id:(4 1 8 7 9)", "fl", "id,a_s,a_i", "sort", "a_i asc", "partitionKeys", "a_i", "qt", "/export");+ // Test ascending+ SolrParams sParamsA =+ params(+ "q",+ "id:(4 1 8 7 9)",+ "fl",+ "id,a_s,a_i",+ "sort",+ "a_i asc",+ "partitionKeys",+ "a_i",+ "qt",+ "/export");CloudSolrStream streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);- SolrParams sParamsB = params("q", "id:(0 2 3 6)", "fl", "id,a_s,a_i", "sort", "a_i asc", "partitionKeys", "a_i", "qt", "/export");+ SolrParams sParamsB =+ params(+ "q",+ "id:(0 2 3 6)",+ "fl",+ "id,a_s,a_i",+ "sort",+ "a_i asc",+ "partitionKeys",+ "a_i",+ "qt",+ "/export");CloudSolrStream streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);- MergeStream mstream = new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));- ParallelStream pstream = parallelStream(mstream, new FieldComparator("a_i", ComparatorOrder.ASCENDING));+ MergeStream mstream =+ new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));+ ParallelStream pstream =+ parallelStream(mstream, new FieldComparator("a_i", ComparatorOrder.ASCENDING));attachStreamFactory(pstream);pstream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(pstream);@@ -2275,11 +2548,10 @@ public void testParallelRankStream() throws Exception {.add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- //Basic CloudSolrStream Test with Descending Sort+ // Basic CloudSolrStream Test with Descending Sorttry {SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i desc");@@ -2290,7 +2562,7 @@ public void testParallelRankStream() throws Exception {assertEquals(5, tuples.size());assertOrder(tuples, 4, 3, 2, 1, 0);- //With Ascending Sort+ // With Ascending SortsParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i asc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);@@ -2299,8 +2571,7 @@ public void testParallelRankStream() throws Exception {assertEquals(5, tuples.size());assertOrder(tuples, 0, 1, 2, 3, 4);-- //Test compound sort+ // Test compound sortsParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);@@ -2309,7 +2580,6 @@ public void testParallelRankStream() throws Exception {assertEquals(5, tuples.size());assertOrder(tuples, 2, 0, 1, 3, 4);-sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);@@ -2323,8 +2593,8 @@ public void testParallelRankStream() throws Exception {}/**- * This test verifies that setting a core into the stream context entries and streamContext.local = true causes the- * streaming expression to only consider data found on the local node.+ * This test verifies that setting a core into the stream context entries and streamContext.local+ * = true causes the streaming expression to only consider data found on the local node.*/@Testpublic void streamLocalTests() throws Exception {@@ -2340,15 +2610,18 @@ public void testParallelRankStream() throws Exception {StreamContext streamContext = new StreamContext();streamContext.setLocal(true);ZkStateReader zkStateReader = cluster.getZkStateReader();- List<String> strings = zkStateReader.aliasesManager.getAliases().resolveAliases(COLLECTIONORALIAS);+ List<String> strings =+ zkStateReader.aliasesManager.getAliases().resolveAliases(COLLECTIONORALIAS);String collName = strings.size() > 0 ? strings.get(0) : COLLECTIONORALIAS;- zkStateReader.forceUpdateCollection(collName);+ zkStateReader.forceUpdateCollection(collName);DocCollection collection = zkStateReader.getClusterState().getCollectionOrNull(collName);List<Replica> replicas = collection.getReplicas();- streamContext.getEntries().put("core",replicas.get(random().nextInt(replicas.size())).getCoreName());+ streamContext+ .getEntries()+ .put("core", replicas.get(random().nextInt(replicas.size())).getCoreName());SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- //Basic CloudSolrStream Test with Descending Sort+ // Basic CloudSolrStream Test with Descending Sorttry {SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i desc");@@ -2365,13 +2638,13 @@ public void testParallelRankStream() throws Exception {assertOrder(tuples, 4, 1, 0);break;case 2: // 2 shards case 2 (randomized)- assertOrder(tuples, 3, 2);+ assertOrder(tuples, 3, 2);break;default: // nope, no way, no how, never good.fail("should have 3, 5 or 2 tuples, has hashing algorithm changed?");}- //With Ascending Sort+ // With Ascending SortsParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i asc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);@@ -2392,7 +2665,7 @@ public void testParallelRankStream() throws Exception {fail("should have 3, 5 or 2 tuples, has hashing algorithm changed?");}- //Test compound sort+ // Test compound sortsParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);@@ -2449,27 +2722,28 @@ public void testParallelRankStream() throws Exception {.add(id, "4", "b_sing", "true", "dt_sing", "1980-04-04T01:02:03.78Z").commit(cluster.getSolrClient(), COLLECTIONORALIAS);-trySortWithQt("/export");trySortWithQt("/select");}+private void trySortWithQt(String which) throws Exception {- //Basic CloudSolrStream Test bools desc+ // Basic CloudSolrStream Test bools desc- SolrParams sParams = params("q", "*:*", "qt", which, "fl", "id,b_sing", "sort", "b_sing asc,id asc");+ SolrParams sParams =+ params("q", "*:*", "qt", which, "fl", "id,b_sing", "sort", "b_sing asc,id asc");StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);- try {+ try {stream.setStreamContext(streamContext);List<Tuple> tuples = getTuples(stream);assertEquals(5, tuples.size());assertOrder(tuples, 0, 2, 1, 3, 4);- //Basic CloudSolrStream Test bools desc+ // Basic CloudSolrStream Test bools descsParams = params("q", "*:*", "qt", which, "fl", "id,b_sing", "sort", "b_sing desc,id desc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);@@ -2478,7 +2752,7 @@ public void testParallelRankStream() throws Exception {assertEquals(5, tuples.size());assertOrder(tuples, 4, 3, 1, 2, 0);- //Basic CloudSolrStream Test dates desc+ // Basic CloudSolrStream Test dates descsParams = params("q", "*:*", "qt", which, "fl", "id,dt_sing", "sort", "dt_sing desc,id asc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);@@ -2487,86 +2761,163 @@ public void testParallelRankStream() throws Exception {assertEquals(5, tuples.size());assertOrder(tuples, 2, 0, 1, 4, 3);- //Basic CloudSolrStream Test ates desc+ // Basic CloudSolrStream Test ates descsParams = params("q", "*:*", "qt", which, "fl", "id,dt_sing", "sort", "dt_sing asc,id desc");stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);stream.setStreamContext(streamContext);tuples = getTuples(stream);- assertEquals (5,tuples.size());+ assertEquals(5, tuples.size());assertOrder(tuples, 3, 4, 1, 0, 2);} finally {solrClientCache.close();}-}-@Testpublic void testAllValidExportTypes() throws Exception {- //Test whether all the expected types are actually returned, including booleans and dates.- // The contract is that the /select and /export handlers return the same format, so we can test this once each- // way+ // Test whether all the expected types are actually returned, including booleans and dates.+ // The contract is that the /select and /export handlers return the same format, so we can test+ // this once each waynew UpdateRequest()- .add(id, "0", "i_sing", "11", "i_multi", "12", "i_multi", "13",- "l_sing", "14", "l_multi", "15", "l_multi", "16",- "f_sing", "1.70", "f_multi", "1.80", "f_multi", "1.90",- "d_sing", "1.20", "d_multi", "1.21", "d_multi", "1.22",- "s_sing", "single", "s_multi", "sm1", "s_multi", "sm2",- "dt_sing", "1980-01-02T11:11:33.89Z", "dt_multi", "1981-03-04T01:02:03.78Z", "dt_multi", "1981-05-24T04:05:06.99Z",- "b_sing", "true", "b_multi", "false", "b_multi", "true"- )+ .add(+ id,+ "0",+ "i_sing",+ "11",+ "i_multi",+ "12",+ "i_multi",+ "13",+ "l_sing",+ "14",+ "l_multi",+ "15",+ "l_multi",+ "16",+ "f_sing",+ "1.70",+ "f_multi",+ "1.80",+ "f_multi",+ "1.90",+ "d_sing",+ "1.20",+ "d_multi",+ "1.21",+ "d_multi",+ "1.22",+ "s_sing",+ "single",+ "s_multi",+ "sm1",+ "s_multi",+ "sm2",+ "dt_sing",+ "1980-01-02T11:11:33.89Z",+ "dt_multi",+ "1981-03-04T01:02:03.78Z",+ "dt_multi",+ "1981-05-24T04:05:06.99Z",+ "b_sing",+ "true",+ "b_multi",+ "false",+ "b_multi",+ "true").commit(cluster.getSolrClient(), COLLECTIONORALIAS);tryWithQt("/export");tryWithQt("/select");}- // We should be getting the exact same thing back with both the export and select handlers, so test+ // We should be getting the exact same thing back with both the export and select handlers, so+ // testprivate void tryWithQt(String which) throws IOException {StreamContext streamContext = new StreamContext();SolrClientCache solrClientCache = new SolrClientCache();streamContext.setSolrClientCache(solrClientCache);- SolrParams sParams = params("q", "*:*", "qt", which, "fl",- "id,i_sing,i_multi,l_sing,l_multi,f_sing,f_multi,d_sing,d_multi,dt_sing,dt_multi,s_sing,s_multi,b_sing,b_multi",- "sort", "i_sing asc");+ SolrParams sParams =+ params(+ "q",+ "*:*",+ "qt",+ which,+ "fl",+ "id,i_sing,i_multi,l_sing,l_multi,f_sing,f_multi,d_sing,d_multi,dt_sing,dt_multi,s_sing,s_multi,b_sing,b_multi",+ "sort",+ "i_sing asc");try (CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams)) {stream.setStreamContext(streamContext);- Tuple tuple = getTuple(stream); // All I really care about is that all the fields are returned. There's+ Tuple tuple = getTuple(stream);assertEquals("Integers should be returned", 11, tuple.getLong("i_sing").longValue());- assertEquals("MV should be returned for i_multi", 12, tuple.getLongs("i_multi").get(0).longValue());- assertEquals("MV should be returned for i_multi", 13, tuple.getLongs("i_multi").get(1).longValue());+ assertEquals(+ "MV should be returned for i_multi", 12, tuple.getLongs("i_multi").get(0).longValue());+ assertEquals(+ "MV should be returned for i_multi", 13, tuple.getLongs("i_multi").get(1).longValue());assertEquals("longs should be returned", 14, tuple.getLong("l_sing").longValue());- assertEquals("MV should be returned for l_multi", 15, tuple.getLongs("l_multi").get(0).longValue());- assertEquals("MV should be returned for l_multi", 16, tuple.getLongs("l_multi").get(1).longValue());-- assertEquals("floats should be returned", 1.7, tuple.getDouble("f_sing").doubleValue(), 0.001);- assertEquals("MV should be returned for f_multi", 1.8, tuple.getDoubles("f_multi").get(0).doubleValue(), 0.001);- assertEquals("MV should be returned for f_multi", 1.9, tuple.getDoubles("f_multi").get(1).doubleValue(), 0.001);-- assertEquals("doubles should be returned", 1.2, tuple.getDouble("d_sing").doubleValue(), 0.001);- assertEquals("MV should be returned for d_multi", 1.21, tuple.getDoubles("d_multi").get(0).doubleValue(), 0.001);- assertEquals("MV should be returned for d_multi", 1.22, tuple.getDoubles("d_multi").get(1).doubleValue(), 0.001);+ assertEquals(+ "MV should be returned for l_multi", 15, tuple.getLongs("l_multi").get(0).longValue());+ assertEquals(+ "MV should be returned for l_multi", 16, tuple.getLongs("l_multi").get(1).longValue());++ assertEquals(+ "floats should be returned", 1.7, tuple.getDouble("f_sing").doubleValue(), 0.001);+ assertEquals(+ "MV should be returned for f_multi",+ 1.8,+ tuple.getDoubles("f_multi").get(0).doubleValue(),+ 0.001);+ assertEquals(+ "MV should be returned for f_multi",+ 1.9,+ tuple.getDoubles("f_multi").get(1).doubleValue(),+ 0.001);++ assertEquals(+ "doubles should be returned", 1.2, tuple.getDouble("d_sing").doubleValue(), 0.001);+ assertEquals(+ "MV should be returned for d_multi",+ 1.21,+ tuple.getDoubles("d_multi").get(0).doubleValue(),+ 0.001);+ assertEquals(+ "MV should be returned for d_multi",+ 1.22,+ tuple.getDoubles("d_multi").get(1).doubleValue(),+ 0.001);assertTrue("Strings should be returned", tuple.getString("s_sing").equals("single"));- assertTrue("MV should be returned for s_multi", tuple.getStrings("s_multi").get(0).equals("sm1"));- assertTrue("MV should be returned for s_multi", tuple.getStrings("s_multi").get(1).equals("sm2"));-- assertTrue("Dates should be returned as Strings", tuple.getString("dt_sing").equals("1980-01-02T11:11:33.890Z"));- assertTrue("MV dates should be returned as Strings for dt_multi", tuple.getStrings("dt_multi").get(0).equals("1981-03-04T01:02:03.780Z"));- assertTrue("MV dates should be returned as Strings for dt_multi", tuple.getStrings("dt_multi").get(1).equals("1981-05-24T04:05:06.990Z"));+ assertTrue(+ "MV should be returned for s_multi", tuple.getStrings("s_multi").get(0).equals("sm1"));+ assertTrue(+ "MV should be returned for s_multi", tuple.getStrings("s_multi").get(1).equals("sm2"));++ assertTrue(+ "Dates should be returned as Strings",+ tuple.getString("dt_sing").equals("1980-01-02T11:11:33.890Z"));+ assertTrue(+ "MV dates should be returned as Strings for dt_multi",+ tuple.getStrings("dt_multi").get(0).equals("1981-03-04T01:02:03.780Z"));+ assertTrue(+ "MV dates should be returned as Strings for dt_multi",+ tuple.getStrings("dt_multi").get(1).equals("1981-05-24T04:05:06.990Z"));// Also test native type conversionDate dt = new Date(Instant.parse("1980-01-02T11:11:33.890Z").toEpochMilli());assertTrue("Dates should be returned as Dates", tuple.getDate("dt_sing").equals(dt));dt = new Date(Instant.parse("1981-03-04T01:02:03.780Z").toEpochMilli());- assertTrue("MV dates should be returned as Dates for dt_multi", tuple.getDates("dt_multi").get(0).equals(dt));+ assertTrue(+ "MV dates should be returned as Dates for dt_multi",+ tuple.getDates("dt_multi").get(0).equals(dt));dt = new Date(Instant.parse("1981-05-24T04:05:06.990Z").toEpochMilli());- assertTrue("MV dates should be returned as Dates for dt_multi", tuple.getDates("dt_multi").get(1).equals(dt));+ assertTrue(+ "MV dates should be returned as Dates for dt_multi",+ tuple.getDates("dt_multi").get(1).equals(dt));assertTrue("Booleans should be returned", tuple.getBool("b_sing"));assertFalse("MV boolean should be returned for b_multi", tuple.getBools("b_multi").get(0));@@ -2574,25 +2925,34 @@ public void testParallelRankStream() throws Exception {} finally {solrClientCache.close();}-}@Testpublic void testTupleStreamGetShardsPreference() throws Exception {StreamContext streamContext = new StreamContext();streamContext.setSolrClientCache(new SolrClientCache());- streamContext.setRequestReplicaListTransformerGenerator(new RequestReplicaListTransformerGenerator(ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":TLOG", null, null, null));+ streamContext.setRequestReplicaListTransformerGenerator(+ new RequestReplicaListTransformerGenerator(+ ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":TLOG", null, null, null));- streamContext.setRequestParams(params(ShardParams.SHARDS_PREFERENCE, ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":nrt"));+ streamContext.setRequestParams(+ params(ShardParams.SHARDS_PREFERENCE, ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":nrt"));try {ZkStateReader zkStateReader = cluster.getZkStateReader();- List<String> strings = zkStateReader.aliasesManager.getAliases().resolveAliases(MULTI_REPLICA_COLLECTIONORALIAS);+ List<String> strings =+ zkStateReader.aliasesManager.getAliases().resolveAliases(MULTI_REPLICA_COLLECTIONORALIAS);String collName = strings.size() > 0 ? strings.get(0) : MULTI_REPLICA_COLLECTIONORALIAS;- Map<String, String> replicaTypeMap = mapReplicasToReplicaType(zkStateReader.getClusterState().getCollectionOrNull(collName));+ Map<String, String> replicaTypeMap =+ mapReplicasToReplicaType(zkStateReader.getClusterState().getCollectionOrNull(collName));// Test from extra params- SolrParams sParams = params("q", "*:*", ShardParams.SHARDS_PREFERENCE, ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":pull");+ SolrParams sParams =+ params(+ "q",+ "*:*",+ ShardParams.SHARDS_PREFERENCE,+ ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":pull");testTupleStreamSorting(streamContext, sParams, "PULL", replicaTypeMap);// Test defaults from streamContext.getParams()@@ -2606,19 +2966,32 @@ public void testParallelRankStream() throws Exception {}}- public void testTupleStreamSorting(StreamContext streamContext, SolrParams solrParams, String replicaType, Map<String, String> replicaTypeMap) throws Exception {- List<String> shards = TupleStream.getShards(cluster.getZkClient().getZkServerAddress(), MULTI_REPLICA_COLLECTIONORALIAS, streamContext, solrParams);+ public void testTupleStreamSorting(+ StreamContext streamContext,+ SolrParams solrParams,+ String replicaType,+ Map<String, String> replicaTypeMap)+ throws Exception {+ List<String> shards =+ TupleStream.getShards(+ cluster.getZkClient().getZkServerAddress(),+ MULTI_REPLICA_COLLECTIONORALIAS,+ streamContext,+ solrParams);for (String shard : shards) {- assertEquals(shard, replicaType.toUpperCase(Locale.ROOT), replicaTypeMap.getOrDefault(shard, "").toUpperCase(Locale.ROOT));+ assertEquals(+ shard,+ replicaType.toUpperCase(Locale.ROOT),+ replicaTypeMap.getOrDefault(shard, "").toUpperCase(Locale.ROOT));}}protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {tupleStream.open();List<Tuple> tuples = new ArrayList<>();- for(;;) {+ for (; ; ) {Tuple t = tupleStream.read();- if(t.EOF) {+ if (t.EOF) {break;} else {tuples.add(t);@@ -2635,12 +3008,11 @@ public void testParallelRankStream() throws Exception {return t;}-protected boolean assertOrder(List<Tuple> tuples, int... ids) {int i = 0;- for(int val : ids) {+ for (int val : ids) {Tuple t = tuples.get(i);- String tip = (String)t.get("id");+ String tip = (String) t.get("id");String valStr = Integer.toString(val);assertEquals(valStr, tip);++i;@@ -2650,12 +3022,12 @@ public void testParallelRankStream() throws Exception {protected boolean assertGroupOrder(Tuple tuple, int... ids) {@SuppressWarnings({"rawtypes"})- List group = (List)tuple.get("tuples");- int i=0;- for(int val : ids) {+ List group = (List) tuple.get("tuples");+ int i = 0;+ for (int val : ids) {@SuppressWarnings({"rawtypes"})- Map t = (Map)group.get(i);- Long tip = (Long)t.get("id");+ Map t = (Map) group.get(i);+ Long tip = (Long) t.get("id");assertEquals(val, tip.intValue());++i;}@@ -2663,9 +3035,9 @@ public void testParallelRankStream() throws Exception {}public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {- long lv = (long)tuple.get(fieldName);- if(lv != l) {- throw new Exception("Longs not equal:"+l+" : "+lv);+ long lv = (long) tuple.get(fieldName);+ if (lv != l) {+ throw new Exception("Longs not equal:" + l + " : " + lv);}return true;@@ -2677,8 +3049,10 @@ public void testParallelRankStream() throws Exception {tupleStream.setStreamContext(streamContext);}- private ParallelStream parallelStream(TupleStream stream, FieldComparator comparator) throws IOException {- ParallelStream pstream = new ParallelStream(zkHost, COLLECTIONORALIAS, stream, numWorkers, comparator);+ private ParallelStream parallelStream(TupleStream stream, FieldComparator comparator)+ throws IOException {+ ParallelStream pstream =+ new ParallelStream(zkHost, COLLECTIONORALIAS, stream, numWorkers, comparator);return pstream;}@@ -2697,8 +3071,12 @@ public void testParallelRankStream() throws Exception {solrClientCache.getCloudSolrClient(zkHost);streamContext.setSolrClientCache(solrClientCache);- String expr = "search(" + MULTI_REPLICA_COLLECTIONORALIAS + ",q=*:*,fl=\"a_i\", qt=\"/export\", sort=\"a_i asc\")";- try (CloudSolrStream stream = new CloudSolrStream(StreamExpressionParser.parse(expr), streamFactory)) {+ String expr =+ "search("+ + MULTI_REPLICA_COLLECTIONORALIAS+ + ",q=*:*,fl=\"a_i\", qt=\"/export\", sort=\"a_i asc\")";+ try (CloudSolrStream stream =+ new CloudSolrStream(StreamExpressionParser.parse(expr), streamFactory)) {stream.setStreamContext(streamContext);stream.open();Tuple t = stream.read();@@ -2709,7 +3087,8 @@ public void testParallelRankStream() throws Exception {List<String> baseUrls = new LinkedList<>();ZkStateReader zkStateReader = cluster.getZkStateReader();- List<String> resolved = zkStateReader.aliasesManager.getAliases().resolveAliases(MULTI_REPLICA_COLLECTIONORALIAS);+ List<String> resolved =+ zkStateReader.aliasesManager.getAliases().resolveAliases(MULTI_REPLICA_COLLECTIONORALIAS);Set<String> liveNodes = zkStateReader.getClusterState().getLiveNodes();int expectedNumStreams = 0;for (String coll : resolved) {@@ -2726,8 +3105,9 @@ public void testParallelRankStream() throws Exception {List<TupleStream> solrStreams = stream.children();assertEquals(expectedNumStreams, solrStreams.size());for (TupleStream next : solrStreams) {- SolrStream ss = (SolrStream)next;- assertTrue(baseUrls.contains(ss.getBaseUrl())); // SolrStream uses the baseUrl of the replica and not the coreUrl+ SolrStream ss = (SolrStream) next;+ // SolrStream uses the baseUrl of the replica and not the coreUrl+ assertTrue(baseUrls.contains(ss.getBaseUrl()));}// verify core filtering@@ -2736,9 +3116,14 @@ public void testParallelRankStream() throws Exception {for (String coll : resolved) {Replica rr = zkStateReader.getCollection(coll).getReplicas().get(0);streamContext.put("core", rr.core);- List<Replica> replicas = TupleStream.getReplicas(zkHost, coll, streamContext, new ModifiableSolrParams());- assertEquals("core filter for " + rr.core + " not applied for " + coll + "; replicas: " + replicas, 1, replicas.size());- assertEquals("core filter for " + rr.core + " not applied for " + coll, rr, replicas.get(0));+ List<Replica> replicas =+ TupleStream.getReplicas(zkHost, coll, streamContext, new ModifiableSolrParams());+ assertEquals(+ "core filter for " + rr.core + " not applied for " + coll + "; replicas: " + replicas,+ 1,+ replicas.size());+ assertEquals(+ "core filter for " + rr.core + " not applied for " + coll, rr, replicas.get(0));}} finally {