Search in sources :

Example 46 with InterpreterResultMessage

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

the class JDBCInterpreterTest method testSelectQueryWithNull.

@Test
public void testSelectQueryWithNull() throws IOException, InterpreterException {
    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 = 'c'";
    InterpreterResult interpreterResult = t.interpret(sqlQuery, context);
    List<InterpreterResultMessage> resultMessages = context.out.toInterpreterResultMessage();
    assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(0).getType());
    assertEquals("ID\tNAME\nc\tnull\n", resultMessages.get(0).getData());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Example 47 with InterpreterResultMessage

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

the class JDBCInterpreterTest method testPrecodeWithAnotherPrefix.

@Test
public void testPrecodeWithAnotherPrefix() throws IOException, InterpreterException {
    Properties properties = new Properties();
    properties.setProperty("anotherPrefix.driver", "org.h2.Driver");
    properties.setProperty("anotherPrefix.url", getJdbcConnection());
    properties.setProperty("anotherPrefix.user", "");
    properties.setProperty("anotherPrefix.password", "");
    properties.setProperty(String.format(PRECODE_KEY_TEMPLATE, "anotherPrefix"), "create table test_precode_2 (id int); insert into test_precode_2 values (2);");
    JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);
    jdbcInterpreter.open();
    Map<String, String> localProperties = new HashMap<>();
    localProperties.put("db", "anotherPrefix");
    InterpreterContext context = InterpreterContext.builder().setAuthenticationInfo(new AuthenticationInfo("testUser")).setInterpreterOut(new InterpreterOutput()).setLocalProperties(localProperties).build();
    jdbcInterpreter.executePrecode(context);
    String sqlQuery = "select * from test_precode_2";
    InterpreterResult interpreterResult = jdbcInterpreter.interpret(sqlQuery, context);
    List<InterpreterResultMessage> resultMessages = context.out.toInterpreterResultMessage();
    assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertEquals(3, resultMessages.size());
    assertEquals(InterpreterResult.Type.TEXT, resultMessages.get(0).getType());
    assertEquals("Query executed successfully. Affected rows : 0\n\n", resultMessages.get(0).getData());
    assertEquals(InterpreterResult.Type.TEXT, resultMessages.get(1).getType());
    assertEquals("Query executed successfully. Affected rows : 1\n", resultMessages.get(1).getData());
    assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(2).getType());
    assertEquals("ID\n2\n", resultMessages.get(2).getData());
}
Also used : HashMap(java.util.HashMap) InterpreterOutput(org.apache.zeppelin.interpreter.InterpreterOutput) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Test(org.junit.Test)

Example 48 with InterpreterResultMessage

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

the class JDBCInterpreterTest method testPrecode.

@Test
public void testPrecode() throws IOException, InterpreterException {
    Properties properties = new Properties();
    properties.setProperty("default.driver", "org.h2.Driver");
    properties.setProperty("default.url", getJdbcConnection());
    properties.setProperty("default.user", "");
    properties.setProperty("default.password", "");
    properties.setProperty(DEFAULT_PRECODE, "create table test_precode (id int); insert into test_precode values (1);");
    JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);
    jdbcInterpreter.open();
    jdbcInterpreter.executePrecode(context);
    String sqlQuery = "select * from test_precode";
    InterpreterResult interpreterResult = jdbcInterpreter.interpret(sqlQuery, context);
    assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
    List<InterpreterResultMessage> resultMessages = context.out.toInterpreterResultMessage();
    assertEquals(3, resultMessages.size());
    assertEquals(InterpreterResult.Type.TEXT, resultMessages.get(0).getType());
    assertEquals("Query executed successfully. Affected rows : 0\n\n", resultMessages.get(0).getData());
    assertEquals(InterpreterResult.Type.TEXT, resultMessages.get(1).getType());
    assertEquals("Query executed successfully. Affected rows : 1\n", resultMessages.get(1).getData());
    assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(2).getType());
    assertEquals("ID\n1\n", resultMessages.get(2).getData());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Example 49 with InterpreterResultMessage

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

the class JDBCInterpreterInterpolationTest method testEscapedInterpolationPattern.

@Test
public void testEscapedInterpolationPattern() throws IOException, InterpreterException {
    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", "");
    properties.setProperty("zeppelin.jdbc.interpolation", "true");
    JDBCInterpreter t = new JDBCInterpreter(properties);
    t.open();
    // 
    // 2 rows (keyboard and mouse) expected when searching names with 2 consecutive vowels ...
    // The 'regexp' keyword is specific to H2 database
    // 
    String sqlQuery = "select * from test_table where name regexp '[aeiou]{{2}}'";
    InterpreterResult interpreterResult = t.interpret(sqlQuery, interpreterContext);
    assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
    List<InterpreterResultMessage> resultMessages = interpreterContext.out.toInterpreterResultMessage();
    assertEquals(1, resultMessages.size());
    assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(0).getType());
    assertEquals("ID\tNAME\nkey\tkeyboard\nmou\tmouse\n", resultMessages.get(0).getData());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Example 50 with InterpreterResultMessage

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

the class JDBCInterpreterTest method testSelectQueryMaxResult.

@Test
public void testSelectQueryMaxResult() throws IOException, InterpreterException {
    Properties properties = new Properties();
    properties.setProperty("common.max_count", "1");
    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";
    InterpreterResult interpreterResult = t.interpret(sqlQuery, context);
    assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
    List<InterpreterResultMessage> resultMessages = context.out.toInterpreterResultMessage();
    assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(0).getType());
    assertEquals("ID\tNAME\na\ta_name\n", resultMessages.get(0).getData());
    assertEquals(InterpreterResult.Type.HTML, resultMessages.get(1).getType());
    assertTrue(resultMessages.get(1).getData().contains("Output is truncated"));
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Aggregations

InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)80 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)78 Test (org.junit.Test)60 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)55 Properties (java.util.Properties)17 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)15 IOException (java.io.IOException)13 File (java.io.File)8 TimeoutException (java.util.concurrent.TimeoutException)7 Waiter (net.jodah.concurrentunit.Waiter)7 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)6 Test (org.junit.jupiter.api.Test)6 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)3 HashMap (java.util.HashMap)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 Map (java.util.Map)2 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 CheckBox (org.apache.zeppelin.display.ui.CheckBox)2 Select (org.apache.zeppelin.display.ui.Select)2