From 2464d892ad2396fde1e2ee1a072eba4d5814729c Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 10 Jun 2021 11:07:33 +0800 Subject: [PATCH 01/52] fix bug --- src/client/src/tscSub.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index a6d09b5d8d..e4f67ba0de 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -282,6 +282,7 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) { SArray* tables = getTableList(pSql); if (tables == NULL) { + pSub->lastSyncTime = 0; //force to get table list next time return 0; } size_t numOfTables = taosArrayGetSize(tables); @@ -488,7 +489,15 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) { SSub *pSub = (SSub *)tsub; if (pSub == NULL) return NULL; - if (pSub->pSql->cmd.command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) { + if (pSub->pTimer == NULL) { + int64_t duration = taosGetTimestampMs() - pSub->lastConsumeTime; + if (duration < (int64_t)(pSub->interval)) { + tscDebug("subscription consume too frequently, blocking..."); + taosMsleep(pSub->interval - (int32_t)duration); + } + } + + if (pSub->pSql->cmd.command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) { //may reach here when retireve stable vgroup failed SSqlObj* pSql = recreateSqlObj(pSub); if (pSql == NULL) { return NULL; @@ -500,6 +509,11 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) { } pSub->pSql = pSql; pSql->pSubscription = pSub; + + // no table list now, force to update it + tscDebug("begin table synchronization"); + if (!tscUpdateSubscription(pSub->taos, pSub)) return NULL; + tscDebug("table synchronization completed"); } tscSaveSubscriptionProgress(pSub); @@ -524,14 +538,6 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) { tscDebug("subscribe:%s set next round subscribe skey:%"PRId64, pSub->topic, pQueryInfo->window.skey); } - if (pSub->pTimer == NULL) { - int64_t duration = taosGetTimestampMs() - pSub->lastConsumeTime; - if (duration < (int64_t)(pSub->interval)) { - tscDebug("subscription consume too frequently, blocking..."); - taosMsleep(pSub->interval - (int32_t)duration); - } - } - size_t size = taosArrayGetSize(pSub->progress) * sizeof(STableIdInfo); size += sizeof(SQueryTableMsg) + 4096; int code = tscAllocPayload(&pSql->cmd, (int)size); From 397d268eac666ff1fe2b4f7bb767879bec24bfee Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 11 Jun 2021 14:11:41 +0800 Subject: [PATCH 02/52] [td-225]refactor --- src/client/inc/tscUtil.h | 1 - src/client/src/tscSQLParser.c | 3 +-- src/client/src/tscUtil.c | 22 ++-------------------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 2c4d711520..a9ac788bc3 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -123,7 +123,6 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i */ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo); bool tscIsTWAQuery(SQueryInfo* pQueryInfo); -bool tscIsDiffQuery(SQueryInfo* pQueryInfo); bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo); bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo); bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 1503638a03..d91301adfe 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3072,7 +3072,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) } } - if (tscIsTWAQuery(pQueryInfo) || tscIsDiffQuery(pQueryInfo)) { + if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivQuery(pQueryInfo)) { if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return true; @@ -7989,7 +7989,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo); pQueryInfo->orderProjectQuery = tscOrderedProjectionQueryOnSTable(pQueryInfo, 0); -// pQueryInfo->diffQuery = tscIsDiffQuery(pQueryInfo); SExprInfo** p = NULL; int32_t numOfExpr = 0; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index e3dba3fcbc..9011bae47b 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -460,24 +460,6 @@ bool tscIsTWAQuery(SQueryInfo* pQueryInfo) { return false; } -bool tscIsDiffQuery(SQueryInfo* pQueryInfo) { - size_t num = tscNumOfExprs(pQueryInfo); - for(int32_t i = 0; i < num; ++i) { - SExprInfo* pExpr = tscExprGet(pQueryInfo, i); - - int32_t f = pExpr->base.functionId; - if (pExpr == NULL || f == TSDB_FUNC_TS_DUMMY) { - continue; - } - - if (f == TSDB_FUNC_DIFF || f == TSDB_FUNC_DERIVATIVE) { - return true; - } - } - - return false; -} - bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo) { return pQueryInfo->sessionWindow.gap > 0; } @@ -516,7 +498,7 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) { return false; } - if (tscIsDiffQuery(pQueryInfo)) { + if (tscIsDiffDerivQuery(pQueryInfo)) { return false; } @@ -4260,7 +4242,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->hasTagResults = hasTagValOutput(pQueryInfo); pQueryAttr->stabledev = isStabledev(pQueryInfo); pQueryAttr->tsCompQuery = isTsCompQuery(pQueryInfo); - pQueryAttr->diffQuery = tscIsDiffQuery(pQueryInfo); + pQueryAttr->diffQuery = tscIsDiffDerivQuery(pQueryInfo); pQueryAttr->simpleAgg = isSimpleAggregateRv(pQueryInfo); pQueryAttr->needReverseScan = tscNeedReverseScan(pQueryInfo); pQueryAttr->stableQuery = QUERY_IS_STABLE_QUERY(pQueryInfo->type); From d198dcbb88e2ff8a813270830e0869dcdde1e25d Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Fri, 11 Jun 2021 16:11:06 +0800 Subject: [PATCH 03/52] add null pointer check --- src/client/src/tscPrepare.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 73e39b471b..38991e9f39 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -879,6 +879,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { return TSDB_CODE_TSC_DISCONNECTED; } + if (sql == NULL) { + tscError("sql is NULL"); + return TSDB_CODE_TSC_APP_ERROR; + } + SSqlObj* pSql = pStmt->pSql; size_t sqlLen = strlen(sql); From 1e92fa7def536c3716d8f9ab0ec2cb5ad0f8b7f0 Mon Sep 17 00:00:00 2001 From: zyyang Date: Fri, 11 Jun 2021 17:44:58 +0800 Subject: [PATCH 04/52] sync from develop to master --- cmake/install.inc | 2 +- src/connector/jdbc/CMakeLists.txt | 6 +- src/connector/jdbc/deploy-pom.xml | 2 +- src/connector/jdbc/pom.xml | 3 +- .../taosdata/jdbc/rs/RestfulConnection.java | 9 ++- .../com/taosdata/jdbc/rs/RestfulDriver.java | 12 ++-- .../taosdata/jdbc/rs/RestfulStatement.java | 6 +- .../jdbc/utils/HttpClientPoolUtil.java | 44 ++++++-------- .../taosdata/jdbc/cases/BatchInsertTest.java | 4 +- ...iTaosdByRestfulWithDifferentTokenTest.java | 59 +++++++++++++++++++ 10 files changed, 98 insertions(+), 49 deletions(-) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java diff --git a/cmake/install.inc b/cmake/install.inc index f8b3b7c3c6..b37cf751fb 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.29.jar DESTINATION connector/jdbc) + INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.31.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 61e976cb18..1db8361faf 100644 --- a/src/connector/jdbc/CMakeLists.txt +++ b/src/connector/jdbc/CMakeLists.txt @@ -8,10 +8,8 @@ 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.29.jar ${LIBRARY_OUTPUT_PATH} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.31.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}) -ENDIF () - - +ENDIF () \ No newline at end of file diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml index 968a9bf470..8f77582d30 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.29 + 2.0.31 jar JDBCDriver diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index ef353d1d19..d08d5502c2 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.29 + 2.0.31 jar JDBCDriver https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc @@ -123,6 +123,7 @@ **/InvalidResultSetPointerTest.java **/RestfulConnectionTest.java **/TD4144Test.java + **/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java true diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java index b810f9aeb5..d6a02b7e3a 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java @@ -17,16 +17,18 @@ public class RestfulConnection extends AbstractConnection { private final int port; private final String url; private volatile String database; + private final String token; /******************************************************/ private boolean isClosed; private final DatabaseMetaData metadata; - public RestfulConnection(String host, String port, Properties props, String database, String url) { + public RestfulConnection(String host, String port, Properties props, String database, String url, String token) { super(props); this.host = host; this.port = Integer.parseInt(port); this.database = database; this.url = url; + this.token = token; this.metadata = new RestfulDatabaseMetaData(url, props.getProperty(TSDBDriver.PROPERTY_KEY_USER), this); } @@ -66,6 +68,7 @@ public class RestfulConnection extends AbstractConnection { return this.metadata; } + // getters public String getHost() { return host; } @@ -81,4 +84,8 @@ public class RestfulConnection extends AbstractConnection { public String getUrl() { return url; } + + public String getToken() { + return token; + } } \ No newline at end of file diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java index a94cfa6e07..9ab67c5502 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java @@ -38,15 +38,11 @@ public class RestfulDriver extends AbstractDriver { String port = props.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "6041"); String database = props.containsKey(TSDBDriver.PROPERTY_KEY_DBNAME) ? props.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME) : null; - String loginUrl = "http://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST) + ":" - + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/login/" - + props.getProperty(TSDBDriver.PROPERTY_KEY_USER) + "/" - + props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD) + ""; + String loginUrl = "http://" + host + ":" + port + "/rest/login/" + props.getProperty(TSDBDriver.PROPERTY_KEY_USER) + "/" + props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD) + ""; try { String user = URLEncoder.encode(props.getProperty(TSDBDriver.PROPERTY_KEY_USER), "UTF-8"); String password = URLEncoder.encode(props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD), "UTF-8"); - loginUrl = "http://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST) + ":" - + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/login/" + user + "/" + password + ""; + loginUrl = "http://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST) + ":" + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/login/" + user + "/" + password + ""; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } @@ -55,12 +51,12 @@ public class RestfulDriver extends AbstractDriver { JSONObject jsonResult = JSON.parseObject(result); String status = jsonResult.getString("status"); String token = jsonResult.getString("desc"); - HttpClientPoolUtil.token = token; + if (!status.equals("succ")) { throw new SQLException(jsonResult.getString("desc")); } - RestfulConnection conn = new RestfulConnection(host, port, props, database, url); + RestfulConnection conn = new RestfulConnection(host, port, props, database, url, token); if (database != null && !database.trim().replaceAll("\\s", "").isEmpty()) { Statement stmt = conn.createStatement(); stmt.execute("use " + database); 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 fbc3a50a27..e9d193f6b4 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 @@ -83,7 +83,7 @@ public class RestfulStatement extends AbstractStatement { } if (SqlSyntaxValidator.isUseSql(sql)) { - HttpClientPoolUtil.execute(url, sql); + HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); this.database = sql.trim().replace("use", "").trim(); this.conn.setCatalog(this.database); result = false; @@ -116,7 +116,7 @@ public class RestfulStatement extends AbstractStatement { if ("UTC".equalsIgnoreCase(timestampFormat)) url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlutc"; - String result = HttpClientPoolUtil.execute(url, sql); + String result = HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); JSONObject resultJson = JSON.parseObject(result); if (resultJson.getString("status").equals("error")) { throw TSDBError.createSQLException(resultJson.getInteger("code"), resultJson.getString("desc")); @@ -130,7 +130,7 @@ public class RestfulStatement extends AbstractStatement { if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql)) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: " + sql); - String result = HttpClientPoolUtil.execute(url, sql); + String result = HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); JSONObject jsonObject = JSON.parseObject(result); if (jsonObject.getString("status").equals("error")) { throw TSDBError.createSQLException(jsonObject.getInteger("code"), jsonObject.getString("desc")); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java index 5e2440fd1d..b1c6dae6b3 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java @@ -20,39 +20,29 @@ import java.nio.charset.Charset; public class HttpClientPoolUtil { - public static PoolingHttpClientConnectionManager cm = null; - public static CloseableHttpClient httpClient = null; - public static String token = "cm9vdDp0YW9zZGF0YQ=="; - /** - * 默认content 类型 - */ - private static final String DEFAULT_CONTENT_TYPE = "application/json"; - /** - * 默认请求超时时间30s - */ - private static final int DEFAULT_TIME_OUT = 15000; - private static final int count = 32; - private static final int totalCount = 1000; - private static final int Http_Default_Keep_Time = 15000; - /** - * 初始化连接池 - */ + private static final String DEFAULT_CONTENT_TYPE = "application/json"; + private static final String DEFAULT_TOKEN = "cm9vdDp0YW9zZGF0YQ=="; + private static final int DEFAULT_TIME_OUT = 15000; + private static final int DEFAULT_MAX_PER_ROUTE = 32; + private static final int DEFAULT_MAX_TOTAL = 1000; + private static final int DEFAULT_HTTP_KEEP_TIME = 15000; + + private static PoolingHttpClientConnectionManager connectionManager; + private static CloseableHttpClient httpClient; + private static synchronized void initPools() { if (httpClient == null) { - cm = new PoolingHttpClientConnectionManager(); - cm.setDefaultMaxPerRoute(count); - cm.setMaxTotal(totalCount); - httpClient = HttpClients.custom().setKeepAliveStrategy(defaultStrategy).setConnectionManager(cm).build(); + connectionManager = new PoolingHttpClientConnectionManager(); + connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE); + connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL); + httpClient = HttpClients.custom().setKeepAliveStrategy(DEFAULT_KEEP_ALIVE_STRATEGY).setConnectionManager(connectionManager).build(); } } - /** - * Http connection keepAlive 设置 - */ - private static ConnectionKeepAliveStrategy defaultStrategy = (response, context) -> { + private static ConnectionKeepAliveStrategy DEFAULT_KEEP_ALIVE_STRATEGY = (response, context) -> { HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); - int keepTime = Http_Default_Keep_Time * 1000; + int keepTime = DEFAULT_HTTP_KEEP_TIME * 1000; while (it.hasNext()) { HeaderElement headerElement = it.nextElement(); String param = headerElement.getName(); @@ -76,7 +66,7 @@ public class HttpClientPoolUtil { * @param data 请求数据 * @return responseBody */ - public static String execute(String uri, String data) { + public static String execute(String uri, String data, String token) { long startTime = System.currentTimeMillis(); HttpEntity httpEntity = null; HttpEntityEnclosingRequestBase method = null; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java index 472da34980..e2541e8109 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java @@ -28,9 +28,7 @@ public class BatchInsertTest { @Before public void before() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); @@ -44,7 +42,7 @@ public class BatchInsertTest { String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))"; statement.executeUpdate(createTableSql); // create tables - for(int i = 0; i < numOfTables; i++) { + for (int i = 0; i < numOfTables; i++) { String loc = i % 2 == 0 ? "beijing" : "shanghai"; String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')"; statement.executeUpdate(createSubTalbesSql); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java new file mode 100644 index 0000000000..7f2d367dce --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java @@ -0,0 +1,59 @@ +package com.taosdata.jdbc.cases; + +import com.taosdata.jdbc.TSDBDriver; +import org.junit.Before; +import org.junit.Test; + +import java.sql.*; +import java.util.Properties; + +public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { + + private static String host1 = "192.168.17.156"; + private static String user1 = "root"; + private static String password1 = "tqueue"; + private Connection conn1; + private static String host2 = "192.168.17.82"; + private static String user2 = "root"; + private static String password2 = "taosdata"; + private Connection conn2; + + @Test + public void test() { + //when + executeSelectStatus(conn1); + executeSelectStatus(conn2); + executeSelectStatus(conn1); + } + + private void executeSelectStatus(Connection connection) { + try (Statement stmt = connection.createStatement()) { + ResultSet rs = stmt.executeQuery("select server_status()"); + ResultSetMetaData meta = rs.getMetaData(); + while (rs.next()) { + for (int i = 1; i <= meta.getColumnCount(); i++) { + System.out.println(meta.getColumnLabel(i) + ": " + rs.getString(i)); + } + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Before + public void before() { + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + + String url1 = "jdbc:TAOS-RS://" + host1 + ":6041/?user=" + user1 + "&password=" + password1; + String url2 = "jdbc:TAOS-RS://" + host2 + ":6041/?user=" + user2 + "&password=" + password2; + try { + conn1 = DriverManager.getConnection(url1, properties); + conn2 = DriverManager.getConnection(url2, properties); + } catch (SQLException e) { + e.printStackTrace(); + } + } +} From b01865f6c45bdb0e8fa80408ae59fbe9f2da6f96 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Fri, 11 Jun 2021 22:17:38 +0800 Subject: [PATCH 05/52] [TD-4366] adding more ntp. try to make sure ntp is turned on --- tests/pytest/client/change_time_1_1.py | 4 +++- tests/pytest/client/change_time_1_2.py | 4 ++-- tests/pytest/fulltest.sh | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/pytest/client/change_time_1_1.py b/tests/pytest/client/change_time_1_1.py index 24e0195a9c..abae49a41f 100644 --- a/tests/pytest/client/change_time_1_1.py +++ b/tests/pytest/client/change_time_1_1.py @@ -51,7 +51,8 @@ class TDTestCase: #move 5 days ahead to 2020/10/25. 4 oldest files should be removed during the new write #leaving 7 data files. os.system ('timedatectl set-time 2020-10-25') - os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_B.json") + os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_B.json") + os.system('sudo timedatectl set-ntp on') commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') print(result.count('data')) @@ -61,6 +62,7 @@ class TDTestCase: tdLog.debug("data file number correct") tdSql.query('select first(ts) from stb_0') tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database + os.system('sudo timedatectl set-ntp on') def stop(self): os.system('sudo timedatectl set-ntp on') diff --git a/tests/pytest/client/change_time_1_2.py b/tests/pytest/client/change_time_1_2.py index cd1a17926d..855b04873c 100644 --- a/tests/pytest/client/change_time_1_2.py +++ b/tests/pytest/client/change_time_1_2.py @@ -62,6 +62,7 @@ class TDTestCase: tdDnodes.start(1) tdSql.query('select first(ts) from stb_0') tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database + os.system('sudo timedatectl set-ntp on') commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') print(result.count('data')) @@ -69,8 +70,7 @@ class TDTestCase: tdLog.exit('wrong number of files') else: tdLog.debug("data file number correct") - - + os.system('sudo timedatectl set-ntp on') def stop(self): os.system('sudo timedatectl set-ntp on') diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index fe023acc4b..bab56fa657 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -256,8 +256,6 @@ python3 ./test.py -f client/client.py python3 ./test.py -f client/version.py python3 ./test.py -f client/alterDatabase.py python3 ./test.py -f client/noConnectionErrorTest.py -python3 test.py -f client/change_time_1_1.py -python3 test.py -f client/change_time_1_2.py # Misc python3 testCompress.py @@ -344,4 +342,6 @@ python3 test.py -f alter/alter_keep.py python3 test.py -f alter/alter_cacheLastRow.py python3 ./test.py -f query/querySession.py python3 test.py -f alter/alter_create_exception.py +python3 test.py -f client/change_time_1_1.py +python3 test.py -f client/change_time_1_2.py #======================p4-end=============== From 0cbe5463e6c848099aa4578ee839aac0f8e82de7 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 14 Jun 2021 19:18:15 +0800 Subject: [PATCH 06/52] [td-4692]: error in system locale set caused client crash. --- src/client/src/tscSystem.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index bd79f81846..c602d1bfcc 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -288,16 +288,23 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { if (strlen(tsLocale) == 0) { // locale does not set yet char* defaultLocale = setlocale(LC_CTYPE, ""); + + // The locale of the current OS does not be set correctly, so the default locale cannot be acquired. + if (defaultLocale == NULL) { + uError("failed to get default locale, please set the correct locale in current OS"); + return -1; + } + tstrncpy(tsLocale, defaultLocale, TSDB_LOCALE_LEN); } // set the user specified locale char *locale = setlocale(LC_CTYPE, pStr); - if (locale != NULL) { + if (locale != NULL) { // failed to set the user specified locale tscInfo("locale set, prev locale:%s, new locale:%s", tsLocale, locale); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - } else { // set the user-specified localed failed, use default LC_CTYPE as current locale + } else { // set the user specified locale failed, use default LC_CTYPE as current locale locale = setlocale(LC_CTYPE, tsLocale); tscInfo("failed to set locale:%s, current locale:%s", pStr, tsLocale); } From 881a5506231700db5b9aeb1928dfd7a159ef905d Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 15 Jun 2021 09:24:15 +0800 Subject: [PATCH 07/52] [TD-4366 adding sleep to prevent time problem] --- tests/pytest/alter/alter_keep.py | 20 ++++++++++---------- tests/pytest/client/change_time_1_1.py | 2 ++ tests/pytest/client/change_time_1_2.py | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/pytest/alter/alter_keep.py b/tests/pytest/alter/alter_keep.py index 9f66b08823..72ca635ac3 100644 --- a/tests/pytest/alter/alter_keep.py +++ b/tests/pytest/alter/alter_keep.py @@ -15,6 +15,7 @@ import sys from util.log import * from util.cases import * from util.sql import * +import time class TDTestCase: @@ -129,9 +130,6 @@ class TDTestCase: tdSql.prepare() - ##TODO: need to wait for TD-4445 to implement the following - ## tests - ## preset the keep tdSql.prepare() @@ -176,20 +174,22 @@ class TDTestCase: tdSql.error('insert into tb values (now-15d, 10)') tdSql.query('select * from tb') tdSql.checkRows(rowNum) - + tdLog.notice('testing keep will be altered if sudden change from small to big') - tdSql.execute('alter database db keep 14,14,14') - tdSql.execute('alter database db keep 15,15,15') - tdSql.execute('insert into tb values (now-15d, 10)') - tdSql.query('select * from tb') - tdSql.checkRows(rowNum + 1) + for i in range(30): + tdSql.execute('alter database db keep 14,14,14') + tdSql.execute('alter database db keep 16,16,16') + tdSql.execute('insert into tb values (now-15d, 10)') + tdSql.query('select * from tb') + rowNum += 1 + tdSql.checkRows(rowNum ) tdLog.notice('testing keep will be altered if sudden change from big to small') tdSql.execute('alter database db keep 16,16,16') tdSql.execute('alter database db keep 14,14,14') tdSql.error('insert into tb values (now-15d, 10)') tdSql.query('select * from tb') - tdSql.checkRows(rowNum + 1) + tdSql.checkRows(rowNum) diff --git a/tests/pytest/client/change_time_1_1.py b/tests/pytest/client/change_time_1_1.py index abae49a41f..54984747b5 100644 --- a/tests/pytest/client/change_time_1_1.py +++ b/tests/pytest/client/change_time_1_1.py @@ -19,6 +19,7 @@ from util.pathFinding import * from util.dnodes import tdDnodes from datetime import datetime import subprocess +import time ##TODO: this is now automatic, but not sure if this will run through jenkins class TDTestCase: @@ -63,6 +64,7 @@ class TDTestCase: tdSql.query('select first(ts) from stb_0') tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database os.system('sudo timedatectl set-ntp on') + time.sleep(5) def stop(self): os.system('sudo timedatectl set-ntp on') diff --git a/tests/pytest/client/change_time_1_2.py b/tests/pytest/client/change_time_1_2.py index 855b04873c..0937080b5c 100644 --- a/tests/pytest/client/change_time_1_2.py +++ b/tests/pytest/client/change_time_1_2.py @@ -71,6 +71,7 @@ class TDTestCase: else: tdLog.debug("data file number correct") os.system('sudo timedatectl set-ntp on') + time.sleep(5) def stop(self): os.system('sudo timedatectl set-ntp on') From 1a5aac6eeb76378868fe64dd5fd9999f16e8c69e Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 15 Jun 2021 10:04:44 +0800 Subject: [PATCH 08/52] [TD-4366 adding sleep to prevent time problem] --- tests/pytest/client/change_time_1_1.py | 22 ++++++++++++++++------ tests/pytest/client/change_time_1_2.py | 17 ++++++++++++----- tests/pytest/fulltest.sh | 4 ++-- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/tests/pytest/client/change_time_1_1.py b/tests/pytest/client/change_time_1_1.py index 54984747b5..32917ab2e4 100644 --- a/tests/pytest/client/change_time_1_1.py +++ b/tests/pytest/client/change_time_1_1.py @@ -40,11 +40,16 @@ class TDTestCase: #run taosdemo to insert data. one row per second from 2020/10/11 to 2020/10/20 #11 data files should be generated #vnode at TDinternal/community/sim/dnode1/data/vnode - os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") - commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] - result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') - print(result.count('data')) + try: + os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") + commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] + result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') + except BaseException: + os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) if result.count('data') != 11: + os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) tdLog.exit('wrong number of files') else: tdLog.debug("data file number correct") @@ -52,8 +57,13 @@ class TDTestCase: #move 5 days ahead to 2020/10/25. 4 oldest files should be removed during the new write #leaving 7 data files. os.system ('timedatectl set-time 2020-10-25') - os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_B.json") + try: + os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_B.json") + except BaseException: + os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') print(result.count('data')) @@ -64,7 +74,7 @@ class TDTestCase: tdSql.query('select first(ts) from stb_0') tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database os.system('sudo timedatectl set-ntp on') - time.sleep(5) + tdLog.sleep(10) def stop(self): os.system('sudo timedatectl set-ntp on') diff --git a/tests/pytest/client/change_time_1_2.py b/tests/pytest/client/change_time_1_2.py index 0937080b5c..d693010be4 100644 --- a/tests/pytest/client/change_time_1_2.py +++ b/tests/pytest/client/change_time_1_2.py @@ -39,11 +39,17 @@ class TDTestCase: #run taosdemo to insert data. one row per second from 2020/10/11 to 2020/10/20 #11 data files should be generated #vnode at TDinternal/community/sim/dnode1/data/vnode - os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") - commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] - result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') - print(result.count('data')) + try: + os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") + commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] + result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') + except BaseException: + os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) + if result.count('data') != 11: + os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) tdLog.exit('wrong number of files') else: tdLog.debug("data file number correct") @@ -63,6 +69,7 @@ class TDTestCase: tdSql.query('select first(ts) from stb_0') tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') print(result.count('data')) @@ -71,7 +78,7 @@ class TDTestCase: else: tdLog.debug("data file number correct") os.system('sudo timedatectl set-ntp on') - time.sleep(5) + tdLog.sleep(10) def stop(self): os.system('sudo timedatectl set-ntp on') diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index bab56fa657..6a8497d241 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -342,6 +342,6 @@ python3 test.py -f alter/alter_keep.py python3 test.py -f alter/alter_cacheLastRow.py python3 ./test.py -f query/querySession.py python3 test.py -f alter/alter_create_exception.py -python3 test.py -f client/change_time_1_1.py -python3 test.py -f client/change_time_1_2.py +# python3 test.py -f client/change_time_1_1.py +# python3 test.py -f client/change_time_1_2.py #======================p4-end=============== From 679762087951bbb8872ed9d0c23a2fa8e3a13979 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Tue, 15 Jun 2021 11:25:57 +0800 Subject: [PATCH 09/52] remove sub query --- src/inc/ttokendef.h | 2 + src/query/inc/sql.y | 3 +- src/query/src/sql.c | 1193 +++++++++++++++++++++---------------------- 3 files changed, 597 insertions(+), 601 deletions(-) diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index c7c4b5968b..e411ac6232 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -212,6 +212,8 @@ + + #define TK_SPACE 300 #define TK_COMMENT 301 #define TK_ILLEGAL 302 diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 5a42b3a631..e0dad6616c 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -28,7 +28,7 @@ #include #include "qSqlparser.h" #include "tcmdtype.h" -#include "tstoken.h" +#include "ttoken.h" #include "ttokendef.h" #include "tutil.h" #include "tvariant.h" @@ -507,7 +507,6 @@ distinct(X) ::= . { X.n = 0;} // A complete FROM clause. %type from {SFromInfo*} from(A) ::= FROM tablelist(X). {A = X;} -from(A) ::= FROM LP union(Y) RP. {A = Y;} %type tablelist {SArray*} tablelist(A) ::= ids(X) cpxName(Y). { diff --git a/src/query/src/sql.c b/src/query/src/sql.c index 8f36638dc9..7213fc30c6 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -26,11 +26,11 @@ #include /************ Begin %include sections from the grammar ************************/ -#include -#include #include #include #include +#include +#include #include "qSqlparser.h" #include "tcmdtype.h" #include "ttoken.h" @@ -137,18 +137,18 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 315 -#define YYNRULE 269 -#define YYNRULE_WITH_ACTION 269 +#define YYNSTATE 313 +#define YYNRULE 268 +#define YYNRULE_WITH_ACTION 268 #define YYNTOKEN 187 -#define YY_MAX_SHIFT 314 -#define YY_MIN_SHIFTREDUCE 508 -#define YY_MAX_SHIFTREDUCE 776 -#define YY_ERROR_ACTION 777 -#define YY_ACCEPT_ACTION 778 -#define YY_NO_ACTION 779 -#define YY_MIN_REDUCE 780 -#define YY_MAX_REDUCE 1048 +#define YY_MAX_SHIFT 312 +#define YY_MIN_SHIFTREDUCE 505 +#define YY_MAX_SHIFTREDUCE 772 +#define YY_ERROR_ACTION 773 +#define YY_ACCEPT_ACTION 774 +#define YY_NO_ACTION 775 +#define YY_MIN_REDUCE 776 +#define YY_MAX_REDUCE 1043 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -215,76 +215,76 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (672) +#define YY_ACTTAB_COUNT (675) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 133, 555, 204, 312, 208, 140, 947, 17, 85, 556, - /* 10 */ 778, 314, 179, 47, 48, 140, 51, 52, 30, 181, - /* 20 */ 214, 41, 181, 50, 262, 55, 53, 57, 54, 1029, - /* 30 */ 926, 211, 1030, 46, 45, 185, 181, 44, 43, 42, - /* 40 */ 47, 48, 914, 51, 52, 210, 1030, 214, 41, 555, - /* 50 */ 50, 262, 55, 53, 57, 54, 938, 556, 1026, 205, - /* 60 */ 46, 45, 923, 247, 44, 43, 42, 48, 944, 51, - /* 70 */ 52, 242, 978, 214, 41, 555, 50, 262, 55, 53, - /* 80 */ 57, 54, 979, 556, 257, 278, 46, 45, 298, 225, - /* 90 */ 44, 43, 42, 509, 510, 511, 512, 513, 514, 515, - /* 100 */ 516, 517, 518, 519, 520, 521, 313, 634, 1025, 231, - /* 110 */ 70, 555, 30, 47, 48, 1024, 51, 52, 825, 556, - /* 120 */ 214, 41, 166, 50, 262, 55, 53, 57, 54, 44, - /* 130 */ 43, 42, 720, 46, 45, 288, 287, 44, 43, 42, - /* 140 */ 47, 49, 834, 51, 52, 198, 166, 214, 41, 234, - /* 150 */ 50, 262, 55, 53, 57, 54, 922, 238, 237, 227, - /* 160 */ 46, 45, 285, 284, 44, 43, 42, 23, 276, 307, - /* 170 */ 306, 275, 274, 273, 305, 272, 304, 303, 302, 271, - /* 180 */ 301, 300, 886, 140, 874, 875, 876, 877, 878, 879, - /* 190 */ 880, 881, 882, 883, 884, 885, 887, 888, 51, 52, - /* 200 */ 826, 219, 214, 41, 166, 50, 262, 55, 53, 57, - /* 210 */ 54, 223, 18, 82, 25, 46, 45, 1, 154, 44, - /* 220 */ 43, 42, 213, 735, 938, 722, 724, 926, 727, 190, - /* 230 */ 730, 226, 213, 735, 140, 191, 724, 912, 727, 206, - /* 240 */ 730, 118, 117, 189, 909, 910, 29, 913, 259, 74, - /* 250 */ 78, 726, 30, 729, 200, 201, 221, 36, 261, 199, - /* 260 */ 23, 723, 307, 306, 200, 201, 924, 305, 30, 304, - /* 270 */ 303, 302, 74, 301, 300, 894, 183, 308, 892, 893, - /* 280 */ 36, 224, 926, 895, 280, 897, 898, 896, 184, 899, - /* 290 */ 900, 920, 658, 217, 69, 655, 923, 656, 725, 657, - /* 300 */ 728, 79, 241, 926, 68, 55, 53, 57, 54, 218, - /* 310 */ 197, 212, 923, 46, 45, 30, 278, 44, 43, 42, - /* 320 */ 673, 103, 108, 228, 229, 56, 911, 97, 107, 113, - /* 330 */ 116, 106, 736, 220, 263, 56, 186, 110, 732, 30, - /* 340 */ 180, 30, 736, 5, 156, 30, 3, 167, 732, 33, - /* 350 */ 155, 92, 87, 91, 731, 6, 281, 701, 702, 923, - /* 360 */ 174, 170, 28, 733, 731, 268, 172, 169, 121, 120, - /* 370 */ 119, 46, 45, 105, 80, 44, 43, 42, 298, 662, - /* 380 */ 282, 663, 286, 923, 670, 923, 290, 71, 12, 923, - /* 390 */ 187, 24, 84, 188, 81, 311, 310, 126, 677, 243, - /* 400 */ 680, 659, 660, 31, 661, 686, 1040, 692, 245, 135, - /* 410 */ 734, 60, 693, 756, 737, 61, 20, 19, 19, 64, - /* 420 */ 644, 265, 646, 267, 31, 31, 60, 83, 645, 67, - /* 430 */ 739, 633, 60, 925, 96, 95, 194, 62, 195, 65, - /* 440 */ 193, 14, 13, 102, 101, 115, 114, 131, 129, 16, - /* 450 */ 15, 178, 192, 182, 989, 988, 215, 239, 985, 132, - /* 460 */ 984, 216, 289, 946, 39, 971, 954, 956, 134, 138, - /* 470 */ 970, 939, 246, 130, 921, 151, 919, 150, 152, 153, - /* 480 */ 248, 837, 270, 685, 890, 299, 104, 291, 148, 37, - /* 490 */ 145, 176, 936, 141, 34, 58, 207, 250, 255, 66, - /* 500 */ 63, 142, 279, 833, 1045, 260, 143, 258, 144, 256, - /* 510 */ 93, 1044, 1042, 254, 157, 146, 283, 1039, 99, 1038, - /* 520 */ 1036, 252, 158, 855, 35, 32, 38, 177, 249, 822, - /* 530 */ 109, 820, 111, 112, 818, 817, 230, 168, 815, 814, - /* 540 */ 813, 812, 811, 810, 171, 173, 807, 805, 803, 801, - /* 550 */ 799, 175, 40, 244, 72, 75, 251, 292, 972, 293, - /* 560 */ 294, 296, 295, 297, 309, 776, 202, 222, 269, 232, - /* 570 */ 233, 203, 775, 235, 88, 89, 236, 196, 774, 762, - /* 580 */ 761, 240, 245, 8, 73, 264, 209, 665, 687, 816, - /* 590 */ 165, 856, 161, 159, 160, 122, 162, 163, 123, 164, - /* 600 */ 809, 2, 76, 124, 125, 808, 800, 136, 137, 4, - /* 610 */ 690, 149, 147, 77, 253, 26, 694, 139, 902, 9, - /* 620 */ 10, 27, 738, 7, 11, 740, 21, 22, 266, 86, - /* 630 */ 597, 593, 84, 591, 590, 589, 586, 559, 277, 90, - /* 640 */ 94, 31, 636, 59, 635, 632, 581, 579, 571, 577, - /* 650 */ 573, 575, 569, 567, 98, 100, 600, 599, 598, 596, - /* 660 */ 595, 594, 592, 588, 587, 60, 557, 525, 523, 780, - /* 670 */ 127, 128, + /* 0 */ 132, 552, 203, 310, 206, 139, 943, 17, 84, 553, + /* 10 */ 774, 312, 178, 46, 47, 139, 50, 51, 29, 180, + /* 20 */ 212, 40, 180, 49, 260, 54, 52, 56, 53, 1024, + /* 30 */ 922, 209, 1025, 45, 44, 184, 180, 43, 42, 41, + /* 40 */ 46, 47, 910, 50, 51, 208, 1025, 212, 40, 552, + /* 50 */ 49, 260, 54, 52, 56, 53, 934, 553, 1021, 204, + /* 60 */ 45, 44, 919, 245, 43, 42, 41, 47, 940, 50, + /* 70 */ 51, 241, 973, 212, 40, 552, 49, 260, 54, 52, + /* 80 */ 56, 53, 974, 553, 255, 217, 45, 44, 276, 223, + /* 90 */ 43, 42, 41, 506, 507, 508, 509, 510, 511, 512, + /* 100 */ 513, 514, 515, 516, 517, 518, 311, 631, 1020, 229, + /* 110 */ 71, 922, 29, 46, 47, 1019, 50, 51, 821, 219, + /* 120 */ 212, 40, 165, 49, 260, 54, 52, 56, 53, 43, + /* 130 */ 42, 41, 716, 45, 44, 286, 285, 43, 42, 41, + /* 140 */ 46, 48, 296, 50, 51, 922, 908, 212, 40, 232, + /* 150 */ 49, 260, 54, 52, 56, 53, 918, 236, 235, 225, + /* 160 */ 45, 44, 283, 282, 43, 42, 41, 23, 274, 305, + /* 170 */ 304, 273, 272, 271, 303, 270, 302, 301, 300, 269, + /* 180 */ 299, 298, 882, 139, 870, 871, 872, 873, 874, 875, + /* 190 */ 876, 877, 878, 879, 880, 881, 883, 884, 50, 51, + /* 200 */ 830, 306, 212, 40, 165, 49, 260, 54, 52, 56, + /* 210 */ 53, 221, 18, 81, 916, 45, 44, 69, 197, 43, + /* 220 */ 42, 41, 211, 731, 139, 276, 720, 922, 723, 189, + /* 230 */ 726, 224, 211, 731, 104, 190, 720, 198, 723, 296, + /* 240 */ 726, 117, 116, 188, 905, 906, 28, 909, 257, 907, + /* 250 */ 77, 722, 29, 725, 199, 200, 218, 242, 259, 261, + /* 260 */ 23, 30, 305, 304, 199, 200, 920, 303, 29, 302, + /* 270 */ 301, 300, 70, 299, 298, 890, 3, 166, 888, 889, + /* 280 */ 35, 222, 182, 891, 278, 893, 894, 892, 79, 895, + /* 290 */ 896, 78, 655, 215, 183, 652, 919, 653, 721, 654, + /* 300 */ 724, 72, 239, 70, 67, 54, 52, 56, 53, 216, + /* 310 */ 196, 35, 919, 45, 44, 29, 822, 43, 42, 41, + /* 320 */ 165, 102, 107, 226, 227, 55, 670, 96, 106, 112, + /* 330 */ 115, 105, 732, 1, 153, 55, 185, 109, 728, 29, + /* 340 */ 179, 29, 732, 5, 155, 29, 697, 698, 728, 32, + /* 350 */ 154, 91, 86, 90, 727, 735, 279, 60, 667, 919, + /* 360 */ 173, 169, 718, 729, 727, 24, 171, 168, 120, 119, + /* 370 */ 118, 45, 44, 210, 682, 43, 42, 41, 134, 61, + /* 380 */ 280, 27, 284, 919, 266, 919, 288, 688, 12, 919, + /* 390 */ 186, 59, 83, 187, 80, 309, 308, 125, 719, 689, + /* 400 */ 63, 656, 752, 20, 674, 733, 19, 641, 263, 19, + /* 410 */ 730, 30, 30, 193, 643, 265, 194, 6, 59, 82, + /* 420 */ 64, 642, 192, 95, 94, 59, 14, 13, 114, 113, + /* 430 */ 101, 100, 66, 659, 630, 660, 177, 16, 15, 657, + /* 440 */ 191, 658, 130, 128, 181, 1035, 921, 237, 935, 984, + /* 450 */ 983, 213, 980, 979, 214, 287, 131, 942, 38, 966, + /* 460 */ 949, 951, 133, 244, 137, 965, 917, 129, 150, 149, + /* 470 */ 243, 246, 205, 915, 681, 297, 151, 152, 886, 148, + /* 480 */ 146, 144, 141, 932, 140, 833, 268, 57, 248, 253, + /* 490 */ 65, 36, 258, 62, 175, 33, 277, 829, 1040, 142, + /* 500 */ 256, 92, 1039, 143, 1037, 156, 254, 281, 1034, 98, + /* 510 */ 1033, 1031, 157, 851, 34, 31, 37, 176, 252, 818, + /* 520 */ 108, 250, 816, 110, 111, 814, 813, 228, 247, 167, + /* 530 */ 811, 810, 809, 808, 807, 806, 170, 172, 803, 801, + /* 540 */ 799, 797, 103, 795, 174, 39, 73, 74, 289, 249, + /* 550 */ 967, 290, 291, 292, 293, 294, 295, 201, 220, 267, + /* 560 */ 307, 772, 230, 231, 202, 87, 195, 88, 771, 233, + /* 570 */ 234, 770, 758, 757, 812, 238, 8, 68, 240, 805, + /* 580 */ 160, 121, 159, 852, 158, 161, 162, 164, 122, 163, + /* 590 */ 2, 123, 804, 4, 262, 124, 796, 662, 75, 683, + /* 600 */ 135, 207, 686, 76, 147, 145, 898, 136, 251, 9, + /* 610 */ 690, 138, 25, 10, 734, 26, 7, 11, 21, 736, + /* 620 */ 22, 85, 264, 594, 590, 83, 588, 587, 586, 583, + /* 630 */ 556, 275, 93, 89, 30, 633, 58, 632, 629, 578, + /* 640 */ 576, 97, 568, 574, 570, 572, 566, 564, 597, 99, + /* 650 */ 596, 595, 593, 592, 591, 589, 585, 584, 59, 554, + /* 660 */ 776, 522, 520, 775, 775, 126, 775, 775, 775, 775, + /* 670 */ 775, 775, 775, 775, 127, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 190, 1, 189, 190, 209, 190, 190, 251, 196, 9, @@ -295,66 +295,66 @@ static const YYCODETYPE yy_lookahead[] = { /* 50 */ 23, 24, 25, 26, 27, 28, 233, 9, 251, 231, /* 60 */ 33, 34, 234, 253, 37, 38, 39, 14, 252, 16, /* 70 */ 17, 248, 257, 20, 21, 1, 23, 24, 25, 26, - /* 80 */ 27, 28, 257, 9, 259, 79, 33, 34, 81, 67, + /* 80 */ 27, 28, 257, 9, 259, 209, 33, 34, 79, 67, /* 90 */ 37, 38, 39, 45, 46, 47, 48, 49, 50, 51, /* 100 */ 52, 53, 54, 55, 56, 57, 58, 5, 251, 61, - /* 110 */ 110, 1, 190, 13, 14, 251, 16, 17, 195, 9, + /* 110 */ 110, 235, 190, 13, 14, 251, 16, 17, 195, 209, /* 120 */ 20, 21, 199, 23, 24, 25, 26, 27, 28, 37, /* 130 */ 38, 39, 105, 33, 34, 33, 34, 37, 38, 39, - /* 140 */ 13, 14, 195, 16, 17, 251, 199, 20, 21, 135, + /* 140 */ 13, 14, 81, 16, 17, 235, 0, 20, 21, 135, /* 150 */ 23, 24, 25, 26, 27, 28, 234, 143, 144, 137, /* 160 */ 33, 34, 140, 141, 37, 38, 39, 88, 89, 90, /* 170 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, /* 180 */ 101, 102, 208, 190, 210, 211, 212, 213, 214, 215, /* 190 */ 216, 217, 218, 219, 220, 221, 222, 223, 16, 17, /* 200 */ 195, 209, 20, 21, 199, 23, 24, 25, 26, 27, - /* 210 */ 28, 67, 44, 196, 104, 33, 34, 197, 198, 37, - /* 220 */ 38, 39, 1, 2, 233, 1, 5, 235, 7, 61, - /* 230 */ 9, 190, 1, 2, 190, 67, 5, 0, 7, 248, - /* 240 */ 9, 73, 74, 75, 227, 228, 229, 230, 255, 104, - /* 250 */ 257, 5, 190, 7, 33, 34, 209, 112, 37, 251, - /* 260 */ 88, 37, 90, 91, 33, 34, 225, 95, 190, 97, - /* 270 */ 98, 99, 104, 101, 102, 208, 251, 209, 211, 212, - /* 280 */ 112, 137, 235, 216, 140, 218, 219, 220, 251, 222, - /* 290 */ 223, 190, 2, 231, 196, 5, 234, 7, 5, 9, - /* 300 */ 7, 257, 134, 235, 136, 25, 26, 27, 28, 231, - /* 310 */ 142, 60, 234, 33, 34, 190, 79, 37, 38, 39, - /* 320 */ 37, 62, 63, 33, 34, 104, 228, 68, 69, 70, - /* 330 */ 71, 72, 111, 232, 15, 104, 251, 78, 117, 190, - /* 340 */ 251, 190, 111, 62, 63, 190, 193, 194, 117, 68, - /* 350 */ 69, 70, 71, 72, 133, 104, 231, 124, 125, 234, - /* 360 */ 62, 63, 104, 117, 133, 107, 68, 69, 70, 71, - /* 370 */ 72, 33, 34, 76, 236, 37, 38, 39, 81, 5, - /* 380 */ 231, 7, 231, 234, 109, 234, 231, 249, 104, 234, - /* 390 */ 251, 116, 108, 251, 110, 64, 65, 66, 115, 105, - /* 400 */ 105, 111, 5, 109, 7, 105, 235, 105, 113, 109, - /* 410 */ 117, 109, 105, 105, 105, 109, 109, 109, 109, 109, - /* 420 */ 105, 105, 105, 105, 109, 109, 109, 109, 105, 104, - /* 430 */ 111, 106, 109, 235, 138, 139, 251, 131, 251, 129, - /* 440 */ 251, 138, 139, 138, 139, 76, 77, 62, 63, 138, - /* 450 */ 139, 251, 251, 251, 226, 226, 226, 190, 226, 190, - /* 460 */ 226, 226, 226, 190, 250, 258, 190, 190, 190, 190, - /* 470 */ 258, 233, 233, 60, 233, 190, 190, 237, 190, 190, - /* 480 */ 254, 190, 190, 117, 224, 103, 87, 86, 239, 190, - /* 490 */ 242, 190, 247, 246, 190, 127, 254, 254, 254, 128, - /* 500 */ 130, 245, 190, 190, 190, 122, 244, 126, 243, 121, - /* 510 */ 190, 190, 190, 120, 190, 241, 190, 190, 190, 190, + /* 210 */ 28, 67, 44, 196, 190, 33, 34, 196, 251, 37, + /* 220 */ 38, 39, 1, 2, 190, 79, 5, 235, 7, 61, + /* 230 */ 9, 190, 1, 2, 76, 67, 5, 251, 7, 81, + /* 240 */ 9, 73, 74, 75, 227, 228, 229, 230, 255, 228, + /* 250 */ 257, 5, 190, 7, 33, 34, 232, 105, 37, 15, + /* 260 */ 88, 109, 90, 91, 33, 34, 225, 95, 190, 97, + /* 270 */ 98, 99, 104, 101, 102, 208, 193, 194, 211, 212, + /* 280 */ 112, 137, 251, 216, 140, 218, 219, 220, 236, 222, + /* 290 */ 223, 257, 2, 231, 251, 5, 234, 7, 5, 9, + /* 300 */ 7, 249, 134, 104, 136, 25, 26, 27, 28, 231, + /* 310 */ 142, 112, 234, 33, 34, 190, 195, 37, 38, 39, + /* 320 */ 199, 62, 63, 33, 34, 104, 37, 68, 69, 70, + /* 330 */ 71, 72, 111, 197, 198, 104, 251, 78, 117, 190, + /* 340 */ 251, 190, 111, 62, 63, 190, 124, 125, 117, 68, + /* 350 */ 69, 70, 71, 72, 133, 111, 231, 109, 109, 234, + /* 360 */ 62, 63, 1, 117, 133, 116, 68, 69, 70, 71, + /* 370 */ 72, 33, 34, 60, 105, 37, 38, 39, 109, 131, + /* 380 */ 231, 104, 231, 234, 107, 234, 231, 105, 104, 234, + /* 390 */ 251, 109, 108, 251, 110, 64, 65, 66, 37, 105, + /* 400 */ 109, 111, 105, 109, 115, 105, 109, 105, 105, 109, + /* 410 */ 117, 109, 109, 251, 105, 105, 251, 104, 109, 109, + /* 420 */ 129, 105, 251, 138, 139, 109, 138, 139, 76, 77, + /* 430 */ 138, 139, 104, 5, 106, 7, 251, 138, 139, 5, + /* 440 */ 251, 7, 62, 63, 251, 235, 235, 190, 233, 226, + /* 450 */ 226, 226, 226, 226, 226, 226, 190, 190, 250, 258, + /* 460 */ 190, 190, 190, 233, 190, 258, 233, 60, 190, 237, + /* 470 */ 191, 254, 254, 190, 117, 103, 190, 190, 224, 238, + /* 480 */ 240, 242, 245, 247, 246, 190, 190, 127, 254, 254, + /* 490 */ 128, 190, 122, 130, 190, 190, 190, 190, 190, 244, + /* 500 */ 126, 190, 190, 243, 190, 190, 121, 190, 190, 190, + /* 510 */ 190, 190, 190, 190, 190, 190, 190, 190, 120, 190, /* 520 */ 190, 119, 190, 190, 190, 190, 190, 190, 118, 190, /* 530 */ 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, - /* 540 */ 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, - /* 550 */ 190, 190, 132, 191, 191, 191, 191, 50, 191, 83, - /* 560 */ 85, 84, 54, 82, 79, 5, 191, 191, 191, 145, - /* 570 */ 5, 191, 5, 145, 196, 196, 5, 191, 5, 90, - /* 580 */ 89, 135, 113, 104, 114, 107, 1, 105, 105, 191, - /* 590 */ 200, 207, 201, 206, 205, 192, 204, 202, 192, 203, - /* 600 */ 191, 197, 109, 192, 192, 191, 191, 104, 109, 193, - /* 610 */ 105, 238, 240, 104, 104, 109, 105, 104, 224, 123, - /* 620 */ 123, 109, 105, 104, 104, 111, 104, 104, 107, 76, - /* 630 */ 9, 5, 108, 5, 5, 5, 5, 80, 15, 76, - /* 640 */ 139, 109, 5, 16, 5, 105, 5, 5, 5, 5, - /* 650 */ 5, 5, 5, 5, 139, 139, 5, 5, 5, 5, - /* 660 */ 5, 5, 5, 5, 5, 109, 80, 60, 59, 0, - /* 670 */ 21, 21, 262, 262, 262, 262, 262, 262, 262, 262, + /* 540 */ 190, 190, 87, 190, 190, 132, 191, 191, 86, 191, + /* 550 */ 191, 50, 83, 85, 54, 84, 82, 191, 191, 191, + /* 560 */ 79, 5, 145, 5, 191, 196, 191, 196, 5, 145, + /* 570 */ 5, 5, 90, 89, 191, 135, 104, 114, 113, 191, + /* 580 */ 201, 192, 205, 207, 206, 204, 202, 200, 192, 203, + /* 590 */ 197, 192, 191, 193, 107, 192, 191, 105, 109, 105, + /* 600 */ 104, 1, 105, 104, 239, 241, 224, 109, 104, 123, + /* 610 */ 105, 104, 109, 123, 105, 109, 104, 104, 104, 111, + /* 620 */ 104, 76, 107, 9, 5, 108, 5, 5, 5, 5, + /* 630 */ 80, 15, 139, 76, 109, 5, 16, 5, 105, 5, + /* 640 */ 5, 139, 5, 5, 5, 5, 5, 5, 5, 139, + /* 650 */ 5, 5, 5, 5, 5, 5, 5, 5, 109, 80, + /* 660 */ 0, 60, 59, 262, 262, 21, 262, 262, 262, 262, + /* 670 */ 262, 262, 262, 262, 21, 262, 262, 262, 262, 262, /* 680 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262, /* 690 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262, /* 700 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262, @@ -372,101 +372,102 @@ static const YYCODETYPE yy_lookahead[] = { /* 820 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262, /* 830 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262, /* 840 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262, - /* 850 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, + /* 850 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262, + /* 860 */ 262, 262, }; -#define YY_SHIFT_COUNT (314) +#define YY_SHIFT_COUNT (312) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (669) +#define YY_SHIFT_MAX (660) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 168, 79, 79, 172, 172, 6, 221, 231, 74, 74, + /* 0 */ 168, 79, 79, 172, 172, 9, 221, 231, 74, 74, /* 10 */ 74, 74, 74, 74, 74, 74, 74, 0, 48, 231, - /* 20 */ 290, 290, 290, 290, 110, 145, 74, 74, 74, 237, - /* 30 */ 74, 74, 297, 6, 7, 7, 672, 672, 672, 231, + /* 20 */ 290, 290, 290, 290, 74, 74, 74, 74, 146, 74, + /* 30 */ 74, 158, 9, 61, 61, 675, 675, 675, 231, 231, /* 40 */ 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, - /* 50 */ 231, 231, 231, 231, 231, 231, 231, 231, 231, 290, - /* 60 */ 290, 102, 102, 102, 102, 102, 102, 102, 74, 74, - /* 70 */ 74, 283, 74, 145, 145, 74, 74, 74, 233, 233, - /* 80 */ 275, 145, 74, 74, 74, 74, 74, 74, 74, 74, + /* 50 */ 231, 231, 231, 231, 231, 231, 231, 231, 290, 290, + /* 60 */ 102, 102, 102, 102, 102, 102, 102, 74, 199, 74, + /* 70 */ 199, 74, 289, 74, 74, 74, 74, 222, 222, 249, + /* 80 */ 199, 74, 74, 74, 74, 74, 74, 74, 74, 74, /* 90 */ 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, /* 100 */ 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, /* 110 */ 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, /* 120 */ 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - /* 130 */ 74, 74, 413, 413, 413, 366, 366, 366, 413, 366, - /* 140 */ 413, 371, 370, 368, 383, 381, 388, 393, 402, 410, - /* 150 */ 420, 413, 413, 413, 382, 6, 6, 413, 413, 399, - /* 160 */ 401, 507, 476, 475, 508, 477, 481, 382, 413, 485, - /* 170 */ 485, 413, 485, 413, 485, 413, 672, 672, 27, 100, - /* 180 */ 127, 100, 100, 53, 182, 280, 280, 280, 280, 259, - /* 190 */ 281, 298, 338, 338, 338, 338, 22, 14, 92, 92, - /* 200 */ 246, 293, 284, 144, 331, 294, 295, 300, 302, 307, - /* 210 */ 308, 309, 224, 251, 319, 306, 310, 315, 316, 317, - /* 220 */ 318, 323, 258, 296, 303, 305, 325, 311, 374, 397, - /* 230 */ 369, 385, 560, 424, 565, 567, 428, 571, 573, 489, - /* 240 */ 491, 446, 469, 478, 479, 470, 482, 493, 483, 503, - /* 250 */ 505, 499, 509, 585, 510, 511, 513, 506, 496, 512, - /* 260 */ 497, 517, 519, 514, 520, 478, 522, 521, 523, 524, - /* 270 */ 553, 621, 626, 628, 629, 630, 631, 557, 623, 563, - /* 280 */ 501, 532, 532, 627, 515, 516, 532, 637, 639, 540, - /* 290 */ 532, 641, 642, 643, 644, 645, 646, 647, 648, 651, - /* 300 */ 652, 653, 654, 655, 656, 657, 658, 659, 556, 586, - /* 310 */ 649, 650, 607, 609, 669, + /* 130 */ 74, 407, 407, 407, 357, 357, 357, 407, 357, 407, + /* 140 */ 362, 363, 360, 370, 374, 385, 398, 402, 410, 413, + /* 150 */ 407, 407, 407, 372, 9, 9, 407, 407, 455, 462, + /* 160 */ 501, 469, 468, 500, 471, 474, 372, 407, 481, 481, + /* 170 */ 407, 481, 407, 481, 407, 675, 675, 27, 100, 127, + /* 180 */ 100, 100, 53, 182, 280, 280, 280, 280, 259, 281, + /* 190 */ 298, 338, 338, 338, 338, 22, 14, 92, 92, 246, + /* 200 */ 293, 284, 144, 331, 152, 269, 282, 294, 297, 300, + /* 210 */ 361, 313, 244, 248, 291, 302, 303, 309, 310, 316, + /* 220 */ 277, 285, 288, 292, 328, 299, 428, 434, 352, 380, + /* 230 */ 556, 417, 558, 563, 424, 565, 566, 482, 484, 440, + /* 240 */ 463, 465, 487, 472, 492, 489, 494, 496, 497, 498, + /* 250 */ 499, 600, 504, 505, 507, 503, 486, 506, 490, 509, + /* 260 */ 512, 508, 513, 487, 514, 515, 516, 517, 545, 614, + /* 270 */ 619, 621, 622, 623, 624, 550, 616, 557, 493, 525, + /* 280 */ 525, 620, 502, 510, 525, 630, 632, 533, 525, 634, + /* 290 */ 635, 637, 638, 639, 640, 641, 642, 643, 645, 646, + /* 300 */ 647, 648, 649, 650, 651, 652, 549, 579, 644, 653, + /* 310 */ 601, 603, 660, }; -#define YY_REDUCE_COUNT (177) +#define YY_REDUCE_COUNT (176) #define YY_REDUCE_MIN (-244) -#define YY_REDUCE_MAX (416) +#define YY_REDUCE_MAX (405) static const short yy_reduce_ofst[] = { /* 0 */ -177, -26, -26, 67, 67, 17, -229, -215, -172, -175, /* 10 */ -7, 62, 78, 125, 149, 151, 155, -184, -187, -232, - /* 20 */ -205, -8, 47, 68, -190, -9, -185, 44, 101, -188, - /* 30 */ 41, -78, -77, 98, -53, 5, 138, 20, 153, -244, - /* 40 */ -239, -216, -193, -143, -136, -106, 8, 25, 37, 85, - /* 50 */ 89, 139, 142, 185, 187, 189, 200, 201, 202, 171, - /* 60 */ 198, 228, 229, 230, 232, 234, 235, 236, 267, 269, - /* 70 */ 273, 214, 276, 238, 239, 277, 278, 279, 207, 212, - /* 80 */ 240, 241, 285, 286, 288, 289, 291, 292, 299, 301, - /* 90 */ 304, 312, 313, 314, 320, 321, 322, 324, 326, 327, - /* 100 */ 328, 329, 330, 332, 333, 334, 335, 336, 337, 339, - /* 110 */ 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, - /* 120 */ 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, - /* 130 */ 360, 361, 362, 363, 364, 226, 242, 243, 365, 244, - /* 140 */ 367, 245, 247, 256, 262, 265, 248, 274, 372, 249, - /* 150 */ 373, 375, 376, 377, 260, 378, 379, 380, 386, 384, - /* 160 */ 387, 389, 391, 392, 395, 396, 390, 394, 398, 403, - /* 170 */ 406, 409, 411, 414, 412, 415, 404, 416, + /* 20 */ -205, -124, -90, -8, -190, -185, 34, 24, -188, 41, + /* 30 */ -78, -77, 21, 5, 121, 52, 136, 83, -244, -239, + /* 40 */ -216, -193, -143, -136, -33, -14, 31, 43, 85, 89, + /* 50 */ 139, 142, 162, 165, 171, 185, 189, 193, 210, 211, + /* 60 */ 223, 224, 225, 226, 227, 228, 229, 257, 215, 266, + /* 70 */ 230, 267, 208, 270, 271, 272, 274, 201, 207, 232, + /* 80 */ 233, 278, 283, 286, 287, 295, 296, 301, 304, 305, + /* 90 */ 306, 307, 308, 311, 312, 314, 315, 317, 318, 319, + /* 100 */ 320, 321, 322, 323, 324, 325, 326, 327, 329, 330, + /* 110 */ 332, 333, 334, 335, 336, 337, 339, 340, 341, 342, + /* 120 */ 343, 344, 345, 346, 347, 348, 349, 350, 351, 353, + /* 130 */ 354, 279, 355, 356, 217, 218, 234, 358, 235, 359, + /* 140 */ 236, 238, 237, 255, 260, 239, 364, 240, 365, 241, + /* 150 */ 366, 367, 368, 254, 369, 371, 373, 375, 376, 378, + /* 160 */ 377, 379, 381, 384, 386, 387, 382, 383, 389, 396, + /* 170 */ 388, 399, 401, 403, 405, 393, 400, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 777, 889, 835, 901, 823, 832, 1032, 1032, 777, 777, - /* 10 */ 777, 777, 777, 777, 777, 777, 777, 948, 796, 1032, - /* 20 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 832, - /* 30 */ 777, 777, 838, 832, 838, 838, 943, 873, 891, 777, - /* 40 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 50 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 60 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 70 */ 777, 950, 953, 777, 777, 955, 777, 777, 975, 975, - /* 80 */ 941, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 90 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 100 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 821, - /* 110 */ 777, 819, 777, 777, 777, 777, 777, 777, 777, 777, - /* 120 */ 777, 777, 777, 777, 777, 777, 806, 777, 777, 777, - /* 130 */ 777, 777, 798, 798, 798, 777, 777, 777, 798, 777, - /* 140 */ 798, 982, 986, 980, 968, 976, 967, 963, 961, 960, - /* 150 */ 990, 798, 798, 798, 836, 832, 832, 798, 798, 854, - /* 160 */ 852, 850, 842, 848, 844, 846, 840, 824, 798, 830, - /* 170 */ 830, 798, 830, 798, 830, 798, 873, 891, 777, 991, - /* 180 */ 777, 1031, 981, 1021, 1020, 1027, 1019, 1018, 1017, 777, - /* 190 */ 777, 777, 1013, 1014, 1016, 1015, 777, 777, 1023, 1022, - /* 200 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 210 */ 777, 777, 777, 993, 777, 987, 983, 777, 777, 777, - /* 220 */ 777, 777, 777, 777, 777, 777, 903, 777, 777, 777, - /* 230 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 240 */ 777, 777, 940, 777, 777, 777, 777, 951, 777, 777, - /* 250 */ 777, 777, 777, 777, 777, 777, 777, 977, 777, 969, - /* 260 */ 777, 777, 777, 777, 777, 915, 777, 777, 777, 777, - /* 270 */ 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 280 */ 777, 1043, 1041, 777, 777, 777, 1037, 777, 777, 777, - /* 290 */ 1035, 777, 777, 777, 777, 777, 777, 777, 777, 777, - /* 300 */ 777, 777, 777, 777, 777, 777, 777, 777, 857, 777, - /* 310 */ 804, 802, 777, 794, 777, + /* 0 */ 773, 885, 831, 897, 819, 828, 1027, 1027, 773, 773, + /* 10 */ 773, 773, 773, 773, 773, 773, 773, 944, 792, 1027, + /* 20 */ 773, 773, 773, 773, 773, 773, 773, 773, 828, 773, + /* 30 */ 773, 834, 828, 834, 834, 939, 869, 887, 773, 773, + /* 40 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 50 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 60 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 70 */ 773, 773, 946, 948, 950, 773, 773, 970, 970, 937, + /* 80 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 90 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 100 */ 773, 773, 773, 773, 773, 773, 773, 773, 817, 773, + /* 110 */ 815, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 120 */ 773, 773, 773, 773, 773, 802, 773, 773, 773, 773, + /* 130 */ 773, 794, 794, 794, 773, 773, 773, 794, 773, 794, + /* 140 */ 977, 981, 975, 963, 971, 962, 958, 956, 955, 985, + /* 150 */ 794, 794, 794, 832, 828, 828, 794, 794, 850, 848, + /* 160 */ 846, 838, 844, 840, 842, 836, 820, 794, 826, 826, + /* 170 */ 794, 826, 794, 826, 794, 869, 887, 773, 986, 773, + /* 180 */ 1026, 976, 1016, 1015, 1022, 1014, 1013, 1012, 773, 773, + /* 190 */ 773, 1008, 1009, 1011, 1010, 773, 773, 1018, 1017, 773, + /* 200 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 210 */ 773, 988, 773, 982, 978, 773, 773, 773, 773, 773, + /* 220 */ 773, 773, 773, 773, 899, 773, 773, 773, 773, 773, + /* 230 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 240 */ 773, 936, 773, 773, 773, 947, 773, 773, 773, 773, + /* 250 */ 773, 773, 773, 773, 773, 972, 773, 964, 773, 773, + /* 260 */ 773, 773, 773, 911, 773, 773, 773, 773, 773, 773, + /* 270 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 1038, + /* 280 */ 1036, 773, 773, 773, 1032, 773, 773, 773, 1030, 773, + /* 290 */ 773, 773, 773, 773, 773, 773, 773, 773, 773, 773, + /* 300 */ 773, 773, 773, 773, 773, 773, 853, 773, 800, 798, + /* 310 */ 773, 790, 773, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1201,103 +1202,102 @@ static const char *const yyRuleName[] = { /* 169 */ "distinct ::= DISTINCT", /* 170 */ "distinct ::=", /* 171 */ "from ::= FROM tablelist", - /* 172 */ "from ::= FROM LP union RP", - /* 173 */ "tablelist ::= ids cpxName", - /* 174 */ "tablelist ::= ids cpxName ids", - /* 175 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 176 */ "tablelist ::= tablelist COMMA ids cpxName ids", - /* 177 */ "tmvar ::= VARIABLE", - /* 178 */ "interval_opt ::= INTERVAL LP tmvar RP", - /* 179 */ "interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP", - /* 180 */ "interval_opt ::=", - /* 181 */ "session_option ::=", - /* 182 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 183 */ "fill_opt ::=", - /* 184 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 185 */ "fill_opt ::= FILL LP ID RP", - /* 186 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 187 */ "sliding_opt ::=", - /* 188 */ "orderby_opt ::=", - /* 189 */ "orderby_opt ::= ORDER BY sortlist", - /* 190 */ "sortlist ::= sortlist COMMA item sortorder", - /* 191 */ "sortlist ::= item sortorder", - /* 192 */ "item ::= ids cpxName", - /* 193 */ "sortorder ::= ASC", - /* 194 */ "sortorder ::= DESC", - /* 195 */ "sortorder ::=", - /* 196 */ "groupby_opt ::=", - /* 197 */ "groupby_opt ::= GROUP BY grouplist", - /* 198 */ "grouplist ::= grouplist COMMA item", - /* 199 */ "grouplist ::= item", - /* 200 */ "having_opt ::=", - /* 201 */ "having_opt ::= HAVING expr", - /* 202 */ "limit_opt ::=", - /* 203 */ "limit_opt ::= LIMIT signed", - /* 204 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 205 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 206 */ "slimit_opt ::=", - /* 207 */ "slimit_opt ::= SLIMIT signed", - /* 208 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 209 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 210 */ "where_opt ::=", - /* 211 */ "where_opt ::= WHERE expr", - /* 212 */ "expr ::= LP expr RP", - /* 213 */ "expr ::= ID", - /* 214 */ "expr ::= ID DOT ID", - /* 215 */ "expr ::= ID DOT STAR", - /* 216 */ "expr ::= INTEGER", - /* 217 */ "expr ::= MINUS INTEGER", - /* 218 */ "expr ::= PLUS INTEGER", - /* 219 */ "expr ::= FLOAT", - /* 220 */ "expr ::= MINUS FLOAT", - /* 221 */ "expr ::= PLUS FLOAT", - /* 222 */ "expr ::= STRING", - /* 223 */ "expr ::= NOW", - /* 224 */ "expr ::= VARIABLE", - /* 225 */ "expr ::= PLUS VARIABLE", - /* 226 */ "expr ::= MINUS VARIABLE", - /* 227 */ "expr ::= BOOL", - /* 228 */ "expr ::= NULL", - /* 229 */ "expr ::= ID LP exprlist RP", - /* 230 */ "expr ::= ID LP STAR RP", - /* 231 */ "expr ::= expr IS NULL", - /* 232 */ "expr ::= expr IS NOT NULL", - /* 233 */ "expr ::= expr LT expr", - /* 234 */ "expr ::= expr GT expr", - /* 235 */ "expr ::= expr LE expr", - /* 236 */ "expr ::= expr GE expr", - /* 237 */ "expr ::= expr NE expr", - /* 238 */ "expr ::= expr EQ expr", - /* 239 */ "expr ::= expr BETWEEN expr AND expr", - /* 240 */ "expr ::= expr AND expr", - /* 241 */ "expr ::= expr OR expr", - /* 242 */ "expr ::= expr PLUS expr", - /* 243 */ "expr ::= expr MINUS expr", - /* 244 */ "expr ::= expr STAR expr", - /* 245 */ "expr ::= expr SLASH expr", - /* 246 */ "expr ::= expr REM expr", - /* 247 */ "expr ::= expr LIKE expr", - /* 248 */ "expr ::= expr IN LP exprlist RP", - /* 249 */ "exprlist ::= exprlist COMMA expritem", - /* 250 */ "exprlist ::= expritem", - /* 251 */ "expritem ::= expr", - /* 252 */ "expritem ::=", - /* 253 */ "cmd ::= RESET QUERY CACHE", - /* 254 */ "cmd ::= SYNCDB ids REPLICA", - /* 255 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 256 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 257 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 258 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 259 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 260 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 261 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 262 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 263 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 264 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 265 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 266 */ "cmd ::= KILL CONNECTION INTEGER", - /* 267 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 268 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 172 */ "tablelist ::= ids cpxName", + /* 173 */ "tablelist ::= ids cpxName ids", + /* 174 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 175 */ "tablelist ::= tablelist COMMA ids cpxName ids", + /* 176 */ "tmvar ::= VARIABLE", + /* 177 */ "interval_opt ::= INTERVAL LP tmvar RP", + /* 178 */ "interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP", + /* 179 */ "interval_opt ::=", + /* 180 */ "session_option ::=", + /* 181 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 182 */ "fill_opt ::=", + /* 183 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 184 */ "fill_opt ::= FILL LP ID RP", + /* 185 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 186 */ "sliding_opt ::=", + /* 187 */ "orderby_opt ::=", + /* 188 */ "orderby_opt ::= ORDER BY sortlist", + /* 189 */ "sortlist ::= sortlist COMMA item sortorder", + /* 190 */ "sortlist ::= item sortorder", + /* 191 */ "item ::= ids cpxName", + /* 192 */ "sortorder ::= ASC", + /* 193 */ "sortorder ::= DESC", + /* 194 */ "sortorder ::=", + /* 195 */ "groupby_opt ::=", + /* 196 */ "groupby_opt ::= GROUP BY grouplist", + /* 197 */ "grouplist ::= grouplist COMMA item", + /* 198 */ "grouplist ::= item", + /* 199 */ "having_opt ::=", + /* 200 */ "having_opt ::= HAVING expr", + /* 201 */ "limit_opt ::=", + /* 202 */ "limit_opt ::= LIMIT signed", + /* 203 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 204 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 205 */ "slimit_opt ::=", + /* 206 */ "slimit_opt ::= SLIMIT signed", + /* 207 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 208 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 209 */ "where_opt ::=", + /* 210 */ "where_opt ::= WHERE expr", + /* 211 */ "expr ::= LP expr RP", + /* 212 */ "expr ::= ID", + /* 213 */ "expr ::= ID DOT ID", + /* 214 */ "expr ::= ID DOT STAR", + /* 215 */ "expr ::= INTEGER", + /* 216 */ "expr ::= MINUS INTEGER", + /* 217 */ "expr ::= PLUS INTEGER", + /* 218 */ "expr ::= FLOAT", + /* 219 */ "expr ::= MINUS FLOAT", + /* 220 */ "expr ::= PLUS FLOAT", + /* 221 */ "expr ::= STRING", + /* 222 */ "expr ::= NOW", + /* 223 */ "expr ::= VARIABLE", + /* 224 */ "expr ::= PLUS VARIABLE", + /* 225 */ "expr ::= MINUS VARIABLE", + /* 226 */ "expr ::= BOOL", + /* 227 */ "expr ::= NULL", + /* 228 */ "expr ::= ID LP exprlist RP", + /* 229 */ "expr ::= ID LP STAR RP", + /* 230 */ "expr ::= expr IS NULL", + /* 231 */ "expr ::= expr IS NOT NULL", + /* 232 */ "expr ::= expr LT expr", + /* 233 */ "expr ::= expr GT expr", + /* 234 */ "expr ::= expr LE expr", + /* 235 */ "expr ::= expr GE expr", + /* 236 */ "expr ::= expr NE expr", + /* 237 */ "expr ::= expr EQ expr", + /* 238 */ "expr ::= expr BETWEEN expr AND expr", + /* 239 */ "expr ::= expr AND expr", + /* 240 */ "expr ::= expr OR expr", + /* 241 */ "expr ::= expr PLUS expr", + /* 242 */ "expr ::= expr MINUS expr", + /* 243 */ "expr ::= expr STAR expr", + /* 244 */ "expr ::= expr SLASH expr", + /* 245 */ "expr ::= expr REM expr", + /* 246 */ "expr ::= expr LIKE expr", + /* 247 */ "expr ::= expr IN LP exprlist RP", + /* 248 */ "exprlist ::= exprlist COMMA expritem", + /* 249 */ "exprlist ::= expritem", + /* 250 */ "expritem ::= expr", + /* 251 */ "expritem ::=", + /* 252 */ "cmd ::= RESET QUERY CACHE", + /* 253 */ "cmd ::= SYNCDB ids REPLICA", + /* 254 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 255 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 256 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 257 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 258 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 259 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 260 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 261 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 262 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 263 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 264 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 265 */ "cmd ::= KILL CONNECTION INTEGER", + /* 266 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 267 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1929,103 +1929,102 @@ static const YYCODETYPE yyRuleInfoLhs[] = { 250, /* (169) distinct ::= DISTINCT */ 250, /* (170) distinct ::= */ 237, /* (171) from ::= FROM tablelist */ - 237, /* (172) from ::= FROM LP union RP */ - 253, /* (173) tablelist ::= ids cpxName */ - 253, /* (174) tablelist ::= ids cpxName ids */ - 253, /* (175) tablelist ::= tablelist COMMA ids cpxName */ - 253, /* (176) tablelist ::= tablelist COMMA ids cpxName ids */ - 254, /* (177) tmvar ::= VARIABLE */ - 239, /* (178) interval_opt ::= INTERVAL LP tmvar RP */ - 239, /* (179) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ - 239, /* (180) interval_opt ::= */ - 240, /* (181) session_option ::= */ - 240, /* (182) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - 241, /* (183) fill_opt ::= */ - 241, /* (184) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - 241, /* (185) fill_opt ::= FILL LP ID RP */ - 242, /* (186) sliding_opt ::= SLIDING LP tmvar RP */ - 242, /* (187) sliding_opt ::= */ - 244, /* (188) orderby_opt ::= */ - 244, /* (189) orderby_opt ::= ORDER BY sortlist */ - 255, /* (190) sortlist ::= sortlist COMMA item sortorder */ - 255, /* (191) sortlist ::= item sortorder */ - 257, /* (192) item ::= ids cpxName */ - 258, /* (193) sortorder ::= ASC */ - 258, /* (194) sortorder ::= DESC */ - 258, /* (195) sortorder ::= */ - 243, /* (196) groupby_opt ::= */ - 243, /* (197) groupby_opt ::= GROUP BY grouplist */ - 259, /* (198) grouplist ::= grouplist COMMA item */ - 259, /* (199) grouplist ::= item */ - 245, /* (200) having_opt ::= */ - 245, /* (201) having_opt ::= HAVING expr */ - 247, /* (202) limit_opt ::= */ - 247, /* (203) limit_opt ::= LIMIT signed */ - 247, /* (204) limit_opt ::= LIMIT signed OFFSET signed */ - 247, /* (205) limit_opt ::= LIMIT signed COMMA signed */ - 246, /* (206) slimit_opt ::= */ - 246, /* (207) slimit_opt ::= SLIMIT signed */ - 246, /* (208) slimit_opt ::= SLIMIT signed SOFFSET signed */ - 246, /* (209) slimit_opt ::= SLIMIT signed COMMA signed */ - 238, /* (210) where_opt ::= */ - 238, /* (211) where_opt ::= WHERE expr */ - 251, /* (212) expr ::= LP expr RP */ - 251, /* (213) expr ::= ID */ - 251, /* (214) expr ::= ID DOT ID */ - 251, /* (215) expr ::= ID DOT STAR */ - 251, /* (216) expr ::= INTEGER */ - 251, /* (217) expr ::= MINUS INTEGER */ - 251, /* (218) expr ::= PLUS INTEGER */ - 251, /* (219) expr ::= FLOAT */ - 251, /* (220) expr ::= MINUS FLOAT */ - 251, /* (221) expr ::= PLUS FLOAT */ - 251, /* (222) expr ::= STRING */ - 251, /* (223) expr ::= NOW */ - 251, /* (224) expr ::= VARIABLE */ - 251, /* (225) expr ::= PLUS VARIABLE */ - 251, /* (226) expr ::= MINUS VARIABLE */ - 251, /* (227) expr ::= BOOL */ - 251, /* (228) expr ::= NULL */ - 251, /* (229) expr ::= ID LP exprlist RP */ - 251, /* (230) expr ::= ID LP STAR RP */ - 251, /* (231) expr ::= expr IS NULL */ - 251, /* (232) expr ::= expr IS NOT NULL */ - 251, /* (233) expr ::= expr LT expr */ - 251, /* (234) expr ::= expr GT expr */ - 251, /* (235) expr ::= expr LE expr */ - 251, /* (236) expr ::= expr GE expr */ - 251, /* (237) expr ::= expr NE expr */ - 251, /* (238) expr ::= expr EQ expr */ - 251, /* (239) expr ::= expr BETWEEN expr AND expr */ - 251, /* (240) expr ::= expr AND expr */ - 251, /* (241) expr ::= expr OR expr */ - 251, /* (242) expr ::= expr PLUS expr */ - 251, /* (243) expr ::= expr MINUS expr */ - 251, /* (244) expr ::= expr STAR expr */ - 251, /* (245) expr ::= expr SLASH expr */ - 251, /* (246) expr ::= expr REM expr */ - 251, /* (247) expr ::= expr LIKE expr */ - 251, /* (248) expr ::= expr IN LP exprlist RP */ - 260, /* (249) exprlist ::= exprlist COMMA expritem */ - 260, /* (250) exprlist ::= expritem */ - 261, /* (251) expritem ::= expr */ - 261, /* (252) expritem ::= */ - 188, /* (253) cmd ::= RESET QUERY CACHE */ - 188, /* (254) cmd ::= SYNCDB ids REPLICA */ - 188, /* (255) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - 188, /* (256) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - 188, /* (257) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - 188, /* (258) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - 188, /* (259) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - 188, /* (260) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - 188, /* (261) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - 188, /* (262) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - 188, /* (263) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - 188, /* (264) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - 188, /* (265) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - 188, /* (266) cmd ::= KILL CONNECTION INTEGER */ - 188, /* (267) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - 188, /* (268) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + 253, /* (172) tablelist ::= ids cpxName */ + 253, /* (173) tablelist ::= ids cpxName ids */ + 253, /* (174) tablelist ::= tablelist COMMA ids cpxName */ + 253, /* (175) tablelist ::= tablelist COMMA ids cpxName ids */ + 254, /* (176) tmvar ::= VARIABLE */ + 239, /* (177) interval_opt ::= INTERVAL LP tmvar RP */ + 239, /* (178) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + 239, /* (179) interval_opt ::= */ + 240, /* (180) session_option ::= */ + 240, /* (181) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + 241, /* (182) fill_opt ::= */ + 241, /* (183) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + 241, /* (184) fill_opt ::= FILL LP ID RP */ + 242, /* (185) sliding_opt ::= SLIDING LP tmvar RP */ + 242, /* (186) sliding_opt ::= */ + 244, /* (187) orderby_opt ::= */ + 244, /* (188) orderby_opt ::= ORDER BY sortlist */ + 255, /* (189) sortlist ::= sortlist COMMA item sortorder */ + 255, /* (190) sortlist ::= item sortorder */ + 257, /* (191) item ::= ids cpxName */ + 258, /* (192) sortorder ::= ASC */ + 258, /* (193) sortorder ::= DESC */ + 258, /* (194) sortorder ::= */ + 243, /* (195) groupby_opt ::= */ + 243, /* (196) groupby_opt ::= GROUP BY grouplist */ + 259, /* (197) grouplist ::= grouplist COMMA item */ + 259, /* (198) grouplist ::= item */ + 245, /* (199) having_opt ::= */ + 245, /* (200) having_opt ::= HAVING expr */ + 247, /* (201) limit_opt ::= */ + 247, /* (202) limit_opt ::= LIMIT signed */ + 247, /* (203) limit_opt ::= LIMIT signed OFFSET signed */ + 247, /* (204) limit_opt ::= LIMIT signed COMMA signed */ + 246, /* (205) slimit_opt ::= */ + 246, /* (206) slimit_opt ::= SLIMIT signed */ + 246, /* (207) slimit_opt ::= SLIMIT signed SOFFSET signed */ + 246, /* (208) slimit_opt ::= SLIMIT signed COMMA signed */ + 238, /* (209) where_opt ::= */ + 238, /* (210) where_opt ::= WHERE expr */ + 251, /* (211) expr ::= LP expr RP */ + 251, /* (212) expr ::= ID */ + 251, /* (213) expr ::= ID DOT ID */ + 251, /* (214) expr ::= ID DOT STAR */ + 251, /* (215) expr ::= INTEGER */ + 251, /* (216) expr ::= MINUS INTEGER */ + 251, /* (217) expr ::= PLUS INTEGER */ + 251, /* (218) expr ::= FLOAT */ + 251, /* (219) expr ::= MINUS FLOAT */ + 251, /* (220) expr ::= PLUS FLOAT */ + 251, /* (221) expr ::= STRING */ + 251, /* (222) expr ::= NOW */ + 251, /* (223) expr ::= VARIABLE */ + 251, /* (224) expr ::= PLUS VARIABLE */ + 251, /* (225) expr ::= MINUS VARIABLE */ + 251, /* (226) expr ::= BOOL */ + 251, /* (227) expr ::= NULL */ + 251, /* (228) expr ::= ID LP exprlist RP */ + 251, /* (229) expr ::= ID LP STAR RP */ + 251, /* (230) expr ::= expr IS NULL */ + 251, /* (231) expr ::= expr IS NOT NULL */ + 251, /* (232) expr ::= expr LT expr */ + 251, /* (233) expr ::= expr GT expr */ + 251, /* (234) expr ::= expr LE expr */ + 251, /* (235) expr ::= expr GE expr */ + 251, /* (236) expr ::= expr NE expr */ + 251, /* (237) expr ::= expr EQ expr */ + 251, /* (238) expr ::= expr BETWEEN expr AND expr */ + 251, /* (239) expr ::= expr AND expr */ + 251, /* (240) expr ::= expr OR expr */ + 251, /* (241) expr ::= expr PLUS expr */ + 251, /* (242) expr ::= expr MINUS expr */ + 251, /* (243) expr ::= expr STAR expr */ + 251, /* (244) expr ::= expr SLASH expr */ + 251, /* (245) expr ::= expr REM expr */ + 251, /* (246) expr ::= expr LIKE expr */ + 251, /* (247) expr ::= expr IN LP exprlist RP */ + 260, /* (248) exprlist ::= exprlist COMMA expritem */ + 260, /* (249) exprlist ::= expritem */ + 261, /* (250) expritem ::= expr */ + 261, /* (251) expritem ::= */ + 188, /* (252) cmd ::= RESET QUERY CACHE */ + 188, /* (253) cmd ::= SYNCDB ids REPLICA */ + 188, /* (254) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + 188, /* (255) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + 188, /* (256) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + 188, /* (257) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + 188, /* (258) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + 188, /* (259) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + 188, /* (260) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + 188, /* (261) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + 188, /* (262) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + 188, /* (263) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + 188, /* (264) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + 188, /* (265) cmd ::= KILL CONNECTION INTEGER */ + 188, /* (266) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + 188, /* (267) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number @@ -2203,103 +2202,102 @@ static const signed char yyRuleInfoNRhs[] = { -1, /* (169) distinct ::= DISTINCT */ 0, /* (170) distinct ::= */ -2, /* (171) from ::= FROM tablelist */ - -4, /* (172) from ::= FROM LP union RP */ - -2, /* (173) tablelist ::= ids cpxName */ - -3, /* (174) tablelist ::= ids cpxName ids */ - -4, /* (175) tablelist ::= tablelist COMMA ids cpxName */ - -5, /* (176) tablelist ::= tablelist COMMA ids cpxName ids */ - -1, /* (177) tmvar ::= VARIABLE */ - -4, /* (178) interval_opt ::= INTERVAL LP tmvar RP */ - -6, /* (179) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ - 0, /* (180) interval_opt ::= */ - 0, /* (181) session_option ::= */ - -7, /* (182) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - 0, /* (183) fill_opt ::= */ - -6, /* (184) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - -4, /* (185) fill_opt ::= FILL LP ID RP */ - -4, /* (186) sliding_opt ::= SLIDING LP tmvar RP */ - 0, /* (187) sliding_opt ::= */ - 0, /* (188) orderby_opt ::= */ - -3, /* (189) orderby_opt ::= ORDER BY sortlist */ - -4, /* (190) sortlist ::= sortlist COMMA item sortorder */ - -2, /* (191) sortlist ::= item sortorder */ - -2, /* (192) item ::= ids cpxName */ - -1, /* (193) sortorder ::= ASC */ - -1, /* (194) sortorder ::= DESC */ - 0, /* (195) sortorder ::= */ - 0, /* (196) groupby_opt ::= */ - -3, /* (197) groupby_opt ::= GROUP BY grouplist */ - -3, /* (198) grouplist ::= grouplist COMMA item */ - -1, /* (199) grouplist ::= item */ - 0, /* (200) having_opt ::= */ - -2, /* (201) having_opt ::= HAVING expr */ - 0, /* (202) limit_opt ::= */ - -2, /* (203) limit_opt ::= LIMIT signed */ - -4, /* (204) limit_opt ::= LIMIT signed OFFSET signed */ - -4, /* (205) limit_opt ::= LIMIT signed COMMA signed */ - 0, /* (206) slimit_opt ::= */ - -2, /* (207) slimit_opt ::= SLIMIT signed */ - -4, /* (208) slimit_opt ::= SLIMIT signed SOFFSET signed */ - -4, /* (209) slimit_opt ::= SLIMIT signed COMMA signed */ - 0, /* (210) where_opt ::= */ - -2, /* (211) where_opt ::= WHERE expr */ - -3, /* (212) expr ::= LP expr RP */ - -1, /* (213) expr ::= ID */ - -3, /* (214) expr ::= ID DOT ID */ - -3, /* (215) expr ::= ID DOT STAR */ - -1, /* (216) expr ::= INTEGER */ - -2, /* (217) expr ::= MINUS INTEGER */ - -2, /* (218) expr ::= PLUS INTEGER */ - -1, /* (219) expr ::= FLOAT */ - -2, /* (220) expr ::= MINUS FLOAT */ - -2, /* (221) expr ::= PLUS FLOAT */ - -1, /* (222) expr ::= STRING */ - -1, /* (223) expr ::= NOW */ - -1, /* (224) expr ::= VARIABLE */ - -2, /* (225) expr ::= PLUS VARIABLE */ - -2, /* (226) expr ::= MINUS VARIABLE */ - -1, /* (227) expr ::= BOOL */ - -1, /* (228) expr ::= NULL */ - -4, /* (229) expr ::= ID LP exprlist RP */ - -4, /* (230) expr ::= ID LP STAR RP */ - -3, /* (231) expr ::= expr IS NULL */ - -4, /* (232) expr ::= expr IS NOT NULL */ - -3, /* (233) expr ::= expr LT expr */ - -3, /* (234) expr ::= expr GT expr */ - -3, /* (235) expr ::= expr LE expr */ - -3, /* (236) expr ::= expr GE expr */ - -3, /* (237) expr ::= expr NE expr */ - -3, /* (238) expr ::= expr EQ expr */ - -5, /* (239) expr ::= expr BETWEEN expr AND expr */ - -3, /* (240) expr ::= expr AND expr */ - -3, /* (241) expr ::= expr OR expr */ - -3, /* (242) expr ::= expr PLUS expr */ - -3, /* (243) expr ::= expr MINUS expr */ - -3, /* (244) expr ::= expr STAR expr */ - -3, /* (245) expr ::= expr SLASH expr */ - -3, /* (246) expr ::= expr REM expr */ - -3, /* (247) expr ::= expr LIKE expr */ - -5, /* (248) expr ::= expr IN LP exprlist RP */ - -3, /* (249) exprlist ::= exprlist COMMA expritem */ - -1, /* (250) exprlist ::= expritem */ - -1, /* (251) expritem ::= expr */ - 0, /* (252) expritem ::= */ - -3, /* (253) cmd ::= RESET QUERY CACHE */ - -3, /* (254) cmd ::= SYNCDB ids REPLICA */ - -7, /* (255) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - -7, /* (256) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - -7, /* (257) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - -7, /* (258) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - -8, /* (259) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - -9, /* (260) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - -7, /* (261) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - -7, /* (262) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - -7, /* (263) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - -7, /* (264) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - -8, /* (265) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - -3, /* (266) cmd ::= KILL CONNECTION INTEGER */ - -5, /* (267) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - -5, /* (268) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + -2, /* (172) tablelist ::= ids cpxName */ + -3, /* (173) tablelist ::= ids cpxName ids */ + -4, /* (174) tablelist ::= tablelist COMMA ids cpxName */ + -5, /* (175) tablelist ::= tablelist COMMA ids cpxName ids */ + -1, /* (176) tmvar ::= VARIABLE */ + -4, /* (177) interval_opt ::= INTERVAL LP tmvar RP */ + -6, /* (178) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + 0, /* (179) interval_opt ::= */ + 0, /* (180) session_option ::= */ + -7, /* (181) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + 0, /* (182) fill_opt ::= */ + -6, /* (183) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + -4, /* (184) fill_opt ::= FILL LP ID RP */ + -4, /* (185) sliding_opt ::= SLIDING LP tmvar RP */ + 0, /* (186) sliding_opt ::= */ + 0, /* (187) orderby_opt ::= */ + -3, /* (188) orderby_opt ::= ORDER BY sortlist */ + -4, /* (189) sortlist ::= sortlist COMMA item sortorder */ + -2, /* (190) sortlist ::= item sortorder */ + -2, /* (191) item ::= ids cpxName */ + -1, /* (192) sortorder ::= ASC */ + -1, /* (193) sortorder ::= DESC */ + 0, /* (194) sortorder ::= */ + 0, /* (195) groupby_opt ::= */ + -3, /* (196) groupby_opt ::= GROUP BY grouplist */ + -3, /* (197) grouplist ::= grouplist COMMA item */ + -1, /* (198) grouplist ::= item */ + 0, /* (199) having_opt ::= */ + -2, /* (200) having_opt ::= HAVING expr */ + 0, /* (201) limit_opt ::= */ + -2, /* (202) limit_opt ::= LIMIT signed */ + -4, /* (203) limit_opt ::= LIMIT signed OFFSET signed */ + -4, /* (204) limit_opt ::= LIMIT signed COMMA signed */ + 0, /* (205) slimit_opt ::= */ + -2, /* (206) slimit_opt ::= SLIMIT signed */ + -4, /* (207) slimit_opt ::= SLIMIT signed SOFFSET signed */ + -4, /* (208) slimit_opt ::= SLIMIT signed COMMA signed */ + 0, /* (209) where_opt ::= */ + -2, /* (210) where_opt ::= WHERE expr */ + -3, /* (211) expr ::= LP expr RP */ + -1, /* (212) expr ::= ID */ + -3, /* (213) expr ::= ID DOT ID */ + -3, /* (214) expr ::= ID DOT STAR */ + -1, /* (215) expr ::= INTEGER */ + -2, /* (216) expr ::= MINUS INTEGER */ + -2, /* (217) expr ::= PLUS INTEGER */ + -1, /* (218) expr ::= FLOAT */ + -2, /* (219) expr ::= MINUS FLOAT */ + -2, /* (220) expr ::= PLUS FLOAT */ + -1, /* (221) expr ::= STRING */ + -1, /* (222) expr ::= NOW */ + -1, /* (223) expr ::= VARIABLE */ + -2, /* (224) expr ::= PLUS VARIABLE */ + -2, /* (225) expr ::= MINUS VARIABLE */ + -1, /* (226) expr ::= BOOL */ + -1, /* (227) expr ::= NULL */ + -4, /* (228) expr ::= ID LP exprlist RP */ + -4, /* (229) expr ::= ID LP STAR RP */ + -3, /* (230) expr ::= expr IS NULL */ + -4, /* (231) expr ::= expr IS NOT NULL */ + -3, /* (232) expr ::= expr LT expr */ + -3, /* (233) expr ::= expr GT expr */ + -3, /* (234) expr ::= expr LE expr */ + -3, /* (235) expr ::= expr GE expr */ + -3, /* (236) expr ::= expr NE expr */ + -3, /* (237) expr ::= expr EQ expr */ + -5, /* (238) expr ::= expr BETWEEN expr AND expr */ + -3, /* (239) expr ::= expr AND expr */ + -3, /* (240) expr ::= expr OR expr */ + -3, /* (241) expr ::= expr PLUS expr */ + -3, /* (242) expr ::= expr MINUS expr */ + -3, /* (243) expr ::= expr STAR expr */ + -3, /* (244) expr ::= expr SLASH expr */ + -3, /* (245) expr ::= expr REM expr */ + -3, /* (246) expr ::= expr LIKE expr */ + -5, /* (247) expr ::= expr IN LP exprlist RP */ + -3, /* (248) exprlist ::= exprlist COMMA expritem */ + -1, /* (249) exprlist ::= expritem */ + -1, /* (250) expritem ::= expr */ + 0, /* (251) expritem ::= */ + -3, /* (252) cmd ::= RESET QUERY CACHE */ + -3, /* (253) cmd ::= SYNCDB ids REPLICA */ + -7, /* (254) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + -7, /* (255) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + -7, /* (256) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + -7, /* (257) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + -8, /* (258) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + -9, /* (259) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + -7, /* (260) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + -7, /* (261) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + -7, /* (262) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + -7, /* (263) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + -8, /* (264) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + -3, /* (265) cmd ::= KILL CONNECTION INTEGER */ + -5, /* (266) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + -5, /* (267) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2922,7 +2920,7 @@ static YYACTIONTYPE yy_reduce( yymsp[-1].minor.yy429 = yylhsminor.yy429; break; case 163: /* sclp ::= */ - case 188: /* orderby_opt ::= */ yytestcase(yyruleno==188); + case 187: /* orderby_opt ::= */ yytestcase(yyruleno==187); {yymsp[1].minor.yy429 = 0;} break; case 164: /* selcollist ::= sclp distinct expr as */ @@ -2955,10 +2953,7 @@ static YYACTIONTYPE yy_reduce( case 171: /* from ::= FROM tablelist */ {yymsp[-1].minor.yy70 = yymsp[0].minor.yy429;} break; - case 172: /* from ::= FROM LP union RP */ -{yymsp[-3].minor.yy70 = yymsp[-1].minor.yy141;} - break; - case 173: /* tablelist ::= ids cpxName */ + case 172: /* tablelist ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; @@ -2966,7 +2961,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-1].minor.yy429 = yylhsminor.yy429; break; - case 174: /* tablelist ::= ids cpxName ids */ + case 173: /* tablelist ::= ids cpxName ids */ { toTSDBType(yymsp[-2].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type); @@ -2975,7 +2970,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy429 = yylhsminor.yy429; break; - case 175: /* tablelist ::= tablelist COMMA ids cpxName */ + case 174: /* tablelist ::= tablelist COMMA ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; @@ -2983,7 +2978,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-3].minor.yy429 = yylhsminor.yy429; break; - case 176: /* tablelist ::= tablelist COMMA ids cpxName ids */ + case 175: /* tablelist ::= tablelist COMMA ids cpxName ids */ { toTSDBType(yymsp[-2].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type); @@ -2993,33 +2988,33 @@ static YYACTIONTYPE yy_reduce( } yymsp[-4].minor.yy429 = yylhsminor.yy429; break; - case 177: /* tmvar ::= VARIABLE */ + case 176: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 178: /* interval_opt ::= INTERVAL LP tmvar RP */ + case 177: /* interval_opt ::= INTERVAL LP tmvar RP */ {yymsp[-3].minor.yy220.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy220.offset.n = 0;} break; - case 179: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + case 178: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ {yymsp[-5].minor.yy220.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy220.offset = yymsp[-1].minor.yy0;} break; - case 180: /* interval_opt ::= */ + case 179: /* interval_opt ::= */ {memset(&yymsp[1].minor.yy220, 0, sizeof(yymsp[1].minor.yy220));} break; - case 181: /* session_option ::= */ + case 180: /* session_option ::= */ {yymsp[1].minor.yy87.col.n = 0; yymsp[1].minor.yy87.gap.n = 0;} break; - case 182: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 181: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-6].minor.yy87.col = yymsp[-4].minor.yy0; yymsp[-6].minor.yy87.gap = yymsp[-1].minor.yy0; } break; - case 183: /* fill_opt ::= */ + case 182: /* fill_opt ::= */ { yymsp[1].minor.yy429 = 0; } break; - case 184: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 183: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { tVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); @@ -3029,34 +3024,34 @@ static YYACTIONTYPE yy_reduce( yymsp[-5].minor.yy429 = yymsp[-1].minor.yy429; } break; - case 185: /* fill_opt ::= FILL LP ID RP */ + case 184: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-3].minor.yy429 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 186: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 185: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 187: /* sliding_opt ::= */ + case 186: /* sliding_opt ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 189: /* orderby_opt ::= ORDER BY sortlist */ + case 188: /* orderby_opt ::= ORDER BY sortlist */ {yymsp[-2].minor.yy429 = yymsp[0].minor.yy429;} break; - case 190: /* sortlist ::= sortlist COMMA item sortorder */ + case 189: /* sortlist ::= sortlist COMMA item sortorder */ { yylhsminor.yy429 = tVariantListAppend(yymsp[-3].minor.yy429, &yymsp[-1].minor.yy218, yymsp[0].minor.yy116); } yymsp[-3].minor.yy429 = yylhsminor.yy429; break; - case 191: /* sortlist ::= item sortorder */ + case 190: /* sortlist ::= item sortorder */ { yylhsminor.yy429 = tVariantListAppend(NULL, &yymsp[-1].minor.yy218, yymsp[0].minor.yy116); } yymsp[-1].minor.yy429 = yylhsminor.yy429; break; - case 192: /* item ::= ids cpxName */ + case 191: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; @@ -3065,227 +3060,227 @@ static YYACTIONTYPE yy_reduce( } yymsp[-1].minor.yy218 = yylhsminor.yy218; break; - case 193: /* sortorder ::= ASC */ + case 192: /* sortorder ::= ASC */ { yymsp[0].minor.yy116 = TSDB_ORDER_ASC; } break; - case 194: /* sortorder ::= DESC */ + case 193: /* sortorder ::= DESC */ { yymsp[0].minor.yy116 = TSDB_ORDER_DESC;} break; - case 195: /* sortorder ::= */ + case 194: /* sortorder ::= */ { yymsp[1].minor.yy116 = TSDB_ORDER_ASC; } break; - case 196: /* groupby_opt ::= */ + case 195: /* groupby_opt ::= */ { yymsp[1].minor.yy429 = 0;} break; - case 197: /* groupby_opt ::= GROUP BY grouplist */ + case 196: /* groupby_opt ::= GROUP BY grouplist */ { yymsp[-2].minor.yy429 = yymsp[0].minor.yy429;} break; - case 198: /* grouplist ::= grouplist COMMA item */ + case 197: /* grouplist ::= grouplist COMMA item */ { yylhsminor.yy429 = tVariantListAppend(yymsp[-2].minor.yy429, &yymsp[0].minor.yy218, -1); } yymsp[-2].minor.yy429 = yylhsminor.yy429; break; - case 199: /* grouplist ::= item */ + case 198: /* grouplist ::= item */ { yylhsminor.yy429 = tVariantListAppend(NULL, &yymsp[0].minor.yy218, -1); } yymsp[0].minor.yy429 = yylhsminor.yy429; break; - case 200: /* having_opt ::= */ - case 210: /* where_opt ::= */ yytestcase(yyruleno==210); - case 252: /* expritem ::= */ yytestcase(yyruleno==252); + case 199: /* having_opt ::= */ + case 209: /* where_opt ::= */ yytestcase(yyruleno==209); + case 251: /* expritem ::= */ yytestcase(yyruleno==251); {yymsp[1].minor.yy170 = 0;} break; - case 201: /* having_opt ::= HAVING expr */ - case 211: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==211); + case 200: /* having_opt ::= HAVING expr */ + case 210: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==210); {yymsp[-1].minor.yy170 = yymsp[0].minor.yy170;} break; - case 202: /* limit_opt ::= */ - case 206: /* slimit_opt ::= */ yytestcase(yyruleno==206); + case 201: /* limit_opt ::= */ + case 205: /* slimit_opt ::= */ yytestcase(yyruleno==205); {yymsp[1].minor.yy18.limit = -1; yymsp[1].minor.yy18.offset = 0;} break; - case 203: /* limit_opt ::= LIMIT signed */ - case 207: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==207); + case 202: /* limit_opt ::= LIMIT signed */ + case 206: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==206); {yymsp[-1].minor.yy18.limit = yymsp[0].minor.yy481; yymsp[-1].minor.yy18.offset = 0;} break; - case 204: /* limit_opt ::= LIMIT signed OFFSET signed */ + case 203: /* limit_opt ::= LIMIT signed OFFSET signed */ { yymsp[-3].minor.yy18.limit = yymsp[-2].minor.yy481; yymsp[-3].minor.yy18.offset = yymsp[0].minor.yy481;} break; - case 205: /* limit_opt ::= LIMIT signed COMMA signed */ + case 204: /* limit_opt ::= LIMIT signed COMMA signed */ { yymsp[-3].minor.yy18.limit = yymsp[0].minor.yy481; yymsp[-3].minor.yy18.offset = yymsp[-2].minor.yy481;} break; - case 208: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ + case 207: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ {yymsp[-3].minor.yy18.limit = yymsp[-2].minor.yy481; yymsp[-3].minor.yy18.offset = yymsp[0].minor.yy481;} break; - case 209: /* slimit_opt ::= SLIMIT signed COMMA signed */ + case 208: /* slimit_opt ::= SLIMIT signed COMMA signed */ {yymsp[-3].minor.yy18.limit = yymsp[0].minor.yy481; yymsp[-3].minor.yy18.offset = yymsp[-2].minor.yy481;} break; - case 212: /* expr ::= LP expr RP */ + case 211: /* expr ::= LP expr RP */ {yylhsminor.yy170 = yymsp[-1].minor.yy170; yylhsminor.yy170->token.z = yymsp[-2].minor.yy0.z; yylhsminor.yy170->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 213: /* expr ::= ID */ + case 212: /* expr ::= ID */ { yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 214: /* expr ::= ID DOT ID */ + case 213: /* expr ::= ID DOT ID */ { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 215: /* expr ::= ID DOT STAR */ + case 214: /* expr ::= ID DOT STAR */ { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 216: /* expr ::= INTEGER */ + case 215: /* expr ::= INTEGER */ { yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 217: /* expr ::= MINUS INTEGER */ - case 218: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==218); + case 216: /* expr ::= MINUS INTEGER */ + case 217: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==217); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} yymsp[-1].minor.yy170 = yylhsminor.yy170; break; - case 219: /* expr ::= FLOAT */ + case 218: /* expr ::= FLOAT */ { yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 220: /* expr ::= MINUS FLOAT */ - case 221: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==221); + case 219: /* expr ::= MINUS FLOAT */ + case 220: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==220); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} yymsp[-1].minor.yy170 = yylhsminor.yy170; break; - case 222: /* expr ::= STRING */ + case 221: /* expr ::= STRING */ { yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 223: /* expr ::= NOW */ + case 222: /* expr ::= NOW */ { yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 224: /* expr ::= VARIABLE */ + case 223: /* expr ::= VARIABLE */ { yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 225: /* expr ::= PLUS VARIABLE */ - case 226: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==226); + case 224: /* expr ::= PLUS VARIABLE */ + case 225: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==225); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} yymsp[-1].minor.yy170 = yylhsminor.yy170; break; - case 227: /* expr ::= BOOL */ + case 226: /* expr ::= BOOL */ { yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 228: /* expr ::= NULL */ + case 227: /* expr ::= NULL */ { yylhsminor.yy170 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 229: /* expr ::= ID LP exprlist RP */ + case 228: /* expr ::= ID LP exprlist RP */ { yylhsminor.yy170 = tSqlExprCreateFunction(yymsp[-1].minor.yy429, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy170 = yylhsminor.yy170; break; - case 230: /* expr ::= ID LP STAR RP */ + case 229: /* expr ::= ID LP STAR RP */ { yylhsminor.yy170 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy170 = yylhsminor.yy170; break; - case 231: /* expr ::= expr IS NULL */ + case 230: /* expr ::= expr IS NULL */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, NULL, TK_ISNULL);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 232: /* expr ::= expr IS NOT NULL */ + case 231: /* expr ::= expr IS NOT NULL */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-3].minor.yy170, NULL, TK_NOTNULL);} yymsp[-3].minor.yy170 = yylhsminor.yy170; break; - case 233: /* expr ::= expr LT expr */ + case 232: /* expr ::= expr LT expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_LT);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 234: /* expr ::= expr GT expr */ + case 233: /* expr ::= expr GT expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_GT);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 235: /* expr ::= expr LE expr */ + case 234: /* expr ::= expr LE expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_LE);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 236: /* expr ::= expr GE expr */ + case 235: /* expr ::= expr GE expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_GE);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 237: /* expr ::= expr NE expr */ + case 236: /* expr ::= expr NE expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_NE);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 238: /* expr ::= expr EQ expr */ + case 237: /* expr ::= expr EQ expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_EQ);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 239: /* expr ::= expr BETWEEN expr AND expr */ + case 238: /* expr ::= expr BETWEEN expr AND expr */ { tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy170); yylhsminor.yy170 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy170, yymsp[-2].minor.yy170, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy170, TK_LE), TK_AND);} yymsp[-4].minor.yy170 = yylhsminor.yy170; break; - case 240: /* expr ::= expr AND expr */ + case 239: /* expr ::= expr AND expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_AND);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 241: /* expr ::= expr OR expr */ + case 240: /* expr ::= expr OR expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_OR); } yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 242: /* expr ::= expr PLUS expr */ + case 241: /* expr ::= expr PLUS expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_PLUS); } yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 243: /* expr ::= expr MINUS expr */ + case 242: /* expr ::= expr MINUS expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_MINUS); } yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 244: /* expr ::= expr STAR expr */ + case 243: /* expr ::= expr STAR expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_STAR); } yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 245: /* expr ::= expr SLASH expr */ + case 244: /* expr ::= expr SLASH expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_DIVIDE);} yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 246: /* expr ::= expr REM expr */ + case 245: /* expr ::= expr REM expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_REM); } yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 247: /* expr ::= expr LIKE expr */ + case 246: /* expr ::= expr LIKE expr */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-2].minor.yy170, yymsp[0].minor.yy170, TK_LIKE); } yymsp[-2].minor.yy170 = yylhsminor.yy170; break; - case 248: /* expr ::= expr IN LP exprlist RP */ + case 247: /* expr ::= expr IN LP exprlist RP */ {yylhsminor.yy170 = tSqlExprCreate(yymsp[-4].minor.yy170, (tSqlExpr*)yymsp[-1].minor.yy429, TK_IN); } yymsp[-4].minor.yy170 = yylhsminor.yy170; break; - case 249: /* exprlist ::= exprlist COMMA expritem */ + case 248: /* exprlist ::= exprlist COMMA expritem */ {yylhsminor.yy429 = tSqlExprListAppend(yymsp[-2].minor.yy429,yymsp[0].minor.yy170,0, 0);} yymsp[-2].minor.yy429 = yylhsminor.yy429; break; - case 250: /* exprlist ::= expritem */ + case 249: /* exprlist ::= expritem */ {yylhsminor.yy429 = tSqlExprListAppend(0,yymsp[0].minor.yy170,0, 0);} yymsp[0].minor.yy429 = yylhsminor.yy429; break; - case 251: /* expritem ::= expr */ + case 250: /* expritem ::= expr */ {yylhsminor.yy170 = yymsp[0].minor.yy170;} yymsp[0].minor.yy170 = yylhsminor.yy170; break; - case 253: /* cmd ::= RESET QUERY CACHE */ + case 252: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 254: /* cmd ::= SYNCDB ids REPLICA */ + case 253: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 255: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 254: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy429, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 256: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 255: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3296,14 +3291,14 @@ static YYACTIONTYPE yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 257: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 256: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy429, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 258: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 257: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3314,7 +3309,7 @@ static YYACTIONTYPE yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 259: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 258: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3328,7 +3323,7 @@ static YYACTIONTYPE yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 260: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 259: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3340,14 +3335,14 @@ static YYACTIONTYPE yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 261: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 260: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy429, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 262: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 261: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3358,14 +3353,14 @@ static YYACTIONTYPE yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 263: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 262: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy429, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 264: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 263: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3376,7 +3371,7 @@ static YYACTIONTYPE yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 265: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 264: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3390,13 +3385,13 @@ static YYACTIONTYPE yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 266: /* cmd ::= KILL CONNECTION INTEGER */ + case 265: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 267: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 266: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 268: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 267: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: From a36b21e8b2d418b74b10f20dc84c40709bb76bb2 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 11 Jun 2021 14:42:36 +0800 Subject: [PATCH 10/52] [TD-4681]: return invalid operator for not equal on primary timestamp column --- src/client/src/tscSQLParser.c | 3 +++ tests/pytest/query/filter.py | 4 ++-- tests/script/general/parser/timestamp_query.sim | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 37f51a856e..d6af2e2ef1 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4694,7 +4694,10 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t win->skey = val; } else if (optr == TK_EQ) { win->ekey = win->skey = val; + } else if (optr == TK_NE) { + return TSDB_CODE_TSC_INVALID_SQL; } + return TSDB_CODE_SUCCESS; } diff --git a/tests/pytest/query/filter.py b/tests/pytest/query/filter.py index 6d2ffbc8b1..f31e972d2c 100644 --- a/tests/pytest/query/filter.py +++ b/tests/pytest/query/filter.py @@ -91,8 +91,8 @@ class TDTestCase: tdSql.query("select * from db.st where name = 1231231") tdSql.checkRows(0) - # <> for timestamp type - tdSql.query("select * from db.st where ts <> '2020-05-13 10:00:00.002'") + # <> for timestamp type not supported for primary timestamp + # tdSql.query("select * from db.st where ts <> '2020-05-13 10:00:00.002'") # tdSql.checkRows(4) # <> for numeric type diff --git a/tests/script/general/parser/timestamp_query.sim b/tests/script/general/parser/timestamp_query.sim index 4e553c73f4..3f6a1af4bc 100644 --- a/tests/script/general/parser/timestamp_query.sim +++ b/tests/script/general/parser/timestamp_query.sim @@ -24,6 +24,8 @@ $tsu = $tsu + $ts0 print ==================>issue #3481, normal column not allowed, sql_error select ts,c1,min(c2) from ts_stb0 +print ==================>issue #4681, not equal operator on primary timestamp not allowed +sql_error select * from ts_stb0 where ts <> $ts0 ##### select from supertable $tb = $tbPrefix . 0 @@ -51,4 +53,4 @@ sql select first(c1), last(c1), (1537325400 - 1537146000)/(5*60) v from $tb wher if $data13 != 598.000000000 then print expect 598.000000000, actual $data03 return -1 -endi \ No newline at end of file +endi From 67d6339f1a4c2072a34d2d6afdc3b654feb774ac Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 15 Jun 2021 12:48:02 +0800 Subject: [PATCH 11/52] [4711] uncomment the test case in fulltest.sh --- tests/pytest/fulltest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 9ab13914de..9e31e930ad 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -346,6 +346,6 @@ python3 test.py -f alter/alter_keep.py python3 test.py -f alter/alter_cacheLastRow.py python3 ./test.py -f query/querySession.py python3 test.py -f alter/alter_create_exception.py -# python3 test.py -f client/change_time_1_1.py -# python3 test.py -f client/change_time_1_2.py +python3 test.py -f client/change_time_1_1.py +python3 test.py -f client/change_time_1_2.py #======================p4-end=============== From 08a9a1f765043c0c04a4e5baef57ed5e1e0b5239 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 15 Jun 2021 13:05:30 +0800 Subject: [PATCH 12/52] [TD-4711] trying to solve the problem of ntp not swtich on --- tests/pytest/client/change_time_1_1.py | 3 ++- tests/pytest/client/change_time_1_2.py | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/pytest/client/change_time_1_1.py b/tests/pytest/client/change_time_1_1.py index 32917ab2e4..1744c09132 100644 --- a/tests/pytest/client/change_time_1_1.py +++ b/tests/pytest/client/change_time_1_1.py @@ -56,8 +56,8 @@ class TDTestCase: #move 5 days ahead to 2020/10/25. 4 oldest files should be removed during the new write #leaving 7 data files. - os.system ('timedatectl set-time 2020-10-25') try: + os.system ('timedatectl set-time 2020-10-25') os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_B.json") except BaseException: os.system('sudo timedatectl set-ntp on') @@ -78,6 +78,7 @@ class TDTestCase: def stop(self): os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) tdSql.close() tdLog.success("alter block manual check finish") diff --git a/tests/pytest/client/change_time_1_2.py b/tests/pytest/client/change_time_1_2.py index d693010be4..d8180136e6 100644 --- a/tests/pytest/client/change_time_1_2.py +++ b/tests/pytest/client/change_time_1_2.py @@ -54,8 +54,14 @@ class TDTestCase: else: tdLog.debug("data file number correct") - tdSql.query('select first(ts) from stb_0') #check the last data in the database - tdSql.checkData(0,0,datetime(2020,10,11,0,0,0,0)) + + try: + tdSql.query('select first(ts) from stb_0') #check the last data in the database + tdSql.checkData(0,0,datetime(2020,10,11,0,0,0,0)) + except BaseException: + os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) + os.system ('timedatectl set-time 2020-10-25') @@ -63,11 +69,17 @@ class TDTestCase: #4 oldest data file should be removed from tsdb/data #7 data file should be found #vnode at TDinternal/community/sim/dnode1/data/vnode - os.system ('timedatectl set-time 2020-10-25') - tdDnodes.stop(1) - tdDnodes.start(1) - tdSql.query('select first(ts) from stb_0') - tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database + + try: + os.system ('timedatectl set-time 2020-10-25') + tdDnodes.stop(1) + tdDnodes.start(1) + tdSql.query('select first(ts) from stb_0') + tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database + except BaseException: + os.system('sudo timedatectl set-ntp on') + tdLog.sleep(10) + os.system('sudo timedatectl set-ntp on') tdLog.sleep(10) commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] From 7247919b765009af0b77d08f0110438ce03d1ea7 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 15 Jun 2021 13:08:31 +0800 Subject: [PATCH 13/52] [TD-4711] trying to solve the problem of ntp not swtich on --- tests/pytest/client/change_time_1_2.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/pytest/client/change_time_1_2.py b/tests/pytest/client/change_time_1_2.py index d8180136e6..76400885f8 100644 --- a/tests/pytest/client/change_time_1_2.py +++ b/tests/pytest/client/change_time_1_2.py @@ -62,9 +62,6 @@ class TDTestCase: os.system('sudo timedatectl set-ntp on') tdLog.sleep(10) - - os.system ('timedatectl set-time 2020-10-25') - #moves 5 days ahead to 2020/10/25 and restart taosd #4 oldest data file should be removed from tsdb/data #7 data file should be found From a56a1cbf170c94077d92b230ff4efb06554c73a4 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Tue, 15 Jun 2021 14:16:10 +0800 Subject: [PATCH 14/52] [TD-4695]update case for <> on primary ts --- tests/pytest/query/filter.py | 2 +- tests/pytest/query/querySecondtscolumnTowherenow.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pytest/query/filter.py b/tests/pytest/query/filter.py index f31e972d2c..944e2f0313 100644 --- a/tests/pytest/query/filter.py +++ b/tests/pytest/query/filter.py @@ -92,7 +92,7 @@ class TDTestCase: tdSql.checkRows(0) # <> for timestamp type not supported for primary timestamp - # tdSql.query("select * from db.st where ts <> '2020-05-13 10:00:00.002'") + tdSql.error("select * from db.st where ts <> '2020-05-13 10:00:00.002'") # tdSql.checkRows(4) # <> for numeric type diff --git a/tests/pytest/query/querySecondtscolumnTowherenow.py b/tests/pytest/query/querySecondtscolumnTowherenow.py index dfc18d99a6..dae50abdf0 100644 --- a/tests/pytest/query/querySecondtscolumnTowherenow.py +++ b/tests/pytest/query/querySecondtscolumnTowherenow.py @@ -58,8 +58,8 @@ class TDTestCase: ts_len4 = len(tdSql.cursor.fetchall()) tdSql.execute("select * from t2ts1 where ts = now") ts_len5 = len(tdSql.cursor.fetchall()) - tdSql.execute("select * from t2ts1 where ts <> now") - ts_len6 = len(tdSql.cursor.fetchall()) + # tdSql.execute("select * from t2ts1 where ts <> now") + ts_len6 = 3 tdSql.execute("select * from t2ts1 where ts between 0 and now") ts_len7 = len(tdSql.cursor.fetchall()) tdSql.execute("select * from t2ts1 where ts between now and now+100d") From 955a19ef0cbb0b66264a92b9b265f6e6b5f41cdd Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Tue, 15 Jun 2021 14:34:26 +0800 Subject: [PATCH 15/52] [TD-4542] : enhance "CACHELAST" mechanism to help "LAST" function. --- documentation20/cn/11.administrator/docs.md | 2 +- documentation20/cn/12.taos-sql/docs.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md index 9e1f627709..82dbe51e8b 100644 --- a/documentation20/cn/11.administrator/docs.md +++ b/documentation20/cn/11.administrator/docs.md @@ -129,7 +129,7 @@ taosd -C - blocks:每个VNODE(TSDB)中有多少cache大小的内存块。因此一个VNODE的用的内存大小粗略为(cache * blocks)。单位为块,默认值:4。(可通过 alter database 修改) - replica:副本个数,取值范围:1-3。单位为个,默认值:1。(可通过 alter database 修改) - precision:时间戳精度标识,ms表示毫秒,us表示微秒。默认值:ms。 -- cacheLast:是否在内存中缓存子表的最近数据,0:关闭;1:缓存子表最近一行数据;2:缓存子表每一列的最近的非NULL值,3:同时打开缓存最近行和列功能,默认值:0。(可通过 alter database 修改)(从 2.0.11 版本开始支持此参数) +- cacheLast:是否在内存中缓存子表的最近数据,0:关闭;1:缓存子表最近一行数据;2:缓存子表每一列的最近的非NULL值,3:同时打开缓存最近行和列功能,默认值:0。(可通过 alter database 修改)(从 2.1.2.0 版本开始此参数支持 0~3 的取值范围,在此之前取值只能是 [0, 1];而 2.0.11.0 之前的版本不支持此参数。) 对于一个应用场景,可能有多种数据特征的数据并存,最佳的设计是将具有相同数据特征的表放在一个库里,这样一个应用有多个库,而每个库可以配置不同的存储参数,从而保证系统有最优的性能。TDengine允许应用在创建库时指定上述存储参数,如果指定,该参数就将覆盖对应的系统配置参数。举例,有下述SQL: diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index 7508bbf86f..0708ea9e79 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -126,7 +126,8 @@ TDengine 缺省的时间戳是毫秒精度,但通过在 CREATE DATABASE 时传 ```mysql ALTER DATABASE db_name CACHELAST 0; ``` - CACHELAST 参数控制是否在内存中缓存数据子表的 last_row。缺省值为 0,取值范围 [0, 1]。其中 0 表示不启用、1 表示启用。(从 2.0.11.0 版本开始支持。从 2.1.1.0 版本开始,修改此参数后无需重启服务器即可生效。) + CACHELAST 参数控制是否在内存中缓存子表的最近数据。缺省值为 0,取值范围 [0, 1, 2, 3]。其中 0 表示不缓存,1 表示缓存子表最近一行数据,2 表示缓存子表每一列的最近的非 NULL 值,3 表示同时打开缓存最近行和列功能。(从 2.0.11.0 版本开始支持参数值 [0, 1],从 2.1.2.0 版本开始支持参数值 [0, 1, 2, 3]。从 2.1.1.0 版本开始,修改此参数后无需重启服务器即可生效。) + 说明:缓存最近行,将显著改善 LAST_ROW 函数的性能表现;缓存每列的最近非 NULL 值,将显著改善无特殊影响(WHERE、ORDER BY、GROUP BY、INTERVAL)下的 LAST 函数的性能表现。 **Tips**: 以上所有参数修改后都可以用show databases来确认是否修改成功。 From be347199c4fd131b02edc4e3ae64ddf6cb84e0c2 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Tue, 15 Jun 2021 14:49:44 +0800 Subject: [PATCH 16/52] Hotfix/sangshuduo/td 4025 fix travis ci broken (#6493) * [TD-4025]: travis ci broken due to valgrind dependency missed. * [TD-4025]: travis ci broken due to valgrind dependency missed. change focal to bionic. * [TD-4025]: travis ci broken due to valgrind dependency missed. install python3.8 * [TD-4025]: travis ci broken due to valgrind dependency missed. install python3.8 and pip, setuptools * [TD-4025]: travis ci broken due to valgrind dependency missed. install python3.8, and install pip and setuptools * [TD-4025]: travis ci broken due to valgrind dependency missed. modify smoketest.sh to python3.8 * fix timezone build error with clang/linux. * change fixed version python 3.8 to 3. Co-authored-by: Shuduo Sang --- tests/pytest/smoketest.sh | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/pytest/smoketest.sh b/tests/pytest/smoketest.sh index 0eb850749f..7c14b673e5 100755 --- a/tests/pytest/smoketest.sh +++ b/tests/pytest/smoketest.sh @@ -2,36 +2,36 @@ ulimit -c unlimited # insert -python3.8 ./test.py $1 -f insert/basic.py -python3.8 ./test.py $1 -s && sleep 1 -python3.8 ./test.py $1 -f insert/bigint.py -python3.8 ./test.py $1 -s && sleep 1 -python3.8 ./test.py $1 -f insert/nchar.py -python3.8 ./test.py $1 -s && sleep 1 -python3.8 ./test.py $1 -f insert/multi.py -python3.8 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/basic.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/bigint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/nchar.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/multi.py +python3 ./test.py $1 -s && sleep 1 # table -python3.8 ./test.py $1 -f table/column_name.py -python3.8 ./test.py $1 -s && sleep 1 -python3.8 ./test.py $1 -f table/column_num.py -python3.8 ./test.py $1 -s && sleep 1 -python3.8 ./test.py $1 -f table/db_table.py -python3.8 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f table/column_name.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f table/column_num.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f table/db_table.py +python3 ./test.py $1 -s && sleep 1 # import -python3.8 ./test.py $1 -f import_merge/importDataLastSub.py -python3.8 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f import_merge/importDataLastSub.py +python3 ./test.py $1 -s && sleep 1 #tag -python3.8 ./test.py $1 -f tag_lite/filter.py -python3.8 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f tag_lite/filter.py +python3 ./test.py $1 -s && sleep 1 #query -python3.8 ./test.py $1 -f query/filter.py -python3.8 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f query/filter.py +python3 ./test.py $1 -s && sleep 1 # client -python3.8 ./test.py $1 -f client/client.py -python3.8 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f client/client.py +python3 ./test.py $1 -s && sleep 1 From 90cc682dd3167ba99722ddeec186dd8ae12b4ef9 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 15 Jun 2021 16:27:20 +0800 Subject: [PATCH 17/52] removing from the auto test --- tests/pytest/fulltest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 9e31e930ad..9ab13914de 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -346,6 +346,6 @@ python3 test.py -f alter/alter_keep.py python3 test.py -f alter/alter_cacheLastRow.py python3 ./test.py -f query/querySession.py python3 test.py -f alter/alter_create_exception.py -python3 test.py -f client/change_time_1_1.py -python3 test.py -f client/change_time_1_2.py +# python3 test.py -f client/change_time_1_1.py +# python3 test.py -f client/change_time_1_2.py #======================p4-end=============== From 800a112f2ad85a634d39d80dae06ff8c8262d39f Mon Sep 17 00:00:00 2001 From: lichuang Date: Tue, 15 Jun 2021 16:29:43 +0800 Subject: [PATCH 18/52] [TD-4394]fix core when select data after modify tag width --- src/inc/tsdb.h | 2 +- src/query/src/qExecutor.c | 6 +++--- src/tsdb/src/tsdbMeta.c | 12 ++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 79d9029dbc..7575951246 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -117,7 +117,7 @@ typedef struct { void tsdbClearTableCfg(STableCfg *config); -void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t bytes); +void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t* bytes); char *tsdbGetTableName(void *pTable); #define TSDB_TABLEID(_table) ((STableId*) (_table)) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 77ceabbd63..4a5dc4f506 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2819,7 +2819,7 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag, val = tsdbGetTableName(pTable); assert(val != NULL); } else { - val = tsdbGetTableTagVal(pTable, tagColId, type, bytes); + val = tsdbGetTableTagVal(pTable, tagColId, type, &bytes); } if (val == NULL || isNull(val, type)) { @@ -6011,7 +6011,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, &bytes); } doSetTagValueToResultBuf(output, data, type, bytes); @@ -6050,7 +6050,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, &bytes); } dst = pColInfo->pData + count * pExprInfo[j].base.resBytes; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 8174698197..52ba3dfb4e 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -201,7 +201,7 @@ _err: return -1; } -void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t bytes) { +void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t* bytes) { // TODO: this function should be changed also STSchema *pSchema = tsdbGetTableTagSchema((STable*) pTable); @@ -211,8 +211,16 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_ } char *val = tdGetKVRowValOfCol(((STable*)pTable)->tagVal, colId); - assert(type == pCol->type && bytes == pCol->bytes); + assert(type == pCol->type && + // if var data type,bytes may >= col bytes,in case of tag width has beed modified + ((IS_VAR_DATA_TYPE(type) && *bytes >= pCol->bytes) || + // otherwise, bytes must be equal to colomn bytes + (!IS_VAR_DATA_TYPE(type) && *bytes == pCol->bytes))); + // in case tag width has been modified bigger but vnode has not been notified + if (val != NULL && IS_VAR_DATA_TYPE(type) && *bytes > pCol->bytes) { + *bytes = pCol->bytes; + } // if (val != NULL && IS_VAR_DATA_TYPE(type)) { // assert(varDataLen(val) < pCol->bytes); // } From 545f2127e11edf3ace3d79558127cf2f607565d9 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 15 Jun 2021 18:09:47 +0800 Subject: [PATCH 19/52] [TD-4366] retry to commit --- tests/pytest/client/change_time_1_1.py | 1 + tests/pytest/client/change_time_1_2.py | 1 + tests/pytest/fulltest.sh | 8 +++----- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pytest/client/change_time_1_1.py b/tests/pytest/client/change_time_1_1.py index 1744c09132..acdea17fbf 100644 --- a/tests/pytest/client/change_time_1_1.py +++ b/tests/pytest/client/change_time_1_1.py @@ -35,6 +35,7 @@ class TDTestCase: ## change system time to 2020/10/20 os.system('sudo timedatectl set-ntp off') + tdLog.sleep(10) os.system('sudo timedatectl set-time 2020-10-20') #run taosdemo to insert data. one row per second from 2020/10/11 to 2020/10/20 diff --git a/tests/pytest/client/change_time_1_2.py b/tests/pytest/client/change_time_1_2.py index 76400885f8..ec483b00be 100644 --- a/tests/pytest/client/change_time_1_2.py +++ b/tests/pytest/client/change_time_1_2.py @@ -34,6 +34,7 @@ class TDTestCase: ## change system time to 2020/10/20 os.system ('timedatectl set-ntp off') + tdLog.sleep(10) os.system ('timedatectl set-time 2020-10-20') #run taosdemo to insert data. one row per second from 2020/10/11 to 2020/10/20 diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index e8b369e0cd..1a7a0b64ee 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -257,8 +257,8 @@ python3 ./test.py -f client/client.py python3 ./test.py -f client/version.py python3 ./test.py -f client/alterDatabase.py python3 ./test.py -f client/noConnectionErrorTest.py -#python3 test.py -f client/change_time_1_1.py -#python3 test.py -f client/change_time_1_2.py +python3 test.py -f client/change_time_1_1.py +python3 test.py -f client/change_time_1_2.py # Misc python3 testCompress.py @@ -342,10 +342,8 @@ python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py python3 ./test.py -f tag_lite/drop_auto_create.py python3 test.py -f insert/insert_before_use_db.py -#python3 test.py -f alter/alter_keep.py +python3 test.py -f alter/alter_keep.py python3 test.py -f alter/alter_cacheLastRow.py python3 ./test.py -f query/querySession.py python3 test.py -f alter/alter_create_exception.py -# python3 test.py -f client/change_time_1_1.py -# python3 test.py -f client/change_time_1_2.py #======================p4-end=============== From 94a3a34f283327dee2165b33cfe82f08ecbd486f Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Tue, 15 Jun 2021 19:16:45 +0800 Subject: [PATCH 20/52] add check --- src/client/src/tscSubquery.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 08ade3acc5..4c3af96bbd 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -3154,6 +3154,13 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { // it is the failure retry insert if (pSql->pSubs != NULL) { + int32_t blockNum = (int32_t)taosArrayGetSize(pCmd->pDataBlocks); + if (pSql->subState.numOfSub != blockNum) { + tscError("0x%"PRIx64" sub num:%d is not same with data block num:%d", pSql->self, pSql->subState.numOfSub, blockNum); + pRes->code = TSDB_CODE_TSC_APP_ERROR; + return pRes->code; + } + for(int32_t i = 0; i < pSql->subState.numOfSub; ++i) { SSqlObj* pSub = pSql->pSubs[i]; SInsertSupporter* pSup = calloc(1, sizeof(SInsertSupporter)); From 9784eb618d030b95cd0490ba7d27e21a543fac7e Mon Sep 17 00:00:00 2001 From: xywang Date: Tue, 15 Jun 2021 19:49:51 +0800 Subject: [PATCH 21/52] [TD-4721]: NULL column in a row was specially processed --- src/plugins/http/src/httpGcJson.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugins/http/src/httpGcJson.c b/src/plugins/http/src/httpGcJson.c index 8c223a1500..397791706d 100644 --- a/src/plugins/http/src/httpGcJson.c +++ b/src/plugins/http/src/httpGcJson.c @@ -133,6 +133,16 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t len; len = snprintf(target, HTTP_GC_TARGET_SIZE, "%s{", aliasBuffer); for (int32_t i = dataFields + 1; i < num_fields; i++) { + if (row[i] == NULL) { + len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:nil", fields[i].name); + + if (i < num_fields - 1) { + len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, ", "); + } + + continue; + } + switch (fields[i].type) { case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: From 019860111d12856047e84e51e973d3f2c492002d Mon Sep 17 00:00:00 2001 From: lichuang Date: Tue, 15 Jun 2021 20:32:59 +0800 Subject: [PATCH 22/52] [TD-4394]fix core when select data after modify tag width --- src/inc/tsdb.h | 2 +- src/mnode/src/mnodeTable.c | 2 ++ src/query/src/qExecutor.c | 6 +++--- src/tsdb/src/tsdbMeta.c | 14 +++----------- src/util/src/tskiplist.c | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 7575951246..79d9029dbc 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -117,7 +117,7 @@ typedef struct { void tsdbClearTableCfg(STableCfg *config); -void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t* bytes); +void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t bytes); char *tsdbGetTableName(void *pTable); #define TSDB_TABLEID(_table) ((STableId*) (_table)) diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index a225c0d938..032c6ee94b 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1475,6 +1475,7 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg) { SSchema *schema = (SSchema *) (pStable->schema + col); ASSERT(schema->type == TSDB_DATA_TYPE_BINARY || schema->type == TSDB_DATA_TYPE_NCHAR); schema->bytes = pAlter->schema[0].bytes; + pStable->sversion++; mInfo("msg:%p, app:%p stable %s, start to modify column %s len to %d", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, name, schema->bytes); @@ -1504,6 +1505,7 @@ static int32_t mnodeChangeSuperTableTag(SMnodeMsg *pMsg) { SSchema *schema = (SSchema *) (pStable->schema + col + pStable->numOfColumns); ASSERT(schema->type == TSDB_DATA_TYPE_BINARY || schema->type == TSDB_DATA_TYPE_NCHAR); schema->bytes = pAlter->schema[0].bytes; + pStable->tversion++; mInfo("msg:%p, app:%p stable %s, start to modify tag len %s to %d", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, name, schema->bytes); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 4a5dc4f506..77ceabbd63 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2819,7 +2819,7 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag, val = tsdbGetTableName(pTable); assert(val != NULL); } else { - val = tsdbGetTableTagVal(pTable, tagColId, type, &bytes); + val = tsdbGetTableTagVal(pTable, tagColId, type, bytes); } if (val == NULL || isNull(val, type)) { @@ -6011,7 +6011,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, &bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, bytes); } doSetTagValueToResultBuf(output, data, type, bytes); @@ -6050,7 +6050,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, &bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, bytes); } dst = pColInfo->pData + count * pExprInfo[j].base.resBytes; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 52ba3dfb4e..86e3aea4b5 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -148,7 +148,7 @@ int tsdbCreateTable(STsdbRepo *repo, STableCfg *pCfg) { return 0; _err: - tsdbFreeTable(super); + //tsdbFreeTable(super); tsdbFreeTable(table); return -1; } @@ -201,7 +201,7 @@ _err: return -1; } -void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t* bytes) { +void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t bytes) { // TODO: this function should be changed also STSchema *pSchema = tsdbGetTableTagSchema((STable*) pTable); @@ -211,16 +211,8 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_ } char *val = tdGetKVRowValOfCol(((STable*)pTable)->tagVal, colId); - assert(type == pCol->type && - // if var data type,bytes may >= col bytes,in case of tag width has beed modified - ((IS_VAR_DATA_TYPE(type) && *bytes >= pCol->bytes) || - // otherwise, bytes must be equal to colomn bytes - (!IS_VAR_DATA_TYPE(type) && *bytes == pCol->bytes))); + assert(type == pCol->type && bytes == pCol->bytes); - // in case tag width has been modified bigger but vnode has not been notified - if (val != NULL && IS_VAR_DATA_TYPE(type) && *bytes > pCol->bytes) { - *bytes = pCol->bytes; - } // if (val != NULL && IS_VAR_DATA_TYPE(type)) { // assert(varDataLen(val) < pCol->bytes); // } diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 842ded19a6..0a394c15c9 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -85,7 +85,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _ } void tSkipListDestroy(SSkipList *pSkipList) { - if (pSkipList == NULL) return; + if (pSkipList == NULL || pSkipList->pHead == NULL) return; tSkipListWLock(pSkipList); From 5c8bd7a3a459ef7eba47c0959bd7a58daf80b5a6 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Tue, 15 Jun 2021 15:47:38 +0800 Subject: [PATCH 23/52] [TD-4682]: not move vnode to new dnode within 2 seconds --- src/balance/src/bnMain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/balance/src/bnMain.c b/src/balance/src/bnMain.c index 67741b1473..f022fff6d8 100644 --- a/src/balance/src/bnMain.c +++ b/src/balance/src/bnMain.c @@ -367,6 +367,7 @@ static bool bnMonitorBalance() { for (int32_t dest = 0; dest < src; dest++) { SDnodeObj *pDestDnode = tsBnDnodes.list[dest]; if (bnCheckDnodeInVgroup(pDestDnode, pVgroup)) continue; + if (taosGetTimestampMs() - pDestDnode->createdTime < 2000) continue; float destScore = bnTryCalcDnodeScore(pDestDnode, 1); if (srcScore + 0.0001 < destScore) continue; From 3e65aedae2d1a2ce4aeaa8b17caaf77516a7aaf9 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 15 Jun 2021 23:33:34 +0800 Subject: [PATCH 24/52] [td-4723]: fix bug in derivative function. --- src/client/src/tscSQLParser.c | 17 ++++++++++++++--- src/client/src/tscSystem.c | 3 ++- src/query/src/qAggMain.c | 12 ++++++------ tests/script/general/parser/function.sim | 6 +++++- tests/script/general/parser/nestquery.sim | 14 ++++++++++++++ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index d91301adfe..38b93e3f31 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1800,7 +1800,6 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS assert(pSelNodeList != NULL && pCmd != NULL); const char* msg1 = "too many items in selection clause"; - const char* msg2 = "functions or others can not be mixed up"; const char* msg3 = "not support query expression"; const char* msg4 = "only support distinct one tag"; @@ -2726,6 +2725,8 @@ void getColumnName(tSqlExprItem* pItem, char* resultFieldName, char* rawName, in strncpy(rawName, pItem->pNode->token.z, len); if (pItem->aliasName != NULL) { + int32_t aliasNameLen = (int32_t) strlen(pItem->aliasName); + len = (aliasNameLen < nameLength)? aliasNameLen:nameLength; strncpy(resultFieldName, pItem->aliasName, len); } else { strncpy(resultFieldName, rawName, len); @@ -7752,6 +7753,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf const char* msg4 = "interval query not supported, since the result of sub query not include valid timestamp column"; const char* msg5 = "only tag query not compatible with normal column filter"; const char* msg6 = "not support stddev/percentile in outer query yet"; + const char* msg7 = "drivative requires timestamp column exists in subquery"; int32_t code = TSDB_CODE_SUCCESS; @@ -7801,13 +7803,23 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } } + // todo derivate funtion requires ts column exists in subquery + STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; + SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, 0); + + if (tscNumOfExprs(pQueryInfo) > 1) { + SExprInfo* pExpr = tscExprGet(pQueryInfo, 1); + if (pExpr->base.functionId == TSDB_FUNC_DERIVATIVE && pSchema->type != TSDB_DATA_TYPE_TIMESTAMP) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); + } + } + // validate the query filter condition info if (pSqlNode->pWhere != NULL) { if (validateWhereNode(pQueryInfo, &pSqlNode->pWhere, pSql) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } - STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; if (pTableMeta->tableInfo.precision == TSDB_TIME_PRECISION_MILLI) { pQueryInfo->window.skey = pQueryInfo->window.skey / 1000; pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000; @@ -7832,7 +7844,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } // set order by info - STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index c602d1bfcc..ac6fc62adb 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -290,8 +290,9 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { char* defaultLocale = setlocale(LC_CTYPE, ""); // The locale of the current OS does not be set correctly, so the default locale cannot be acquired. + // The launch of current system will abort soon. if (defaultLocale == NULL) { - uError("failed to get default locale, please set the correct locale in current OS"); + tscError("failed to get default locale, please set the correct locale in current OS"); return -1; } diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index e225439d99..117dd2c1d9 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -3662,7 +3662,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null - *pTimestamp = tsList[i]; + *pTimestamp = (tsList != NULL)? tsList[i]:0; pOutput += 1; pTimestamp += 1; } @@ -3684,7 +3684,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet *pOutput = pData[i] - pCtx->param[1].i64; // direct previous may be null - *pTimestamp = tsList[i]; + *pTimestamp = (tsList != NULL)? tsList[i]:0; pOutput += 1; pTimestamp += 1; } @@ -3706,7 +3706,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet *pOutput = pData[i] - pCtx->param[1].dKey; // direct previous may be null - *pTimestamp = tsList[i]; + *pTimestamp = (tsList != NULL)? tsList[i]:0; pOutput += 1; pTimestamp += 1; } @@ -3728,7 +3728,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet *pOutput = (float)(pData[i] - pCtx->param[1].dKey); // direct previous may be null - *pTimestamp = tsList[i]; + *pTimestamp = (tsList != NULL)? tsList[i]:0; pOutput += 1; pTimestamp += 1; } @@ -3750,7 +3750,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet *pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null - *pTimestamp = tsList[i]; + *pTimestamp = (tsList != NULL)? tsList[i]:0; pOutput += 1; pTimestamp += 1; } @@ -3773,7 +3773,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet *pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null - *pTimestamp = tsList[i]; + *pTimestamp = (tsList != NULL)? tsList[i]:0; pOutput += 1; pTimestamp += 1; } diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 6a3e5596c1..ad900b92e0 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -1080,6 +1080,8 @@ sql insert into t1 values('2020-1-1 1:1:10', 20000); sql_error select derivative(k, 1s, 0) from m1; sql_error select derivative(k, 1s, 0) from m1 group by a; +sql_error select derivative(f1, 1s, 0) from (select k from t1); + sql select derivative(k, 1s, 0) from m1 group by tbname if $rows != 12 then return -1 @@ -1119,4 +1121,6 @@ endi if $data92 != t1 then return -1 -endi \ No newline at end of file +endi + +sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s)); diff --git a/tests/script/general/parser/nestquery.sim b/tests/script/general/parser/nestquery.sim index 98c0918c0f..8249d9197f 100644 --- a/tests/script/general/parser/nestquery.sim +++ b/tests/script/general/parser/nestquery.sim @@ -273,4 +273,18 @@ if $data03 != @20-09-15 00:00:00.000@ then return -1 endi +sql_error select derivative(val, 1s, 0) from (select c1 val from nest_tb0); +sql select diff(val) from (select c1 val from nest_tb0); +if $rows != 9999 then + return -1 +endi + +if $data00 != @70-01-01 08:00:00.000@ then + return -1 +endi + +if $data01 != 1 then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 86414f03efaf9f20a58fee3df6cfd6fe3fcb31a3 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Wed, 16 Jun 2021 09:05:46 +0800 Subject: [PATCH 25/52] [TD-4366] removing time alter test case from auto test --- tests/pytest/fulltest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 1a7a0b64ee..146c47c51d 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -257,8 +257,8 @@ python3 ./test.py -f client/client.py python3 ./test.py -f client/version.py python3 ./test.py -f client/alterDatabase.py python3 ./test.py -f client/noConnectionErrorTest.py -python3 test.py -f client/change_time_1_1.py -python3 test.py -f client/change_time_1_2.py +# python3 test.py -f client/change_time_1_1.py +# python3 test.py -f client/change_time_1_2.py # Misc python3 testCompress.py From c2a558cd21bc4d9e2c3f1eabd3a2d4384c0b95a2 Mon Sep 17 00:00:00 2001 From: lichuang Date: Wed, 16 Jun 2021 10:44:01 +0800 Subject: [PATCH 26/52] [TD-4394]fix core when select data after modify tag width --- src/query/src/qExecutor.c | 3 ++- src/tsdb/src/tsdbMeta.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 77ceabbd63..3227102559 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -7519,7 +7519,8 @@ static void doSetTagValueToResultBuf(char* output, const char* val, int16_t type if (IS_VAR_DATA_TYPE(type)) { // Binary data overflows for sort of unknown reasons. Let trim the overflow data if (varDataTLen(val) > bytes) { - int32_t len = bytes - VARSTR_HEADER_SIZE; // remain available space + int32_t maxLen = bytes - VARSTR_HEADER_SIZE; + int32_t len = (varDataLen(val) > maxLen)? maxLen:varDataLen(val); memcpy(varDataVal(output), varDataVal(val), len); varDataSetLen(output, len); } else { diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 86e3aea4b5..17223c99fe 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -211,7 +211,7 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_ } char *val = tdGetKVRowValOfCol(((STable*)pTable)->tagVal, colId); - assert(type == pCol->type && bytes == pCol->bytes); + assert(type == pCol->type && bytes >= pCol->bytes); // if (val != NULL && IS_VAR_DATA_TYPE(type)) { // assert(varDataLen(val) < pCol->bytes); From 93f544f593a149bf7350e85a8d18b2303f961d27 Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Wed, 16 Jun 2021 11:12:03 +0800 Subject: [PATCH 27/52] [TD-4412] : update DATABASE related parameters. --- documentation20/cn/11.administrator/docs.md | 31 ++++++++++++--------- documentation20/cn/12.taos-sql/docs.md | 19 +++++++++++-- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md index 82dbe51e8b..ae13a36f76 100644 --- a/documentation20/cn/11.administrator/docs.md +++ b/documentation20/cn/11.administrator/docs.md @@ -116,20 +116,22 @@ taosd -C **注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030到6042共13个端口,而且必须TCP和UDP都打开。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port)) -不同应用场景的数据往往具有不同的数据特征,比如保留天数、副本数、采集频次、记录大小、采集点的数量、压缩等都可完全不同。为获得在存储上的最高效率,TDengine提供如下存储相关的系统配置参数: +不同应用场景的数据往往具有不同的数据特征,比如保留天数、副本数、采集频次、记录大小、采集点的数量、压缩等都可完全不同。为获得在存储上的最高效率,TDengine提供如下存储相关的系统配置参数(既可以作为 create database 指令的参数,也可以写在 taos.cfg 配置文件中用来设定创建新数据库时所采用的默认值): -- days:一个数据文件存储数据的时间跨度,单位为天,默认值:10。 -- keep:数据库中数据保留的天数,单位为天,默认值:3650。(可通过 alter database 修改) -- minRows:文件块中记录的最小条数,单位为条,默认值:100。 -- maxRows:文件块中记录的最大条数,单位为条,默认值:4096。 -- comp:文件压缩标志位,0:关闭;1:一阶段压缩;2:两阶段压缩。默认值:2。(可通过 alter database 修改) -- walLevel:WAL级别。1:写wal,但不执行fsync;2:写wal, 而且执行fsync。默认值:1。 -- fsync:当wal设置为2时,执行fsync的周期。设置为0,表示每次写入,立即执行fsync。单位为毫秒,默认值:3000。 -- cache:内存块的大小,单位为兆字节(MB),默认值:16。 +- days:一个数据文件存储数据的时间跨度。单位为天,默认值:10。 +- keep:数据库中数据保留的天数。单位为天,默认值:3650。(可通过 alter database 修改) +- minRows:文件块中记录的最小条数。单位为条,默认值:100。 +- maxRows:文件块中记录的最大条数。单位为条,默认值:4096。 +- comp:文件压缩标志位。0:关闭;1:一阶段压缩;2:两阶段压缩。默认值:2。(可通过 alter database 修改) +- wal:WAL级别。1:写wal,但不执行fsync;2:写wal, 而且执行fsync。默认值:1。(在 taos.cfg 中参数名需要写作 walLevel)(可通过 alter database 修改) +- fsync:当wal设置为2时,执行fsync的周期。设置为0,表示每次写入,立即执行fsync。单位为毫秒,默认值:3000。(可通过 alter database 修改) +- cache:内存块的大小。单位为兆字节(MB),默认值:16。 - blocks:每个VNODE(TSDB)中有多少cache大小的内存块。因此一个VNODE的用的内存大小粗略为(cache * blocks)。单位为块,默认值:4。(可通过 alter database 修改) -- replica:副本个数,取值范围:1-3。单位为个,默认值:1。(可通过 alter database 修改) -- precision:时间戳精度标识,ms表示毫秒,us表示微秒。默认值:ms。 -- cacheLast:是否在内存中缓存子表的最近数据,0:关闭;1:缓存子表最近一行数据;2:缓存子表每一列的最近的非NULL值,3:同时打开缓存最近行和列功能,默认值:0。(可通过 alter database 修改)(从 2.1.2.0 版本开始此参数支持 0~3 的取值范围,在此之前取值只能是 [0, 1];而 2.0.11.0 之前的版本不支持此参数。) +- replica:副本个数。取值范围:1-3,单位为个,默认值:1。(可通过 alter database 修改) +- quorum:多副本环境下指令执行的确认数要求。取值范围:1、2,单位为个,默认值:1。(可通过 alter database 修改) +- precision:时间戳精度标识。ms表示毫秒,us表示微秒,默认值:ms。(2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。) +- cacheLast:是否在内存中缓存子表的最近数据。0:关闭;1:缓存子表最近一行数据;2:缓存子表每一列的最近的非NULL值;3:同时打开缓存最近行和列功能。默认值:0。(可通过 alter database 修改)(从 2.1.2.0 版本开始此参数支持 0~3 的取值范围,在此之前取值只能是 [0, 1];而 2.0.11.0 之前的版本在 SQL 指令中不支持此参数。)(2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。) +- update:是否允许更新。0:不允许;1:允许。默认值:0。(可通过 alter database 修改) 对于一个应用场景,可能有多种数据特征的数据并存,最佳的设计是将具有相同数据特征的表放在一个库里,这样一个应用有多个库,而每个库可以配置不同的存储参数,从而保证系统有最优的性能。TDengine允许应用在创建库时指定上述存储参数,如果指定,该参数就将覆盖对应的系统配置参数。举例,有下述SQL: @@ -142,7 +144,6 @@ taosd -C TDengine集群中加入一个新的dnode时,涉及集群相关的一些参数必须与已有集群的配置相同,否则不能成功加入到集群中。会进行校验的参数如下: - numOfMnodes:系统中管理节点个数。默认值:3。 -- balance:是否启动负载均衡。0:否,1:是。默认值:1。 - mnodeEqualVnodeNum: 一个mnode等同于vnode消耗的个数。默认值:4。 - offlineThreshold: dnode离线阈值,超过该时间将导致该dnode从集群中删除。单位为秒,默认值:86400*10(即10天)。 - statusInterval: dnode向mnode报告状态时长。单位为秒,默认值:1。 @@ -150,6 +151,10 @@ TDengine集群中加入一个新的dnode时,涉及集群相关的一些参数 - maxVgroupsPerDb: 每个数据库中能够使用的最大vgroup个数。 - arbitrator: 系统中裁决器的end point,缺省为空。 - timezone、locale、charset 的配置见客户端配置。(2.0.20.0 及以上的版本里,集群中加入新节点已不要求 locale 和 charset 参数取值一致) +- balance:是否启用负载均衡。0:否,1:是。默认值:1。 +- flowctrl:是否启用非阻塞流控。0:否,1:是。默认值:1。 +- slaveQuery:是否启用 slave vnode 参与查询。0:否,1:是。默认值:1。 +- adjustMaster:是否启用 vnode master 负载均衡。0:否,1:是。默认值:1。 为方便调试,可通过SQL语句临时调整每个dnode的日志配置,系统重启后会失效: diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index 0708ea9e79..abbe7d8a0a 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -126,10 +126,25 @@ TDengine 缺省的时间戳是毫秒精度,但通过在 CREATE DATABASE 时传 ```mysql ALTER DATABASE db_name CACHELAST 0; ``` - CACHELAST 参数控制是否在内存中缓存子表的最近数据。缺省值为 0,取值范围 [0, 1, 2, 3]。其中 0 表示不缓存,1 表示缓存子表最近一行数据,2 表示缓存子表每一列的最近的非 NULL 值,3 表示同时打开缓存最近行和列功能。(从 2.0.11.0 版本开始支持参数值 [0, 1],从 2.1.2.0 版本开始支持参数值 [0, 1, 2, 3]。从 2.1.1.0 版本开始,修改此参数后无需重启服务器即可生效。) + CACHELAST 参数控制是否在内存中缓存子表的最近数据。缺省值为 0,取值范围 [0, 1, 2, 3]。其中 0 表示不缓存,1 表示缓存子表最近一行数据,2 表示缓存子表每一列的最近的非 NULL 值,3 表示同时打开缓存最近行和列功能。(从 2.0.11.0 版本开始支持参数值 [0, 1],从 2.1.2.0 版本开始支持参数值 [0, 1, 2, 3]。) 说明:缓存最近行,将显著改善 LAST_ROW 函数的性能表现;缓存每列的最近非 NULL 值,将显著改善无特殊影响(WHERE、ORDER BY、GROUP BY、INTERVAL)下的 LAST 函数的性能表现。 - **Tips**: 以上所有参数修改后都可以用show databases来确认是否修改成功。 + ```mysql + ALTER DATABASE db_name WAL 1; + ``` + WAL 参数控制 WAL 日志的落盘方式。缺省值为 1,取值范围为 [1, 2]。1 表示写 WAL,但不执行 fsync;2 表示写 WAL,而且执行 fsync。 + + ```mysql + ALTER DATABASE db_name FSYNC 3000; + ``` + FSYNC 参数控制执行 fsync 操作的周期。缺省值为 3000,单位是毫秒,取值范围为 [0, 180000]。如果设置为 0,表示每次写入,立即执行 fsync。该设置项主要用于调节 WAL 参数设为 2 时的系统行为。 + + ```mysql + ALTER DATABASE db_name UPDATE 0; + ``` + UPDATE 参数控制是否允许更新数据。缺省值为 0,取值范围为 [0, 1]。0 表示会直接丢弃后写入的相同时间戳的数据;1 表示会使用后写入的数据覆盖已有的相同时间戳的数据。 + + **Tips**: 以上所有参数修改后都可以用show databases来确认是否修改成功。另外,从 2.1.1.0 版本开始,修改这些参数后无需重启服务器即可生效。 - **显示系统所有数据库** From a14f792d797f961e790278d1aa2830c54a737173 Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Wed, 16 Jun 2021 11:22:07 +0800 Subject: [PATCH 28/52] [TD-2639] : fix word "MATLAB" spelling. --- documentation20/cn/00.index/docs.md | 2 +- documentation20/cn/01.evaluation/docs.md | 4 ++-- documentation20/cn/08.connector/docs.md | 2 +- documentation20/cn/09.connections/docs.md | 14 +++++++------- documentation20/en/00.index/docs.md | 2 +- documentation20/en/01.evaluation/docs.md | 4 ++-- documentation20/en/08.connector/docs.md | 2 +- documentation20/en/09.connections/docs.md | 14 +++++++------- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/documentation20/cn/00.index/docs.md b/documentation20/cn/00.index/docs.md index 49cfa12119..4c37ce598c 100644 --- a/documentation20/cn/00.index/docs.md +++ b/documentation20/cn/00.index/docs.md @@ -81,7 +81,7 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专 ## [与其他工具的连接](/connections) * [Grafana](/connections#grafana):获取并可视化保存在TDengine的数据 -* [Matlab](/connections#matlab):通过配置Matlab的JDBC数据源访问保存在TDengine的数据 +* [MATLAB](/connections#matlab):通过配置MATLAB的JDBC数据源访问保存在TDengine的数据 * [R](/connections#r):通过配置R的JDBC数据源访问保存在TDengine的数据 * [IDEA Database](https://www.taosdata.com/blog/2020/08/27/1767.html):通过IDEA 数据库管理工具可视化使用 TDengine diff --git a/documentation20/cn/01.evaluation/docs.md b/documentation20/cn/01.evaluation/docs.md index 0ae2106ff2..7f70ccec56 100644 --- a/documentation20/cn/01.evaluation/docs.md +++ b/documentation20/cn/01.evaluation/docs.md @@ -9,8 +9,8 @@ TDengine的模块之一是时序数据库。但除此之外,为减少研发的 * __10倍以上的性能提升__:定义了创新的数据存储结构,单核每秒能处理至少2万次请求,插入数百万个数据点,读出一千万以上数据点,比现有通用数据库快十倍以上。 * __硬件或云服务成本降至1/5__:由于超强性能,计算资源不到通用大数据方案的1/5;通过列式存储和先进的压缩算法,存储空间不到通用数据库的1/10。 * __全栈时序数据处理引擎__:将数据库、消息队列、缓存、流式计算等功能融为一体,应用无需再集成Kafka/Redis/HBase/Spark/HDFS等软件,大幅降低应用开发和维护的复杂度成本。 -* __强大的分析功能__:无论是十年前还是一秒钟前的数据,指定时间范围即可查询。数据可在时间轴上或多个设备上进行聚合。即席查询可通过Shell, Python, R, Matlab随时进行。 -* __与第三方工具无缝连接__:不用一行代码,即可与Telegraf, Grafana, EMQ, HiveMQ, Prometheus, Matlab, R等集成。后续将支持OPC, Hadoop, Spark等, BI工具也将无缝连接。 +* __强大的分析功能__:无论是十年前还是一秒钟前的数据,指定时间范围即可查询。数据可在时间轴上或多个设备上进行聚合。即席查询可通过Shell, Python, R, MATLAB随时进行。 +* __与第三方工具无缝连接__:不用一行代码,即可与Telegraf, Grafana, EMQ, HiveMQ, Prometheus, MATLAB, R等集成。后续将支持OPC, Hadoop, Spark等, BI工具也将无缝连接。 * __零运维成本、零学习成本__:安装集群简单快捷,无需分库分表,实时备份。类似标准SQL,支持RESTful, 支持Python/Java/C/C++/C#/Go/Node.js, 与MySQL相似,零学习成本。 采用TDengine,可将典型的物联网、车联网、工业互联网大数据平台的总拥有成本大幅降低。但需要指出的是,因充分利用了物联网时序数据的特点,它无法用来处理网络爬虫、微博、微信、电商、ERP、CRM等通用型数据。 diff --git a/documentation20/cn/08.connector/docs.md b/documentation20/cn/08.connector/docs.md index 991c3ce6ce..c74d1ebc3e 100644 --- a/documentation20/cn/08.connector/docs.md +++ b/documentation20/cn/08.connector/docs.md @@ -56,7 +56,7 @@ TDengine提供了丰富的应用程序开发接口,其中包括C/C++、Java、 ​ *taos.tar.gz*:应用驱动安装包 ​ *driver*:TDengine应用驱动driver ​ *connector*: 各种编程语言连接器(go/grafanaplugin/nodejs/python/JDBC) -​ *examples*: 各种编程语言的示例程序(c/C#/go/JDBC/matlab/python/R) +​ *examples*: 各种编程语言的示例程序(c/C#/go/JDBC/MATLAB/python/R) 运行install_client.sh进行安装 diff --git a/documentation20/cn/09.connections/docs.md b/documentation20/cn/09.connections/docs.md index 6a2ead3766..d1dba5a736 100644 --- a/documentation20/cn/09.connections/docs.md +++ b/documentation20/cn/09.connections/docs.md @@ -75,17 +75,17 @@ sudo cp -rf /usr/local/taos/connector/grafanaplugin /var/lib/grafana/plugins/tde ![img](page://images/connections/import_dashboard2.jpg) -## Matlab +## MATLAB -MatLab可以通过安装包内提供的JDBC Driver直接连接到TDengine获取数据到本地工作空间。 +MATLAB可以通过安装包内提供的JDBC Driver直接连接到TDengine获取数据到本地工作空间。 -### MatLab的JDBC接口适配 +### MATLAB的JDBC接口适配 -MatLab的适配有下面几个步骤,下面以Windows10上适配MatLab2017a为例: +MATLAB的适配有下面几个步骤,下面以Windows10上适配MATLAB2017a为例: - 将TDengine安装包内的驱动程序JDBCDriver-1.0.0-dist.jar拷贝到${matlab_root}\MATLAB\R2017a\java\jar\toolbox - 将TDengine安装包内的taos.lib文件拷贝至${matlab_ root _dir}\MATLAB\R2017a\lib\win64 -- 将新添加的驱动jar包加入MatLab的classpath。在${matlab_ root _dir}\MATLAB\R2017a\toolbox\local\classpath.txt文件中添加下面一行 +- 将新添加的驱动jar包加入MATLAB的classpath。在${matlab_ root _dir}\MATLAB\R2017a\toolbox\local\classpath.txt文件中添加下面一行 ​ ``` $matlabroot/java/jar/toolbox/JDBCDriver-1.0.0-dist.jar @@ -96,9 +96,9 @@ $matlabroot/java/jar/toolbox/JDBCDriver-1.0.0-dist.jar C:\Windows\System32 ``` -### 在MatLab中连接TDengine获取数据 +### 在MATLAB中连接TDengine获取数据 -在成功进行了上述配置后,打开MatLab。 +在成功进行了上述配置后,打开MATLAB。 - 创建一个连接: diff --git a/documentation20/en/00.index/docs.md b/documentation20/en/00.index/docs.md index f8ebe8c35b..27f873b704 100644 --- a/documentation20/en/00.index/docs.md +++ b/documentation20/en/00.index/docs.md @@ -82,7 +82,7 @@ TDengine is a highly efficient platform to store, query, and analyze time-series ## [Connections with Other Tools](/connections) - [Grafana](/connections#grafana): query the data saved in TDengine and provide visualization -- [Matlab](/connections#matlab): access data stored in TDengine server via JDBC configured within Matlab +- [MATLAB](/connections#matlab): access data stored in TDengine server via JDBC configured within MATLAB - [R](/connections#r): access data stored in TDengine server via JDBC configured within R - [IDEA Database](https://www.taosdata.com/blog/2020/08/27/1767.html): use TDengine visually through IDEA Database Management Tool diff --git a/documentation20/en/01.evaluation/docs.md b/documentation20/en/01.evaluation/docs.md index 89fb6443cb..50948efbd8 100644 --- a/documentation20/en/01.evaluation/docs.md +++ b/documentation20/en/01.evaluation/docs.md @@ -9,8 +9,8 @@ One of the modules of TDengine is the time-series database. However, in addition - **Performance improvement over 10 times**: An innovative data storage structure is defined, with each single core can process at least 20,000 requests per second, insert millions of data points, and read more than 10 million data points, which is more than 10 times faster than other existing general database. - **Reduce the cost of hardware or cloud services to 1/5**: Due to its ultra-performance, TDengine’s computing resources consumption is less than 1/5 of other common Big Data solutions; through columnar storage and advanced compression algorithms, the storage consumption is less than 1/10 of other general databases. - **Full-stack time-series data processing engine**: Integrate database, message queue, cache, stream computing, and other functions, and the applications do not need to integrate with software such as Kafka/Redis/HBase/Spark/HDFS, thus greatly reducing the complexity cost of application development and maintenance. -- **Powerful analysis functions**: Data from ten years ago or one second ago, can all be queried based on a specified time range. Data can be aggregated on a timeline or multiple devices. Ad-hoc queries can be made at any time through Shell, Python, R, and Matlab. -- **Seamless connection with third-party tools**: Integration with Telegraf, Grafana, EMQ, HiveMQ, Prometheus, Matlab, R, etc. without even one single line of code. OPC, Hadoop, Spark, etc. will be supported in the future, and more BI tools will be seamlessly connected to. +- **Powerful analysis functions**: Data from ten years ago or one second ago, can all be queried based on a specified time range. Data can be aggregated on a timeline or multiple devices. Ad-hoc queries can be made at any time through Shell, Python, R, and MATLAB. +- **Seamless connection with third-party tools**: Integration with Telegraf, Grafana, EMQ, HiveMQ, Prometheus, MATLAB, R, etc. without even one single line of code. OPC, Hadoop, Spark, etc. will be supported in the future, and more BI tools will be seamlessly connected to. - **Zero operation cost & zero learning cost**: Installing clusters is simple and quick, with real-time backup built-in, and no need to split libraries or tables. Similar to standard SQL, TDengine can support RESTful, Python/Java/C/C + +/C#/Go/Node.js, and similar to MySQL with zero learning cost. With TDengine, the total cost of ownership of typical IoT, Internet of Vehicles, and Industrial Internet Big Data platforms can be greatly reduced. However, it should be pointed out that due to making full use of the characteristics of IoT time-series data, TDengine cannot be used to process general data from web crawlers, microblogs, WeChat, e-commerce, ERP, CRM, and other sources. diff --git a/documentation20/en/08.connector/docs.md b/documentation20/en/08.connector/docs.md index 9913a2958f..36dc06a36e 100644 --- a/documentation20/en/08.connector/docs.md +++ b/documentation20/en/08.connector/docs.md @@ -58,7 +58,7 @@ After extracting the package, you will see the following files (directories) in *connector*: Connectors for various programming languages (go/grafanaplugin/nodejs/python/JDBC) -*Examples*: Sample programs for various programming languages (C/C #/go/JDBC/matlab/python/R) +*Examples*: Sample programs for various programming languages (C/C #/go/JDBC/MATLAB/python/R) Run install_client.sh to install. diff --git a/documentation20/en/09.connections/docs.md b/documentation20/en/09.connections/docs.md index 93633ea369..e759da3167 100644 --- a/documentation20/en/09.connections/docs.md +++ b/documentation20/en/09.connections/docs.md @@ -74,17 +74,17 @@ You can see as follows after Dashboard imported. ![img](page://images/connections/import_dashboard2.jpg) -## Matlab +## MATLAB -MatLab can access data to the local workspace by connecting directly to the TDengine via the JDBC Driver provided in the installation package. +MATLAB can access data to the local workspace by connecting directly to the TDengine via the JDBC Driver provided in the installation package. -### JDBC Interface Adaptation of MatLab +### JDBC Interface Adaptation of MATLAB -Several steps are required to adapt Matlab to TDengine. Taking adapting Matlab2017a on Windows10 as an example: +Several steps are required to adapt MATLAB to TDengine. Taking adapting MATLAB2017a on Windows10 as an example: - Copy the file JDBCDriver-1.0.0-dist.ja*r* in TDengine package to the directory ${matlab_root}\MATLAB\R2017a\java\jar\toolbox - Copy the file taos.lib in TDengine package to ${matlab root dir}\MATLAB\R2017a\lib\win64 -- Add the .jar package just copied to the Matlab classpath. Append the line below as the end of the file of ${matlab root dir}\MATLAB\R2017a\toolbox\local\classpath.txt +- Add the .jar package just copied to the MATLAB classpath. Append the line below as the end of the file of ${matlab root dir}\MATLAB\R2017a\toolbox\local\classpath.txt - ``` $matlabroot/java/jar/toolbox/JDBCDriver-1.0.0-dist.jar ``` @@ -94,9 +94,9 @@ Several steps are required to adapt Matlab to TDengine. Taking adapting Matlab20 C:\Windows\System32 ``` -- ### Connect to TDengine in MatLab to get data +- ### Connect to TDengine in MATLAB to get data -After the above configured successfully, open MatLab. +After the above configured successfully, open MATLAB. - Create a connection: From 1dd6f365074c97b3aca07c894ebb5bc8e3af4be9 Mon Sep 17 00:00:00 2001 From: Jun Li Date: Tue, 15 Jun 2021 20:35:46 -0700 Subject: [PATCH 29/52] Add support to build queryTest, cliTest and osTest (#6497) --- src/client/tests/CMakeLists.txt | 7 ++++++- src/os/tests/CMakeLists.txt | 7 ++++++- src/query/src/qTsbuf.c | 29 +++++++++++++---------------- src/query/tests/CMakeLists.txt | 8 +++++++- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/client/tests/CMakeLists.txt b/src/client/tests/CMakeLists.txt index f07af85e25..1a6c45aade 100644 --- a/src/client/tests/CMakeLists.txt +++ b/src/client/tests/CMakeLists.txt @@ -7,7 +7,12 @@ FIND_LIBRARY(LIB_GTEST_STATIC_DIR libgtest.a /usr/lib/ /usr/local/lib) IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) MESSAGE(STATUS "gTest library found, build unit test") - INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR}) + # GoogleTest requires at least C++11 + SET(CMAKE_CXX_STANDARD 11) + + INCLUDE_DIRECTORIES(/usr/include /usr/local/include) + LINK_DIRECTORIES(/usr/lib /usr/local/lib) + AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(cliTest ${SOURCE_LIST}) diff --git a/src/os/tests/CMakeLists.txt b/src/os/tests/CMakeLists.txt index b87e3d2a62..b00f0ebdc8 100644 --- a/src/os/tests/CMakeLists.txt +++ b/src/os/tests/CMakeLists.txt @@ -7,7 +7,12 @@ FIND_LIBRARY(LIB_GTEST_STATIC_DIR libgtest.a /usr/lib/ /usr/local/lib) IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) MESSAGE(STATUS "gTest library found, build unit test") - INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR}) + # GoogleTest requires at least C++11 + SET(CMAKE_CXX_STANDARD 11) + + INCLUDE_DIRECTORIES(/usr/include /usr/local/include) + LINK_DIRECTORIES(/usr/lib /usr/local/lib) + AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(osTest ${SOURCE_LIST}) diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index 5d599ff08a..cf67e37cf2 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -812,34 +812,31 @@ int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf) { int64_t offset = getDataStartOffset(); int32_t size = (int32_t)pSrcBuf->fileSize - (int32_t)offset; - - int64_t rc = taosFSendFile(pDestBuf->f, pSrcBuf->f, &offset, size); + int64_t written = taosFSendFile(pDestBuf->f, pSrcBuf->f, &offset, size); - if (rc == -1) { -// tscError("failed to merge tsBuf from:%s to %s, reason:%s\n", pSrcBuf->path, pDestBuf->path, strerror(errno)); - return -1; - } - - if (rc != size) { -// tscError("failed to merge tsBuf from:%s to %s, reason:%s\n", pSrcBuf->path, pDestBuf->path, strerror(errno)); + if (written == -1 || written != size) { return -1; } pDestBuf->numOfTotal += pSrcBuf->numOfTotal; - + int32_t oldSize = pDestBuf->fileSize; - + + // file meta data may be cached, close and reopen the file for accurate file size. + fclose(pDestBuf->f); + pDestBuf->f = fopen(pDestBuf->path, "rb+"); + if (pDestBuf->f == NULL) { + return -1; + } + struct stat fileStat; if (fstat(fileno(pDestBuf->f), &fileStat) != 0) { return -1; } pDestBuf->fileSize = (uint32_t)fileStat.st_size; - + assert(pDestBuf->fileSize == oldSize + size); - -// tscDebug("tsBuf merge success, %p, path:%s, fd:%d, file size:%d, numOfGroups:%d, autoDelete:%d", pDestBuf, -// pDestBuf->path, fileno(pDestBuf->f), pDestBuf->fileSize, pDestBuf->numOfGroups, pDestBuf->autoDelete); - + return 0; } diff --git a/src/query/tests/CMakeLists.txt b/src/query/tests/CMakeLists.txt index f8b6daaa90..0cfe2ff165 100644 --- a/src/query/tests/CMakeLists.txt +++ b/src/query/tests/CMakeLists.txt @@ -7,11 +7,17 @@ FIND_LIBRARY(LIB_GTEST_STATIC_DIR libgtest.a /usr/lib/ /usr/local/lib) IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) MESSAGE(STATUS "gTest library found, build unit test") + # GoogleTest requires at least C++11 + SET(CMAKE_CXX_STANDARD 11) + + INCLUDE_DIRECTORIES(/usr/include /usr/local/include) + LINK_DIRECTORIES(/usr/lib /usr/local/lib) + INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR}) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(queryTest ${SOURCE_LIST}) - TARGET_LINK_LIBRARIES(queryTest taos query gtest pthread gcov) + TARGET_LINK_LIBRARIES(queryTest taos query gtest pthread) ENDIF() SET_SOURCE_FILES_PROPERTIES(./astTest.cpp PROPERTIES COMPILE_FLAGS -w) From 83aa4e115a4c48484fd7340a4247b37e37cd690e Mon Sep 17 00:00:00 2001 From: xywang Date: Wed, 16 Jun 2021 15:06:33 +0800 Subject: [PATCH 30/52] [TD-4598]: refactored mapping of TD error code to HTTP error code --- src/plugins/http/inc/httpParser.h | 64 ++++++++++ src/plugins/http/src/httpParser.c | 194 +++++++++++++++--------------- src/plugins/http/src/httpResp.c | 78 ++++++------ 3 files changed, 200 insertions(+), 136 deletions(-) diff --git a/src/plugins/http/inc/httpParser.h b/src/plugins/http/inc/httpParser.h index 85ba843716..c7cf7a9608 100644 --- a/src/plugins/http/inc/httpParser.h +++ b/src/plugins/http/inc/httpParser.h @@ -19,6 +19,70 @@ #define HTTP_MAX_URL 5 // http url stack size +#define HTTP_CODE_CONTINUE 100 +#define HTTP_CODE_SWITCHING_PROTOCOL 101 +#define HTTP_CODE_PROCESSING 102 +#define HTTP_CODE_EARLY_HINTS 103 +#define HTTP_CODE_OK 200 +#define HTTP_CODE_CREATED 201 +#define HTTP_CODE_ACCEPTED 202 +#define HTTP_CODE_NON_AUTHORITATIVE_INFO 203 +#define HTTP_CODE_NO_CONTENT 204 +#define HTTP_CODE_RESET_CONTENT 205 +#define HTTP_CODE_PARTIAL_CONTENT 206 +#define HTTP_CODE_MULTI_STATUS 207 +#define HTTP_CODE_ALREADY_REPORTED 208 +#define HTTP_CODE_IM_USED 226 +#define HTTP_CODE_MULTIPLE_CHOICE 300 +#define HTTP_CODE_MOVED_PERMANENTLY 301 +#define HTTP_CODE_FOUND 302 +#define HTTP_CODE_SEE_OTHER 303 +#define HTTP_CODE_NOT_MODIFIED 304 +#define HTTP_CODE_USE_PROXY 305 +#define HTTP_CODE_UNUSED 306 +#define HTTP_CODE_TEMPORARY_REDIRECT 307 +#define HTTP_CODE_PERMANENT_REDIRECT 308 +#define HTTP_CODE_BAD_REQUEST 400 +#define HTTP_CODE_UNAUTHORIZED 401 +#define HTTP_CODE_PAYMENT_REQUIRED 402 +#define HTTP_CODE_FORBIDDEN 403 +#define HTTP_CODE_NOT_FOUND 404 +#define HTTP_CODE_METHOD_NOT_ALLOWED 405 +#define HTTP_CODE_NOT_ACCEPTABLE 406 +#define HTTP_CODE_PROXY_AUTH_REQUIRED 407 +#define HTTP_CODE_REQUEST_TIMEOUT 408 +#define HTTP_CODE_CONFLICT 409 +#define HTTP_CODE_GONE 410 +#define HTTP_CODE_LENGTH_REQUIRED 411 +#define HTTP_CODE_PRECONDITION_FAILED 412 +#define HTTP_CODE_PAYLOAD_TOO_LARGE 413 +#define HTTP_CODE_URI_TOO_LARGE 414 +#define HTTP_CODE_UNSUPPORTED_MEDIA_TYPE 415 +#define HTTP_CODE_RANGE_NOT_SATISFIABLE 416 +#define HTTP_CODE_EXPECTATION_FAILED 417 +#define HTTP_CODE_IM_A_TEAPOT 418 +#define HTTP_CODE_MISDIRECTED_REQUEST 421 +#define HTTP_CODE_UNPROCESSABLE_ENTITY 422 +#define HTTP_CODE_LOCKED 423 +#define HTTP_CODE_FAILED_DEPENDENCY 424 +#define HTTP_CODE_TOO_EARLY 425 +#define HTTP_CODE_UPGRADE_REQUIRED 426 +#define HTTP_CODE_PRECONDITION_REQUIRED 428 +#define HTTP_CODE_TOO_MANY_REQUESTS 429 +#define HTTP_CODE_REQ_HDR_FIELDS_TOO_LARGE 431 +#define HTTP_CODE_UNAVAIL_4_LEGAL_REASONS 451 +#define HTTP_CODE_INTERNAL_SERVER_ERROR 500 +#define HTTP_CODE_NOT_IMPLEMENTED 501 +#define HTTP_CODE_BAD_GATEWAY 502 +#define HTTP_CODE_SERVICE_UNAVAILABLE 503 +#define HTTP_CODE_GATEWAY_TIMEOUT 504 +#define HTTP_CODE_HTTP_VER_NOT_SUPPORTED 505 +#define HTTP_CODE_VARIANT_ALSO_NEGOTIATES 506 +#define HTTP_CODE_INSUFFICIENT_STORAGE 507 +#define HTTP_CODE_LOOP_DETECTED 508 +#define HTTP_CODE_NOT_EXTENDED 510 +#define HTTP_CODE_NETWORK_AUTH_REQUIRED 511 + typedef enum HTTP_PARSER_STATE { HTTP_PARSER_BEGIN, HTTP_PARSER_REQUEST_OR_RESPONSE, diff --git a/src/plugins/http/src/httpParser.c b/src/plugins/http/src/httpParser.c index 599991da63..a68a9bd7ed 100644 --- a/src/plugins/http/src/httpParser.c +++ b/src/plugins/http/src/httpParser.c @@ -25,70 +25,70 @@ static void httpOnData(ehttp_gzip_t *gzip, void *arg, const char *buf, int32_t len); static HttpStatus httpStatusCodes[] = { - {100, "Continue"}, - {101, "Switching Protocol"}, - {102, "Processing (WebDAV)"}, - {103, "Early Hints"}, - {200, "OK"}, - {201, "Created"}, - {202, "Accepted"}, - {203, "Non-Authoritative Information"}, - {204, "No Content"}, - {205, "Reset Content"}, - {206, "Partial Content"}, - {207, "Multi-Status (WebDAV)"}, - {208, "Already Reported (WebDAV)"}, - {226, "IM Used (HTTP Delta encoding)"}, - {300, "Multiple Choice"}, - {301, "Moved Permanently"}, - {302, "Found"}, - {303, "See Other"}, - {304, "Not Modified"}, - {305, "Use Proxy"}, - {306, "unused"}, - {307, "Temporary Redirect"}, - {308, "Permanent Redirect"}, - {400, "Bad Request"}, - {401, "Unauthorized"}, - {402, "Payment Required"}, - {403, "Forbidden"}, - {404, "Not Found"}, - {405, "Method Not Allowed"}, - {406, "Not Acceptable"}, - {407, "Proxy Authentication Required"}, - {408, "Request Timeout"}, - {409, "Conflict"}, - {410, "Gone"}, - {411, "Length Required"}, - {412, "Precondition Failed"}, - {413, "Payload Too Large"}, - {414, "URI Too Long"}, - {415, "Unsupported Media Type"}, - {416, "Range Not Satisfiable"}, - {417, "Expectation Failed"}, - {418, "I'm a teapot"}, - {421, "Misdirected Request"}, - {422, "Unprocessable Entity (WebDAV)"}, - {423, "Locked (WebDAV)"}, - {424, "Failed Dependency (WebDAV)"}, - {425, "Too Early"}, - {426, "Upgrade Required"}, - {428, "Precondition Required"}, - {429, "Too Many Requests"}, - {431, "Request Header Fields Too Large"}, - {451, "Unavailable For Legal Reasons"}, - {500, "Internal Server Error"}, - {501, "Not Implemented"}, - {502, "Bad Gateway"}, - {503, "Service Unavailable"}, - {504, "Gateway Timeout"}, - {505, "HTTP Version Not Supported"}, - {506, "Variant Also Negotiates"}, - {507, "Insufficient Storage"}, - {508, "Loop Detected (WebDAV)"}, - {510, "Not Extended"}, - {511, "Network Authentication Required"}, - {0, NULL} + {HTTP_CODE_CONTINUE, "Continue"}, + {HTTP_CODE_SWITCHING_PROTOCOL, "Switching Protocol"}, + {HTTP_CODE_PROCESSING, "Processing (WebDAV)"}, + {HTTP_CODE_EARLY_HINTS, "Early Hints"}, + {HTTP_CODE_OK, "OK"}, + {HTTP_CODE_CREATED, "Created"}, + {HTTP_CODE_ACCEPTED, "Accepted"}, + {HTTP_CODE_NON_AUTHORITATIVE_INFO, "Non-Authoritative Information"}, + {HTTP_CODE_NO_CONTENT, "No Content"}, + {HTTP_CODE_RESET_CONTENT, "Reset Content"}, + {HTTP_CODE_PARTIAL_CONTENT, "Partial Content"}, + {HTTP_CODE_MULTI_STATUS, "Multi-Status (WebDAV)"}, + {HTTP_CODE_ALREADY_REPORTED, "Already Reported (WebDAV)"}, + {HTTP_CODE_IM_USED, "IM Used (HTTP Delta encoding)"}, + {HTTP_CODE_MULTIPLE_CHOICE, "Multiple Choice"}, + {HTTP_CODE_MOVED_PERMANENTLY, "Moved Permanently"}, + {HTTP_CODE_FOUND, "Found"}, + {HTTP_CODE_SEE_OTHER, "See Other"}, + {HTTP_CODE_NOT_MODIFIED, "Not Modified"}, + {HTTP_CODE_USE_PROXY, "Use Proxy"}, + {HTTP_CODE_UNUSED, "unused"}, + {HTTP_CODE_TEMPORARY_REDIRECT, "Temporary Redirect"}, + {HTTP_CODE_PERMANENT_REDIRECT, "Permanent Redirect"}, + {HTTP_CODE_BAD_REQUEST, "Bad Request"}, + {HTTP_CODE_UNAUTHORIZED, "Unauthorized"}, + {HTTP_CODE_PAYMENT_REQUIRED, "Payment Required"}, + {HTTP_CODE_FORBIDDEN, "Forbidden"}, + {HTTP_CODE_NOT_FOUND, "Not Found"}, + {HTTP_CODE_METHOD_NOT_ALLOWED, "Method Not Allowed"}, + {HTTP_CODE_NOT_ACCEPTABLE, "Not Acceptable"}, + {HTTP_CODE_PROXY_AUTH_REQUIRED, "Proxy Authentication Required"}, + {HTTP_CODE_REQUEST_TIMEOUT, "Request Timeout"}, + {HTTP_CODE_CONFLICT, "Conflict"}, + {HTTP_CODE_GONE, "Gone"}, + {HTTP_CODE_LENGTH_REQUIRED, "Length Required"}, + {HTTP_CODE_PRECONDITION_FAILED, "Precondition Failed"}, + {HTTP_CODE_PAYLOAD_TOO_LARGE, "Payload Too Large"}, + {HTTP_CODE_URI_TOO_LARGE, "URI Too Long"}, + {HTTP_CODE_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type"}, + {HTTP_CODE_RANGE_NOT_SATISFIABLE, "Range Not Satisfiable"}, + {HTTP_CODE_EXPECTATION_FAILED, "Expectation Failed"}, + {HTTP_CODE_IM_A_TEAPOT, "I'm a teapot"}, + {HTTP_CODE_MISDIRECTED_REQUEST, "Misdirected Request"}, + {HTTP_CODE_UNPROCESSABLE_ENTITY, "Unprocessable Entity (WebDAV)"}, + {HTTP_CODE_LOCKED, "Locked (WebDAV)"}, + {HTTP_CODE_FAILED_DEPENDENCY, "Failed Dependency (WebDAV)"}, + {HTTP_CODE_TOO_EARLY, "Too Early"}, + {HTTP_CODE_UPGRADE_REQUIRED, "Upgrade Required"}, + {HTTP_CODE_PRECONDITION_REQUIRED, "Precondition Required"}, + {HTTP_CODE_TOO_MANY_REQUESTS, "Too Many Requests"}, + {HTTP_CODE_REQ_HDR_FIELDS_TOO_LARGE,"Request Header Fields Too Large"}, + {HTTP_CODE_UNAVAIL_4_LEGAL_REASONS, "Unavailable For Legal Reasons"}, + {HTTP_CODE_INTERNAL_SERVER_ERROR, "Internal Server Error"}, + {HTTP_CODE_NOT_IMPLEMENTED, "Not Implemented"}, + {HTTP_CODE_BAD_GATEWAY, "Bad Gateway"}, + {HTTP_CODE_SERVICE_UNAVAILABLE, "Service Unavailable"}, + {HTTP_CODE_GATEWAY_TIMEOUT, "Gateway Timeout"}, + {HTTP_CODE_HTTP_VER_NOT_SUPPORTED, "HTTP Version Not Supported"}, + {HTTP_CODE_VARIANT_ALSO_NEGOTIATES, "Variant Also Negotiates"}, + {HTTP_CODE_INSUFFICIENT_STORAGE, "Insufficient Storage"}, + {HTTP_CODE_LOOP_DETECTED, "Loop Detected (WebDAV)"}, + {HTTP_CODE_NOT_EXTENDED, "Not Extended"}, + {HTTP_CODE_NETWORK_AUTH_REQUIRED, "Network Authentication Required"}, + {0, NULL} }; char *httpGetStatusDesc(int32_t statusCode) { @@ -552,7 +552,7 @@ static int32_t httpParserOnBegin(HttpParser *parser, HTTP_PARSER_STATE state, co if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); break; } httpPopStack(parser); @@ -561,7 +561,7 @@ static int32_t httpParserOnBegin(HttpParser *parser, HTTP_PARSER_STATE state, co } httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); } while (0); return ok; } @@ -599,7 +599,7 @@ static int32_t httpParserOnRquestOrResponse(HttpParser *parser, HTTP_PARSER_STAT httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); } while (0); return ok; } @@ -612,7 +612,7 @@ static int32_t httpParserOnMethod(HttpParser *parser, HTTP_PARSER_STATE state, c if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); break; } break; @@ -621,7 +621,7 @@ static int32_t httpParserOnMethod(HttpParser *parser, HTTP_PARSER_STATE state, c if (!parser->method) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); break; } else { httpTrace("context:%p, fd:%d, httpMethod:%s", pContext, pContext->fd, parser->method); @@ -641,7 +641,7 @@ static int32_t httpParserOnTarget(HttpParser *parser, HTTP_PARSER_STATE state, c if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_TARGET_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_TARGET_FAILED); break; } break; @@ -650,7 +650,7 @@ static int32_t httpParserOnTarget(HttpParser *parser, HTTP_PARSER_STATE state, c if (!parser->target) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_TARGET_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_TARGET_FAILED); break; } httpClearString(&parser->str); @@ -670,13 +670,13 @@ static int32_t httpParserOnVersion(HttpParser *parser, HTTP_PARSER_STATE state, if (prefix[parser->str.pos] != c) { httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); break; } if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); break; } break; @@ -685,14 +685,14 @@ static int32_t httpParserOnVersion(HttpParser *parser, HTTP_PARSER_STATE state, if (c != '0' && c != '1' && c != '2') { httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); break; } if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); break; } @@ -709,7 +709,7 @@ static int32_t httpParserOnVersion(HttpParser *parser, HTTP_PARSER_STATE state, if (!parser->version) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); break; } @@ -739,7 +739,7 @@ static int32_t httpParserOnSp(HttpParser *parser, HTTP_PARSER_STATE state, const } httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_SP_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_SP_FAILED); } while (0); return ok; } @@ -752,7 +752,7 @@ static int32_t httpParserOnStatusCode(HttpParser *parser, HTTP_PARSER_STATE stat if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_STATUS_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_STATUS_FAILED); break; } if (parser->str.pos < 3) break; @@ -764,7 +764,7 @@ static int32_t httpParserOnStatusCode(HttpParser *parser, HTTP_PARSER_STATE stat } httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_STATUS_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_STATUS_FAILED); } while (0); return ok; } @@ -778,7 +778,7 @@ static int32_t httpParserOnReasonPhrase(HttpParser *parser, HTTP_PARSER_STATE st if (!parser->reasonPhrase) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_PHRASE_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_PHRASE_FAILED); break; } ok = httpOnStatusLine(parser, parser->statusCode, parser->reasonPhrase); @@ -790,7 +790,7 @@ static int32_t httpParserOnReasonPhrase(HttpParser *parser, HTTP_PARSER_STATE st if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_PHRASE_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_PHRASE_FAILED); break; } } while (0); @@ -802,7 +802,7 @@ static int32_t httpParserPostProcess(HttpParser *parser) { if (parser->gzip) { if (ehttp_gzip_finish(parser->gzip)) { httpError("context:%p, fd:%d, gzip failed", pContext, pContext->fd); - httpOnError(parser, 507, TSDB_CODE_HTTP_FINISH_GZIP_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_FINISH_GZIP_FAILED); return -1; } } @@ -819,13 +819,13 @@ static int32_t httpParserOnCrlf(HttpParser *parser, HTTP_PARSER_STATE state, con if (s[parser->str.pos] != c) { httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_CRLF_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_CRLF_FAILED); break; } if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_CRLF_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_CRLF_FAILED); break; } if (parser->str.pos == len) { @@ -862,7 +862,7 @@ static int32_t httpParserOnHeader(HttpParser *parser, HTTP_PARSER_STATE state, c if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_HEADER_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_HEADER_FAILED); break; } httpPushStack(parser, HTTP_PARSER_CRLF); @@ -873,7 +873,7 @@ static int32_t httpParserOnHeader(HttpParser *parser, HTTP_PARSER_STATE state, c } httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_HEADER_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_HEADER_FAILED); } while (0); return ok; } @@ -886,7 +886,7 @@ static int32_t httpParserOnHeaderKey(HttpParser *parser, HTTP_PARSER_STATE state if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED); break; } break; @@ -896,7 +896,7 @@ static int32_t httpParserOnHeaderKey(HttpParser *parser, HTTP_PARSER_STATE state if (!parser->key) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED); break; } httpClearString(&parser->str); @@ -905,7 +905,7 @@ static int32_t httpParserOnHeaderKey(HttpParser *parser, HTTP_PARSER_STATE state } httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED); } while (0); return ok; } @@ -919,7 +919,7 @@ static int32_t httpParserOnHeaderVal(HttpParser *parser, HTTP_PARSER_STATE state httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; parser->parseCode = TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED); break; } break; @@ -948,7 +948,7 @@ static int32_t httpParserOnChunkSize(HttpParser *parser, HTTP_PARSER_STATE state if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED); break; } break; @@ -982,7 +982,7 @@ static int32_t httpParserOnChunkSize(HttpParser *parser, HTTP_PARSER_STATE state } httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED); + httpOnError(parser, HTTP_CODE_BAD_REQUEST, TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED); } while (0); return ok; } @@ -994,7 +994,7 @@ static int32_t httpParserOnChunk(HttpParser *parser, HTTP_PARSER_STATE state, co if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_CHUNK_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_CHUNK_FAILED); break; } ++parser->receivedSize; @@ -1005,7 +1005,7 @@ static int32_t httpParserOnChunk(HttpParser *parser, HTTP_PARSER_STATE state, co if (ehttp_gzip_write(parser->gzip, parser->str.str, parser->str.pos)) { httpError("context:%p, fd:%d, gzip failed", pContext, pContext->fd); ok = -1; - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_CHUNK_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_CHUNK_FAILED); break; } } else { @@ -1027,7 +1027,7 @@ static int32_t httpParserOnEnd(HttpParser *parser, HTTP_PARSER_STATE state, cons do { ok = -1; httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); - httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_END_FAILED); + httpOnError(parser, HTTP_CODE_INSUFFICIENT_STORAGE, TSDB_CODE_HTTP_PARSE_END_FAILED); } while (0); return ok; } @@ -1104,7 +1104,7 @@ static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) { ok = -1; httpError("context:%p, fd:%d, unknown parse state:%d", pContext, pContext->fd, state); - httpOnError(parser, 500, TSDB_CODE_HTTP_PARSE_INVALID_STATE); + httpOnError(parser, HTTP_CODE_INTERNAL_SERVER_ERROR, TSDB_CODE_HTTP_PARSE_INVALID_STATE); } while (0); if (ok == -1) { @@ -1115,7 +1115,7 @@ static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) { if (ok == -2) { ok = -1; httpError("context:%p, fd:%d, failed to parse, invalid state", pContext, pContext->fd); - httpOnError(parser, 500, TSDB_CODE_HTTP_PARSE_ERROR_STATE); + httpOnError(parser, HTTP_CODE_INTERNAL_SERVER_ERROR, TSDB_CODE_HTTP_PARSE_ERROR_STATE); } return ok; diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index 4fcf236fce..79e728dd45 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -67,81 +67,81 @@ static void httpSendErrorRespImp(HttpContext *pContext, int32_t httpCode, char * } void httpSendErrorResp(HttpContext *pContext, int32_t errNo) { - int32_t httpCode = 500; + int32_t httpCode = HTTP_CODE_INTERNAL_SERVER_ERROR; if (errNo == TSDB_CODE_SUCCESS) - httpCode = 200; + httpCode = HTTP_CODE_OK; else if (errNo == TSDB_CODE_HTTP_SERVER_OFFLINE) - httpCode = 404; + httpCode = HTTP_CODE_NOT_FOUND; else if (errNo == TSDB_CODE_HTTP_UNSUPPORT_URL) - httpCode = 404; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_INVALID_URL) - httpCode = 404; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_NO_ENOUGH_MEMORY) - httpCode = 507; + httpCode = HTTP_CODE_INSUFFICIENT_STORAGE; else if (errNo == TSDB_CODE_HTTP_REQUSET_TOO_BIG) - httpCode = 413; + httpCode = HTTP_CODE_PAYLOAD_TOO_LARGE; else if (errNo == TSDB_CODE_HTTP_NO_AUTH_INFO) - httpCode = 401; + httpCode = HTTP_CODE_UNAUTHORIZED; else if (errNo == TSDB_CODE_HTTP_NO_MSG_INPUT) - httpCode = 400; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_NO_SQL_INPUT) - httpCode = 400; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_NO_EXEC_USEDB) - httpCode = 400; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_SESSION_FULL) - httpCode = 421; + httpCode = HTTP_CODE_INTERNAL_SERVER_ERROR; else if (errNo == TSDB_CODE_HTTP_GEN_TAOSD_TOKEN_ERR) - httpCode = 507; + httpCode = HTTP_CODE_INTERNAL_SERVER_ERROR; else if (errNo == TSDB_CODE_HTTP_INVALID_MULTI_REQUEST) - httpCode = 400; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_CREATE_GZIP_FAILED) - httpCode = 507; + httpCode = HTTP_CODE_INTERNAL_SERVER_ERROR; else if (errNo == TSDB_CODE_HTTP_FINISH_GZIP_FAILED) - httpCode = 507; + httpCode = HTTP_CODE_INTERNAL_SERVER_ERROR; else if (errNo == TSDB_CODE_HTTP_INVALID_VERSION) - httpCode = 406; + httpCode = HTTP_CODE_HTTP_VER_NOT_SUPPORTED; else if (errNo == TSDB_CODE_HTTP_INVALID_CONTENT_LENGTH) - httpCode = 406; + httpCode = HTTP_CODE_LENGTH_REQUIRED; else if (errNo == TSDB_CODE_HTTP_INVALID_AUTH_TYPE) - httpCode = 406; + httpCode = HTTP_CODE_UNAUTHORIZED; else if (errNo == TSDB_CODE_HTTP_INVALID_AUTH_FORMAT) - httpCode = 406; + httpCode = HTTP_CODE_UNAUTHORIZED; else if (errNo == TSDB_CODE_HTTP_INVALID_BASIC_AUTH) - httpCode = 406; + httpCode = HTTP_CODE_UNAUTHORIZED; else if (errNo == TSDB_CODE_HTTP_INVALID_TAOSD_AUTH) - httpCode = 406; + httpCode = HTTP_CODE_UNAUTHORIZED; else if (errNo == TSDB_CODE_HTTP_PARSE_METHOD_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_TARGET_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_VERSION_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_SP_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_STATUS_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_PHRASE_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_CRLF_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_HEADER_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_CHUNK_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_END_FAILED) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_INVALID_STATE) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else if (errNo == TSDB_CODE_HTTP_PARSE_ERROR_STATE) - httpCode = 406; + httpCode = HTTP_CODE_BAD_REQUEST; else - httpCode = 400; + httpCode = HTTP_CODE_BAD_REQUEST; if (pContext->parser && pContext->parser->httpCode != 0) { httpCode = pContext->parser->httpCode; @@ -152,7 +152,7 @@ void httpSendErrorResp(HttpContext *pContext, int32_t errNo) { } void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char *errMsg) { - int32_t httpCode = 400; + int32_t httpCode = HTTP_CODE_BAD_REQUEST; char temp[512] = {0}; int32_t len = sprintf(temp, "invalid SQL: %s", errMsg); From c77c1091a394438054722199fe377ae1a2ea4cfe Mon Sep 17 00:00:00 2001 From: lichuang Date: Wed, 16 Jun 2021 16:08:24 +0800 Subject: [PATCH 31/52] [TD-4394]fix core when select data after modify tag width --- src/tsdb/src/tsdbMeta.c | 4 +++- src/util/src/tskiplist.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 17223c99fe..b4d41dcd08 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -148,7 +148,9 @@ int tsdbCreateTable(STsdbRepo *repo, STableCfg *pCfg) { return 0; _err: - //tsdbFreeTable(super); + if (newSuper) { + tsdbFreeTable(super); + } tsdbFreeTable(table); return -1; } diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 0a394c15c9..842ded19a6 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -85,7 +85,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _ } void tSkipListDestroy(SSkipList *pSkipList) { - if (pSkipList == NULL || pSkipList->pHead == NULL) return; + if (pSkipList == NULL) return; tSkipListWLock(pSkipList); From d1d2ad540b1d3b4be141d9c3abf7d0faa260f90d Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 16 Jun 2021 17:04:51 +0800 Subject: [PATCH 32/52] [TD-4671]: mark dropped dnode in dnodeCfg.json & exit early when startup --- src/dnode/inc/dnodeCfg.h | 1 + src/dnode/src/dnodeCfg.c | 22 ++++++++++++++++++++++ src/dnode/src/dnodeVnodes.c | 1 + 3 files changed, 24 insertions(+) diff --git a/src/dnode/inc/dnodeCfg.h b/src/dnode/inc/dnodeCfg.h index 896b3f574c..99733e46ef 100644 --- a/src/dnode/inc/dnodeCfg.h +++ b/src/dnode/inc/dnodeCfg.h @@ -27,6 +27,7 @@ void dnodeUpdateCfg(SDnodeCfg *cfg); int32_t dnodeGetDnodeId(); void dnodeGetClusterId(char *clusterId); void dnodeGetCfg(int32_t *dnodeId, char *clusterId); +void dnodeSetDropped(); #ifdef __cplusplus } diff --git a/src/dnode/src/dnodeCfg.c b/src/dnode/src/dnodeCfg.c index c573d709f5..a6bb7a4800 100644 --- a/src/dnode/src/dnodeCfg.c +++ b/src/dnode/src/dnodeCfg.c @@ -21,6 +21,7 @@ static SDnodeCfg tsCfg = {0}; static pthread_mutex_t tsCfgMutex; +static int32_t tsDnodeDropped; static int32_t dnodeReadCfg(); static int32_t dnodeWriteCfg(); @@ -34,6 +35,10 @@ int32_t dnodeInitCfg() { if (ret == 0) { dInfo("dnode cfg is initialized"); } + if (tsDnodeDropped) { + dInfo("dnode is dropped, exiting"); + return -1; + } return ret; } @@ -44,6 +49,14 @@ void dnodeUpdateCfg(SDnodeCfg *cfg) { dnodeResetCfg(cfg); } +void dnodeSetDropped() { + pthread_mutex_lock(&tsCfgMutex); + tsDnodeDropped = 1; + + dnodeWriteCfg(); + pthread_mutex_unlock(&tsCfgMutex); +} + int32_t dnodeGetDnodeId() { int32_t dnodeId = 0; pthread_mutex_lock(&tsCfgMutex); @@ -119,6 +132,14 @@ static int32_t dnodeReadCfg() { } cfg.dnodeId = (int32_t)dnodeId->valueint; + cJSON *dnodeDropped = cJSON_GetObjectItem(root, "dnodeDropped"); + if (!dnodeDropped || dnodeDropped->type != cJSON_Number) { + dError("failed to read %s, dnodeDropped not found", file); + //goto PARSE_CFG_OVER; + } else { + tsDnodeDropped = (int32_t)dnodeDropped->valueint; + } + cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); if (!clusterId || clusterId->type != cJSON_String) { dError("failed to read %s, clusterId not found", file); @@ -154,6 +175,7 @@ static int32_t dnodeWriteCfg() { len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", tsCfg.dnodeId); + len += snprintf(content + len, maxLen - len, " \"dnodeDropped\": %d,\n", tsDnodeDropped); len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%s\"\n", tsCfg.clusterId); len += snprintf(content + len, maxLen - len, "}\n"); diff --git a/src/dnode/src/dnodeVnodes.c b/src/dnode/src/dnodeVnodes.c index d96251cebe..f01a510370 100644 --- a/src/dnode/src/dnodeVnodes.c +++ b/src/dnode/src/dnodeVnodes.c @@ -202,6 +202,7 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) { char clusterId[TSDB_CLUSTER_ID_LEN]; dnodeGetClusterId(clusterId); if (clusterId[0] != '\0') { + dnodeSetDropped(); dError("exit zombie dropped dnode"); exit(EXIT_FAILURE); } From 97952bff6f16d350975ecb6bf8f596be480cc07e Mon Sep 17 00:00:00 2001 From: zyyang <69311263+zyyang-taosdata@users.noreply.github.com> Date: Wed, 16 Jun 2021 18:22:51 +0800 Subject: [PATCH 33/52] [TD-4696]: fix the connection multi taosd error within jdbc-restful (#6499) --- cmake/install.inc | 2 +- src/connector/jdbc/CMakeLists.txt | 3 +- src/connector/jdbc/deploy-pom.xml | 2 +- src/connector/jdbc/pom.xml | 3 +- .../taosdata/jdbc/rs/RestfulConnection.java | 9 ++- .../com/taosdata/jdbc/rs/RestfulDriver.java | 12 ++-- .../taosdata/jdbc/rs/RestfulStatement.java | 6 +- .../jdbc/utils/HttpClientPoolUtil.java | 44 ++++++-------- .../taosdata/jdbc/cases/BatchInsertTest.java | 4 +- ...iTaosdByRestfulWithDifferentTokenTest.java | 59 +++++++++++++++++++ 10 files changed, 97 insertions(+), 47 deletions(-) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java diff --git a/cmake/install.inc b/cmake/install.inc index 63764348d3..b37cf751fb 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.30.jar DESTINATION connector/jdbc) + INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.31.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 a04902a422..f6829bd0ea 100644 --- a/src/connector/jdbc/CMakeLists.txt +++ b/src/connector/jdbc/CMakeLists.txt @@ -8,9 +8,8 @@ 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.30.jar ${LIBRARY_OUTPUT_PATH} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.31.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}) ENDIF () - diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml index 657645d46c..8f77582d30 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.30 + 2.0.31 jar JDBCDriver diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 96e17bcd9b..8ec65a243e 100644 --- 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.30 + 2.0.31 jar JDBCDriver https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc @@ -123,6 +123,7 @@ **/InvalidResultSetPointerTest.java **/RestfulConnectionTest.java **/TD4144Test.java + **/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java true diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java index b810f9aeb5..d6a02b7e3a 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java @@ -17,16 +17,18 @@ public class RestfulConnection extends AbstractConnection { private final int port; private final String url; private volatile String database; + private final String token; /******************************************************/ private boolean isClosed; private final DatabaseMetaData metadata; - public RestfulConnection(String host, String port, Properties props, String database, String url) { + public RestfulConnection(String host, String port, Properties props, String database, String url, String token) { super(props); this.host = host; this.port = Integer.parseInt(port); this.database = database; this.url = url; + this.token = token; this.metadata = new RestfulDatabaseMetaData(url, props.getProperty(TSDBDriver.PROPERTY_KEY_USER), this); } @@ -66,6 +68,7 @@ public class RestfulConnection extends AbstractConnection { return this.metadata; } + // getters public String getHost() { return host; } @@ -81,4 +84,8 @@ public class RestfulConnection extends AbstractConnection { public String getUrl() { return url; } + + public String getToken() { + return token; + } } \ No newline at end of file diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java index a94cfa6e07..9ab67c5502 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java @@ -38,15 +38,11 @@ public class RestfulDriver extends AbstractDriver { String port = props.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "6041"); String database = props.containsKey(TSDBDriver.PROPERTY_KEY_DBNAME) ? props.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME) : null; - String loginUrl = "http://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST) + ":" - + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/login/" - + props.getProperty(TSDBDriver.PROPERTY_KEY_USER) + "/" - + props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD) + ""; + String loginUrl = "http://" + host + ":" + port + "/rest/login/" + props.getProperty(TSDBDriver.PROPERTY_KEY_USER) + "/" + props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD) + ""; try { String user = URLEncoder.encode(props.getProperty(TSDBDriver.PROPERTY_KEY_USER), "UTF-8"); String password = URLEncoder.encode(props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD), "UTF-8"); - loginUrl = "http://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST) + ":" - + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/login/" + user + "/" + password + ""; + loginUrl = "http://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST) + ":" + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/login/" + user + "/" + password + ""; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } @@ -55,12 +51,12 @@ public class RestfulDriver extends AbstractDriver { JSONObject jsonResult = JSON.parseObject(result); String status = jsonResult.getString("status"); String token = jsonResult.getString("desc"); - HttpClientPoolUtil.token = token; + if (!status.equals("succ")) { throw new SQLException(jsonResult.getString("desc")); } - RestfulConnection conn = new RestfulConnection(host, port, props, database, url); + RestfulConnection conn = new RestfulConnection(host, port, props, database, url, token); if (database != null && !database.trim().replaceAll("\\s", "").isEmpty()) { Statement stmt = conn.createStatement(); stmt.execute("use " + database); 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 fbc3a50a27..e9d193f6b4 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 @@ -83,7 +83,7 @@ public class RestfulStatement extends AbstractStatement { } if (SqlSyntaxValidator.isUseSql(sql)) { - HttpClientPoolUtil.execute(url, sql); + HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); this.database = sql.trim().replace("use", "").trim(); this.conn.setCatalog(this.database); result = false; @@ -116,7 +116,7 @@ public class RestfulStatement extends AbstractStatement { if ("UTC".equalsIgnoreCase(timestampFormat)) url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlutc"; - String result = HttpClientPoolUtil.execute(url, sql); + String result = HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); JSONObject resultJson = JSON.parseObject(result); if (resultJson.getString("status").equals("error")) { throw TSDBError.createSQLException(resultJson.getInteger("code"), resultJson.getString("desc")); @@ -130,7 +130,7 @@ public class RestfulStatement extends AbstractStatement { if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql)) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: " + sql); - String result = HttpClientPoolUtil.execute(url, sql); + String result = HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); JSONObject jsonObject = JSON.parseObject(result); if (jsonObject.getString("status").equals("error")) { throw TSDBError.createSQLException(jsonObject.getInteger("code"), jsonObject.getString("desc")); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java index 5e2440fd1d..b1c6dae6b3 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java @@ -20,39 +20,29 @@ import java.nio.charset.Charset; public class HttpClientPoolUtil { - public static PoolingHttpClientConnectionManager cm = null; - public static CloseableHttpClient httpClient = null; - public static String token = "cm9vdDp0YW9zZGF0YQ=="; - /** - * 默认content 类型 - */ - private static final String DEFAULT_CONTENT_TYPE = "application/json"; - /** - * 默认请求超时时间30s - */ - private static final int DEFAULT_TIME_OUT = 15000; - private static final int count = 32; - private static final int totalCount = 1000; - private static final int Http_Default_Keep_Time = 15000; - /** - * 初始化连接池 - */ + private static final String DEFAULT_CONTENT_TYPE = "application/json"; + private static final String DEFAULT_TOKEN = "cm9vdDp0YW9zZGF0YQ=="; + private static final int DEFAULT_TIME_OUT = 15000; + private static final int DEFAULT_MAX_PER_ROUTE = 32; + private static final int DEFAULT_MAX_TOTAL = 1000; + private static final int DEFAULT_HTTP_KEEP_TIME = 15000; + + private static PoolingHttpClientConnectionManager connectionManager; + private static CloseableHttpClient httpClient; + private static synchronized void initPools() { if (httpClient == null) { - cm = new PoolingHttpClientConnectionManager(); - cm.setDefaultMaxPerRoute(count); - cm.setMaxTotal(totalCount); - httpClient = HttpClients.custom().setKeepAliveStrategy(defaultStrategy).setConnectionManager(cm).build(); + connectionManager = new PoolingHttpClientConnectionManager(); + connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE); + connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL); + httpClient = HttpClients.custom().setKeepAliveStrategy(DEFAULT_KEEP_ALIVE_STRATEGY).setConnectionManager(connectionManager).build(); } } - /** - * Http connection keepAlive 设置 - */ - private static ConnectionKeepAliveStrategy defaultStrategy = (response, context) -> { + private static ConnectionKeepAliveStrategy DEFAULT_KEEP_ALIVE_STRATEGY = (response, context) -> { HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); - int keepTime = Http_Default_Keep_Time * 1000; + int keepTime = DEFAULT_HTTP_KEEP_TIME * 1000; while (it.hasNext()) { HeaderElement headerElement = it.nextElement(); String param = headerElement.getName(); @@ -76,7 +66,7 @@ public class HttpClientPoolUtil { * @param data 请求数据 * @return responseBody */ - public static String execute(String uri, String data) { + public static String execute(String uri, String data, String token) { long startTime = System.currentTimeMillis(); HttpEntity httpEntity = null; HttpEntityEnclosingRequestBase method = null; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java index 472da34980..e2541e8109 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java @@ -28,9 +28,7 @@ public class BatchInsertTest { @Before public void before() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); @@ -44,7 +42,7 @@ public class BatchInsertTest { String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))"; statement.executeUpdate(createTableSql); // create tables - for(int i = 0; i < numOfTables; i++) { + for (int i = 0; i < numOfTables; i++) { String loc = i % 2 == 0 ? "beijing" : "shanghai"; String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')"; statement.executeUpdate(createSubTalbesSql); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java new file mode 100644 index 0000000000..7f2d367dce --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java @@ -0,0 +1,59 @@ +package com.taosdata.jdbc.cases; + +import com.taosdata.jdbc.TSDBDriver; +import org.junit.Before; +import org.junit.Test; + +import java.sql.*; +import java.util.Properties; + +public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { + + private static String host1 = "192.168.17.156"; + private static String user1 = "root"; + private static String password1 = "tqueue"; + private Connection conn1; + private static String host2 = "192.168.17.82"; + private static String user2 = "root"; + private static String password2 = "taosdata"; + private Connection conn2; + + @Test + public void test() { + //when + executeSelectStatus(conn1); + executeSelectStatus(conn2); + executeSelectStatus(conn1); + } + + private void executeSelectStatus(Connection connection) { + try (Statement stmt = connection.createStatement()) { + ResultSet rs = stmt.executeQuery("select server_status()"); + ResultSetMetaData meta = rs.getMetaData(); + while (rs.next()) { + for (int i = 1; i <= meta.getColumnCount(); i++) { + System.out.println(meta.getColumnLabel(i) + ": " + rs.getString(i)); + } + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Before + public void before() { + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + + String url1 = "jdbc:TAOS-RS://" + host1 + ":6041/?user=" + user1 + "&password=" + password1; + String url2 = "jdbc:TAOS-RS://" + host2 + ":6041/?user=" + user2 + "&password=" + password2; + try { + conn1 = DriverManager.getConnection(url1, properties); + conn2 = DriverManager.getConnection(url2, properties); + } catch (SQLException e) { + e.printStackTrace(); + } + } +} From 402762bdbcde651c6bec7c22e1cf87c336c5ece7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Jun 2021 23:48:23 +0800 Subject: [PATCH 34/52] [TD-4737] --- src/client/src/tscSQLParser.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 82a3a1f55b..5646dc2f11 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -956,8 +956,10 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable) { const char* msg1 = "invalid column name"; + const char* msg2 = "invalid column type"; const char* msg3 = "not support state_window with group by "; const char* msg4 = "function not support for super table query"; + const char* msg5 = "not support state_window on tag column"; SStrToken *col = &(pSqlNode->windowstateVal.col) ; if (col->z == NULL || col->n <= 0) { @@ -985,8 +987,10 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; int32_t numOfCols = tscGetNumOfColumns(pTableMeta); - if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX || index.columnIndex >= numOfCols) { + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + } else if (index.columnIndex >= numOfCols) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } SGroupbyExpr* pGroupExpr = &pQueryInfo->groupbyExpr; @@ -995,8 +999,10 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS } SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, index.columnIndex); - if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP || pSchema->type == TSDB_DATA_TYPE_FLOAT || pSchema->type == TSDB_DATA_TYPE_DOUBLE) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP || pSchema->type == TSDB_DATA_TYPE_FLOAT + || pSchema->type == TSDB_DATA_TYPE_DOUBLE || pSchema->type == TSDB_DATA_TYPE_NCHAR + || pSchema->type == TSDB_DATA_TYPE_BINARY) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } tscColumnListInsert(pQueryInfo->colList, index.columnIndex, pTableMeta->id.uid, pSchema); From 9b6460e1750df2f3634c3c2bc64ca13c50eee2a6 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 17 Jun 2021 02:59:37 +0000 Subject: [PATCH 35/52] [TD-4608] add test case for stmt error --- tests/script/api/stmtBatchTest.c | 649 +++++++++++++++++++++++++++++++ 1 file changed, 649 insertions(+) diff --git a/tests/script/api/stmtBatchTest.c b/tests/script/api/stmtBatchTest.c index 24291adfa0..c488f2fa89 100644 --- a/tests/script/api/stmtBatchTest.c +++ b/tests/script/api/stmtBatchTest.c @@ -4406,6 +4406,654 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { } +/*=======================*/ +/* +char * taos_stmt_errstr(TAOS_STMT *stmt) 用于在其他stmt API 返回错误(返回错误码或空指针)时获取错误信息,返回的错误信息可能是以下3种的一个: +1. 当stmt或sqlobj为空时的terrno对于的错误消息; +2. (可有的)详细错误消息; +3. 返回的错误码对于的错误消息; +*/ +static int stmt_specifyCol_bind_error_case_001(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { + sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + + int totalRowsPerTbl = rowsOfPerColum * bingNum; + + v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + + int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + + int64_t tts = 1591060628000; + + for (int i = 0; i < rowsOfPerColum; ++i) { + lb[i] = lenOfBinaryAct; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v->b[i] = (int8_t)(i % 2); + v->v1[i] = (int8_t)((i+1) % 2); + v->v2[i] = (int16_t)i; + v->v4[i] = (int32_t)(i+1); + v->v8[i] = (int64_t)(i+2); + v->f4[i] = (float)(i+3); + v->f8[i] = (double)(i+4); + char tbuf[MAX_BINARY_DEF_LEN]; + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "binary-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->br + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "nchar-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->nr + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + v->ts2[i] = tts + i; + } + + int i = 0; + for (int j = 0; j < bingNum * tableNum; j++) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v->ts[j*rowsOfPerColum]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = rowsOfPerColum; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v->b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = rowsOfPerColum; + + params[i+2].buffer_type = TSDB_DATA_TYPE_INT; + params[i+2].buffer_length = sizeof(int32_t); + params[i+2].buffer = v->v4; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = rowsOfPerColum; + + params[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+3].buffer_length = sizeof(float); + params[i+3].buffer = v->f4; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = rowsOfPerColum; + + params[i+4].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+4].buffer_length = (uintptr_t)lenOfBinaryDef; + params[i+4].buffer = v->br; + params[i+4].length = lb; + params[i+4].is_null = is_null; + params[i+4].num = rowsOfPerColum; + + i+=columnNum; + } + + //int64_t tts = 1591060628000; + for (int i = 0; i < totalRowsPerTbl * tableNum; ++i) { + v->ts[i] = tts + i; + } + + unsigned long long starttime = getCurrentTime(); + +// create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, br binary(%d), nr nchar(%d), ts2 timestamp) + char *sql = "insert into m0 (ts,b,v4,f4,br) values(?,?,?,?,?)"; + + int code; + //TAOS_STMT *stmtNull = NULL; + //int code = taos_stmt_prepare(stmtNull, sql, 0); + //if (code != 0){ + // printf("failed to execute taos_stmt_prepare. code:0x%x[%s][%s]\n", code, tstrerror(code), taos_stmt_errstr(stmtNull)); + // return -1; + //} + + //char* sqlNull = NULL; + //code = taos_stmt_prepare(stmt, sqlNull, 0); + //if (code != 0){ + // printf("failed to execute taos_stmt_prepare. code:0x%x[%s][%s]\n", code, tstrerror(code), taos_stmt_errstr(stmt)); + //} + + code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x[%s][%s]\n", code, tstrerror(code), taos_stmt_errstr(stmt)); + return -1; + } + + int id = 0; + for (int l = 0; l < bingNum; l++) { + for (int zz = 0; zz < tableNum; zz++) { + //char buf[32]; + //sprintf(buf, "m%d", zz); + //code = taos_stmt_set_tbname(stmt, buf); + //if (code != 0){ + // printf("failed to execute taos_stmt_set_tbname. code:0x%x[%s]\n", code, tstrerror(code)); + // return -1; + //} + + //for (int col=0; col < columnNum + 1000; ++col) { + for (int col=0; col < columnNum; ++col) { + if (col >= columnNum) col = 0; + //code = taos_stmt_bind_single_param_batch(NULL, params + id, col); + //code = taos_stmt_bind_single_param_batch(stmt, NULL, col); + //code = taos_stmt_bind_single_param_batch(stmt, params + id, columnNum); + code = taos_stmt_bind_single_param_batch(stmt, params + id, col); + if (code != 0){ + printf("failed to execute taos_stmt_bind_single_param_batch. code:0x%x[%s][%s]\n", code, tstrerror(code), taos_stmt_errstr(stmt)); + return -1; + } + id++; + } + + //code = taos_stmt_add_batch(NULL); + code = taos_stmt_add_batch(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_add_batch. code:0x%x[%s][%s]\n", code, tstrerror(code), taos_stmt_errstr(stmt)); + return -1; + } + + //code = taos_stmt_add_batch(stmt); + //if (code != 0) { + // printf("failed to execute taos_stmt_add_batch second. code:0x%x[%s][%s]\n", code, tstrerror(code), taos_stmt_errstr(stmt)); + // return -1; + //} + } + + code = taos_stmt_execute(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_execute. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + unsigned long long endtime = getCurrentTime(); + unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); + printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); + + free(v->ts); + free(v->br); + free(v->nr); + free(v); + free(lb); + free(params); + free(is_null); + free(no_null); + + return 0; +} + +static int stmt_specifyCol_bind_error_case_002(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { + sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + + int totalRowsPerTbl = rowsOfPerColum * bingNum; + + v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + + int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + + int64_t tts = 1591060628000; + + for (int i = 0; i < rowsOfPerColum; ++i) { + lb[i] = lenOfBinaryAct; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v->b[i] = (int8_t)(i % 2); + v->v1[i] = (int8_t)((i+1) % 2); + v->v2[i] = (int16_t)i; + v->v4[i] = (int32_t)(i+1); + v->v8[i] = (int64_t)(i+2); + v->f4[i] = (float)(i+3); + v->f8[i] = (double)(i+4); + char tbuf[MAX_BINARY_DEF_LEN]; + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "binary-%d", i%10); + memcpy(v->br + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "nchar-%d", i%10); + memcpy(v->nr + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + v->ts2[i] = tts + i; + } + + int i = 0; + for (int j = 0; j < bingNum * tableNum; j++) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v->ts[j*rowsOfPerColum]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = rowsOfPerColum; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v->b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = rowsOfPerColum; + + params[i+2].buffer_type = TSDB_DATA_TYPE_INT; + params[i+2].buffer_length = sizeof(int32_t); + params[i+2].buffer = v->v4; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = rowsOfPerColum; + + params[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+3].buffer_length = sizeof(float); + params[i+3].buffer = v->f4; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = rowsOfPerColum; + + params[i+4].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+4].buffer_length = (uintptr_t)lenOfBinaryDef; + params[i+4].buffer = v->br; + params[i+4].length = lb; + params[i+4].is_null = is_null; + params[i+4].num = rowsOfPerColum; + + i+=columnNum; + } + + //int64_t tts = 1591060628000; + for (int i = 0; i < totalRowsPerTbl * tableNum; ++i) { + v->ts[i] = tts + i; + } + + unsigned long long starttime = getCurrentTime(); + +// create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, br binary(%d), nr nchar(%d), ts2 timestamp) + char *sql = "insert into ? (ts,b,v4,f4,br) values(?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + int id = 0; + for (int l = 0; l < bingNum; l++) { + for (int zz = 0; zz < tableNum; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + + //stmt=NULL; + code = taos_stmt_set_tbname(stmt, buf); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname. code:0x%x[%s][%s]\n", code, tstrerror(code), taos_stmt_errstr(stmt)); + return -1; + } + + for (int col=0; col < columnNum; ++col) { + code = taos_stmt_bind_single_param_batch(stmt, params + id, col); + if (code != 0){ + printf("failed to execute taos_stmt_bind_single_param_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + id++; + } + + code = taos_stmt_add_batch(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_add_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + code = taos_stmt_execute(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_execute. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + unsigned long long endtime = getCurrentTime(); + unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); + printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); + + free(v->ts); + free(v->br); + free(v->nr); + free(v); + free(lb); + free(params); + free(is_null); + free(no_null); + + return 0; +} + +static void SpecifyColumnBatchErrorCase(TAOS *taos) { + TAOS_STMT *stmt = NULL; + + int tableNum; + int lenOfBinaryDef; + int rowsOfPerColum; + int bingNum; + int lenOfBinaryAct; + int columnNum; + + int totalRowsPerTbl; + +//=======================================================================// +//=============================== single table ==========================// +//========== case 1: ======================// +#if 0 +{ + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 1; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db1"); + stmt_specifyCol_bind_error_case_001(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 1 check result end\n\n"); +} +#endif + + //========== case 2: ======================// +#if 1 +{ + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 5; + bingNum = 1; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 15; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db2"); + stmt_specifyCol_bind_error_case_002(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 2 check result end\n\n"); +} +#endif + + //========== case 2-1: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 32767; + bingNum = 1; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 15; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db2_1"); + stmt_specifyCol_bind_case_001(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 2-1 check result end\n\n"); + } +#endif + //========== case 2-2: ======================// +#if 0 + { + printf("====case 2-2 error test start\n"); + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 32768; + bingNum = 1; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 15; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db2_2"); + stmt_specifyCol_bind_case_001(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("====case 2-2 check result end\n\n"); + } +#endif + + + //========== case 3: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 1; + bingNum = 5; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 20; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db3"); + stmt_specifyCol_bind_case_001(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 3 check result end\n\n"); + } +#endif + + //========== case 4: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 5; + bingNum = 5; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 33; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db4"); + stmt_specifyCol_bind_case_001(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 4 check result end\n\n"); + } +#endif + +//=======================================================================// +//=============================== multi tables ==========================// + //========== case 5: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 5; + rowsOfPerColum = 1; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 16; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db5"); + stmt_specifyCol_bind_case_002(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m1", 0, totalRowsPerTbl); + checkResult(taos, "m2", 0, totalRowsPerTbl); + checkResult(taos, "m3", 0, totalRowsPerTbl); + checkResult(taos, "m4", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 5 check result end\n\n"); + } +#endif + + //========== case 6: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 5; + rowsOfPerColum = 5; + bingNum = 1; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 20; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db6"); + stmt_specifyCol_bind_case_002(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m1", 0, totalRowsPerTbl); + checkResult(taos, "m2", 0, totalRowsPerTbl); + checkResult(taos, "m3", 0, totalRowsPerTbl); + checkResult(taos, "m4", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 6 check result end\n\n"); + } +#endif + + //========== case 7: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 5; + rowsOfPerColum = 1; + bingNum = 5; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 33; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db7"); + stmt_specifyCol_bind_case_002(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m1", 0, totalRowsPerTbl); + checkResult(taos, "m2", 0, totalRowsPerTbl); + checkResult(taos, "m3", 0, totalRowsPerTbl); + checkResult(taos, "m4", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 7 check result end\n\n"); + } +#endif + + //========== case 8: ======================// +#if 0 +{ + stmt = taos_stmt_init(taos); + + tableNum = 5; + rowsOfPerColum = 5; + bingNum = 5; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 40; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db8"); + stmt_specifyCol_bind_case_002(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m1", 0, totalRowsPerTbl); + checkResult(taos, "m2", 0, totalRowsPerTbl); + checkResult(taos, "m3", 0, totalRowsPerTbl); + checkResult(taos, "m4", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 8 check result end\n\n"); +} +#endif + + //=======================================================================// + //=============================== multi-rows to single table ==========================// + //========== case 9: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 23740; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn(taos, 1, tableNum, lenOfBinaryDef, "db9"); + stmt_specifyCol_bind_case_001(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 9 check result end\n\n"); + } +#endif + + return ; + +} + int main(int argc, char *argv[]) { TAOS *taos; @@ -4472,6 +5120,7 @@ int main(int argc, char *argv[]) //runCase_long(taos); //SpecifyColumnBatchCase(taos); SpecifyColumnBatchCase_autoCreateTbl(taos); + //SpecifyColumnBatchErrorCase(taos); return 0; } From affc644242a7ee08fd87510cd502ba6486787a75 Mon Sep 17 00:00:00 2001 From: lichuang Date: Thu, 17 Jun 2021 14:01:46 +0800 Subject: [PATCH 36/52] [TD-4715]bug fix:fix unreset hasRestoreLastColumn flag bug --- src/tsdb/src/tsdbMain.c | 3 +++ src/tsdb/src/tsdbMeta.c | 5 ++++- src/tsdb/src/tsdbRead.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 0cbabb8909..d44f8ec748 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -812,6 +812,7 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) { STable *pTable = pMeta->tables[i]; if (pTable == NULL) continue; pTable->restoreColumnNum = 0; + pTable->hasRestoreLastColumn = false; } } @@ -895,6 +896,7 @@ int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) { maxTableIdx = i; if (cacheLastCol) { pTable->restoreColumnNum = 0; + pTable->hasRestoreLastColumn = false; } } @@ -913,6 +915,7 @@ int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) { } if (need_free_last_col) { tsdbFreeLastColumns(pTable); + pTable->hasRestoreLastColumn = false; } } } diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 8174698197..8d49421194 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -607,6 +607,7 @@ void tsdbFreeLastColumns(STable* pTable) { pTable->maxColNum = 0; pTable->lastColSVersion = -1; pTable->restoreColumnNum = 0; + pTable->hasRestoreLastColumn = false; } int16_t tsdbGetLastColumnsIndexByColId(STable* pTable, int16_t colId) { @@ -643,6 +644,7 @@ int tsdbInitColIdCacheWithSchema(STable* pTable, STSchema* pSchema) { pTable->lastColSVersion = schemaVersion(pSchema); pTable->maxColNum = numOfColumn; pTable->restoreColumnNum = 0; + pTable->hasRestoreLastColumn = false; return 0; } @@ -655,7 +657,7 @@ int tsdbUpdateLastColSchema(STable *pTable, STSchema *pNewSchema) { return 0; } - tsdbInfo("tsdbUpdateLastColSchema:%s,%d->%d", pTable->name->data, pTable->lastColSVersion, schemaVersion(pNewSchema)); + tsdbDebug("tsdbUpdateLastColSchema:%s,%d->%d", pTable->name->data, pTable->lastColSVersion, schemaVersion(pNewSchema)); int16_t numOfCols = pNewSchema->numOfCols; SDataCol *lastCols = (SDataCol*)malloc(numOfCols * sizeof(SDataCol)); @@ -800,6 +802,7 @@ static STable *tsdbNewTable() { pTable->lastCols = NULL; pTable->restoreColumnNum = 0; pTable->maxColNum = 0; + pTable->hasRestoreLastColumn = false; pTable->lastColSVersion = -1; return pTable; } diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 972c3c4e10..4ac900e30e 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -2520,7 +2520,7 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) { int32_t numOfCols = pTable->maxColNum; if (pTable->lastCols == NULL || pTable->maxColNum <= 0) { - tsdbWarn("no last cached for table, uid:%" PRIu64 ",tid:%d", pTable->tableId.uid, pTable->tableId.tid); + tsdbWarn("no last cached for table %s, uid:%" PRIu64 ",tid:%d", pTable->name->data, pTable->tableId.uid, pTable->tableId.tid); continue; } From 5062604688c5ffcb39ece6bf3c093782799096aa Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 17 Jun 2021 14:24:53 +0800 Subject: [PATCH 37/52] [td-4739]: fix bug in derivative. --- src/client/src/tscUtil.c | 1 + src/query/src/qAggMain.c | 11 +---------- tests/script/general/parser/function.sim | 6 ++++++ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 9011bae47b..89f2563e14 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -3477,6 +3477,7 @@ static void tscSubqueryRetrieveCallback(void* param, TAOS_RES* tres, int code) { if (pSql->res.code == TSDB_CODE_SUCCESS) { (*pSql->fp)(pParentSql->param, pParentSql, pParentSql->res.numOfRows); } else { + pParentSql->res.code = pSql->res.code; tscAsyncResultOnError(pParentSql); } } diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 68de902556..bc14c75af5 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -3613,16 +3613,7 @@ static void deriv_function(SQLFunctionCtx *pCtx) { qError("error input type"); } - // initial value is not set yet, all data block are null - if (!pDerivInfo->valueSet || notNullElems <= 0) { - /* - * 1. current block and blocks before are full of null - * 2. current block may be null value - */ - assert(pCtx->hasNull); - } else { - GET_RES_INFO(pCtx)->numOfRes += notNullElems; - } + GET_RES_INFO(pCtx)->numOfRes += notNullElems; } #define DIFF_IMPL(ctx, d, type) \ diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index ad900b92e0..827f21f0bf 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -1073,6 +1073,12 @@ sql insert into t0 values('2020-1-1 1:3:9', 9); sql insert into t0 values('2020-1-1 1:4:10', 10); sql insert into t1 values('2020-1-1 1:1:2', 2); +print ===========================>td-4739 +sql select diff(val) from (select derivative(k, 1s, 0) from t1); +if $rows != 0 then + return -1 +endi + sql insert into t1 values('2020-1-1 1:1:4', 20); sql insert into t1 values('2020-1-1 1:1:6', 200); sql insert into t1 values('2020-1-1 1:1:8', 2000); From 1edb4960cd65b4ef5c72327af34a9caec09517f9 Mon Sep 17 00:00:00 2001 From: happyguoxy Date: Thu, 17 Jun 2021 15:02:49 +0800 Subject: [PATCH 38/52] [TD4541] --- tests/pytest/insert/modify_column.py | 382 +++++++++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 tests/pytest/insert/modify_column.py diff --git a/tests/pytest/insert/modify_column.py b/tests/pytest/insert/modify_column.py new file mode 100644 index 0000000000..3632eb817a --- /dev/null +++ b/tests/pytest/insert/modify_column.py @@ -0,0 +1,382 @@ +################################################################### +# 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 datetime + +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + # test case for https://jira.taosdata.com:18080/browse/TD-4541 + + tdLog.info("=============== step1,check normal table") + + tdLog.info("=============== step1.1,drop table && create table") + cmd1 = 'drop table if exists length11 ;' + cmd2 = 'create table length11 (ts timestamp,lengthbia binary(10),lengthnchar nchar(20));' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + + tdLog.info("=============== step1.2,insert table right data") + cmd1 = 'insert into length11 values(now,\'aaaaaaaaaa\',\'bbbbbbbbbbbbbbbbbbbb\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from length11 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb') + + tdLog.info("=============== step1.3,insert table wrong data") + cmd1 = 'insert into length11 values(now,\'aaaaaaaaaa1\',\'bbbbbbbbbbbbbbbbbbbb1\') ;' + tdLog.info(cmd1) + tdSql.error(cmd1) + try: + tdSql.execute(cmd1) + tdLog.exit("string data overflow") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("insert wrong data error catched") + tdSql.query('select * from length11 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb') + + tdLog.info("=============== step1.4,modify columu length ") + cmd1 = 'alter table length11 modify column lengthbia binary(10) ;' + tdLog.info(cmd1) + tdSql.error(cmd1) + try: + tdSql.execute(cmd1) + tdLog.exit("new column length should be bigger than old one") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("new column length should be bigger than old one") + + cmd2 = 'alter table length11 modify column lengthnchar nchar(20);' + tdLog.info(cmd2) + tdSql.error(cmd2) + try: + tdSql.execute(cmd2) + tdLog.exit("new column length should be bigger than old one") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("new column length should be bigger than old one") + + cmd3 = 'alter table length11 modify column lengthbia binary(11) ;' + cmd4 = 'describe length11 ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdLog.info(cmd4) + tdSql.execute(cmd4) + tdSql.query('describe length11 ;') + tdSql.checkData(1,2,11) + + cmd5 = 'alter table length11 modify column lengthnchar nchar(21);' + cmd6 = 'describe length11 ;' + tdLog.info(cmd5) + tdSql.execute(cmd5) + tdLog.info(cmd6) + tdSql.execute(cmd6) + tdSql.query('describe length11 ;') + tdSql.checkData(2,2,21) + + tdSql.query('select * from length11 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb') + + + tdLog.info("=============== step1.5,insert table right data") + cmd1 = 'insert into length11 values(now,\'aaaaaaaaaa1\',\'bbbbbbbbbbbbbbbbbbbb1\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from length11 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + + + + + tdLog.info("=============== step2,check stable table and tag") + + tdLog.info("=============== step2.1,drop table && create table") + cmd1 = 'drop table if exists length1 ;' + cmd2 = 'drop table if exists length2 ;' + cmd3 = 'drop table if exists length2 ;' + cmd4 = 'drop table if exists lengthsta1 ;' + cmd5 = 'create stable lengthsta1(ts timestamp,lengthbia binary(10),lengthnchar nchar(20)) tags (tlengthbia binary(15),tlengthnchar nchar(25)) ;' + cmd6 = 'create table length1 using lengthsta1 tags(\'aaaaabbbbbaaaaa\',\'bbbbbaaaaabbbbbaaaaabbbbb\') ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdLog.info(cmd4) + tdSql.execute(cmd4) + tdLog.info(cmd5) + tdSql.execute(cmd5) + tdLog.info(cmd6) + tdSql.execute(cmd6) + + tdLog.info("=============== step2.2,insert table right data") + cmd1 = 'insert into length1 values(now,\'aaaaaaaaaa\',\'bbbbbbbbbbbbbbbbbbbb\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from length1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb') + + tdLog.info("=============== step2.3,insert table wrong data") + cmd1 = 'insert into length1 values(now,\'aaaaaaaaaa1\',\'bbbbbbbbbbbbbbbbbbbb1\') ;' + tdLog.info(cmd1) + tdSql.error(cmd1) + try: + tdSql.execute(cmd1) + tdLog.exit("string data overflow") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("insert wrong data error catched") + tdSql.query('select * from length1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb') + + tdLog.info("=============== step2.4,modify columu length ") + cmd0 = 'alter table length1 modify column lengthbia binary(10) ;' + tdLog.info(cmd0) + tdSql.error(cmd0) + try: + tdSql.execute(cmd1) + tdLog.exit("invalid operation: column can only be modified by super table") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: column can only be modified by super table") + + cmd1 = 'alter table lengthsta1 modify column lengthbia binary(10) ;' + tdLog.info(cmd1) + tdSql.error(cmd1) + try: + tdSql.execute(cmd1) + tdLog.exit("new column length should be bigger than old one") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("new column length should be bigger than old one") + + cmd2 = 'alter table lengthsta1 modify column lengthnchar nchar(20);' + tdLog.info(cmd2) + tdSql.error(cmd2) + try: + tdSql.execute(cmd2) + tdLog.exit("new column length should be bigger than old one") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("new column length should be bigger than old one") + + cmd3 = 'alter table lengthsta1 modify column lengthbia binary(11) ;' + cmd4 = 'describe lengthsta1 ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdLog.info(cmd4) + tdSql.execute(cmd4) + tdSql.query('describe length1 ;') + tdSql.checkData(1,2,11) + + cmd5 = 'alter table lengthsta1 modify column lengthnchar nchar(21);' + cmd6 = 'describe lengthsta1 ;' + tdLog.info(cmd5) + tdSql.execute(cmd5) + tdLog.info(cmd6) + tdSql.execute(cmd6) + tdSql.query('describe lengthsta1 ;') + tdSql.checkData(2,2,21) + + tdSql.query('select * from lengthsta1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb') + + + tdLog.info("=============== step2.5,insert table right data") + cmd1 = 'insert into length1 values(now,\'aaaaaaaaaa1\',\'bbbbbbbbbbbbbbbbbbbb1\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from length1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + + + + tdLog.info("=============== step2.6,create table wrong tag") + cmd1 = 'create table length2 using lengthsta1 tags(\'aaaaabbbbbaaaaa1\',\'bbbbbaaaaabbbbbaaaaabbbbb1\') ;' + tdLog.info(cmd1) + tdSql.error(cmd1) + try: + tdSql.execute(cmd1) + tdLog.exit("invalid operation: tag value too long") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: tag value too long") + tdSql.query('select * from lengthsta1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + + tdLog.info("=============== step2.7,modify tag columu length ") + cmd1 = 'alter table lengthsta1 modify tag tlengthbia binary(15) ;' + tdLog.info(cmd1) + tdSql.error(cmd1) + try: + tdSql.execute(cmd1) + tdLog.exit("new column length should be bigger than old one") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("new column length should be bigger than old one") + + cmd2 = 'alter table lengthsta1 modify tag tlengthnchar nchar(25);' + tdLog.info(cmd2) + tdSql.error(cmd2) + try: + tdSql.execute(cmd2) + tdLog.exit("new column length should be bigger than old one") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("new column length should be bigger than old one") + + cmd3 = 'alter table lengthsta1 modify tag tlengthbia binary(16) ;' + cmd4 = 'describe lengthsta1 ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdLog.info(cmd4) + tdSql.execute(cmd4) + tdSql.query('describe lengthsta1 ;') + tdSql.checkData(3,2,16) + + cmd5 = 'alter table lengthsta1 modify tag tlengthnchar nchar(26);' + cmd6 = 'describe lengthsta1 ;' + tdLog.info(cmd5) + tdSql.execute(cmd5) + tdLog.info(cmd6) + tdSql.execute(cmd6) + tdSql.query('describe lengthsta1 ;') + tdSql.checkData(4,2,26) + + tdSql.query('select * from lengthsta1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + tdSql.checkData(0,3,'aaaaabbbbbaaaaa') + tdSql.checkData(0,4,'bbbbbaaaaabbbbbaaaaabbbbb') + + + tdLog.info("=============== step2.8,creat tag right data and insert data") + cmd1 = 'create table length2 using lengthsta1 tags(\'aaaaabbbbbaaaaa1\',\'bbbbbaaaaabbbbbaaaaabbbbb1\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('describe length2 ;') + tdSql.checkData(3,2,16) + tdSql.checkData(4,2,26) + + cmd2 = 'insert into length2 values(now,\'aaaaaaaaaa1\',\'bbbbbbbbbbbbbbbbbbbb1\') ;' + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdSql.query('select * from length2 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + tdSql.query('select * from lengthsta1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + tdSql.checkData(0,3,'aaaaabbbbbaaaaa1') + tdSql.checkData(0,4,'bbbbbaaaaabbbbbaaaaabbbbb1') + + + tdLog.info("=============== step2.9,modify tag columu length again ") + cmd1 = 'alter table lengthsta1 modify tag tlengthbia binary(16) ;' + tdLog.info(cmd1) + tdSql.error(cmd1) + try: + tdSql.execute(cmd1) + tdLog.exit("new column length should be bigger than old one") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("new column length should be bigger than old one") + + cmd2 = 'alter table lengthsta1 modify tag tlengthnchar nchar(26);' + tdLog.info(cmd2) + tdSql.error(cmd2) + try: + tdSql.execute(cmd2) + tdLog.exit("new column length should be bigger than old one") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("new column length should be bigger than old one") + + cmd3 = 'alter table lengthsta1 modify tag tlengthbia binary(20) ;' + cmd4 = 'describe lengthsta1 ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdLog.info(cmd4) + tdSql.execute(cmd4) + tdSql.query('describe lengthsta1 ;') + tdSql.checkData(3,2,20) + + cmd5 = 'alter table lengthsta1 modify tag tlengthnchar nchar(30);' + cmd6 = 'describe lengthsta1 ;' + tdLog.info(cmd5) + tdSql.execute(cmd5) + tdLog.info(cmd6) + tdSql.execute(cmd6) + tdSql.query('describe lengthsta1 ;') + tdSql.checkData(4,2,30) + + tdSql.query('select * from lengthsta1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + tdSql.checkData(0,3,'aaaaabbbbbaaaaa1') + tdSql.checkData(0,4,'bbbbbaaaaabbbbbaaaaabbbbb1') + + + tdLog.info("=============== step2.10,creat tag right data and insert data again") + cmd1 = 'create table length3 using lengthsta1 tags(\'aaaaabbbbbaaaaabbbbb\',\'bbbbbaaaaabbbbbaaaaabbbbbaaaaa\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('describe length3 ;') + tdSql.checkData(3,2,20) + tdSql.checkData(4,2,30) + + cmd2 = 'insert into length3 values(now,\'aaaaaaaaaa1\',\'bbbbbbbbbbbbbbbbbbbb1\') ;' + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdSql.query('select * from length3 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + tdSql.query('select * from lengthsta1 order by ts desc') + tdSql.checkData(0,1,'aaaaaaaaaa1') + tdSql.checkData(0,2,'bbbbbbbbbbbbbbbbbbbb1') + tdSql.checkData(0,3,'aaaaabbbbbaaaaabbbbb') + tdSql.checkData(0,4,'bbbbbaaaaabbbbbaaaaabbbbbaaaaa') + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From e3bdca23b34b8e6740f0120114099bf6e3e456b4 Mon Sep 17 00:00:00 2001 From: happyguoxy Date: Thu, 17 Jun 2021 15:03:46 +0800 Subject: [PATCH 39/52] [TD4568] --- tests/pytest/insert/in_function.py | 726 +++++++++++++++++++++++++++++ 1 file changed, 726 insertions(+) create mode 100644 tests/pytest/insert/in_function.py diff --git a/tests/pytest/insert/in_function.py b/tests/pytest/insert/in_function.py new file mode 100644 index 0000000000..d1fbfd702a --- /dev/null +++ b/tests/pytest/insert/in_function.py @@ -0,0 +1,726 @@ +################################################################### +# 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 datetime + +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + # test case for https://jira.taosdata.com:18080/browse/TD-4568 + + tdLog.info("=============== step1,check bool and tinyint data type") + + tdLog.info("=============== step1.1,drop table && create table") + cmd1 = 'drop table if exists in_bool_tinyint_1 ;' + cmd2 = 'drop table if exists in_bool_tinyint_2 ;' + cmd3 = 'drop table if exists in_bool_tinyint_3 ;' + cmd10 = 'drop table if exists in_stable_1 ;' + cmd11 = 'create stable in_stable_1(ts timestamp,in_bool bool,in_tinyint tinyint) tags (tin_bool bool,tin_tinyint tinyint) ;' + cmd12 = 'create table in_bool_tinyint_1 using in_stable_1 tags(\'true\',\'127\') ; ' + cmd13 = 'create table in_bool_tinyint_2 using in_stable_1 tags(\'false\',\'-127\') ; ' + cmd14 = 'create table in_bool_tinyint_3 using in_stable_1 tags(\'false\',\'0\') ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdLog.info(cmd10) + tdSql.execute(cmd10) + tdLog.info(cmd11) + tdSql.execute(cmd11) + tdLog.info(cmd12) + tdSql.execute(cmd12) + tdLog.info(cmd13) + tdSql.execute(cmd13) + tdLog.info(cmd14) + tdSql.execute(cmd14) + + tdLog.info("=============== step1.2,insert stable right data and check in function") + cmd1 = 'insert into in_bool_tinyint_1 values(now,\'true\',\'-127\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from in_stable_1 where in_bool in (true) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'-127') + tdSql.checkData(0,3,'True') + tdSql.checkData(0,4,'127') + tdSql.query('select * from in_stable_1 where in_tinyint in (-127) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'-127') + tdSql.checkData(0,3,'True') + tdSql.checkData(0,4,'127') + tdSql.query('select * from in_stable_1 where tin_bool in (true) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'-127') + tdSql.checkData(0,3,'True') + tdSql.checkData(0,4,'127') + tdSql.query('select * from in_stable_1 where tin_tinyint in (127) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'-127') + tdSql.checkData(0,3,'True') + tdSql.checkData(0,4,'127') + tdSql.query('select * from in_bool_tinyint_1 where in_bool in (true) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'-127') + tdSql.query('select * from in_bool_tinyint_1 where in_tinyint in (-127) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'-127') + + cmd2 = 'insert into in_bool_tinyint_2 values(now,\'false\',\'127\') ;' + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdSql.query('select * from in_stable_1 where in_bool in (false) order by ts desc') + tdSql.checkData(0,1,'False') + tdSql.checkData(0,2,'127') + tdSql.checkData(0,3,'False') + tdSql.checkData(0,4,'-127') + tdSql.query('select * from in_stable_1 where in_tinyint in (127) order by ts desc') + tdSql.checkData(0,1,'False') + tdSql.checkData(0,2,'127') + tdSql.checkData(0,3,'False') + tdSql.checkData(0,4,'-127') + tdSql.query('select * from in_stable_1 where tin_bool in (false) order by ts desc') + tdSql.checkData(0,1,'False') + tdSql.checkData(0,2,'127') + tdSql.checkData(0,3,'False') + tdSql.checkData(0,4,'-127') + tdSql.query('select * from in_stable_1 where tin_tinyint in (-127) order by ts desc') + tdSql.checkData(0,1,'False') + tdSql.checkData(0,2,'127') + tdSql.checkData(0,3,'False') + tdSql.checkData(0,4,'-127') + tdSql.query('select * from in_bool_tinyint_2 where in_bool in (false) order by ts desc') + tdSql.checkData(0,1,'False') + tdSql.checkData(0,2,'127') + tdSql.query('select * from in_bool_tinyint_2 where in_tinyint in (127) order by ts desc') + tdSql.checkData(0,1,'False') + tdSql.checkData(0,2,'127') + + cmd3 = 'insert into in_bool_tinyint_3 values(now,\'true\',\'0\') ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdSql.query('select * from in_stable_1 where in_tinyint in (0) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'False') + tdSql.checkData(0,4,'0') + tdSql.query('select * from in_stable_1 where tin_tinyint in (0) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'False') + tdSql.checkData(0,4,'0') + tdSql.query('select * from in_bool_tinyint_3 where in_bool in (true) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'0') + tdSql.query('select * from in_bool_tinyint_3 where in_tinyint in (0) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'0') + + + tdLog.info("=============== step1.3,drop normal table && create table") + cmd1 = 'drop table if exists normal_in_bool_tinyint_1 ;' + cmd2 = 'create table normal_in_bool_tinyint_1 (ts timestamp,in_bool bool,in_tinyint tinyint) ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + + + tdLog.info("=============== step1.4,insert normal table right data and check in function") + cmd1 = 'insert into normal_in_bool_tinyint_1 values(now,\'true\',\'-127\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from normal_in_bool_tinyint_1 where in_bool in (true) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'-127') + tdSql.query('select * from normal_in_bool_tinyint_1 where in_tinyint in (-127) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'-127') + + cmd2 = 'insert into normal_in_bool_tinyint_1 values(now,\'false\',\'127\') ;' + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdSql.query('select * from normal_in_bool_tinyint_1 where in_bool in (false) order by ts desc') + tdSql.checkData(0,1,'False') + tdSql.checkData(0,2,'127') + tdSql.query('select * from normal_in_bool_tinyint_1 where in_tinyint in (127) order by ts desc') + tdSql.checkData(0,1,'False') + tdSql.checkData(0,2,'127') + + cmd3 = 'insert into normal_in_bool_tinyint_1 values(now,\'true\',\'0\') ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdSql.query('select * from normal_in_bool_tinyint_1 where in_tinyint in (0) order by ts desc') + tdSql.checkData(0,1,'True') + tdSql.checkData(0,2,'0') + + + + tdLog.info("=============== step2,check int、smallint and bigint data type") + + tdLog.info("=============== step2.1,drop table && create table") + cmd1 = 'drop table if exists in_int_smallint_bigint_1 ;' + cmd2 = 'drop table if exists in_int_smallint_bigint_2 ;' + cmd3 = 'drop table if exists in_int_smallint_bigint_3 ;' + cmd10 = 'drop table if exists in_stable_2 ;' + cmd11 = 'create stable in_stable_2(ts timestamp,in_int int,in_small smallint , in_big bigint) tags (tin_int int,tin_small smallint , tin_big bigint) ;' + cmd12 = 'create table in_int_smallint_bigint_1 using in_stable_2 tags(\'2147483647\',\'-32767\',\'0\') ; ' + cmd13 = 'create table in_int_smallint_bigint_2 using in_stable_2 tags(\'-2147483647\',\'0\',\'9223372036854775807\') ; ' + cmd14 = 'create table in_int_smallint_bigint_3 using in_stable_2 tags(\'0\',\'32767\',\'-9223372036854775807\') ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdLog.info(cmd10) + tdSql.execute(cmd10) + tdLog.info(cmd11) + tdSql.execute(cmd11) + tdLog.info(cmd12) + tdSql.execute(cmd12) + tdLog.info(cmd13) + tdSql.execute(cmd13) + tdLog.info(cmd14) + tdSql.execute(cmd14) + + tdLog.info("=============== step2.2,insert stable right data and check in function") + cmd1 = 'insert into in_int_smallint_bigint_1 values(now,\'2147483647\',\'-32767\',\'0\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from in_stable_2 where in_int in (2147483647) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'2147483647') + tdSql.checkData(0,5,'-32767') + tdSql.checkData(0,6,'0') + tdSql.query('select * from in_stable_2 where in_small in (-32767) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'2147483647') + tdSql.checkData(0,5,'-32767') + tdSql.checkData(0,6,'0') + tdSql.query('select * from in_stable_2 where in_big in (0) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'2147483647') + tdSql.checkData(0,5,'-32767') + tdSql.checkData(0,6,'0') + tdSql.query('select * from in_stable_2 where tin_int in (2147483647) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'2147483647') + tdSql.checkData(0,5,'-32767') + tdSql.checkData(0,6,'0') + tdSql.query('select * from in_stable_2 where tin_small in (-32767) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'2147483647') + tdSql.checkData(0,5,'-32767') + tdSql.checkData(0,6,'0') + tdSql.query('select * from in_stable_2 where tin_big in (0) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'2147483647') + tdSql.checkData(0,5,'-32767') + tdSql.checkData(0,6,'0') + tdSql.query('select * from in_int_smallint_bigint_1 where in_int in (2147483647) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.query('select * from in_int_smallint_bigint_1 where in_small in (-32767) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.query('select * from in_int_smallint_bigint_1 where in_big in (0) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + + cmd2 = 'insert into in_int_smallint_bigint_2 values(now,\'-2147483647\',\'0\',\'9223372036854775807\') ;' + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdSql.query('select * from in_stable_2 where in_int in (-2147483647) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.checkData(0,4,'-2147483647') + tdSql.checkData(0,5,'0') + tdSql.checkData(0,6,'9223372036854775807') + tdSql.query('select * from in_stable_2 where in_small in (0) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.checkData(0,4,'-2147483647') + tdSql.checkData(0,5,'0') + tdSql.checkData(0,6,'9223372036854775807') + tdSql.query('select * from in_stable_2 where in_big in (9223372036854775807) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.checkData(0,4,'-2147483647') + tdSql.checkData(0,5,'0') + tdSql.checkData(0,6,'9223372036854775807') + tdSql.query('select * from in_stable_2 where tin_int in (-2147483647) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.checkData(0,4,'-2147483647') + tdSql.checkData(0,5,'0') + tdSql.checkData(0,6,'9223372036854775807') + tdSql.query('select * from in_stable_2 where tin_small in (0) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.checkData(0,4,'-2147483647') + tdSql.checkData(0,5,'0') + tdSql.checkData(0,6,'9223372036854775807') + tdSql.query('select * from in_stable_2 where tin_big in (9223372036854775807) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.checkData(0,4,'-2147483647') + tdSql.checkData(0,5,'0') + tdSql.checkData(0,6,'9223372036854775807') + tdSql.query('select * from in_int_smallint_bigint_2 where in_int in (-2147483647) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.query('select * from in_int_smallint_bigint_2 where in_small in (0) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.query('select * from in_int_smallint_bigint_2 where in_big in (9223372036854775807) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + + cmd3 = 'insert into in_int_smallint_bigint_3 values(now,\'0\',\'32767\',\'-9223372036854775807\') ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdSql.query('select * from in_stable_2 where in_int in (0) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.checkData(0,4,'0') + tdSql.checkData(0,5,'32767') + tdSql.checkData(0,6,'-9223372036854775807') + tdSql.query('select * from in_stable_2 where in_small in (32767) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.checkData(0,4,'0') + tdSql.checkData(0,5,'32767') + tdSql.checkData(0,6,'-9223372036854775807') + tdSql.query('select * from in_stable_2 where in_big in (-9223372036854775807) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.checkData(0,4,'0') + tdSql.checkData(0,5,'32767') + tdSql.checkData(0,6,'-9223372036854775807') + tdSql.query('select * from in_stable_2 where tin_int in (0) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.checkData(0,4,'0') + tdSql.checkData(0,5,'32767') + tdSql.checkData(0,6,'-9223372036854775807') + tdSql.query('select * from in_stable_2 where tin_small in (32767) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.checkData(0,4,'0') + tdSql.checkData(0,5,'32767') + tdSql.checkData(0,6,'-9223372036854775807') + tdSql.query('select * from in_stable_2 where tin_big in (-9223372036854775807) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.checkData(0,4,'0') + tdSql.checkData(0,5,'32767') + tdSql.checkData(0,6,'-9223372036854775807') + tdSql.query('select * from in_int_smallint_bigint_3 where in_int in (0) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.query('select * from in_int_smallint_bigint_3 where in_small in (32767) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.query('select * from in_int_smallint_bigint_3 where in_big in (-9223372036854775807) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + + + tdLog.info("=============== step2.3,drop normal table && create table") + cmd1 = 'drop table if exists normal_int_smallint_bigint_1 ;' + cmd2 = 'create table normal_int_smallint_bigint_1 (ts timestamp,in_int int,in_small smallint , in_big bigint) ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + + + tdLog.info("=============== step2.4,insert normal table right data and check in function") + cmd1 = 'insert into normal_int_smallint_bigint_1 values(now,\'2147483647\',\'-32767\',\'0\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from normal_int_smallint_bigint_1 where in_int in (2147483647) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.query('select * from normal_int_smallint_bigint_1 where in_small in (-32767) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + tdSql.query('select * from normal_int_smallint_bigint_1 where in_big in (0) order by ts desc') + tdSql.checkData(0,1,'2147483647') + tdSql.checkData(0,2,'-32767') + tdSql.checkData(0,3,'0') + + cmd2 = 'insert into normal_int_smallint_bigint_1 values(now,\'-2147483647\',\'0\',\'9223372036854775807\') ;' + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdSql.query('select * from normal_int_smallint_bigint_1 where in_int in (-2147483647) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.query('select * from normal_int_smallint_bigint_1 where in_small in (0) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + tdSql.query('select * from normal_int_smallint_bigint_1 where in_big in (9223372036854775807) order by ts desc') + tdSql.checkData(0,1,'-2147483647') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'9223372036854775807') + + cmd3 = 'insert into normal_int_smallint_bigint_1 values(now,\'0\',\'32767\',\'-9223372036854775807\') ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdSql.query('select * from normal_int_smallint_bigint_1 where in_int in (0) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.query('select * from normal_int_smallint_bigint_1 where in_small in (32767) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + tdSql.query('select * from normal_int_smallint_bigint_1 where in_big in (-9223372036854775807) order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'32767') + tdSql.checkData(0,3,'-9223372036854775807') + + + tdLog.info("=============== step3,check binary and nchar data type") + + tdLog.info("=============== step3.1,drop table && create table") + cmd1 = 'drop table if exists in_binary_nchar_1 ;' + cmd2 = 'drop table if exists in_binary_nchar_2 ;' + cmd3 = 'drop table if exists in_binary_nchar_3 ;' + cmd10 = 'drop table if exists in_stable_3 ;' + cmd11 = 'create stable in_stable_3(ts timestamp,in_binary binary(8),in_nchar nchar(12)) tags (tin_binary binary(16),tin_nchar nchar(20)) ;' + cmd12 = 'create table in_binary_nchar_1 using in_stable_3 tags(\'0\',\'0\') ; ' + cmd13 = 'create table in_binary_nchar_2 using in_stable_3 tags(\'TDengine\',\'北京涛思数据科技有限公司\') ; ' + cmd14 = 'create table in_binary_nchar_3 using in_stable_3 tags(\'taosdataTDengine\',\'北京涛思数据科技有限公司TDengine\') ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdLog.info(cmd10) + tdSql.execute(cmd10) + tdLog.info(cmd11) + tdSql.execute(cmd11) + tdLog.info(cmd12) + tdSql.execute(cmd12) + tdLog.info(cmd13) + tdSql.execute(cmd13) + tdLog.info(cmd14) + tdSql.execute(cmd14) + + tdLog.info("=============== step3.2,insert stable right data and check in function") + cmd1 = 'insert into in_binary_nchar_1 values(now,\'0\',\'0\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from in_stable_3 where in_binary in (\'0\') order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'0') + tdSql.query('select * from in_stable_3 where in_nchar in (\'0\') order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'0') + tdSql.query('select * from in_stable_3 where tin_binary in (\'0\') order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'0') + tdSql.query('select * from in_stable_3 where tin_nchar in (\'0\') order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'0') + tdSql.checkData(0,3,'0') + tdSql.checkData(0,4,'0') + tdSql.query('select * from in_binary_nchar_1 where in_binary in (\'0\') order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'0') + tdSql.query('select * from in_binary_nchar_1 where in_nchar in (\'0\') order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'0') + + cmd2 = 'insert into in_binary_nchar_2 values(now,\'TAOS\',\'涛思数据TAOSdata\') ;' + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdSql.query('select * from in_stable_3 where in_binary in (\'TAOS\') order by ts desc') + tdSql.checkData(0,1,'TAOS') + tdSql.checkData(0,2,'涛思数据TAOSdata') + tdSql.checkData(0,3,'TDengine') + tdSql.checkData(0,4,'北京涛思数据科技有限公司') + tdSql.query('select * from in_stable_3 where in_nchar in (\'涛思数据TAOSdata\') order by ts desc') + tdSql.checkData(0,1,'TAOS') + tdSql.checkData(0,2,'涛思数据TAOSdata') + tdSql.checkData(0,3,'TDengine') + tdSql.checkData(0,4,'北京涛思数据科技有限公司') + tdSql.query('select * from in_stable_3 where tin_binary in (\'TDengine\') order by ts desc') + tdSql.checkData(0,1,'TAOS') + tdSql.checkData(0,2,'涛思数据TAOSdata') + tdSql.checkData(0,3,'TDengine') + tdSql.checkData(0,4,'北京涛思数据科技有限公司') + tdSql.query('select * from in_stable_3 where tin_nchar in (\'北京涛思数据科技有限公司\') order by ts desc') + tdSql.checkData(0,1,'TAOS') + tdSql.checkData(0,2,'涛思数据TAOSdata') + tdSql.checkData(0,3,'TDengine') + tdSql.checkData(0,4,'北京涛思数据科技有限公司') + tdSql.query('select * from in_binary_nchar_2 where in_binary in (\'TAOS\') order by ts desc') + tdSql.checkData(0,1,'TAOS') + tdSql.checkData(0,2,'涛思数据TAOSdata') + tdSql.query('select * from in_binary_nchar_2 where in_nchar in (\'涛思数据TAOSdata\') order by ts desc') + tdSql.checkData(0,1,'TAOS') + tdSql.checkData(0,2,'涛思数据TAOSdata') + + cmd3 = 'insert into in_binary_nchar_3 values(now,\'TDengine\',\'北京涛思数据科技有限公司\') ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdSql.query('select * from in_stable_3 where in_binary in (\'TDengine\') order by ts desc') + tdSql.checkData(0,1,'TDengine') + tdSql.checkData(0,2,'北京涛思数据科技有限公司') + tdSql.checkData(0,3,'taosdataTDengine') + tdSql.checkData(0,4,'北京涛思数据科技有限公司TDengine') + tdSql.query('select * from in_stable_3 where in_nchar in (\'北京涛思数据科技有限公司\') order by ts desc') + tdSql.checkData(0,1,'TDengine') + tdSql.checkData(0,2,'北京涛思数据科技有限公司') + tdSql.checkData(0,3,'taosdataTDengine') + tdSql.checkData(0,4,'北京涛思数据科技有限公司TDengine') + tdSql.query('select * from in_stable_3 where tin_binary in (\'taosdataTDengine\') order by ts desc') + tdSql.checkData(0,1,'TDengine') + tdSql.checkData(0,2,'北京涛思数据科技有限公司') + tdSql.checkData(0,3,'taosdataTDengine') + tdSql.checkData(0,4,'北京涛思数据科技有限公司TDengine') + tdSql.query('select * from in_stable_3 where tin_nchar in (\'北京涛思数据科技有限公司TDengine\') order by ts desc') + tdSql.checkData(0,1,'TDengine') + tdSql.checkData(0,2,'北京涛思数据科技有限公司') + tdSql.checkData(0,3,'taosdataTDengine') + tdSql.checkData(0,4,'北京涛思数据科技有限公司TDengine') + tdSql.query('select * from in_binary_nchar_3 where in_binary in (\'TDengine\') order by ts desc') + tdSql.checkData(0,1,'TDengine') + tdSql.checkData(0,2,'北京涛思数据科技有限公司') + tdSql.query('select * from in_binary_nchar_3 where in_nchar in (\'北京涛思数据科技有限公司\') order by ts desc') + tdSql.checkData(0,1,'TDengine') + tdSql.checkData(0,2,'北京涛思数据科技有限公司') + + + tdLog.info("=============== step3.3,drop normal table && create table") + cmd1 = 'drop table if exists normal_in_binary_nchar_1 ;' + cmd2 = 'create table normal_in_binary_nchar_1 (ts timestamp,in_binary binary(8),in_nchar nchar(12)) ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + + + tdLog.info("=============== step3.4,insert normal table right data and check in function") + cmd1 = 'insert into normal_in_binary_nchar_1 values(now,\'0\',\'0\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdSql.query('select * from normal_in_binary_nchar_1 where in_binary in (\'0\') order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'0') + tdSql.query('select * from normal_in_binary_nchar_1 where in_nchar in (\'0\') order by ts desc') + tdSql.checkData(0,1,'0') + tdSql.checkData(0,2,'0') + + cmd2 = 'insert into normal_in_binary_nchar_1 values(now,\'TAOS\',\'涛思数据TAOSdata\') ;' + tdLog.info(cmd2) + tdSql.execute(cmd2) + tdSql.query('select * from normal_in_binary_nchar_1 where in_binary in (\'TAOS\') order by ts desc') + tdSql.checkData(0,1,'TAOS') + tdSql.checkData(0,2,'涛思数据TAOSdata') + tdSql.query('select * from normal_in_binary_nchar_1 where in_nchar in (\'涛思数据TAOSdata\') order by ts desc') + tdSql.checkData(0,1,'TAOS') + tdSql.checkData(0,2,'涛思数据TAOSdata') + + cmd3 = 'insert into normal_in_binary_nchar_1 values(now,\'TDengine\',\'北京涛思数据科技有限公司\') ;' + tdLog.info(cmd3) + tdSql.execute(cmd3) + tdSql.query('select * from normal_in_binary_nchar_1 where in_binary in (\'TDengine\') order by ts desc') + tdSql.checkData(0,1,'TDengine') + tdSql.checkData(0,2,'北京涛思数据科技有限公司') + tdSql.query('select * from normal_in_binary_nchar_1 where in_nchar in (\'北京涛思数据科技有限公司\') order by ts desc') + tdSql.checkData(0,1,'TDengine') + tdSql.checkData(0,2,'北京涛思数据科技有限公司') + + tdLog.info("=============== step4,check float and double data type,not support") + + tdLog.info("=============== step4.1,drop table && create table") + cmd1 = 'drop table if exists in_float_double_1 ;' + cmd10 = 'drop table if exists in_stable_4 ;' + cmd11 = 'create stable in_stable_4(ts timestamp,in_float float,in_double double) tags (tin_float float,tin_double double) ;' + cmd12 = 'create table in_float_double_1 using in_stable_4 tags(\'666\',\'88888\') ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd10) + tdSql.execute(cmd10) + tdLog.info(cmd11) + tdSql.execute(cmd11) + tdLog.info(cmd12) + tdSql.execute(cmd12) + + tdLog.info("=============== step4.2,insert stable right data and check in function") + cmd1 = 'insert into in_float_double_1 values(now,\'888\',\'66666\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + + cmd2 = 'select * from in_stable_4 where in_float in (\'888\');' + tdLog.info(cmd2) + tdSql.error(cmd2) + try: + tdSql.execute(cmd2) + tdLog.exit("invalid operation: not supported filter condition") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: not supported filter condition") + + cmd3 = 'select * from in_stable_4 where in_double in (\'66666\');' + tdLog.info(cmd3) + tdSql.error(cmd3) + try: + tdSql.execute(cmd3) + tdLog.exit("invalid operation: not supported filter condition") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: not supported filter condition") + + cmd4 = 'select * from in_stable_4 where tin_float in (\'666\');' + tdLog.info(cmd4) + tdSql.error(cmd4) + try: + tdSql.execute(cmd4) + tdLog.exit("invalid operation: not supported filter condition") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: not supported filter condition") + + cmd5 = 'select * from in_stable_4 where tin_double in (\'88888\');' + tdLog.info(cmd5) + tdSql.error(cmd5) + try: + tdSql.execute(cmd5) + tdLog.exit("invalid operation: not supported filter condition") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: not supported filter condition") + + cmd6 = 'select * from in_float_double_1 where in_float in (\'888\');' + tdLog.info(cmd6) + tdSql.error(cmd6) + try: + tdSql.execute(cmd6) + tdLog.exit("invalid operation: not supported filter condition") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: not supported filter condition") + + cmd7 = 'select * from in_float_double_1 where in_double in (\'66666\');' + tdLog.info(cmd7) + tdSql.error(cmd7) + try: + tdSql.execute(cmd7) + tdLog.exit("invalid operation: not supported filter condition") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: not supported filter condition") + + + + tdLog.info("=============== step4.3,drop normal table && create table") + cmd1 = 'drop table if exists normal_in_float_double_1 ;' + cmd2 = 'create table normal_in_float_double_1 (ts timestamp,in_float float,in_double double) ; ' + tdLog.info(cmd1) + tdSql.execute(cmd1) + tdLog.info(cmd2) + tdSql.execute(cmd2) + + + tdLog.info("=============== step4.4,insert normal table right data and check in function") + cmd1 = 'insert into normal_in_float_double_1 values(now,\'888\',\'666666\') ;' + tdLog.info(cmd1) + tdSql.execute(cmd1) + + cmd2 = 'select * from normal_in_float_double_1 where in_float in (\'888\');' + tdLog.info(cmd2) + tdSql.error(cmd2) + try: + tdSql.execute(cmd2) + tdLog.exit("invalid operation: not supported filter condition") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: not supported filter condition") + + cmd3 = 'select * from normal_in_float_double_1 where in_double in (\'66666\');' + tdLog.info(cmd3) + tdSql.error(cmd3) + try: + tdSql.execute(cmd3) + tdLog.exit("invalid operation: not supported filter condition") + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("invalid operation: not supported filter condition") + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From ad46ff86fee34ba602fd53dfe34e2a29f9c02cd9 Mon Sep 17 00:00:00 2001 From: happyguoxy Date: Thu, 17 Jun 2021 15:05:14 +0800 Subject: [PATCH 40/52] [TD4541][TD4568] --- tests/pytest/fulltest.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 146c47c51d..b9b7bbcaf6 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -25,6 +25,8 @@ python3 ./test.py -f insert/special_character_show.py python3 bug2265.py python3 ./test.py -f insert/bug3654.py python3 ./test.py -f insert/insertDynamicColBeforeVal.py +python3 ./test.py -f insert/in_function.py +python3 ./test.py -f insert/modify_column.py #table python3 ./test.py -f table/alter_wal0.py From 402748d9f5823f06751d4cb9363270b9a1ce4cd9 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 14 May 2021 11:45:47 +0800 Subject: [PATCH 41/52] [TD-3776]set time precision after parsing and JNI time precision minor change --- .../jni/com_taosdata_jdbc_TSDBJNIConnector.h | 6 +- src/client/src/TSDBJNIConnector.c | 18 +++-- src/client/src/tscSQLParser.c | 4 ++ .../com/taosdata/jdbc/TSDBJNIConnector.java | 10 +++ .../taosdata/jdbc/TSDBResultSetRowData.java | 42 +++++++---- .../taosdata/jdbc/TSDBJNIConnectorTest.java | 71 +++++++++++++++++-- 6 files changed, 123 insertions(+), 28 deletions(-) diff --git a/src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h b/src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h index d16b672f38..7181c658dd 100644 --- a/src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h +++ b/src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h @@ -51,10 +51,10 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getTsCharset /* * Class: com_taosdata_jdbc_TSDBJNIConnector - * Method: getResultTimePrecision - * Signature: (J)J + * Method: getResultTimePrecisionImp + * Signature: (JJ)I */ -JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TDDBJNIConnector_getResultTimePrecision +JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TDDBJNIConnector_getResultTimePrecisionImp (JNIEnv *, jobject, jlong, jlong); /* diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index 324c436dce..379cf86301 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -113,7 +113,7 @@ static void jniGetGlobalMethod(JNIEnv *env) { g_rowdataSetFloatFp = (*env)->GetMethodID(env, g_rowdataClass, "setFloat", "(IF)V"); g_rowdataSetDoubleFp = (*env)->GetMethodID(env, g_rowdataClass, "setDouble", "(ID)V"); g_rowdataSetStringFp = (*env)->GetMethodID(env, g_rowdataClass, "setString", "(ILjava/lang/String;)V"); - g_rowdataSetTimestampFp = (*env)->GetMethodID(env, g_rowdataClass, "setTimestamp", "(IJ)V"); + g_rowdataSetTimestampFp = (*env)->GetMethodID(env, g_rowdataClass, "setTimestamp", "(IJI)V"); g_rowdataSetByteArrayFp = (*env)->GetMethodID(env, g_rowdataClass, "setByteArray", "(I[B)V"); (*env)->DeleteLocalRef(env, rowdataClass); @@ -519,9 +519,11 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn jniFromNCharToByteArray(env, (char *)row[i], length[i])); break; } - case TSDB_DATA_TYPE_TIMESTAMP: - (*env)->CallVoidMethod(env, rowobj, g_rowdataSetTimestampFp, i, (jlong) * ((int64_t *)row[i])); + case TSDB_DATA_TYPE_TIMESTAMP: { + int precision = taos_result_precision(result); + (*env)->CallVoidMethod(env, rowobj, g_rowdataSetTimestampFp, i, (jlong) * ((int64_t *)row[i]), precision); break; + } default: break; } @@ -672,7 +674,15 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getTsCharset(J return (*env)->NewStringUTF(env, (const char *)tsCharset); } -JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TDDBJNIConnector_getResultTimePrecision(JNIEnv *env, jobject jobj, jlong con, +/** + * Get Result Time Precision + * @param env vm + * @param jobj the TSDBJNIConnector java object + * @param con the c connection pointer + * @param res the TAOS_RES object, i.e. the SSqlObject + * @return precision 0:ms 1:us 2:ns + */ +JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultTimePrecisionImp(JNIEnv *env, jobject jobj, jlong con, jlong res) { TAOS *tscon = (TAOS *)con; if (tscon == NULL) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 82a3a1f55b..d0bd767a46 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -772,6 +772,10 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { pCmd->active = pCmd->pQueryInfo; pCmd->command = pCmd->pQueryInfo->command; + if (pTableMetaInfo->pTableMeta != NULL) { + pSql->res.precision = tscGetTableInfo(pTableMetaInfo->pTableMeta).precision; + } + return TSDB_CODE_SUCCESS; // do not build query message here } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index 92792d9751..bc4d58785a 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -216,6 +216,16 @@ public class TSDBJNIConnector { private native int fetchBlockImp(long connection, long resultSet, TSDBResultSetBlockData blockData); + /** + * Get Result Time Precision. + * @return 0: ms, 1: us, 2: ns + */ + public int getResultTimePrecision(long sqlObj) { + return this.getResultTimePrecisionImp(this.taos, sqlObj); + } + + private native int getResultTimePrecisionImp(long connection, long result); + /** * Execute close operation from C to release connection pointer by JNI * diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java index 01104440ab..b0b3ae4180 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java @@ -414,26 +414,40 @@ public class TSDBResultSetRowData { * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api */ public void setTimestampValue(int colIndex, long value) { - setTimestamp(colIndex - 1, value); + setTimestamp(colIndex - 1, value, 0); } /** * !!! this method is invoked by JNI method and the index start from 0 in C implementations + * @param precision 0 : ms, 1 : us, 2 : ns */ - public void setTimestamp(int col, long ts) { - //TODO: this implementation contains logical error - // when precision is us the (long ts) is 16 digital number - // when precision is ms, the (long ts) is 13 digital number - // we need a JNI function like this: - // public void setTimestamp(int col, long epochSecond, long nanoAdjustment) - if (ts < 1_0000_0000_0000_0L) { - data.set(col, new Timestamp(ts)); - } else { - long epochSec = ts / 1000_000l; - long nanoAdjustment = ts % 1000_000l * 1000l; - Timestamp timestamp = Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); - data.set(col, timestamp); + public void setTimestamp(int col, long ts, int precision) { + long milliseconds = 0; + int fracNanoseconds = 0; + switch (precision) { + case 0: { + milliseconds = ts; + fracNanoseconds = (int)(ts*1_000_000%1_000_000_000); + break; + } + case 1: { + milliseconds = ts/1_000; + fracNanoseconds = (int)(ts*1_000%1_000_000_000); + break; + } + case 2: { + milliseconds = ts/1_000_000; + fracNanoseconds = (int)(ts%1_000_000_000); + break; + } + default: { + throw new IllegalArgumentException("precision is not valid. precision: " + precision); + } } + + Timestamp tsObj = new Timestamp(milliseconds); + tsObj.setNanos(fracNanoseconds); + data.set(col, tsObj); } public Timestamp getTimestamp(int col, int nativeType) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java index 66078ef503..b5f8114bff 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java @@ -1,12 +1,17 @@ package com.taosdata.jdbc; import org.junit.Test; +import static org.junit.Assert.*; import java.sql.SQLException; import java.sql.SQLWarning; import java.util.ArrayList; import java.util.List; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.lang.management.ThreadMXBean; + public class TSDBJNIConnectorTest { private static TSDBResultSetRowData rowData; @@ -14,17 +19,68 @@ public class TSDBJNIConnectorTest { @Test public void test() { try { + + try { + //change sleepSeconds when debugging with attach to process to find PID + int sleepSeconds = -1; + if (sleepSeconds>0) { + RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); + String jvmName = runtimeBean.getName(); + long pid = Long.valueOf(jvmName.split("@")[0]); + System.out.println("JVM PID = " + pid); + + Thread.sleep(sleepSeconds*1000); + } + } + catch (Exception e) { + e.printStackTrace(); + } + // init - TSDBJNIConnector.init("/etc/taos/taos.cfg", null, null, null); + TSDBJNIConnector.init("/etc/taos", null, null, null); + // connect TSDBJNIConnector connector = new TSDBJNIConnector(); - connector.connect("127.0.0.1", 6030, "unsign_jni", "root", "taosdata"); + connector.connect("127.0.0.1", 6030, null, "root", "taosdata"); + + // setup + String setupSqlStrs[] = {"create database if not exists d precision \"us\"", + "create table if not exists d.t(ts timestamp, f int)", + "create database if not exists d2", + "create table if not exists d2.t2(ts timestamp, f int)", + "insert into d.t values(now+100s, 100)", + "insert into d2.t2 values(now+200s, 200)" + }; + for (String setupSqlStr : setupSqlStrs) { + long setupSql = connector.executeQuery(setupSqlStr); + + assertEquals(0, connector.getResultTimePrecision(setupSql)); + if (connector.isUpdateQuery(setupSql)) { + connector.freeResultSet(setupSql); + } + } + + { + long sqlObj1 = connector.executeQuery("select * from d2.t2"); + assertEquals(0, connector.getResultTimePrecision(sqlObj1)); + List columnMetaDataList = new ArrayList<>(); + int code = connector.getSchemaMetaData(sqlObj1, columnMetaDataList); + rowData = new TSDBResultSetRowData(columnMetaDataList.size()); + assertTrue(next(connector, sqlObj1)); + assertEquals(0, connector.getResultTimePrecision(sqlObj1)); + connector.freeResultSet(sqlObj1); + } + // executeQuery - long pSql = connector.executeQuery("select * from unsign_jni.us_table"); + long pSql = connector.executeQuery("select * from d.t"); + if (connector.isUpdateQuery(pSql)) { connector.freeResultSet(pSql); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY); } + + assertEquals(1, connector.getResultTimePrecision(pSql)); + // get schema List columnMetaDataList = new ArrayList<>(); int code = connector.getSchemaMetaData(pSql, columnMetaDataList); @@ -37,6 +93,8 @@ public class TSDBJNIConnectorTest { if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0); } + + assertEquals(1, connector.getResultTimePrecision(pSql)); int columnSize = columnMetaDataList.size(); // print metadata for (int i = 0; i < columnSize; i++) { @@ -45,9 +103,8 @@ public class TSDBJNIConnectorTest { rowData = new TSDBResultSetRowData(columnSize); // iterate resultSet for (int i = 0; next(connector, pSql); i++) { -// System.out.println("col[" + i + "] size: " + rowData.getColSize()); -// rowData.getData().stream().forEach(col -> System.out.print(col + "\t")); -// System.out.println(); + assertEquals(1, connector.getResultTimePrecision(pSql)); + System.out.println(); } // close resultSet code = connector.freeResultSet(pSql); @@ -86,4 +143,4 @@ public class TSDBJNIConnectorTest { } } -} \ No newline at end of file +} From 700571c95cffb88db97192d1227d70a2bb210e4e Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Thu, 17 Jun 2021 16:28:32 +0800 Subject: [PATCH 42/52] [TD-4747]grafana query multi NULL col --- tests/script/general/http/grafana_bug.sim | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/script/general/http/grafana_bug.sim b/tests/script/general/http/grafana_bug.sim index e66cd29dea..0816e88f3f 100644 --- a/tests/script/general/http/grafana_bug.sim +++ b/tests/script/general/http/grafana_bug.sim @@ -20,17 +20,22 @@ sql use db sql create table tb (ts timestamp, val int, val1 int, val2 int) sql create table tb2 (ts timestamp, val int, val1 int, val2 int) sql create table t2 (ts timestamp, val int) +sql create table tb3 (ts timestamp, val int, val1 int, val2 int) sql insert into tb values('2020-01-01 00:00:00.000', 1, 11, 21) sql insert into tb values('2020-01-02 00:00:00.000', 1, 12, 22) sql insert into tb values('2020-01-03 00:00:00.000', 2, 13, 23) sql insert into tb values('2020-01-04 00:00:00.000', 2, 14, 24) + sql insert into tb2 values('2020-01-01 00:00:00.000', 21, 211, 221) sql insert into tb2 values('2020-01-02 00:00:00.000', 21, 212, 222) sql insert into tb2 values('2020-01-03 00:00:00.000', 22, 213, 223) sql insert into tb2 values('2020-01-04 00:00:00.000', 22, 214, 224) + +sql insert into tb3 values('2020-01-01 00:00:00.000', NULL, NULL, NULL) +sql insert into tb3 values('2020-01-02 00:00:00.000', NULL, NULL, NULL) print =============== step1 - one query, 1 column, with timestamp system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select ts from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query @@ -235,4 +240,11 @@ if $system_content != @[{"refId":"B","target":"BB{val2:223,}","datapoints":[[213 return -1 endi +print =============== step26 - 2 column, no timestamp, NULL +system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select * from db.tb3 "} ]' 127.0.0.1:7111/grafana/query +print step1-> $system_content +if $system_content != @[{"refId":"A","target":"{val1:nil, val2:nil}","datapoints":[[null,1577808000000],[null,1577894400000]]}]@ then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 958d2454dffdbc6a1b94f3ef144d80acf4fcdf0b Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Thu, 17 Jun 2021 17:29:25 +0800 Subject: [PATCH 43/52] [TD-4733]: add test case for derivative function --- tests/pytest/functions/function_derivative.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/pytest/functions/function_derivative.py b/tests/pytest/functions/function_derivative.py index 4ddb9c309b..9d60129672 100644 --- a/tests/pytest/functions/function_derivative.py +++ b/tests/pytest/functions/function_derivative.py @@ -128,7 +128,14 @@ class TDTestCase: def run(self): tdSql.prepare() - self.insertAndCheckData() + self.insertAndCheckData() + + tdSql.execute("create table st(ts timestamp, c1 int, c2 int) tags(id int)") + tdSql.execute("insert into dev1(ts, c1) using st tags(1) values(now, 1)") + + tdSql.error("select derivative(c1, 10s, 0) from (select c1 from st)") + tdSql.query("select diff(c1) from (select derivative(c1, 1s, 0) c1 from dev1)") + tdSql.checkRows(0) def stop(self): tdSql.close() From ed59bedfb55c10a9b7babae70bd06338c95e16e4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 17 Jun 2021 18:53:44 +0800 Subject: [PATCH 44/52] [td-225]fix bug in sim. --- tests/script/general/parser/function.sim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 827f21f0bf..4d62c9fc18 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -1074,7 +1074,7 @@ sql insert into t0 values('2020-1-1 1:4:10', 10); sql insert into t1 values('2020-1-1 1:1:2', 2); print ===========================>td-4739 -sql select diff(val) from (select derivative(k, 1s, 0) from t1); +sql select diff(val) from (select derivative(k, 1s, 0) val from t1); if $rows != 0 then return -1 endi From 2be7275d99c2e2439366ee86ff9c85cec78abd4c Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Thu, 17 Jun 2021 23:03:53 +0800 Subject: [PATCH 45/52] [TD-4752]: python connector support nanosecond. (#6528) --- src/connector/python/setup.py | 2 +- src/connector/python/taos/cinterface.py | 54 ++++++++++++++----------- src/connector/python/taos/constants.py | 2 + 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/connector/python/setup.py b/src/connector/python/setup.py index 901e8396c0..284861ca87 100644 --- a/src/connector/python/setup.py +++ b/src/connector/python/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="taos", - version="2.0.10", + version="2.0.11", author="Taosdata Inc.", author_email="support@taosdata.com", description="TDengine python client package", diff --git a/src/connector/python/taos/cinterface.py b/src/connector/python/taos/cinterface.py index 0f690aeb27..61a2a0e9c7 100644 --- a/src/connector/python/taos/cinterface.py +++ b/src/connector/python/taos/cinterface.py @@ -14,12 +14,22 @@ def _convert_microsecond_to_datetime(micro): return datetime.datetime.fromtimestamp(micro / 1000000.0) -def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False): +def _convert_nanosecond_to_datetime(nanosec): + return datetime.datetime.fromtimestamp(nanosec / 1000000000.0) + + +def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C bool row to python row """ _timestamp_converter = _convert_millisecond_to_datetime - if micro: + if precision == FieldType.C_TIMESTAMP_MILLI: + _timestamp_converter = _convert_millisecond_to_datetime + elif precision == FieldType.C_TIMESTAMP_MICRO: _timestamp_converter = _convert_microsecond_to_datetime + elif precision == FieldType.C_TIMESTAMP_NANO: + _timestamp_converter = _convert_nanosecond_to_datetime + else: + raise DatabaseError("Unknown precision returned from database") return [ None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( @@ -28,7 +38,7 @@ def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False): :abs(num_of_rows)]] -def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_bool_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C bool row to python row """ return [ @@ -38,7 +48,7 @@ def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False): :abs(num_of_rows)]] -def _crow_tinyint_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_tinyint_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C tinyint row to python row """ return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( @@ -49,7 +59,7 @@ def _crow_tinyint_unsigned_to_python( data, num_of_rows, nbytes=None, - micro=False): + precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C tinyint row to python row """ return [ @@ -59,7 +69,7 @@ def _crow_tinyint_unsigned_to_python( :abs(num_of_rows)]] -def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_smallint_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C smallint row to python row """ return [ @@ -70,7 +80,7 @@ def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False): def _crow_smallint_unsigned_to_python( - data, num_of_rows, nbytes=None, micro=False): + data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C smallint row to python row """ return [ @@ -80,14 +90,14 @@ def _crow_smallint_unsigned_to_python( :abs(num_of_rows)]] -def _crow_int_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_int_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C int row to python row """ return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] -def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C int row to python row """ return [ @@ -97,7 +107,7 @@ def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, micro=False): :abs(num_of_rows)]] -def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_bigint_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C bigint row to python row """ return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( @@ -108,7 +118,7 @@ def _crow_bigint_unsigned_to_python( data, num_of_rows, nbytes=None, - micro=False): + precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C bigint row to python row """ return [ @@ -118,21 +128,21 @@ def _crow_bigint_unsigned_to_python( :abs(num_of_rows)]] -def _crow_float_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_float_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C float row to python row """ return [None if math.isnan(ele) else ele for ele in ctypes.cast( data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] -def _crow_double_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_double_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C double row to python row """ return [None if math.isnan(ele) else ele for ele in ctypes.cast( data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] -def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_binary_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C binary row to python row """ assert(nbytes is not None) @@ -140,7 +150,7 @@ def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False): 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] -def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): +def _crow_nchar_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C nchar row to python row """ assert(nbytes is not None) @@ -159,7 +169,7 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): return res -def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False): +def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C binary row to python row """ assert(nbytes is not None) @@ -178,7 +188,7 @@ def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False): return res -def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, micro=False): +def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): """Function to convert C nchar row to python row """ assert(nbytes is not None) @@ -448,8 +458,7 @@ class CTaosInterface(object): result, ctypes.byref(pblock)) if num_of_rows == 0: return None, 0 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) + precision = CTaosInterface.libtaos.taos_result_precision(result) blocks = [None] * len(fields) fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) fieldLen = [ @@ -462,7 +471,7 @@ class CTaosInterface(object): if fields[i]['type'] not in _CONVERT_FUNC_BLOCK: raise DatabaseError("Invalid data type returned from database") blocks[i] = _CONVERT_FUNC_BLOCK[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) + data, num_of_rows, fieldLen[i], precision) return blocks, abs(num_of_rows) @@ -472,8 +481,7 @@ class CTaosInterface(object): pblock = CTaosInterface.libtaos.taos_fetch_row(result) if pblock: num_of_rows = 1 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) + precision = CTaosInterface.libtaos.taos_result_precision(result) blocks = [None] * len(fields) fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) fieldLen = [ @@ -490,7 +498,7 @@ class CTaosInterface(object): blocks[i] = [None] else: blocks[i] = _CONVERT_FUNC[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) + data, num_of_rows, fieldLen[i], precision) else: return None, 0 return blocks, abs(num_of_rows) diff --git a/src/connector/python/taos/constants.py b/src/connector/python/taos/constants.py index 93466f5184..85689b02db 100644 --- a/src/connector/python/taos/constants.py +++ b/src/connector/python/taos/constants.py @@ -40,3 +40,5 @@ class FieldType(object): # Timestamp precision definition C_TIMESTAMP_MILLI = 0 C_TIMESTAMP_MICRO = 1 + C_TIMESTAMP_NANO = 2 + C_TIMESTAMP_UNKNOWN = 3 From 3358f33f9c9a9389f72e87bf8d3f7418f79b1d6f Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 17 Jun 2021 23:11:43 +0800 Subject: [PATCH 46/52] [td-4753] --- src/client/inc/tscUtil.h | 2 ++ src/client/src/tscSQLParser.c | 10 ++++++---- src/client/src/tscUtil.c | 16 ++++++++++++++++ tests/script/general/parser/function.sim | 3 +++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index a9ac788bc3..35f3b42811 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -123,6 +123,8 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i */ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo); bool tscIsTWAQuery(SQueryInfo* pQueryInfo); +bool tscIsIrateQuery(SQueryInfo* pQueryInfo); + bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo); bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo); bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 569c9e95d7..d64fedab0c 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2022,8 +2022,10 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { SSchema colSchema = *tGetTbnameColumnSchema(); - getColumnName(pItem, colSchema.name, colSchema.name, sizeof(colSchema.name) - 1); + char name[TSDB_COL_NAME_LEN] = {0}; + getColumnName(pItem, name, colSchema.name, sizeof(colSchema.name) - 1); + tstrncpy(colSchema.name, name, TSDB_COL_NAME_LEN); /*SExprInfo* pExpr = */tscAddFuncInSelectClause(pQueryInfo, startPos, TSDB_FUNC_TAGPRJ, &index, &colSchema, TSDB_COL_TAG, getNewResColId(pCmd)); } else { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); @@ -3062,8 +3064,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) { } bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { - const char* msg1 = "TWA/Diff not allowed to apply to super table directly"; - const char* msg2 = "TWA/Diff only support group by tbname for super table query"; + const char* msg1 = "TWA/Diff/Derivative/Irate not allowed to apply to super table directly"; + const char* msg2 = "TWA/Diff/Derivative/Irate only support group by tbname for super table query"; const char* msg3 = "function not support for super table query"; // filter sql function not supported by metric query yet. @@ -3076,7 +3078,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) } } - if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivQuery(pQueryInfo)) { + if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivQuery(pQueryInfo) || tscIsIrateQuery(pQueryInfo)) { if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return true; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 89f2563e14..9d2c500a92 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -460,6 +460,22 @@ bool tscIsTWAQuery(SQueryInfo* pQueryInfo) { return false; } +bool tscIsIrateQuery(SQueryInfo* pQueryInfo) { + size_t numOfExprs = tscNumOfExprs(pQueryInfo); + for (int32_t i = 0; i < numOfExprs; ++i) { + SExprInfo* pExpr = tscExprGet(pQueryInfo, i); + if (pExpr == NULL) { + continue; + } + + if (pExpr->base.functionId == TSDB_FUNC_IRATE) { + return true; + } + } + + return false; +} + bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo) { return pQueryInfo->sessionWindow.gap > 0; } diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 4d62c9fc18..a485276e01 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -817,6 +817,9 @@ print ====================> TODO stddev + normal column filter print ====================> irate +sql_error select irate(f1) from st1; +sql select irate(f1) from st1 group by tbname; + sql select irate(k) from t1 if $rows != 1 then return -1 From 75700683de32c82b2d60993372a95641e4c1e87b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 18 Jun 2021 10:18:55 +0800 Subject: [PATCH 47/52] [td-225]refactor. --- src/query/src/qExecutor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 395903f75e..f403e9dd97 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1312,6 +1312,8 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn } } + + // todo opt perf for (int32_t k = 0; k < pOperator->numOfOutput; ++k) { pInfo->binfo.pCtx[k].size = 1; int32_t functionId = pInfo->binfo.pCtx[k].functionId; From 155b4a66c7c4d9740f24ba293942fa350d88f2ab Mon Sep 17 00:00:00 2001 From: Zhiyu Yang <69311263+zyyang-taosdata@users.noreply.github.com> Date: Fri, 18 Jun 2021 11:40:31 +0800 Subject: [PATCH 48/52] [TD-4684]: nano second timestamp precision supported (#6529) * [TD-4684]: add test case for nano second timestamp * [TD-4684]: nano second timestamp precision is supported in jdbc-restful * [TD-4684] * change * [TD-4745]: fix resultsetMetadata is null if query resultSet is null * [TD-4668]: test prepared statement batch insert * [TD-4668]: fix executeBatch error in prepared statment for JNI * change * change * change * change * change * change --- src/connector/jdbc/pom.xml | 1 - .../com/taosdata/jdbc/AbstractConnection.java | 5 +- .../com/taosdata/jdbc/AbstractStatement.java | 2 - .../java/com/taosdata/jdbc/TSDBError.java | 1 + .../com/taosdata/jdbc/TSDBErrorNumbers.java | 2 + .../taosdata/jdbc/TSDBPreparedStatement.java | 44 +--- .../taosdata/jdbc/TSDBResultSetRowData.java | 63 +++-- .../jdbc/enums/TimestampPrecision.java | 8 + .../jdbc/rs/RestfulPreparedStatement.java | 21 +- .../taosdata/jdbc/rs/RestfulResultSet.java | 107 +++++---- .../jdbc/rs/RestfulResultSetMetaData.java | 8 +- .../jdbc/rs/enums/TimestampFormat.java | 7 + .../jdbc/utils/HttpClientPoolUtil.java | 17 +- .../java/com/taosdata/jdbc/utils/Utils.java | 104 ++++++--- .../jdbc/TSDBPreparedStatementTest.java | 218 +++++++++--------- ...174Test.java => DoubleQuoteInSqlTest.java} | 62 ++--- ....java => MicroSecondPrecisionJNITest.java} | 2 +- ...a => MicroSecondPrecisionRestfulTest.java} | 3 +- .../cases/NanoSecondTimestampJNITest.java | 182 +++++++++++++++ .../cases/NanoSecondTimestampRestfulTest.java | 182 +++++++++++++++ ....java => NullValueInResultSetJNITest.java} | 2 +- ...a => NullValueInResultSetRestfulTest.java} | 2 +- ...est.java => NullValueInResultSetTest.java} | 2 +- .../PreparedStatementBatchInsertJNITest.java | 98 ++++++++ ...eparedStatementBatchInsertRestfulTest.java | 98 ++++++++ ...sultSetMetaShouldNotBeNullRestfulTest.java | 86 +++++++ .../com/taosdata/jdbc/cases/TD4144Test.java | 105 --------- .../com/taosdata/jdbc/utils/UtilsTest.java | 78 ++++++- 28 files changed, 1092 insertions(+), 418 deletions(-) create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/enums/TimestampFormat.java rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/{TD4174Test.java => DoubleQuoteInSqlTest.java} (55%) rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/{TwoTypeTimestampPercisionInJniTest.java => MicroSecondPrecisionJNITest.java} (98%) rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/{TwoTypeTimestampPercisionInRestfulTest.java => MicroSecondPrecisionRestfulTest.java} (99%) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/{NullValueInResultSetForJdbcJniTest.java => NullValueInResultSetJNITest.java} (97%) rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/{NullValueInResultSetForJdbcRestfulTest.java => NullValueInResultSetRestfulTest.java} (97%) rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/{TD3841Test.java => NullValueInResultSetTest.java} (99%) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertJNITest.java create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertRestfulTest.java create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java delete mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4144Test.java diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 8ec65a243e..a3a36d54cf 100644 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -122,7 +122,6 @@ **/FailOverTest.java **/InvalidResultSetPointerTest.java **/RestfulConnectionTest.java - **/TD4144Test.java **/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java true diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java index 2970f6c2d3..686ef36262 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java @@ -1,5 +1,7 @@ package com.taosdata.jdbc; +import com.taosdata.jdbc.rs.enums.TimestampFormat; + import java.sql.*; import java.util.Enumeration; import java.util.Map; @@ -18,7 +20,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti for (String propName : propNames) { clientInfoProps.setProperty(propName, properties.getProperty(propName)); } - String timestampFormat = properties.getProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, "STRING"); + String timestampFormat = properties.getProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, String.valueOf(TimestampFormat.STRING)); clientInfoProps.setProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, timestampFormat); } @@ -516,7 +518,6 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti public void abort(Executor executor) throws SQLException { if (isClosed()) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); - // do nothing } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java index 9dc559339a..8b6c074d1b 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java @@ -9,8 +9,6 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement protected List batchedArgs; private int fetchSize; - - @Override public abstract ResultSet executeQuery(String sql) throws SQLException; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java index 90967b3620..411a61eb86 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java @@ -32,6 +32,7 @@ public class TSDBError { TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_SQL, "invalid sql"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE, "numeric value out of range"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE, "unknown taos type in tdengine"); + TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TIMESTAMP_PERCISION, "unknown timestamp precision"); /**************************************************/ TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error"); 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 c978bb3a2e..9f0ba5afab 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 @@ -25,6 +25,7 @@ public class TSDBErrorNumbers { public static final int ERROR_INVALID_SQL = 0x2313; // invalid sql public static final int ERROR_NUMERIC_VALUE_OUT_OF_RANGE = 0x2314; // numeric value out of range public static final int ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE = 0x2315; //unknown taos type in tdengine + public static final int ERROR_UNKNOWN_TIMESTAMP_PERCISION = 0x2316; // unknown timestamp precision public static final int ERROR_UNKNOWN = 0x2350; //unknown error @@ -62,6 +63,7 @@ public class TSDBErrorNumbers { errorNumbers.add(ERROR_INVALID_SQL); errorNumbers.add(ERROR_NUMERIC_VALUE_OUT_OF_RANGE); errorNumbers.add(ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE); + errorNumbers.add(ERROR_UNKNOWN_TIMESTAMP_PERCISION); /*****************************************************/ errorNumbers.add(ERROR_SUBSCRIBE_FAILED); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java index c3d5abf35c..1a007156e9 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java @@ -38,7 +38,6 @@ import java.util.regex.Pattern; public class TSDBPreparedStatement extends TSDBStatement implements PreparedStatement { private String rawSql; private Object[] parameters; - private boolean isPrepared; private ArrayList colData; private ArrayList tableTags; @@ -47,8 +46,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat private String tableName; private long nativeStmtHandle = 0; - private volatile TSDBParameterMetaData parameterMetaData; - TSDBPreparedStatement(TSDBConnection connection, String sql) { super(connection); init(sql); @@ -61,7 +58,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat } } parameters = new Object[parameterCnt]; - this.isPrepared = true; } if (parameterCnt > 1) { @@ -76,11 +72,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat preprocessSql(); } - @Override - public int[] executeBatch() throws SQLException { - return super.executeBatch(); - } - /* * Some of the SQLs sent by other popular frameworks or tools like Spark, contains syntax that cannot be parsed by * the TDengine client. Thus, some simple parsers/filters are intentionally added in this JDBC implementation in @@ -137,29 +128,15 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat /***** for inner queries *****/ } - /** - * Populate parameters into prepared sql statements - * - * @return a string of the native sql statement for TSDB - */ - private String getNativeSql(String rawSql) throws SQLException { - return Utils.getNativeSql(rawSql, this.parameters); - } - @Override public ResultSet executeQuery() throws SQLException { - if (!isPrepared) - return executeQuery(this.rawSql); - - final String sql = getNativeSql(this.rawSql); + final String sql = Utils.getNativeSql(this.rawSql, this.parameters); return executeQuery(sql); } @Override public int executeUpdate() throws SQLException { - if (!isPrepared) - return executeUpdate(this.rawSql); - String sql = getNativeSql(this.rawSql); + String sql = Utils.getNativeSql(this.rawSql, this.parameters); return executeUpdate(sql); } @@ -282,25 +259,14 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public boolean execute() throws SQLException { - if (!isPrepared) - return execute(this.rawSql); - - final String sql = getNativeSql(this.rawSql); + final String sql = Utils.getNativeSql(this.rawSql, this.parameters); return execute(sql); } @Override public void addBatch() throws SQLException { - if (this.batchedArgs == null) { - batchedArgs = new ArrayList<>(); - } - - if (!isPrepared) { - addBatch(this.rawSql); - } else { - String sql = this.getConnection().nativeSQL(this.rawSql); - addBatch(sql); - } + String sql = Utils.getNativeSql(this.rawSql, this.parameters); + addBatch(sql); } @Override diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java index b0b3ae4180..e00ec1e758 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java @@ -147,30 +147,14 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_NCHAR: case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Integer.parseInt((String) obj); - case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: { - Byte value = (byte) obj; - if (value < 0) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); - return value; - } - case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: { - short value = (short) obj; - if (value < 0) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); - return value; - } - case TSDBConstants.TSDB_DATA_TYPE_UINT: { - int value = (int) obj; - if (value < 0) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); - return value; - } - case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { - long value = (long) obj; - if (value < 0) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); - return Long.valueOf(value).intValue(); - } + case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: + return parseUnsignedTinyIntToInt(obj); + case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: + return parseUnsignedSmallIntToInt(obj); + case TSDBConstants.TSDB_DATA_TYPE_UINT: + return parseUnsignedIntegerToInt(obj); + case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: + return parseUnsignedBigIntToInt(obj); case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).intValue(); case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: @@ -180,6 +164,35 @@ public class TSDBResultSetRowData { } } + private byte parseUnsignedTinyIntToInt(Object obj) throws SQLException { + byte value = (byte) obj; + if (value < 0) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); + return value; + } + + private short parseUnsignedSmallIntToInt(Object obj) throws SQLException { + short value = (short) obj; + if (value < 0) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); + return value; + } + + private int parseUnsignedIntegerToInt(Object obj) throws SQLException { + int value = (int) obj; + if (value < 0) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); + return value; + } + + private int parseUnsignedBigIntToInt(Object obj) throws SQLException { + long value = (long) obj; + if (value < 0) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); + return Long.valueOf(value).intValue(); + } + + /** * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api */ @@ -216,7 +229,7 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Long.parseLong((String) obj); case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: { - Byte value = (byte) obj; + byte value = (byte) obj; if (value < 0) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); return value; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java new file mode 100644 index 0000000000..79350076c7 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java @@ -0,0 +1,8 @@ +package com.taosdata.jdbc.enums; + +public enum TimestampPrecision { + MS, + US, + NS, + UNKNOWN +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulPreparedStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulPreparedStatement.java index f58e3f8cd2..16272f4289 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulPreparedStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulPreparedStatement.java @@ -44,7 +44,7 @@ public class RestfulPreparedStatement extends RestfulStatement implements Prepar if (!isPrepared) return executeQuery(this.rawSql); - final String sql = getNativeSql(this.rawSql); + final String sql = Utils.getNativeSql(this.rawSql, this.parameters); return executeQuery(sql); } @@ -55,20 +55,10 @@ public class RestfulPreparedStatement extends RestfulStatement implements Prepar if (!isPrepared) return executeUpdate(this.rawSql); - final String sql = getNativeSql(this.rawSql); + final String sql = Utils.getNativeSql(rawSql, this.parameters); return executeUpdate(sql); } - /**** - * 将rawSql转换成一条可执行的sql语句,使用属性parameters中的变脸进行替换 - * 对于insert into ?.? (?,?,?) using ?.? (?,?,?) tags(?, ?, ?) values(?, ?, ?) - * @param rawSql,可能是insert、select或其他,使用?做占位符 - * @return - */ - private String getNativeSql(String rawSql) { - return Utils.getNativeSql(rawSql, this.parameters); - } - @Override public void setNull(int parameterIndex, int sqlType) throws SQLException { if (isClosed()) @@ -224,16 +214,13 @@ public class RestfulPreparedStatement extends RestfulStatement implements Prepar throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); if (!isPrepared) return execute(this.rawSql); - final String sql = getNativeSql(rawSql); + final String sql = Utils.getNativeSql(rawSql, this.parameters); return execute(sql); } @Override public void addBatch() throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - - final String sql = getNativeSql(this.rawSql); + final String sql = Utils.getNativeSql(rawSql, this.parameters); addBatch(sql); } 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 530b433d42..13850f0b80 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 @@ -6,6 +6,8 @@ import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; import com.google.common.primitives.Shorts; import com.taosdata.jdbc.*; +import com.taosdata.jdbc.enums.TimestampPrecision; +import com.taosdata.jdbc.rs.enums.TimestampFormat; import com.taosdata.jdbc.utils.Utils; import java.math.BigDecimal; @@ -46,6 +48,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { columnNames.clear(); columns.clear(); this.resultSet.clear(); + this.metaData = new RestfulResultSetMetaData(this.database, null, this); return; } // get head @@ -131,7 +134,6 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { } } - private Object parseColumnData(JSONArray row, int colIndex, int taosType) throws SQLException { switch (taosType) { case TSDBConstants.TSDB_DATA_TYPE_NULL: @@ -150,44 +152,8 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { return row.getFloat(colIndex); case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return row.getDouble(colIndex); - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: { - if (row.get(colIndex) == null) - return null; - String timestampFormat = this.statement.getConnection().getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT); - if ("TIMESTAMP".equalsIgnoreCase(timestampFormat)) { - Long value = row.getLong(colIndex); - //TODO: this implementation has bug if the timestamp bigger than 9999_9999_9999_9 - if (value < 1_0000_0000_0000_0L) - return new Timestamp(value); - long epochSec = value / 1000_000l; - long nanoAdjustment = value % 1000_000l * 1000l; - return Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); - } - if ("UTC".equalsIgnoreCase(timestampFormat)) { - String value = row.getString(colIndex); - long epochSec = Timestamp.valueOf(value.substring(0, 19).replace("T", " ")).getTime() / 1000; - int fractionalSec = Integer.parseInt(value.substring(20, value.length() - 5)); - long nanoAdjustment = 0; - if (value.length() > 28) { - // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00 - nanoAdjustment = fractionalSec * 1000l; - } else { - // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00 - nanoAdjustment = fractionalSec * 1000_000l; - } - ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5)); - Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant(); - return Timestamp.from(instant); - } - String value = row.getString(colIndex); - if (value.length() <= 23) // ms timestamp: yyyy-MM-dd HH:mm:ss.SSS - return row.getTimestamp(colIndex); - // us timestamp: yyyy-MM-dd HH:mm:ss.SSSSSS - long epochSec = Timestamp.valueOf(value.substring(0, 19)).getTime() / 1000; - long nanoAdjustment = Integer.parseInt(value.substring(20)) * 1000l; - Timestamp timestamp = Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); - return timestamp; - } + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + return parseTimestampColumnData(row, colIndex); case TSDBConstants.TSDB_DATA_TYPE_BINARY: return row.getString(colIndex) == null ? null : row.getString(colIndex).getBytes(); case TSDBConstants.TSDB_DATA_TYPE_NCHAR: @@ -197,7 +163,66 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { } } - public class Field { + private Timestamp parseTimestampColumnData(JSONArray row, int colIndex) throws SQLException { + if (row.get(colIndex) == null) + return null; + String tsFormatUpperCase = this.statement.getConnection().getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT).toUpperCase(); + TimestampFormat timestampFormat = TimestampFormat.valueOf(tsFormatUpperCase); + switch (timestampFormat) { + case TIMESTAMP: { + Long value = row.getLong(colIndex); + //TODO: this implementation has bug if the timestamp bigger than 9999_9999_9999_9 + if (value < 1_0000_0000_0000_0L) + return new Timestamp(value); + long epochSec = value / 1000_000l; + long nanoAdjustment = value % 1000_000l * 1000l; + return Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + } + case UTC: { + String value = row.getString(colIndex); + long epochSec = Timestamp.valueOf(value.substring(0, 19).replace("T", " ")).getTime() / 1000; + int fractionalSec = Integer.parseInt(value.substring(20, value.length() - 5)); + long nanoAdjustment; + if (value.length() > 31) { + // ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x00 + nanoAdjustment = fractionalSec; + } else if (value.length() > 28) { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00 + nanoAdjustment = fractionalSec * 1000L; + } else { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00 + nanoAdjustment = fractionalSec * 1000_000L; + } + ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5)); + Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant(); + return Timestamp.from(instant); + } + case STRING: + default: { + String value = row.getString(colIndex); + TimestampPrecision precision = Utils.guessTimestampPrecision(value); + if (precision == TimestampPrecision.MS) { + // ms timestamp: yyyy-MM-dd HH:mm:ss.SSS + return row.getTimestamp(colIndex); + } + if (precision == TimestampPrecision.US) { + // us timestamp: yyyy-MM-dd HH:mm:ss.SSSSSS + long epochSec = Timestamp.valueOf(value.substring(0, 19)).getTime() / 1000; + long nanoAdjustment = Integer.parseInt(value.substring(20)) * 1000L; + return Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + } + if (precision == TimestampPrecision.NS) { + // ms timestamp: yyyy-MM-dd HH:mm:ss.SSSSSSSSS + long epochSec = Timestamp.valueOf(value.substring(0, 19)).getTime() / 1000; + long nanoAdjustment = Integer.parseInt(value.substring(20)); + return Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + } + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_TIMESTAMP_PERCISION); + } + } + } + + public static class Field { String name; int type; int length; @@ -211,6 +236,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { this.note = note; this.taos_type = taos_type; } + } @Override @@ -334,6 +360,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { wasNull = true; return 0; } + wasNull = false; if (value instanceof Timestamp) { return ((Timestamp) value).getTime(); 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 7ead8bd1bb..a185abb709 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 @@ -8,20 +8,22 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.sql.Types; import java.util.ArrayList; +import java.util.Collections; +import java.util.List; public class RestfulResultSetMetaData extends WrapperImpl implements ResultSetMetaData { private final String database; - private ArrayList fields; + private List fields; private final RestfulResultSet resultSet; public RestfulResultSetMetaData(String database, ArrayList fields, RestfulResultSet resultSet) { this.database = database; - this.fields = fields; + this.fields = fields == null ? Collections.emptyList() : fields; this.resultSet = resultSet; } - public ArrayList getFields() { + public List getFields() { return fields; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/enums/TimestampFormat.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/enums/TimestampFormat.java new file mode 100644 index 0000000000..edc429857e --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/enums/TimestampFormat.java @@ -0,0 +1,7 @@ +package com.taosdata.jdbc.rs.enums; + +public enum TimestampFormat { + STRING, + TIMESTAMP, + UTC +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java index b1c6dae6b3..ff27bdbdad 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java @@ -16,13 +16,12 @@ import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; public class HttpClientPoolUtil { private static final String DEFAULT_CONTENT_TYPE = "application/json"; - private static final String DEFAULT_TOKEN = "cm9vdDp0YW9zZGF0YQ=="; private static final int DEFAULT_TIME_OUT = 15000; private static final int DEFAULT_MAX_PER_ROUTE = 32; private static final int DEFAULT_MAX_TOTAL = 1000; @@ -80,7 +79,7 @@ public class HttpClientPoolUtil { method.setHeader("Connection", "keep-alive"); method.setHeader("Authorization", "Taosd " + token); - method.setEntity(new StringEntity(data, Charset.forName("UTF-8"))); + method.setEntity(new StringEntity(data, StandardCharsets.UTF_8)); HttpContext context = HttpClientContext.create(); CloseableHttpResponse httpResponse = httpClient.execute(method, context); httpEntity = httpResponse.getEntity(); @@ -165,28 +164,18 @@ public class HttpClientPoolUtil { httpEntity = httpResponse.getEntity(); if (httpEntity != null) { responseBody = EntityUtils.toString(httpEntity, "UTF-8"); -// logger.info("请求URL: " + uri + "+ 返回状态码:" + httpResponse.getStatusLine().getStatusCode()); } } catch (Exception e) { if (method != null) { method.abort(); } e.printStackTrace(); -// logger.error("execute get request exception, url:" + uri + ", exception:" + e.toString() + ",cost time(ms):" -// + (System.currentTimeMillis() - startTime)); - System.out.println("log:调用 HttpClientPoolUtil execute get request exception, url:" + uri + ", exception:" + e.toString() + ",cost time(ms):" - + (System.currentTimeMillis() - startTime)); } finally { if (httpEntity != null) { try { EntityUtils.consumeQuietly(httpEntity); } catch (Exception e) { -// e.printStackTrace(); -// logger.error("close response exception, url:" + uri + ", exception:" + e.toString() -// + ",cost time(ms):" + (System.currentTimeMillis() - startTime)); - new Exception("close response exception, url:" + uri + ", exception:" + e.toString() - + ",cost time(ms):" + (System.currentTimeMillis() - startTime)) - .printStackTrace(); + new Exception("close response exception, url:" + uri + ", exception:" + e.toString() + ",cost time(ms):" + (System.currentTimeMillis() - startTime)).printStackTrace(); } } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java index 8ab610fec6..4c92d27a28 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java @@ -3,14 +3,13 @@ package com.taosdata.jdbc.utils; import com.google.common.collect.Range; import com.google.common.collect.RangeSet; import com.google.common.collect.TreeRangeSet; +import com.taosdata.jdbc.enums.TimestampPrecision; import java.nio.charset.Charset; import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; -import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; @@ -25,39 +24,52 @@ public class Utils { private static Pattern ptn = Pattern.compile(".*?'"); - private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder() - .appendPattern("yyyy-MM-dd HH:mm:ss.SSS").toFormatter(); - private static final DateTimeFormatter formatter2 = new DateTimeFormatterBuilder() - .appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").toFormatter(); + private static final DateTimeFormatter milliSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSS").toFormatter(); + private static final DateTimeFormatter microSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").toFormatter(); + private static final DateTimeFormatter nanoSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS").toFormatter(); public static Time parseTime(String timestampStr) throws DateTimeParseException { - LocalTime time; - try { - time = LocalTime.parse(timestampStr, formatter); - } catch (DateTimeParseException e) { - time = LocalTime.parse(timestampStr, formatter2); - } - return Time.valueOf(time); + LocalDateTime dateTime = parseLocalDateTime(timestampStr); + return dateTime != null ? Time.valueOf(dateTime.toLocalTime()) : null; } - public static Date parseDate(String timestampStr) throws DateTimeParseException { - LocalDate date; - try { - date = LocalDate.parse(timestampStr, formatter); - } catch (DateTimeParseException e) { - date = LocalDate.parse(timestampStr, formatter2); - } - return Date.valueOf(date); + public static Date parseDate(String timestampStr) { + LocalDateTime dateTime = parseLocalDateTime(timestampStr); + return dateTime != null ? Date.valueOf(String.valueOf(dateTime)) : null; } public static Timestamp parseTimestamp(String timeStampStr) { - LocalDateTime dateTime; + LocalDateTime dateTime = parseLocalDateTime(timeStampStr); + return dateTime != null ? Timestamp.valueOf(dateTime) : null; + } + + private static LocalDateTime parseLocalDateTime(String timeStampStr) { try { - dateTime = LocalDateTime.parse(timeStampStr, formatter); + return parseMilliSecTimestamp(timeStampStr); } catch (DateTimeParseException e) { - dateTime = LocalDateTime.parse(timeStampStr, formatter2); + try { + return parseMicroSecTimestamp(timeStampStr); + } catch (DateTimeParseException ee) { + try { + return parseNanoSecTimestamp(timeStampStr); + } catch (DateTimeParseException eee) { + eee.printStackTrace(); + } + } } - return Timestamp.valueOf(dateTime); + return null; + } + + private static LocalDateTime parseMilliSecTimestamp(String timeStampStr) throws DateTimeParseException { + return LocalDateTime.parse(timeStampStr, milliSecFormatter); + } + + private static LocalDateTime parseMicroSecTimestamp(String timeStampStr) throws DateTimeParseException { + return LocalDateTime.parse(timeStampStr, microSecFormatter); + } + + private static LocalDateTime parseNanoSecTimestamp(String timeStampStr) throws DateTimeParseException { + return LocalDateTime.parse(timeStampStr, nanoSecFormatter); } public static String escapeSingleQuota(String origin) { @@ -93,6 +105,8 @@ public class Utils { } public static String getNativeSql(String rawSql, Object[] parameters) { + if (parameters == null || !rawSql.contains("?")) + return rawSql; // toLowerCase String preparedSql = rawSql.trim().toLowerCase(); String[] clause = new String[]{"values\\s*\\(.*?\\)", "tags\\s*\\(.*?\\)", "where\\s*.*"}; @@ -167,13 +181,47 @@ public class Utils { }).collect(Collectors.joining()); } - public static String formatTimestamp(Timestamp timestamp) { int nanos = timestamp.getNanos(); if (nanos % 1000000l != 0) - return timestamp.toLocalDateTime().format(formatter2); - return timestamp.toLocalDateTime().format(formatter); + return timestamp.toLocalDateTime().format(microSecFormatter); + return timestamp.toLocalDateTime().format(milliSecFormatter); } + public static TimestampPrecision guessTimestampPrecision(String value) { + if (isMilliSecFormat(value)) + return TimestampPrecision.MS; + if (isMicroSecFormat(value)) + return TimestampPrecision.US; + if (isNanoSecFormat(value)) + return TimestampPrecision.NS; + return TimestampPrecision.UNKNOWN; + } + private static boolean isMilliSecFormat(String timestampStr) { + try { + milliSecFormatter.parse(timestampStr); + } catch (DateTimeParseException e) { + return false; + } + return true; + } + + private static boolean isMicroSecFormat(String timestampStr) { + try { + microSecFormatter.parse(timestampStr); + } catch (DateTimeParseException e) { + return false; + } + return true; + } + + private static boolean isNanoSecFormat(String timestampStr) { + try { + nanoSecFormatter.parse(timestampStr); + } catch (DateTimeParseException e) { + return false; + } + return true; + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java index 3f8bef4a7e..40ff5c23ef 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java @@ -5,7 +5,6 @@ import org.junit.*; import java.io.IOException; import java.math.BigDecimal; import java.sql.*; -import java.time.LocalTime; import java.util.ArrayList; import java.util.Random; @@ -15,6 +14,7 @@ public class TSDBPreparedStatementTest { private static Connection conn; private static final String sql_insert = "insert into t1 values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; private static final String sql_select = "select * from t1 where ts >= ? and ts < ? and f1 >= ?"; + private static final String dbname = "test_pstmt_jni"; private PreparedStatement pstmt_insert; private PreparedStatement pstmt_select; @@ -299,53 +299,53 @@ public class TSDBPreparedStatementTest { } @Test - public void executeTest() throws SQLException { - Statement stmt = conn.createStatement(); + public void executeTest() throws SQLException { + Statement stmt = conn.createStatement(); - int numOfRows = 1000; + int numOfRows = 1000; - for (int loop = 0; loop < 10; loop++){ + for (int loop = 0; loop < 10; loop++) { stmt.execute("drop table if exists weather_test"); - stmt.execute("create table weather_test(ts timestamp, f1 nchar(4), f2 float, f3 double, f4 timestamp, f5 int, f6 bool, f7 binary(10))"); + stmt.execute("create table weather_test(ts timestamp, f1 nchar(4), f2 float, f3 double, f4 timestamp, f5 int, f6 bool, f7 binary(10))"); TSDBPreparedStatement s = (TSDBPreparedStatement) conn.prepareStatement("insert into ? values(?, ?, ?, ?, ?, ?, ?, ?)"); Random r = new Random(); s.setTableName("weather_test"); - + ArrayList ts = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { + for (int i = 0; i < numOfRows; i++) { ts.add(System.currentTimeMillis() + i); - } + } s.setTimestamp(0, ts); int random = 10 + r.nextInt(5); - ArrayList s2 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + ArrayList s2 = new ArrayList(); + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { s2.add(null); - }else{ + } else { s2.add("分支" + i % 4); } - } - s.setNString(1, s2, 4); + } + s.setNString(1, s2, 4); random = 10 + r.nextInt(5); - ArrayList s3 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + ArrayList s3 = new ArrayList(); + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { s3.add(null); - }else{ + } else { s3.add(r.nextFloat()); } - } + } s.setFloat(2, s3); random = 10 + r.nextInt(5); ArrayList s4 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { s4.add(null); - }else{ + } else { s4.add(r.nextDouble()); } } @@ -353,47 +353,47 @@ public class TSDBPreparedStatementTest { random = 10 + r.nextInt(5); ArrayList ts2 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { ts2.add(null); - }else{ + } else { ts2.add(System.currentTimeMillis() + i); } } s.setTimestamp(4, ts2); random = 10 + r.nextInt(5); - ArrayList vals = new ArrayList<>(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + ArrayList vals = new ArrayList<>(); + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { vals.add(null); - }else{ + } else { vals.add(r.nextInt()); - } + } } s.setInt(5, vals); random = 10 + r.nextInt(5); ArrayList sb = new ArrayList<>(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { sb.add(null); - }else{ + } else { sb.add(i % 2 == 0 ? true : false); } } - s.setBoolean(6, sb); + s.setBoolean(6, sb); random = 10 + r.nextInt(5); ArrayList s5 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { s5.add(null); - }else{ + } else { s5.add("test" + i % 10); } } - s.setString(7, s5, 10); + s.setString(7, s5, 10); s.columnDataAddBatch(); s.columnDataExecuteBatch(); @@ -403,54 +403,54 @@ public class TSDBPreparedStatementTest { PreparedStatement statement = conn.prepareStatement(sql); ResultSet rs = statement.executeQuery(); int rows = 0; - while(rs.next()) { + while (rs.next()) { rows++; } - Assert.assertEquals(numOfRows, rows); + Assert.assertEquals(numOfRows, rows); } } @Test - public void bindDataSelectColumnTest() throws SQLException { - Statement stmt = conn.createStatement(); + public void bindDataSelectColumnTest() throws SQLException { + Statement stmt = conn.createStatement(); - int numOfRows = 1000; + int numOfRows = 1000; - for (int loop = 0; loop < 10; loop++){ + for (int loop = 0; loop < 10; loop++) { stmt.execute("drop table if exists weather_test"); - stmt.execute("create table weather_test(ts timestamp, f1 nchar(4), f2 float, f3 double, f4 timestamp, f5 int, f6 bool, f7 binary(10))"); + stmt.execute("create table weather_test(ts timestamp, f1 nchar(4), f2 float, f3 double, f4 timestamp, f5 int, f6 bool, f7 binary(10))"); TSDBPreparedStatement s = (TSDBPreparedStatement) conn.prepareStatement("insert into ? (ts, f1, f7) values(?, ?, ?)"); Random r = new Random(); s.setTableName("weather_test"); - + ArrayList ts = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { + for (int i = 0; i < numOfRows; i++) { ts.add(System.currentTimeMillis() + i); - } + } s.setTimestamp(0, ts); int random = 10 + r.nextInt(5); - ArrayList s2 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + ArrayList s2 = new ArrayList(); + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { s2.add(null); - }else{ + } else { s2.add("分支" + i % 4); } - } - s.setNString(1, s2, 4); + } + s.setNString(1, s2, 4); random = 10 + r.nextInt(5); ArrayList s3 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { + for (int i = 0; i < numOfRows; i++) { + if (i % random == 0) { s3.add(null); - }else{ + } else { s3.add("test" + i % 10); } } - s.setString(2, s3, 10); + s.setString(2, s3, 10); s.columnDataAddBatch(); s.columnDataExecuteBatch(); @@ -460,30 +460,30 @@ public class TSDBPreparedStatementTest { PreparedStatement statement = conn.prepareStatement(sql); ResultSet rs = statement.executeQuery(); int rows = 0; - while(rs.next()) { + while (rs.next()) { rows++; } - Assert.assertEquals(numOfRows, rows); + Assert.assertEquals(numOfRows, rows); } } @Test - public void bindDataWithSingleTagTest() throws SQLException { - Statement stmt = conn.createStatement(); + public void bindDataWithSingleTagTest() throws SQLException { + Statement stmt = conn.createStatement(); - String types[] = new String[] {"tinyint", "smallint", "int", "bigint", "bool", "float", "double", "binary(10)", "nchar(10)"}; + String types[] = new String[]{"tinyint", "smallint", "int", "bigint", "bool", "float", "double", "binary(10)", "nchar(10)"}; for (String type : types) { stmt.execute("drop table if exists weather_test"); stmt.execute("create table weather_test(ts timestamp, f1 nchar(10), f2 binary(10)) tags (t " + type + ")"); int numOfRows = 1; - + TSDBPreparedStatement s = (TSDBPreparedStatement) conn.prepareStatement("insert into ? using weather_test tags(?) values(?, ?, ?)"); Random r = new Random(); s.setTableName("w1"); - - switch(type) { + + switch (type) { case "tinyint": case "smallint": case "int": @@ -508,37 +508,37 @@ public class TSDBPreparedStatementTest { default: break; } - - + + ArrayList ts = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { + for (int i = 0; i < numOfRows; i++) { ts.add(System.currentTimeMillis() + i); - } + } s.setTimestamp(0, ts); - + int random = 10 + r.nextInt(5); - ArrayList s2 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - s2.add("分支" + i % 4); - } + ArrayList s2 = new ArrayList(); + for (int i = 0; i < numOfRows; i++) { + s2.add("分支" + i % 4); + } s.setNString(1, s2, 10); - + random = 10 + r.nextInt(5); - ArrayList s3 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - s3.add("test" + i % 4); - } + ArrayList s3 = new ArrayList(); + for (int i = 0; i < numOfRows; i++) { + s3.add("test" + i % 4); + } s.setString(2, s3, 10); - + s.columnDataAddBatch(); s.columnDataExecuteBatch(); s.columnDataCloseBatch(); - + String sql = "select * from weather_test"; PreparedStatement statement = conn.prepareStatement(sql); ResultSet rs = statement.executeQuery(); int rows = 0; - while(rs.next()) { + while (rs.next()) { rows++; } Assert.assertEquals(numOfRows, rows); @@ -547,32 +547,32 @@ public class TSDBPreparedStatementTest { @Test - public void bindDataWithMultipleTagsTest() throws SQLException { - Statement stmt = conn.createStatement(); - + public void bindDataWithMultipleTagsTest() throws SQLException { + Statement stmt = conn.createStatement(); + stmt.execute("drop table if exists weather_test"); stmt.execute("create table weather_test(ts timestamp, f1 nchar(10), f2 binary(10)) tags (t1 int, t2 binary(10))"); int numOfRows = 1; - TSDBPreparedStatement s = (TSDBPreparedStatement) conn.prepareStatement("insert into ? using weather_test tags(?,?) (ts, f2) values(?, ?)"); - s.setTableName("w2"); + TSDBPreparedStatement s = (TSDBPreparedStatement) conn.prepareStatement("insert into ? using weather_test tags(?,?) (ts, f2) values(?, ?)"); + s.setTableName("w2"); s.setTagInt(0, 1); s.setTagString(1, "test"); - - + + ArrayList ts = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { + for (int i = 0; i < numOfRows; i++) { ts.add(System.currentTimeMillis() + i); - } + } s.setTimestamp(0, ts); - - ArrayList s2 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { + + ArrayList s2 = new ArrayList(); + for (int i = 0; i < numOfRows; i++) { s2.add("test" + i % 4); } s.setString(1, s2, 10); - + s.columnDataAddBatch(); s.columnDataExecuteBatch(); s.columnDataCloseBatch(); @@ -581,21 +581,20 @@ public class TSDBPreparedStatementTest { PreparedStatement statement = conn.prepareStatement(sql); ResultSet rs = statement.executeQuery(); int rows = 0; - while(rs.next()) { + while (rs.next()) { rows++; } Assert.assertEquals(numOfRows, rows); - } - - @Test + + @Test(expected = SQLException.class) public void createTwoSameDbTest() throws SQLException { - Statement stmt = conn.createStatement(); - + // when + Statement stmt = conn.createStatement(); + stmt.execute("create database dbtest"); stmt.execute("create database dbtest"); - Assert.assertThrows(SQLException.class, () -> stmt.execute("create database dbtest")); } - + @Test public void setBoolean() throws SQLException { // given @@ -1097,9 +1096,9 @@ public class TSDBPreparedStatementTest { try { conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists test_pstmt_jni"); - stmt.execute("create database if not exists test_pstmt_jni"); - stmt.execute("use test_pstmt_jni"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); } } catch (SQLException e) { e.printStackTrace(); @@ -1109,6 +1108,9 @@ public class TSDBPreparedStatementTest { @AfterClass public static void afterClass() { try { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); if (conn != null) conn.close(); } catch (SQLException e) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4174Test.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DoubleQuoteInSqlTest.java similarity index 55% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4174Test.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DoubleQuoteInSqlTest.java index 2704d4cfa5..212a751ec3 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4174Test.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DoubleQuoteInSqlTest.java @@ -7,56 +7,64 @@ import org.junit.*; import java.sql.*; import java.util.Properties; -public class TD4174Test { - private Connection conn; +public class DoubleQuoteInSqlTest { private static final String host = "127.0.0.1"; + private static final String dbname = "td4174"; + + private Connection conn; @Test public void test() { + // given long ts = System.currentTimeMillis(); - try (PreparedStatement pstmt = conn.prepareStatement("insert into weather values(" + ts + ", ?)")) { - JSONObject value = new JSONObject(); - value.put("name", "John Smith"); - value.put("age", 20); - Assert.assertEquals("{\"name\":\"John Smith\",\"age\":20}",value.toJSONString()); - pstmt.setString(1, value.toJSONString()); - - int ret = pstmt.executeUpdate(); - Assert.assertEquals(1, ret); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public static void main(String[] args) { JSONObject value = new JSONObject(); value.put("name", "John Smith"); value.put("age", 20); - System.out.println(value.toJSONString()); + + // when + int ret = 0; + try (PreparedStatement pstmt = conn.prepareStatement("insert into weather values(" + ts + ", ?)")) { + pstmt.setString(1, value.toJSONString()); + ret = pstmt.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertEquals("{\"name\":\"John Smith\",\"age\":20}", value.toJSONString()); + Assert.assertEquals(1, ret); } @Before - public void before() throws SQLException { + public void before() { String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists td4174"); - stmt.execute("create database if not exists td4174"); - stmt.execute("use td4174"); + try { + conn = DriverManager.getConnection(url, properties); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table weather(ts timestamp, text binary(64))"); + } catch (SQLException e) { + e.printStackTrace(); } } @After - public void after() throws SQLException { - if (conn != null) + public void after() { + try { + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.close(); conn.close(); - + } catch (SQLException e) { + e.printStackTrace(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TwoTypeTimestampPercisionInJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java similarity index 98% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TwoTypeTimestampPercisionInJniTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java index f9b111bb12..54e4273ea3 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TwoTypeTimestampPercisionInJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java @@ -10,7 +10,7 @@ import org.junit.Test; import java.sql.*; import java.util.Properties; -public class TwoTypeTimestampPercisionInJniTest { +public class MicroSecondPrecisionJNITest { private static final String host = "127.0.0.1"; private static final String ms_timestamp_db = "ms_precision_test"; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TwoTypeTimestampPercisionInRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java similarity index 99% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TwoTypeTimestampPercisionInRestfulTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java index 5c83b5a9da..7e9f04cd63 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TwoTypeTimestampPercisionInRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java @@ -10,10 +10,9 @@ import org.junit.Test; import java.sql.*; import java.util.Properties; -public class TwoTypeTimestampPercisionInRestfulTest { +public class MicroSecondPrecisionRestfulTest { private static final String host = "127.0.0.1"; - private static final String ms_timestamp_db = "ms_precision_test"; private static final String us_timestamp_db = "us_precision_test"; private static final long timestamp1 = System.currentTimeMillis(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java new file mode 100644 index 0000000000..4f2c87966a --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java @@ -0,0 +1,182 @@ +package com.taosdata.jdbc.cases; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.*; +import java.time.Instant; +import java.util.Random; + +public class NanoSecondTimestampJNITest { + + private static final String host = "127.0.0.1"; + private static final String dbname = "nano_sec_test"; + private static final Random random = new Random(System.currentTimeMillis()); + private static Connection conn; + + @Test + public void insertUsingLongValue() { + // given + long ms = System.currentTimeMillis(); + long ns = ms * 1000_000 + random.nextInt(1000_000); + + // when + int ret = 0; + try (Statement stmt = conn.createStatement()) { + ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertEquals(1, ret); + } + + @Test + public void insertUsingStringValue() { + // given + + // when + int ret = 0; + try (Statement stmt = conn.createStatement()) { + ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)"); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertEquals(1, ret); + } + + @Test + public void insertUsingTimestampValue() { + // given + long epochSec = System.currentTimeMillis() / 1000; + long nanoAdjustment = random.nextInt(1000_000_000); + Timestamp ts = Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + + // when + int ret = 0; + String sql = "insert into weather(ts, temperature, humidity) values( ?, ?, ?)"; + try (PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setTimestamp(1, ts); + pstmt.setFloat(2, 12.34f); + pstmt.setInt(3, 55); + ret = pstmt.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertEquals(1, ret); + } + + @Test + public void selectUsingLongValue() throws SQLException { + // given + long ms = System.currentTimeMillis(); + long ns = ms * 1000_000L + random.nextInt(1000_000); + + // when + ResultSet rs = null; + try (Statement stmt = conn.createStatement()) { + stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); + rs = stmt.executeQuery("select * from weather"); + rs.next(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + long actual = rs.getLong(1); + Assert.assertEquals(ms, actual); + actual = rs.getLong("ts"); + Assert.assertEquals(ms, actual); + } + + @Test + public void selectUsingStringValue() throws SQLException { + // given + String timestampStr = "2021-01-01 12:00:00.123456789"; + + // when + ResultSet rs = null; + try (Statement stmt = conn.createStatement()) { + stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)"); + rs = stmt.executeQuery("select * from weather"); + rs.next(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + String actual = rs.getString(1); + Assert.assertEquals(timestampStr, actual); + actual = rs.getString("ts"); + Assert.assertEquals(timestampStr, actual); + } + + @Test + public void selectUsingTimestampValue() throws SQLException { + // given + long timeMillis = System.currentTimeMillis(); + long epochSec = timeMillis / 1000; + long nanoAdjustment = (timeMillis % 1000) * 1000_000L + random.nextInt(1000_000); + Timestamp ts = Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + + // insert one row + String sql = "insert into weather(ts, temperature, humidity) values( ?, ?, ?)"; + try (PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setTimestamp(1, ts); + pstmt.setFloat(2, 12.34f); + pstmt.setInt(3, 55); + pstmt.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // when + ResultSet rs = null; + try (Statement stmt = conn.createStatement()) { + rs = stmt.executeQuery("select * from weather"); + rs.next(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Timestamp actual = rs.getTimestamp(1); + Assert.assertEquals(ts, actual); + actual = rs.getTimestamp("ts"); + Assert.assertEquals(ts, actual); + Assert.assertEquals(timeMillis, actual.getTime()); + Assert.assertEquals(nanoAdjustment, actual.getNanos()); + } + + @Before + public void before() { + try (Statement stmt = conn.createStatement()) { + stmt.execute("drop table if exists weather"); + stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @BeforeClass + public static void beforeClass() { + final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + try { + conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname + " precision 'ns'"); + stmt.execute("use " + dbname); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java new file mode 100644 index 0000000000..4271f918b9 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java @@ -0,0 +1,182 @@ +package com.taosdata.jdbc.cases; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.*; +import java.time.Instant; +import java.util.Random; + +public class NanoSecondTimestampRestfulTest { + + private static final String host = "127.0.0.1"; + private static final String dbname = "nano_sec_test"; + private static final Random random = new Random(System.currentTimeMillis()); + private static Connection conn; + + @Test + public void insertUsingLongValue() { + // given + long ms = System.currentTimeMillis(); + long ns = ms * 1000_000 + random.nextInt(1000_000); + + // when + int ret = 0; + try (Statement stmt = conn.createStatement()) { + ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertEquals(1, ret); + } + + @Test + public void insertUsingStringValue() { + // given + + // when + int ret = 0; + try (Statement stmt = conn.createStatement()) { + ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)"); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertEquals(1, ret); + } + + @Test + public void insertUsingTimestampValue() { + // given + long epochSec = System.currentTimeMillis() / 1000; + long nanoAdjustment = random.nextInt(1000_000_000); + Timestamp ts = Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + + // when + int ret = 0; + String sql = "insert into weather(ts, temperature, humidity) values( ?, ?, ?)"; + try (PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setTimestamp(1, ts); + pstmt.setFloat(2, 12.34f); + pstmt.setInt(3, 55); + ret = pstmt.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertEquals(1, ret); + } + + @Test + public void selectUsingLongValue() throws SQLException { + // given + long ms = System.currentTimeMillis(); + long ns = ms * 1000_000L + random.nextInt(1000_000); + + // when + ResultSet rs = null; + try (Statement stmt = conn.createStatement()) { + stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); + rs = stmt.executeQuery("select * from weather"); + rs.next(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + long actual = rs.getLong(1); + Assert.assertEquals(ms, actual); + actual = rs.getLong("ts"); + Assert.assertEquals(ms, actual); + } + + @Test + public void selectUsingStringValue() throws SQLException { + // given + String timestampStr = "2021-01-01 12:00:00.123456789"; + + // when + ResultSet rs = null; + try (Statement stmt = conn.createStatement()) { + stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)"); + rs = stmt.executeQuery("select * from weather"); + rs.next(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + String actual = rs.getString(1); + Assert.assertEquals(timestampStr, actual); + actual = rs.getString("ts"); + Assert.assertEquals(timestampStr, actual); + } + + @Test + public void selectUsingTimestampValue() throws SQLException { + // given + long timeMillis = System.currentTimeMillis(); + long epochSec = timeMillis / 1000; + long nanoAdjustment = (timeMillis % 1000) * 1000_000L + random.nextInt(1000_000); + Timestamp ts = Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + + // insert one row + String sql = "insert into weather(ts, temperature, humidity) values( ?, ?, ?)"; + try (PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setTimestamp(1, ts); + pstmt.setFloat(2, 12.34f); + pstmt.setInt(3, 55); + pstmt.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // when + ResultSet rs = null; + try (Statement stmt = conn.createStatement()) { + rs = stmt.executeQuery("select * from weather"); + rs.next(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Timestamp actual = rs.getTimestamp(1); + Assert.assertEquals(ts, actual); + actual = rs.getTimestamp("ts"); + Assert.assertEquals(ts, actual); + Assert.assertEquals(timeMillis, actual.getTime()); + Assert.assertEquals(nanoAdjustment, actual.getNanos()); + } + + @Before + public void before() { + try (Statement stmt = conn.createStatement()) { + stmt.execute("drop table if exists weather"); + stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @BeforeClass + public static void beforeClass() { + final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; + try { + conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname + " precision 'ns'"); + stmt.execute("use " + dbname); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java similarity index 97% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcJniTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java index 782125144c..076125a752 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java @@ -6,7 +6,7 @@ import org.junit.Test; import java.sql.*; -public class NullValueInResultSetForJdbcJniTest { +public class NullValueInResultSetJNITest { private static final String host = "127.0.0.1"; Connection conn; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java similarity index 97% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcRestfulTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java index f2ac94adc1..ea6e36ec1d 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java @@ -6,7 +6,7 @@ import org.junit.Test; import java.sql.*; -public class NullValueInResultSetForJdbcRestfulTest { +public class NullValueInResultSetRestfulTest { private static final String host = "127.0.0.1"; Connection conn; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD3841Test.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java similarity index 99% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD3841Test.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java index c6fba81eb2..61d767b5cf 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD3841Test.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java @@ -7,7 +7,7 @@ import org.junit.*; import java.sql.*; import java.util.Properties; -public class TD3841Test { +public class NullValueInResultSetTest { private static final String host = "127.0.0.1"; private static Properties properties; private static Connection conn_restful; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertJNITest.java new file mode 100644 index 0000000000..ed78c2561e --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertJNITest.java @@ -0,0 +1,98 @@ +package com.taosdata.jdbc.cases; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.sql.*; +import java.util.List; +import java.util.Random; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class PreparedStatementBatchInsertJNITest { + + private static final String host = "127.0.0.1"; + private static final String dbname = "td4668"; + + private final Random random = new Random(System.currentTimeMillis()); + private Connection conn; + + @Test + public void test() { + // given + long ts = System.currentTimeMillis(); + List rows = IntStream.range(0, 10).mapToObj(i -> { + Object[] row = new Object[6]; + final String groupId = String.format("%02d", random.nextInt(100)); + // table name (d + groupId)组合 + row[0] = "d" + groupId; + // tag + row[1] = groupId; + // ts + row[2] = ts + i; + // current 电流 + row[3] = random.nextFloat(); + // voltage 电压 + row[4] = Math.random() > 0.5 ? 220 : 380; + // phase 相位 + row[5] = random.nextInt(10); + return row; + }).collect(Collectors.toList()); + final String sql = "INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,?,?)"; + + // when + try (PreparedStatement pstmt = conn.prepareStatement(sql)) { + for (Object[] row : rows) { + for (int i = 0; i < row.length; i++) { + pstmt.setObject(i + 1, row[i]); + } + pstmt.addBatch(); + } + pstmt.executeBatch(); + } catch (SQLException e) { + e.printStackTrace(); + Assert.fail(); + } + + // then + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from meters"); + int count = 0; + while (rs.next()) { + count++; + } + Assert.assertEquals(10, count); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Before + public void before() { + try { + conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); + stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(groupId int)"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @After + public void after() { + try { + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertRestfulTest.java new file mode 100644 index 0000000000..90b285381a --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertRestfulTest.java @@ -0,0 +1,98 @@ +package com.taosdata.jdbc.cases; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.sql.*; +import java.util.List; +import java.util.Random; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class PreparedStatementBatchInsertRestfulTest { + + private static final String host = "127.0.0.1"; + private static final String dbname = "td4668"; + + private final Random random = new Random(System.currentTimeMillis()); + private Connection conn; + + @Test + public void test() { + // given + long ts = System.currentTimeMillis(); + List rows = IntStream.range(0, 10).mapToObj(i -> { + Object[] row = new Object[6]; + final String groupId = String.format("%02d", random.nextInt(100)); + // table name (d + groupId)组合 + row[0] = "d" + groupId; + // tag + row[1] = groupId; + // ts + row[2] = ts + i; + // current 电流 + row[3] = random.nextFloat(); + // voltage 电压 + row[4] = Math.random() > 0.5 ? 220 : 380; + // phase 相位 + row[5] = random.nextInt(10); + return row; + }).collect(Collectors.toList()); + final String sql = "INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,?,?)"; + + // when + try (PreparedStatement pstmt = conn.prepareStatement(sql)) { + for (Object[] row : rows) { + for (int i = 0; i < row.length; i++) { + pstmt.setObject(i + 1, row[i]); + } + pstmt.addBatch(); + } + pstmt.executeBatch(); + } catch (SQLException e) { + e.printStackTrace(); + Assert.fail(); + } + + // then + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from meters"); + int count = 0; + while (rs.next()) { + count++; + } + Assert.assertEquals(10, count); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Before + public void before() { + try { + conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); + stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(groupId int)"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @After + public void after() { + try { + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java new file mode 100644 index 0000000000..f6d6bb2556 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java @@ -0,0 +1,86 @@ +package com.taosdata.jdbc.cases; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.sql.*; + +public class ResultSetMetaShouldNotBeNullRestfulTest { + + private static final String host = "127.0.0.1"; + private static final String dbname = "td4745"; + + private Connection connection; + + @Test + public void testExecuteQuery() { + // given + ResultSetMetaData metaData = null; + int columnCount = -1; + + // when + try { + Statement statement = connection.createStatement(); + metaData = statement.executeQuery("select * from weather").getMetaData(); + columnCount = metaData.getColumnCount(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertNotNull(metaData); + Assert.assertEquals(0, columnCount); + } + + @Test + public void testExecute() { + // given + ResultSetMetaData metaData = null; + int columnCount = -1; + boolean execute = false; + // when + try { + Statement statement = connection.createStatement(); + execute = statement.execute("select * from weather"); + metaData = statement.getResultSet().getMetaData(); + columnCount = metaData.getColumnCount(); + } catch (SQLException e) { + e.printStackTrace(); + } + + // then + Assert.assertEquals(true, execute); + Assert.assertNotNull(metaData); + Assert.assertEquals(0, columnCount); + } + + @Before + public void before() { + try { + connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); + Statement stmt = connection.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); + stmt.execute("create table weather (ts timestamp, temperature float)"); + stmt.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @After + public void after() { + try { + Statement stmt = connection.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.close(); + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4144Test.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4144Test.java deleted file mode 100644 index 6f29f64111..0000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4144Test.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.taosdata.jdbc.cases; - -import com.taosdata.jdbc.TSDBConnection; -import com.taosdata.jdbc.TSDBDriver; -import com.taosdata.jdbc.TSDBResultSet; -import com.taosdata.jdbc.TSDBSubscribe; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.sql.DriverManager; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -public class TD4144Test { - - private static TSDBConnection connection; - private static final String host = "127.0.0.1"; - - private static final String topic = "topic-meter-current-bg-10"; - private static final String sql = "select * from meters where current > 10"; - private static final String sql2 = "select * from meters where ts >= '2020-08-15 12:20:00.000'"; - - - @Test - public void test() throws SQLException { - TSDBSubscribe subscribe = null; - TSDBResultSet res = null; - boolean hasNext = false; - - try { - subscribe = connection.subscribe(topic, sql, false); - int count = 0; - while (true) { - // 等待1秒,避免频繁调用 consume,给服务端造成压力 - TimeUnit.SECONDS.sleep(1); - if (res == null) { - // 消费数据 - res = subscribe.consume(); - hasNext = res.next(); - } - - if (res == null) { - continue; - } - ResultSetMetaData metaData = res.getMetaData(); - int number = 0; - while (hasNext) { - int columnCount = metaData.getColumnCount(); - for (int i = 1; i <= columnCount; i++) { - System.out.print(metaData.getColumnLabel(i) + ": " + res.getString(i) + "\t"); - } - System.out.println(); - count++; - number++; - hasNext = res.next(); - if (!hasNext) { - res.close(); - res = null; - System.out.println("rows: " + count); - } - if (hasNext == true && number >= 10) { - System.out.println("batch" + number); - break; - } - } - - } - - } catch (SQLException | InterruptedException throwables) { - throwables.printStackTrace(); - } finally { - if (subscribe != null) - subscribe.close(true); - } - } - - @BeforeClass - public static void beforeClass() throws SQLException { - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; - connection = (DriverManager.getConnection(url, properties)).unwrap(TSDBConnection.class); - try (Statement stmt = connection.createStatement()) { - stmt.execute("drop database if exists power"); - stmt.execute("create database if not exists power"); - stmt.execute("use power"); - stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(location binary(64), groupId int)"); - stmt.execute("create table d1001 using meters tags(\"Beijing.Chaoyang\", 2)"); - stmt.execute("create table d1002 using meters tags(\"Beijing.Haidian\", 2)"); - stmt.execute("insert into d1001 values(\"2020-08-15 12:00:00.000\", 12, 220, 1),(\"2020-08-15 12:10:00.000\", 12.3, 220, 2),(\"2020-08-15 12:20:00.000\", 12.2, 220, 1)"); - stmt.execute("insert into d1002 values(\"2020-08-15 12:00:00.000\", 9.9, 220, 1),(\"2020-08-15 12:10:00.000\", 10.3, 220, 1),(\"2020-08-15 12:20:00.000\", 11.2, 220, 1)"); - } - } - - @AfterClass - public static void afterClass() throws SQLException { - if (connection != null) - connection.close(); - } -} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java index c861ef2966..ee83f6ceb2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java @@ -3,22 +3,98 @@ package com.taosdata.jdbc.utils; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.*; +import java.util.stream.Stream; public class UtilsTest { @Test public void escapeSingleQuota() { + // given String s = "'''''a\\'"; + // when String news = Utils.escapeSingleQuota(s); + // then Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); + // given s = "\'''''a\\'"; + // when news = Utils.escapeSingleQuota(s); + // then Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); + // given s = "\'\'\'\''a\\'"; + // when news = Utils.escapeSingleQuota(s); + // then Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); } + + @Test + public void getNativeSqlReplaceQuestionMarks() { + // given + String nativeSql = "insert into ?.? (ts, temperature, humidity) using ?.? tags(?,?) values(now, ?, ?)"; + Object[] parameters = Stream.of("test", "t1", "test", "weather", "beijing", 1, 12.2, 4).toArray(); + + // when + String actual = Utils.getNativeSql(nativeSql, parameters); + + // then + String expected = "insert into test.t1 (ts, temperature, humidity) using test.weather tags('beijing',1) values(now, 12.2, 4)"; + Assert.assertEquals(expected, actual); + } + + @Test + public void getNativeSqlReplaceQuestionMarks2() { + // given + String nativeSql = "INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,?,?)"; + Object[] parameters = Stream.of("d1", 1, 123, 3.14, 220, 4).toArray(); + + // when + String actual = Utils.getNativeSql(nativeSql, parameters); + + // then + String expected = "INSERT INTO d1 (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (1) VALUES (123,3.14,220,4)"; + Assert.assertEquals(expected, actual); + } + + + @Test + public void getNativeSqlReplaceNothing() { + // given + String nativeSql = "insert into test.t1 (ts, temperature, humidity) using test.weather tags('beijing',1) values(now, 12.2, 4)"; + + // when + String actual = Utils.getNativeSql(nativeSql, null); + + // then + Assert.assertEquals(nativeSql, actual); + } + + @Test + public void getNativeSqlReplaceNothing2() { + // given + String nativeSql = "insert into test.t1 (ts, temperature, humidity) using test.weather tags('beijing',1) values(now, 12.2, 4)"; + Object[] parameters = Stream.of("test", "t1", "test", "weather", "beijing", 1, 12.2, 4).toArray(); + + // when + String actual = Utils.getNativeSql(nativeSql, parameters); + + // then + Assert.assertEquals(nativeSql, actual); + } + + @Test + public void getNativeSqlReplaceNothing3() { + // given + String nativeSql = "insert into ?.? (ts, temperature, humidity) using ?.? tags(?,?) values(now, ?, ?)"; + + // when + String actual = Utils.getNativeSql(nativeSql, null); + + // then + Assert.assertEquals(nativeSql, actual); + + } } \ No newline at end of file From f7580dc4376d1ce8085331bb11143d3d5467c256 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 18 Jun 2021 13:31:26 +0800 Subject: [PATCH 49/52] [td-225]fix crash during query. --- src/client/src/tscSQLParser.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 79d9b6e8e3..38d1b33d02 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -423,18 +423,6 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { if(code != TSDB_CODE_SUCCESS) { return code; } - - if (pInfo->pMiscInfo->tableType == TSDB_SUPER_TABLE) { -//// code = tscGetTableMeta(pSql, pTableMetaInfo); -//// if (code != TSDB_CODE_SUCCESS) { -//// return code; -//// } -// -// if (!UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { -// return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); -// } - } - } else if (pInfo->type == TSDB_SQL_DROP_DNODE) { if (pzName->type == TK_STRING) { pzName->n = strdequote(pzName->z); @@ -772,6 +760,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { pCmd->active = pCmd->pQueryInfo; pCmd->command = pCmd->pQueryInfo->command; + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pCmd->active, 0); if (pTableMetaInfo->pTableMeta != NULL) { pSql->res.precision = tscGetTableInfo(pTableMetaInfo->pTableMeta).precision; } @@ -7793,7 +7782,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } } - // todo derivate funtion requires ts column exists in subquery + // todo derivative function requires ts column exists in subquery STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, 0); From dbe8dd40c1a80fbc13375ef267070d72bb250e40 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Fri, 18 Jun 2021 05:45:05 +0000 Subject: [PATCH 50/52] [TD-4690]script:check install package --- packaging/check_package.sh | 245 +++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100755 packaging/check_package.sh diff --git a/packaging/check_package.sh b/packaging/check_package.sh new file mode 100755 index 0000000000..e4d783d2f9 --- /dev/null +++ b/packaging/check_package.sh @@ -0,0 +1,245 @@ +#!/bin/bash +# +# This file is used to install database on linux systems. The operating system +# is required to use systemd to manage services at boot + +set -e +#set -x + +verMode=edge +pagMode=full + +iplist="" +serverFqdn="" + +# -----------------------Variables definition--------------------- +script_dir="../release" +# Dynamic directory +data_dir="/var/lib/taos" +log_dir="/var/log/taos" + +data_link_dir="/usr/local/taos/data" +log_link_dir="/usr/local/taos/log" + +cfg_install_dir="/etc/taos" + +bin_link_dir="/usr/bin" +lib_link_dir="/usr/lib" +lib64_link_dir="/usr/lib64" +inc_link_dir="/usr/include" + +#install main path +install_main_dir="/usr/local/taos" + +# old bin dir +sbin_dir="/usr/local/taos/bin" + +temp_version="" +fin_result="" + +service_config_dir="/etc/systemd/system" +nginx_port=6060 +nginx_dir="/usr/local/nginxd" + +# Color setting +RED='\033[0;31m' +GREEN='\033[1;32m' +GREEN_DARK='\033[0;32m' +GREEN_UNDERLINE='\033[4;32m' +NC='\033[0m' + +csudo="" +if command -v sudo > /dev/null; then + csudo="sudo" +fi + +# ============================= get input parameters ================================================= + +# install.sh -v [server | client] -e [yes | no] -i [systemd | service | ...] + +# set parameters by default value +interactiveFqdn=yes # [yes | no] +verType=server # [server | client] +initType=systemd # [systemd | service | ...] + +while getopts "hv:d:" arg +do + case $arg in + d) + #echo "interactiveFqdn=$OPTARG" + script_dir=$( echo $OPTARG ) + ;; + h) + echo "Usage: `basename $0` -d scripy_path" + exit 0 + ;; + ?) #unknow option + echo "unkonw argument" + exit 1 + ;; + esac +done + +#echo "verType=${verType} interactiveFqdn=${interactiveFqdn}" + +function kill_process() { + pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}') + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi +} + +function check_file() { + #check file whether exists + if [ ! -e $1/$2 ];then + echo -e "$1/$2 \033[31mnot exists\033[0m!quit" + fin_result=$fin_result"\033[31m$temp_version\033[0m test failed!\n" + echo -e $fin_result + exit 8 + fi +} + +function get_package_name() { + var=$1 + if [[ $1 =~ 'aarch' ]];then + echo ${var::-21} + else + echo ${var::-17} + fi +} +function check_link() { + #check Link whether exists or broken + if [ -L $1 ] ; then + if [ ! -e $1 ] ; then + echo -e "$1 \033[31Broken link\033[0m" + fin_result=$fin_result"\033[31m$temp_version\033[0m test failed!\n" + echo -e $fin_result + exit 8 + fi + else + echo -e "$1 \033[31mnot exists\033[0m!quit" + fin_result=$fin_result"\033[31m$temp_version\033[0m test failed!\n" + echo -e $fin_result + exit 8 + fi +} + +function check_main_path() { + #check install main dir and all sub dir + main_dir=("" "cfg" "bin" "connector" "driver" "examples" "include" "init.d") + for i in ${main_dir[@]};do + check_file ${install_main_dir} $i + done + if [ "$verMode" == "cluster" ]; then + nginx_main_dir=("admin" "conf" "html" "sbin" "logs") + for i in ${nginx_main_dir[@]};do + check_file ${nginx_dir} $i + done + fi + echo -e "Check main path:\033[32mOK\033[0m!" +} + +function check_bin_path() { + # check install bin dir and all sub dir + bin_dir=("taos" "taosd" "taosdemo" "taosdump" "remove.sh" "tarbitrator" "set_core.sh") + for i in ${bin_dir[@]};do + check_file ${sbin_dir} $i + done + lbin_dir=("taos" "taosd" "taosdemo" "taosdump" "rmtaos" "tarbitrator" "set_core") + for i in ${lbin_dir[@]};do + check_link ${bin_link_dir}/$i + done + if [ "$verMode" == "cluster" ]; then + check_file ${nginx_dir}/sbin nginx + fi + echo -e "Check bin path:\033[32mOK\033[0m!" +} + + +function check_lib_path() { + # check all links + check_link ${lib_link_dir}/libtaos.so + check_link ${lib_link_dir}/libtaos.so.1 + + if [[ -d ${lib64_link_dir} ]]; then + check_link ${lib64_link_dir}/libtaos.so + check_link ${lib64_link_dir}/libtaos.so.1 + fi + echo -e "Check lib path:\033[32mOK\033[0m!" +} + + +function check_header_path() { + # check all header + header_dir=("taos.h" "taoserror.h") + for i in ${header_dir[@]};do + check_link ${inc_link_dir}/$i + done + echo -e "Check bin path:\033[32mOK\033[0m!" +} + + +function check_config_dir() { + # check all config + check_file ${cfg_install_dir} taos.cfg + check_file ${install_main_dir}/cfg taos.cfg.org + echo -e "Check conf path:\033[32mOK\033[0m!" +} + +function check_log_path() { + # check log path + check_file ${log_dir} + echo -e "Check log path:\033[32mOK\033[0m!" +} + +function check_data_path() { + # check data path + check_file ${data_dir} + echo -e "Check data path:\033[32mOK\033[0m!" +} + +function install_TDengine() { + cd ${script_dir} + tar zxf $1 + temp_version=$(get_package_name $1) + cd $(get_package_name $1) + echo -e "\033[32muninstall TDengine && install TDengine...\033[0m" + rmtaos >/dev/null 2>&1 || echo 'taosd not installed' && echo -e '\n\n' |./install.sh >/dev/null 2>&1 + echo -e "\033[32mTDengine has been installed!\033[0m" + echo -e "\033[32mTDengine is starting...\033[0m" + kill_process taos && systemctl start taosd && sleep 10 +} + +function test_TDengine() { + check_main_path + check_bin_path + check_lib_path + check_header_path + check_config_dir + check_log_path + check_data_path + result=`taos -s 'create database test ;create table test.tt(ts timestamp ,i int);insert into test.tt values(now,11);select * from test.tt' 2>&1 ||:` + if [[ $result =~ "Unable to establish" ]];then + echo -e "\033[31mTDengine connect failed\033[0m" + fin_result=$fin_result"\033[31m$temp_version\033[0m test failed!\n" + echo -e $fin_result + exit 8 + fi + echo -e "Check TDengine connect:\033[32mOK\033[0m!" + fin_result=$fin_result"\033[32m$temp_version\033[0m test OK!\n" +} +# ## ==============================Main program starts from here============================ +TD_package_name=`ls ${script_dir}/*server*gz |awk -F '/' '{print $NF}' ` +temp=`pwd` +for i in $TD_package_name;do + if [[ $i =~ 'enterprise' ]];then + verMode="cluster" + else + verMode="" + fi + cd $temp + install_TDengine $i + test_TDengine +done +echo "============================================================" +echo -e $fin_result \ No newline at end of file From bd1b2a84a89206e474eb4a72adc3de4af99c9b5b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 18 Jun 2021 13:56:09 +0800 Subject: [PATCH 51/52] [td-225]fix compiler error. --- src/client/src/tscSQLParser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 38d1b33d02..0ab7c38186 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -760,9 +760,9 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { pCmd->active = pCmd->pQueryInfo; pCmd->command = pCmd->pQueryInfo->command; - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pCmd->active, 0); - if (pTableMetaInfo->pTableMeta != NULL) { - pSql->res.precision = tscGetTableInfo(pTableMetaInfo->pTableMeta).precision; + STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pCmd->active, 0); + if (pTableMetaInfo1->pTableMeta != NULL) { + pSql->res.precision = tscGetTableInfo(pTableMetaInfo1->pTableMeta).precision; } return TSDB_CODE_SUCCESS; // do not build query message here From 945354280cbf386fbb9338a39d0eca3c1a51afb1 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 18 Jun 2021 18:34:54 +0800 Subject: [PATCH 52/52] Feature/sangshuduo/td 4752 python support ns (#6534) * [TD-4752]: python connector support nanosecond. * [TD-4752]: support nanosecond in test framework. return integer for nanosecond in connector since python does not support nanosecond yet. --- src/connector/python/taos/cinterface.py | 2 +- tests/pytest/util/sql.py | 38 +++++++++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/connector/python/taos/cinterface.py b/src/connector/python/taos/cinterface.py index 61a2a0e9c7..cc7c279458 100644 --- a/src/connector/python/taos/cinterface.py +++ b/src/connector/python/taos/cinterface.py @@ -15,7 +15,7 @@ def _convert_microsecond_to_datetime(micro): def _convert_nanosecond_to_datetime(nanosec): - return datetime.datetime.fromtimestamp(nanosec / 1000000000.0) + return nanosec def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN): diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 8f62c5932b..913c158d05 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -18,6 +18,7 @@ import datetime import inspect import psutil import shutil +import pandas as pd from util.log import * @@ -134,25 +135,32 @@ class TDSql: return self.cursor.istype(col, dataType) def checkData(self, row, col, data): - self.checkRowCol(row, col) - if self.queryResult[row][col] != data: - if self.cursor.istype(col, "TIMESTAMP") and self.queryResult[row][col] == datetime.datetime.fromisoformat(data): - tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % + self.checkRowCol(row, col) + if self.queryResult[row][col] != data: + if self.cursor.istype(col, "TIMESTAMP"): + # suppose user want to check nanosecond timestamp if a longer data passed + if (len(data) >= 28): + if pd.to_datetime(self.queryResult[row][col]) == pd.to_datetime(data): + tdLog.info("sql:%s, row:%d col:%d data:%d == expect:%s" % + (self.sql, row, col, self.queryResult[row][col], data)) + else: + if self.queryResult[row][col] == datetime.datetime.fromisoformat(data): + tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % (self.sql, row, col, self.queryResult[row][col], data)) return if str(self.queryResult[row][col]) == str(data): tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % - (self.sql, row, col, self.queryResult[row][col], data)) + (self.sql, row, col, self.queryResult[row][col], data)) return - elif isinstance(data, float) and abs(self.queryResult[row][col] - data) <= 0.000001: + elif isinstance(data, float) and abs(self.queryResult[row][col] - data) <= 0.000001: tdLog.info("sql:%s, row:%d col:%d data:%f == expect:%f" % - (self.sql, row, col, self.queryResult[row][col], data)) + (self.sql, row, col, self.queryResult[row][col], data)) return else: caller = inspect.getframeinfo(inspect.stack()[1][0]) args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) - tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) + tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) if data is None: tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % @@ -162,11 +170,11 @@ class TDSql: (self.sql, row, col, self.queryResult[row][col], data)) elif isinstance(data, datetime.date): tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % - (self.sql, row, col, self.queryResult[row][col], data)) + (self.sql, row, col, self.queryResult[row][col], data)) elif isinstance(data, float): tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % (self.sql, row, col, self.queryResult[row][col], data)) - else: + else: tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%d" % (self.sql, row, col, self.queryResult[row][col], data)) @@ -200,7 +208,7 @@ class TDSql: tdLog.exit("%s(%d) failed: sql:%s, affectedRows:%d != expect:%d" % args) tdLog.info("sql:%s, affectedRows:%d == expect:%d" % (self.sql, self.affectedRows, expectAffectedRows)) - + def taosdStatus(self, state): tdLog.sleep(5) pstate = 0 @@ -221,7 +229,7 @@ class TDSql: continue pstate = 0 break - + args=(pstate,state) if pstate == state: tdLog.info("taosd state is %d == expect:%d" %args) @@ -236,11 +244,11 @@ class TDSql: tdLog.exit("dir: %s is empty, expect: not empty" %dir) else: tdLog.info("dir: %s is empty, expect: empty" %dir) - else: + else: if state : tdLog.info("dir: %s is not empty, expect: not empty" %dir) else: - tdLog.exit("dir: %s is not empty, expect: empty" %dir) + tdLog.exit("dir: %s is not empty, expect: empty" %dir) else: tdLog.exit("dir: %s doesn't exist" %dir) def createDir(self, dir): @@ -250,5 +258,5 @@ class TDSql: os.makedirs( dir, 755 ) tdLog.info("dir: %s is created" %dir) pass - + tdSql = TDSql()