Search in sources :

Example 96 with InterpreterResult

use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.

the class CassandraInterpreterTest method should_bind_null_value.

@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
    final InterpreterResult actual = interpreter.interpret(queries, intrContext);
    //Then
    assertThat(actual.code()).isEqualTo(Code.SUCCESS);
    assertThat(actual.message().get(0).getData()).isEqualTo("firstname\tlastname\n" + "null\tNULL\n");
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

Example 97 with InterpreterResult

use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.

the class CassandraInterpreterTest method should_display_statistics_for_non_select_statement.

@Test
public void should_display_statistics_for_non_select_statement() throws Exception {
    //Given
    String query = "USE zeppelin;\nCREATE TABLE IF NOT EXISTS no_select(id int PRIMARY KEY);";
    final String rawResult = reformatHtml(readTestResource("/scalate/NoResultWithExecutionInfo.html"));
    //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).replaceAll("QUERIED_HOSTS", address + ":" + port);
    assertThat(actual.code()).isEqualTo(Code.SUCCESS);
    assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Cluster(com.datastax.driver.core.Cluster)

Example 98 with InterpreterResult

use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.

the class CassandraInterpreterTest method should_execute_prepared_and_bound_statements.

@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
    final InterpreterResult actual = interpreter.interpret(queries, intrContext);
    //Then
    assertThat(actual.code()).isEqualTo(Code.SUCCESS);
    assertThat(actual.message().get(0).getData()).isEqualTo("key\tval\n" + "myKey\tmyValue\n");
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

Example 99 with InterpreterResult

use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.

the class CassandraInterpreterTest method should_error_and_display_stack_trace.

@Test
public void should_error_and_display_stack_trace() throws Exception {
    //Given
    String query = "@consistency=THREE\n" + "SELECT * FROM zeppelin.users LIMIT 3;";
    //When
    final InterpreterResult actual = interpreter.interpret(query, intrContext);
    //Then
    assertThat(actual.code()).isEqualTo(Code.ERROR);
    assertThat(actual.message().get(0).getData()).contains("All host(s) tried for query failed");
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

Example 100 with InterpreterResult

use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.

the class AlluxioInterpreterTest method mkdirComplexPathTest.

@Test
public void mkdirComplexPathTest() throws IOException, AlluxioException {
    InterpreterResult output = alluxioInterpreter.interpret("mkdir /Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File", null);
    boolean existsDir = fs.exists(new AlluxioURI("/Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File"));
    Assert.assertEquals("Successfully created directory /Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File\n\n", output.message().get(0).getData());
    Assert.assertTrue(existsDir);
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) AlluxioURI(alluxio.AlluxioURI)

Aggregations

InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)153 Test (org.junit.Test)63 Properties (java.util.Properties)17 File (java.io.File)10 IOException (java.io.IOException)9 AlluxioURI (alluxio.AlluxioURI)8 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)7 Theory (org.junit.experimental.theories.Theory)7 FileWriter (java.io.FileWriter)6 PrintStream (java.io.PrintStream)5 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)5 Code (org.apache.zeppelin.interpreter.InterpreterResult.Code)5 ActionResponse (org.apache.zeppelin.elasticsearch.action.ActionResponse)4 FileInStream (alluxio.client.file.FileInStream)3 JsonObject (com.google.gson.JsonObject)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3