You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by jo...@apache.org on 2018/08/26 04:44:30 UTC
[47/49] zeppelin git commit: [ZEPPELIN-3740] Adopt
`google-java-format` and `fmt-maven-plugin`
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
----------------------------------------------------------------------
diff --git a/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java b/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
index df5e4ac..7ee6351 100644
--- a/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
+++ b/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
@@ -16,13 +16,8 @@
*/
package org.apache.zeppelin.cassandra;
-import static com.google.common.collect.FluentIterable.from;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.when;
-
import static com.datastax.driver.core.ProtocolOptions.DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS;
-
+import static com.google.common.collect.FluentIterable.from;
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_CLUSTER_NAME;
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_COMPRESSION_PROTOCOL;
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_CREDENTIALS_PASSWORD;
@@ -52,40 +47,38 @@ import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_SOCKE
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_SOCKET_READ_TIMEOUT_MILLIS;
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_SOCKET_TCP_NO_DELAY;
import static org.apache.zeppelin.cassandra.CassandraInterpreter.CASSANDRA_SPECULATIVE_EXECUTION_POLICY;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Properties;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ProtocolVersion;
import com.datastax.driver.core.Session;
-
import info.archinnov.achilles.embedded.CassandraEmbeddedServerBuilder;
-
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
import org.apache.zeppelin.display.AngularObjectRegistry;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class CassandraInterpreterTest {
private static final String ARTISTS_TABLE = "zeppelin.artists";
- public static Session session = CassandraEmbeddedServerBuilder
- .noEntityPackages()
+ public static Session session =
+ CassandraEmbeddedServerBuilder.noEntityPackages()
.withKeyspaceName("zeppelin")
.withScript("prepare_schema.cql")
.withScript("prepare_data.cql")
@@ -113,8 +106,9 @@ public class CassandraInterpreterTest {
properties.setProperty(CASSANDRA_RECONNECTION_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_SPECULATIVE_EXECUTION_POLICY, "DEFAULT");
- properties.setProperty(CASSANDRA_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS,
- DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS + "");
+ properties.setProperty(
+ CASSANDRA_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS,
+ DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS + "");
properties.setProperty(CASSANDRA_POOLING_NEW_CONNECTION_THRESHOLD_LOCAL, "100");
properties.setProperty(CASSANDRA_POOLING_NEW_CONNECTION_THRESHOLD_REMOTE, "100");
@@ -137,10 +131,11 @@ public class CassandraInterpreterTest {
properties.setProperty(CASSANDRA_SOCKET_READ_TIMEOUT_MILLIS, "12000");
properties.setProperty(CASSANDRA_SOCKET_TCP_NO_DELAY, "true");
- properties.setProperty(CASSANDRA_HOSTS, from(cluster.getMetadata().getAllHosts()).first()
- .get().getAddress().getHostAddress());
- properties.setProperty(CASSANDRA_PORT, cluster.getConfiguration().getProtocolOptions()
- .getPort() + "");
+ properties.setProperty(
+ CASSANDRA_HOSTS,
+ from(cluster.getMetadata().getAllHosts()).first().get().getAddress().getHostAddress());
+ properties.setProperty(
+ CASSANDRA_PORT, cluster.getConfiguration().getProtocolOptions().getPort() + "");
interpreter = new CassandraInterpreter(properties);
interpreter.open();
}
@@ -158,392 +153,418 @@ public class CassandraInterpreterTest {
@Test
public void should_create_cluster_and_session_upon_call_to_open() throws Exception {
assertThat(interpreter.cluster).isNotNull();
- assertThat(interpreter.cluster.getClusterName()).isEqualTo(session.getCluster()
- .getClusterName());
+ assertThat(interpreter.cluster.getClusterName())
+ .isEqualTo(session.getCluster().getClusterName());
assertThat(interpreter.session).isNotNull();
assertThat(interpreter.helper).isNotNull();
}
@Test
public void should_interpret_simple_select() throws Exception {
- //Given
+ // Given
- //When
- final InterpreterResult actual = interpreter.interpret("SELECT * FROM " + ARTISTS_TABLE +
- " LIMIT 10;", intrContext);
+ // When
+ final InterpreterResult actual =
+ interpreter.interpret("SELECT * FROM " + ARTISTS_TABLE + " LIMIT 10;", intrContext);
- //Then
+ // Then
assertThat(actual).isNotNull();
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("name\tborn\tcountry\tdied\tgender\t" +
- "styles\ttype\n" +
- "Bogdan Raczynski\t1977-01-01\tPoland\tnull\tMale\t[Dance, Electro]\tPerson\n" +
- "Krishna Das\t1947-05-31\tUSA\tnull\tMale\t[Unknown]\tPerson\n" +
- "Sheryl Crow\t1962-02-11\tUSA\tnull\tFemale\t" +
- "[Classic, Rock, Country, Blues, Pop, Folk]\tPerson\n" +
- "Doof\t1968-08-31\tUnited Kingdom\tnull\tnull\t[Unknown]\tPerson\n" +
- "House of Large Sizes\t1986-01-01\tUSA\t2003\tnull\t[Unknown]\tGroup\n" +
- "Fanfarlo\t2006-01-01\tUnited Kingdom\tnull\tnull\t" +
- "[Rock, Indie, Pop, Classic]\tGroup\n" +
- "Jeff Beck\t1944-06-24\tUnited Kingdom\tnull\tMale\t[Rock, Pop, Classic]\tPerson\n" +
- "Los Paranoias\tnull\tUnknown\tnull\tnull\t[Unknown]\tnull\n" +
- "…And You Will Know Us by the Trail of Dead\t1994-01-01\tUSA\tnull\tnull\t" +
- "[Rock, Pop, Classic]\tGroup\n");
+ assertThat(actual.message().get(0).getData())
+ .isEqualTo(
+ "name\tborn\tcountry\tdied\tgender\t"
+ + "styles\ttype\n"
+ + "Bogdan Raczynski\t1977-01-01\tPoland\tnull\tMale\t[Dance, Electro]\tPerson\n"
+ + "Krishna Das\t1947-05-31\tUSA\tnull\tMale\t[Unknown]\tPerson\n"
+ + "Sheryl Crow\t1962-02-11\tUSA\tnull\tFemale\t"
+ + "[Classic, Rock, Country, Blues, Pop, Folk]\tPerson\n"
+ + "Doof\t1968-08-31\tUnited Kingdom\tnull\tnull\t[Unknown]\tPerson\n"
+ + "House of Large Sizes\t1986-01-01\tUSA\t2003\tnull\t[Unknown]\tGroup\n"
+ + "Fanfarlo\t2006-01-01\tUnited Kingdom\tnull\tnull\t"
+ + "[Rock, Indie, Pop, Classic]\tGroup\n"
+ + "Jeff Beck\t1944-06-24\tUnited Kingdom\tnull\tMale\t[Rock, Pop, Classic]\tPerson\n"
+ + "Los Paranoias\tnull\tUnknown\tnull\tnull\t[Unknown]\tnull\n"
+ + "…And You Will Know Us by the Trail of Dead\t1994-01-01\tUSA\tnull\tnull\t"
+ + "[Rock, Pop, Classic]\tGroup\n");
}
@Test
public void should_interpret_select_statement() throws Exception {
- //Given
+ // Given
- //When
- final InterpreterResult actual = interpreter.interpret("SELECT * FROM " + ARTISTS_TABLE +
- " LIMIT 2;", intrContext);
+ // When
+ final InterpreterResult actual =
+ interpreter.interpret("SELECT * FROM " + ARTISTS_TABLE + " LIMIT 2;", intrContext);
- //Then
+ // Then
assertThat(actual).isNotNull();
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(actual.message().get(0).getData())
- .isEqualTo("name\tborn\tcountry\tdied\tgender\tstyles\ttype\n" +
- "Bogdan Raczynski\t1977-01-01\tPoland\tnull\tMale\t[Dance, Electro]\tPerson\n" +
- "Krishna Das\t1947-05-31\tUSA\tnull\tMale\t[Unknown]\tPerson\n");
+ .isEqualTo(
+ "name\tborn\tcountry\tdied\tgender\tstyles\ttype\n"
+ + "Bogdan Raczynski\t1977-01-01\tPoland\tnull\tMale\t[Dance, Electro]\tPerson\n"
+ + "Krishna Das\t1947-05-31\tUSA\tnull\tMale\t[Unknown]\tPerson\n");
}
@Test
public void should_interpret_multiple_statements_with_single_line_logged_batch() {
- //Given
- String statements = "CREATE TABLE IF NOT EXISTS zeppelin.albums(\n" +
- " title text PRIMARY KEY,\n" +
- " artist text,\n" +
- " year int\n" +
- ");\n" +
- "BEGIN BATCH" +
- " INSERT INTO zeppelin.albums(title,artist,year) " +
- "VALUES('The Impossible Dream EP','Carter the Unstoppable Sex Machine',1992);" +
- " INSERT INTO zeppelin.albums(title,artist,year) " +
- "VALUES('The Way You Are','Tears for Fears',1983);" +
- " INSERT INTO zeppelin.albums(title,artist,year) " +
- "VALUES('Primitive','Soulfly',2003);" +
- "APPLY BATCH;\n" +
- "SELECT * FROM zeppelin.albums;";
- //When
+ // Given
+ String statements =
+ "CREATE TABLE IF NOT EXISTS zeppelin.albums(\n"
+ + " title text PRIMARY KEY,\n"
+ + " artist text,\n"
+ + " year int\n"
+ + ");\n"
+ + "BEGIN BATCH"
+ + " INSERT INTO zeppelin.albums(title,artist,year) "
+ + "VALUES('The Impossible Dream EP','Carter the Unstoppable Sex Machine',1992);"
+ + " INSERT INTO zeppelin.albums(title,artist,year) "
+ + "VALUES('The Way You Are','Tears for Fears',1983);"
+ + " INSERT INTO zeppelin.albums(title,artist,year) "
+ + "VALUES('Primitive','Soulfly',2003);"
+ + "APPLY BATCH;\n"
+ + "SELECT * FROM zeppelin.albums;";
+ // When
final InterpreterResult actual = interpreter.interpret(statements, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("title\tartist\tyear\n" +
- "The Impossible Dream EP\tCarter the Unstoppable Sex Machine\t1992\n" +
- "The Way You Are\tTears for Fears\t1983\n" +
- "Primitive\tSoulfly\t2003\n");
+ assertThat(actual.message().get(0).getData())
+ .isEqualTo(
+ "title\tartist\tyear\n"
+ + "The Impossible Dream EP\tCarter the Unstoppable Sex Machine\t1992\n"
+ + "The Way You Are\tTears for Fears\t1983\n"
+ + "Primitive\tSoulfly\t2003\n");
}
-
+
@Test
public void should_throw_statement_not_having_semi_colon() throws Exception {
- //Given
+ // Given
String statement = "SELECT * zeppelin.albums";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.ERROR);
assertThat(actual.message().get(0).getData())
- .contains("Error parsing input:\n" +
- "\t'SELECT * zeppelin.albums'\n" +
- "Did you forget to add ; (semi-colon) at the end of each CQL statement ?");
+ .contains(
+ "Error parsing input:\n"
+ + "\t'SELECT * zeppelin.albums'\n"
+ + "Did you forget to add ; (semi-colon) at the end of each CQL statement ?");
}
@Test
public void should_validate_statement() throws Exception {
- //Given
+ // Given
String statement = "SELECT * zeppelin.albums;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.ERROR);
assertThat(actual.message().get(0).getData())
- .contains("line 1:9 missing K_FROM at 'zeppelin' (SELECT * [zeppelin]....)");
+ .contains("line 1:9 missing K_FROM at 'zeppelin' (SELECT * [zeppelin]....)");
}
@Test
public void should_execute_statement_with_consistency_option() throws Exception {
- //Given
- String statement = "@consistency=THREE\n" +
- "SELECT * FROM zeppelin.artists LIMIT 1;";
+ // Given
+ String statement = "@consistency=THREE\n" + "SELECT * FROM zeppelin.artists LIMIT 1;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.ERROR);
assertThat(actual.message().get(0).getData())
- .contains("Not enough replicas available for query at consistency THREE (3 required " +
- "but only 1 alive)");
+ .contains(
+ "Not enough replicas available for query at consistency THREE (3 required "
+ + "but only 1 alive)");
}
@Test
public void should_execute_statement_with_serial_consistency_option() throws Exception {
- //Given
- String statement = "@serialConsistency=SERIAL\n" +
- "SELECT * FROM zeppelin.artists LIMIT 1;";
+ // Given
+ String statement = "@serialConsistency=SERIAL\n" + "SELECT * FROM zeppelin.artists LIMIT 1;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
}
@Test
public void should_execute_statement_with_timestamp_option() throws Exception {
- //Given
+ // Given
String statement1 = "INSERT INTO zeppelin.ts(key,val) VALUES('k','v1');";
- String statement2 = "@timestamp=15\n" +
- "INSERT INTO zeppelin.ts(key,val) VALUES('k','v2');";
+ String statement2 = "@timestamp=15\n" + "INSERT INTO zeppelin.ts(key,val) VALUES('k','v2');";
// Insert v1 with current timestamp
interpreter.interpret(statement1, intrContext);
Thread.sleep(1);
- //When
+ // When
// Insert v2 with past timestamp
interpreter.interpret(statement2, intrContext);
- final String actual = session.execute("SELECT * FROM zeppelin.ts LIMIT 1").one()
- .getString("val");
+ final String actual =
+ session.execute("SELECT * FROM zeppelin.ts LIMIT 1").one().getString("val");
- //Then
+ // Then
assertThat(actual).isEqualTo("v1");
}
@Test
public void should_execute_statement_with_retry_policy() throws Exception {
- //Given
- String statement = "@retryPolicy=" + interpreter.LOGGING_DOWNGRADING_RETRY + "\n" +
- "@consistency=THREE\n" +
- "SELECT * FROM zeppelin.artists LIMIT 1;";
-
- //When
+ // Given
+ String statement =
+ "@retryPolicy="
+ + interpreter.LOGGING_DOWNGRADING_RETRY
+ + "\n"
+ + "@consistency=THREE\n"
+ + "SELECT * FROM zeppelin.artists LIMIT 1;";
+
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
}
@Test
public void should_execute_statement_with_request_timeout() throws Exception {
- //Given
- String statement = "@requestTimeOut=10000000\n" +
- "SELECT * FROM zeppelin.artists;";
+ // Given
+ String statement = "@requestTimeOut=10000000\n" + "SELECT * FROM zeppelin.artists;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(statement, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
}
@Test
public void should_execute_prepared_and_bound_statements() throws Exception {
- //Given
- String queries = "@prepare[ps]=INSERT INTO zeppelin.prepared(key,val) VALUES(?,?)\n" +
- "@prepare[select]=SELECT * FROM zeppelin.prepared WHERE key=:key\n" +
- "@bind[ps]='myKey','myValue'\n" +
- "@bind[select]='myKey'";
-
- //When
+ // Given
+ String queries =
+ "@prepare[ps]=INSERT INTO zeppelin.prepared(key,val) VALUES(?,?)\n"
+ + "@prepare[select]=SELECT * FROM zeppelin.prepared WHERE key=:key\n"
+ + "@bind[ps]='myKey','myValue'\n"
+ + "@bind[select]='myKey'";
+
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("key\tval\n" +
- "myKey\tmyValue\n");
+ assertThat(actual.message().get(0).getData()).isEqualTo("key\tval\n" + "myKey\tmyValue\n");
}
@Test
public void should_execute_bound_statement() throws Exception {
- //Given
- String queries = "@prepare[users_insert]=INSERT INTO zeppelin.users" +
- "(login,firstname,lastname,addresses,location)" +
- "VALUES(:login,:fn,:ln,:addresses,:loc)\n" +
- "@bind[users_insert]='jdoe','John','DOE'," +
- "{street_number: 3, street_name: 'Beverly Hills Bld', zip_code: 90209," +
- " country: 'USA', extra_info: ['Right on the hills','Next to the post box']," +
- " phone_numbers: {'home': 2016778524, 'office': 2015790847}}," +
- "('USA', 90209, 'Beverly Hills')\n" +
- "SELECT * FROM zeppelin.users WHERE login='jdoe';";
- //When
+ // Given
+ String queries =
+ "@prepare[users_insert]=INSERT INTO zeppelin.users"
+ + "(login,firstname,lastname,addresses,location)"
+ + "VALUES(:login,:fn,:ln,:addresses,:loc)\n"
+ + "@bind[users_insert]='jdoe','John','DOE',"
+ + "{street_number: 3, street_name: 'Beverly Hills Bld', zip_code: 90209,"
+ + " country: 'USA', extra_info: ['Right on the hills','Next to the post box'],"
+ + " phone_numbers: {'home': 2016778524, 'office': 2015790847}},"
+ + "('USA', 90209, 'Beverly Hills')\n"
+ + "SELECT * FROM zeppelin.users WHERE login='jdoe';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo(
- "login\taddresses\tage\tdeceased\tfirstname\tlast_update\tlastname\tlocation\n" +
- "jdoe\t" +
- "{street_number:3,street_name:'Beverly Hills Bld',zip_code:90209," +
- "country:'USA',extra_info:['Right on the hills','Next to the post box']," +
- "phone_numbers:{'office':2015790847,'home':2016778524}}\tnull\t" +
- "null\t" +
- "John\t" +
- "null\t" +
- "DOE\t" +
- "('USA',90209,'Beverly Hills')\n");
+ assertThat(actual.message().get(0).getData())
+ .isEqualTo(
+ "login\taddresses\tage\tdeceased\tfirstname\tlast_update\tlastname\tlocation\n"
+ + "jdoe\t"
+ + "{street_number:3,street_name:'Beverly Hills Bld',zip_code:90209,"
+ + "country:'USA',extra_info:['Right on the hills','Next to the post box'],"
+ + "phone_numbers:{'office':2015790847,'home':2016778524}}\tnull\t"
+ + "null\t"
+ + "John\t"
+ + "null\t"
+ + "DOE\t"
+ + "('USA',90209,'Beverly Hills')\n");
}
@Test
public void should_exception_when_executing_unknown_bound_statement() throws Exception {
- //Given
+ // Given
String queries = "@bind[select_users]='jdoe'";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.ERROR);
assertThat(actual.message().get(0).getData())
- .isEqualTo("The statement 'select_users' can not be bound to values. " +
- "Are you sure you did prepare it with @prepare[select_users] ?");
+ .isEqualTo(
+ "The statement 'select_users' can not be bound to values. "
+ + "Are you sure you did prepare it with @prepare[select_users] ?");
}
@Test
public void should_extract_variable_from_statement() throws Exception {
- //Given
+ // Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getGui().input("login", "hsue")).thenReturn("hsue");
when(intrContext.getGui().input("age", "27")).thenReturn("27");
- String queries = "@prepare[test_insert_with_variable]=" +
- "INSERT INTO zeppelin.users(login,firstname,lastname,age) VALUES(?,?,?,?)\n" +
- "@bind[test_insert_with_variable]='{{login=hsue}}','Helen','SUE',{{age=27}}\n" +
- "SELECT firstname,lastname,age FROM zeppelin.users WHERE login='hsue';";
- //When
+ String queries =
+ "@prepare[test_insert_with_variable]="
+ + "INSERT INTO zeppelin.users(login,firstname,lastname,age) VALUES(?,?,?,?)\n"
+ + "@bind[test_insert_with_variable]='{{login=hsue}}','Helen','SUE',{{age=27}}\n"
+ + "SELECT firstname,lastname,age FROM zeppelin.users WHERE login='hsue';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("firstname\tlastname\tage\n" +
- "Helen\tSUE\t27\n");
+ assertThat(actual.message().get(0).getData())
+ .isEqualTo("firstname\tlastname\tage\n" + "Helen\tSUE\t27\n");
}
@Test
public void should_just_prepare_statement() throws Exception {
- //Given
- String queries = "@prepare[just_prepare]=SELECT name,country,styles " +
- "FROM zeppelin.artists LIMIT 3";
- final String expected = reformatHtml(
- readTestResource("/scalate/NoResult.html"));
+ // Given
+ String queries =
+ "@prepare[just_prepare]=SELECT name,country,styles " + "FROM zeppelin.artists LIMIT 3";
+ final String expected = reformatHtml(readTestResource("/scalate/NoResult.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
@Test
public void should_execute_bound_statement_with_no_bound_value() throws Exception {
- //Given
- String queries = "@prepare[select_no_bound_value]=SELECT name,country,styles " +
- "FROM zeppelin.artists LIMIT 3\n" +
- "@bind[select_no_bound_value]";
+ // Given
+ String queries =
+ "@prepare[select_no_bound_value]=SELECT name,country,styles "
+ + "FROM zeppelin.artists LIMIT 3\n"
+ + "@bind[select_no_bound_value]";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("name\tcountry\tstyles\n" +
- "Bogdan Raczynski\tPoland\t[Dance, Electro]\n" +
- "Krishna Das\tUSA\t[Unknown]\n" +
- "Sheryl Crow\tUSA\t[Classic, Rock, Country, Blues, Pop, Folk]\n");
+ assertThat(actual.message().get(0).getData())
+ .isEqualTo(
+ "name\tcountry\tstyles\n"
+ + "Bogdan Raczynski\tPoland\t[Dance, Electro]\n"
+ + "Krishna Das\tUSA\t[Unknown]\n"
+ + "Sheryl Crow\tUSA\t[Classic, Rock, Country, Blues, Pop, Folk]\n");
}
@Test
public void should_parse_date_value() throws Exception {
- //Given
- String queries = "@prepare[parse_date]=INSERT INTO zeppelin.users(login,last_update) " +
- "VALUES(?,?)\n" +
- "@bind[parse_date]='last_update','2015-07-30 12:00:01'\n" +
- "SELECT last_update FROM zeppelin.users WHERE login='last_update';";
- //When
+ // Given
+ String queries =
+ "@prepare[parse_date]=INSERT INTO zeppelin.users(login,last_update) "
+ + "VALUES(?,?)\n"
+ + "@bind[parse_date]='last_update','2015-07-30 12:00:01'\n"
+ + "SELECT last_update FROM zeppelin.users WHERE login='last_update';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).contains("last_update\n" +
- "Thu Jul 30 12:00:01");
+ assertThat(actual.message().get(0).getData()).contains("last_update\n" + "Thu Jul 30 12:00:01");
}
@Test
public void should_bind_null_value() throws Exception {
- //Given
- String queries = "@prepare[bind_null]=INSERT INTO zeppelin.users(login,firstname,lastname) " +
- "VALUES(?,?,?)\n" +
- "@bind[bind_null]='bind_null',null,'NULL'\n" +
- "SELECT firstname,lastname FROM zeppelin.users WHERE login='bind_null';";
- //When
+ // Given
+ String queries =
+ "@prepare[bind_null]=INSERT INTO zeppelin.users(login,firstname,lastname) "
+ + "VALUES(?,?,?)\n"
+ + "@bind[bind_null]='bind_null',null,'NULL'\n"
+ + "SELECT firstname,lastname FROM zeppelin.users WHERE login='bind_null';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("firstname\tlastname\n" +
- "null\tNULL\n");
+ assertThat(actual.message().get(0).getData())
+ .isEqualTo("firstname\tlastname\n" + "null\tNULL\n");
}
@Test
public void should_bind_boolean_value() throws Exception {
- //Given
- String queries = "@prepare[bind_boolean]=INSERT INTO zeppelin.users(login,deceased) " +
- "VALUES(?,?)\n" +
- "@bind[bind_boolean]='bind_bool',false\n" +
- "SELECT login,deceased FROM zeppelin.users WHERE login='bind_bool';";
- //When
+ // Given
+ String queries =
+ "@prepare[bind_boolean]=INSERT INTO zeppelin.users(login,deceased) "
+ + "VALUES(?,?)\n"
+ + "@bind[bind_boolean]='bind_bool',false\n"
+ + "SELECT login,deceased FROM zeppelin.users WHERE login='bind_bool';";
+ // When
final InterpreterResult actual = interpreter.interpret(queries, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
- assertThat(actual.message().get(0).getData()).isEqualTo("login\tdeceased\n" +
- "bind_bool\tfalse\n");
+ assertThat(actual.message().get(0).getData())
+ .isEqualTo("login\tdeceased\n" + "bind_bool\tfalse\n");
}
@Test
public void should_fail_when_executing_a_removed_prepared_statement() throws Exception {
- //Given
- String prepareFirst = "@prepare[to_be_removed]=INSERT INTO zeppelin.users(login,deceased) " +
- "VALUES(?,?)";
+ // Given
+ String prepareFirst =
+ "@prepare[to_be_removed]=INSERT INTO zeppelin.users(login,deceased) " + "VALUES(?,?)";
interpreter.interpret(prepareFirst, intrContext);
- String removePrepared = "@remove_prepare[to_be_removed]\n" +
- "@bind[to_be_removed]='bind_bool'";
+ String removePrepared = "@remove_prepare[to_be_removed]\n" + "@bind[to_be_removed]='bind_bool'";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(removePrepared, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.ERROR);
- assertThat(actual.message().get(0).getData()).isEqualTo("The statement 'to_be_removed' can " +
- "not be bound to values. Are you sure you did prepare it with " +
- "@prepare[to_be_removed] ?");
+ assertThat(actual.message().get(0).getData())
+ .isEqualTo(
+ "The statement 'to_be_removed' can "
+ + "not be bound to values. Are you sure you did prepare it with "
+ + "@prepare[to_be_removed] ?");
}
@Test
public void should_display_statistics_for_non_select_statement() throws Exception {
- //Given
+ // Given
String query = "USE zeppelin;\nCREATE TABLE IF NOT EXISTS no_select(id int PRIMARY KEY);";
- final String rawResult = reformatHtml(readTestResource(
- "/scalate/NoResultWithExecutionInfo.html"));
+ final String rawResult =
+ reformatHtml(readTestResource("/scalate/NoResultWithExecutionInfo.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
final Cluster cluster = session.getCluster();
final int port = cluster.getConfiguration().getProtocolOptions().getPort();
- final String address = cluster.getMetadata().getAllHosts().iterator().next()
- .getAddress().getHostAddress()
- .replaceAll("/", "").replaceAll("\\[", "").replaceAll("\\]", "");
- //Then
- final String expected = rawResult.replaceAll("TRIED_HOSTS", address + ":" + port)
+ final String address =
+ cluster
+ .getMetadata()
+ .getAllHosts()
+ .iterator()
+ .next()
+ .getAddress()
+ .getHostAddress()
+ .replaceAll("/", "")
+ .replaceAll("\\[", "")
+ .replaceAll("\\]", "");
+ // Then
+ final String expected =
+ rawResult
+ .replaceAll("TRIED_HOSTS", address + ":" + port)
.replaceAll("QUERIED_HOSTS", address + ":" + port);
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
@@ -552,228 +573,225 @@ public class CassandraInterpreterTest {
@Test
public void should_error_and_display_stack_trace() throws Exception {
- //Given
- String query = "@consistency=THREE\n" +
- "SELECT * FROM zeppelin.users LIMIT 3;";
- //When
+ // Given
+ String query = "@consistency=THREE\n" + "SELECT * FROM zeppelin.users LIMIT 3;";
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.ERROR);
assertThat(actual.message().get(0).getData()).contains("All host(s) tried for query failed");
}
@Test
public void should_describe_cluster() throws Exception {
- //Given
+ // Given
String query = "DESCRIBE CLUSTER;";
- final String expected = reformatHtml(
- readTestResource("/scalate/DescribeCluster.html"));
+ final String expected = reformatHtml(readTestResource("/scalate/DescribeCluster.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
@Test
public void should_describe_keyspaces() throws Exception {
- //Given
+ // Given
String query = "DESCRIBE KEYSPACES;";
- final String expected = reformatHtml(
- readTestResource("/scalate/DescribeKeyspaces.html"));
+ final String expected = reformatHtml(readTestResource("/scalate/DescribeKeyspaces.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
@Test
public void should_describe_keyspace() throws Exception {
- //Given
+ // Given
String query = "DESCRIBE KEYSPACE live_data;";
- final String expected = reformatHtml(
- readTestResource("/scalate/DescribeKeyspace_live_data.html"));
+ final String expected =
+ reformatHtml(readTestResource("/scalate/DescribeKeyspace_live_data.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
@Test
@Ignore
- //TODO(n.a.) activate test when using Java 8 and C* 3.x
+ // TODO(n.a.) activate test when using Java 8 and C* 3.x
public void should_describe_function() throws Exception {
- //Given
+ // Given
Properties properties = new Properties();
properties.setProperty(CASSANDRA_HOSTS, "127.0.0.1");
- properties.setProperty(CASSANDRA_PORT, "9042");
+ properties.setProperty(CASSANDRA_PORT, "9042");
Interpreter interpreter = new CassandraInterpreter(properties);
interpreter.open();
- String createFunction = "CREATE FUNCTION zeppelin.maxof(val1 int,val2 int) " +
- "RETURNS NULL ON NULL INPUT " +
- "RETURNS int " +
- "LANGUAGE java " +
- "AS $$" +
- " return Math.max(val1, val2);\n" +
- "$$;";
+ String createFunction =
+ "CREATE FUNCTION zeppelin.maxof(val1 int,val2 int) "
+ + "RETURNS NULL ON NULL INPUT "
+ + "RETURNS int "
+ + "LANGUAGE java "
+ + "AS $$"
+ + " return Math.max(val1, val2);\n"
+ + "$$;";
interpreter.interpret(createFunction, intrContext);
String query = "DESCRIBE FUNCTION zeppelin.maxOf;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(actual.message()).isEqualTo("xxxxx");
}
@Test
@Ignore
- //TODO(n.a.) activate test when using Java 8 and C* 3.x
+ // TODO(n.a.) activate test when using Java 8 and C* 3.x
public void should_describe_aggregate() throws Exception {
- //Given
+ // Given
Properties properties = new Properties();
properties.setProperty(CASSANDRA_HOSTS, "127.0.0.1");
- properties.setProperty(CASSANDRA_PORT, "9042");
+ properties.setProperty(CASSANDRA_PORT, "9042");
Interpreter interpreter = new CassandraInterpreter(properties);
interpreter.open();
final String query = "DESCRIBE AGGREGATES;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
}
@Test
@Ignore
- //TODO(n.a.) activate test when using Java 8 and C* 3.x
+ // TODO(n.a.) activate test when using Java 8 and C* 3.x
public void should_describe_materialized_view() throws Exception {
- //Given
+ // Given
Properties properties = new Properties();
properties.setProperty(CASSANDRA_HOSTS, "127.0.0.1");
- properties.setProperty(CASSANDRA_PORT, "9042");
+ properties.setProperty(CASSANDRA_PORT, "9042");
Interpreter interpreter = new CassandraInterpreter(properties);
interpreter.open();
final String query = "DESCRIBE MATERIALIZED VIEWS;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
}
@Test
public void should_describe_table() throws Exception {
- //Given
+ // Given
String query = "DESCRIBE TABLE live_data.complex_table;";
- final String expected = reformatHtml(
- readTestResource("/scalate/DescribeTable_live_data_complex_table.html"));
+ final String expected =
+ reformatHtml(readTestResource("/scalate/DescribeTable_live_data_complex_table.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
@Test
public void should_describe_udt() throws Exception {
- //Given
+ // Given
String query = "DESCRIBE TYPE live_data.address;";
- final String expected = reformatHtml(
- readTestResource("/scalate/DescribeType_live_data_address.html"));
+ final String expected =
+ reformatHtml(readTestResource("/scalate/DescribeType_live_data_address.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
@Test
public void should_describe_udt_withing_logged_in_keyspace() throws Exception {
- //Given
- String query = "USE live_data;\n" +
- "DESCRIBE TYPE address;";
- final String expected = reformatHtml(readTestResource(
- "/scalate/DescribeType_live_data_address_within_current_keyspace.html"));
-
- //When
+ // Given
+ String query = "USE live_data;\n" + "DESCRIBE TYPE address;";
+ final String expected =
+ reformatHtml(
+ readTestResource(
+ "/scalate/DescribeType_live_data_address_within_current_keyspace.html"));
+
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
@Test
public void should_error_describing_non_existing_table() throws Exception {
- //Given
- String query = "USE system;\n" +
- "DESCRIBE TABLE complex_table;";
+ // Given
+ String query = "USE system;\n" + "DESCRIBE TABLE complex_table;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.ERROR);
assertThat(actual.message().get(0).getData())
- .contains("Cannot find table system.complex_table");
+ .contains("Cannot find table system.complex_table");
}
@Test
public void should_error_describing_non_existing_udt() throws Exception {
- //Given
- String query = "USE system;\n" +
- "DESCRIBE TYPE address;";
+ // Given
+ String query = "USE system;\n" + "DESCRIBE TYPE address;";
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.ERROR);
assertThat(actual.message().get(0).getData()).contains("Cannot find type system.address");
}
@Test
public void should_show_help() throws Exception {
- //Given
+ // Given
String query = "HELP;";
final String expected = reformatHtml(readTestResource("/scalate/Help.html"));
- //When
+ // When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
- //Then
+ // Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
private static String reformatHtml(String rawHtml) {
- return rawHtml
- .replaceAll("\\s*\n\\s*", "")
- .replaceAll(">\\s+<", "><")
- .replaceAll("(?s)data-target=\"#[a-f0-9-]+(?:_asCQL|_indices_asCQL)?\"", "")
- .replaceAll("(?s)id=\"[a-f0-9-]+(?:_asCQL|_indices_asCQL)?\"", "")
- .trim();
+ return rawHtml
+ .replaceAll("\\s*\n\\s*", "")
+ .replaceAll(">\\s+<", "><")
+ .replaceAll("(?s)data-target=\"#[a-f0-9-]+(?:_asCQL|_indices_asCQL)?\"", "")
+ .replaceAll("(?s)id=\"[a-f0-9-]+(?:_asCQL|_indices_asCQL)?\"", "")
+ .trim();
}
private static String readTestResource(String testResource) {
@@ -786,7 +804,7 @@ public class CassandraInterpreterTest {
builder.append(line).append("\n");
}
} catch (Exception ex) {
- throw new RuntimeException(ex);
+ throw new RuntimeException(ex);
}
return builder.toString();
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java
----------------------------------------------------------------------
diff --git a/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java b/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java
index e096a0c..71db121 100644
--- a/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java
+++ b/cassandra/src/test/java/org/apache/zeppelin/cassandra/InterpreterLogicTest.java
@@ -16,6 +16,13 @@
*/
package org.apache.zeppelin.cassandra;
+import static com.datastax.driver.core.BatchStatement.Type.UNLOGGED;
+import static com.datastax.driver.core.ConsistencyLevel.ALL;
+import static com.datastax.driver.core.ConsistencyLevel.LOCAL_SERIAL;
+import static com.datastax.driver.core.ConsistencyLevel.ONE;
+import static com.datastax.driver.core.ConsistencyLevel.QUORUM;
+import static com.datastax.driver.core.ConsistencyLevel.SERIAL;
+import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
@@ -24,39 +31,16 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
-import static java.util.Arrays.asList;
-
-import static com.datastax.driver.core.BatchStatement.Type.UNLOGGED;
-import static com.datastax.driver.core.ConsistencyLevel.ALL;
-import static com.datastax.driver.core.ConsistencyLevel.LOCAL_SERIAL;
-import static com.datastax.driver.core.ConsistencyLevel.ONE;
-import static com.datastax.driver.core.ConsistencyLevel.QUORUM;
-import static com.datastax.driver.core.ConsistencyLevel.SERIAL;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-
import com.datastax.driver.core.BatchStatement;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.Statement;
-
-import scala.Option;
-
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
import org.apache.zeppelin.cassandra.TextBlockHierarchy.AnyBlock;
import org.apache.zeppelin.cassandra.TextBlockHierarchy.Consistency;
import org.apache.zeppelin.cassandra.TextBlockHierarchy.DowngradingRetryPolicy$;
@@ -72,80 +56,90 @@ import org.apache.zeppelin.display.GUI;
import org.apache.zeppelin.display.ui.OptionInput.ParamOption;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import scala.Option;
@RunWith(MockitoJUnitRunner.class)
public class InterpreterLogicTest {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
+ @Rule public ExpectedException expectedException = ExpectedException.none();
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private InterpreterContext intrContext;
- @Mock
- private Session session;
+ @Mock private Session session;
final InterpreterLogic helper = new InterpreterLogic(session);
- @Captor
- ArgumentCaptor<ParamOption[]> optionsCaptor;
+ @Captor ArgumentCaptor<ParamOption[]> optionsCaptor;
@Test
public void should_parse_input_string_block() throws Exception {
- //Given
+ // Given
String input = "SELECT * FROM users LIMIT 10;";
- //When
+ // When
final List<AnyBlock> anyBlocks = this.<AnyBlock>toJavaList(helper.parseInput(input));
- //Then
+ // Then
assertThat(anyBlocks).hasSize(1);
assertThat(anyBlocks.get(0)).isInstanceOf(SimpleStm.class);
}
@Test
public void should_exception_while_parsing_input() throws Exception {
- //Given
+ // Given
String input = "SELECT * FROM users LIMIT 10";
- //When
+ // When
expectedException.expect(InterpreterException.class);
- expectedException.expectMessage("Error parsing input:\n" +
- "\t'SELECT * FROM users LIMIT 10'\n" +
- "Did you forget to add ; (semi-colon) at the end of each CQL statement ?");
+ expectedException.expectMessage(
+ "Error parsing input:\n"
+ + "\t'SELECT * FROM users LIMIT 10'\n"
+ + "Did you forget to add ; (semi-colon) at the end of each CQL statement ?");
helper.parseInput(input);
}
@Test
public void should_extract_variable_and_default_value() throws Exception {
- //Given
+ // Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getGui().input("table", "zeppelin.demo")).thenReturn("zeppelin.demo");
when(intrContext.getGui().input("id", "'John'")).thenReturn("'John'");
- //When
- final String actual = helper.maybeExtractVariables(
+ // When
+ final String actual =
+ helper.maybeExtractVariables(
"SELECT * FROM {{table=zeppelin.demo}} WHERE id={{id='John'}}", intrContext);
- //Then
+ // Then
assertThat(actual).isEqualTo("SELECT * FROM zeppelin.demo WHERE id='John'");
}
@Test
public void should_extract_variable_and_choices() throws Exception {
- //Given
+ // Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getGui().select(eq("name"), eq("'Paul'"), optionsCaptor.capture()))
- .thenReturn("'Jack'");
+ .thenReturn("'Jack'");
- //When
- final String actual = helper.maybeExtractVariables(
+ // When
+ final String actual =
+ helper.maybeExtractVariables(
"SELECT * FROM zeppelin.artists WHERE name={{name='Paul'|'Jack'|'Smith'}}",
intrContext);
- //Then
+ // Then
assertThat(actual).isEqualTo("SELECT * FROM zeppelin.artists WHERE name='Jack'");
final List<ParamOption> paramOptions = asList(optionsCaptor.getValue());
assertThat(paramOptions.get(0).getValue()).isEqualTo("'Paul'");
@@ -155,131 +149,137 @@ public class InterpreterLogicTest {
@Test
public void should_extract_no_variable() throws Exception {
- //Given
+ // Given
GUI gui = mock(GUI.class);
when(intrContext.getGui()).thenReturn(gui);
- //When
+ // When
final String actual = helper.maybeExtractVariables("SELECT * FROM zeppelin.demo", intrContext);
- //Then
+ // Then
verifyZeroInteractions(gui);
assertThat(actual).isEqualTo("SELECT * FROM zeppelin.demo");
}
@Test
public void should_extract_variable_from_angular_object_registry() throws Exception {
- //Given
+ // Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
angularObjectRegistry.add("id", "from_angular_registry", "noteId", "paragraphId");
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getNoteId()).thenReturn("noteId");
when(intrContext.getParagraphId()).thenReturn("paragraphId");
- //When
- final String actual = helper.maybeExtractVariables(
+ // When
+ final String actual =
+ helper.maybeExtractVariables(
"SELECT * FROM zeppelin.demo WHERE id='{{id=John}}'", intrContext);
- //Then
+ // Then
assertThat(actual).isEqualTo("SELECT * FROM zeppelin.demo WHERE id='from_angular_registry'");
verify(intrContext, never()).getGui();
}
@Test
public void should_error_if_incorrect_variable_definition() throws Exception {
- //Given
+ // Given
- //When
+ // When
expectedException.expect(ParsingException.class);
- expectedException.expectMessage("Invalid bound variable definition for " +
- "'{{table?zeppelin.demo}}' in 'SELECT * FROM {{table?zeppelin.demo}} " +
- "WHERE id={{id='John'}}'. It should be of form 'variable=defaultValue'");
-
- //Then
- helper.maybeExtractVariables("SELECT * FROM {{table?zeppelin.demo}} WHERE id={{id='John'}}",
- intrContext);
+ expectedException.expectMessage(
+ "Invalid bound variable definition for "
+ + "'{{table?zeppelin.demo}}' in 'SELECT * FROM {{table?zeppelin.demo}} "
+ + "WHERE id={{id='John'}}'. It should be of form 'variable=defaultValue'");
+
+ // Then
+ helper.maybeExtractVariables(
+ "SELECT * FROM {{table?zeppelin.demo}} WHERE id={{id='John'}}", intrContext);
}
@Test
public void should_extract_consistency_option() throws Exception {
- //Given
- List<QueryParameters> options = Arrays.<QueryParameters>asList(new Consistency(ALL),
- new Consistency(ONE));
+ // Given
+ List<QueryParameters> options =
+ Arrays.<QueryParameters>asList(new Consistency(ALL), new Consistency(ONE));
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
+ // Then
assertThat(actual.consistency().get()).isEqualTo(ALL);
}
@Test
public void should_extract_serial_consistency_option() throws Exception {
- //Given
- List<QueryParameters> options = Arrays.<QueryParameters>asList(new SerialConsistency(SERIAL),
- new SerialConsistency(LOCAL_SERIAL));
+ // Given
+ List<QueryParameters> options =
+ Arrays.<QueryParameters>asList(
+ new SerialConsistency(SERIAL), new SerialConsistency(LOCAL_SERIAL));
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
+ // Then
assertThat(actual.serialConsistency().get()).isEqualTo(SERIAL);
}
@Test
public void should_extract_timestamp_option() throws Exception {
- //Given
- List<QueryParameters> options = Arrays.<QueryParameters>asList(new Timestamp(123L),
- new Timestamp(456L));
+ // Given
+ List<QueryParameters> options =
+ Arrays.<QueryParameters>asList(new Timestamp(123L), new Timestamp(456L));
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
+ // Then
assertThat(actual.timestamp().get()).isEqualTo(123L);
}
@Test
public void should_extract_retry_policy_option() throws Exception {
- //Given
- List<QueryParameters> options = Arrays.<QueryParameters>asList(DowngradingRetryPolicy$.MODULE$,
- LoggingDefaultRetryPolicy$.MODULE$);
+ // Given
+ List<QueryParameters> options =
+ Arrays.<QueryParameters>asList(
+ DowngradingRetryPolicy$.MODULE$, LoggingDefaultRetryPolicy$.MODULE$);
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
+ // Then
assertThat(actual.retryPolicy().get()).isSameAs(DowngradingRetryPolicy$.MODULE$);
}
@Test
public void should_extract_request_timeout_option() throws Exception {
- //Given
+ // Given
List<QueryParameters> options = Arrays.<QueryParameters>asList(new RequestTimeOut(100));
- //When
+ // When
final CassandraQueryOptions actual = helper.extractQueryOptions(toScalaList(options));
- //Then
+ // Then
assertThat(actual.requestTimeOut().get()).isEqualTo(100);
}
@Test
public void should_generate_simple_statement() throws Exception {
- //Given
+ // Given
String input = "SELECT * FROM users LIMIT 10;";
- CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
+ CassandraQueryOptions options =
+ new CassandraQueryOptions(
+ Option.apply(QUORUM),
Option.<ConsistencyLevel>empty(),
Option.empty(),
Option.<RetryPolicy>empty(),
Option.empty(),
Option.empty());
- //When
- final SimpleStatement actual = helper.generateSimpleStatement(new SimpleStm(input), options,
- intrContext);
+ // When
+ final SimpleStatement actual =
+ helper.generateSimpleStatement(new SimpleStm(input), options, intrContext);
- //Then
+ // Then
assertThat(actual).isNotNull();
assertThat(actual.getQueryString()).isEqualTo("SELECT * FROM users LIMIT 10;");
assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
@@ -287,22 +287,24 @@ public class InterpreterLogicTest {
@Test
public void should_generate_batch_statement() throws Exception {
- //Given
+ // Given
Statement st1 = new SimpleStatement("SELECT * FROM users LIMIT 10;");
Statement st2 = new SimpleStatement("INSERT INTO users(id) VALUES(10);");
Statement st3 = new SimpleStatement("UPDATE users SET name = 'John DOE' WHERE id=10;");
- CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
+ CassandraQueryOptions options =
+ new CassandraQueryOptions(
+ Option.apply(QUORUM),
Option.<ConsistencyLevel>empty(),
Option.empty(),
Option.<RetryPolicy>empty(),
Option.empty(),
Option.empty());
- //When
- BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options,
- toScalaList(asList(st1, st2, st3)));
+ // When
+ BatchStatement actual =
+ helper.generateBatchStatement(UNLOGGED, options, toScalaList(asList(st1, st2, st3)));
- //Then
+ // Then
assertThat(actual).isNotNull();
final List<Statement> statements = new ArrayList<>(actual.getStatements());
assertThat(statements).hasSize(3);
@@ -314,26 +316,26 @@ public class InterpreterLogicTest {
@Test
public void should_parse_bound_values() throws Exception {
- //Given
+ // Given
String bs = "'jdoe',32,'John DOE',null, true, '2014-06-12 34:00:34'";
- //When
+ // When
final List<String> actual = this.<String>toJavaList(helper.parseBoundValues("ps", bs));
- //Then
- assertThat(actual).containsExactly("'jdoe'", "32", "'John DOE'",
- "null", "true", "2014-06-12 34:00:34");
+ // Then
+ assertThat(actual)
+ .containsExactly("'jdoe'", "32", "'John DOE'", "null", "true", "2014-06-12 34:00:34");
}
@Test
public void should_parse_simple_date() throws Exception {
- //Given
+ // Given
String dateString = "2015-07-30 12:00:01";
- //When
+ // When
final Date actual = helper.parseDate(dateString);
- //Then
+ // Then
Calendar calendar = Calendar.getInstance();
calendar.setTime(actual);
@@ -347,13 +349,13 @@ public class InterpreterLogicTest {
@Test
public void should_parse_accurate_date() throws Exception {
- //Given
+ // Given
String dateString = "2015-07-30 12:00:01.123";
- //When
+ // When
final Date actual = helper.parseDate(dateString);
- //Then
+ // Then
Calendar calendar = Calendar.getInstance();
calendar.setTime(actual);
@@ -366,11 +368,11 @@ public class InterpreterLogicTest {
assertThat(calendar.get(Calendar.MILLISECOND)).isEqualTo(123);
}
- private <A> scala.collection.immutable.List<A> toScalaList(java.util.List<A> list) {
+ private <A> scala.collection.immutable.List<A> toScalaList(java.util.List<A> list) {
return scala.collection.JavaConversions.collectionAsScalaIterable(list).toList();
}
- private <A> java.util.List<A> toJavaList(scala.collection.immutable.List<A> list){
+ private <A> java.util.List<A> toJavaList(scala.collection.immutable.List<A> list) {
return scala.collection.JavaConversions.seqAsJavaList(list);
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/docs/development/contribution/how_to_contribute_code.md
----------------------------------------------------------------------
diff --git a/docs/development/contribution/how_to_contribute_code.md b/docs/development/contribution/how_to_contribute_code.md
index e71326e..05963f1 100644
--- a/docs/development/contribution/how_to_contribute_code.md
+++ b/docs/development/contribution/how_to_contribute_code.md
@@ -37,6 +37,10 @@ Since Zeppelin uses Git for it's SCM system, you need git client installed in yo
You are free to use whatever IDE you prefer, or your favorite command line editor.
+#### Code Style
+
+We decided to use `google-java-format`. You can install this formatter from [https://github.com/google/google-java-format](https://github.com/google/google-java-format). And the build script also contains `fmt-maven-plugin` to verify the formats of files. You can check `mvn validate` and fix wrong formats by running `mvn fmt:format` manually.
+
#### Build Tools
To build the code, install
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/elasticsearch/pom.xml b/elasticsearch/pom.xml
index 4e4021f..f80cbc5 100644
--- a/elasticsearch/pom.xml
+++ b/elasticsearch/pom.xml
@@ -101,13 +101,6 @@
<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <configuration>
- <skip>false</skip>
- </configuration>
- </plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java
index 45b37c4..3c58b50 100644
--- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java
+++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java
@@ -17,23 +17,10 @@
package org.apache.zeppelin.elasticsearch;
+import com.github.wnameless.json.flattener.JsonFlattener;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
-
-import org.apache.commons.lang3.StringUtils;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentHelper;
-import org.elasticsearch.search.aggregations.Aggregation;
-import org.elasticsearch.search.aggregations.Aggregations;
-import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
-import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation;
-import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
-import org.elasticsearch.search.aggregations.metrics.InternalMetricsAggregation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -48,9 +35,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
-import com.github.wnameless.json.flattener.JsonFlattener;
-
+import org.apache.commons.lang3.StringUtils;
import org.apache.zeppelin.completer.CompletionType;
import org.apache.zeppelin.elasticsearch.action.ActionResponse;
import org.apache.zeppelin.elasticsearch.action.AggWrapper;
@@ -62,33 +47,43 @@ import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentHelper;
+import org.elasticsearch.search.aggregations.Aggregation;
+import org.elasticsearch.search.aggregations.Aggregations;
+import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
+import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation;
+import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
+import org.elasticsearch.search.aggregations.metrics.InternalMetricsAggregation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-/**
- * Elasticsearch Interpreter for Zeppelin.
- */
+/** Elasticsearch Interpreter for Zeppelin. */
public class ElasticsearchInterpreter extends Interpreter {
private static Logger logger = LoggerFactory.getLogger(ElasticsearchInterpreter.class);
- private static final String HELP = "Elasticsearch interpreter:\n"
- + "General format: <command> /<indices>/<types>/<id> <option> <JSON>\n"
- + " - indices: list of indices separated by commas (depends on the command)\n"
- + " - types: list of document types separated by commas (depends on the command)\n"
- + "Commands:\n"
- + " - search /indices/types <query>\n"
- + " . indices and types can be omitted (at least, you have to provide '/')\n"
- + " . a query is either a JSON-formatted query, nor a lucene query\n"
- + " - size <value>\n"
- + " . defines the size of the result set (default value is in the config)\n"
- + " . if used, this command must be declared before a search command\n"
- + " - count /indices/types <query>\n"
- + " . same comments as for the search\n"
- + " - get /index/type/id\n"
- + " - delete /index/type/id\n"
- + " - index /index/type/id <json-formatted document>\n"
- + " . the id can be omitted, elasticsearch will generate one";
-
- protected static final List<String> COMMANDS = Arrays.asList(
- "count", "delete", "get", "help", "index", "search");
+ private static final String HELP =
+ "Elasticsearch interpreter:\n"
+ + "General format: <command> /<indices>/<types>/<id> <option> <JSON>\n"
+ + " - indices: list of indices separated by commas (depends on the command)\n"
+ + " - types: list of document types separated by commas (depends on the command)\n"
+ + "Commands:\n"
+ + " - search /indices/types <query>\n"
+ + " . indices and types can be omitted (at least, you have to provide '/')\n"
+ + " . a query is either a JSON-formatted query, nor a lucene query\n"
+ + " - size <value>\n"
+ + " . defines the size of the result set (default value is in the config)\n"
+ + " . if used, this command must be declared before a search command\n"
+ + " - count /indices/types <query>\n"
+ + " . same comments as for the search\n"
+ + " - get /index/type/id\n"
+ + " - delete /index/type/id\n"
+ + " - index /index/type/id <json-formatted document>\n"
+ + " . the id can be omitted, elasticsearch will generate one";
+
+ protected static final List<String> COMMANDS =
+ Arrays.asList("count", "delete", "get", "help", "index", "search");
private static final Pattern FIELD_NAME_PATTERN = Pattern.compile("\\[\\\\\"(.+)\\\\\"\\](.*)");
@@ -119,8 +114,12 @@ public class ElasticsearchInterpreter extends Interpreter {
this.resultSize = Integer.parseInt(getProperty(ELASTICSEARCH_RESULT_SIZE));
} catch (final NumberFormatException e) {
this.resultSize = 10;
- logger.error("Unable to parse " + ELASTICSEARCH_RESULT_SIZE + " : " +
- getProperty(ELASTICSEARCH_RESULT_SIZE), e);
+ logger.error(
+ "Unable to parse "
+ + ELASTICSEARCH_RESULT_SIZE
+ + " : "
+ + getProperty(ELASTICSEARCH_RESULT_SIZE),
+ e);
}
try {
@@ -154,8 +153,9 @@ public class ElasticsearchInterpreter extends Interpreter {
int currentResultSize = resultSize;
if (elsClient == null) {
- return new InterpreterResult(InterpreterResult.Code.ERROR,
- "Problem with the Elasticsearch client, please check your configuration (host, port,...)");
+ return new InterpreterResult(
+ InterpreterResult.Code.ERROR,
+ "Problem with the Elasticsearch client, please check your configuration (host, port,...)");
}
String[] items = StringUtils.split(cmd.trim(), " ", 3);
@@ -171,8 +171,7 @@ public class ElasticsearchInterpreter extends Interpreter {
final String[] lines = StringUtils.split(cmd.trim(), "\n", 2);
if (lines.length < 2) {
- return processHelp(InterpreterResult.Code.ERROR,
- "Size cmd must be followed by a search");
+ return processHelp(InterpreterResult.Code.ERROR, "Size cmd must be followed by a search");
}
final String[] sizeLine = StringUtils.split(lines[0], " ", 2);
@@ -229,8 +228,8 @@ public class ElasticsearchInterpreter extends Interpreter {
}
@Override
- public List<InterpreterCompletion> completion(String s, int i,
- InterpreterContext interpreterContext) {
+ public List<InterpreterCompletion> completion(
+ String s, int i, InterpreterContext interpreterContext) {
final List suggestions = new ArrayList<>();
for (final String cmd : COMMANDS) {
@@ -242,9 +241,9 @@ public class ElasticsearchInterpreter extends Interpreter {
}
private void addAngularObject(InterpreterContext interpreterContext, String prefix, Object obj) {
- interpreterContext.getAngularObjectRegistry().add(
- prefix + "_" + interpreterContext.getParagraphId().replace("-", "_"),
- obj, null, null);
+ interpreterContext
+ .getAngularObjectRegistry()
+ .add(prefix + "_" + interpreterContext.getParagraphId().replace("-", "_"), obj, null, null);
}
private String[] getIndexTypeId(String[] urlItems) {
@@ -256,13 +255,11 @@ public class ElasticsearchInterpreter extends Interpreter {
final String type = urlItems[1];
final String id = StringUtils.join(Arrays.copyOfRange(urlItems, 2, urlItems.length), '/');
- if (StringUtils.isEmpty(index)
- || StringUtils.isEmpty(type)
- || StringUtils.isEmpty(id)) {
+ if (StringUtils.isEmpty(index) || StringUtils.isEmpty(type) || StringUtils.isEmpty(id)) {
return null;
}
- return new String[] { index, type, id };
+ return new String[] {index, type, id};
}
private InterpreterResult processHelp(InterpreterResult.Code code, String additionalMessage) {
@@ -287,8 +284,8 @@ public class ElasticsearchInterpreter extends Interpreter {
final String[] indexTypeId = getIndexTypeId(urlItems);
if (indexTypeId == null) {
- return new InterpreterResult(InterpreterResult.Code.ERROR,
- "Bad URL (it should be /index/type/id)");
+ return new InterpreterResult(
+ InterpreterResult.Code.ERROR, "Bad URL (it should be /index/type/id)");
}
final ActionResponse response = elsClient.get(indexTypeId[0], indexTypeId[1], indexTypeId[2]);
@@ -300,9 +297,7 @@ public class ElasticsearchInterpreter extends Interpreter {
addAngularObject(interpreterContext, "get", json);
return new InterpreterResult(
- InterpreterResult.Code.SUCCESS,
- InterpreterResult.Type.TEXT,
- jsonStr);
+ InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, jsonStr);
}
return new InterpreterResult(InterpreterResult.Code.ERROR, "Document not found");
@@ -316,10 +311,11 @@ public class ElasticsearchInterpreter extends Interpreter {
* @param interpreterContext Instance of the context
* @return Result of the count request, it contains the total hits
*/
- private InterpreterResult processCount(String[] urlItems, String data,
- InterpreterContext interpreterContext) {
+ private InterpreterResult processCount(
+ String[] urlItems, String data, InterpreterContext interpreterContext) {
if (urlItems.length > 2) {
- return new InterpreterResult(InterpreterResult.Code.ERROR,
+ return new InterpreterResult(
+ InterpreterResult.Code.ERROR,
"Bad URL (it should be /index1,index2,.../type1,type2,...)");
}
@@ -328,9 +324,7 @@ public class ElasticsearchInterpreter extends Interpreter {
addAngularObject(interpreterContext, "count", response.getTotalHits());
return new InterpreterResult(
- InterpreterResult.Code.SUCCESS,
- InterpreterResult.Type.TEXT,
- "" + response.getTotalHits());
+ InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, "" + response.getTotalHits());
}
/**
@@ -342,18 +336,22 @@ public class ElasticsearchInterpreter extends Interpreter {
* @param interpreterContext Instance of the context
* @return Result of the search request, it contains a tab-formatted string of the matching hits
*/
- private InterpreterResult processSearch(String[] urlItems, String data, int size,
- InterpreterContext interpreterContext) {
+ private InterpreterResult processSearch(
+ String[] urlItems, String data, int size, InterpreterContext interpreterContext) {
if (urlItems.length > 2) {
- return new InterpreterResult(InterpreterResult.Code.ERROR,
+ return new InterpreterResult(
+ InterpreterResult.Code.ERROR,
"Bad URL (it should be /index1,index2,.../type1,type2,...)");
}
final ActionResponse response = searchData(urlItems, data, size);
- addAngularObject(interpreterContext, "search",
- (response.getAggregations() != null && response.getAggregations().size() > 0) ?
- response.getAggregations() : response.getHits());
+ addAngularObject(
+ interpreterContext,
+ "search",
+ (response.getAggregations() != null && response.getAggregations().size() > 0)
+ ? response.getAggregations()
+ : response.getHits());
return buildResponseMessage(response);
}
@@ -367,17 +365,15 @@ public class ElasticsearchInterpreter extends Interpreter {
*/
private InterpreterResult processIndex(String[] urlItems, String data) {
if (urlItems.length < 2 || urlItems.length > 3) {
- return new InterpreterResult(InterpreterResult.Code.ERROR,
- "Bad URL (it should be /index/type or /index/type/id)");
+ return new InterpreterResult(
+ InterpreterResult.Code.ERROR, "Bad URL (it should be /index/type or /index/type/id)");
}
- final ActionResponse response = elsClient.index(
- urlItems[0], urlItems[1], urlItems.length == 2 ? null : urlItems[2], data);
+ final ActionResponse response =
+ elsClient.index(urlItems[0], urlItems[1], urlItems.length == 2 ? null : urlItems[2], data);
return new InterpreterResult(
- InterpreterResult.Code.SUCCESS,
- InterpreterResult.Type.TEXT,
- response.getHit().getId());
+ InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, response.getHit().getId());
}
/**
@@ -390,8 +386,8 @@ public class ElasticsearchInterpreter extends Interpreter {
final String[] indexTypeId = getIndexTypeId(urlItems);
if (indexTypeId == null) {
- return new InterpreterResult(InterpreterResult.Code.ERROR,
- "Bad URL (it should be /index/type/id)");
+ return new InterpreterResult(
+ InterpreterResult.Code.ERROR, "Bad URL (it should be /index/type/id)");
}
final ActionResponse response =
@@ -399,9 +395,7 @@ public class ElasticsearchInterpreter extends Interpreter {
if (response.isSucceeded()) {
return new InterpreterResult(
- InterpreterResult.Code.SUCCESS,
- InterpreterResult.Type.TEXT,
- response.getHit().getId());
+ InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, response.getHit().getId());
}
return new InterpreterResult(InterpreterResult.Code.ERROR, "Document not found");
@@ -451,7 +445,7 @@ public class ElasticsearchInterpreter extends Interpreter {
final StringBuffer buffer = new StringBuffer();
final String[] keys = headerKeys.toArray(new String[0]);
- for (final String key: keys) {
+ for (final String key : keys) {
buffer.append("\t" + key);
}
buffer.deleteCharAt(0);
@@ -459,7 +453,7 @@ public class ElasticsearchInterpreter extends Interpreter {
for (final Map<String, Object> bucket : buckets) {
buffer.append("\n");
- for (final String key: keys) {
+ for (final String key : keys) {
buffer.append(bucket.get(key)).append("\t");
}
buffer.deleteCharAt(buffer.length() - 1);
@@ -479,7 +473,7 @@ public class ElasticsearchInterpreter extends Interpreter {
final Set<String> headerKeys = new HashSet<>();
final List<Map<String, Object>> buckets = new LinkedList<>();
- for (final AggWrapper aggregation: aggregations) {
+ for (final AggWrapper aggregation : aggregations) {
final Map<String, Object> bucketMap = JsonFlattener.flattenAsMap(aggregation.getResult());
headerKeys.addAll(bucketMap.keySet());
buckets.add(bucketMap);
@@ -487,7 +481,7 @@ public class ElasticsearchInterpreter extends Interpreter {
final StringBuffer buffer = new StringBuffer();
final String[] keys = headerKeys.toArray(new String[0]);
- for (final String key: keys) {
+ for (final String key : keys) {
buffer.append("\t" + key);
}
buffer.deleteCharAt(0);
@@ -495,7 +489,7 @@ public class ElasticsearchInterpreter extends Interpreter {
for (final Map<String, Object> bucket : buckets) {
buffer.append("\n");
- for (final String key: keys) {
+ for (final String key : keys) {
buffer.append(bucket.get(key)).append("\t");
}
buffer.deleteCharAt(buffer.length() - 1);
@@ -511,7 +505,7 @@ public class ElasticsearchInterpreter extends Interpreter {
return "";
}
- //First : get all the keys in order to build an ordered list of the values for each hit
+ // First : get all the keys in order to build an ordered list of the values for each hit
//
final List<Map<String, Object>> flattenHits = new LinkedList<>();
final Set<String> keys = new TreeSet<>();
@@ -526,8 +520,8 @@ public class ElasticsearchInterpreter extends Interpreter {
final String fieldName = iter.next();
final Matcher fieldNameMatcher = FIELD_NAME_PATTERN.matcher(fieldName);
if (fieldNameMatcher.matches()) {
- flattenMap.put(fieldNameMatcher.group(1) + fieldNameMatcher.group(2),
- flattenJsonMap.get(fieldName));
+ flattenMap.put(
+ fieldNameMatcher.group(1) + fieldNameMatcher.group(2), flattenJsonMap.get(fieldName));
} else {
flattenMap.put(fieldName, flattenJsonMap.get(fieldName));
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionException.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionException.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionException.java
index 6846d0a..458fce3 100644
--- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionException.java
+++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionException.java
@@ -17,9 +17,7 @@
package org.apache.zeppelin.elasticsearch.action;
-/**
- * Runtime exception thrown when there is a problem during an action (search, get, ...).
- */
+/** Runtime exception thrown when there is a problem during an action (search, get, ...). */
public class ActionException extends RuntimeException {
public ActionException(String message) {
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionResponse.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionResponse.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionResponse.java
index 4141bce..0acb4c4 100644
--- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionResponse.java
+++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/ActionResponse.java
@@ -20,9 +20,7 @@ package org.apache.zeppelin.elasticsearch.action;
import java.util.LinkedList;
import java.util.List;
-/**
- * Contains the result of an action (hits, aggregations, ...).
- */
+/** Contains the result of an action (hits, aggregations, ...). */
public class ActionResponse {
private boolean succeeded;
@@ -30,7 +28,6 @@ public class ActionResponse {
private final List<HitWrapper> hits = new LinkedList<>();
private final List<AggWrapper> aggregations = new LinkedList<>();
-
public ActionResponse succeeded(boolean succeeded) {
this.succeeded = succeeded;
return this;
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/AggWrapper.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/AggWrapper.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/AggWrapper.java
index a3ed951..1c0bd92 100644
--- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/AggWrapper.java
+++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/AggWrapper.java
@@ -17,14 +17,13 @@
package org.apache.zeppelin.elasticsearch.action;
-/**
- * Contains the result of an aggregation.
- */
+/** Contains the result of an aggregation. */
public class AggWrapper {
- /**
- * Type of an aggregation (to know if there are buckets or not).
- */
- public enum AggregationType { SIMPLE, MULTI_BUCKETS };
+ /** Type of an aggregation (to know if there are buckets or not). */
+ public enum AggregationType {
+ SIMPLE,
+ MULTI_BUCKETS
+ };
private final AggregationType type;
private final String result;
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/HitWrapper.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/HitWrapper.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/HitWrapper.java
index 3be4514..2175485 100644
--- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/HitWrapper.java
+++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/action/HitWrapper.java
@@ -21,9 +21,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-/**
- * Contains the data of a hit.
- */
+/** Contains the data of a hit. */
public class HitWrapper {
private final JsonParser parser = new JsonParser();
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClient.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClient.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClient.java
index 48e1980..36423ab 100644
--- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClient.java
+++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClient.java
@@ -19,9 +19,7 @@ package org.apache.zeppelin.elasticsearch.client;
import org.apache.zeppelin.elasticsearch.action.ActionResponse;
-/**
- * Interface that must be implemented by any kind of Elasticsearch client (transport, ...).
- */
+/** Interface that must be implemented by any kind of Elasticsearch client (transport, ...). */
public interface ElasticsearchClient {
ActionResponse get(String index, String type, String id);