You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by jf...@apache.org on 2020/03/01 19:10:50 UTC

[incubator-iotdb] branch bugfix/several-fixes created (now 799ad95)

This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a change to branch bugfix/several-fixes
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.


      at 799ad95  Several fixes. - Fixed an issue in Utils and added test - Fixed BasicDaoImpl (query was invalid) in IoTDB-Grafana

This branch includes the following new commits:

     new 799ad95  Several fixes. - Fixed an issue in Utils and added test - Fixed BasicDaoImpl (query was invalid) in IoTDB-Grafana

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-iotdb] 01/01: Several fixes. - Fixed an issue in Utils and added test - Fixed BasicDaoImpl (query was invalid) in IoTDB-Grafana

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch bugfix/several-fixes
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit 799ad95b9baf0e80f248a2d43985b83e6f2ec679
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Sun Mar 1 20:10:37 2020 +0100

    Several fixes.
    - Fixed an issue in Utils and added test
    - Fixed BasicDaoImpl (query was invalid) in IoTDB-Grafana
---
 .../iotdb/web/grafana/dao/impl/BasicDaoImpl.java   | 32 +++++++++++-----------
 .../src/main/java/org/apache/iotdb/jdbc/Utils.java | 11 +++++---
 .../test/java/org/apache/iotdb/jdbc/UtilsTest.java | 17 +++++++++---
 3 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java b/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
index 881c026..a1b7af7 100644
--- a/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
+++ b/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
@@ -18,12 +18,22 @@
  */
 package org.apache.iotdb.web.grafana.dao.impl;
 
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.web.grafana.bean.TimeValues;
+import org.apache.iotdb.web.grafana.dao.BasicDao;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.ConnectionCallback;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Repository;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.sql.Connection;
-import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -31,17 +41,6 @@ import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
-import org.apache.iotdb.jdbc.Constant;
-import org.apache.iotdb.tsfile.utils.Pair;
-import org.apache.iotdb.web.grafana.bean.TimeValues;
-import org.apache.iotdb.web.grafana.dao.BasicDao;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.ConnectionCallback;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.stereotype.Repository;
 
 /**
  * Created by dell on 2017/7/17.
@@ -86,7 +85,7 @@ public class BasicDaoImpl implements BasicDao {
     ConnectionCallback<Object> connectionCallback = new ConnectionCallback<Object>() {
       public Object doInConnection(Connection connection) throws SQLException {
         Statement statement = connection.createStatement();
-        statement.execute("show timeseries" + "root *");
+        statement.execute("show timeseries root.*");
         ResultSet resultSet = statement.getResultSet();
         logger.info("Start to get timeseries");
         List<String> columnsName = new ArrayList<>();
@@ -104,9 +103,10 @@ public class BasicDaoImpl implements BasicDao {
   public List<TimeValues> querySeries(String s, Pair<ZonedDateTime, ZonedDateTime> timeRange) {
     Long from = zonedCovertToLong(timeRange.left);
     Long to = zonedCovertToLong(timeRange.right);
-    String sql = "SELECT " + s.substring(s.lastIndexOf('.') + 1) + " FROM root."
-        + s.substring(0, s.lastIndexOf('.')) + " WHERE time > " + from * TIMESTAMP_RADIX
-        + " and time < " + to * TIMESTAMP_RADIX;
+    // How many rows will the result have?
+    String sql = String.format("SELECT %s FROM root.%s WHERE time > %d and time < %d",
+        s.substring(s.lastIndexOf('.') + 1), s.substring(0, s.lastIndexOf('.')),
+        from * TIMESTAMP_RADIX, to * TIMESTAMP_RADIX);
     logger.info(sql);
     List<TimeValues> rows = null;
     try {
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 1eb79e8..156f645 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
@@ -40,10 +40,13 @@ public class Utils {
       return params;
     }
     boolean isUrlLegal = false;
-    String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
-    Matcher matcher = URL_PATTERN.matcher(subURL);
-    if(matcher.matches()) {
-      isUrlLegal = true;
+    Matcher matcher = null;
+    if (url.startsWith(Config.IOTDB_URL_PREFIX)) {
+      String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
+      matcher = URL_PATTERN.matcher(subURL);
+      if (matcher.matches()) {
+        isUrlLegal = true;
+      }
     }
     if (!isUrlLegal) {
       throw new IoTDBURLException("Error url format, url should be jdbc:iotdb://anything:port/ or jdbc:iotdb://anything:port");
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 34a0c3e..c5fa182 100644
--- a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
+++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
@@ -53,10 +53,10 @@ public class UtilsTest {
     IoTDBConnectionParams params = Utils
         .parseUrl(String.format(Config.IOTDB_URL_PREFIX + "%s:%s/", host1, port),
             properties);
-    assertEquals(params.getHost(), host1);
-    assertEquals(params.getPort(), port);
-    assertEquals(params.getUsername(), userName);
-    assertEquals(params.getPassword(), userPwd);
+    assertEquals(host1, params.getHost());
+    assertEquals(port, params.getPort());
+    assertEquals(userName, params.getUsername());
+    assertEquals(userPwd, params.getPassword());
 
     params = Utils.parseUrl(String.format(Config.IOTDB_URL_PREFIX + "%s:%s", host1, port), properties);
     assertEquals(params.getHost(), host1);
@@ -71,6 +71,15 @@ public class UtilsTest {
     Utils.parseUrl("jdbc:iotdb//test6667", properties);
   }
 
+  @Test
+  public void testParseDomainName() throws IoTDBURLException {
+    Properties properties = new Properties();
+    final IoTDBConnectionParams params = Utils.parseUrl("jdbc:iotdb://test:6667", properties);
+
+    assertEquals("test", params.getHost());
+    assertEquals(6667, params.getPort());
+  }
+
   @Test(expected = IoTDBURLException.class)
   public void testParseWrongUrl2() throws IoTDBURLException {
     Properties properties = new Properties();