You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by wa...@apache.org on 2021/09/28 01:47:21 UTC
[iotdb] branch master updated: [IOTDB-1037] set rpc_compression as
a parameter in JDBC URL (#3988)
This is an automated email from the ASF dual-hosted git repository.
wangchao316 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 05b9b0e [IOTDB-1037] set rpc_compression as a parameter in JDBC URL (#3988)
05b9b0e is described below
commit 05b9b0e767382155bad632885f145136b6af0434
Author: Xieqijun <44...@users.noreply.github.com>
AuthorDate: Tue Sep 28 09:46:54 2021 +0800
[IOTDB-1037] set rpc_compression as a parameter in JDBC URL (#3988)
[IOTDB-1037] set rpc_compression as a parameter in JDBC URL (#3988)
---
docs/UserGuide/API/Programming-JDBC.md | 2 +
docs/zh/UserGuide/API/Programming-JDBC.md | 2 +
.../src/main/java/org/apache/iotdb/jdbc/Utils.java | 47 ++++++++++++++++++++--
.../test/java/org/apache/iotdb/jdbc/UtilsTest.java | 12 ++++++
4 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/docs/UserGuide/API/Programming-JDBC.md b/docs/UserGuide/API/Programming-JDBC.md
index 4014783..27c9ab0 100644
--- a/docs/UserGuide/API/Programming-JDBC.md
+++ b/docs/UserGuide/API/Programming-JDBC.md
@@ -163,6 +163,8 @@ public class JDBCExample {
// JDBC driver name and database URL
String driver = "org.apache.iotdb.jdbc.IoTDBDriver";
String url = "jdbc:iotdb://127.0.0.1:6667/";
+ // set rpc compress mode
+ // String url = "jdbc:iotdb://127.0.0.1:6667?rpc_compress=true";
// Database credentials
String username = "root";
diff --git a/docs/zh/UserGuide/API/Programming-JDBC.md b/docs/zh/UserGuide/API/Programming-JDBC.md
index eae3170..f1a15c0 100644
--- a/docs/zh/UserGuide/API/Programming-JDBC.md
+++ b/docs/zh/UserGuide/API/Programming-JDBC.md
@@ -153,6 +153,8 @@ public class JDBCExample {
// JDBC driver name and database URL
String driver = "org.apache.iotdb.jdbc.IoTDBDriver";
String url = "jdbc:iotdb://127.0.0.1:6667/";
+ // set rpc compress mode
+ // String url = "jdbc:iotdb://127.0.0.1:6667?rpc_compress=true";
// Database credentials
String username = "root";
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
index cced38b..7c4837f 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
@@ -25,7 +25,9 @@ import java.util.regex.Pattern;
/** Utils to convert between thrift format and TsFile format. */
public class Utils {
- static final Pattern URL_PATTERN = Pattern.compile("([^:]+):([0-9]{1,5})/?");
+ static final Pattern URL_PATTERN = Pattern.compile("([^:]+):([0-9]{1,5})(/|\\?.*=.*(&.*=.*)*)?");
+
+ static final String RPC_COMPRESS = "rpc_compress";
/**
* Parse JDBC connection URL The only supported format of the URL is:
@@ -42,13 +44,16 @@ public class Utils {
String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
matcher = URL_PATTERN.matcher(subURL);
if (matcher.matches()) {
- isUrlLegal = true;
+ if (parseUrlParam(subURL)) {
+ isUrlLegal = true;
+ }
}
}
if (!isUrlLegal) {
throw new IoTDBURLException(
- "Error url format, url should be jdbc:iotdb://anything:port/ or jdbc:iotdb://anything:port");
+ "Error url format, url should be jdbc:iotdb://anything:port/ or jdbc:iotdb://anything:port?property1=value1&property2=value2");
}
+
params.setHost(matcher.group(1));
params.setPort(Integer.parseInt(matcher.group(2)));
@@ -69,4 +74,40 @@ public class Utils {
return params;
}
+
+ /**
+ * Parse the parameters in the URL and assign values to those that meet the conditions
+ *
+ * @param subURL Need to deal with url ,format like a=b&c=d
+ * @return Judge whether it is legal. Illegal situations include: 1.there is a key that does not
+ * need to be resolved 2.the value corresponding to the key that needs to be resolved does not
+ * match the type
+ */
+ private static boolean parseUrlParam(String subURL) {
+ if (!subURL.contains("?")) {
+ return true;
+ }
+ String paramURL = subURL.substring(subURL.indexOf('?') + 1);
+ String[] params = paramURL.split("&");
+ for (String tmpParam : params) {
+ String[] paramSplit = tmpParam.split("=");
+ if (paramSplit.length != 2) {
+ return false;
+ }
+ String key = tmpParam.split("=")[0];
+ String value = tmpParam.split("=")[1];
+ switch (key) {
+ case RPC_COMPRESS:
+ if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
+ Config.rpcThriftCompressionEnable = Boolean.getBoolean(value);
+ } else {
+ return false;
+ }
+ break;
+ default:
+ return false;
+ }
+ }
+ return true;
+ }
}
diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
index aa28d6e..82d1e5a 100644
--- a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
+++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
@@ -85,6 +85,18 @@ public class UtilsTest {
}
@Test(expected = IoTDBURLException.class)
+ public void testParseWrongUrl3() throws IoTDBURLException {
+ Properties properties = new Properties();
+ Utils.parseUrl("jdbc:iotdb//6667?rpc_compress=1", properties);
+ }
+
+ @Test(expected = IoTDBURLException.class)
+ public void testParseWrongUrl4() throws IoTDBURLException {
+ Properties properties = new Properties();
+ Utils.parseUrl("jdbc:iotdb//6667?rpc_compress=true&aaa=bbb", properties);
+ }
+
+ @Test(expected = IoTDBURLException.class)
public void testParseWrongPort() throws IoTDBURLException {
String userName = "test";
String userPwd = "test";