You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2020/11/19 02:47:10 UTC
[zeppelin] branch branch-0.9 updated: [ZEPPELIN-5135]. Keep
default.splitQueries in jdbc
This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/branch-0.9 by this push:
new 1de2462 [ZEPPELIN-5135]. Keep default.splitQueries in jdbc
1de2462 is described below
commit 1de246257ec576b2ac4bb23264a3790710a91926
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Wed Nov 18 16:56:55 2020 +0800
[ZEPPELIN-5135]. Keep default.splitQueries in jdbc
### What is this PR for?
This PR is to bring back `default.splitQueries` in jdbc, so that user can choose whether split sql. But by default, we still enable it.
### What type of PR is it?
[Improvement ]
### Todos
* [ ] - Task
### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-5135
### How should this be tested?
* CI pass
### Screenshots (if appropriate)
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Jeff Zhang <zj...@apache.org>
Closes #3974 from zjffdu/ZEPPELIN-5135 and squashes the following commits:
8b8c23241 [Jeff Zhang] fix wrong import
d0978d576 [Jeff Zhang] [ZEPPELIN-5135]. Keep default.splitQueries in jdbc
(cherry picked from commit 7c78b30ebe8a50af0699f2b54b4d7f0fb1695a70)
Signed-off-by: Jeff Zhang <zj...@apache.org>
---
.../org/apache/zeppelin/jdbc/JDBCInterpreter.java | 13 +++++++-
jdbc/src/main/resources/interpreter-setting.json | 7 ++++
.../apache/zeppelin/jdbc/JDBCInterpreterTest.java | 37 ++++++++++++++++++++++
3 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
index e72481e..fb89d5c 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
@@ -50,6 +50,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -108,6 +109,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
static final String DRIVER_KEY = "driver";
static final String URL_KEY = "url";
static final String USER_KEY = "user";
+ static final String SPLIT_QURIES_KEY = "splitQueries";
static final String PASSWORD_KEY = "password";
static final String PRECODE_KEY = "precode";
static final String STATEMENT_PRECODE_KEY = "statementPrecode";
@@ -709,7 +711,16 @@ public class JDBCInterpreter extends KerberosInterpreter {
}
try {
- List<String> sqlArray = sqlSplitter.splitSql(sql);
+ boolean splitSql = Boolean.parseBoolean(getJDBCConfiguration(user)
+ .getPropertyMap(dbPrefix)
+ .getProperty(SPLIT_QURIES_KEY, "true"));
+ List<String> sqlArray = null;
+ if (splitSql) {
+ sqlArray = sqlSplitter.splitSql(sql);
+ } else {
+ sqlArray = Collections.singletonList(sql);
+ }
+
for (String sqlToExecute : sqlArray) {
statement = connection.createStatement();
diff --git a/jdbc/src/main/resources/interpreter-setting.json b/jdbc/src/main/resources/interpreter-setting.json
index f203ac1..d020782 100644
--- a/jdbc/src/main/resources/interpreter-setting.json
+++ b/jdbc/src/main/resources/interpreter-setting.json
@@ -32,6 +32,13 @@
"description": "JDBC Driver Name",
"type": "string"
},
+ "default.splitQueries": {
+ "envName": null,
+ "propertyName": "default.splitQueries",
+ "defaultValue": "true",
+ "description": "Whether split the whole text into multiple sql statements",
+ "type": "checkbox"
+ },
"default.completer.ttlInSeconds": {
"envName": null,
"propertyName": "default.completer.ttlInSeconds",
diff --git a/jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java b/jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java
index 92e0c24..b43eb7c 100644
--- a/jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java
+++ b/jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java
@@ -818,6 +818,43 @@ public class JDBCInterpreterTest extends BasicJDBCTestCaseAdapter {
assertEquals(3, resultMessages.size());
}
+ @Test
+ public void testSqlWithoutSplit() 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("default.splitQueries", "false");
+ JDBCInterpreter t = new JDBCInterpreter(properties);
+ t.open();
+
+ String sqlQuery = "-- comment\n" +
+ "--select * from test_table\n" +
+ "select * from test_table;";
+
+ InterpreterResult interpreterResult = t.interpret(sqlQuery, context);
+ assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
+ List<InterpreterResultMessage> resultMessages = context.out.toInterpreterResultMessage();
+ assertEquals(1, resultMessages.size());
+ assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(0).getType());
+
+
+ // the second sql is skipped.
+ context = getInterpreterContext();
+ sqlQuery = "select * from test_table;" +
+ "select name from test_table";
+ interpreterResult = t.interpret(sqlQuery, context);
+ assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
+ resultMessages = context.out.toInterpreterResultMessage();
+ assertEquals(1, resultMessages.size());
+ assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(0).getType());
+ assertTrue(resultMessages.get(0).getData(),
+ resultMessages.get(0).getData().startsWith("ID\tNAME"));
+ }
private InterpreterContext getInterpreterContext() {
return InterpreterContext.builder()
.setAuthenticationInfo(new AuthenticationInfo("testUser"))