change
This commit is contained in:
parent
e783e017e1
commit
9a55077b7c
|
@ -14,54 +14,54 @@ import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
|
||||||
public class TdEngineSuperDataGen {
|
public class TdEngineSuperDataGen {
|
||||||
|
|
||||||
public static void main(String[] args) throws ClassNotFoundException, SQLException {
|
public static void main(String[] args) throws ClassNotFoundException, SQLException {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
String url = "jdbc:TAOS://127.0.0.1:6030/test?user=root&password=taosdata";
|
String url = "jdbc:TAOS://127.0.0.1:6030/test?user=root&password=taosdata";
|
||||||
Connection conn = DriverManager.getConnection(url);
|
Connection conn = DriverManager.getConnection(url);
|
||||||
Statement stmt = conn.createStatement();
|
Statement stmt = conn.createStatement();
|
||||||
// create database
|
// create database
|
||||||
stmt.executeUpdate("create database if not exists hdb");
|
stmt.executeUpdate("create database if not exists hdb");
|
||||||
// use database
|
// use database
|
||||||
stmt.executeUpdate("use hdb");
|
stmt.executeUpdate("use hdb");
|
||||||
stmt.executeUpdate("drop table if exists sdata");
|
stmt.executeUpdate("drop table if exists sdata");
|
||||||
// create table
|
// create table
|
||||||
stmt.executeUpdate(
|
stmt.executeUpdate(
|
||||||
"create table if not exists sdata (uptime timestamp, id int, x int , y int ,cmt binary(100)) tags(location nchar(100),tname nchar(100))");
|
"create table if not exists sdata (uptime timestamp, id int, x int , y int ,cmt binary(100)) tags(location nchar(100),tname nchar(100))");
|
||||||
|
|
||||||
ZoneId zoneId = ZoneId.systemDefault();
|
ZoneId zoneId = ZoneId.systemDefault();
|
||||||
Map<String, String> table = new HashMap<>();
|
Map<String, String> table = new HashMap<>();
|
||||||
table.put("dt001", "beijing");
|
table.put("dt001", "beijing");
|
||||||
table.put("dt002", "shanghai");
|
table.put("dt002", "shanghai");
|
||||||
table.put("dt003", "chongqing");
|
table.put("dt003", "chongqing");
|
||||||
table.put("dt004", "xian");
|
table.put("dt004", "xian");
|
||||||
for (Entry<String, String> kv : table.entrySet()) {
|
for (Entry<String, String> kv : table.entrySet()) {
|
||||||
LocalDateTime d = LocalDateTime.now().minusMonths(2);
|
LocalDateTime d = LocalDateTime.now().minusMonths(2);
|
||||||
long rowCount = LocalDateTime.now().atZone(zoneId).toEpochSecond() - d.atZone(zoneId).toEpochSecond();
|
long rowCount = LocalDateTime.now().atZone(zoneId).toEpochSecond() - d.atZone(zoneId).toEpochSecond();
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
StringBuilder sb = null;
|
StringBuilder sb = null;
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
for (long i = 0; i < rowCount; i++) {
|
for (long i = 0; i < rowCount; i++) {
|
||||||
sb = new StringBuilder("insert into " + kv.getKey() + " using sdata tags(" + kv.getValue() + ","
|
sb = new StringBuilder("insert into " + kv.getKey() + " using sdata tags(" + kv.getValue() + "," + kv.getKey() + ") values('");
|
||||||
+ kv.getKey() + ") values('");
|
d = d.plusSeconds(1);
|
||||||
d = d.plusSeconds(1);
|
sb.append(d.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.MS")));
|
||||||
sb.append(d.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.MS")));
|
sb.append("'," + i + "," + r.nextInt(100) + "," + r.nextInt(100) + ",'");
|
||||||
sb.append("'," + i + "," + r.nextInt(100) + "," + r.nextInt(100) + ",'");
|
sb.append(DigestUtils.md5Hex(d.toString()));
|
||||||
sb.append(DigestUtils.md5Hex(d.toString()));
|
sb.append("')");
|
||||||
sb.append("')");
|
System.out.println("SQL >>> " + sb.toString());
|
||||||
stmt.executeUpdate(sb.toString());
|
stmt.executeUpdate(sb.toString());
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println(d);
|
System.out.println(d);
|
||||||
System.out.println(sb.toString());
|
System.out.println(sb.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
System.out.println("generate data execute time:" + (endTime - startTime) + "ms, resultset rows " + rowCount
|
System.out.println("generate data execute time:" + (endTime - startTime) + "ms, resultset rows " + rowCount
|
||||||
+ ", " + rowCount * 1000 / (endTime - startTime) + " rows/sec");
|
+ ", " + rowCount * 1000 / (endTime - startTime) + " rows/sec");
|
||||||
}
|
}
|
||||||
stmt.close();
|
stmt.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue