mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
[ZEPPELIN-1988] fixes of review items
This commit is contained in:
parent
9d37bc46e3
commit
66d6ae4040
5 changed files with 12 additions and 18 deletions
|
|
@ -168,7 +168,7 @@ There are more JDBC interpreter properties you can specify like below.
|
|||
<td>jceks credential key</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>zeppelin.interpreter.precode</td>
|
||||
<td>zeppelin.jdbc.precode</td>
|
||||
<td>Some SQL which executes while opening connection</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
|
|||
import static org.apache.commons.lang.StringUtils.isEmpty;
|
||||
import static org.apache.commons.lang.StringUtils.isNotEmpty;
|
||||
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
|
||||
import static org.apache.zeppelin.interpreter.Constants.ZEPPELIN_PRECODE_PROPERTY_KEY;
|
||||
|
||||
/**
|
||||
* JDBC interpreter for Zeppelin. This interpreter can also be used for accessing HAWQ,
|
||||
|
|
@ -104,6 +103,7 @@ public class JDBCInterpreter extends Interpreter {
|
|||
static final String PASSWORD_KEY = "password";
|
||||
static final String JDBC_JCEKS_FILE = "jceks.file";
|
||||
static final String JDBC_JCEKS_CREDENTIAL_KEY = "jceks.credentialKey";
|
||||
static final String ZEPPELIN_JDBC_PRECODE_KEY = "zeppelin.jdbc.precode";
|
||||
static final String DOT = ".";
|
||||
|
||||
private static final char WHITESPACE = ' ';
|
||||
|
|
@ -342,7 +342,7 @@ public class JDBCInterpreter extends Interpreter {
|
|||
if (!getJDBCConfiguration(user).isConnectionInDBDriverPool(propertyKey)) {
|
||||
createConnectionPool(url, user, propertyKey, properties);
|
||||
try (Connection connection = DriverManager.getConnection(jdbcDriver)) {
|
||||
executePreCode(connection);
|
||||
executePrecode(connection);
|
||||
}
|
||||
}
|
||||
return DriverManager.getConnection(jdbcDriver);
|
||||
|
|
@ -544,8 +544,8 @@ public class JDBCInterpreter extends Interpreter {
|
|||
return queries;
|
||||
}
|
||||
|
||||
private void executePreCode(Connection connection) {
|
||||
String precode = getProperty(ZEPPELIN_PRECODE_PROPERTY_KEY);
|
||||
private void executePrecode(Connection connection) throws SQLException {
|
||||
String precode = getProperty(ZEPPELIN_JDBC_PRECODE_KEY);
|
||||
if (StringUtils.isNotEmpty(precode)) {
|
||||
logger.info("Run SQL precode '{}'", precode);
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
|
|
@ -553,8 +553,6 @@ public class JDBCInterpreter extends Interpreter {
|
|||
if (!connection.getAutoCommit()) {
|
||||
connection.commit();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("Cannot create precode statement", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@
|
|||
"defaultValue": "",
|
||||
"description": "Kerberos principal"
|
||||
},
|
||||
"zeppelin.interpreter.precode": {
|
||||
"zeppelin.jdbc.precode": {
|
||||
"envName": null,
|
||||
"propertyName": "zeppelin.interpreter.precode",
|
||||
"propertyName": "zeppelin.jdbc.precode",
|
||||
"defaultValue": "",
|
||||
"description": "SQL which executes while opening connection"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.zeppelin.interpreter.Constants;
|
||||
import org.apache.zeppelin.interpreter.InterpreterContext;
|
||||
import org.apache.zeppelin.interpreter.InterpreterResult;
|
||||
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
|
||||
|
|
@ -45,7 +44,7 @@ import org.junit.Test;
|
|||
|
||||
import com.mockrunner.jdbc.BasicJDBCTestCaseAdapter;
|
||||
|
||||
import static org.apache.zeppelin.interpreter.Constants.ZEPPELIN_PRECODE_PROPERTY_KEY;
|
||||
import static org.apache.zeppelin.jdbc.JDBCInterpreter.ZEPPELIN_JDBC_PRECODE_KEY;
|
||||
|
||||
/**
|
||||
* JDBC interpreter unit tests
|
||||
|
|
@ -398,7 +397,7 @@ public class JDBCInterpreterTest extends BasicJDBCTestCaseAdapter {
|
|||
properties.setProperty("default.url", getJdbcConnection());
|
||||
properties.setProperty("default.user", "");
|
||||
properties.setProperty("default.password", "");
|
||||
properties.setProperty(ZEPPELIN_PRECODE_PROPERTY_KEY, "SET @testVariable=1");
|
||||
properties.setProperty(ZEPPELIN_JDBC_PRECODE_KEY, "SET @testVariable=1");
|
||||
JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);
|
||||
jdbcInterpreter.open();
|
||||
|
||||
|
|
@ -418,7 +417,7 @@ public class JDBCInterpreterTest extends BasicJDBCTestCaseAdapter {
|
|||
properties.setProperty("default.url", getJdbcConnection());
|
||||
properties.setProperty("default.user", "");
|
||||
properties.setProperty("default.password", "");
|
||||
properties.setProperty(ZEPPELIN_PRECODE_PROPERTY_KEY, "incorrect command");
|
||||
properties.setProperty(ZEPPELIN_JDBC_PRECODE_KEY, "incorrect command");
|
||||
JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);
|
||||
jdbcInterpreter.open();
|
||||
|
||||
|
|
@ -426,8 +425,7 @@ public class JDBCInterpreterTest extends BasicJDBCTestCaseAdapter {
|
|||
|
||||
InterpreterResult interpreterResult = jdbcInterpreter.interpret(sqlQuery, interpreterContext);
|
||||
|
||||
assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
|
||||
assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
|
||||
assertEquals("1\n1\n", interpreterResult.message().get(0).getData());
|
||||
assertEquals(InterpreterResult.Code.ERROR, interpreterResult.code());
|
||||
assertEquals(InterpreterResult.Type.TEXT, interpreterResult.message().get(0).getType());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ public class Constants {
|
|||
|
||||
public static final String ZEPPELIN_INTERPRETER_HOST = "zeppelin.interpreter.host";
|
||||
|
||||
public static final String ZEPPELIN_PRECODE_PROPERTY_KEY = "zeppelin.interpreter.precode";
|
||||
|
||||
public static final String EXISTING_PROCESS = "existing_process";
|
||||
|
||||
public static final int ZEPPELIN_INTERPRETER_DEFAUlT_PORT = 29914;
|
||||
|
|
|
|||
Loading…
Reference in a new issue