change
This commit is contained in:
parent
c2215eb214
commit
cb017ca0bd
|
@ -67,7 +67,7 @@
|
|||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.18</version>
|
||||
<version>2.0.19</version>
|
||||
<!-- <scope>system</scope>-->
|
||||
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
|
||||
</dependency>
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.taosdata.taosdemo.components.DataSourceFactory;
|
|||
import com.taosdata.taosdemo.components.JdbcTaosdemoConfig;
|
||||
import com.taosdata.taosdemo.domain.SuperTableMeta;
|
||||
import com.taosdata.taosdemo.service.DatabaseService;
|
||||
import com.taosdata.taosdemo.service.QueryService;
|
||||
import com.taosdata.taosdemo.service.SubTableService;
|
||||
import com.taosdata.taosdemo.service.SuperTableService;
|
||||
import com.taosdata.taosdemo.service.data.SuperTableMetaGenerator;
|
||||
|
@ -34,6 +35,7 @@ public class TaosDemoApplication {
|
|||
final DatabaseService databaseService = new DatabaseService(dataSource);
|
||||
final SuperTableService superTableService = new SuperTableService(dataSource);
|
||||
final SubTableService subTableService = new SubTableService(dataSource);
|
||||
final QueryService queryService = new QueryService(dataSource);
|
||||
// 创建数据库
|
||||
long start = System.currentTimeMillis();
|
||||
Map<String, String> databaseParam = new HashMap<>();
|
||||
|
@ -90,6 +92,11 @@ public class TaosDemoApplication {
|
|||
int affectedRows = subTableService.insertMultiThreads(superTableMeta, threadSize, tableSize, startTime, gap, config);
|
||||
end = System.currentTimeMillis();
|
||||
logger.info("insert " + affectedRows + " rows, time cost: " + (end - start) + " ms");
|
||||
/**********************************************************************************/
|
||||
// 查询
|
||||
|
||||
|
||||
|
||||
/**********************************************************************************/
|
||||
// 删除表
|
||||
if (config.dropTable) {
|
||||
|
|
|
@ -23,7 +23,6 @@ public class DataSourceFactory {
|
|||
properties.load(is);
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
|
||||
if (properties.containsKey("jdbc.driver")) {
|
||||
// String driverName = properties.getProperty("jdbc.driver");
|
||||
// System.out.println(">>> load driver : " + driverName);
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package com.taosdata.taosdemo.service;
|
||||
|
||||
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class QueryService {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
public QueryService(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
/* only select or show SQL Statement is valid for executeQuery */
|
||||
public Boolean[] areValidQueries(String[] sqls) {
|
||||
Boolean[] ret = new Boolean[sqls.length];
|
||||
for (int i = 0; i < sqls.length; i++) {
|
||||
ret[i] = true;
|
||||
if (!SqlSyntaxValidator.isValidForExecuteQuery(sqls[i])) {
|
||||
ret[i] = false;
|
||||
continue;
|
||||
}
|
||||
try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {
|
||||
stmt.executeQuery(sqls[i]);
|
||||
} catch (SQLException e) {
|
||||
ret[i] = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String[] generateSuperTableQueries(String dbName) {
|
||||
List<String> sqls = new ArrayList<>();
|
||||
try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {
|
||||
stmt.execute("use " + dbName);
|
||||
ResultSet rs = stmt.executeQuery("show stables");
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
sqls.add("select count(*) from " + dbName + "." + name);
|
||||
sqls.add("select first(*) from " + dbName + "." + name);
|
||||
sqls.add("select last(*) from " + dbName + "." + name);
|
||||
sqls.add("select last_row(*) from " + dbName + "." + name);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String[] sqlArr = new String[sqls.size()];
|
||||
return sqls.toArray(sqlArr);
|
||||
}
|
||||
|
||||
public void querySuperTable(String[] sqls, int interval, int threadCount, long queryTimes) {
|
||||
List<Thread> threads = IntStream.range(0, threadCount).mapToObj(i -> new Thread(() -> {
|
||||
// do query
|
||||
try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {
|
||||
long count = queryTimes;
|
||||
if (count == 0)
|
||||
count = Long.MAX_VALUE;
|
||||
while (count > 0) {
|
||||
for (String sql : sqls) {
|
||||
long start = System.currentTimeMillis();
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
printResultSet(rs);
|
||||
long end = System.currentTimeMillis();
|
||||
long timecost = end - start;
|
||||
if (interval - timecost > 0) {
|
||||
TimeUnit.MILLISECONDS.sleep(interval - timecost);
|
||||
}
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
} catch (SQLException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
})).collect(Collectors.toList());
|
||||
threads.stream().forEach(Thread::start);
|
||||
for (Thread thread : threads) {
|
||||
try {
|
||||
thread.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printResultSet(ResultSet rs) throws SQLException {
|
||||
ResultSetMetaData meta = rs.getMetaData();
|
||||
while (rs.next()) {
|
||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.taosdata.taosdemo.service;
|
|||
|
||||
import com.taosdata.taosdemo.dao.TableMapper;
|
||||
import com.taosdata.taosdemo.domain.TableMeta;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
"password": "taosdata",
|
||||
"databases": "db01",
|
||||
"super_table_query":
|
||||
{"rate":1, "concurrent":1,
|
||||
{"rate":1, "concurrent":1,"time":10000,
|
||||
"sqls": [{"sql": "select count(*) from stb01", "result": "./query_res0.txt"}]
|
||||
},
|
||||
"sub_table_query":
|
||||
"sub_table_query":
|
||||
{"stblname": "stb01", "rate":1, "threads":1,
|
||||
"sqls": [{"sql": "select count(*) from xxxx", "result": "./query_res1.txt"}]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.taosdata.taosdemo.service;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class QueryServiceTest {
|
||||
private static QueryService queryService;
|
||||
|
||||
@Test
|
||||
public void areValidQueries() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateSuperTableQueries() {
|
||||
String[] sqls = queryService.generateSuperTableQueries("restful_test");
|
||||
for (String sql : sqls) {
|
||||
System.out.println(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void querySuperTable() {
|
||||
String[] sqls = queryService.generateSuperTableQueries("restful_test");
|
||||
queryService.querySuperTable(sqls, 1000, 10, 10);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws ClassNotFoundException {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setJdbcUrl("jdbc:TAOS://127.0.0.1:6030/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8");
|
||||
config.setUsername("root");
|
||||
config.setPassword("taosdata");
|
||||
HikariDataSource dataSource = new HikariDataSource(config);
|
||||
queryService = new QueryService(dataSource);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue