Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0cab1f28
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看板
提交
0cab1f28
编写于
12月 14, 2020
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
078ed83e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
78 addition
and
26 deletion
+78
-26
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication.java
...osdata/jdbc/springbootdemo/SpringbootdemoApplication.java
+1
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/TaosDemoCommandLineRunner.java
...osdata/taosdemo/components/TaosDemoCommandLineRunner.java
+15
-10
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java
...n/java/com/taosdata/taosdemo/service/SubTableService.java
+19
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/data/SubTableMetaGenerator.java
...taosdata/taosdemo/service/data/SubTableMetaGenerator.java
+12
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/data/SubTableValueGenerator.java
...aosdata/taosdemo/service/data/SubTableValueGenerator.java
+19
-3
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/utils/JdbcTaosdemoConfig.java
.../java/com/taosdata/taosdemo/utils/JdbcTaosdemoConfig.java
+12
-12
未找到文件。
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication.java
浏览文件 @
0cab1f28
...
...
@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan
(
basePackages
=
{
"com.taosdata.jdbc.springbootdemo.dao"
})
@SpringBootApplication
public
class
SpringbootdemoApplication
{
public
class
cd
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SpringbootdemoApplication
.
class
,
args
);
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/TaosDemoCommandLineRunner.java
浏览文件 @
0cab1f28
...
...
@@ -16,9 +16,7 @@ import org.springframework.stereotype.Component;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.time.temporal.ChronoUnit
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
@Component
...
...
@@ -33,7 +31,7 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
private
SubTableService
subTableService
;
private
SuperTableMeta
superTableMeta
;
private
List
<
SubTableMeta
>
subTableMetaList
;
//
private List<SubTableMeta> subTableMetaList;
// private List<SubTableValue> subTableValueList;
// private List<List<SubTableValue>> dataList;
...
...
@@ -48,10 +46,14 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
}
// 准备数据
prepareMetaData
(
config
);
// 超级表的meta
superTableMeta
=
createSupertable
(
config
);
// 子表的meta
// subTableMetaList = SubTableMetaGenerator.generate(superTableMeta, config.numOfTables, config.tablePrefix);
// 创建数据库
//
createDatabaseTask(config);
createDatabaseTask
(
config
);
// 建表
//
createTableTask(config);
createTableTask
(
config
);
// 插入
insertTask
(
config
);
// 查询: 1. 生成查询语句, 2. 执行查询
...
...
@@ -87,7 +89,7 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
if
(
config
.
autoCreateTable
)
return
;
// 批量建子表
subTableService
.
createSubTable
(
su
bTableMetaList
,
config
.
numOfThreadsForCreate
);
subTableService
.
createSubTable
(
su
perTableMeta
,
config
.
numOfTables
,
config
.
prefixOfTable
,
config
.
numOfThreadsForCreate
);
}
long
end
=
System
.
currentTimeMillis
();
logger
.
info
(
">>> create table time cost : "
+
(
end
-
start
)
+
" ms."
);
...
...
@@ -124,11 +126,14 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
}
/***********************************************/
long
startTime
=
config
.
startTime
+
rowCnt
*
config
.
timeGap
;
// System.out.print("tableCnt: " + tableCnt + ", tableSize: " + tableSize + ", rowCnt: " + rowCnt + ", rowSize: " + rowSize);
// System.out.println(", startTime: " + TimeStampUtil.longToDatetime(startTime) + ",timeGap: " + config.timeGap);
// for (int i = 0; i < tableSize; i++) {
// System.out.print(config.prefixOfTable + (tableCnt + i + 1) + ", tableSize: " + tableSize + ", rowSize: " + rowSize);
// System.out.println(", startTime: " + TimeStampUtil.longToDatetime(startTime) + ",timeGap: " + config.timeGap);
// }
// 生成数据
List
<
SubTableValue
>
data
=
SubTableValueGenerator
.
generate
(
subTableMetaList
,
tableCnt
,
tableSize
,
rowSize
,
startTime
,
config
.
timeGap
);
List
<
SubTableValue
>
data
=
SubTableValueGenerator
.
generate
(
superTableMeta
,
config
.
prefixOfFields
,
tableCnt
,
tableSize
,
rowSize
,
startTime
,
config
.
timeGap
);
// List<SubTableValue> data = SubTableValueGenerator.generate(subTableMetaList, tableCnt, tableSize, rowSize, startTime, config.timeGap);
// 乱序
if
(
config
.
order
!=
0
)
{
SubTableValueGenerator
.
disrupt
(
data
,
config
.
rate
,
config
.
range
);
...
...
@@ -168,7 +173,7 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
// 超级表的meta
superTableMeta
=
createSupertable
(
config
);
// 子表的meta
subTableMetaList
=
SubTableMetaGenerator
.
generate
(
superTableMeta
,
config
.
numOfTables
,
config
.
tablePrefix
);
// subTableMetaList = SubTableMetaGenerator.generate(superTableMeta, config.numOfTables, config.prefixOfTable
);
/*
// 子表的data
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java
浏览文件 @
0cab1f28
...
...
@@ -2,7 +2,9 @@ package com.taosdata.taosdemo.service;
import
com.taosdata.taosdemo.domain.SubTableMeta
;
import
com.taosdata.taosdemo.domain.SubTableValue
;
import
com.taosdata.taosdemo.domain.SuperTableMeta
;
import
com.taosdata.taosdemo.mapper.SubTableMapper
;
import
com.taosdata.taosdemo.service.data.SubTableMetaGenerator
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -39,6 +41,20 @@ public class SubTableService extends AbstractService {
return
getAffectRows
(
futureList
);
}
public
void
createSubTable
(
SuperTableMeta
superTableMeta
,
int
numOfTables
,
String
prefixOfTable
,
int
numOfThreadsForCreate
)
{
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
numOfThreadsForCreate
);
for
(
int
i
=
0
;
i
<
numOfTables
;
i
++)
{
int
tableIndex
=
i
;
executor
.
execute
(()
->
createSubTable
(
superTableMeta
,
prefixOfTable
+
(
tableIndex
+
1
)));
}
executor
.
shutdown
();
}
public
void
createSubTable
(
SuperTableMeta
superTableMeta
,
String
tableName
)
{
// 构造数据
SubTableMeta
meta
=
SubTableMetaGenerator
.
generate
(
superTableMeta
,
tableName
);
mapper
.
createUsingSuperTable
(
meta
);
}
// 创建一张子表,可以指定database,supertable,tablename,tag值
public
int
createSubTable
(
SubTableMeta
subTableMeta
)
{
...
...
@@ -98,4 +114,7 @@ public class SubTableService extends AbstractService {
}
}
/********************************************************************/
}
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/data/SubTableMetaGenerator.java
浏览文件 @
0cab1f28
...
...
@@ -27,4 +27,16 @@ public class SubTableMetaGenerator {
return
subTableMetaList
;
}
public
static
SubTableMeta
generate
(
SuperTableMeta
superTableMeta
,
String
tableName
)
{
SubTableMeta
subTableMeta
=
new
SubTableMeta
();
// create table xxx.xxx using xxx tags(...)
subTableMeta
.
setDatabase
(
superTableMeta
.
getDatabase
());
subTableMeta
.
setName
(
tableName
);
subTableMeta
.
setSupertable
(
superTableMeta
.
getName
());
subTableMeta
.
setFields
(
superTableMeta
.
getFields
());
List
<
TagValue
>
tagValues
=
TagValueGenerator
.
generate
(
superTableMeta
.
getTags
());
subTableMeta
.
setTags
(
tagValues
);
return
subTableMeta
;
}
}
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/data/SubTableValueGenerator.java
浏览文件 @
0cab1f28
package
com.taosdata.taosdemo.service.data
;
import
com.taosdata.taosdemo.domain.RowValue
;
import
com.taosdata.taosdemo.domain.SubTableMeta
;
import
com.taosdata.taosdemo.domain.SubTableValue
;
import
com.taosdata.taosdemo.domain.*
;
import
com.taosdata.taosdemo.utils.TimeStampUtil
;
import
org.springframework.beans.BeanUtils
;
...
...
@@ -11,6 +9,24 @@ import java.util.List;
public
class
SubTableValueGenerator
{
public
static
List
<
SubTableValue
>
generate
(
SuperTableMeta
superTableMeta
,
String
prefixOfTables
,
int
tableIndex
,
int
tableSize
,
int
valueSize
,
long
startTime
,
long
timeGap
)
{
List
<
SubTableValue
>
subTableValues
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<=
tableSize
;
i
++)
{
SubTableValue
subTableValue
=
new
SubTableValue
();
subTableValue
.
setDatabase
(
superTableMeta
.
getDatabase
());
subTableValue
.
setName
(
prefixOfTables
+
(
tableIndex
+
i
));
subTableValue
.
setSupertable
(
superTableMeta
.
getName
());
TimeStampUtil
.
TimeTuple
tuple
=
TimeStampUtil
.
range
(
startTime
,
timeGap
,
valueSize
);
List
<
TagValue
>
tags
=
TagValueGenerator
.
generate
(
superTableMeta
.
getTags
());
subTableValue
.
setTags
(
tags
);
List
<
RowValue
>
values
=
FieldValueGenerator
.
generate
(
tuple
.
start
,
tuple
.
end
,
tuple
.
timeGap
,
superTableMeta
.
getFields
());
subTableValue
.
setValues
(
values
);
subTableValues
.
add
(
subTableValue
);
}
return
subTableValues
;
}
public
static
List
<
SubTableValue
>
generate
(
List
<
SubTableMeta
>
subTableMetaList
,
int
numOfRowsPerTable
,
long
start
,
long
timeGap
)
{
return
generate
(
subTableMetaList
,
0
,
subTableMetaList
.
size
(),
numOfRowsPerTable
,
start
,
timeGap
);
}
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/utils/JdbcTaosdemoConfig.java
浏览文件 @
0cab1f28
...
...
@@ -12,7 +12,7 @@ public final class JdbcTaosdemoConfig {
public
int
days
=
30
;
//days
public
int
replica
=
1
;
//replica
//super table
public
boolean
doCreateTable
=
tru
e
;
public
boolean
doCreateTable
=
fals
e
;
public
String
superTable
=
"weather"
;
//super table name
public
String
prefixOfFields
=
"col"
;
public
int
numOfFields
;
...
...
@@ -20,17 +20,17 @@ public final class JdbcTaosdemoConfig {
public
int
numOfTags
;
public
String
superTableSQL
;
//sub table
public
String
tablePrefix
=
"t"
;
public
int
numOfTables
=
1
;
public
int
numOfThreadsForCreate
=
1
;
public
String
prefixOfTable
=
"t"
;
// insert task
public
boolean
autoCreateTable
;
public
int
numOfRowsPerTable
=
1
;
public
boolean
autoCreateTable
=
true
;
public
int
numOfTables
=
100
;
public
int
numOfRowsPerTable
=
100
;
public
int
numOfTablesPerSQL
=
10
;
public
int
numOfValuesPerSQL
=
10
;
public
int
numOfThreadsForCreate
=
1
;
public
int
numOfThreadsForInsert
=
1
;
public
int
numOfTablesPerSQL
=
1
;
public
int
numOfValuesPerSQL
=
1
;
public
long
startTime
;
public
long
timeGap
;
public
long
timeGap
=
1
;
public
int
frequency
;
public
int
order
;
public
int
rate
=
10
;
...
...
@@ -63,7 +63,7 @@ public final class JdbcTaosdemoConfig {
" 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
(
"-
tablePrefix
The prefix of sub tables. Default is 't'"
);
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
...
...
@@ -142,8 +142,8 @@ public final class JdbcTaosdemoConfig {
superTableSQL
=
args
[++
i
];
}
// sub table
if
(
"-
tablePrefix
"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
tablePrefix
=
args
[++
i
];
if
(
"-
prefixOfTable
"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
prefixOfTable
=
args
[++
i
];
}
if
(
"-numOfTables"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
numOfTables
=
Integer
.
parseInt
(
args
[++
i
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录