@@ -63,12 +56,18 @@
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.4
+ 2.0.8
log4j
log4j
1.2.17
+
+ junit
+ junit
+ 4.13.1
+ test
+
diff --git a/tests/examples/JDBC/JDBCDemo/readme.md b/tests/examples/JDBC/JDBCDemo/readme.md
index a91624a9e47a3015d88e2e9aa9f62cf8dd0672cc..9b8790adaddb20246232392dd323ec502102fa18 100644
--- a/tests/examples/JDBC/JDBCDemo/readme.md
+++ b/tests/examples/JDBC/JDBCDemo/readme.md
@@ -2,12 +2,14 @@
TDengine's JDBC demo project is organized in a Maven way so that users can easily compile, package and run the project. If you don't have Maven on your server, you may install it using
sudo apt-get install maven
-## Compile and Install JDBC Driver
-TDengine's JDBC driver jar is not yet published to maven center repo, so we need to manually compile it and install it to the local Maven repository. This can be easily done with Maven. Go to source directory of the JDBC driver ``TDengine/src/connector/jdbc`` and execute
-mvn clean package install
+## Install TDengine Client
+Make sure you have already installed a tdengine client on your current develop environment.
+Download the tdengine package on our website: ``https://www.taosdata.com/cn/all-downloads/`` and install the client.
## Compile the Demo Code and Run It
To compile the demo project, go to the source directory ``TDengine/tests/examples/JDBC/JDBCDemo`` and execute
-mvn clean assembly:single package
-The ``pom.xml`` is configured to package all the dependencies into one executable jar file. To run it, go to ``examples/JDBC/JDBCDemo/target`` and execute
-java -jar jdbcdemo-1.0-SNAPSHOT-jar-with-dependencies.jar
+mvn clean package assembly:single
+The ``pom.xml`` is configured to package all the dependencies into one executable jar file.
+
+To run it, go to ``examples/JDBC/JDBCDemo/target`` and execute
+java -jar jdbcChecker-SNAPSHOT-jar-with-dependencies.jar -host localhost
\ No newline at end of file
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample.java b/tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample.java
deleted file mode 100644
index c093b604da6dc6f815272f99d7fc786dab87928b..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample.java
+++ /dev/null
@@ -1,205 +0,0 @@
-import java.sql.*;
-
-public class TSDBSyncSample {
- private static final String JDBC_PROTOCAL = "jdbc:TAOS://";
- private static final String TSDB_DRIVER = "com.taosdata.jdbc.TSDBDriver";
-
- private String host = "127.0.0.1";
- private String user = "root";
- private String password = "taosdata";
- private int port = 0;
- private String jdbcUrl = "";
-
- private String databaseName = "db";
- private String metricsName = "mt";
- private String tablePrefix = "t";
-
- private int tablesCount = 1;
- private int loopCount = 2;
- private int batchSize = 10;
- private long beginTimestamp = 1519833600000L;
-
- private long rowsInserted = 0;
-
- static {
- try {
- Class.forName(TSDB_DRIVER);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- TSDBSyncSample tester = new TSDBSyncSample();
- tester.doReadArgument(args);
-
- System.out.println("---------------------------------------------------------------");
- System.out.println("Start testing...");
- System.out.println("---------------------------------------------------------------");
-
- tester.doMakeJdbcUrl();
- tester.doCreateDbAndTable();
- tester.doExecuteInsert();
- tester.doExecuteQuery();
-
- System.out.println("\n---------------------------------------------------------------");
- System.out.println("Stop testing...");
- System.out.println("---------------------------------------------------------------");
- }
-
- private void doReadArgument(String[] args) {
- System.out.println("Arguments format: host tables loop batchs");
- if (args.length >= 1) {
- this.host = args[0];
- }
-
- if (args.length >= 2) {
- this.tablesCount = Integer.parseInt(args[1]);
- }
-
- if (args.length >= 3) {
- this.loopCount = Integer.parseInt(args[2]);
- }
-
- if (args.length >= 4) {
- this.batchSize = Integer.parseInt(args[3]);
- }
- }
-
- private void doMakeJdbcUrl() {
- // jdbc:TSDB://127.0.0.1:0/dbname?user=root&password=taosdata
- System.out.println("\nJDBC URL to use:");
- this.jdbcUrl = String.format("%s%s:%d/%s?user=%s&password=%s", JDBC_PROTOCAL, this.host, this.port, "",
- this.user, this.password);
- System.out.println(this.jdbcUrl);
- }
-
- private void doCreateDbAndTable() {
- System.out.println("\n---------------------------------------------------------------");
- System.out.println("Start creating databases and tables...");
- String sql = "";
- try (Connection conn = DriverManager.getConnection(jdbcUrl);
- Statement stmt = conn.createStatement()){
-
- sql = "create database if not exists " + this.databaseName;
- stmt.executeUpdate(sql);
- System.out.printf("Successfully executed: %s\n", sql);
-
- sql = "use " + this.databaseName;
- stmt.executeUpdate(sql);
- System.out.printf("Successfully executed: %s\n", sql);
-
- sql = "create table if not exists " + this.metricsName + " (ts timestamp, v1 int) tags(t1 int)";
- stmt.executeUpdate(sql);
- System.out.printf("Successfully executed: %s\n", sql);
-
- for (int i = 0; i < this.tablesCount; i++) {
- sql = String.format("create table if not exists %s%d using %s tags(%d)", this.tablePrefix, i,
- this.metricsName, i);
- stmt.executeUpdate(sql);
- System.out.printf("Successfully executed: %s\n", sql);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.printf("Failed to execute SQL: %s\n", sql);
- System.exit(4);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(4);
- }
- System.out.println("Successfully created databases and tables");
- }
-
- public void doExecuteInsert() {
- System.out.println("\n---------------------------------------------------------------");
- System.out.println("Start inserting data...");
- int start = (int) System.currentTimeMillis();
- StringBuilder sql = new StringBuilder("");
- try (Connection conn = DriverManager.getConnection(jdbcUrl);
- Statement stmt = conn.createStatement()){
- stmt.executeUpdate("use " + databaseName);
- for (int loop = 0; loop < this.loopCount; loop++) {
- for (int table = 0; table < this.tablesCount; ++table) {
- sql = new StringBuilder("insert into ");
- sql.append(this.tablePrefix).append(table).append(" values");
- for (int batch = 0; batch < this.batchSize; ++batch) {
- int rows = loop * this.batchSize + batch;
- sql.append("(").append(this.beginTimestamp + rows).append(",").append(rows).append(")");
- }
- int affectRows = stmt.executeUpdate(sql.toString());
- this.rowsInserted += affectRows;
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.printf("Failed to execute SQL: %s\n", sql.toString());
- System.exit(4);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(4);
- }
- int end = (int) System.currentTimeMillis();
- System.out.println("Inserting completed!");
- System.out.printf("Total %d rows inserted, %d rows failed, time spend %d seconds.\n", this.rowsInserted,
- this.loopCount * this.batchSize - this.rowsInserted, (end - start) / 1000);
- }
-
- public void doExecuteQuery() {
- System.out.println("\n---------------------------------------------------------------");
- System.out.println("Starting querying data...");
- ResultSet resSet = null;
- StringBuilder sql = new StringBuilder("");
- StringBuilder resRow = new StringBuilder("");
- try (Connection conn = DriverManager.getConnection(jdbcUrl);
- Statement stmt = conn.createStatement()){
- stmt.executeUpdate("use " + databaseName);
- for (int i = 0; i < this.tablesCount; ++i) {
- sql = new StringBuilder("select * from ").append(this.tablePrefix).append(i);
-
- resSet = stmt.executeQuery(sql.toString());
- if (resSet == null) {
- System.out.println(sql + " failed");
- System.exit(4);
- }
-
- ResultSetMetaData metaData = resSet.getMetaData();
- System.out.println("Retrieve metadata of " + tablePrefix + i);
- for (int column = 1; column <= metaData.getColumnCount(); ++column) {
- System.out.printf("Column%d: name = %s, type = %d, type name = %s, display size = %d\n", column, metaData.getColumnName(column), metaData.getColumnType(column),
- metaData.getColumnTypeName(column), metaData.getColumnDisplaySize(column));
- }
- int rows = 0;
- System.out.println("Retrieve data of " + tablePrefix + i);
- while (resSet.next()) {
- resRow = new StringBuilder();
- for (int col = 1; col <= metaData.getColumnCount(); col++) {
- resRow.append(metaData.getColumnName(col)).append("=").append(resSet.getObject(col))
- .append(" ");
- }
- System.out.println(resRow.toString());
- rows++;
- }
-
- try {
- if (resSet != null)
- resSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- System.out.printf("Successfully executed query: %s;\nTotal rows returned: %d\n", sql.toString(), rows);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.printf("Failed to execute query: %s\n", sql.toString());
- System.exit(4);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(4);
- }
- System.out.println("Query completed!");
- }
-
-}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCConnectorChecker.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcChecker.java
similarity index 98%
rename from tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCConnectorChecker.java
rename to tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcChecker.java
index a19f0a009325e9b278160c37ced463ac8d89ac60..4be71c52214c348ed7b41c3e763de0d908514907 100644
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCConnectorChecker.java
+++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcChecker.java
@@ -5,7 +5,7 @@ import com.taosdata.jdbc.TSDBDriver;
import java.sql.*;
import java.util.Properties;
-public class JDBCConnectorChecker {
+public class JdbcChecker {
private static String host;
private static String dbName = "test";
private static String tbName = "weather";
@@ -158,7 +158,7 @@ public class JDBCConnectorChecker {
return;
}
- JDBCConnectorChecker checker = new JDBCConnectorChecker();
+ JdbcChecker checker = new JdbcChecker();
checker.init();
checker.createDatabase();
checker.useDatabase();
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
index c30d85a084d7175e9e6861ad33d7374a868553d9..259985ec9f4708b9317575fd97919adcc82d7161 100644
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
+++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
@@ -25,6 +25,7 @@ public class JdbcTaosdemo {
}
public static void main(String[] args) {
+ // parse config from args
JdbcTaosdemoConfig config = new JdbcTaosdemoConfig(args);
boolean isHelp = Arrays.asList(args).contains("--help");
@@ -38,27 +39,51 @@ public class JdbcTaosdemo {
}
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. !!!!");
+ logger.info("!!! Infinite Insert Mode Started. !!!");
taosdemo.insertInfinite();
} else {
+ // insert into table
taosdemo.insertMultiThreads();
- // single table select
+ // select from sub table
taosdemo.selectFromTableLimit();
taosdemo.selectCountFromTable();
taosdemo.selectAvgMinMaxFromTable();
- // super table select
+ // 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.isDeleteTable())
taosdemo.dropSuperTable();
@@ -196,6 +221,11 @@ public class JdbcTaosdemo {
executeQuery(sql);
}
+ private void selectLastFromTable() {
+ String sql = SqlSpeller.selectLastFromTableSQL(config.getDbName(), config.getTbPrefix(), 1);
+ executeQuery(sql);
+ }
+
private void selectFromSuperTableLimit() {
String sql = SqlSpeller.selectFromSuperTableLimitSQL(config.getDbName(), config.getStbName(), 10, 0);
executeQuery(sql);
@@ -211,6 +241,52 @@ public class JdbcTaosdemo {
executeQuery(sql);
}
+ private void selectAvgMinMaxFromSuperTableWhereTag() {
+ String sql = SqlSpeller.selectAvgMinMaxFromSuperTableWhere("current", config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+ private void selectLastFromSuperTableWhere() {
+ String sql = SqlSpeller.selectLastFromSuperTableWhere("current", config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+ private void selectGroupBy() {
+ String sql = SqlSpeller.selectGroupBy("current", config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+ private void selectLike() {
+ String sql = SqlSpeller.selectLike(config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+ private void selectLastOneHour() {
+ String sql = SqlSpeller.selectLastOneHour(config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+ private void selectLastOneDay() {
+ String sql = SqlSpeller.selectLastOneDay(config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+ private void selectLastOneWeek() {
+ String sql = SqlSpeller.selectLastOneWeek(config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+ private void selectLastOneMonth() {
+ String sql = SqlSpeller.selectLastOneMonth(config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+ private void selectLastOneYear() {
+ String sql = SqlSpeller.selectLastOneYear(config.getDbName(), config.getStbName());
+ executeQuery(sql);
+ }
+
+
private void close() {
try {
if (connection != null) {
@@ -241,6 +317,7 @@ public class JdbcTaosdemo {
long end = System.currentTimeMillis();
printSql(sql, execute, (end - start));
} catch (SQLException e) {
+ logger.error("ERROR execute SQL ===> " + sql);
logger.error(e.getMessage());
e.printStackTrace();
}
@@ -258,6 +335,7 @@ public class JdbcTaosdemo {
printSql(sql, true, (end - start));
printResult(resultSet);
} catch (SQLException e) {
+ logger.error("ERROR execute SQL ===> " + sql);
logger.error(e.getMessage());
e.printStackTrace();
}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
index 3cca9a3d7a8b45be5d733b9f7a4836eb89c828c3..82613037dbccd3be1f2c8a85a2f25e7a25ffad01 100644
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
+++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
@@ -14,9 +14,9 @@ public final class JdbcTaosdemoConfig {
//Destination database. Default is 'test'
private String dbName = "test";
//keep
- private int keep = 365 * 20;
+ private int keep = 3650;
//days
- private int days = 30;
+ private int days = 10;
//Super table Name. Default is 'meters'
private String stbName = "meters";
@@ -35,7 +35,7 @@ public final class JdbcTaosdemoConfig {
private boolean deleteTable = false;
public static void printHelp() {
- System.out.println("Usage: java -jar JDBCConnectorChecker.jar [OPTION...]");
+ System.out.println("Usage: java -jar JdbcTaosDemo.jar [OPTION...]");
System.out.println("-h host The host to connect to TDengine. you must input one");
System.out.println("-p port The TCP/IP port number to use for the connection. Default is 6030");
System.out.println("-u user The TDengine user name to use when connecting to the server. Default is 'root'");
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
index d6d6ebbff1ac08e68e3e8034a59f84189ad86bf4..a35628bb58c6630d92bd2b6aebb09f9912e57536 100644
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
+++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
@@ -3,44 +3,49 @@ 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 com.taosdata.example.jdbcTaosdemo.utils.TimeStampUtil;
import org.apache.log4j.Logger;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.concurrent.atomic.AtomicLong;
+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 static AtomicLong beginTimestamp = new AtomicLong(TimeStampUtil.datetimeToLong("2005-01-01 00:00:00.000"));
private final JdbcTaosdemoConfig config;
- private final int startIndex;
+ private final int startTbIndex;
private final int tableNumber;
- private final int recordsNumber;
+ private final int recordsNumberPerTable;
- public InsertTableTask(JdbcTaosdemoConfig config, int startIndex, int tableNumber, int recordsNumber) {
+ public InsertTableTask(JdbcTaosdemoConfig config, int startTbIndex, int tableNumber, int recordsNumberPerTable) {
this.config = config;
- this.startIndex = startIndex;
+ this.startTbIndex = startTbIndex;
this.tableNumber = tableNumber;
- this.recordsNumber = recordsNumber;
+ this.recordsNumberPerTable = recordsNumberPerTable;
}
@Override
public void run() {
try {
Connection connection = ConnectionFactory.build(config);
+ int keep = config.getKeep();
+ 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 < recordsNumber; j++) {
- long ts = beginTimestamp.getAndIncrement();
+ for (int j = 0; j < recordsNumberPerTable; j++) {
+ long ts = start.toEpochMilli() + (j * timeGap);
// insert data into echo table
- for (int i = startIndex; i < startIndex + tableNumber; i++) {
+ for (int i = startTbIndex; i < startTbIndex + tableNumber; i++) {
String sql = SqlSpeller.insertOneRowSQL(config.getDbName(), config.getTbPrefix(), i + 1, ts);
+ logger.info(Thread.currentThread().getName() + ">>> " + sql);
Statement statement = connection.createStatement();
statement.execute(sql);
statement.close();
- logger.info(Thread.currentThread().getName() + ">>> " + sql);
}
}
connection.close();
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java
index 7af97f3b1baa0206f6f29b18a1ae59d2182c5423..b4a79e9eba47cc947d822b645d0ae1f9952f08f0 100644
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java
+++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java
@@ -78,5 +78,49 @@ public class SqlSpeller {
return "select avg(" + field + "),min(" + field + "),max(" + field + ") from " + dbName + "." + stbName + "";
}
+ public static String selectLastFromTableSQL(String dbName, String tbPrefix, int tbIndex) {
+ return "select last(*) from " + dbName + "." + tbPrefix + "" + tbIndex;
+ }
+
+ //select avg ,max from stb where tag
+ public static String selectAvgMinMaxFromSuperTableWhere(String field, String dbName, String stbName) {
+ return "select avg(" + field + "),min(" + field + "),max(" + field + ") from " + dbName + "." + stbName + " where location = '" + locations[random.nextInt(locations.length)] + "'";
+ }
+
+ //select last from stb where
+ public static String selectLastFromSuperTableWhere(String field, String dbName, String stbName) {
+ return "select last(" + field + ") from " + dbName + "." + stbName + " where location = '" + locations[random.nextInt(locations.length)] + "'";
+ }
+
+ public static String selectGroupBy(String field, String dbName, String stbName) {
+ return "select avg(" + field + ") from " + dbName + "." + stbName + " group by location";
+ }
+
+ public static String selectLike(String dbName, String stbName) {
+ return "select * from " + dbName + "." + stbName + " where location like 'S%'";
+ }
+
+ public static String selectLastOneHour(String dbName, String stbName) {
+ return "select * from " + dbName + "." + stbName + " where ts >= now - 1h";
+ }
+
+ public static String selectLastOneDay(String dbName, String stbName) {
+ return "select * from " + dbName + "." + stbName + " where ts >= now - 1d";
+ }
+
+ public static String selectLastOneWeek(String dbName, String stbName) {
+ return "select * from " + dbName + "." + stbName + " where ts >= now - 1w";
+ }
+
+ public static String selectLastOneMonth(String dbName, String stbName) {
+ return "select * from " + dbName + "." + stbName + " where ts >= now - 1n";
+ }
+
+ public static String selectLastOneYear(String dbName, String stbName) {
+ return "select * from " + dbName + "." + stbName + " where ts >= now - 1y";
+ }
+ // select group by
+ // select like
+ // select ts >= ts<=
}
\ No newline at end of file
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java
index d00471f58147f9c66f3747c1f8a1eadbae3a6dab..0a345afdd1e45123d889d7ee198cf8efd201176b 100644
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java
+++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java
@@ -1,8 +1,10 @@
package com.taosdata.example.jdbcTaosdemo.utils;
-import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Date;
public class TimeStampUtil {
private static final String datetimeFormat = "yyyy-MM-dd HH:mm:ss.SSS";
@@ -21,14 +23,14 @@ public class TimeStampUtil {
return sdf.format(new Date(time));
}
- public static void main(String[] args) {
- final String startTime = "2005-01-01 00:00:00.000";
+ public static void main(String[] args) throws ParseException {
+
+// Instant now = Instant.now();
+// System.out.println(now);
+// Instant years20Ago = now.minus(Duration.ofDays(365));
+// System.out.println(years20Ago);
- long start = TimeStampUtil.datetimeToLong(startTime);
- System.out.println(start);
- String datetime = TimeStampUtil.longToDatetime(1519833600000L);
- System.out.println(datetime);
}
diff --git a/tests/examples/JDBC/JDBCDemo/src/test/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtilTest.java b/tests/examples/JDBC/JDBCDemo/src/test/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtilTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..f370b2ef6eaa708b061ebf4a7f58f3d31f78f999
--- /dev/null
+++ b/tests/examples/JDBC/JDBCDemo/src/test/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtilTest.java
@@ -0,0 +1,52 @@
+package com.taosdata.example.jdbcTaosdemo.utils;
+
+import org.junit.Test;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.Date;
+
+import static org.junit.Assert.*;
+
+public class TimeStampUtilTest {
+
+ @Test
+ public void datetimeToLong() {
+ final String startTime = "2005-01-01 00:00:00.000";
+ long start = TimeStampUtil.datetimeToLong(startTime);
+ assertEquals(1104508800000l, start);
+ }
+
+ @Test
+ public void longToDatetime() {
+ String datetime = TimeStampUtil.longToDatetime(1510000000000L);
+ assertEquals("2017-11-07 04:26:40.000", datetime);
+ }
+
+ @Test
+ public void getStartDateTime() {
+ int keep = 365;
+
+ Instant end = Instant.now();
+ System.out.println(end.toString());
+ System.out.println(end.toEpochMilli());
+
+ Instant start = end.minus(Duration.ofDays(keep));
+ System.out.println(start.toString());
+ System.out.println(start.toEpochMilli());
+
+ int numberOfRecordsPerTable = 10;
+ long timeGap = ChronoUnit.MILLIS.between(start, end) / (numberOfRecordsPerTable - 1);
+ System.out.println(timeGap);
+
+ System.out.println("===========================");
+ for (int i = 0; i < numberOfRecordsPerTable; i++) {
+ long ts = start.toEpochMilli() + (i * timeGap);
+ System.out.println(i + " : " + ts);
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/examples/nodejs/nodejsChecker.js b/tests/examples/nodejs/nodejsChecker.js
new file mode 100644
index 0000000000000000000000000000000000000000..c77944f75243a50e6e2c738e659cb4e64f3e5574
--- /dev/null
+++ b/tests/examples/nodejs/nodejsChecker.js
@@ -0,0 +1,60 @@
+const taos = require('td2.0-connector');
+
+
+var host = null;
+var port = 6030;
+for(var i = 2; i < global.process.argv.length; i++){
+ var key = global.process.argv[i].split("=")[0];
+ var value = global.process.argv[i].split("=")[1];
+
+ if("host" == key){
+ host = value;
+ }
+ if("port" == key){
+ port = value;
+ }
+}
+
+if(host == null){
+ console.log("Usage: node nodejsChecker.js host= port=");
+ process.exit(0);
+}
+
+// establish connection
+var conn = taos.connect({host:host, user:"root", password:"taosdata",port:port});
+var cursor = conn.cursor();
+// create database
+executeSql("create database if not exists test", 0);
+// use db
+executeSql("use test", 0);
+// drop table
+executeSql("drop table if exists test.weather", 0);
+// create table
+executeSql("create table if not exists test.weather(ts timestamp, temperature float, humidity int)", 0);
+// insert
+executeSql("insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)", 1);
+// select
+executeQuery("select * from test.weather");
+// close connection
+conn.close();
+
+function executeQuery(sql){
+ var start = new Date().getTime();
+ var promise = cursor.query(sql, true);
+ var end = new Date().getTime();
+ printSql(sql, promise != null,(end - start));
+ promise.then(function(result){
+ result.pretty();
+ });
+}
+
+function executeSql(sql, affectRows){
+ var start = new Date().getTime();
+ var promise = cursor.execute(sql);
+ var end = new Date().getTime();
+ printSql(sql, promise == affectRows, (end - start));
+}
+
+function printSql(sql, succeed, cost){
+ console.log("[ "+(succeed ? "OK" : "ERROR!")+" ] time cost: " + cost + " ms, execute statement ====> " + sql);
+}
diff --git a/tests/pytest/insert/before_1970.py b/tests/pytest/insert/before_1970.py
new file mode 100644
index 0000000000000000000000000000000000000000..cb17b657aad1a3bfdb915c9661bad291b75d6f04
--- /dev/null
+++ b/tests/pytest/insert/before_1970.py
@@ -0,0 +1,80 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import sys
+import taos
+from util.log import tdLog
+from util.cases import tdCases
+from util.sql import tdSql
+from util.dnodes import tdDnodes
+
+
+class TDTestCase:
+ """
+ add test data before 1970s
+ """
+ def init(self, conn, logSql):
+ tdLog.debug("start to execute %s" % __file__)
+ tdSql.init(conn.cursor(), logSql)
+
+ def run(self):
+ tdSql.prepare()
+
+ print("==============step1")
+ tdSql.execute("create database if not exists demo keep 36500;");
+ print("==============create db demo keep 365000 days")
+ tdSql.execute("use demo;")
+ tdSql.execute("CREATE table if not exists test (ts timestamp, f1 int);")
+ print("==============create table test")
+
+ print("==============step2")
+ #TODO : should add more testcases
+ tdSql.execute("insert into test values('1930-12-12 01:19:20.345', 1);")
+ tdSql.execute("insert into test values('1969-12-30 23:59:59.999', 2);")
+ tdSql.execute("insert into test values(-3600, 3);")
+ tdSql.execute("insert into test values('2020-10-20 14:02:53.770', 4);")
+ print("==============insert data")
+
+ # tdSql.query("select * from test;")
+ #
+ # tdSql.checkRows(3)
+ #
+ # tdSql.checkData(0,0,'1969-12-12 01:19:20.345000')
+ # tdSql.checkData(1,0,'1970-01-01 07:00:00.000000')
+ # tdSql.checkData(2,0,'2020-10-20 14:02:53.770000')
+ print("==============step3")
+ tdDnodes.stopAll()
+ tdDnodes.start(1)
+ print("==============restart taosd")
+
+
+ print("==============step4")
+ tdSql.execute("use demo;")
+ tdSql.query("select * from test;")
+ # print(tdSql.queryResult)
+ tdSql.checkRows(4)
+ tdSql.checkData(0,0,'1930-12-12 01:19:20.345000')
+ tdSql.checkData(1,0,'1969-12-30 23:59:59.999000')
+ tdSql.checkData(2,0,'1970-01-01 07:00:00.000000')
+ tdSql.checkData(3,0,'2020-10-20 14:02:53.770000')
+ print("==============check data")
+
+
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success("%s successfully executed" % __file__)
+
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
diff --git a/tests/pytest/table/alter_wal0.py b/tests/pytest/table/alter_wal0.py
new file mode 100644
index 0000000000000000000000000000000000000000..15ad69998f450b8e385cbf58052d246d9de27380
--- /dev/null
+++ b/tests/pytest/table/alter_wal0.py
@@ -0,0 +1,75 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import sys
+import taos
+from util.log import tdLog
+from util.cases import tdCases
+from util.sql import tdSql
+from util.dnodes import tdDnodes
+
+
+class TDTestCase:
+ """
+ remove last tow bytes of file 'wal0',then restart taosd and create new tables.
+ """
+ def init(self, conn, logSql):
+ tdLog.debug("start to execute %s" % __file__)
+ tdSql.init(conn.cursor(), logSql)
+
+ def run(self):
+ tdSql.prepare()
+
+ print("==============step1")
+ tdSql.execute("create database if not exists demo;");
+ tdSql.execute("use demo;")
+ tdSql.execute("create table if not exists meters(ts timestamp, f1 int) tags(t1 int);");
+ for i in range(1,11):
+ tdSql.execute("CREATE table if not exists test{num} using meters tags({num});".format(num=i))
+ print("==============insert 10 tables")
+
+ tdSql.query('show tables;')
+ tdSql.checkRows(10)
+
+ print("==============step2")
+ tdDnodes.stopAll()
+ filename = '/var/lib/taos/mnode/wal/wal0'
+
+ with open(filename, 'rb') as f1:
+ temp = f1.read()
+
+ with open(filename, 'wb') as f2:
+ f2.write(temp[:-2])
+
+ tdDnodes.start(1)
+ print("==============remove last tow bytes of file 'wal0' and restart taosd")
+
+ print("==============step3")
+ tdSql.execute("use demo;")
+ tdSql.query('show tables;')
+ tdSql.checkRows(10)
+ for i in range(11,21):
+ tdSql.execute("CREATE table if not exists test{num} using meters tags({num});".format(num=i))
+
+ tdSql.query('show tables;')
+ tdSql.checkRows(20)
+ print("==============check table numbers and create 10 tables")
+
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success("%s successfully executed" % __file__)
+
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())