Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cb017ca0
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cb017ca0
编写于
2月 07, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
c2215eb2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
155 addition
and
5 deletion
+155
-5
tests/examples/JDBC/taosdemo/pom.xml
tests/examples/JDBC/taosdemo/pom.xml
+1
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
.../main/java/com/taosdata/taosdemo/TaosDemoApplication.java
+7
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java
...a/com/taosdata/taosdemo/components/DataSourceFactory.java
+0
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/QueryService.java
...main/java/com/taosdata/taosdemo/service/QueryService.java
+104
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/TableService.java
...main/java/com/taosdata/taosdemo/service/TableService.java
+0
-1
tests/examples/JDBC/taosdemo/src/main/resources/query.json
tests/examples/JDBC/taosdemo/src/main/resources/query.json
+2
-2
tests/examples/JDBC/taosdemo/src/test/java/com/taosdata/taosdemo/service/QueryServiceTest.java
.../java/com/taosdata/taosdemo/service/QueryServiceTest.java
+41
-0
未找到文件。
tests/examples/JDBC/taosdemo/pom.xml
浏览文件 @
cb017ca0
...
...
@@ -67,7 +67,7 @@
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.1
8
</version>
<version>
2.0.1
9
</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
</dependency>
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
浏览文件 @
cb017ca0
...
...
@@ -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
)
{
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/DataSourceFactory.java
浏览文件 @
cb017ca0
...
...
@@ -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);
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/QueryService.java
0 → 100644
浏览文件 @
cb017ca0
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
();
}
}
}
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/TableService.java
浏览文件 @
cb017ca0
...
...
@@ -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
;
...
...
tests/examples/JDBC/taosdemo/src/main/resources/query.json
浏览文件 @
cb017ca0
...
...
@@ -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"
}]
}
...
...
tests/examples/JDBC/taosdemo/src/test/java/com/taosdata/taosdemo/service/QueryServiceTest.java
0 → 100644
浏览文件 @
cb017ca0
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
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录