diff --git a/cmake/install.inc b/cmake/install.inc
index 0dda0f68211b..0ea79589caef 100755
--- a/cmake/install.inc
+++ b/cmake/install.inc
@@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
IF (TD_MVN_INSTALLED)
- INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.20-dist.jar DESTINATION connector/jdbc)
+ INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.21-dist.jar DESTINATION connector/jdbc)
ENDIF ()
ELSEIF (TD_DARWIN)
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
diff --git a/src/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt
index cec8197849ec..3c50ac566b5f 100644
--- a/src/connector/jdbc/CMakeLists.txt
+++ b/src/connector/jdbc/CMakeLists.txt
@@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
POST_BUILD
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.20-dist.jar ${LIBRARY_OUTPUT_PATH}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.21-dist.jar ${LIBRARY_OUTPUT_PATH}
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
COMMENT "build jdbc driver")
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml
index 999e11357d7e..1c24b621efe5 100755
--- a/src/connector/jdbc/deploy-pom.xml
+++ b/src/connector/jdbc/deploy-pom.xml
@@ -5,7 +5,7 @@
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.20
+ 2.0.21
jar
JDBCDriver
diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml
index 25ed3d22f2b5..7a421eff2296 100755
--- a/src/connector/jdbc/pom.xml
+++ b/src/connector/jdbc/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.20
+ 2.0.21
jar
JDBCDriver
https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
index 66dc07a63452..f6a0fcca316c 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
@@ -308,7 +308,7 @@ public int findColumn(String columnLabel) throws SQLException {
return colMetaData.getColIndex() + 1;
}
}
- throw new SQLException(TSDBConstants.INVALID_VARIABLES);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
@Override
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
index 043db9bbd75f..6179b47da104 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
@@ -14,16 +14,13 @@
*****************************************************************************/
package com.taosdata.jdbc;
+import java.sql.SQLException;
+import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
public abstract class TSDBConstants {
- public static final String STATEMENT_CLOSED = "statement is closed";
- public static final String UNSUPPORTED_METHOD_EXCEPTION_MSG = "this operation is NOT supported currently!";
- public static final String INVALID_VARIABLES = "invalid variables";
- public static final String RESULT_SET_IS_CLOSED = "resultSet is closed";
-
public static final String DEFAULT_PORT = "6200";
public static Map DATATYPE_MAP = null;
@@ -77,8 +74,65 @@ public static String FixErrMsg(int code) {
return WrapErrMsg("unkown error!");
}
+ public static int taosType2JdbcType(int taosType) throws SQLException {
+ switch (taosType) {
+ case TSDBConstants.TSDB_DATA_TYPE_NULL:
+ return Types.NULL;
+ case TSDBConstants.TSDB_DATA_TYPE_BOOL:
+ return Types.BOOLEAN;
+ case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
+ return Types.TINYINT;
+ case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
+ return Types.SMALLINT;
+ case TSDBConstants.TSDB_DATA_TYPE_INT:
+ return Types.INTEGER;
+ case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
+ return Types.BIGINT;
+ case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
+ return Types.FLOAT;
+ case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
+ return Types.DOUBLE;
+ case TSDBConstants.TSDB_DATA_TYPE_BINARY:
+ return Types.BINARY;
+ case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
+ return Types.TIMESTAMP;
+ case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
+ return Types.NCHAR;
+ }
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
+ }
+
+ public static int jdbcType2TaosType(int jdbcType) throws SQLException {
+ switch (jdbcType){
+ case Types.NULL:
+ return TSDBConstants.TSDB_DATA_TYPE_NULL;
+ case Types.BOOLEAN:
+ return TSDBConstants.TSDB_DATA_TYPE_BOOL;
+ case Types.TINYINT:
+ return TSDBConstants.TSDB_DATA_TYPE_TINYINT;
+ case Types.SMALLINT:
+ return TSDBConstants.TSDB_DATA_TYPE_SMALLINT;
+ case Types.INTEGER:
+ return TSDBConstants.TSDB_DATA_TYPE_INT;
+ case Types.BIGINT:
+ return TSDBConstants.TSDB_DATA_TYPE_BIGINT;
+ case Types.FLOAT:
+ return TSDBConstants.TSDB_DATA_TYPE_FLOAT;
+ case Types.DOUBLE:
+ return TSDBConstants.TSDB_DATA_TYPE_DOUBLE;
+ case Types.BINARY:
+ return TSDBConstants.TSDB_DATA_TYPE_BINARY;
+ case Types.TIMESTAMP:
+ return TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP;
+ case Types.NCHAR:
+ return TSDBConstants.TSDB_DATA_TYPE_NCHAR;
+ }
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
+ }
+
static {
DATATYPE_MAP = new HashMap<>();
+ DATATYPE_MAP.put(0, "NULL");
DATATYPE_MAP.put(1, "BOOL");
DATATYPE_MAP.put(2, "TINYINT");
DATATYPE_MAP.put(3, "SMALLINT");
@@ -90,4 +144,8 @@ public static String FixErrMsg(int code) {
DATATYPE_MAP.put(9, "TIMESTAMP");
DATATYPE_MAP.put(10, "NCHAR");
}
+
+ public static String jdbcType2TaosTypeName(int type) throws SQLException {
+ return DATATYPE_MAP.get(jdbcType2TaosType(type));
+ }
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
index 3ae8696f7d39..78e7aec79c25 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
@@ -18,6 +18,7 @@ public class TSDBErrorNumbers {
public static final int ERROR_INVALID_FOR_EXECUTE = 0x230c; //not a valid sql for execute: (SQL)
public static final int ERROR_PARAMETER_INDEX_OUT_RANGE = 0x230d; // parameter index out of range
public static final int ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED = 0x230e; // connection already closed
+ public static final int ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE = 0x230f; //unknown sql type in tdengine
public static final int ERROR_UNKNOWN = 0x2350; //unknown error
@@ -49,6 +50,7 @@ public class TSDBErrorNumbers {
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE);
errorNumbers.add(ERROR_PARAMETER_INDEX_OUT_RANGE);
errorNumbers.add(ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED);
+ errorNumbers.add(ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
/*****************************************************/
errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
index 0c0071a94902..e0b1c246cbea 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
@@ -20,7 +20,7 @@
import java.sql.Types;
import java.util.List;
-public class TSDBResultSetMetaData implements ResultSetMetaData {
+public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaData {
List colMetaDataList = null;
@@ -28,14 +28,6 @@ public TSDBResultSetMetaData(List metaDataList) {
this.colMetaDataList = metaDataList;
}
- public T unwrap(Class iface) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
- }
-
- public boolean isWrapperFor(Class> iface) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
- }
-
public int getColumnCount() throws SQLException {
return colMetaDataList.size();
}
@@ -94,7 +86,7 @@ public String getColumnName(int column) throws SQLException {
}
public String getSchemaName(int column) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
public int getPrecision(int column) throws SQLException {
@@ -125,18 +117,18 @@ public int getScale(int column) throws SQLException {
}
public String getTableName(int column) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
public String getCatalogName(int column) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
public int getColumnType(int column) throws SQLException {
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
switch (meta.getColType()) {
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
- return java.sql.Types.BIT;
+ return Types.BOOLEAN;
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
return java.sql.Types.TINYINT;
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
@@ -150,13 +142,13 @@ public int getColumnType(int column) throws SQLException {
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
return java.sql.Types.DOUBLE;
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
- return java.sql.Types.CHAR;
+ return Types.BINARY;
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
- return java.sql.Types.BIGINT;
+ return java.sql.Types.TIMESTAMP;
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
- return java.sql.Types.CHAR;
+ return Types.NCHAR;
}
- throw new SQLException(TSDBConstants.INVALID_VARIABLES);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
public String getColumnTypeName(int column) throws SQLException {
@@ -173,7 +165,7 @@ public boolean isWritable(int column) throws SQLException {
}
public boolean isDefinitelyWritable(int column) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
public String getColumnClassName(int column) throws SQLException {
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetWrapper.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetWrapper.java
index 98b823a3c1d5..48854e773f89 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetWrapper.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetWrapper.java
@@ -1153,11 +1153,11 @@ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
}
public T getObject(int columnIndex, Class type) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
public T getObject(String columnLabel, Class type) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java
index c21a058ba2bd..dd0d0d5b7b27 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java
@@ -14,12 +14,11 @@
*****************************************************************************/
package com.taosdata.jdbc;
-import javax.management.OperationsException;
import java.sql.SQLException;
public class TSDBSubscribe {
- private TSDBJNIConnector connecter = null;
- private long id = 0;
+ private final TSDBJNIConnector connecter;
+ private final long id;
TSDBSubscribe(TSDBJNIConnector connecter, long id) throws SQLException {
if (null != connecter) {
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
index b7a0df7de75c..9d394b8b0389 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
@@ -18,10 +18,10 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
private final String database;
private final Statement statement;
// data
- private ArrayList> resultSet = new ArrayList<>();
+ private ArrayList> resultSet;
// meta
- private ArrayList columnNames = new ArrayList<>();
- private ArrayList columns = new ArrayList<>();
+ private ArrayList columnNames;
+ private ArrayList columns;
private RestfulResultSetMetaData metaData;
/**
@@ -29,11 +29,36 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
*
* @param resultJson: 包含data信息的结果集,有sql返回的结果集
***/
- public RestfulResultSet(String database, Statement statement, JSONObject resultJson) {
+ public RestfulResultSet(String database, Statement statement, JSONObject resultJson) throws SQLException {
this.database = database;
this.statement = statement;
+ // column metadata
+ JSONArray columnMeta = resultJson.getJSONArray("column_meta");
+ columnNames = new ArrayList<>();
+ columns = new ArrayList<>();
+ for (int colIndex = 0; colIndex < columnMeta.size(); colIndex++) {
+ JSONArray col = columnMeta.getJSONArray(colIndex);
+ String col_name = col.getString(0);
+ int col_type = TSDBConstants.taosType2JdbcType(col.getInteger(1));
+ int col_length = col.getInteger(2);
+ columnNames.add(col_name);
+ columns.add(new Field(col_name, col_type, col_length, ""));
+ }
+ this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
+
// row data
JSONArray data = resultJson.getJSONArray("data");
+ resultSet = new ArrayList<>();
+ for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) {
+ ArrayList row = new ArrayList();
+ JSONArray jsonRow = data.getJSONArray(rowIndex);
+ for (int colIndex = 0; colIndex < jsonRow.size(); colIndex++) {
+ row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).type));
+ }
+ resultSet.add(row);
+ }
+
+ /*
int columnIndex = 0;
for (; columnIndex < data.size(); columnIndex++) {
ArrayList oneRow = new ArrayList<>();
@@ -52,50 +77,77 @@ public RestfulResultSet(String database, Statement statement, JSONObject resultJ
columns.add(new Field(name, "", 0, ""));
}
this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
- }
-
- /**
- * 由多个resultSet的JSON构造结果集
- *
- * @param resultJson: 包含data信息的结果集,有sql返回的结果集
- * @param fieldJson: 包含多个(最多2个)meta信息的结果集,有describe xxx
- **/
- public RestfulResultSet(String database, Statement statement, JSONObject resultJson, List fieldJson) {
- this(database, statement, resultJson);
- ArrayList newColumns = new ArrayList<>();
-
- for (Field column : columns) {
- Field field = findField(column.name, fieldJson);
- if (field != null) {
- newColumns.add(field);
- } else {
- newColumns.add(column);
- }
- }
- this.columns = newColumns;
- this.metaData = new RestfulResultSetMetaData(this.database, this.columns, this);
- }
-
- public Field findField(String columnName, List fieldJsonList) {
- for (JSONObject fieldJSON : fieldJsonList) {
- JSONArray fieldDataJson = fieldJSON.getJSONArray("data");
- for (int i = 0; i < fieldDataJson.size(); i++) {
- JSONArray field = fieldDataJson.getJSONArray(i);
- if (columnName.equalsIgnoreCase(field.getString(0))) {
- return new Field(field.getString(0), field.getString(1), field.getInteger(2), field.getString(3));
- }
- }
+ */
+ }
+
+ private Object parseColumnData(JSONArray row, int colIndex, int sqlType) {
+ switch (sqlType) {
+ case Types.NULL:
+ return null;
+ case Types.BOOLEAN:
+ return row.getBoolean(colIndex);
+ case Types.TINYINT:
+ case Types.SMALLINT:
+ return row.getShort(colIndex);
+ case Types.INTEGER:
+ return row.getInteger(colIndex);
+ case Types.BIGINT:
+ return row.getBigInteger(colIndex);
+ case Types.FLOAT:
+ return row.getFloat(colIndex);
+ case Types.DOUBLE:
+ return row.getDouble(colIndex);
+ case Types.TIMESTAMP:
+ return new Timestamp(row.getDate(colIndex).getTime());
+ case Types.BINARY:
+ case Types.NCHAR:
+ default:
+ return row.getString(colIndex);
}
- return null;
}
+// /**
+// * 由多个resultSet的JSON构造结果集
+// *
+// * @param resultJson: 包含data信息的结果集,有sql返回的结果集
+// * @param fieldJson: 包含多个(最多2个)meta信息的结果集,有describe xxx
+// **/
+// public RestfulResultSet(String database, Statement statement, JSONObject resultJson, List fieldJson) throws SQLException {
+// this(database, statement, resultJson);
+// ArrayList newColumns = new ArrayList<>();
+//
+// for (Field column : columns) {
+// Field field = findField(column.name, fieldJson);
+// if (field != null) {
+// newColumns.add(field);
+// } else {
+// newColumns.add(column);
+// }
+// }
+// this.columns = newColumns;
+// this.metaData = new RestfulResultSetMetaData(this.database, this.columns, this);
+// }
+
+// public Field findField(String columnName, List fieldJsonList) {
+// for (JSONObject fieldJSON : fieldJsonList) {
+// JSONArray fieldDataJson = fieldJSON.getJSONArray("data");
+// for (int i = 0; i < fieldDataJson.size(); i++) {
+// JSONArray field = fieldDataJson.getJSONArray(i);
+// if (columnName.equalsIgnoreCase(field.getString(0))) {
+// return new Field(field.getString(0), field.getString(1), field.getInteger(2), field.getString(3));
+// }
+// }
+// }
+// return null;
+// }
+
public class Field {
String name;
- String type;
+ int type;
int length;
String note;
- public Field(String name, String type, int length, String note) {
+ public Field(String name, int type, int length, String note) {
this.name = name;
this.type = type;
this.length = length;
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java
index 44a02f486b22..29ba13bec107 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java
@@ -5,6 +5,7 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
+import java.sql.Types;
import java.util.ArrayList;
public class RestfulResultSetMetaData implements ResultSetMetaData {
@@ -53,14 +54,14 @@ public int isNullable(int column) throws SQLException {
@Override
public boolean isSigned(int column) throws SQLException {
- String type = this.fields.get(column - 1).type.toUpperCase();
+ int type = this.fields.get(column - 1).type;
switch (type) {
- case "TINYINT":
- case "SMALLINT":
- case "INT":
- case "BIGINT":
- case "FLOAT":
- case "DOUBLE":
+ case Types.TINYINT:
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.BIGINT:
+ case Types.FLOAT:
+ case Types.DOUBLE:
return true;
default:
return false;
@@ -89,14 +90,14 @@ public String getSchemaName(int column) throws SQLException {
@Override
public int getPrecision(int column) throws SQLException {
- String type = this.fields.get(column - 1).type.toUpperCase();
+ int type = this.fields.get(column - 1).type;
switch (type) {
- case "FLOAT":
+ case Types.FLOAT:
return 5;
- case "DOUBLE":
+ case Types.DOUBLE:
return 9;
- case "BINARY":
- case "NCHAR":
+ case Types.BINARY:
+ case Types.NCHAR:
return this.fields.get(column - 1).length;
default:
return 0;
@@ -105,11 +106,11 @@ public int getPrecision(int column) throws SQLException {
@Override
public int getScale(int column) throws SQLException {
- String type = this.fields.get(column - 1).type.toUpperCase();
+ int type = this.fields.get(column - 1).type;
switch (type) {
- case "FLOAT":
+ case Types.FLOAT:
return 5;
- case "DOUBLE":
+ case Types.DOUBLE:
return 9;
default:
return 0;
@@ -128,36 +129,13 @@ public String getCatalogName(int column) throws SQLException {
@Override
public int getColumnType(int column) throws SQLException {
- String type = this.fields.get(column - 1).type.toUpperCase();
- switch (type) {
- case "BOOL":
- return java.sql.Types.BOOLEAN;
- case "TINYINT":
- return java.sql.Types.TINYINT;
- case "SMALLINT":
- return java.sql.Types.SMALLINT;
- case "INT":
- return java.sql.Types.INTEGER;
- case "BIGINT":
- return java.sql.Types.BIGINT;
- case "FLOAT":
- return java.sql.Types.FLOAT;
- case "DOUBLE":
- return java.sql.Types.DOUBLE;
- case "BINARY":
- return java.sql.Types.BINARY;
- case "TIMESTAMP":
- return java.sql.Types.TIMESTAMP;
- case "NCHAR":
- return java.sql.Types.NCHAR;
- }
- throw new SQLException(TSDBConstants.INVALID_VARIABLES);
+ return this.fields.get(column - 1).type;
}
@Override
public String getColumnTypeName(int column) throws SQLException {
- String type = fields.get(column - 1).type;
- return type.toUpperCase();
+ int type = fields.get(column - 1).type;
+ return TSDBConstants.jdbcType2TaosTypeName(type);
}
@Override
@@ -177,26 +155,26 @@ public boolean isDefinitelyWritable(int column) throws SQLException {
@Override
public String getColumnClassName(int column) throws SQLException {
- String type = this.fields.get(column - 1).type;
+ int type = this.fields.get(column - 1).type;
String columnClassName = "";
switch (type) {
- case "BOOL":
+ case Types.BOOLEAN:
return Boolean.class.getName();
- case "TINYINT":
- case "SMALLINT":
+ case Types.TINYINT:
+ case Types.SMALLINT:
return Short.class.getName();
- case "INT":
+ case Types.INTEGER:
return Integer.class.getName();
- case "BIGINT":
+ case Types.BIGINT:
return Long.class.getName();
- case "FLOAT":
+ case Types.FLOAT:
return Float.class.getName();
- case "DOUBLE":
+ case Types.DOUBLE:
return Double.class.getName();
- case "TIMESTAMP":
+ case Types.TIMESTAMP:
return Timestamp.class.getName();
- case "BINARY":
- case "NCHAR":
+ case Types.BINARY:
+ case Types.NCHAR:
return String.class.getName();
}
return columnClassName;
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
index 8d67586be257..d60940d87762 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
@@ -151,22 +151,21 @@ private ResultSet executeOneQuery(String url, String sql) throws SQLException {
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code")));
}
// parse table name from sql
- String[] tableIdentifiers = parseTableIdentifier(sql);
- if (tableIdentifiers != null) {
- List fieldJsonList = new ArrayList<>();
- for (String tableIdentifier : tableIdentifiers) {
- // field meta
- String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier);
- JSONObject fieldJson = JSON.parseObject(fields);
- if (fieldJson.getString("status").equals("error")) {
- throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code")));
- }
- fieldJsonList.add(fieldJson);
- }
- this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJsonList);
- } else {
- this.resultSet = new RestfulResultSet(database, this, resultJson);
- }
+// String[] tableIdentifiers = parseTableIdentifier(sql);
+// if (tableIdentifiers != null) {
+// List fieldJsonList = new ArrayList<>();
+// for (String tableIdentifier : tableIdentifiers) {
+// String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier);
+// JSONObject fieldJson = JSON.parseObject(fields);
+// if (fieldJson.getString("status").equals("error")) {
+// throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code")));
+// }
+// fieldJsonList.add(fieldJson);
+// }
+// this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJsonList);
+// } else {
+ this.resultSet = new RestfulResultSet(database, this, resultJson);
+// }
this.affectedRows = 0;
return resultSet;
}
@@ -201,7 +200,7 @@ private int checkJsonResultSet(JSONObject jsonObject) {
@Override
public ResultSet getResultSet() throws SQLException {
if (isClosed())
- throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return resultSet;
}
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
index fb0053cb4b1b..87348f902611 100644
--- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
@@ -13,7 +13,6 @@
import java.util.Properties;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
public class ResultSetTest {
static Connection connection;
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
index 685957d60af6..11c3de305280 100644
--- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
@@ -48,29 +48,28 @@ public void createDatabase() {
@Test
public void subscribe() {
try {
-
String rawSql = "select * from " + dbName + "." + tName + ";";
System.out.println(rawSql);
- TSDBSubscribe subscribe = ((TSDBConnection) connection).subscribe(topic, rawSql, false);
+// TSDBSubscribe subscribe = ((TSDBConnection) connection).subscribe(topic, rawSql, false);
- int a = 0;
- while (true) {
- TimeUnit.MILLISECONDS.sleep(1000);
- TSDBResultSet resSet = subscribe.consume();
- while (resSet.next()) {
- for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
- System.out.printf(i + ": " + resSet.getString(i) + "\t");
- }
- System.out.println("\n======" + a + "==========");
- }
- a++;
- if (a >= 2) {
- break;
- }
+// int a = 0;
+// while (true) {
+// TimeUnit.MILLISECONDS.sleep(1000);
+// TSDBResultSet resSet = subscribe.consume();
+// while (resSet.next()) {
+// for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
+// System.out.printf(i + ": " + resSet.getString(i) + "\t");
+// }
+// System.out.println("\n======" + a + "==========");
+// }
+// a++;
+// if (a >= 2) {
+// break;
+// }
// resSet.close();
- }
-
- subscribe.close(true);
+// }
+//
+// subscribe.close(true);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java
index 185c0306f525..451f5d49160a 100644
--- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java
@@ -10,7 +10,7 @@
public class RestfulJDBCTest {
private static final String host = "127.0.0.1";
- // private static final String host = "master";
+// private static final String host = "master";
private static Connection connection;
private Random random = new Random(System.currentTimeMillis());
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java
index 313abfd27865..fe4d04775da6 100644
--- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java
@@ -12,7 +12,7 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SQLTest {
private static final String host = "127.0.0.1";
- // private static final String host = "master";
+// private static final String host = "master";
private static Connection connection;
@Test
@@ -323,6 +323,18 @@ public void testCase051() {
SQLExecutor.executeQuery(connection, sql);
}
+ @Test
+ public void testCase052() {
+ String sql = "select server_status()";
+ SQLExecutor.executeQuery(connection, sql);
+ }
+
+ @Test
+ public void testCase053() {
+ String sql = "select avg(cpu_taosd), avg(cpu_system), max(cpu_cores), avg(mem_taosd), avg(mem_system), max(mem_total), avg(disk_used), max(disk_total), avg(band_speed), avg(io_read), avg(io_write), sum(req_http), sum(req_select), sum(req_insert) from log.dn1 where ts> now - 60m and ts<= now interval(1m) fill(value, 0)";
+ SQLExecutor.executeQuery(connection, sql);
+ }
+
@BeforeClass
public static void before() throws ClassNotFoundException, SQLException {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c
index 6d34c9fb1531..cae227cbdb73 100644
--- a/src/rpc/src/rpcMain.c
+++ b/src/rpc/src/rpcMain.c
@@ -1281,7 +1281,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) {
SRpcConn *pConn = rpcSetupConnToServer(pContext);
if (pConn == NULL) {
pContext->code = terrno;
- taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl);
+ taosTmrStart(rpcProcessConnError, 1, pContext, pRpc->tmrCtrl);
return;
}
diff --git a/tests/examples/JDBC/springbootdemo/pom.xml b/tests/examples/JDBC/springbootdemo/pom.xml
index 52fb8caa90b1..bd5f7efbc032 100644
--- a/tests/examples/JDBC/springbootdemo/pom.xml
+++ b/tests/examples/JDBC/springbootdemo/pom.xml
@@ -63,7 +63,9 @@
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.18
+ 2.0.20
+
+
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java
index 8066126d62b1..8f30c299466c 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java
@@ -10,4 +10,4 @@ public class SpringbootdemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemoApplication.class, args);
}
-}
+}
\ No newline at end of file
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java
index 4a4109dcf326..c153e2770140 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java
@@ -6,6 +6,7 @@
import org.springframework.web.bind.annotation.*;
import java.util.List;
+import java.util.Map;
@RequestMapping("/weather")
@RestController
@@ -20,7 +21,7 @@ public class WeatherController {
* @return
*/
@GetMapping("/init")
- public boolean init() {
+ public int init() {
return weatherService.init();
}
@@ -44,19 +45,23 @@ public List queryWeather(@PathVariable Long limit, @PathVariable Long o
* @return
*/
@PostMapping("/{temperature}/{humidity}")
- public int saveWeather(@PathVariable int temperature, @PathVariable float humidity) {
+ public int saveWeather(@PathVariable float temperature, @PathVariable int humidity) {
return weatherService.save(temperature, humidity);
}
- /**
- * upload multi weather info
- *
- * @param weatherList
- * @return
- */
- @PostMapping("/batch")
- public int batchSaveWeather(@RequestBody List weatherList) {
- return weatherService.save(weatherList);
+ @GetMapping("/count")
+ public int count() {
+ return weatherService.count();
+ }
+
+ @GetMapping("/subTables")
+ public List getSubTables() {
+ return weatherService.getSubTables();
+ }
+
+ @GetMapping("/avg")
+ public List avg() {
+ return weatherService.avg();
}
}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java
index cae1a1aec032..ad6733558a9d 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java
@@ -4,16 +4,26 @@
import org.apache.ibatis.annotations.Param;
import java.util.List;
+import java.util.Map;
public interface WeatherMapper {
+ void dropDB();
+
+ void createDB();
+
+ void createSuperTable();
+
+ void createTable(Weather weather);
+
+ List select(@Param("limit") Long limit, @Param("offset") Long offset);
+
int insert(Weather weather);
- int batchInsert(List weatherList);
+ int count();
- List select(@Param("limit") Long limit, @Param("offset")Long offset);
+ List getSubTables();
- void createDB();
+ List avg();
- void createTable();
}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml
index a9bcda0b00ca..2d3e0540650f 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml
@@ -4,28 +4,29 @@
-
-
-
+
+
+
-
- create database if not exists test;
+
+ drop database if exists test
+
+
+
+ create database if not exists test
-
- create table if not exists test.weather(ts timestamp, temperature int, humidity float);
+
+ create table if not exists test.weather(ts timestamp, temperature float, humidity float) tags(location nchar(64), groupId int)
-
- ts, temperature, humidity
-
+
+ create table if not exists test.t#{groupId} using test.weather tags(#{location}, #{groupId})
+
-
- insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
+
+ insert into test.t#{groupId} (ts, temperature, humidity) values (#{ts}, ${temperature}, ${humidity})
-
- insert into test.weather (ts, temperature, humidity) values
-
- (now + #{index}a, #{weather.temperature}, #{weather.humidity})
-
-
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java
index 60565448ad7d..255b2cdca920 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java
@@ -6,12 +6,21 @@
public class Weather {
- @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS",timezone = "GMT+8")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
private Timestamp ts;
+ private float temperature;
+ private float humidity;
+ private String location;
+ private int groupId;
- private int temperature;
+ public Weather() {
+ }
- private float humidity;
+ public Weather(Timestamp ts, float temperature, float humidity) {
+ this.ts = ts;
+ this.temperature = temperature;
+ this.humidity = humidity;
+ }
public Timestamp getTs() {
return ts;
@@ -21,11 +30,11 @@ public void setTs(Timestamp ts) {
this.ts = ts;
}
- public int getTemperature() {
+ public float getTemperature() {
return temperature;
}
- public void setTemperature(int temperature) {
+ public void setTemperature(float temperature) {
this.temperature = temperature;
}
@@ -36,4 +45,20 @@ public float getHumidity() {
public void setHumidity(float humidity) {
this.humidity = humidity;
}
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public int getGroupId() {
+ return groupId;
+ }
+
+ public void setGroupId(int groupId) {
+ this.groupId = groupId;
+ }
}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java
index 31ce8f1dd96b..0aef828e1cf1 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java
@@ -5,25 +5,41 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.sql.Timestamp;
import java.util.List;
+import java.util.Map;
+import java.util.Random;
@Service
public class WeatherService {
@Autowired
private WeatherMapper weatherMapper;
+ private Random random = new Random(System.currentTimeMillis());
+ private String[] locations = {"北京", "上海", "广州", "深圳", "天津"};
- public boolean init() {
+ public int init() {
+ weatherMapper.dropDB();
weatherMapper.createDB();
- weatherMapper.createTable();
- return true;
+ weatherMapper.createSuperTable();
+ long ts = System.currentTimeMillis();
+ long thirtySec = 1000 * 30;
+ int count = 0;
+ for (int i = 0; i < 20; i++) {
+ Weather weather = new Weather(new Timestamp(ts + (thirtySec * i)), 30 * random.nextFloat(), random.nextInt(100));
+ weather.setLocation(locations[random.nextInt(locations.length)]);
+ weather.setGroupId(i % locations.length);
+ weatherMapper.createTable(weather);
+ count += weatherMapper.insert(weather);
+ }
+ return count;
}
public List query(Long limit, Long offset) {
return weatherMapper.select(limit, offset);
}
- public int save(int temperature, float humidity) {
+ public int save(float temperature, int humidity) {
Weather weather = new Weather();
weather.setTemperature(temperature);
weather.setHumidity(humidity);
@@ -31,8 +47,15 @@ public int save(int temperature, float humidity) {
return weatherMapper.insert(weather);
}
- public int save(List weatherList) {
- return weatherMapper.batchInsert(weatherList);
+ public int count() {
+ return weatherMapper.count();
}
+ public List getSubTables() {
+ return weatherMapper.getSubTables();
+ }
+
+ public List avg() {
+ return weatherMapper.avg();
+ }
}
diff --git a/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties b/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties
index 4fb68758c454..4d7e64d10576 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties
+++ b/tests/examples/JDBC/springbootdemo/src/main/resources/application.properties
@@ -1,12 +1,14 @@
# datasource config - JDBC-JNI
-spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
-spring.datasource.url=jdbc:TAOS://127.0.0.1:6030/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
-spring.datasource.username=root
-spring.datasource.password=taosdata
+#spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
+#spring.datasource.url=jdbc:TAOS://127.0.0.1:6030/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
+#spring.datasource.username=root
+#spring.datasource.password=taosdata
# datasource config - JDBC-RESTful
-#spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
-#spring.datasource.url=jdbc:TAOS-RS://master:6041/test?user=root&password=taosdata
+spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
+spring.datasource.url=jdbc:TAOS-RS://master:6041/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
+spring.datasource.username=root
+spring.datasource.password=taosdata
spring.datasource.druid.initial-size=5
spring.datasource.druid.min-idle=5
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
index 19f47e13d611..c361df82b0ae 100644
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
@@ -4,7 +4,7 @@
import com.taosdata.taosdemo.components.JdbcTaosdemoConfig;
import com.taosdata.taosdemo.domain.SuperTableMeta;
import com.taosdata.taosdemo.service.DatabaseService;
-import com.taosdata.taosdemo.service.QueryService;
+import com.taosdata.taosdemo.service.SqlExecuteTask;
import com.taosdata.taosdemo.service.SubTableService;
import com.taosdata.taosdemo.service.SuperTableService;
import com.taosdata.taosdemo.service.data.SuperTableMetaGenerator;
@@ -32,6 +32,17 @@ public static void main(String[] args) throws IOException {
}
// 初始化
final DataSource dataSource = DataSourceFactory.getInstance(config.host, config.port, config.user, config.password);
+ if (config.executeSql != null && !config.executeSql.isEmpty() && !config.executeSql.replaceAll("\\s", "").isEmpty()) {
+ Thread task = new Thread(new SqlExecuteTask(dataSource, config.executeSql));
+ task.start();
+ try {
+ task.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return;
+ }
+
final DatabaseService databaseService = new DatabaseService(dataSource);
final SuperTableService superTableService = new SuperTableService(dataSource);
final SubTableService subTableService = new SubTableService(dataSource);
@@ -96,7 +107,6 @@ public static void main(String[] args) throws IOException {
// 查询
-
/**********************************************************************************/
// 删除表
if (config.dropTable) {
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
index 971c10dee288..974a2755a5a0 100644
--- a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
@@ -42,7 +42,7 @@ public final class JdbcTaosdemoConfig {
public int rate = 10;
public long range = 1000l;
// select task
-
+ public String executeSql;
// drop task
public boolean dropTable = false;
@@ -89,7 +89,7 @@ public static void printHelp() {
System.out.println("-rate The proportion of data out of order. effective only if order is 1. min 0, max 100, default is 10");
System.out.println("-range The range of data out of order. effective only if order is 1. default is 1000 ms");
// query task
-// System.out.println("-sqlFile The select sql file");
+ System.out.println("-executeSql execute a specific sql.");
// drop task
System.out.println("-dropTable Drop data before quit. Default is false");
System.out.println("--help Give this help list");
@@ -207,6 +207,9 @@ public JdbcTaosdemoConfig(String[] args) {
range = Integer.parseInt(args[++i]);
}
// select task
+ if ("-executeSql".equals(args[i]) && i < args.length - 1) {
+ executeSql = args[++i];
+ }
// drop task
if ("-dropTable".equals(args[i]) && i < args.length - 1) {
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SqlExecuteTask.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SqlExecuteTask.java
new file mode 100644
index 000000000000..ff2e4d0af068
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SqlExecuteTask.java
@@ -0,0 +1,36 @@
+package com.taosdata.taosdemo.service;
+
+import com.taosdata.taosdemo.utils.Printer;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class SqlExecuteTask implements Runnable {
+ private final DataSource dataSource;
+ private final String sql;
+
+ public SqlExecuteTask(DataSource dataSource, String sql) {
+ this.dataSource = dataSource;
+ this.sql = sql;
+ }
+
+ @Override
+ public void run() {
+ try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {
+ long start = System.currentTimeMillis();
+ boolean execute = stmt.execute(sql);
+ long end = System.currentTimeMillis();
+ if (execute) {
+ ResultSet rs = stmt.getResultSet();
+ Printer.printResult(rs);
+ } else {
+ Printer.printSql(sql, true, (end - start));
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/utils/Printer.java b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/utils/Printer.java
new file mode 100644
index 000000000000..a4627463ec5c
--- /dev/null
+++ b/tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/utils/Printer.java
@@ -0,0 +1,27 @@
+package com.taosdata.taosdemo.utils;
+
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+public class Printer {
+
+ public static void printResult(ResultSet resultSet) throws SQLException {
+ ResultSetMetaData metaData = resultSet.getMetaData();
+ while (resultSet.next()) {
+ for (int i = 1; i <= metaData.getColumnCount(); i++) {
+ String columnLabel = metaData.getColumnLabel(i);
+ String value = resultSet.getString(i);
+ System.out.printf("%s: %s\t", columnLabel, value);
+ }
+ System.out.println();
+ }
+ }
+
+ public static void printSql(String sql, boolean succeed, long cost) {
+ System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
+ }
+
+ private Printer() {
+ }
+}
diff --git a/tests/pytest/functions/function_operations.py b/tests/pytest/functions/function_operations.py
index 8bbe6dc9a34b..e703147b6722 100644
--- a/tests/pytest/functions/function_operations.py
+++ b/tests/pytest/functions/function_operations.py
@@ -69,15 +69,37 @@ def run(self):
tdSql.checkData(10, 0, None)
# test for tarithoperator.c coverage
- col_list = [ 'col1' , 'col2' , 'col3' , 'col4' , 'col5' , 'col6' , 'col11' , 'col12' , 'col13' , 'col14' , '1' ]
+ tdSql.execute("insert into test1 values(1537146000010,1,NULL,9,8,1.2,1.3,0,1,1,5,4,3,2)")
+ tdSql.execute("insert into test1 values(1537146000011,2,1,NULL,9,1.2,1.3,1,2,2,6,5,4,3)")
+ tdSql.execute("insert into test1 values(1537146000012,3,2,1,NULL,1.2,1.3,0,3,3,7,6,5,4)")
+ tdSql.execute("insert into test1 values(1537146000013,4,3,2,1,1.2,1.3,1,4,4,8,7,6,5)")
+ tdSql.execute("insert into test1 values(1537146000014,5,4,3,2,1.2,1.3,0,5,5,9,8,7,6)")
+ tdSql.execute("insert into test1 values(1537146000015,6,5,4,3,1.2,1.3,1,6,6,NULL,9,8,7)")
+ tdSql.execute("insert into test1 values(1537146000016,7,6,5,4,1.2,1.3,0,7,7,1,NULL,9,8)")
+ tdSql.execute("insert into test1 values(1537146000017,8,7,6,5,1.2,1.3,1,8,8,2,1,NULL,9)")
+ tdSql.execute("insert into test1 values(1537146000018,9,8,7,6,1.2,1.3,0,9,9,3,2,1,NULL)")
+ tdSql.execute("insert into test1 values(1537146000019,NULL,9,8,7,1.2,1.3,1,10,10,4,3,2,1)")
+
+ self.ts = self.ts + self.rowNum + 10
+
+ tdSql.execute("insert into test1 values(%d, 1, 1, 1, 1, 1.1, 1.1, 1, NULL, '涛思数据3', 1, 1, 1, 1)" % ( self.ts + self.rowNum + 1 ))
+ tdSql.execute("insert into test1 values(%d, 1, 1, 1, 1, 1.1, 1.1, 1, 'taosdata', NULL, 1, 1, 1, 1)" % ( self.ts + self.rowNum + 2 ))
+ tdSql.execute("insert into test1 values(%d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)" % ( self.ts + self.rowNum + 3 ))
+ tdSql.execute("insert into test1 values(%d, 1, 1, 1, 1, NULL, 1.1, 1, NULL, '涛思数据3', 1, 1, 1, 1)" % ( self.ts + self.rowNum + 4 ))
+ tdSql.execute("insert into test1 values(%d, 1, 1, 1, 1, 1.1, NULL, 1, 'taosdata', NULL, 1, 1, 1, 1)" % ( self.ts + self.rowNum + 5 ))
+ self.rowNum = self.rowNum + 5
+
+ col_list = [ 'col1' , 'col2' , 'col3' , 'col4' , 'col5' , 'col6' , 'col7' , 'col8' , 'col9' , 'col11' , 'col12' , 'col13' , 'col14' , '1' , '1.1' , 'NULL' ]
op_list = [ '+' , '-' , '*' , '/' , '%' ]
+ err_list = [ 'col7' , 'col8' , 'col9' , 'NULL' ]
for i in col_list :
for j in col_list :
for k in op_list :
sql = " select %s %s %s from test1 " % ( i , k , j )
- print(sql)
- tdSql.query(sql)
-
+ if i in err_list or j in err_list:
+ tdSql.error(sql)
+ else:
+ tdSql.query(sql)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
diff --git a/tests/pytest/functions/function_operations_restart.py b/tests/pytest/functions/function_operations_restart.py
index e0e9d36e466c..3ba787a4a0f3 100644
--- a/tests/pytest/functions/function_operations_restart.py
+++ b/tests/pytest/functions/function_operations_restart.py
@@ -41,24 +41,24 @@ def run(self):
tdSql.error("select col1 + col9 from test1")
tdSql.query("select col1 + col2 from test1")
- tdSql.checkRows(11)
+ tdSql.checkRows(25)
tdSql.checkData(0, 0, 2.0)
tdSql.query("select col1 + col2 * col3 + col3 / col4 + col5 + col6 + col11 + col12 + col13 + col14 from test1")
- tdSql.checkRows(11)
+ tdSql.checkRows(25)
tdSql.checkData(0, 0, 7.2)
#tdSql.execute("insert into test1(ts, col1) values(%d, 11)" % (self.ts + 11))
tdSql.query("select col1 + col2 from test1")
- tdSql.checkRows(11)
+ tdSql.checkRows(25)
tdSql.checkData(10, 0, None)
tdSql.query("select col1 + col2 * col3 from test1")
- tdSql.checkRows(11)
+ tdSql.checkRows(25)
tdSql.checkData(10, 0, None)
tdSql.query("select col1 + col2 * col3 + col3 / col4 + col5 + col6 + col11 + col12 + col13 + col14 from test1")
- tdSql.checkRows(11)
+ tdSql.checkRows(25)
tdSql.checkData(10, 0, None)
diff --git a/tests/pytest/insert/metadataUpdate.py b/tests/pytest/insert/metadataUpdate.py
index 77795d13f139..76b9a3ae8f81 100644
--- a/tests/pytest/insert/metadataUpdate.py
+++ b/tests/pytest/insert/metadataUpdate.py
@@ -52,13 +52,12 @@ def run(self):
p.start()
p.join()
p.terminate()
-
- tdSql.execute("insert into tb values(%d, 1, 2)" % (self.ts + 1))
+
tdSql.execute("insert into tb(ts, col1, col2) values(%d, 1, 2)" % (self.ts + 2))
print("==============step2")
tdSql.query("select * from tb")
- tdSql.checkRows(3)
+ tdSql.checkRows(2)
def stop(self):
tdSql.close()
diff --git a/tests/pytest/tools/taosdemoTest.py b/tests/pytest/tools/taosdemoTest.py
index 1cb2f71d8fc9..c450570d2446 100644
--- a/tests/pytest/tools/taosdemoTest.py
+++ b/tests/pytest/tools/taosdemoTest.py
@@ -24,7 +24,7 @@ def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
- self.numberOfTables = 10000
+ self.numberOfTables = 1000
self.numberOfRecords = 100
def getBuildPath(self):