Search in sources :

Example 66 with InterpreterResult

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

the class JDBCInterpreterTest method testSelectQuery.

@Test
public void testSelectQuery() throws SQLException, IOException {
    Properties properties = new Properties();
    properties.setProperty("common.max_count", "1000");
    properties.setProperty("common.max_retry", "3");
    properties.setProperty("default.driver", "org.h2.Driver");
    properties.setProperty("default.url", getJdbcConnection());
    properties.setProperty("default.user", "");
    properties.setProperty("default.password", "");
    JDBCInterpreter t = new JDBCInterpreter(properties);
    t.open();
    String sqlQuery = "select * from test_table WHERE ID in ('a', 'b')";
    InterpreterResult interpreterResult = t.interpret(sqlQuery, interpreterContext);
    assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
    assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", interpreterResult.message().get(0).getData());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) Test(org.junit.Test)

Example 67 with InterpreterResult

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

the class JDBCInterpreterTest method testSelectMultipleQuries.

@Test
public void testSelectMultipleQuries() throws SQLException, IOException {
    Properties properties = new Properties();
    properties.setProperty("common.max_count", "1000");
    properties.setProperty("common.max_retry", "3");
    properties.setProperty("default.driver", "org.h2.Driver");
    properties.setProperty("default.url", getJdbcConnection());
    properties.setProperty("default.user", "");
    properties.setProperty("default.password", "");
    JDBCInterpreter t = new JDBCInterpreter(properties);
    t.open();
    String sqlQuery = "select * from test_table;" + "select * from test_table WHERE ID = ';';";
    InterpreterResult interpreterResult = t.interpret(sqlQuery, interpreterContext);
    assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertEquals(2, interpreterResult.message().size());
    assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
    assertEquals("ID\tNAME\na\ta_name\nb\tb_name\nc\tnull\n", interpreterResult.message().get(0).getData());
    assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(1).getType());
    assertEquals("ID\tNAME\n", interpreterResult.message().get(1).getData());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) Test(org.junit.Test)

Example 68 with InterpreterResult

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

the class CassandraInterpreterTest method should_bind_boolean_value.

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

Example 69 with InterpreterResult

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

the class CassandraInterpreterTest method should_describe_udt_withing_logged_in_keyspace.

@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
    final InterpreterResult actual = interpreter.interpret(query, intrContext);
    //Then
    assertThat(actual.code()).isEqualTo(Code.SUCCESS);
    assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

Example 70 with InterpreterResult

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

the class CassandraInterpreterTest method should_throw_statement_not_having_semi_colon.

@Test
public void should_throw_statement_not_having_semi_colon() throws Exception {
    //Given
    String statement = "SELECT * zeppelin.albums";
    //When
    final InterpreterResult actual = interpreter.interpret(statement, intrContext);
    //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 ?");
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

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