Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冷面1992
TDengine
提交
efe299f0
TDengine
项目概览
冷面1992
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
efe299f0
编写于
1月 06, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
4fee1be8
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
1 addition
and
737 deletion
+1
-737
tests/examples/JDBC/JDBCDemo/pom.xml
tests/examples/JDBC/JDBCDemo/pom.xml
+1
-0
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
.../java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
+0
-352
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
...sdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
+0
-205
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/CreateTableTask.java
...m/taosdata/example/jdbcTaosdemo/task/CreateTableTask.java
+0
-42
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableDatetimeTask.java
...ta/example/jdbcTaosdemo/task/InsertTableDatetimeTask.java
+0
-49
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
...m/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
+0
-57
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/ConnectionFactory.java
...aosdata/example/jdbcTaosdemo/utils/ConnectionFactory.java
+0
-32
未找到文件。
tests/examples/JDBC/JDBCDemo/pom.xml
浏览文件 @
efe299f0
...
...
@@ -8,6 +8,7 @@
<artifactId>
JDBCDemo
</artifactId>
<version>
SNAPSHOT
</version>
<packaging>
jar
</packaging>
<build>
<plugins>
<plugin>
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
已删除
100644 → 0
浏览文件 @
4fee1be8
package
com.taosdata.example.jdbcTaosdemo
;
import
com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.jdbcTaosdemo.task.CreateTableTask
;
import
com.taosdata.example.jdbcTaosdemo.task.InsertTableDatetimeTask
;
import
com.taosdata.example.jdbcTaosdemo.task.InsertTableTask
;
import
com.taosdata.example.jdbcTaosdemo.utils.ConnectionFactory
;
import
com.taosdata.example.jdbcTaosdemo.utils.SqlSpeller
;
import
com.taosdata.example.jdbcTaosdemo.utils.TimeStampUtil
;
import
org.apache.log4j.Logger
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
JdbcTaosdemo
{
private
static
Logger
logger
=
Logger
.
getLogger
(
JdbcTaosdemo
.
class
);
private
final
JdbcTaosdemoConfig
config
;
private
Connection
connection
;
public
JdbcTaosdemo
(
JdbcTaosdemoConfig
config
)
{
this
.
config
=
config
;
}
public
static
void
main
(
String
[]
args
)
{
// parse config from args
JdbcTaosdemoConfig
config
=
new
JdbcTaosdemoConfig
(
args
);
boolean
isHelp
=
Arrays
.
asList
(
args
).
contains
(
"--help"
);
if
(
isHelp
||
config
.
host
==
null
||
config
.
host
.
isEmpty
())
{
JdbcTaosdemoConfig
.
printHelp
();
return
;
}
JdbcTaosdemo
taosdemo
=
new
JdbcTaosdemo
(
config
);
// establish connection
taosdemo
.
init
();
// drop database
taosdemo
.
dropDatabase
();
// create database
taosdemo
.
createDatabase
();
// use db
taosdemo
.
useDatabase
();
// create super table
taosdemo
.
createSuperTable
();
// create sub tables
taosdemo
.
createTableMultiThreads
();
boolean
infinite
=
Arrays
.
asList
(
args
).
contains
(
"--infinite"
);
if
(
infinite
)
{
logger
.
info
(
"!!! Infinite Insert Mode Started. !!!"
);
taosdemo
.
insertInfinite
();
}
else
{
// insert into table
taosdemo
.
insertMultiThreads
();
// select from sub table
taosdemo
.
selectFromTableLimit
();
taosdemo
.
selectCountFromTable
();
taosdemo
.
selectAvgMinMaxFromTable
();
// select last from
taosdemo
.
selectLastFromTable
();
// select from super table
taosdemo
.
selectFromSuperTableLimit
();
taosdemo
.
selectCountFromSuperTable
();
taosdemo
.
selectAvgMinMaxFromSuperTable
();
//select avg ,max from stb where tag
taosdemo
.
selectAvgMinMaxFromSuperTableWhereTag
();
//select last from stb where location = ''
taosdemo
.
selectLastFromSuperTableWhere
();
// select group by
taosdemo
.
selectGroupBy
();
// select like
taosdemo
.
selectLike
();
// select where ts >= ts<=
taosdemo
.
selectLastOneHour
();
taosdemo
.
selectLastOneDay
();
taosdemo
.
selectLastOneWeek
();
taosdemo
.
selectLastOneMonth
();
taosdemo
.
selectLastOneYear
();
// drop super table
if
(
config
.
dropTable
)
taosdemo
.
dropSuperTable
();
taosdemo
.
close
();
}
}
/**
* establish the connection
*/
private
void
init
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
connection
=
ConnectionFactory
.
build
(
config
);
if
(
connection
!=
null
)
logger
.
info
(
"[ OK ] Connection established."
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
logger
.
error
(
e
.
getMessage
());
throw
new
RuntimeException
(
"connection failed: "
+
config
.
host
);
}
}
/**
* create database
*/
private
void
createDatabase
()
{
String
sql
=
SqlSpeller
.
createDatabaseSQL
(
config
.
database
,
config
.
keep
,
config
.
days
);
execute
(
sql
);
}
/**
* drop database
*/
private
void
dropDatabase
()
{
String
sql
=
SqlSpeller
.
dropDatabaseSQL
(
config
.
database
);
execute
(
sql
);
}
/**
* use database
*/
private
void
useDatabase
()
{
String
sql
=
SqlSpeller
.
useDatabaseSQL
(
config
.
database
);
execute
(
sql
);
}
/**
* create super table
*/
private
void
createSuperTable
()
{
String
sql
=
SqlSpeller
.
createSuperTableSQL
(
config
.
superTable
);
execute
(
sql
);
}
/**
* create table use super table with multi threads
*/
private
void
createTableMultiThreads
()
{
try
{
final
int
tableSize
=
(
int
)
(
config
.
numOfTables
/
config
.
numOfThreadsForCreate
);
List
<
Thread
>
threads
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
config
.
numOfThreadsForCreate
;
i
++)
{
Thread
thread
=
new
Thread
(
new
CreateTableTask
(
config
,
i
*
tableSize
,
tableSize
),
"Thread-"
+
i
);
threads
.
add
(
thread
);
thread
.
start
();
}
for
(
Thread
thread
:
threads
)
{
thread
.
join
();
}
logger
.
info
(
"<<< Multi Threads create table finished."
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
/**
* insert data infinitely
*/
private
void
insertInfinite
()
{
try
{
final
long
startDatetime
=
TimeStampUtil
.
datetimeToLong
(
"2005-01-01 00:00:00.000"
);
final
long
finishDatetime
=
TimeStampUtil
.
datetimeToLong
(
"2030-01-01 00:00:00.000"
);
final
int
tableSize
=
(
int
)
(
config
.
numOfTables
/
config
.
numOfThreadsForInsert
);
List
<
Thread
>
threads
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
config
.
numOfThreadsForInsert
;
i
++)
{
Thread
thread
=
new
Thread
(
new
InsertTableDatetimeTask
(
config
,
i
*
tableSize
,
tableSize
,
startDatetime
,
finishDatetime
),
"Thread-"
+
i
);
threads
.
add
(
thread
);
thread
.
start
();
}
for
(
Thread
thread
:
threads
)
{
thread
.
join
();
}
logger
.
info
(
"<<< Multi Threads insert table finished."
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
private
void
insertMultiThreads
()
{
try
{
final
int
tableSize
=
(
int
)
(
config
.
numOfTables
/
config
.
numOfThreadsForInsert
);
final
int
numberOfRecordsPerTable
=
(
int
)
config
.
numOfRowsPerTable
;
List
<
Thread
>
threads
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
config
.
numOfThreadsForInsert
;
i
++)
{
Thread
thread
=
new
Thread
(
new
InsertTableTask
(
config
,
i
*
tableSize
,
tableSize
,
numberOfRecordsPerTable
),
"Thread-"
+
i
);
threads
.
add
(
thread
);
thread
.
start
();
}
for
(
Thread
thread
:
threads
)
{
thread
.
join
();
}
logger
.
info
(
"<<< Multi Threads insert table finished."
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
private
void
selectFromTableLimit
()
{
String
sql
=
SqlSpeller
.
selectFromTableLimitSQL
(
config
.
database
,
config
.
prefixOfTable
,
1
,
10
,
0
);
executeQuery
(
sql
);
}
private
void
selectCountFromTable
()
{
String
sql
=
SqlSpeller
.
selectCountFromTableSQL
(
config
.
database
,
config
.
prefixOfTable
,
1
);
executeQuery
(
sql
);
}
private
void
selectAvgMinMaxFromTable
()
{
String
sql
=
SqlSpeller
.
selectAvgMinMaxFromTableSQL
(
"current"
,
config
.
database
,
config
.
prefixOfTable
,
1
);
executeQuery
(
sql
);
}
private
void
selectLastFromTable
()
{
String
sql
=
SqlSpeller
.
selectLastFromTableSQL
(
config
.
database
,
config
.
prefixOfTable
,
1
);
executeQuery
(
sql
);
}
private
void
selectFromSuperTableLimit
()
{
String
sql
=
SqlSpeller
.
selectFromSuperTableLimitSQL
(
config
.
database
,
config
.
superTable
,
10
,
0
);
executeQuery
(
sql
);
}
private
void
selectCountFromSuperTable
()
{
String
sql
=
SqlSpeller
.
selectCountFromSuperTableSQL
(
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectAvgMinMaxFromSuperTable
()
{
String
sql
=
SqlSpeller
.
selectAvgMinMaxFromSuperTableSQL
(
"current"
,
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectAvgMinMaxFromSuperTableWhereTag
()
{
String
sql
=
SqlSpeller
.
selectAvgMinMaxFromSuperTableWhere
(
"current"
,
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectLastFromSuperTableWhere
()
{
String
sql
=
SqlSpeller
.
selectLastFromSuperTableWhere
(
"current"
,
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectGroupBy
()
{
String
sql
=
SqlSpeller
.
selectGroupBy
(
"current"
,
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectLike
()
{
String
sql
=
SqlSpeller
.
selectLike
(
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectLastOneHour
()
{
String
sql
=
SqlSpeller
.
selectLastOneHour
(
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectLastOneDay
()
{
String
sql
=
SqlSpeller
.
selectLastOneDay
(
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectLastOneWeek
()
{
String
sql
=
SqlSpeller
.
selectLastOneWeek
(
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectLastOneMonth
()
{
String
sql
=
SqlSpeller
.
selectLastOneMonth
(
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
selectLastOneYear
()
{
String
sql
=
SqlSpeller
.
selectLastOneYear
(
config
.
database
,
config
.
superTable
);
executeQuery
(
sql
);
}
private
void
close
()
{
try
{
if
(
connection
!=
null
)
{
this
.
connection
.
close
();
logger
.
info
(
"connection closed."
);
}
}
catch
(
SQLException
e
)
{
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
/**
* drop super table
*/
private
void
dropSuperTable
()
{
String
sql
=
SqlSpeller
.
dropSuperTableSQL
(
config
.
database
,
config
.
superTable
);
execute
(
sql
);
}
/**
* execute sql, use this method when sql is create, alter, drop..
*/
private
void
execute
(
String
sql
)
{
try
(
Statement
statement
=
connection
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
boolean
execute
=
statement
.
execute
(
sql
);
long
end
=
System
.
currentTimeMillis
();
printSql
(
sql
,
execute
,
(
end
-
start
));
}
catch
(
SQLException
e
)
{
logger
.
error
(
"ERROR execute SQL ===> "
+
sql
);
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
private
static
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
System
.
out
.
println
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
}
private
void
executeQuery
(
String
sql
)
{
try
(
Statement
statement
=
connection
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
ResultSet
resultSet
=
statement
.
executeQuery
(
sql
);
long
end
=
System
.
currentTimeMillis
();
printSql
(
sql
,
true
,
(
end
-
start
));
printResult
(
resultSet
);
}
catch
(
SQLException
e
)
{
logger
.
error
(
"ERROR execute SQL ===> "
+
sql
);
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
private
static
void
printResult
(
ResultSet
resultSet
)
throws
SQLException
{
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
while
(
resultSet
.
next
())
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
1
;
i
<=
metaData
.
getColumnCount
();
i
++)
{
String
columnLabel
=
metaData
.
getColumnLabel
(
i
);
String
value
=
resultSet
.
getString
(
i
);
sb
.
append
(
columnLabel
+
": "
+
value
+
"\t"
);
}
System
.
out
.
println
(
sb
.
toString
());
}
}
}
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
已删除
100644 → 0
浏览文件 @
4fee1be8
package
com.taosdata.example.jdbcTaosdemo.domain
;
import
com.taosdata.example.jdbcTaosdemo.utils.TimeStampUtil
;
public
final
class
JdbcTaosdemoConfig
{
// instance
public
String
host
;
//host
public
int
port
=
6030
;
//port
public
String
user
=
"root"
;
//user
public
String
password
=
"taosdata"
;
//password
// database
public
String
database
=
"test"
;
//database
public
int
keep
=
3650
;
//keep
public
int
days
=
30
;
//days
public
int
replica
=
1
;
//replica
//super table
public
boolean
doCreateTable
=
true
;
public
String
superTable
=
"weather"
;
//super table name
public
String
prefixOfFields
=
"col"
;
public
int
numOfFields
;
public
String
prefixOfTags
=
"tag"
;
public
int
numOfTags
;
public
String
superTableSQL
;
//sub table
public
String
prefixOfTable
=
"t"
;
// insert task
public
boolean
autoCreateTable
=
true
;
public
long
numOfTables
=
100
;
public
long
numOfRowsPerTable
=
100
;
public
int
numOfTablesPerSQL
=
10
;
public
int
numOfValuesPerSQL
=
10
;
public
int
numOfThreadsForCreate
=
1
;
public
int
numOfThreadsForInsert
=
1
;
public
long
startTime
;
public
long
timeGap
=
1
;
public
int
frequency
;
public
int
order
;
public
int
rate
=
10
;
public
long
range
=
1000
l
;
// select task
// drop task
public
boolean
dropTable
=
false
;
public
static
void
printHelp
()
{
System
.
out
.
println
(
"Usage: java -jar jdbc-taosdemo-2.0.jar [OPTION...]"
);
// instance
System
.
out
.
println
(
"-host The host to connect to TDengine which you must specify"
);
System
.
out
.
println
(
"-port The TCP/IP port number to use for the connection. Default is 6030"
);
System
.
out
.
println
(
"-user The TDengine user name to use when connecting to the server. Default is 'root'"
);
System
.
out
.
println
(
"-password The password to use when connecting to the server.Default is 'taosdata'"
);
// database
System
.
out
.
println
(
"-database Destination database. Default is 'test'"
);
System
.
out
.
println
(
"-keep database keep parameter. Default is 3650"
);
System
.
out
.
println
(
"-days database days parameter. Default is 30"
);
System
.
out
.
println
(
"-replica database replica parameter. Default 1, min: 1, max: 3"
);
// super table
System
.
out
.
println
(
"-doCreateTable do create super table and sub table, true or false, Default true"
);
System
.
out
.
println
(
"-superTable super table name. Default 'weather'"
);
System
.
out
.
println
(
"-prefixOfFields The prefix of field in super table. Default is 'col'"
);
System
.
out
.
println
(
"-numOfFields The number of field in super table. Default is (ts timestamp, temperature float, humidity int)."
);
System
.
out
.
println
(
"-prefixOfTags The prefix of tag in super table. Default is 'tag'"
);
System
.
out
.
println
(
"-numOfTags The number of tag in super table. Default is (location nchar(64), groupId int)."
);
System
.
out
.
println
(
"-superTableSQL specify a sql statement for the super table.\n"
+
" Default is 'create table weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int). \n"
+
" if you use this parameter, the numOfFields and numOfTags will be invalid'"
);
// sub table
System
.
out
.
println
(
"-prefixOfTable The prefix of sub tables. Default is 't'"
);
System
.
out
.
println
(
"-numOfTables The number of tables. Default is 1"
);
System
.
out
.
println
(
"-numOfThreadsForCreate The number of thread during create sub table. Default is 1"
);
// insert task
System
.
out
.
println
(
"-autoCreateTable Use auto Create sub tables SQL. Default is false"
);
System
.
out
.
println
(
"-numOfRowsPerTable The number of records per table. Default is 1"
);
System
.
out
.
println
(
"-numOfThreadsForInsert The number of threads during insert row. Default is 1"
);
System
.
out
.
println
(
"-numOfTablesPerSQL The number of table per SQL. Default is 1"
);
System
.
out
.
println
(
"-numOfValuesPerSQL The number of value per SQL. Default is 1"
);
System
.
out
.
println
(
"-startTime start time for insert task, The format is \"yyyy-MM-dd HH:mm:ss.SSS\"."
);
System
.
out
.
println
(
"-timeGap the number of time gap. Default is 1000 ms"
);
System
.
out
.
println
(
"-frequency the number of records per second inserted into one table. default is 0, do not control frequency"
);
System
.
out
.
println
(
"-order Insert mode--0: In order, 1: Out of order. Default is in order"
);
System
.
out
.
println
(
"-rate The proportion of data out of order. effective only if order is 1. min 0, max 100, default is 10"
);
System
.
out
.
println
(
"-range The range of data out of order. effective only if order is 1. default is 1000 ms"
);
// query task
// System.out.println("-sqlFile The select sql file");
// drop task
System
.
out
.
println
(
"-dropTable Drop data before quit. Default is false"
);
System
.
out
.
println
(
"--help Give this help list"
);
}
/**
* parse args from command line
*
* @param args command line args
* @return JdbcTaosdemoConfig
*/
public
JdbcTaosdemoConfig
(
String
[]
args
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
// instance
if
(
"-host"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
host
=
args
[++
i
];
}
if
(
"-port"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
port
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-user"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
user
=
args
[++
i
];
}
if
(
"-password"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
password
=
args
[++
i
];
}
// database
if
(
"-database"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
database
=
args
[++
i
];
}
if
(
"-keep"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
keep
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-days"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
days
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-replica"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
replica
=
Integer
.
parseInt
(
args
[++
i
]);
}
// super table
if
(
"-doCreateTable"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
doCreateTable
=
Boolean
.
parseBoolean
(
args
[++
i
]);
}
if
(
"-superTable"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
superTable
=
args
[++
i
];
}
if
(
"-prefixOfFields"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
prefixOfFields
=
args
[++
i
];
}
if
(
"-numOfFields"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfFields
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-prefixOfTags"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
prefixOfTags
=
args
[++
i
];
}
if
(
"-numOfTags"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfTags
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-superTableSQL"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
superTableSQL
=
args
[++
i
];
}
// sub table
if
(
"-prefixOfTable"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
prefixOfTable
=
args
[++
i
];
}
if
(
"-numOfTables"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfTables
=
Long
.
parseLong
(
args
[++
i
]);
}
if
(
"-autoCreateTable"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
autoCreateTable
=
Boolean
.
parseBoolean
(
args
[++
i
]);
}
if
(
"-numOfThreadsForCreate"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfThreadsForCreate
=
Integer
.
parseInt
(
args
[++
i
]);
}
// insert task
if
(
"-numOfRowsPerTable"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfRowsPerTable
=
Long
.
parseLong
(
args
[++
i
]);
}
if
(
"-numOfThreadsForInsert"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfThreadsForInsert
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-numOfTablesPerSQL"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfTablesPerSQL
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-numOfValuesPerSQL"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfValuesPerSQL
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-startTime"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
startTime
=
TimeStampUtil
.
datetimeToLong
(
args
[++
i
]);
}
if
(
"-timeGap"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
timeGap
=
Long
.
parseLong
(
args
[++
i
]);
}
if
(
"-frequency"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
frequency
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-order"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
order
=
Integer
.
parseInt
(
args
[++
i
]);
}
if
(
"-rate"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
rate
=
Integer
.
parseInt
(
args
[++
i
]);
if
(
rate
<
0
||
rate
>
100
)
throw
new
IllegalArgumentException
(
"rate must between 0 and 100"
);
}
if
(
"-range"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
range
=
Integer
.
parseInt
(
args
[++
i
]);
}
// select task
// drop task
if
(
"-dropTable"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
dropTable
=
Boolean
.
parseBoolean
(
args
[++
i
]);
}
}
}
public
static
void
main
(
String
[]
args
)
{
JdbcTaosdemoConfig
config
=
new
JdbcTaosdemoConfig
(
args
);
}
}
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/CreateTableTask.java
已删除
100644 → 0
浏览文件 @
4fee1be8
package
com.taosdata.example.jdbcTaosdemo.task
;
import
com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.jdbcTaosdemo.utils.ConnectionFactory
;
import
com.taosdata.example.jdbcTaosdemo.utils.SqlSpeller
;
import
org.apache.log4j.Logger
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
CreateTableTask
implements
Runnable
{
private
static
Logger
logger
=
Logger
.
getLogger
(
CreateTableTask
.
class
);
private
final
JdbcTaosdemoConfig
config
;
private
final
int
startIndex
;
private
final
int
tableNumber
;
public
CreateTableTask
(
JdbcTaosdemoConfig
config
,
int
startIndex
,
int
tableNumber
)
{
this
.
config
=
config
;
this
.
startIndex
=
startIndex
;
this
.
tableNumber
=
tableNumber
;
}
@Override
public
void
run
()
{
try
{
Connection
connection
=
ConnectionFactory
.
build
(
config
);
for
(
int
i
=
startIndex
;
i
<
startIndex
+
tableNumber
;
i
++)
{
Statement
statement
=
connection
.
createStatement
();
String
sql
=
SqlSpeller
.
createTableSQL
(
i
+
1
,
config
.
database
,
config
.
superTable
);
statement
.
execute
(
sql
);
statement
.
close
();
logger
.
info
(
">>> "
+
sql
);
}
connection
.
close
();
}
catch
(
SQLException
e
)
{
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
}
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableDatetimeTask.java
已删除
100644 → 0
浏览文件 @
4fee1be8
package
com.taosdata.example.jdbcTaosdemo.task
;
import
com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.jdbcTaosdemo.utils.ConnectionFactory
;
import
com.taosdata.example.jdbcTaosdemo.utils.SqlSpeller
;
import
org.apache.log4j.Logger
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
InsertTableDatetimeTask
implements
Runnable
{
private
static
Logger
logger
=
Logger
.
getLogger
(
InsertTableDatetimeTask
.
class
);
private
final
JdbcTaosdemoConfig
config
;
private
final
int
startTableIndex
;
private
final
int
tableNumber
;
private
final
long
startDatetime
;
private
final
long
finishedDatetime
;
public
InsertTableDatetimeTask
(
JdbcTaosdemoConfig
config
,
int
startTableIndex
,
int
tableNumber
,
long
startDatetime
,
long
finishedDatetime
)
{
this
.
config
=
config
;
this
.
startTableIndex
=
startTableIndex
;
this
.
tableNumber
=
tableNumber
;
this
.
startDatetime
=
startDatetime
;
this
.
finishedDatetime
=
finishedDatetime
;
}
@Override
public
void
run
()
{
try
{
Connection
connection
=
ConnectionFactory
.
build
(
config
);
int
valuesCount
=
config
.
numOfValuesPerSQL
;
for
(
long
ts
=
startDatetime
;
ts
<
finishedDatetime
;
ts
+=
valuesCount
)
{
for
(
int
i
=
startTableIndex
;
i
<
startTableIndex
+
tableNumber
;
i
++)
{
String
sql
=
SqlSpeller
.
insertBatchSizeRowsSQL
(
config
.
database
,
config
.
prefixOfTable
,
i
+
1
,
ts
,
valuesCount
);
Statement
statement
=
connection
.
createStatement
();
statement
.
execute
(
sql
);
statement
.
close
();
logger
.
info
(
Thread
.
currentThread
().
getName
()
+
">>> "
+
sql
);
}
}
connection
.
close
();
}
catch
(
SQLException
e
)
{
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
}
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
已删除
100644 → 0
浏览文件 @
4fee1be8
package
com.taosdata.example.jdbcTaosdemo.task
;
import
com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig
;
import
com.taosdata.example.jdbcTaosdemo.utils.ConnectionFactory
;
import
com.taosdata.example.jdbcTaosdemo.utils.SqlSpeller
;
import
org.apache.log4j.Logger
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.time.temporal.ChronoUnit
;
public
class
InsertTableTask
implements
Runnable
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
InsertTableTask
.
class
);
private
final
JdbcTaosdemoConfig
config
;
private
final
int
startTbIndex
;
private
final
int
tableNumber
;
private
final
int
recordsNumberPerTable
;
public
InsertTableTask
(
JdbcTaosdemoConfig
config
,
int
startTbIndex
,
int
tableNumber
,
int
recordsNumberPerTable
)
{
this
.
config
=
config
;
this
.
startTbIndex
=
startTbIndex
;
this
.
tableNumber
=
tableNumber
;
this
.
recordsNumberPerTable
=
recordsNumberPerTable
;
}
@Override
public
void
run
()
{
try
{
Connection
connection
=
ConnectionFactory
.
build
(
config
);
int
keep
=
config
.
keep
;
Instant
end
=
Instant
.
now
();
Instant
start
=
end
.
minus
(
Duration
.
ofDays
(
keep
-
1
));
long
timeGap
=
ChronoUnit
.
MILLIS
.
between
(
start
,
end
)
/
(
recordsNumberPerTable
-
1
);
// iterate insert
for
(
int
j
=
0
;
j
<
recordsNumberPerTable
;
j
++)
{
long
ts
=
start
.
toEpochMilli
()
+
(
j
*
timeGap
);
// insert data into echo table
for
(
int
i
=
startTbIndex
;
i
<
startTbIndex
+
tableNumber
;
i
++)
{
String
sql
=
SqlSpeller
.
insertBatchSizeRowsSQL
(
config
.
database
,
config
.
prefixOfTable
,
i
+
1
,
ts
,
config
.
numOfValuesPerSQL
);
logger
.
info
(
Thread
.
currentThread
().
getName
()
+
">>> "
+
sql
);
Statement
statement
=
connection
.
createStatement
();
statement
.
execute
(
sql
);
statement
.
close
();
}
}
connection
.
close
();
}
catch
(
SQLException
e
)
{
logger
.
error
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
}
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/ConnectionFactory.java
已删除
100644 → 0
浏览文件 @
4fee1be8
package
com.taosdata.example.jdbcTaosdemo.utils
;
import
com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig
;
import
com.taosdata.jdbc.TSDBDriver
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.util.Properties
;
public
class
ConnectionFactory
{
public
static
Connection
build
(
JdbcTaosdemoConfig
config
)
throws
SQLException
{
return
build
(
config
.
host
,
config
.
port
,
config
.
database
,
config
.
user
,
config
.
password
);
}
public
static
Connection
build
(
String
host
,
int
port
,
String
dbName
)
throws
SQLException
{
return
build
(
host
,
port
,
dbName
,
"root"
,
"taosdata"
);
}
private
static
Connection
build
(
String
host
,
int
port
,
String
dbName
,
String
user
,
String
password
)
throws
SQLException
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_USER
,
user
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_PASSWORD
,
password
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
return
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":"
+
port
+
"/"
+
dbName
+
""
,
properties
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录