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());
}
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());
}
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());
}
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());
}
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"));
}
Aggregations