提交 a150b2b6 编写于 作者: Z zyyang

change

上级 0cab1f28
package com.taosdata.taosdemo.components; package com.taosdata.taosdemo.components;
import com.taosdata.taosdemo.domain.*; import com.taosdata.taosdemo.domain.FieldMeta;
import com.taosdata.taosdemo.domain.SubTableValue;
import com.taosdata.taosdemo.domain.SuperTableMeta;
import com.taosdata.taosdemo.domain.TagMeta;
import com.taosdata.taosdemo.service.DatabaseService; import com.taosdata.taosdemo.service.DatabaseService;
import com.taosdata.taosdemo.service.SubTableService; import com.taosdata.taosdemo.service.SubTableService;
import com.taosdata.taosdemo.service.SuperTableService; import com.taosdata.taosdemo.service.SuperTableService;
import com.taosdata.taosdemo.service.data.SubTableMetaGenerator;
import com.taosdata.taosdemo.service.data.SubTableValueGenerator; import com.taosdata.taosdemo.service.data.SubTableValueGenerator;
import com.taosdata.taosdemo.service.data.SuperTableMetaGenerator; import com.taosdata.taosdemo.service.data.SuperTableMetaGenerator;
import com.taosdata.taosdemo.utils.JdbcTaosdemoConfig; import com.taosdata.taosdemo.utils.JdbcTaosdemoConfig;
...@@ -103,53 +105,58 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner { ...@@ -103,53 +105,58 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
int numOfRowsPerTable = config.numOfRowsPerTable; int numOfRowsPerTable = config.numOfRowsPerTable;
int numOfValuesPerSQL = config.numOfValuesPerSQL; int numOfValuesPerSQL = config.numOfValuesPerSQL;
if (config.startTime == 0) { Instant now = Instant.now();
Instant end = Instant.now(); long earliest = now.minus(Duration.ofDays(config.keep)).toEpochMilli();
config.startTime = end.minus(Duration.ofDays(config.keep)).toEpochMilli(); if (config.startTime == 0 || config.startTime < earliest) {
config.startTime = earliest;
} }
if (numOfRowsPerTable < numOfValuesPerSQL) if (numOfRowsPerTable < numOfValuesPerSQL)
numOfValuesPerSQL = numOfRowsPerTable; numOfValuesPerSQL = numOfRowsPerTable;
if (numOfTables < numOfTablesPerSQL) if (numOfTables < numOfTablesPerSQL)
numOfTablesPerSQL = numOfTables; numOfTablesPerSQL = numOfTables;
//table
for (int tableCnt = 0; tableCnt < numOfTables; ) { // row
int tableSize = numOfTablesPerSQL; for (int rowCnt = 0; rowCnt < numOfRowsPerTable; ) {
if (tableCnt + tableSize > numOfTables) { int rowSize = numOfValuesPerSQL;
tableSize = numOfTables - tableCnt; if (rowCnt + rowSize > numOfRowsPerTable) {
rowSize = numOfRowsPerTable - rowCnt;
} }
// row
for (int rowCnt = 0; rowCnt < numOfRowsPerTable; ) { //table
int rowSize = numOfValuesPerSQL; for (int tableCnt = 0; tableCnt < numOfTables; ) {
if (rowCnt + rowSize > numOfRowsPerTable) { int tableSize = numOfTablesPerSQL;
rowSize = numOfRowsPerTable - rowCnt; if (tableCnt + tableSize > numOfTables) {
tableSize = numOfTables - tableCnt;
} }
/***********************************************/ /***********************************************/
long startTime = config.startTime + rowCnt * config.timeGap; long startTime = config.startTime + rowCnt * config.timeGap;
// for (int i = 0; i < tableSize; i++) {
// System.out.print(config.prefixOfTable + (tableCnt + i + 1) + ", tableSize: " + tableSize + ", rowSize: " + rowSize); for (int i = 0; i < tableSize; i++) {
// System.out.println(", startTime: " + TimeStampUtil.longToDatetime(startTime) + ",timeGap: " + config.timeGap); 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(superTableMeta, config.prefixOfFields, tableCnt, tableSize, rowSize, startTime, config.timeGap); // List<SubTableValue> data = SubTableValueGenerator.generate(superTableMeta, config.prefixOfTable, tableCnt, tableSize, rowSize, startTime, config.timeGap);
// List<SubTableValue> data = SubTableValueGenerator.generate(subTableMetaList, tableCnt, tableSize, rowSize, startTime, config.timeGap); // List<SubTableValue> data = SubTableValueGenerator.generate(subTableMetaList, tableCnt, tableSize, rowSize, startTime, config.timeGap);
// 乱序 // 乱序
if (config.order != 0) { // if (config.order != 0) {
SubTableValueGenerator.disrupt(data, config.rate, config.range); // SubTableValueGenerator.disrupt(data, config.rate, config.range);
} // }
// insert // insert
if (config.autoCreateTable) { // if (config.autoCreateTable) {
subTableService.insertAutoCreateTable(data, config.numOfThreadsForInsert, config.frequency); // subTableService.insertAutoCreateTable(data, config.numOfThreadsForInsert, config.frequency);
} else { // } else {
subTableService.insert(data, config.numOfThreadsForInsert, config.frequency); // subTableService.insert(data, config.numOfThreadsForInsert, config.frequency);
} // }
/***********************************************/ /***********************************************/
rowCnt += rowSize; tableCnt += tableSize;
} }
tableCnt += tableSize; rowCnt += rowSize;
} }
/*********************************************************************************/ /*********************************************************************************/
// 批量插入,自动建表 // 批量插入,自动建表
// dataList.stream().forEach(subTableValues -> { // dataList.stream().forEach(subTableValues -> {
...@@ -196,7 +203,6 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner { ...@@ -196,7 +203,6 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
private SuperTableMeta createSupertable(JdbcTaosdemoConfig config) { private SuperTableMeta createSupertable(JdbcTaosdemoConfig config) {
SuperTableMeta tableMeta; SuperTableMeta tableMeta;
// create super table // create super table
logger.info(">>> create super table <<<");
if (config.superTableSQL != null) { if (config.superTableSQL != null) {
// use a sql to create super table // use a sql to create super table
tableMeta = SuperTableMetaGenerator.generate(config.superTableSQL); tableMeta = SuperTableMetaGenerator.generate(config.superTableSQL);
......
...@@ -12,7 +12,7 @@ public final class JdbcTaosdemoConfig { ...@@ -12,7 +12,7 @@ public final class JdbcTaosdemoConfig {
public int days = 30; //days public int days = 30; //days
public int replica = 1; //replica public int replica = 1; //replica
//super table //super table
public boolean doCreateTable = false; public boolean doCreateTable = true;
public String superTable = "weather"; //super table name public String superTable = "weather"; //super table name
public String prefixOfFields = "col"; public String prefixOfFields = "col";
public int numOfFields; public int numOfFields;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册