change
This commit is contained in:
parent
078ed83e90
commit
0cab1f289e
|
@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@MapperScan(basePackages = {"com.taosdata.jdbc.springbootdemo.dao"})
|
@MapperScan(basePackages = {"com.taosdata.jdbc.springbootdemo.dao"})
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class SpringbootdemoApplication {
|
public class cd {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SpringbootdemoApplication.class, args);
|
SpringApplication.run(SpringbootdemoApplication.class, args);
|
||||||
|
|
|
@ -16,9 +16,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -33,7 +31,7 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
|
||||||
private SubTableService subTableService;
|
private SubTableService subTableService;
|
||||||
|
|
||||||
private SuperTableMeta superTableMeta;
|
private SuperTableMeta superTableMeta;
|
||||||
private List<SubTableMeta> subTableMetaList;
|
// private List<SubTableMeta> subTableMetaList;
|
||||||
// private List<SubTableValue> subTableValueList;
|
// private List<SubTableValue> subTableValueList;
|
||||||
// private List<List<SubTableValue>> dataList;
|
// private List<List<SubTableValue>> dataList;
|
||||||
|
|
||||||
|
@ -48,10 +46,14 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
|
||||||
}
|
}
|
||||||
// 准备数据
|
// 准备数据
|
||||||
prepareMetaData(config);
|
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);
|
insertTask(config);
|
||||||
// 查询: 1. 生成查询语句, 2. 执行查询
|
// 查询: 1. 生成查询语句, 2. 执行查询
|
||||||
|
@ -87,7 +89,7 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
|
||||||
if (config.autoCreateTable)
|
if (config.autoCreateTable)
|
||||||
return;
|
return;
|
||||||
// 批量建子表
|
// 批量建子表
|
||||||
subTableService.createSubTable(subTableMetaList, config.numOfThreadsForCreate);
|
subTableService.createSubTable(superTableMeta, config.numOfTables, config.prefixOfTable, config.numOfThreadsForCreate);
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
logger.info(">>> create table time cost : " + (end - start) + " ms.");
|
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;
|
long startTime = config.startTime + rowCnt * config.timeGap;
|
||||||
// System.out.print("tableCnt: " + tableCnt + ", tableSize: " + tableSize + ", rowCnt: " + rowCnt + ", rowSize: " + rowSize);
|
// 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);
|
// 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) {
|
if (config.order != 0) {
|
||||||
SubTableValueGenerator.disrupt(data, config.rate, config.range);
|
SubTableValueGenerator.disrupt(data, config.rate, config.range);
|
||||||
|
@ -168,7 +173,7 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
|
||||||
// 超级表的meta
|
// 超级表的meta
|
||||||
superTableMeta = createSupertable(config);
|
superTableMeta = createSupertable(config);
|
||||||
// 子表的meta
|
// 子表的meta
|
||||||
subTableMetaList = SubTableMetaGenerator.generate(superTableMeta, config.numOfTables, config.tablePrefix);
|
// subTableMetaList = SubTableMetaGenerator.generate(superTableMeta, config.numOfTables, config.prefixOfTable);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// 子表的data
|
// 子表的data
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.taosdata.taosdemo.service;
|
||||||
|
|
||||||
import com.taosdata.taosdemo.domain.SubTableMeta;
|
import com.taosdata.taosdemo.domain.SubTableMeta;
|
||||||
import com.taosdata.taosdemo.domain.SubTableValue;
|
import com.taosdata.taosdemo.domain.SubTableValue;
|
||||||
|
import com.taosdata.taosdemo.domain.SuperTableMeta;
|
||||||
import com.taosdata.taosdemo.mapper.SubTableMapper;
|
import com.taosdata.taosdemo.mapper.SubTableMapper;
|
||||||
|
import com.taosdata.taosdemo.service.data.SubTableMetaGenerator;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -39,6 +41,20 @@ public class SubTableService extends AbstractService {
|
||||||
return getAffectRows(futureList);
|
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值
|
// 创建一张子表,可以指定database,supertable,tablename,tag值
|
||||||
public int createSubTable(SubTableMeta subTableMeta) {
|
public int createSubTable(SubTableMeta subTableMeta) {
|
||||||
|
@ -98,4 +114,7 @@ public class SubTableService extends AbstractService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,16 @@ public class SubTableMetaGenerator {
|
||||||
return subTableMetaList;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package com.taosdata.taosdemo.service.data;
|
package com.taosdata.taosdemo.service.data;
|
||||||
|
|
||||||
import com.taosdata.taosdemo.domain.RowValue;
|
import com.taosdata.taosdemo.domain.*;
|
||||||
import com.taosdata.taosdemo.domain.SubTableMeta;
|
|
||||||
import com.taosdata.taosdemo.domain.SubTableValue;
|
|
||||||
import com.taosdata.taosdemo.utils.TimeStampUtil;
|
import com.taosdata.taosdemo.utils.TimeStampUtil;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
|
@ -11,6 +9,24 @@ import java.util.List;
|
||||||
|
|
||||||
public class SubTableValueGenerator {
|
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) {
|
public static List<SubTableValue> generate(List<SubTableMeta> subTableMetaList, int numOfRowsPerTable, long start, long timeGap) {
|
||||||
return generate(subTableMetaList, 0, subTableMetaList.size(), numOfRowsPerTable, start, timeGap);
|
return generate(subTableMetaList, 0, subTableMetaList.size(), numOfRowsPerTable, start, timeGap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 = true;
|
public boolean doCreateTable = false;
|
||||||
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;
|
||||||
|
@ -20,17 +20,17 @@ public final class JdbcTaosdemoConfig {
|
||||||
public int numOfTags;
|
public int numOfTags;
|
||||||
public String superTableSQL;
|
public String superTableSQL;
|
||||||
//sub table
|
//sub table
|
||||||
public String tablePrefix = "t";
|
public String prefixOfTable = "t";
|
||||||
public int numOfTables = 1;
|
|
||||||
public int numOfThreadsForCreate = 1;
|
|
||||||
// insert task
|
// insert task
|
||||||
public boolean autoCreateTable;
|
public boolean autoCreateTable = true;
|
||||||
public int numOfRowsPerTable = 1;
|
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 numOfThreadsForInsert = 1;
|
||||||
public int numOfTablesPerSQL = 1;
|
|
||||||
public int numOfValuesPerSQL = 1;
|
|
||||||
public long startTime;
|
public long startTime;
|
||||||
public long timeGap;
|
public long timeGap = 1;
|
||||||
public int frequency;
|
public int frequency;
|
||||||
public int order;
|
public int order;
|
||||||
public int rate = 10;
|
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" +
|
" 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'");
|
" if you use this parameter, the numOfFields and numOfTags will be invalid'");
|
||||||
// sub table
|
// 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("-numOfTables The number of tables. Default is 1");
|
||||||
System.out.println("-numOfThreadsForCreate The number of thread during create sub table. Default is 1");
|
System.out.println("-numOfThreadsForCreate The number of thread during create sub table. Default is 1");
|
||||||
// insert task
|
// insert task
|
||||||
|
@ -142,8 +142,8 @@ public final class JdbcTaosdemoConfig {
|
||||||
superTableSQL = args[++i];
|
superTableSQL = args[++i];
|
||||||
}
|
}
|
||||||
// sub table
|
// sub table
|
||||||
if ("-tablePrefix".equals(args[i]) && i < args.length - 1) {
|
if ("-prefixOfTable".equals(args[i]) && i < args.length - 1) {
|
||||||
tablePrefix = args[++i];
|
prefixOfTable = args[++i];
|
||||||
}
|
}
|
||||||
if ("-numOfTables".equals(args[i]) && i < args.length - 1) {
|
if ("-numOfTables".equals(args[i]) && i < args.length - 1) {
|
||||||
numOfTables = Integer.parseInt(args[++i]);
|
numOfTables = Integer.parseInt(args[++i]);
|
||||||
|
|
Loading…
Reference in New Issue