You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2022/04/26 15:10:47 UTC
[solr] branch main updated: SOLR-16070: Enable spotless for solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/ (#717)
This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new b218c177b8e SOLR-16070: Enable spotless for solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/ (#717)
b218c177b8e is described below
commit b218c177b8e3b387ada03acbad214a0c3bfe1443
Author: Kevin Risden <ri...@users.noreply.github.com>
AuthorDate: Tue Apr 26 11:10:41 2022 -0400
SOLR-16070: Enable spotless for solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/ (#717)
* SOLR-16070: Enable spotless for solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/
Co-authored-by: Erick Erickson <Er...@gmail.com>
---
gradle/validation/spotless.gradle | 3 -
.../solrj/io/stream/CloudAuthStreamTest.java | 994 +++---
.../client/solrj/io/stream/JDBCStreamTest.java | 632 ++--
.../client/solrj/io/stream/MathExpressionTest.java | 3414 +++++++++++---------
.../stream/ParallelFacetStreamOverAliasTest.java | 223 +-
.../client/solrj/io/stream/RecordCountStream.java | 78 +-
.../solrj/io/stream/SelectWithEvaluatorsTest.java | 155 +-
.../solr/client/solrj/io/stream/StreamAssert.java | 27 +-
.../solrj/io/stream/StreamDecoratorTest.java | 2981 ++++++++++-------
.../solrj/io/stream/StreamExpressionTest.java | 1995 +++++++-----
.../io/stream/StreamExpressionToExpessionTest.java | 460 +--
.../stream/StreamExpressionToExplanationTest.java | 242 +-
.../solr/client/solrj/io/stream/StreamingTest.java | 1733 ++++++----
13 files changed, 7666 insertions(+), 5271 deletions(-)
diff --git a/gradle/validation/spotless.gradle b/gradle/validation/spotless.gradle
index 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"
- break
case ":solr:modules:hdfs":
// Exclude Hadoop copied files to make upgrades easier
targetExclude "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.java
index 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 {
@BeforeClass
public 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);
}
-
+
@AfterClass
public static void clearVariables() {
solrUrl = null;
}
-
+
@After
public 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.java
index 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")
-@LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})
+/** */
+@SuppressPointFields(bugUrl = "https://issues.apache.org/jira/browse/SOLR-10960")
+@LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"})
@ThreadLeakLingering(linger = 0)
public class JDBCStreamTest extends SolrCloudTestCase {
@@ -65,7 +63,14 @@ public class JDBCStreamTest extends SolrCloudTestCase {
@BeforeClass
public 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());
}
}
@BeforeClass
public 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 {
@Before
public void cleanIndex() throws Exception {
- new UpdateRequest()
- .deleteByQuery("*:*")
- .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
}
@Before
public void cleanDatabase() throws Exception {
// Clear database
try (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 Data
try (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"));
+ }
}
-
+
@Test
public void testJDBCJoin() throws Exception {
-
+
// Load Database Data
try (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");
}
@Test
public void testJDBCSolrMerge() throws Exception {
-
+
// Load Database Data
try (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 Solr
new 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 Data
try (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
new 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 Data
try (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
new 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 alias
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"
+ " ),"
@@ -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 Data
try (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.java
index 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
-@LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})
+@LuceneTestCase.SuppressCodecs({"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 {
@BeforeClass
public 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());
}
}
@Before
public 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 {
@Test
public 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");
}
-
@Test
public 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 {
@Test
public 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");
}
-
@Test
public 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");
-
}
@Test
public 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");
}
-
@Test
public 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");
}
-
@Test
public 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);
}
@Test
public 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);
-
}
-
+
@Test
public 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);
}
}
@Test
public 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.387204 [...]
- " 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. [...]
+ + " 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);
-
-
}
@Test
public 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.387204 [...]
- " 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. [...]
+ + " 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";
}
@Test
public 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 {
@Test
public 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 {
@Test
public 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 {
@Test
public 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);
}
-
@Test
public 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);
}
-
@Test
public 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);
}
-
@Test
public 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);
}
-
@Test
public 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 {
@Test
public 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 mean
if (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 {
@Test
public 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 {
@Test
public 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 {
@Test
public 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 {
@Test
public 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 {
@Test
public 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-2018
public 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 {
@Test
public 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);
-
}
-
@Test
public 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");
}
-
@Test
public 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);
}
-
@Test
public 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);
-
}
-
@Test
public 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);
}
-
@Test
public 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);
}
@Test
public 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 {
@Test
public 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);
}
-
-
-
@Test
public 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 clusters
assertTrue(!(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 {
}
}
-
-
@Test
public 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 {
@Test
public 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 {
@Test
public 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 {
@Test
public 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 clusters
assertTrue(!(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 {
@Test
public 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 clusters
assertTrue(!(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 matrix
assertEquals(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 matrix
assertEquals(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 {
@Test
public 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 {
@Test
public 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);
}
-
-
@Test
public 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);
}
-
@Test
public 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 {
@Test
public 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);
}
@Test
public 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");
}
-
@Test
public 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 distribution
assertEquals(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);
}
@Test
public 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);
}
@Test
public 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);
}
@Test
public 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 {
}
}
-
@Test
public 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 {
@Test
public 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);
}
@Test
public 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);
}
-
@Test
public 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 {
@Test
public 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);
}
@Test
public 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);
}
@Test
public 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 {
@Test
public 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);
}
@Test
public 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);
}
@Test
public 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-2018
public 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 {
@Test
public 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);
}
@Test
public 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);
-
}
@Test
public 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 {
@Test
public 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 {
@Test
public 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);
}
-
@Test
public 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
+ @Test
public 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 {
@Test
public 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 set
assertEquals(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 {
@Test
public 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");
}
@Test
public 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");
}
-
-
@Test
public 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);
-
}
@Test
public 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);
}
-
@Test
public 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 {
@Test
public 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);
}
@Test
public 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 {
@Test
public 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 {
@Test
public 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 change
assertTrue(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-2018
public 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);
}
@Test
public 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());
-
}
@Test
public 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 {
@Test
public 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");
-
-
}
@Test
public 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 {
@Test
public 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);
}
@Test
public 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 tuple
String 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.java
index 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 */
@Test
public 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
*/
@Test
public 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);
}
@Test
public 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);
}
@Test
public 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 values
private 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.java
index 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, Seria
public 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 name
StreamExpression 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;
}
-
+
@Override
public 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, Seria
public 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, Seria
public 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.java
index 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
-@LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})
+@LuceneTestCase.SuppressCodecs({"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 {
@BeforeClass
public 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());
}
}
@Before
public 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.java
index 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.java
index 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
-@LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})
+@LuceneTestCase.SuppressCodecs({"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 {
@BeforeClass
public 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());
}
}
@Before
public 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);
... 12194 lines suppressed ...