Skip to content

Commit

Permalink
Merge 799ad95 into 6f80172
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianFeinauer committed Mar 1, 2020
2 parents 6f80172 + 799ad95 commit 9e3b7fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
Expand Up @@ -18,30 +18,29 @@
*/
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;
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.
Expand Down Expand Up @@ -86,7 +85,7 @@ public List<String> getMetaData() {
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<>();
Expand All @@ -104,9 +103,10 @@ public Object doInConnection(Connection connection) throws SQLException {
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 {
Expand Down
11 changes: 7 additions & 4 deletions jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
Expand Up @@ -40,10 +40,13 @@ static IoTDBConnectionParams parseUrl(String url, Properties info)
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");
Expand Down
17 changes: 13 additions & 4 deletions jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
Expand Up @@ -53,10 +53,10 @@ public void testParseURL() throws IoTDBURLException {
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);
Expand All @@ -71,6 +71,15 @@ public void testParseWrongUrl1() throws IoTDBURLException {
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();
Expand Down

0 comments on commit 9e3b7fa

Please sign in to comment.