diff --git a/README.md b/README.md index 2c33119e34305cbbfa114842e2589ddf87417100..0e1adcd97c61265ec0ad272043c9604736545b3d 100644 --- a/README.md +++ b/README.md @@ -131,10 +131,10 @@ cmake .. -DCPUTYPE=mips64 && cmake --build . ### On Windows platform If you use the Visual Studio 2013, please open a command window by executing "cmd.exe". -Please specify "x86_amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat. +Please specify "amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat. ```cmd mkdir debug && cd debug -"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" < x86_amd64 | x86 > +"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" < amd64 | x86 > cmake .. -G "NMake Makefiles" nmake ``` diff --git a/cmake/define.inc b/cmake/define.inc index cc8bd0fc355847354b23453d2329bda88bfaa2b7..441bf199974549fbe0acd33b3f971c0b29742096 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -122,10 +122,14 @@ IF (TD_LINUX) ADD_DEFINITIONS(-D_TD_NINGSI_60) MESSAGE(STATUS "set ningsi macro to true") ENDIF () - - SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG") + ELSE () + SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + ENDIF () SET(RELEASE_FLAGS "-O3 -Wno-error") - + IF (${COVER} MATCHES "true") MESSAGE(STATUS "Test coverage mode, add extra flags") SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage") @@ -144,7 +148,11 @@ IF (TD_DARWIN_64) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "darwin64 is defined") SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") - SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -O0 -g3 -DDEBUG") + ELSE () + SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + ENDIF () SET(RELEASE_FLAGS "-Og") INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc) @@ -162,7 +170,14 @@ IF (TD_WINDOWS) IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18") ENDIF () - SET(DEBUG_FLAGS "/fsanitize=thread /fsanitize=leak /fsanitize=memory /fsanitize=undefined /fsanitize=hwaddress /Zi /W3 /GL") + + IF (TD_MEMORY_SANITIZER) +MESSAGE("memory sanitizer detected as true") + SET(DEBUG_FLAGS "/fsanitize=address /Zi /W3 /GL") + ELSE () +MESSAGE("memory sanitizer detected as false") + SET(DEBUG_FLAGS "/Zi /W3 /GL") + ENDIF () SET(RELEASE_FLAGS "/W0 /O3 /GL") ENDIF () @@ -171,7 +186,7 @@ IF (TD_WINDOWS) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/wepoll/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/MsvcLibX/include) -ENDIF () +ENDIF () IF (TD_WINDOWS_64) ADD_DEFINITIONS(-D_M_X64) diff --git a/cmake/input.inc b/cmake/input.inc index 9b72a35d940ba5e3d79458bbe2455b0db2b59e14..c073bbbc037d105dbacea1e14981537cd31b7202 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -83,3 +83,8 @@ SET(TD_BUILD_JDBC TRUE) IF (${BUILD_JDBC} MATCHES "false") SET(TD_BUILD_JDBC FALSE) ENDIF () + +SET(TD_MEMORY_SANITIZER FALSE) +IF (${MEMORY_SANITIZER} MATCHES "true") + SET(TD_MEMORY_SANITIZER TRUE) +ENDIF () diff --git a/cmake/install.inc b/cmake/install.inc index f8b3b7c3c62c16df537a941d7f14ccb74bc64217..63764348d339d992e8ff3be1036c1c9921fd7b99 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.30.jar DESTINATION connector/jdbc) ENDIF () ELSEIF (TD_DARWIN) SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh") diff --git a/documentation20/cn/03.architecture/docs.md b/documentation20/cn/03.architecture/docs.md index 2668967102986952793cd0f000f32ae4cc5e1125..d22855198abc804d6cee5603b56537c9315d610e 100644 --- a/documentation20/cn/03.architecture/docs.md +++ b/documentation20/cn/03.architecture/docs.md @@ -176,7 +176,7 @@ TDengine 分布式架构的逻辑结构图如下: **通讯方式:**TDengine系统的各个数据节点之间,以及应用驱动与各数据节点之间的通讯是通过TCP/UDP进行的。因为考虑到物联网场景,数据写入的包一般不大,因此TDengine 除采用TCP做传输之外,还采用UDP方式,因为UDP 更加高效,而且不受连接数的限制。TDengine实现了自己的超时、重传、确认等机制,以确保UDP的可靠传输。对于数据量不到15K的数据包,采取UDP的方式进行传输,超过15K的,或者是查询类的操作,自动采取TCP的方式进行传输。同时,TDengine根据配置和数据包,会自动对数据进行压缩/解压缩,数字签名/认证等处理。对于数据节点之间的数据复制,只采用TCP方式进行数据传输。 -**FQDN配置**:一个数据节点有一个或多个FQDN,可以在系统配置文件taos.cfg通过参数“fqdn"进行指定,如果没有指定,系统将自动获取计算机的hostname作为其FQDN。如果节点没有配置FQDN,可以直接将该节点的配置参数fqdn设置为它的IP地址。但不建议使用IP,因为IP地址可变,一旦变化,将让集群无法正常工作。一个数据节点的EP(End Point)由FQDN + Port组成。采用FQDN,需要保证DNS服务正常工作,或者在节点以及应用所在的节点配置好hosts文件。 +**FQDN配置**:一个数据节点有一个或多个FQDN,可以在系统配置文件taos.cfg通过参数“fqdn"进行指定,如果没有指定,系统将自动获取计算机的hostname作为其FQDN。如果节点没有配置FQDN,可以直接将该节点的配置参数fqdn设置为它的IP地址。但不建议使用IP,因为IP地址可变,一旦变化,将让集群无法正常工作。一个数据节点的EP(End Point)由FQDN + Port组成。采用FQDN,需要保证DNS服务正常工作,或者在节点以及应用所在的节点配置好hosts文件。另外,这个参数值的长度需要控制在 96 个字符以内。 **端口配置:**一个数据节点对外的端口由TDengine的系统配置参数serverPort决定,对集群内部通讯的端口是serverPort+5。集群内数据节点之间的数据复制操作还占有一个TCP端口,是serverPort+10. 为支持多线程高效的处理UDP数据,每个对内和对外的UDP连接,都需要占用5个连续的端口。因此一个数据节点总的端口范围为serverPort到serverPort + 10,总共11个TCP/UDP端口。(另外还可能有 RESTful、Arbitrator 所使用的端口,那样的话就一共是 13 个。)使用时,需要确保防火墙将这些端口打开,以备使用。每个数据节点可以配置不同的serverPort。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port)) diff --git a/documentation20/cn/08.connector/01.java/docs.md b/documentation20/cn/08.connector/01.java/docs.md index ffea252c86b5b3eab41e93685e04dfcccccec879..e6d214c74d3367d814e0022d4c6a147c4a44b326 100644 --- a/documentation20/cn/08.connector/01.java/docs.md +++ b/documentation20/cn/08.connector/01.java/docs.md @@ -325,10 +325,12 @@ for (int i = 0; i < numOfRows; i++){ } s.setString(2, s2, 10); -// AddBatch 之后,可以再设定新的表名、TAGS、VALUES 取值,这样就能实现一次执行向多个数据表写入: +// AddBatch 之后,缓存并未清空。为避免混乱,并不推荐在 ExecuteBatch 之前再次绑定新一批的数据: s.columnDataAddBatch(); -// 执行语句: +// 执行绑定数据后的语句: s.columnDataExecuteBatch(); +// 执行语句后清空缓存。在清空之后,可以复用当前的对象,绑定新的一批数据(可以是新表名、新 TAGS 值、新 VALUES 值): +s.columnDataClearBatch(); // 执行完毕,释放资源: s.columnDataCloseBatch(); ``` diff --git a/documentation20/cn/08.connector/docs.md b/documentation20/cn/08.connector/docs.md index b6125e3cfea180007bc784868d7be6e9d3747244..8c22d50185d1c30459487682800241b48e782d95 100644 --- a/documentation20/cn/08.connector/docs.md +++ b/documentation20/cn/08.connector/docs.md @@ -307,6 +307,8 @@ TDengine的异步API均采用非阻塞调用模式。应用程序可以用多线 8. 调用 `taos_stmt_execute` 执行已经准备好的批处理指令; 9. 执行完毕,调用 `taos_stmt_close` 释放所有资源。 +说明:如果 `taos_stmt_execute` 执行成功,假如不需要改变 SQL 语句的话,那么是可以复用 `taos_stmt_prepare` 的解析结果,直接进行第 3~6 步绑定新数据的。但如果执行出错,那么并不建议继续在当前的环境上下文下继续工作,而是建议释放资源,然后从 `taos_stmt_init` 步骤重新开始。 + 除 C/C++ 语言外,TDengine 的 Java 语言 JNI Connector 也提供参数绑定接口支持,具体请另外参见:[参数绑定接口的 Java 用法](https://www.taosdata.com/cn/documentation/connector/java#stmt-java)。 接口相关的具体函数如下(也可以参考 [apitest.c](https://github.com/taosdata/TDengine/blob/develop/tests/examples/c/apitest.c) 文件中使用对应函数的方式): @@ -378,6 +380,11 @@ typedef struct TAOS_MULTI_BIND { 执行完毕,释放所有资源。 +- `char * taos_stmt_errstr(TAOS_STMT *stmt)` + + (2.1.3.0 版本新增) + 用于在其他 stmt API 返回错误(返回错误码或空指针)时获取错误信息。 + ### 连续查询接口 TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时间段,对一张或多张数据库的表(数据流)进行各种实时聚合计算操作。操作简单,仅有打开、关闭流的API。具体如下: diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md index ee2f34ff11ef5e69195c01d0b605383c3257f48c..d0e82a16c8a1faf5568b2b4dd930af5af6646bf4 100644 --- a/documentation20/cn/11.administrator/docs.md +++ b/documentation20/cn/11.administrator/docs.md @@ -99,7 +99,7 @@ taosd -C 下面仅仅列出一些重要的配置参数,更多的参数请看配置文件里的说明。各个参数的详细介绍及作用请看前述章节,而且这些参数的缺省配置都是工作的,一般无需设置。**注意:配置修改后,需要重启*taosd*服务才能生效。** - firstEp: taosd启动时,主动连接的集群中首个dnode的end point, 默认值为localhost:6030。 -- fqdn:数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。 +- fqdn:数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。这个参数值的长度需要控制在 96 个字符以内。 - serverPort:taosd启动后,对外服务的端口号,默认值为6030。(RESTful服务使用的端口号是在此基础上+11,即默认值为6041。) - dataDir: 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。 - logDir:日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos。 diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index f747184ce017e9cb780ba2a61b87360cee0379d8..427431d3c00549da4008bb6a9879288b4685b92d 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -123,6 +123,7 @@ 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); @@ -132,7 +133,6 @@ bool hasTagValOutput(SQueryInfo* pQueryInfo); bool timeWindowInterpoRequired(SQueryInfo *pQueryInfo); bool isStabledev(SQueryInfo* pQueryInfo); bool isTsCompQuery(SQueryInfo* pQueryInfo); -bool isSimpleAggregate(SQueryInfo* pQueryInfo); bool isBlockDistQuery(SQueryInfo* pQueryInfo); bool isSimpleAggregateRv(SQueryInfo* pQueryInfo); @@ -214,7 +214,7 @@ void tscColumnListDestroy(SArray* pColList); void tscColumnListCopy(SArray* dst, const SArray* src, uint64_t tableUid); void tscColumnListCopyAll(SArray* dst, const SArray* src); -void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo); +void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId); void tscDequoteAndTrimToken(SStrToken* pToken); int32_t tscValidateName(SStrToken* pToken); @@ -329,9 +329,7 @@ STableMeta* tscTableMetaDup(STableMeta* pTableMeta); SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo); int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr); - -void tsCreateSQLFunctionCtx(SQueryInfo* pQueryInfo, SQLFunctionCtx* pCtx, SSchema* pSchema); -void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage); +void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage, uint64_t qId); void* malloc_throw(size_t size); void* calloc_throw(size_t nmemb, size_t size); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c002f2cf323a03ec024f4ebc41e04ac7e6c07571..5a0dcf6208be2b95268dd2df2d83bc185d96fde5 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -320,7 +320,7 @@ int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo); void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo); void tscSetResRawPtrRv(SSqlRes* pRes, SQueryInfo* pQueryInfo, SSDataBlock* pBlock); -void handleDownstreamOperator(SSqlObj** pSqlList, int32_t numOfUpstream, SQueryInfo* px, SSqlRes* pOutput); +void handleDownstreamOperator(SSqlObj** pSqlList, int32_t numOfUpstream, SQueryInfo* px, SSqlObj* pParent); void destroyTableNameList(SInsertStatementParam* pInsertParam); void tscResetSqlCmd(SSqlCmd *pCmd, bool removeMeta); diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 15276a38887523541cbe37ebf1add2152d2ffe80..d857d00e159d06df266187693913a6b6e404a2b3 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -144,7 +144,7 @@ static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows) { } // local merge has handle this situation during super table non-projection query. - if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE) { + if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE) { pRes->numOfClauseTotal += pRes->numOfRows; } @@ -174,7 +174,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo } pSql->fp = fp; - if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) { + if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) { pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; } @@ -257,14 +257,14 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) { } return; - } else if (pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE) { + } else if (pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE) { // in case of show command, return no data (*pSql->fetchFp)(param, pSql, 0); } else { assert(0); } } else { // current query is not completed, continue retrieve from node - if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) { + if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) { pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; } diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index f97f54a6267d2754cb2edf2fd38ff6c075a2b285..2c9717306f2b26dfbbb5ec1d676b5baad3eb2d2d 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -323,7 +323,7 @@ TAOS_ROW tscFetchRow(void *param) { // current data set are exhausted, fetch more data from node if (pRes->row >= pRes->numOfRows && (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) && (pCmd->command == TSDB_SQL_RETRIEVE || - pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE || + pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE || pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE || pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_SHOW || diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index f199a5798779523e90e95bfce468a68b8afb6c6d..3f12bc811bd2508583397c37723b498c710088d1 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -78,6 +78,16 @@ typedef struct STscStmt { SNormalStmt normal; } STscStmt; +#define STMT_RET(c) do { \ + int32_t _code = c; \ + if (pStmt && pStmt->pSql) { pStmt->pSql->res.code = _code; } else {terrno = _code;} \ + return _code; \ +} while (0) + +static int32_t invalidOperationMsg(char* dstBuffer, const char* errMsg) { + return tscInvalidOperationMsg(dstBuffer, errMsg, NULL); +} + static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_t len) { uint16_t size = stmt->numParts + 1; if (size > stmt->sizeParts) { @@ -163,8 +173,8 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { break; default: - tscDebug("0x%"PRIx64" bind column%d: type mismatch or invalid", stmt->pSql->self, i); - return TSDB_CODE_TSC_INVALID_VALUE; + tscError("0x%"PRIx64" bind column%d: type mismatch or invalid", stmt->pSql->self, i); + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind type mismatch or invalid"); } } @@ -727,6 +737,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, #endif if (bind->buffer_type != param->type) { + tscError("column type mismatch"); return TSDB_CODE_TSC_INVALID_VALUE; } @@ -754,6 +765,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, case TSDB_DATA_TYPE_BINARY: if ((*bind->length) > (uintptr_t)param->bytes) { + tscError("column length is too big"); return TSDB_CODE_TSC_INVALID_VALUE; } size = (short)*bind->length; @@ -763,6 +775,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, case TSDB_DATA_TYPE_NCHAR: { int32_t output = 0; if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) { + tscError("convert nchar failed"); return TSDB_CODE_TSC_INVALID_VALUE; } varDataSetLen(data + param->offset, output); @@ -787,6 +800,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, static int doBindBatchParam(STableDataBlocks* pBlock, SParamInfo* param, TAOS_MULTI_BIND* bind, int32_t rowNum) { if (bind->buffer_type != param->type || !isValidDataType(param->type)) { + tscError("column mismatch or invalid"); return TSDB_CODE_TSC_INVALID_VALUE; } @@ -892,8 +906,8 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { int code = doBindParam(pBlock, data, param, &bind[param->idx], 1); if (code != TSDB_CODE_SUCCESS) { - tscDebug("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx); - return code; + tscDebug("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx); + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid"); } } @@ -957,13 +971,13 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c SParamInfo* param = &pBlock->params[j]; if (bind[param->idx].num != rowNum) { tscError("0x%"PRIx64" param %d: num[%d:%d] not match", pStmt->pSql->self, param->idx, rowNum, bind[param->idx].num); - return TSDB_CODE_TSC_INVALID_VALUE; + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind row num mismatch"); } int code = doBindBatchParam(pBlock, param, &bind[param->idx], pCmd->batchSize); if (code != TSDB_CODE_SUCCESS) { tscError("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx); - return code; + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid"); } } @@ -974,7 +988,7 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c int code = doBindBatchParam(pBlock, param, bind, pCmd->batchSize); if (code != TSDB_CODE_SUCCESS) { tscError("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx); - return code; + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid"); } if (colIdx == (pBlock->numOfParams - 1)) { @@ -993,7 +1007,7 @@ static int insertStmtUpdateBatch(STscStmt* stmt) { if (pCmd->batchSize > INT16_MAX) { tscError("too many record:%d", pCmd->batchSize); - return TSDB_CODE_TSC_APP_ERROR; + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "too many records"); } if (taosHashGetSize(pCmd->insertParam.pTableBlockHashList) == 0) { @@ -1057,7 +1071,8 @@ static int insertStmtReset(STscStmt* pStmt) { static int insertStmtExecute(STscStmt* stmt) { SSqlCmd* pCmd = &stmt->pSql->cmd; if (pCmd->batchSize == 0) { - return TSDB_CODE_TSC_INVALID_VALUE; + tscError("no records bind"); + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "no records bind"); } if (taosHashGetSize(pCmd->insertParam.pTableBlockHashList) == 0) { @@ -1174,7 +1189,7 @@ static int insertBatchStmtExecute(STscStmt* pStmt) { if(pStmt->mtb.nameSet == false) { tscError("0x%"PRIx64" no table name set", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no table name set"); } pStmt->pSql->retry = pStmt->pSql->maxRetry + 1; //no retry @@ -1215,7 +1230,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { int32_t index = 0; SStrToken sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n == 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("table is is expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "table name is expected", pCmd->insertParam.sql); } if (sToken.n == 1 && sToken.type == TK_QUESTION) { @@ -1237,24 +1253,28 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { return TSDB_CODE_SUCCESS; } - if (sToken.n <= 0 || sToken.type != TK_USING) { - return tscSQLSyntaxErrMsg(pCmd->payload, "keywords USING is expected", sToken.z); + if (sToken.n <= 0 || sToken.type != TK_USING) { + tscError("keywords USING is expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "keywords USING is expected", sToken.z ? sToken.z : pCmd->insertParam.sql); } sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || ((sToken.type != TK_ID) && (sToken.type != TK_STRING))) { - return tscSQLSyntaxErrMsg(pCmd->payload, "invalid token", sToken.z); + tscError("invalid token, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "invalid token", sToken.z ? sToken.z : pCmd->insertParam.sql); } pStmt->mtb.stbname = sToken; sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || sToken.type != TK_TAGS) { - return tscSQLSyntaxErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z); + tscError("keyword TAGS expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z ? sToken.z : pCmd->insertParam.sql); } sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || sToken.type != TK_LP) { - return tscSQLSyntaxErrMsg(pCmd->payload, ") expected", sToken.z); + tscError("( expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "( expected", sToken.z ? sToken.z : pCmd->insertParam.sql); } pStmt->mtb.tags = taosArrayInit(4, sizeof(SStrToken)); @@ -1264,7 +1284,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { while (loopCont) { sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("unexpected sql end, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "unexpected sql end", pCmd->insertParam.sql); } switch (sToken.type) { @@ -1272,7 +1293,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { loopCont = 0; break; case TK_VALUES: - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("unexpected token values, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "unexpected token", sToken.z); case TK_QUESTION: pStmt->mtb.tagSet = false; //continue default: @@ -1282,12 +1304,14 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { } if (taosArrayGetSize(pStmt->mtb.tags) <= 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("no tags, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "no tags", pCmd->insertParam.sql); } sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || (sToken.type != TK_VALUES && sToken.type != TK_LP)) { - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("sql error, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "sql error", sToken.z ? sToken.z : pCmd->insertParam.sql); } pStmt->mtb.values = sToken; @@ -1329,8 +1353,8 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO } else { if (tags[j].buffer == NULL) { free(str); - tscError("empty"); - return TSDB_CODE_TSC_APP_ERROR; + tscError("empty tag value in params"); + return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "empty tag value in params"); } ret = converToStr(str + len, tags[j].buffer_type, tags[j].buffer, tags[j].length ? (int32_t)*tags[j].length : -1, &l); @@ -1387,13 +1411,15 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO TAOS_STMT* taos_stmt_init(TAOS* taos) { STscObj* pObj = (STscObj*)taos; + STscStmt* pStmt = NULL; + if (pObj == NULL || pObj->signature != pObj) { terrno = TSDB_CODE_TSC_DISCONNECTED; tscError("connection disconnected"); return NULL; } - STscStmt* pStmt = calloc(1, sizeof(STscStmt)); + pStmt = calloc(1, sizeof(STscStmt)); if (pStmt == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); @@ -1410,6 +1436,14 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { return NULL; } + if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { + free(pSql); + free(pStmt); + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + tscError("failed to malloc payload buffer"); + return NULL; + } + tsem_init(&pSql->rspSem, 0, 0); pSql->signature = pSql; pSql->pTscObj = pObj; @@ -1425,13 +1459,12 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->last != STMT_INIT) { tscError("prepare status error, last:%d", pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "prepare status error")); } pStmt->last = STMT_PREPARE; @@ -1447,17 +1480,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { pCmd->insertParam.insertType = TSDB_QUERY_TYPE_STMT_INSERT; - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { - tscError("%p failed to malloc payload buffer", pSql); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); - free(pCmd->payload); - return TSDB_CODE_TSC_OUT_OF_MEMORY; + STMT_RET(TSDB_CODE_TSC_OUT_OF_MEMORY); } pRes->qId = 0; @@ -1476,11 +1503,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { int32_t ret = stmtParseInsertTbTags(pSql, pStmt); if (ret != TSDB_CODE_SUCCESS) { - return ret; + STMT_RET(ret); } if (pStmt->multiTbInsert) { - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } memset(&pStmt->mtb, 0, sizeof(pStmt->mtb)); @@ -1489,14 +1516,14 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { // wait for the callback function to post the semaphore tsem_wait(&pSql->rspSem); - return pSql->res.code; + STMT_RET(pSql->res.code); } - return code; + STMT_RET(code); } pStmt->isInsert = false; - return normalStmtPrepare(pStmt); + STMT_RET(normalStmtPrepare(pStmt)); } int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) { @@ -1505,25 +1532,22 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags SSqlCmd* pCmd = &pSql->cmd; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (name == NULL) { - terrno = TSDB_CODE_TSC_APP_ERROR; tscError("0x%"PRIx64" name is NULL", pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "name is NULL")); } if (pStmt->multiTbInsert == false || !tscIsInsertData(pSql->sqlstr)) { - terrno = TSDB_CODE_TSC_APP_ERROR; - tscError("0x%"PRIx64" not multi table insert", pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + tscError("0x%"PRIx64" not multiple table insert", pSql->self); + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not multiple table insert")); } if (pStmt->last == STMT_INIT || pStmt->last == STMT_BIND || pStmt->last == STMT_BIND_COL) { - tscError("0x%"PRIx64" settbname status error, last:%d", pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + tscError("0x%"PRIx64" set_tbname_tags status error, last:%d", pSql->self, pStmt->last); + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "set_tbname_tags status error")); } pStmt->last = STMT_SETTBNAME; @@ -1535,7 +1559,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pStmt->mtb.pTableBlockHashList, (const char*)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid)); if (t1 == NULL) { tscError("0x%"PRIx64" no table data block in hash list, uid:%" PRId64 , pSql->self, pStmt->mtb.currentUid); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(TSDB_CODE_TSC_APP_ERROR); } SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData; @@ -1544,7 +1568,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)t1, POINTER_BYTES); tscDebug("0x%"PRIx64" table:%s is already prepared, uid:%" PRIu64, pSql->self, name, pStmt->mtb.currentUid); - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } if (pStmt->mtb.tagSet) { @@ -1552,12 +1576,12 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags } else { if (tags == NULL) { tscError("No tags set"); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no tags set")); } int32_t ret = stmtGenInsertStatement(pSql, pStmt, name, tags); if (ret != TSDB_CODE_SUCCESS) { - return ret; + STMT_RET(ret); } } @@ -1591,7 +1615,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags code = tscGetDataBlockFromList(pCmd->insertParam.pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, sizeof(SSubmitBlk), pTableMeta->tableInfo.rowSize, &pTableMetaInfo->name, pTableMeta, &pBlock, NULL); if (code != TSDB_CODE_SUCCESS) { - return code; + STMT_RET(code); } SSubmitBlk* blk = (SSubmitBlk*)pBlock->pData; @@ -1606,7 +1630,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid); } - return code; + STMT_RET(code); } @@ -1639,35 +1663,34 @@ int taos_stmt_close(TAOS_STMT* stmt) { } taos_free_result(pStmt->pSql); - free(pStmt); - return TSDB_CODE_SUCCESS; + tfree(pStmt); + STMT_RET(TSDB_CODE_SUCCESS); } int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { if (pStmt->multiTbInsert) { if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } else { if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_EXECUTE) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } pStmt->last = STMT_BIND; - return insertStmtBindParam(pStmt, bind); + STMT_RET(insertStmtBindParam(pStmt, bind)); } else { - return normalStmtBindParam(pStmt, bind); + STMT_RET(normalStmtBindParam(pStmt, bind)); } } @@ -1676,69 +1699,67 @@ int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (bind == NULL || bind->num <= 0 || bind->num > INT16_MAX) { tscError("0x%"PRIx64" invalid parameter", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "invalid bind param")); } if (!pStmt->isInsert) { tscError("0x%"PRIx64" not or invalid batch insert", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not or invalid batch insert")); } if (pStmt->multiTbInsert) { if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } else { if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_EXECUTE) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } pStmt->last = STMT_BIND; - return insertStmtBindParamBatch(pStmt, bind, -1); + STMT_RET(insertStmtBindParamBatch(pStmt, bind, -1)); } int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int colIdx) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (bind == NULL || bind->num <= 0 || bind->num > INT16_MAX) { tscError("0x%"PRIx64" invalid parameter", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "invalid bind param")); } if (!pStmt->isInsert) { tscError("0x%"PRIx64" not or invalid batch insert", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not or invalid batch insert")); } if (pStmt->multiTbInsert) { if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_BIND_COL) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } else { if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_BIND_COL && pStmt->last != STMT_EXECUTE) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } pStmt->last = STMT_BIND_COL; - return insertStmtBindParamBatch(pStmt, bind, colIdx); + STMT_RET(insertStmtBindParamBatch(pStmt, bind, colIdx)); } @@ -1746,44 +1767,42 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, in int taos_stmt_add_batch(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { if (pStmt->last != STMT_BIND && pStmt->last != STMT_BIND_COL) { tscError("0x%"PRIx64" add batch status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "add batch status error")); } pStmt->last = STMT_ADD_BATCH; - return insertStmtAddBatch(pStmt); + STMT_RET(insertStmtAddBatch(pStmt)); } - return TSDB_CODE_COM_OPS_NOT_SUPPORT; + STMT_RET(TSDB_CODE_COM_OPS_NOT_SUPPORT); } int taos_stmt_reset(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; if (pStmt->isInsert) { - return insertStmtReset(pStmt); + STMT_RET(insertStmtReset(pStmt)); } - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } int taos_stmt_execute(TAOS_STMT* stmt) { int ret = 0; STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { if (pStmt->last != STMT_ADD_BATCH) { tscError("0x%"PRIx64" exec status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "exec status error")); } pStmt->last = STMT_EXECUTE; @@ -1809,7 +1828,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { } } - return ret; + STMT_RET(ret); } TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) { @@ -1833,32 +1852,30 @@ int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (insert) *insert = pStmt->isInsert; - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { SSqlObj* pSql = pStmt->pSql; SSqlCmd *pCmd = &pSql->cmd; *nums = pCmd->insertParam.numOfParams; - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } else { SNormalStmt* normal = &pStmt->normal; *nums = normal->numParams; - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } } @@ -1866,8 +1883,7 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { @@ -1884,24 +1900,37 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) { tscGetDataBlockFromList(pCmd->insertParam.pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, sizeof(SSubmitBlk), pTableMeta->tableInfo.rowSize, &pTableMetaInfo->name, pTableMeta, &pBlock, NULL); if (ret != 0) { - // todo handle error + STMT_RET(ret); } if (idx<0 || idx>=pBlock->numOfParams) { tscError("0x%"PRIx64" param %d: out of range", pStmt->pSql->self, idx); - abort(); + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "idx out of range")); } SParamInfo* param = &pBlock->params[idx]; if (type) *type = param->type; if (bytes) *bytes = param->bytes; - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } else { - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(TSDB_CODE_COM_OPS_NOT_SUPPORT); + } +} + + +char *taos_stmt_errstr(TAOS_STMT *stmt) { + STscStmt* pStmt = (STscStmt*)stmt; + + if (stmt == NULL) { + return (char*) tstrerror(terrno); } + + return taos_errstr(pStmt->pSql); } + + const char *taos_data_type(int type) { switch (type) { case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL"; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 35c737d5e441e581beb602a028da2fcefa018471..17752e5e4d0b06528f61f7ac33bb068b64528c0b 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -63,6 +63,9 @@ static SExprInfo* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int3 static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo); static char* getAccountId(SSqlObj* pSql); +static bool serializeExprListToVariant(SArray* pList, tVariant **dest, int16_t colType); +static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType); + static bool has(SArray* pFieldList, int32_t startIdx, const char* name); static char* cloneCurrentDBName(SSqlObj* pSql); static int32_t getDelimiterIndex(SStrToken* pTableName); @@ -119,7 +122,7 @@ static int32_t getColumnIndexByName(SSqlCmd* pCmd, const SStrToken* pToken, SQue static int32_t getTableIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex); static int32_t getTableIndexImpl(SStrToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex); -static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); +static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* msg); static int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode); static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate); @@ -134,14 +137,97 @@ static bool validateDebugFlag(int32_t v); static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); static int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo); -static bool isTimeWindowQuery(SQueryInfo* pQueryInfo) { +static bool isTimeWindowQuery(SQueryInfo* pQueryInfo) { return pQueryInfo->interval.interval > 0 || pQueryInfo->sessionWindow.gap > 0; } + int16_t getNewResColId(SSqlCmd* pCmd) { return pCmd->resColumnId--; } +// serialize expr in exprlist to binary +// formate "type | size | value" +bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType) { + bool ret = false; + if (!pList || pList->size <= 0) { + return ret; + } + if (colType == TSDB_DATA_TYPE_DOUBLE || colType == TSDB_DATA_TYPE_FLOAT) { + return ret; + } + + tSqlExprItem* item = (tSqlExprItem *)taosArrayGet(pList, 0); + int32_t firstTokenType = item->pNode->token.type; + int32_t type = firstTokenType; + + //nchar to binary and + toTSDBType(type); + if (type != colType && (type != TSDB_DATA_TYPE_BINARY || colType != TSDB_DATA_TYPE_NCHAR)) { + return false; + } + type = colType; + + SBufferWriter bw = tbufInitWriter( NULL, false ); + tbufEnsureCapacity(&bw, 512); + + int32_t size = (int32_t)(pList->size); + tbufWriteUint32(&bw, type); + tbufWriteInt32(&bw, size); + + for (int32_t i = 0; i < size; i++) { + tSqlExpr* pSub = ((tSqlExprItem*)(taosArrayGet(pList, i)))->pNode; + + // check all the token type in expr list same or not + if (firstTokenType != pSub->token.type) { + break; + } + + toTSDBType(pSub->token.type); + + tVariant var; + tVariantCreate(&var, &pSub->token); + if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT + || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { + tbufWriteInt64(&bw, var.i64); + } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) { + tbufWriteDouble(&bw, var.dKey); + } else if (type == TSDB_DATA_TYPE_BINARY){ + tbufWriteBinary(&bw, var.pz, var.nLen); + } else if (type == TSDB_DATA_TYPE_NCHAR) { + char *buf = (char *)calloc(1, (var.nLen + 1)*TSDB_NCHAR_SIZE); + if (tVariantDump(&var, buf, type, false) != TSDB_CODE_SUCCESS) { + free(buf); + tVariantDestroy(&var); + break; + } + tbufWriteBinary(&bw, buf, twcslen((wchar_t *)buf) * TSDB_NCHAR_SIZE); + free(buf); + } + tVariantDestroy(&var); + + if (i == size - 1) { ret = true;} + } + + if (ret == true) { + if ((*dst = calloc(1, sizeof(tVariant))) != NULL) { + tVariantCreateFromBinary(*dst, tbufGetData(&bw, false), tbufTell(&bw), TSDB_DATA_TYPE_BINARY); + } else { + ret = false; + } + } + tbufCloseWriter(&bw); + return ret; +} + +static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType) { + if (pVar->nType != TSDB_DATA_TYPE_BINARY) { + return -1; + } + SBufferReader br = tbufInitReader(pVar->pz, pVar->nLen, false); + return colType == TSDB_DATA_TYPE_NCHAR ? 0 : (tbufReadUint32(&br) == colType ? 0: -1); +} + static uint8_t convertOptr(SStrToken *pToken) { switch (pToken->type) { case TK_LT: @@ -162,6 +248,7 @@ static uint8_t convertOptr(SStrToken *pToken) { return TSDB_RELATION_EQUAL; case TK_PLUS: return TSDB_BINARY_OP_ADD; + case TK_MINUS: return TSDB_BINARY_OP_SUBTRACT; case TK_STAR: @@ -177,6 +264,8 @@ static uint8_t convertOptr(SStrToken *pToken) { return TSDB_RELATION_ISNULL; case TK_NOTNULL: return TSDB_RELATION_NOTNULL; + case TK_IN: + return TSDB_RELATION_IN; default: { return 0; } } } @@ -2068,7 +2157,9 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col const char* msg6 = "function applied to tags not allowed"; const char* msg7 = "normal table can not apply this function"; const char* msg8 = "multi-columns selection does not support alias column name"; - const char* msg9 = "diff can no be applied to unsigned numeric type"; + const char* msg9 = "diff/derivative can no be applied to unsigned numeric type"; + const char* msg10 = "derivative duration should be greater than 1 Second"; + const char* msg11 = "third parameter in derivative should be 0 or 1"; switch (functionId) { case TSDB_FUNC_COUNT: { @@ -2157,11 +2248,14 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col case TSDB_FUNC_MIN: case TSDB_FUNC_MAX: case TSDB_FUNC_DIFF: + case TSDB_FUNC_DERIVATIVE: case TSDB_FUNC_STDDEV: case TSDB_FUNC_LEASTSQR: { // 1. valid the number of parameters - if (pItem->pNode->pParam == NULL || (functionId != TSDB_FUNC_LEASTSQR && taosArrayGetSize(pItem->pNode->pParam) != 1) || - (functionId == TSDB_FUNC_LEASTSQR && taosArrayGetSize(pItem->pNode->pParam) != 3)) { + int32_t numOfParams = (pItem->pNode->pParam == NULL)? 0: (int32_t) taosArrayGetSize(pItem->pNode->pParam); + if (pItem->pNode->pParam == NULL || + (functionId != TSDB_FUNC_LEASTSQR && functionId != TSDB_FUNC_DERIVATIVE && numOfParams != 1) || + ((functionId == TSDB_FUNC_LEASTSQR || functionId == TSDB_FUNC_DERIVATIVE) && numOfParams != 3)) { /* no parameters or more than one parameter for function */ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } @@ -2182,11 +2276,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col // 2. check if sql function can be applied on this column data type pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); + STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta); + SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex); if (!IS_NUMERIC_TYPE(pSchema->type)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); - } else if (IS_UNSIGNED_NUMERIC_TYPE(pSchema->type) && functionId == TSDB_FUNC_DIFF) { + } else if (IS_UNSIGNED_NUMERIC_TYPE(pSchema->type) && (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9); } @@ -2200,11 +2296,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col } // set the first column ts for diff query - if (functionId == TSDB_FUNC_DIFF) { + if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) { colIndex += 1; SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0}; - SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, - getNewResColId(pCmd), TSDB_KEYSIZE, false); + SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, + TSDB_KEYSIZE, getNewResColId(pCmd), TSDB_KEYSIZE, false); SColumnList ids = createColumnList(1, 0, 0); insertResultField(pQueryInfo, 0, &ids, TSDB_KEYSIZE, TSDB_DATA_TYPE_TIMESTAMP, aAggs[TSDB_FUNC_TS_DUMMY].name, pExpr); @@ -2215,7 +2311,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } - SExprInfo* pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), resultSize, false); + SExprInfo* pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), intermediateResSize, false); if (functionId == TSDB_FUNC_LEASTSQR) { // set the leastsquares parameters char val[8] = {0}; @@ -2230,12 +2326,39 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return TSDB_CODE_TSC_INVALID_OPERATION; } - tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); + tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES); } else if (functionId == TSDB_FUNC_IRATE) { - STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta); int64_t prec = info.precision; - tscExprAddParams(&pExpr->base, (char*)&prec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); + } else if (functionId == TSDB_FUNC_DERIVATIVE) { + char val[8] = {0}; + + int64_t tickPerSec = 0; + if (tVariantDump(&pParamElem[1].pNode->value, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, true) < 0) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + if (info.precision == TSDB_TIME_PRECISION_MILLI) { + tickPerSec /= 1000; + } + + if (tickPerSec <= 0 || tickPerSec < TSDB_TICK_PER_SECOND(info.precision)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10); + } + + tscExprAddParams(&pExpr->base, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); + memset(val, 0, tListLen(val)); + + if (tVariantDump(&pParamElem[2].pNode->value, val, TSDB_DATA_TYPE_BIGINT, true) < 0) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + int64_t v = *(int64_t*) val; + if (v != 0 && v != 1) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg11); + } + + tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); } SColumnList ids = createColumnList(1, index.tableIndex, index.columnIndex); @@ -2935,8 +3058,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) { } bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { - const char* msg1 = "TWA not allowed to apply to super table directly"; - const char* msg2 = "TWA only support group by tbname for super table query"; + 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* msg3 = "function not support for super table query"; // filter sql function not supported by metric query yet. @@ -2949,7 +3072,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) } } - if (tscIsTWAQuery(pQueryInfo)) { + if (tscIsTWAQuery(pQueryInfo) || tscIsDiffQuery(pQueryInfo)) { if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return true; @@ -3207,6 +3330,25 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, retVal = tVariantDump(&pRight->value, (char*)&pColumnFilter->upperBndd, colType, false); // TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd + } else if (pExpr->tokenId == TK_IN) { + tVariant *pVal; + if (pRight->tokenId != TK_SET || !serializeExprListToVariant(pRight->pParam, &pVal, colType) || colType == TSDB_DATA_TYPE_TIMESTAMP) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + } + if (validateParamOfRelationIn(pVal, colType) != TSDB_CODE_SUCCESS) { + tVariantDestroy(pVal); + free(pVal); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + } + pColumnFilter->pz = (int64_t)calloc(1, pVal->nLen + 1); + pColumnFilter->len = pVal->nLen; + pColumnFilter->filterstr = 1; + memcpy((char *)(pColumnFilter->pz), (char *)(pVal->pz), pVal->nLen); + //retVal = tVariantDump(pVal, (char *)(pColumnFilter->pz), TSDB_DATA_TYPE_BINARY, false); + + tVariantDestroy(pVal); + free(pVal); + } else if (colType == TSDB_DATA_TYPE_BINARY) { pColumnFilter->pz = (int64_t)calloc(1, bufLen * TSDB_NCHAR_SIZE); pColumnFilter->len = pRight->value.nLen; @@ -3255,6 +3397,9 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, case TK_NOTNULL: pColumnFilter->lowerRelOptr = TSDB_RELATION_NOTNULL; break; + case TK_IN: + pColumnFilter->lowerRelOptr = TSDB_RELATION_IN; + break; default: return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } @@ -3370,7 +3515,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC && pExpr->tokenId != TK_ISNULL && pExpr->tokenId != TK_NOTNULL && pExpr->tokenId != TK_LIKE - ) { + && pExpr->tokenId != TK_IN) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } } else { @@ -3380,7 +3525,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC if (pSchema->type == TSDB_DATA_TYPE_BOOL) { int32_t t = pExpr->tokenId; - if (t != TK_EQ && t != TK_NE && t != TK_NOTNULL && t != TK_ISNULL) { + if (t != TK_EQ && t != TK_NE && t != TK_NOTNULL && t != TK_ISNULL && t != TK_IN) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } } @@ -4422,7 +4567,11 @@ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) { free(tmp); } else { double tmp; - retVal = tVariantDump(vVariant, (char*)&tmp, schemaType, false); + if (p->_node.optr == TSDB_RELATION_IN) { + retVal = validateParamOfRelationIn(vVariant, schemaType); + } else { + retVal = tVariantDump(vVariant, (char*)&tmp, schemaType, false); + } } if (retVal != TSDB_CODE_SUCCESS) { @@ -5508,7 +5657,7 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { bool isProjectionFunction = false; - const char* msg1 = "column projection is not compatible with interval"; + const char* msg1 = "functions not compatible with interval"; // multi-output set/ todo refactor size_t size = taosArrayGetSize(pQueryInfo->exprList); @@ -5532,8 +5681,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu } } - if ((pExpr->base.functionId == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || pExpr->base.functionId == TSDB_FUNC_DIFF || - pExpr->base.functionId == TSDB_FUNC_ARITHM) { + int32_t f = pExpr->base.functionId; + if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ARITHM || f == TSDB_FUNC_DERIVATIVE) { isProjectionFunction = true; } } @@ -6121,7 +6270,7 @@ static void updateTagPrjFunction(SQueryInfo* pQueryInfo) { * 2. if selectivity function and tagprj function both exist, there should be only * one selectivity function exists. */ -static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) { +static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { const char* msg1 = "only one selectivity function allowed in presence of tags function"; const char* msg3 = "aggregation function should not be mixed up with projection"; @@ -6148,6 +6297,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) continue; } + if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) { numOfSelectivity++; } else { @@ -6159,7 +6309,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) // When the tag projection function on tag column that is not in the group by clause, aggregation function and // selectivity function exist in select clause is not allowed. if (numOfAggregation > 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + return invalidOperationMsg(msg, msg1); } /* @@ -6188,7 +6338,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) (functionId == TSDB_FUNC_LAST_DST && (pExpr->base.colInfo.flag & TSDB_COL_NULL) != 0)) { // do nothing } else { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + return invalidOperationMsg(msg, msg1); } } @@ -6201,7 +6351,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) } else { if ((pQueryInfo->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0) { if (numOfAggregation > 0 && pQueryInfo->groupbyExpr.numOfGroupCols == 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + return invalidOperationMsg(msg, msg3); } if (numOfAggregation > 0 || numOfSelectivity > 0) { @@ -6311,7 +6461,7 @@ static int32_t doTagFunctionCheck(SQueryInfo* pQueryInfo) { return (tableCounting && tagProjection)? -1:0; } -int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { +int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* msg) { const char* msg1 = "functions/columns not allowed in group by query"; const char* msg2 = "projection query on columns not allowed"; const char* msg3 = "group by/session/state_window not allowed on projection query"; @@ -6321,17 +6471,17 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { // only retrieve tags, group by is not supportted if (tscQueryTags(pQueryInfo)) { if (doTagFunctionCheck(pQueryInfo) != TSDB_CODE_SUCCESS) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); + return invalidOperationMsg(msg, msg5); } if (pQueryInfo->groupbyExpr.numOfGroupCols > 0 || isTimeWindowQuery(pQueryInfo)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + return invalidOperationMsg(msg, msg4); } else { return TSDB_CODE_SUCCESS; } } if (tscIsProjectionQuery(pQueryInfo) && tscIsSessionWindowQuery(pQueryInfo)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + return invalidOperationMsg(msg, msg3); } if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { @@ -6339,6 +6489,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { if (onlyTagPrjFunction(pQueryInfo) && allTagPrjInGroupby(pQueryInfo)) { // It is a groupby aggregate query, the tag project function is not suitable for this case. updateTagPrjFunction(pQueryInfo); + return doAddGroupbyColumnsOnDemand(pCmd, pQueryInfo); } @@ -6363,21 +6514,21 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { } if (!qualified) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + return invalidOperationMsg(msg, msg2); } } if (IS_MULTIOUTPUT(aAggs[functId].status) && functId != TSDB_FUNC_TOP && functId != TSDB_FUNC_BOTTOM && - functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_PRJ) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + functId != TSDB_FUNC_DIFF && functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_PRJ) { + return invalidOperationMsg(msg, msg1); } if (functId == TSDB_FUNC_COUNT && pExpr->base.colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + return invalidOperationMsg(msg, msg1); } } - if (checkUpdateTagPrjFunctions(pQueryInfo, pCmd) != TSDB_CODE_SUCCESS) { + if (checkUpdateTagPrjFunctions(pQueryInfo, msg) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -6387,12 +6538,12 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { // projection query on super table does not compatible with "group by" syntax if (tscIsProjectionQuery(pQueryInfo)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + return invalidOperationMsg(msg, msg3); } return TSDB_CODE_SUCCESS; } else { - return checkUpdateTagPrjFunctions(pQueryInfo, pCmd); + return checkUpdateTagPrjFunctions(pQueryInfo, msg); } } int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode) { @@ -6478,6 +6629,13 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } + int32_t blocks = ntohl(pCreate->totalBlocks); + if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) { + snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks, + TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + } + if (pCreate->quorum != -1 && (pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) { snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum, @@ -6850,7 +7008,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { const char* msg6 = "from missing in subclause"; const char* msg7 = "time interval is required"; const char* msg8 = "the first column should be primary timestamp column"; - + SSqlCmd* pCmd = &pSql->cmd; SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); assert(pQueryInfo->numOfTables == 1); @@ -7644,7 +7802,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf if (validateIntervalNode(pSql, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } else { - if (isTimeWindowQuery(pQueryInfo)) { + if (isTimeWindowQuery(pQueryInfo) || pQueryInfo->sessionWindow.gap > 0) { // check if the first column of the nest query result is timestamp column SColumn* pCol = taosArrayGetP(pQueryInfo->colList, 0); if (pCol->info.type != TSDB_DATA_TYPE_TIMESTAMP) { @@ -7659,10 +7817,13 @@ 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) { + if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } + + if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo, tscGetErrorMsgPayload(pCmd))) != TSDB_CODE_SUCCESS) { + return code; + } } else { pQueryInfo->command = TSDB_SQL_SELECT; @@ -7727,11 +7888,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf // set interval value if (validateIntervalNode(pSql, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; - } else { - if (isTimeWindowQuery(pQueryInfo) && - (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } } if (tscQueryTags(pQueryInfo)) { @@ -7762,6 +7918,11 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf return TSDB_CODE_TSC_INVALID_OPERATION; } + if ((isTimeWindowQuery(pQueryInfo) || pQueryInfo->sessionWindow.gap > 0) && + (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS)) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + if (isSTable) { tscTansformFuncForSTableQuery(pQueryInfo); if (hasUnsupportFunctionsForSTableQuery(pCmd, pQueryInfo)) { @@ -7791,7 +7952,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf return code; } - if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo)) != TSDB_CODE_SUCCESS) { + if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo,tscGetErrorMsgPayload(pCmd))) != TSDB_CODE_SUCCESS) { return code; } @@ -7804,14 +7965,15 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } { // set the query info - pQueryInfo->projectionQuery = tscIsProjectionQuery(pQueryInfo); - pQueryInfo->hasFilter = tscHasColumnFilter(pQueryInfo); - pQueryInfo->simpleAgg = isSimpleAggregateRv(pQueryInfo); - pQueryInfo->onlyTagQuery = onlyTagPrjFunction(pQueryInfo); - pQueryInfo->groupbyColumn = tscGroupbyColumn(pQueryInfo); + pQueryInfo->projectionQuery = tscIsProjectionQuery(pQueryInfo); + pQueryInfo->hasFilter = tscHasColumnFilter(pQueryInfo); + pQueryInfo->simpleAgg = isSimpleAggregateRv(pQueryInfo); + pQueryInfo->onlyTagQuery = onlyTagPrjFunction(pQueryInfo); + pQueryInfo->groupbyColumn = tscGroupbyColumn(pQueryInfo); - pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo); + pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo); pQueryInfo->orderProjectQuery = tscOrderedProjectionQueryOnSTable(pQueryInfo, 0); + pQueryInfo->diffQuery = tscIsDiffQuery(pQueryInfo); SExprInfo** p = NULL; int32_t numOfExpr = 0; @@ -7922,6 +8084,24 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS } return TSDB_CODE_SUCCESS; + } else if (pSqlExpr->tokenId == TK_SET) { + int32_t type = -1; + STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; + if (pCols != NULL) { + SColIndex* idx = taosArrayGet(pCols, 0); + SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); + if (pSchema != NULL) { + type = pSchema->type; + } + } + + tVariant *pVal; + if (serializeExprListToVariant(pSqlExpr->pParam, &pVal, type) == false) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression"); + } + *pExpr = calloc(1, sizeof(tExprNode)); + (*pExpr)->nodeType = TSQL_NODE_VALUE; + (*pExpr)->pVal = pVal; } else { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression"); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index f997d487d1687ec41385651160bc7146019724ec..b4c7a64fd0e566bd323d9c5f44507f849900b9c7 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -912,7 +912,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } SGroupbyExpr *pGroupbyExpr = query.pGroupbyExpr; - if (pGroupbyExpr->numOfGroupCols > 0) { + if (pGroupbyExpr != NULL && pGroupbyExpr->numOfGroupCols > 0) { pQueryMsg->orderByIdx = htons(pGroupbyExpr->orderIndex); pQueryMsg->orderType = htons(pGroupbyExpr->orderType); @@ -1588,7 +1588,7 @@ int tscProcessLocalRetrieveRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder(pSql, numOfRes); } -int tscProcessRetrieveLocalMergeRsp(SSqlObj *pSql) { +int tscProcessRetrieveGlobalMergeRsp(SSqlObj *pSql) { SSqlRes *pRes = &pSql->res; SSqlCmd* pCmd = &pSql->cmd; @@ -1615,12 +1615,13 @@ int tscProcessRetrieveLocalMergeRsp(SSqlObj *pSql) { taosArrayPush(group, &tableKeyInfo); taosArrayPush(tableGroupInfo.pGroupList, &group); - pQueryInfo->pQInfo = createQInfoFromQueryNode(pQueryInfo, &tableGroupInfo, NULL, NULL, pRes->pMerger, MERGE_STAGE); + tscDebug("0x%"PRIx64" create QInfo 0x%"PRIx64" to execute query processing", pSql->self, pSql->self); + pQueryInfo->pQInfo = createQInfoFromQueryNode(pQueryInfo, &tableGroupInfo, NULL, NULL, pRes->pMerger, MERGE_STAGE, pSql->self); } - uint64_t localQueryId = 0; + uint64_t localQueryId = pSql->self; qTableQuery(pQueryInfo->pQInfo, &localQueryId); - convertQueryResult(pRes, pQueryInfo); + convertQueryResult(pRes, pQueryInfo, pSql->self); code = pRes->code; if (pRes->code == TSDB_CODE_SUCCESS) { @@ -2689,7 +2690,7 @@ void tscInitMsgsFp() { tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; - tscProcessMsgRsp[TSDB_SQL_RETRIEVE_LOCALMERGE] = tscProcessRetrieveLocalMergeRsp; + tscProcessMsgRsp[TSDB_SQL_RETRIEVE_GLOBALMERGE] = tscProcessRetrieveGlobalMergeRsp; tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp; tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 554ce351eb05a3196a08a79c3b3067df6de6aab8..1e9389287674996b63ff3a7cc2d8ece81d4bc130 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -456,7 +456,7 @@ static bool needToFetchNewBlock(SSqlObj* pSql) { return (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) && (pCmd->command == TSDB_SQL_RETRIEVE || - pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE || + pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE || pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE || pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_SHOW || diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 2f32e775d66e3c3e1cf45b1437f3fa82278346a6..49ce73854520aa95249d9f42590acd36d83bb523 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1977,9 +1977,8 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) { } memset(pSql->subState.states, 0, sizeof(*pSql->subState.states) * pSql->subState.numOfSub); - tscDebug("0x%"PRIx64" reset all sub states to 0", pSql->self); + tscDebug("0x%"PRIx64" reset all sub states to 0, start subquery, total:%d", pSql->self, pQueryInfo->numOfTables); - tscDebug("0x%"PRIx64" start subquery, total:%d", pSql->self, pQueryInfo->numOfTables); for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, i); if (pSupporter == NULL) { // failed to create support struct, abort current query @@ -2424,7 +2423,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { // pRes->code check only serves in launching metric sub-queries if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) { - pCmd->command = TSDB_SQL_RETRIEVE_LOCALMERGE; // enable the abort of kill super table function. + pCmd->command = TSDB_SQL_RETRIEVE_GLOBALMERGE; // enable the abort of kill super table function. return pRes->code; } @@ -2780,7 +2779,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p if (code == TSDB_CODE_SUCCESS && trsupport->pExtMemBuffer == NULL) { pParentSql->cmd.command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; // no result, set the result empty } else { - pParentSql->cmd.command = TSDB_SQL_RETRIEVE_LOCALMERGE; + pParentSql->cmd.command = TSDB_SQL_RETRIEVE_GLOBALMERGE; } tscCreateResPointerInfo(&pParentSql->res, pPQueryInfo); @@ -3502,7 +3501,7 @@ static UNUSED_FUNC bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) { } void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pSourceOperator, - char* sql, void* merger, int32_t stage) { + char* sql, void* merger, int32_t stage, uint64_t qId) { assert(pQueryInfo != NULL); SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo)); if (pQInfo == NULL) { @@ -3511,7 +3510,7 @@ void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGr // to make sure third party won't overwrite this structure pQInfo->signature = pQInfo; - + pQInfo->qId = qId; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryAttr *pQueryAttr = &pQInfo->query; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index b5dfc956ddd31a141c009bbf8200299cd82c607f..60919c98b5ae1d1ebc4d229b2023d679c87c1118 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -222,6 +222,8 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM && functionId != TSDB_FUNC_TS_COMP && + functionId != TSDB_FUNC_DIFF && + functionId != TSDB_FUNC_TS_DUMMY && functionId != TSDB_FUNC_TID_TAG) { return false; } @@ -434,6 +436,23 @@ 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); + if (pExpr == NULL || pExpr->base.functionId == TSDB_FUNC_TS_DUMMY) { + continue; + } + + if (pExpr->base.functionId == TSDB_FUNC_DIFF) { + return true; + } + } + + return false; +} + bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo) { return pQueryInfo->sessionWindow.gap > 0; } @@ -467,42 +486,12 @@ bool tscNeedReverseScan(SQueryInfo* pQueryInfo) { return false; } -bool isSimpleAggregate(SQueryInfo* pQueryInfo) { - if (pQueryInfo->interval.interval > 0) { - return false; - } - - // Note:top/bottom query is fixed output query - if (tscIsTopBotQuery(pQueryInfo) || tscGroupbyColumn(pQueryInfo) || isTsCompQuery(pQueryInfo)) { - return true; - } - - size_t numOfExprs = tscNumOfExprs(pQueryInfo); - for (int32_t i = 0; i < numOfExprs; ++i) { - SExprInfo* pExpr = tscExprGet(pQueryInfo, i); - if (pExpr == NULL) { - continue; - } - - int32_t functionId = pExpr->base.functionId; - if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY) { - continue; - } - - if (!IS_MULTIOUTPUT(aAggs[functionId].status)) { - return true; - } - } - - return false; -} - bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) { if (pQueryInfo->interval.interval > 0 || pQueryInfo->sessionWindow.gap > 0) { return false; } - if (tscGroupbyColumn(pQueryInfo) || isTsCompQuery(pQueryInfo)) { + if (tscIsDiffQuery(pQueryInfo)) { return false; } @@ -518,13 +507,13 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) { continue; } - if (!IS_MULTIOUTPUT(aAggs[functionId].status)) { + if ((!IS_MULTIOUTPUT(aAggs[functionId].status)) || + (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_TS_COMP)) { return true; } } return false; - } bool isBlockDistQuery(SQueryInfo* pQueryInfo) { @@ -812,6 +801,7 @@ static void fetchNextBlockIfCompleted(SOperatorInfo* pOperator, bool* newgroup) for (int32_t i = 0; i < pOperator->numOfUpstream; ++i) { SJoinStatus* pStatus = &pJoinInfo->status[i]; if (pStatus->pBlock == NULL || pStatus->index >= pStatus->pBlock->info.rows) { + tscDebug("Retrieve nest query result, index:%d, total:%d", i, pOperator->numOfUpstream); pStatus->pBlock = pOperator->upstream[i]->exec(pOperator->upstream[i], newgroup); pStatus->index = 0; @@ -972,6 +962,9 @@ static void destroyDummyInputOperator(void* param, int32_t numOfOutput) { pInfo->block = destroyOutputBuf(pInfo->block); pInfo->pSql = NULL; + + cleanupResultRowInfo(&pInfo->pTableQueryInfo->resInfo); + tfree(pInfo->pTableQueryInfo); } // todo this operator servers as the adapter for Operator tree and SqlRes result, remove it later @@ -1056,7 +1049,7 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pUpstream, int32_t numOfUp return pOperator; } -void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo) { +void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId) { // set the correct result SSDataBlock* p = pQueryInfo->pQInfo->runtimeEnv.outputBuf; pRes->numOfRows = (p != NULL)? p->info.rows: 0; @@ -1066,6 +1059,7 @@ void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo) { tscSetResRawPtrRv(pRes, pQueryInfo, p); } + tscDebug("0x%"PRIx64" retrieve result in pRes, numOfRows:%d", objId, pRes->numOfRows); pRes->row = 0; pRes->completed = (pRes->numOfRows == 0); } @@ -1088,7 +1082,9 @@ static void createInputDataFilterInfo(SQueryInfo* px, int32_t numOfCol1, int32_t tfree(tableCols); } -void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQueryInfo* px, SSqlRes* pOutput) { +void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQueryInfo* px, SSqlObj* pSql) { + SSqlRes* pOutput = &pSql->res; + // handle the following query process if (px->pQInfo == NULL) { SColumnInfo* pColumnInfo = extractColumnInfoFromResult(px->colList); @@ -1168,7 +1164,9 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue } } - px->pQInfo = createQInfoFromQueryNode(px, &tableGroupInfo, pSourceOperator, NULL, NULL, MASTER_SCAN); + tscDebug("0x%"PRIx64" create QInfo 0x%"PRIx64" to execute the main query while all nest queries are ready", pSql->self, pSql->self); + px->pQInfo = createQInfoFromQueryNode(px, &tableGroupInfo, pSourceOperator, NULL, NULL, MASTER_SCAN, pSql->self); + tfree(pColumnInfo); tfree(schema); @@ -1176,9 +1174,9 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue pSourceOperator->pRuntimeEnv = &px->pQInfo->runtimeEnv; } - uint64_t qId = 0; + uint64_t qId = pSql->self; qTableQuery(px->pQInfo, &qId); - convertQueryResult(pOutput, px); + convertQueryResult(pOutput, px, pSql->self); } static void tscDestroyResPointerInfo(SSqlRes* pRes) { @@ -1374,7 +1372,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { SSqlCmd* pCmd = &pSql->cmd; int32_t cmd = pCmd->command; - if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_LOCALMERGE || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT || + if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_GLOBALMERGE || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT || cmd == TSDB_SQL_TABLE_JOIN_RETRIEVE) { tscRemoveFromSqlList(pSql); } @@ -2177,6 +2175,7 @@ size_t tscNumOfExprs(SQueryInfo* pQueryInfo) { return taosArrayGetSize(pQueryInfo->exprList); } +// todo REFACTOR void tscExprAddParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes) { assert (pExpr != NULL || argument != NULL || bytes != 0); @@ -3278,7 +3277,6 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t pNewQueryInfo->numOfTables = 0; pNewQueryInfo->pTableMetaInfo = NULL; pNewQueryInfo->bufLen = pQueryInfo->bufLen; - pNewQueryInfo->buf = malloc(pQueryInfo->bufLen); if (pNewQueryInfo->buf == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -3438,7 +3436,7 @@ void doRetrieveSubqueryData(SSchedMsg *pMsg) { } SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd); - handleDownstreamOperator(pSql->pSubs, pSql->subState.numOfSub, pQueryInfo, &pSql->res); + handleDownstreamOperator(pSql->pSubs, pSql->subState.numOfSub, pQueryInfo, pSql); pSql->res.qId = -1; if (pSql->res.code == TSDB_CODE_SUCCESS) { @@ -3468,13 +3466,12 @@ static void tscSubqueryRetrieveCallback(void* param, TAOS_RES* tres, int code) { } pParentSql->cmd.active = pParentSql->cmd.pQueryInfo; - - SSchedMsg schedMsg = {0}; - schedMsg.fp = doRetrieveSubqueryData; - schedMsg.ahandle = (void *)pParentSql; - schedMsg.thandle = (void *)1; - schedMsg.msg = 0; - taosScheduleTask(tscQhandle, &schedMsg); + pParentSql->res.qId = -1; + if (pSql->res.code == TSDB_CODE_SUCCESS) { + (*pSql->fp)(pParentSql->param, pParentSql, pParentSql->res.numOfRows); + } else { + tscAsyncResultOnError(pParentSql); + } } // todo handle the failure @@ -4238,7 +4235,8 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->hasTagResults = hasTagValOutput(pQueryInfo); pQueryAttr->stabledev = isStabledev(pQueryInfo); pQueryAttr->tsCompQuery = isTsCompQuery(pQueryInfo); - pQueryAttr->simpleAgg = isSimpleAggregate(pQueryInfo); + pQueryAttr->diffQuery = tscIsDiffQuery(pQueryInfo); + pQueryAttr->simpleAgg = isSimpleAggregateRv(pQueryInfo); pQueryAttr->needReverseScan = tscNeedReverseScan(pQueryInfo); pQueryAttr->stableQuery = QUERY_IS_STABLE_QUERY(pQueryInfo->type); pQueryAttr->groupbyColumn = (!pQueryInfo->stateWindow) && tscGroupbyColumn(pQueryInfo); @@ -4257,7 +4255,6 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->fillType = pQueryInfo->fillType; pQueryAttr->havingNum = pQueryInfo->havingFieldNum; - if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor pQueryAttr->window = pQueryInfo->window; } else { @@ -4269,10 +4266,9 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt STableMetaInfo* pTableMetaInfo = pQueryInfo->pTableMetaInfo[0]; - pQueryAttr->pGroupbyExpr = calloc(1, sizeof(SGroupbyExpr)); - *(pQueryAttr->pGroupbyExpr) = pQueryInfo->groupbyExpr; - if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { + pQueryAttr->pGroupbyExpr = calloc(1, sizeof(SGroupbyExpr)); + *(pQueryAttr->pGroupbyExpr) = pQueryInfo->groupbyExpr; pQueryAttr->pGroupbyExpr->columnInfo = taosArrayDup(pQueryInfo->groupbyExpr.columnInfo); } else { assert(pQueryInfo->groupbyExpr.columnInfo == NULL); @@ -4351,7 +4347,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt return TSDB_CODE_TSC_INVALID_OPERATION; } - if (pQueryAttr->pGroupbyExpr->numOfGroupCols < 0) { + if (pQueryAttr->pGroupbyExpr != NULL && pQueryAttr->pGroupbyExpr->numOfGroupCols < 0) { tscError("%p illegal value of numOfGroupCols in query msg: %d", addr, pQueryInfo->groupbyExpr.numOfGroupCols); return TSDB_CODE_TSC_INVALID_OPERATION; } diff --git a/src/common/inc/tcmdtype.h b/src/common/inc/tcmdtype.h index adf210cfebb15ddc0adcfce2aa85e606f79c44a5..90426519e66682ab9d5fab16a3a38e827a7d97df 100644 --- a/src/common/inc/tcmdtype.h +++ b/src/common/inc/tcmdtype.h @@ -76,7 +76,7 @@ enum { // SQL below for client local TSDB_DEFINE_SQL_TYPE( TSDB_SQL_LOCAL, "local" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DESCRIBE_TABLE, "describe-table" ) - TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_LOCALMERGE, "retrieve-localmerge" ) + TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_GLOBALMERGE, "retrieve-globalmerge" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_TABLE_JOIN_RETRIEVE, "join-retrieve" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW_CREATE_TABLE, "show-create-table") diff --git a/src/common/inc/texpr.h b/src/common/inc/texpr.h index 275dd12fd7ca9f9771592039d846593fa958f240..2e49a69366c2277c98ec32a1d8419c141ddecc0f 100644 --- a/src/common/inc/texpr.h +++ b/src/common/inc/texpr.h @@ -94,6 +94,8 @@ bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order, char *(*cb)(void *, const char*, int32_t)); +void buildFilterSetFromBinary(void **q, const char *buf, int32_t len); + #ifdef __cplusplus } #endif diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index f2dd3890a163ec1e1e25d2ac8b55f23aa9d5a79d..6fa4d68734df6fde94725026bd65b219cc6564ab 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -466,6 +466,32 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { return expr; } +void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) { + SBufferReader br = tbufInitReader(buf, len, false); + uint32_t type = tbufReadUint32(&br); + SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false); + int dummy = -1; + int32_t sz = tbufReadInt32(&br); + for (int32_t i = 0; i < sz; i++) { + if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { + int64_t val = tbufReadInt64(&br); + taosHashPut(pObj, (char *)&val, sizeof(val), &dummy, sizeof(dummy)); + } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) { + double val = tbufReadDouble(&br); + taosHashPut(pObj, (char *)&val, sizeof(val), &dummy, sizeof(dummy)); + } else if (type == TSDB_DATA_TYPE_BINARY) { + size_t t = 0; + const char *val = tbufReadBinary(&br, &t); + taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy)); + } else if (type == TSDB_DATA_TYPE_NCHAR) { + size_t t = 0; + const char *val = tbufReadBinary(&br, &t); + taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy)); + } + } + *q = (void *)pObj; +} + tExprNode* exprdup(tExprNode* pNode) { if (pNode == NULL) { return NULL; diff --git a/src/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt index 61e976cb184d3240bdc8917a5b2e5f3182d55fcc..a04902a422deadf590fa9f6172b1a58c739be19a 100644 --- a/src/connector/jdbc/CMakeLists.txt +++ b/src/connector/jdbc/CMakeLists.txt @@ -8,10 +8,9 @@ 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.30.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 968a9bf470ddde1996467467fa24cfd2fbf355e0..657645d46c00d6b7554c931a6dacca4695e34383 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.30 jar JDBCDriver diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index e350e9738e9a15be58a3d288ddc2af564fbf3fbe..96e17bcd9b0eedc2116c2a8358e46d7b6e696b4e 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.29 + 2.0.30 jar JDBCDriver https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java index 5dcaa77ebd4a15087785a6a9b642b85f160f5287..48811d30a6903c077a9c0fb55176b0bc2ca9ba75 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java @@ -12,6 +12,9 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da private final static int DRIVER_MAJAR_VERSION = 2; private final static int DRIVER_MINOR_VERSION = 0; + private String precision = "ms"; + private String database; + public boolean allProceduresAreCallable() throws SQLException { return false; } @@ -493,102 +496,105 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException; - protected ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types, Connection connection) throws SQLException { - try (Statement stmt = connection.createStatement()) { - if (catalog == null || catalog.isEmpty()) - return null; - - ResultSet databases = stmt.executeQuery("show databases"); - String dbname = null; - while (databases.next()) { - dbname = databases.getString("name"); - if (dbname.equalsIgnoreCase(catalog)) - break; - } - databases.close(); - if (dbname == null) - return null; + private List buildGetTablesColumnMetaDataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT + columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM + columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME + columnMetaDataList.add(buildTableTypeMeta(4)); // 4. TABLE_TYPE + columnMetaDataList.add(buildRemarksMeta(5)); // 5. remarks + columnMetaDataList.add(buildTypeCatMeta(6)); // 6. TYPE_CAT + columnMetaDataList.add(buildTypeSchemaMeta(7)); // 7. TYPE_SCHEM + columnMetaDataList.add(buildTypeNameMeta(8)); // 8. TYPE_NAME + columnMetaDataList.add(buildSelfReferencingColName(9)); // 9. SELF_REFERENCING_COL_NAME + columnMetaDataList.add(buildRefGenerationMeta(10)); // 10. REF_GENERATION + return columnMetaDataList; + } + + private ColumnMetaData buildTypeCatMeta(int colIndex) { + ColumnMetaData col6 = new ColumnMetaData(); + col6.setColIndex(colIndex); + col6.setColName("TYPE_CAT"); + col6.setColType(Types.NCHAR); + return col6; + } + + private ColumnMetaData buildTypeSchemaMeta(int colIndex) { + ColumnMetaData col7 = new ColumnMetaData(); + col7.setColIndex(colIndex); + col7.setColName("TYPE_SCHEM"); + col7.setColType(Types.NCHAR); + return col7; + } + + private ColumnMetaData buildTypeNameMeta(int colIndex) { + ColumnMetaData col8 = new ColumnMetaData(); + col8.setColIndex(colIndex); + col8.setColName("TYPE_NAME"); + col8.setColType(Types.NCHAR); + return col8; + } + + private ColumnMetaData buildSelfReferencingColName(int colIndex) { + ColumnMetaData col9 = new ColumnMetaData(); + col9.setColIndex(colIndex); + col9.setColName("SELF_REFERENCING_COL_NAME"); + col9.setColType(Types.NCHAR); + return col9; + } + + private ColumnMetaData buildRefGenerationMeta(int colIndex) { + ColumnMetaData col10 = new ColumnMetaData(); + col10.setColIndex(colIndex); + col10.setColName("REF_GENERATION"); + col10.setColType(Types.NCHAR); + return col10; + } - stmt.execute("use " + dbname); - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - List columnMetaDataList = new ArrayList<>(); - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(1); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - ColumnMetaData col2 = new ColumnMetaData(); - col2.setColIndex(2); - col2.setColName("TABLE_SCHEM"); - col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col2); - ColumnMetaData col3 = new ColumnMetaData(); - col3.setColIndex(3); - col3.setColName("TABLE_NAME"); - col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col3); - ColumnMetaData col4 = new ColumnMetaData(); - col4.setColIndex(4); - col4.setColName("TABLE_TYPE"); - col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col4); - ColumnMetaData col5 = new ColumnMetaData(); - col5.setColIndex(5); - col5.setColName("REMARKS"); - col5.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col5); - ColumnMetaData col6 = new ColumnMetaData(); - col6.setColIndex(6); - col6.setColName("TYPE_CAT"); - col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col6); - ColumnMetaData col7 = new ColumnMetaData(); - col7.setColIndex(7); - col7.setColName("TYPE_SCHEM"); - col7.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col7); - ColumnMetaData col8 = new ColumnMetaData(); - col8.setColIndex(8); - col8.setColName("TYPE_NAME"); - col8.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col8); - ColumnMetaData col9 = new ColumnMetaData(); - col9.setColIndex(9); - col9.setColName("SELF_REFERENCING_COL_NAME"); - col9.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col9); - ColumnMetaData col10 = new ColumnMetaData(); - col10.setColIndex(10); - col10.setColName("REF_GENERATION"); - col10.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col10); - resultSet.setColumnMetaDataList(columnMetaDataList); + protected ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types, Connection connection) throws SQLException { + if (catalog == null || catalog.isEmpty()) + return null; + if (!isAvailableCatalog(connection, catalog)) + return new EmptyResultSet(); - List rowDataList = new ArrayList<>(); + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + // set column metadata list + resultSet.setColumnMetaDataList(buildGetTablesColumnMetaDataList()); + // set row data + List rowDataList = new ArrayList<>(); + try (Statement stmt = connection.createStatement()) { + stmt.execute("use " + catalog); ResultSet tables = stmt.executeQuery("show tables"); while (tables.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(10); - rowData.setString(0, dbname); //table_cat - rowData.setString(1, null); //TABLE_SCHEM - rowData.setString(2, tables.getString("table_name")); //TABLE_NAME - rowData.setString(3, "TABLE"); //TABLE_TYPE - rowData.setString(4, ""); //REMARKS + rowData.setStringValue(1, catalog); //TABLE_CAT + rowData.setStringValue(2, null); //TABLE_SCHEM + rowData.setStringValue(3, tables.getString("table_name")); //TABLE_NAME + rowData.setStringValue(4, "TABLE"); //TABLE_TYPE + rowData.setStringValue(5, ""); //REMARKS rowDataList.add(rowData); } - ResultSet stables = stmt.executeQuery("show stables"); while (stables.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(10); - rowData.setString(0, dbname); //TABLE_CAT - rowData.setString(1, null); //TABLE_SCHEM - rowData.setString(2, stables.getString("name")); //TABLE_NAME - rowData.setString(3, "TABLE"); //TABLE_TYPE - rowData.setString(4, "STABLE"); //REMARKS + rowData.setStringValue(1, catalog); //TABLE_CAT + rowData.setStringValue(2, null); //TABLE_SCHEM + rowData.setStringValue(3, stables.getString("name")); //TABLE_NAME + rowData.setStringValue(4, "TABLE"); //TABLE_TYPE + rowData.setStringValue(5, "STABLE"); //REMARKS rowDataList.add(rowData); } resultSet.setRowDataList(rowDataList); - return resultSet; } + return resultSet; + } + + private ColumnMetaData buildTableTypeMeta(int colIndex) { + ColumnMetaData col4 = new ColumnMetaData(); + col4.setColIndex(colIndex); + col4.setColName("TABLE_TYPE"); + col4.setColType(Types.NCHAR); + return col4; } public ResultSet getSchemas() throws SQLException { @@ -597,25 +603,24 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da public abstract ResultSet getCatalogs() throws SQLException; + private List buildTableTypesColumnMetadataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableTypeMeta(1)); + return columnMetaDataList; + } + public ResultSet getTableTypes() throws SQLException { DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList<>(); - ColumnMetaData colMetaData = new ColumnMetaData(); - colMetaData.setColIndex(0); - colMetaData.setColName("TABLE_TYPE"); - colMetaData.setColSize(10); - colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(colMetaData); - resultSet.setColumnMetaDataList(columnMetaDataList); + resultSet.setColumnMetaDataList(buildTableTypesColumnMetadataList()); // set up rowDataList List rowDataList = new ArrayList<>(); TSDBResultSetRowData rowData = new TSDBResultSetRowData(1); - rowData.setString(0, "TABLE"); + rowData.setStringValue(1, "TABLE"); rowDataList.add(rowData); rowData = new TSDBResultSetRowData(1); - rowData.setString(0, "STABLE"); + rowData.setStringValue(1, "STABLE"); rowDataList.add(rowData); resultSet.setRowDataList(rowDataList); @@ -625,278 +630,330 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException; protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) { - try (Statement stmt = conn.createStatement()) { - if (catalog == null || catalog.isEmpty()) - return null; - - ResultSet databases = stmt.executeQuery("show databases"); - String dbname = null; - while (databases.next()) { - dbname = databases.getString("name"); - if (dbname.equalsIgnoreCase(catalog)) - break; - } - databases.close(); - if (dbname == null) - return null; + if (catalog == null || catalog.isEmpty()) + return null; + if (!isAvailableCatalog(conn, catalog)) + return new EmptyResultSet(); - stmt.execute("use " + dbname); - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - // set up ColumnMetaDataList - - List columnMetaDataList = new ArrayList<>(); - // TABLE_CAT - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(1); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - // TABLE_SCHEM - ColumnMetaData col2 = new ColumnMetaData(); - col2.setColIndex(2); - col2.setColName("TABLE_SCHEM"); - col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col2); - // TABLE_NAME - ColumnMetaData col3 = new ColumnMetaData(); - col3.setColIndex(3); - col3.setColName("TABLE_NAME"); - col3.setColSize(193); - col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col3); - // COLUMN_NAME - ColumnMetaData col4 = new ColumnMetaData(); - col4.setColIndex(4); - col4.setColName("COLUMN_NAME"); - col4.setColSize(65); - col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col4); - // DATA_TYPE - ColumnMetaData col5 = new ColumnMetaData(); - col5.setColIndex(5); - col5.setColName("DATA_TYPE"); - col5.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col5); - // TYPE_NAME - ColumnMetaData col6 = new ColumnMetaData(); - col6.setColIndex(6); - col6.setColName("TYPE_NAME"); - col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col6); - // COLUMN_SIZE - ColumnMetaData col7 = new ColumnMetaData(); - col7.setColIndex(7); - col7.setColName("COLUMN_SIZE"); - col7.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col7); - // BUFFER_LENGTH, not used - ColumnMetaData col8 = new ColumnMetaData(); - col8.setColIndex(8); - col8.setColName("BUFFER_LENGTH"); - columnMetaDataList.add(col8); - // DECIMAL_DIGITS - ColumnMetaData col9 = new ColumnMetaData(); - col9.setColIndex(9); - col9.setColName("DECIMAL_DIGITS"); - col9.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col9); - // add NUM_PREC_RADIX - ColumnMetaData col10 = new ColumnMetaData(); - col10.setColIndex(10); - col10.setColName("NUM_PREC_RADIX"); - col10.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col10); - // NULLABLE - ColumnMetaData col11 = new ColumnMetaData(); - col11.setColIndex(11); - col11.setColName("NULLABLE"); - col11.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col11); - // REMARKS - ColumnMetaData col12 = new ColumnMetaData(); - col12.setColIndex(12); - col12.setColName("REMARKS"); - col12.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col12); - // COLUMN_DEF - ColumnMetaData col13 = new ColumnMetaData(); - col13.setColIndex(13); - col13.setColName("COLUMN_DEF"); - col13.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col13); - //SQL_DATA_TYPE - ColumnMetaData col14 = new ColumnMetaData(); - col14.setColIndex(14); - col14.setColName("SQL_DATA_TYPE"); - col14.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col14); - //SQL_DATETIME_SUB - ColumnMetaData col15 = new ColumnMetaData(); - col15.setColIndex(15); - col15.setColName("SQL_DATETIME_SUB"); - col15.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col15); - //CHAR_OCTET_LENGTH - ColumnMetaData col16 = new ColumnMetaData(); - col16.setColIndex(16); - col16.setColName("CHAR_OCTET_LENGTH"); - col16.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col16); - //ORDINAL_POSITION - ColumnMetaData col17 = new ColumnMetaData(); - col17.setColIndex(17); - col17.setColName("ORDINAL_POSITION"); - col17.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col17); - // IS_NULLABLE - ColumnMetaData col18 = new ColumnMetaData(); - col18.setColIndex(18); - col18.setColName("IS_NULLABLE"); - col18.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col18); - //SCOPE_CATALOG - ColumnMetaData col19 = new ColumnMetaData(); - col19.setColIndex(19); - col19.setColName("SCOPE_CATALOG"); - col19.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col19); - //SCOPE_SCHEMA - ColumnMetaData col20 = new ColumnMetaData(); - col20.setColIndex(20); - col20.setColName("SCOPE_SCHEMA"); - col20.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col20); - //SCOPE_TABLE - ColumnMetaData col21 = new ColumnMetaData(); - col21.setColIndex(21); - col21.setColName("SCOPE_TABLE"); - col21.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col21); - //SOURCE_DATA_TYPE - ColumnMetaData col22 = new ColumnMetaData(); - col22.setColIndex(22); - col22.setColName("SOURCE_DATA_TYPE"); - col22.setColType(TSDBConstants.TSDB_DATA_TYPE_SMALLINT); - columnMetaDataList.add(col22); - //IS_AUTOINCREMENT - ColumnMetaData col23 = new ColumnMetaData(); - col23.setColIndex(23); - col23.setColName("IS_AUTOINCREMENT"); - col23.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col23); - //IS_GENERATEDCOLUMN - ColumnMetaData col24 = new ColumnMetaData(); - col24.setColIndex(24); - col24.setColName("IS_GENERATEDCOLUMN"); - col24.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col24); - - resultSet.setColumnMetaDataList(columnMetaDataList); - // set up rowDataList - ResultSet rs = stmt.executeQuery("describe " + dbname + "." + tableNamePattern); - List rowDataList = new ArrayList<>(); - int index = 0; + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + // set up ColumnMetaDataList + resultSet.setColumnMetaDataList(buildGetColumnsColumnMetaDataList()); + // set up rowDataList + List rowDataList = new ArrayList<>(); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("describe " + catalog + "." + tableNamePattern); + int rowIndex = 0; while (rs.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(24); // set TABLE_CAT - rowData.setString(0, dbname); + rowData.setStringValue(1, catalog); + // set TABLE_SCHEM + rowData.setStringValue(2, null); // set TABLE_NAME - rowData.setString(2, tableNamePattern); + rowData.setStringValue(3, tableNamePattern); // set COLUMN_NAME - rowData.setString(3, rs.getString("Field")); + rowData.setStringValue(4, rs.getString("Field")); // set DATA_TYPE String typeName = rs.getString("Type"); - rowData.setInt(4, getDataType(typeName)); + rowData.setIntValue(5, TSDBConstants.typeName2JdbcType(typeName)); // set TYPE_NAME - rowData.setString(5, typeName); + rowData.setStringValue(6, typeName); // set COLUMN_SIZE int length = rs.getInt("Length"); - rowData.setInt(6, getColumnSize(typeName, length)); + rowData.setIntValue(7, calculateColumnSize(typeName, precision, length)); + // set BUFFER LENGTH + rowData.setStringValue(8, null); // set DECIMAL_DIGITS - rowData.setInt(8, getDecimalDigits(typeName)); + Integer decimalDigits = calculateDecimalDigits(typeName); + if (decimalDigits != null) { + rowData.setIntValue(9, decimalDigits); + } else { + rowData.setStringValue(9, null); + } // set NUM_PREC_RADIX - rowData.setInt(9, 10); + rowData.setIntValue(10, 10); // set NULLABLE - rowData.setInt(10, getNullable(index, typeName)); + rowData.setIntValue(11, isNullable(rowIndex, typeName)); // set REMARKS - rowData.setString(11, rs.getString("Note")); + String note = rs.getString("Note"); + rowData.setStringValue(12, note.trim().isEmpty() ? null : note); rowDataList.add(rowData); - index++; + rowIndex++; } resultSet.setRowDataList(rowDataList); - return resultSet; - } catch (SQLException e) { e.printStackTrace(); } - return null; + return resultSet; } - protected int getNullable(int index, String typeName) { + private int isNullable(int index, String typeName) { if (index == 0 && "TIMESTAMP".equals(typeName)) return DatabaseMetaData.columnNoNulls; return DatabaseMetaData.columnNullable; } - protected int getColumnSize(String typeName, int length) { + private Integer calculateColumnSize(String typeName, String precisionType, int length) { switch (typeName) { case "TIMESTAMP": - return 23; - default: - return 0; - } - } - - protected int getDecimalDigits(String typeName) { - switch (typeName) { + return precisionType.equals("ms") ? TSDBConstants.TIMESTAMP_MS_PRECISION : TSDBConstants.TIMESTAMP_US_PRECISION; + case "BOOL": + return TSDBConstants.BOOLEAN_PRECISION; + case "TINYINT": + return TSDBConstants.TINYINT_PRECISION; + case "SMALLINT": + return TSDBConstants.SMALLINT_PRECISION; + case "INT": + return TSDBConstants.INT_PRECISION; + case "BIGINT": + return TSDBConstants.BIGINT_PRECISION; case "FLOAT": - return 5; + return TSDBConstants.FLOAT_PRECISION; case "DOUBLE": - return 9; + return TSDBConstants.DOUBLE_PRECISION; + case "NCHAR": + case "BINARY": + return length; default: - return 0; + return null; } } - protected int getDataType(String typeName) { + private Integer calculateDecimalDigits(String typeName) { switch (typeName) { - case "TIMESTAMP": - return Types.TIMESTAMP; + case "TINYINT": + case "SMALLINT": case "INT": - return Types.INTEGER; case "BIGINT": - return Types.BIGINT; - case "FLOAT": - return Types.FLOAT; - case "DOUBLE": - return Types.DOUBLE; - case "BINARY": - return Types.BINARY; - case "SMALLINT": - return Types.SMALLINT; - case "TINYINT": - return Types.TINYINT; - case "BOOL": - return Types.BOOLEAN; - case "NCHAR": - return Types.NCHAR; + return 0; default: - return Types.NULL; + return null; } } - public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) - throws SQLException { + private ColumnMetaData buildTableCatalogMeta(int colIndex) { + ColumnMetaData col1 = new ColumnMetaData(); + col1.setColIndex(colIndex); + col1.setColName("TABLE_CAT"); + col1.setColType(Types.NCHAR); + return col1; + } + + private ColumnMetaData buildTableSchemaMeta(int colIndex) { + ColumnMetaData col2 = new ColumnMetaData(); + col2.setColIndex(colIndex); + col2.setColName("TABLE_SCHEM"); + col2.setColType(Types.NCHAR); + return col2; + } + + private ColumnMetaData buildTableNameMeta(int colIndex) { + ColumnMetaData col3 = new ColumnMetaData(); + col3.setColIndex(colIndex); + col3.setColName("TABLE_NAME"); + col3.setColSize(193); + col3.setColType(Types.NCHAR); + return col3; + } + + private ColumnMetaData buildColumnNameMeta(int colIndex) { + ColumnMetaData col4 = new ColumnMetaData(); + col4.setColIndex(colIndex); + col4.setColName("COLUMN_NAME"); + col4.setColSize(65); + col4.setColType(Types.NCHAR); + return col4; + } + + private ColumnMetaData buildDataTypeMeta(int colIndex) { + ColumnMetaData col5 = new ColumnMetaData(); + col5.setColIndex(colIndex); + col5.setColName("DATA_TYPE"); + col5.setColType(Types.INTEGER); + return col5; + } + + private ColumnMetaData buildColumnSizeMeta() { + ColumnMetaData col7 = new ColumnMetaData(); + col7.setColIndex(7); + col7.setColName("COLUMN_SIZE"); + col7.setColType(Types.INTEGER); + return col7; + } + + private ColumnMetaData buildBufferLengthMeta() { + ColumnMetaData col8 = new ColumnMetaData(); + col8.setColIndex(8); + col8.setColName("BUFFER_LENGTH"); + return col8; + } + + private ColumnMetaData buildDecimalDigitsMeta() { + ColumnMetaData col9 = new ColumnMetaData(); + col9.setColIndex(9); + col9.setColName("DECIMAL_DIGITS"); + col9.setColType(Types.INTEGER); + return col9; + } + + private ColumnMetaData buildNumPrecRadixMeta() { + ColumnMetaData col10 = new ColumnMetaData(); + col10.setColIndex(10); + col10.setColName("NUM_PREC_RADIX"); + col10.setColType(Types.INTEGER); + return col10; + } + + private ColumnMetaData buildNullableMeta() { + ColumnMetaData col11 = new ColumnMetaData(); + col11.setColIndex(11); + col11.setColName("NULLABLE"); + col11.setColType(Types.INTEGER); + return col11; + } + + private ColumnMetaData buildRemarksMeta(int colIndex) { + ColumnMetaData col12 = new ColumnMetaData(); + col12.setColIndex(colIndex); + col12.setColName("REMARKS"); + col12.setColType(Types.NCHAR); + return col12; + } + + private ColumnMetaData buildColumnDefMeta() { + ColumnMetaData col13 = new ColumnMetaData(); + col13.setColIndex(13); + col13.setColName("COLUMN_DEF"); + col13.setColType(Types.NCHAR); + return col13; + } + + private ColumnMetaData buildSqlDataTypeMeta() { + ColumnMetaData col14 = new ColumnMetaData(); + col14.setColIndex(14); + col14.setColName("SQL_DATA_TYPE"); + col14.setColType(Types.INTEGER); + return col14; + } + + private ColumnMetaData buildSqlDatetimeSubMeta() { + ColumnMetaData col15 = new ColumnMetaData(); + col15.setColIndex(15); + col15.setColName("SQL_DATETIME_SUB"); + col15.setColType(Types.INTEGER); + return col15; + } + + private ColumnMetaData buildCharOctetLengthMeta() { + ColumnMetaData col16 = new ColumnMetaData(); + col16.setColIndex(16); + col16.setColName("CHAR_OCTET_LENGTH"); + col16.setColType(Types.INTEGER); + return col16; + } + + private ColumnMetaData buildOrdinalPositionMeta() { + ColumnMetaData col17 = new ColumnMetaData(); + col17.setColIndex(17); + col17.setColName("ORDINAL_POSITION"); + col17.setColType(Types.INTEGER); + return col17; + } + + private ColumnMetaData buildIsNullableMeta() { + ColumnMetaData col18 = new ColumnMetaData(); + col18.setColIndex(18); + col18.setColName("IS_NULLABLE"); + col18.setColType(Types.NCHAR); + return col18; + } + + private ColumnMetaData buildScopeCatalogMeta() { + ColumnMetaData col19 = new ColumnMetaData(); + col19.setColIndex(19); + col19.setColName("SCOPE_CATALOG"); + col19.setColType(Types.NCHAR); + return col19; + } + + private ColumnMetaData buildScopeSchemaMeta() { + ColumnMetaData col20 = new ColumnMetaData(); + col20.setColIndex(20); + col20.setColName("SCOPE_SCHEMA"); + col20.setColType(Types.NCHAR); + return col20; + } + + private ColumnMetaData buildScopeTableMeta() { + ColumnMetaData col21 = new ColumnMetaData(); + col21.setColIndex(21); + col21.setColName("SCOPE_TABLE"); + col21.setColType(Types.NCHAR); + return col21; + } + + private ColumnMetaData buildSourceDataTypeMeta() { + ColumnMetaData col22 = new ColumnMetaData(); + col22.setColIndex(22); + col22.setColName("SOURCE_DATA_TYPE"); + col22.setColType(TSDBConstants.TSDB_DATA_TYPE_SMALLINT); + return col22; + } + + private ColumnMetaData buildIsAutoIncrementMeta() { + ColumnMetaData col23 = new ColumnMetaData(); + col23.setColIndex(23); + col23.setColName("IS_AUTOINCREMENT"); + col23.setColType(Types.NCHAR); + return col23; + } + + private ColumnMetaData buildIsGeneratedColumnMeta() { + ColumnMetaData col24 = new ColumnMetaData(); + col24.setColIndex(24); + col24.setColName("IS_GENERATEDCOLUMN"); + col24.setColType(Types.NCHAR); + return col24; + } + + private List buildGetColumnsColumnMetaDataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); //1. TABLE_CAT + columnMetaDataList.add(buildTableSchemaMeta(2)); //2. TABLE_SCHEMA + columnMetaDataList.add(buildTableNameMeta(3)); //3. TABLE_NAME + columnMetaDataList.add(buildColumnNameMeta(4)); //4. COLUMN_NAME + columnMetaDataList.add(buildDataTypeMeta(5)); //5. DATA_TYPE + columnMetaDataList.add(buildTypeNameMeta(6)); //6. TYPE_NAME + columnMetaDataList.add(buildColumnSizeMeta()); //7. COLUMN_SIZE + columnMetaDataList.add(buildBufferLengthMeta()); //8. BUFFER_LENGTH, not used + columnMetaDataList.add(buildDecimalDigitsMeta()); //9. DECIMAL_DIGITS + columnMetaDataList.add(buildNumPrecRadixMeta()); //10. NUM_PREC_RADIX + columnMetaDataList.add(buildNullableMeta()); //11. NULLABLE + columnMetaDataList.add(buildRemarksMeta(12)); //12. REMARKS + columnMetaDataList.add(buildColumnDefMeta()); //13. COLUMN_DEF + columnMetaDataList.add(buildSqlDataTypeMeta()); //14. SQL_DATA_TYPE + columnMetaDataList.add(buildSqlDatetimeSubMeta()); //15. SQL_DATETIME_SUB + columnMetaDataList.add(buildCharOctetLengthMeta()); //16. CHAR_OCTET_LENGTH + columnMetaDataList.add(buildOrdinalPositionMeta()); //17. ORDINAL_POSITION + columnMetaDataList.add(buildIsNullableMeta()); //18. IS_NULLABLE + columnMetaDataList.add(buildScopeCatalogMeta()); //19. SCOPE_CATALOG + columnMetaDataList.add(buildScopeSchemaMeta()); //20. SCOPE_SCHEMA + columnMetaDataList.add(buildScopeTableMeta()); //21. SCOPE_TABLE + columnMetaDataList.add(buildSourceDataTypeMeta()); //22. SOURCE_DATA_TYPE + columnMetaDataList.add(buildIsAutoIncrementMeta()); //23. IS_AUTOINCREMENT + columnMetaDataList.add(buildIsGeneratedColumnMeta()); //24. IS_GENERATEDCOLUMN + return columnMetaDataList; + } + + public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException { return getEmptyResultSet(); } - public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) - throws SQLException { + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { return getEmptyResultSet(); } - public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) - throws SQLException { + public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException { return getEmptyResultSet(); } @@ -914,8 +971,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return getEmptyResultSet(); } - public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, - String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { + public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { return getEmptyResultSet(); } @@ -923,8 +979,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return getEmptyResultSet(); } - public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) - throws SQLException { + public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException { return getEmptyResultSet(); } @@ -976,8 +1031,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return false; } - public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) - throws SQLException { + public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException { return getEmptyResultSet(); } @@ -1005,8 +1059,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da public abstract ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException; - public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, - String attributeNamePattern) throws SQLException { + public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException { return getEmptyResultSet(); } @@ -1069,18 +1122,15 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return getEmptyResultSet(); } - public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) - throws SQLException { + public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { return getEmptyResultSet(); } - public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, - String columnNamePattern) throws SQLException { + public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException { return getEmptyResultSet(); } - public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, - String columnNamePattern) throws SQLException { + public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { return getEmptyResultSet(); } @@ -1093,164 +1143,142 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da } protected ResultSet getCatalogs(Connection conn) throws SQLException { - try (Statement stmt = conn.createStatement()) { - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList<>(); - // TABLE_CAT - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(1); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - - resultSet.setColumnMetaDataList(columnMetaDataList); + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + // set up ColumnMetaDataList + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT + resultSet.setColumnMetaDataList(columnMetaDataList); + try (Statement stmt = conn.createStatement()) { List rowDataList = new ArrayList<>(); ResultSet rs = stmt.executeQuery("show databases"); while (rs.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(1); - rowData.setString(0, rs.getString("name")); + rowData.setStringValue(1, rs.getString("name")); rowDataList.add(rowData); } resultSet.setRowDataList(rowDataList); - return resultSet; } + return resultSet; } protected ResultSet getPrimaryKeys(String catalog, String schema, String table, Connection conn) throws SQLException { - try (Statement stmt = conn.createStatement()) { - if (catalog == null || catalog.isEmpty()) - return null; + if (catalog == null || catalog.isEmpty()) + return null; + if (!isAvailableCatalog(conn, catalog)) + return new EmptyResultSet(); - ResultSet databases = stmt.executeQuery("show databases"); - String dbname = null; - while (databases.next()) { - dbname = databases.getString("name"); - if (dbname.equalsIgnoreCase(catalog)) - break; - } - databases.close(); - if (dbname == null) - return null; - - stmt.execute("use " + dbname); - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + try (Statement stmt = conn.createStatement()) { // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList<>(); - // TABLE_CAT - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(0); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - // TABLE_SCHEM - ColumnMetaData col2 = new ColumnMetaData(); - col2.setColIndex(1); - col2.setColName("TABLE_SCHEM"); - col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col2); - // TABLE_NAME - ColumnMetaData col3 = new ColumnMetaData(); - col3.setColIndex(2); - col3.setColName("TABLE_NAME"); - col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col3); - // COLUMN_NAME - ColumnMetaData col4 = new ColumnMetaData(); - col4.setColIndex(3); - col4.setColName("COLUMN_NAME"); - col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col4); - // KEY_SEQ - ColumnMetaData col5 = new ColumnMetaData(); - col5.setColIndex(4); - col5.setColName("KEY_SEQ"); - col5.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col5); - // PK_NAME - ColumnMetaData col6 = new ColumnMetaData(); - col6.setColIndex(5); - col6.setColName("PK_NAME"); - col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col6); - resultSet.setColumnMetaDataList(columnMetaDataList); - + resultSet.setColumnMetaDataList(buildGetPrimaryKeysMetadataList()); // set rowData List rowDataList = new ArrayList<>(); - ResultSet rs = stmt.executeQuery("describe " + dbname + "." + table); + ResultSet rs = stmt.executeQuery("describe " + catalog + "." + table); rs.next(); TSDBResultSetRowData rowData = new TSDBResultSetRowData(6); - rowData.setString(0, null); - rowData.setString(1, null); - rowData.setString(2, table); - String pkName = rs.getString(1); - rowData.setString(3, pkName); - rowData.setInt(4, 1); - rowData.setString(5, pkName); + rowData.setStringValue(1, catalog); + rowData.setStringValue(2, null); + rowData.setStringValue(3, table); + String primaryKey = rs.getString("Field"); + rowData.setStringValue(4, primaryKey); + rowData.setShortValue(5, (short) 1); + rowData.setStringValue(6, primaryKey); rowDataList.add(rowData); resultSet.setRowDataList(rowDataList); - return resultSet; } + return resultSet; } - protected ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern, Connection conn) throws SQLException { - try (Statement stmt = conn.createStatement()) { - if (catalog == null || catalog.isEmpty()) - return null; + private List buildGetPrimaryKeysMetadataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT + columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM + columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME + columnMetaDataList.add(buildColumnNameMeta(4)); // 4. COLUMN_NAME + columnMetaDataList.add(buildKeySeqMeta(5)); // 5. KEY_SEQ + columnMetaDataList.add(buildPrimaryKeyNameMeta(6)); // 6. PK_NAME + return columnMetaDataList; + } + + private ColumnMetaData buildKeySeqMeta(int colIndex) { + ColumnMetaData col5 = new ColumnMetaData(); + col5.setColIndex(colIndex); + col5.setColName("KEY_SEQ"); + col5.setColType(Types.SMALLINT); + return col5; + } + + private ColumnMetaData buildPrimaryKeyNameMeta(int colIndex) { + ColumnMetaData col6 = new ColumnMetaData(); + col6.setColIndex(colIndex); + col6.setColName("PK_NAME"); + col6.setColType(Types.NCHAR); + return col6; + } + private boolean isAvailableCatalog(Connection connection, String catalog) { + try (Statement stmt = connection.createStatement()) { ResultSet databases = stmt.executeQuery("show databases"); - String dbname = null; while (databases.next()) { - dbname = databases.getString("name"); + String dbname = databases.getString("name"); + this.database = dbname; + this.precision = databases.getString("precision"); if (dbname.equalsIgnoreCase(catalog)) - break; + return true; } databases.close(); - if (dbname == null) - return null; + } catch (SQLException e) { + e.printStackTrace(); + } + return false; + } - stmt.execute("use " + dbname); - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList<>(); - // TABLE_CAT - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(0); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - // TABLE_SCHEM - ColumnMetaData col2 = new ColumnMetaData(); - col2.setColIndex(1); - col2.setColName("TABLE_SCHEM"); - col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col2); - // TABLE_NAME - ColumnMetaData col3 = new ColumnMetaData(); - col3.setColIndex(2); - col3.setColName("TABLE_NAME"); - col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col3); - // SUPERTABLE_NAME - ColumnMetaData col4 = new ColumnMetaData(); - col4.setColIndex(3); - col4.setColName("SUPERTABLE_NAME"); - col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col4); - resultSet.setColumnMetaDataList(columnMetaDataList); + protected ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern, Connection conn) throws SQLException { + if (catalog == null || catalog.isEmpty()) + return null; + + if (!isAvailableCatalog(conn, catalog)) { + return new EmptyResultSet(); + } + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + try (Statement stmt = conn.createStatement()) { + // set up ColumnMetaDataList + resultSet.setColumnMetaDataList(buildGetSuperTablesColumnMetaDataList()); + // set result set row data + stmt.execute("use " + catalog); ResultSet rs = stmt.executeQuery("show tables like '" + tableNamePattern + "'"); List rowDataList = new ArrayList<>(); while (rs.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(4); - rowData.setString(2, rs.getString(1)); - rowData.setString(3, rs.getString(4)); + rowData.setStringValue(1, catalog); + rowData.setStringValue(2, null); + rowData.setStringValue(3, rs.getString("table_name")); + rowData.setStringValue(4, rs.getString("stable_name")); rowDataList.add(rowData); } resultSet.setRowDataList(rowDataList); - return resultSet; } + return resultSet; + } + + private List buildGetSuperTablesColumnMetaDataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT + columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM + columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME + columnMetaDataList.add(buildSuperTableNameMeta(4)); // 4. SUPERTABLE_NAME + return columnMetaDataList; } + + private ColumnMetaData buildSuperTableNameMeta(int colIndex) { + ColumnMetaData col4 = new ColumnMetaData(); + col4.setColIndex(colIndex); + col4.setColName("SUPERTABLE_NAME"); + col4.setColType(Types.NCHAR); + return col4; + } + } \ No newline at end of file diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java index 7df7252ae2010b5aa5e8f74de2cca55844e25b83..cb6c7d40ad1f1e12324043d78cb423fcfd46dca8 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java @@ -1,5 +1,7 @@ package com.taosdata.jdbc; +import com.sun.org.apache.xpath.internal.operations.Bool; + import java.sql.ParameterMetaData; import java.sql.SQLException; import java.sql.Timestamp; @@ -49,6 +51,22 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P if (param < 1 && param >= parameters.length) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE); + if (parameters[param - 1] instanceof Boolean) + return TSDBConstants.BOOLEAN_PRECISION; + if (parameters[param - 1] instanceof Byte) + return TSDBConstants.TINYINT_PRECISION; + if (parameters[param - 1] instanceof Short) + return TSDBConstants.SMALLINT_PRECISION; + if (parameters[param - 1] instanceof Integer) + return TSDBConstants.INT_PRECISION; + if (parameters[param - 1] instanceof Long) + return TSDBConstants.BIGINT_PRECISION; + if (parameters[param - 1] instanceof Timestamp) + return TSDBConstants.TIMESTAMP_MS_PRECISION; + if (parameters[param - 1] instanceof Float) + return TSDBConstants.FLOAT_PRECISION; + if (parameters[param - 1] instanceof Double) + return TSDBConstants.DOUBLE_PRECISION; if (parameters[param - 1] instanceof String) return ((String) parameters[param - 1]).length(); if (parameters[param - 1] instanceof byte[]) @@ -60,6 +78,11 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P public int getScale(int param) throws SQLException { if (param < 1 && param >= parameters.length) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE); + + if (parameters[param - 1] instanceof Float) + return TSDBConstants.FLOAT_SCALE; + if (parameters[param - 1] instanceof Double) + return TSDBConstants.DOUBLE_SCALE; return 0; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java index f8ea9af4230e9584197f1141dc5a4f7c1621b3ff..e17548055c792e900a1e2fb5b510de8bf65de7a7 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java @@ -66,10 +66,16 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet public abstract byte[] getBytes(int columnIndex) throws SQLException; @Override - public abstract Date getDate(int columnIndex) throws SQLException; + public Date getDate(int columnIndex) throws SQLException { + Timestamp timestamp = getTimestamp(columnIndex); + return timestamp == null ? null : new Date(timestamp.getTime()); + } @Override - public abstract Time getTime(int columnIndex) throws SQLException; + public Time getTime(int columnIndex) throws SQLException { + Timestamp timestamp = getTimestamp(columnIndex); + return timestamp == null ? null : new Time(timestamp.getTime()); + } @Override public abstract Timestamp getTimestamp(int columnIndex) throws SQLException; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java index f6a0fcca316cb07d28c71a4e1d51d9405de083ba..cd266529f34c0693a9891af33c12705b90132800 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java @@ -14,76 +14,42 @@ *****************************************************************************/ package com.taosdata.jdbc; -import java.io.InputStream; -import java.io.Reader; import java.math.BigDecimal; -import java.net.URL; -import java.sql.Date; import java.sql.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Iterator; +import java.util.List; /* - * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * TDengine only supports a subset of the standard SQL, thus this implementation of the * standard JDBC API contains more or less some adjustments customized for certain * compatibility needs. */ -public class DatabaseMetaDataResultSet implements ResultSet { +public class DatabaseMetaDataResultSet extends AbstractResultSet { - private List columnMetaDataList; - private List rowDataList; + private List columnMetaDataList = new ArrayList<>(); + private List rowDataList = new ArrayList<>(); private TSDBResultSetRowData rowCursor; // position of cursor, starts from 0 as beforeFirst, increases as next() is called private int cursorRowNumber = 0; - public DatabaseMetaDataResultSet() { - rowDataList = new ArrayList(); - columnMetaDataList = new ArrayList(); - } - - public List getRowDataList() { - return rowDataList; - } - public void setRowDataList(List rowDataList) { this.rowDataList = rowDataList; } - public List getColumnMetaDataList() { - return columnMetaDataList; - } - public void setColumnMetaDataList(List columnMetaDataList) { this.columnMetaDataList = columnMetaDataList; } - public TSDBResultSetRowData getRowCursor() { - return rowCursor; - } - - public void setRowCursor(TSDBResultSetRowData rowCursor) { - this.rowCursor = rowCursor; - } - @Override public boolean next() throws SQLException { -// boolean ret = false; -// if (rowDataList.size() > 0) { -// ret = rowDataList.iterator().hasNext(); -// if (ret) { -// rowCursor = rowDataList.iterator().next(); -// cursorRowNumber++; -// } -// } -// return ret; - - /**** add by zyyang 2020-09-29 ****************/ boolean ret = false; if (!rowDataList.isEmpty() && cursorRowNumber < rowDataList.size()) { rowCursor = rowDataList.get(cursorRowNumber++); ret = true; } - return ret; } @@ -99,189 +65,72 @@ public class DatabaseMetaDataResultSet implements ResultSet { @Override public String getString(int columnIndex) throws SQLException { - columnIndex--; - int colType = columnMetaDataList.get(columnIndex).getColType(); - return rowCursor.getString(columnIndex, colType); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getString(columnIndex, nativeType); } @Override public boolean getBoolean(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getBoolean(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getBoolean(columnIndex, nativeType); } @Override public byte getByte(int columnIndex) throws SQLException { - columnIndex--; - return (byte) rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return (byte) rowCursor.getInt(columnIndex, nativeType); } @Override public short getShort(int columnIndex) throws SQLException { - columnIndex--; - return (short) rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return (short) rowCursor.getInt(columnIndex, nativeType); } @Override public int getInt(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getInt(columnIndex, nativeType); } @Override public long getLong(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getLong(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getLong(columnIndex, nativeType); } @Override public float getFloat(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getFloat(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getFloat(columnIndex, nativeType); } @Override public double getDouble(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType()); - } - - @Override - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - columnIndex--; - return new BigDecimal(rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType())); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getDouble(columnIndex, nativeType); } @Override public byte[] getBytes(int columnIndex) throws SQLException { - columnIndex--; - return (rowCursor.getString(columnIndex, columnMetaDataList.get(columnIndex).getColType())).getBytes(); - } - - @Override - public Date getDate(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Time getTime(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return (rowCursor.getString(columnIndex, nativeType)).getBytes(); } @Override public Timestamp getTimestamp(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getTimestamp(columnIndex); - } - - @Override - public InputStream getAsciiStream(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public InputStream getBinaryStream(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public String getString(String columnLabel) throws SQLException { - return getString(findColumn(columnLabel)); - } - - @Override - public boolean getBoolean(String columnLabel) throws SQLException { - return getBoolean(findColumn(columnLabel)); - } - - @Override - public byte getByte(String columnLabel) throws SQLException { - return getByte(findColumn(columnLabel)); - } - - @Override - public short getShort(String columnLabel) throws SQLException { - return getShort(findColumn(columnLabel)); - } - - @Override - public int getInt(String columnLabel) throws SQLException { - return getInt(findColumn(columnLabel)); - } - - @Override - public long getLong(String columnLabel) throws SQLException { - return getLong(findColumn(columnLabel)); - } - - @Override - public float getFloat(String columnLabel) throws SQLException { - return getFloat(findColumn(columnLabel)); - } - - @Override - public double getDouble(String columnLabel) throws SQLException { - return getDouble(findColumn(columnLabel)); - } - - @Override - public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { - return getBigDecimal(findColumn(columnLabel)); - } - - @Override - public byte[] getBytes(String columnLabel) throws SQLException { - return getBytes(findColumn(columnLabel)); - } - - @Override - public Date getDate(String columnLabel) throws SQLException { - return getDate(findColumn(columnLabel)); - } - - @Override - public Time getTime(String columnLabel) throws SQLException { - return getTime(findColumn(columnLabel)); - } - - @Override - public Timestamp getTimestamp(String columnLabel) throws SQLException { - return getTimestamp(findColumn(columnLabel)); - } - - @Override - public InputStream getAsciiStream(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public InputStream getUnicodeStream(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public InputStream getBinaryStream(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public SQLWarning getWarnings() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void clearWarnings() throws SQLException { - - } - - @Override - public String getCursorName() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getTimestamp(columnIndex,nativeType); } @Override @@ -291,12 +140,7 @@ public class DatabaseMetaDataResultSet implements ResultSet { @Override public Object getObject(int columnIndex) throws SQLException { - return rowCursor.get(columnIndex); - } - - @Override - public Object getObject(String columnLabel) throws SQLException { - return rowCursor.get(findColumn(columnLabel)); + return rowCursor.getObject(columnIndex); } @Override @@ -304,31 +148,19 @@ public class DatabaseMetaDataResultSet implements ResultSet { Iterator colMetaDataIt = this.columnMetaDataList.iterator(); while (colMetaDataIt.hasNext()) { ColumnMetaData colMetaData = colMetaDataIt.next(); - if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) { - return colMetaData.getColIndex() + 1; + if (colMetaData.getColName() != null && colMetaData.getColName().equals(columnLabel)) { + return colMetaData.getColIndex(); } } throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); } - @Override - public Reader getCharacterStream(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Reader getCharacterStream(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - @Override public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - return new BigDecimal(rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType())); - } - - @Override - public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - return getBigDecimal(findColumn(columnLabel)); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + double value = rowCursor.getDouble(columnIndex, nativeType); + return new BigDecimal(value); } @Override @@ -378,7 +210,6 @@ public class DatabaseMetaDataResultSet implements ResultSet { } else { return 0; } - } @Override @@ -397,680 +228,23 @@ public class DatabaseMetaDataResultSet implements ResultSet { } @Override - public void setFetchDirection(int direction) throws SQLException { - - } - - @Override - public int getFetchDirection() throws SQLException { - return ResultSet.FETCH_FORWARD; - } - - @Override - public void setFetchSize(int rows) throws SQLException { - - } - - @Override - public int getFetchSize() throws SQLException { - return 0; - } - - @Override - public int getType() throws SQLException { - return ResultSet.TYPE_FORWARD_ONLY; - } - - @Override - public int getConcurrency() throws SQLException { - return ResultSet.CONCUR_READ_ONLY; - } - - @Override - public boolean rowUpdated() throws SQLException { - return false; + public Statement getStatement() throws SQLException { + return null; } - @Override - public boolean rowInserted() throws SQLException { - return false; + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + //TODO: calendar is not used + return getTimestamp(columnIndex); } @Override - public boolean rowDeleted() throws SQLException { + public boolean isClosed() throws SQLException { return false; } @Override - public void updateNull(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateByte(int columnIndex, byte x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateShort(int columnIndex, short x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateInt(int columnIndex, int x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateLong(int columnIndex, long x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateFloat(int columnIndex, float x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateDouble(int columnIndex, double x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateString(int columnIndex, String x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBytes(int columnIndex, byte[] x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateDate(int columnIndex, Date x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateTime(int columnIndex, Time x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateObject(int columnIndex, Object x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateNull(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBoolean(String columnLabel, boolean x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateByte(String columnLabel, byte x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateShort(String columnLabel, short x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateInt(String columnLabel, int x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateLong(String columnLabel, long x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateFloat(String columnLabel, float x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateDouble(String columnLabel, double x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateString(String columnLabel, String x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + public String getNString(int columnIndex) throws SQLException { + return getString(columnIndex); } - @Override - public void updateBytes(String columnLabel, byte[] x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateDate(String columnLabel, Date x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateTime(String columnLabel, Time x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateObject(String columnLabel, Object x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void insertRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void deleteRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void refreshRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void cancelRowUpdates() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void moveToInsertRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void moveToCurrentRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Statement getStatement() throws SQLException { - return null; - } - - @Override - public Object getObject(int columnIndex, Map> map) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Ref getRef(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Blob getBlob(int columnIndex) throws SQLException { - return null; - } - - @Override - public Clob getClob(int columnIndex) throws SQLException { - return null; - } - - @Override - public Array getArray(int columnIndex) throws SQLException { - return null; - } - - @Override - public Object getObject(String columnLabel, Map> map) throws SQLException { - return null; - } - - @Override - public Ref getRef(String columnLabel) throws SQLException { - return null; - } - - @Override - public Blob getBlob(String columnLabel) throws SQLException { - return null; - } - - @Override - public Clob getClob(String columnLabel) throws SQLException { - return null; - } - - @Override - public Array getArray(String columnLabel) throws SQLException { - return null; - } - - @Override - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Date getDate(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Time getTime(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public URL getURL(int columnIndex) throws SQLException { - return null; - } - - @Override - public URL getURL(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateRef(int columnIndex, Ref x) throws SQLException { - - } - - @Override - public void updateRef(String columnLabel, Ref x) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, Blob x) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, Blob x) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Clob x) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Clob x) throws SQLException { - - } - - @Override - public void updateArray(int columnIndex, Array x) throws SQLException { - - } - - @Override - public void updateArray(String columnLabel, Array x) throws SQLException { - - } - - @Override - public RowId getRowId(int columnIndex) throws SQLException { - return null; - } - - @Override - public RowId getRowId(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateRowId(int columnIndex, RowId x) throws SQLException { - - } - - @Override - public void updateRowId(String columnLabel, RowId x) throws SQLException { - - } - - @Override - public int getHoldability() throws SQLException { - return 0; - } - - @Override - public boolean isClosed() throws SQLException { - return false; - } - - @Override - public void updateNString(int columnIndex, String nString) throws SQLException { - - } - - @Override - public void updateNString(String columnLabel, String nString) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, NClob nClob) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, NClob nClob) throws SQLException { - - } - - @Override - public NClob getNClob(int columnIndex) throws SQLException { - return null; - } - - @Override - public NClob getNClob(String columnLabel) throws SQLException { - return null; - } - - @Override - public SQLXML getSQLXML(int columnIndex) throws SQLException { - return null; - } - - @Override - public SQLXML getSQLXML(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { - - } - - @Override - public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { - - } - - @Override - public String getNString(int columnIndex) throws SQLException { - return null; - } - - @Override - public String getNString(String columnLabel) throws SQLException { - return null; - } - - @Override - public Reader getNCharacterStream(int columnIndex) throws SQLException { - return null; - } - - @Override - public Reader getNCharacterStream(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - - } - - @Override - public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { - - } - - @Override - public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { - - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { - - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { - - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { - - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { - - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Reader reader) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, Reader reader) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public T getObject(int columnIndex, Class type) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public T getObject(String columnLabel, Class type) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public T unwrap(Class iface) throws SQLException { - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } - - private int getTrueColumnIndex(int columnIndex) throws SQLException { - if (columnIndex < 1) { - throw new SQLException("Column Index out of range, " + columnIndex + " < " + 1); - } - - int numOfCols = this.columnMetaDataList.size(); - if (columnIndex > numOfCols) { - throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols); - } - - return columnIndex - 1; - } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java index f38555ce8a6c7ee946b3bdbda2204c702b49198a..e6406d2c6dc7990ec4f3149bb8c5146202f5d326 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java @@ -41,15 +41,15 @@ public abstract class TSDBConstants { public static final int TSDB_DATA_TYPE_BINARY = 8; public static final int TSDB_DATA_TYPE_TIMESTAMP = 9; public static final int TSDB_DATA_TYPE_NCHAR = 10; - /* - 系统增加新的无符号数据类型,分别是: - unsigned tinyint, 数值范围:0-254, NULL 为255 - unsigned smallint,数值范围: 0-65534, NULL 为65535 - unsigned int,数值范围:0-4294967294,NULL 为4294967295u - unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。 - example: - create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned); - */ + /** + * 系统增加新的无符号数据类型,分别是: + * unsigned tinyint, 数值范围:0-254, NULL 为255 + * unsigned smallint,数值范围: 0-65534, NULL 为65535 + * unsigned int,数值范围:0-4294967294,NULL 为4294967295u + * unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。 + * example: + * create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned); + */ public static final int TSDB_DATA_TYPE_UTINYINT = 11; //unsigned tinyint public static final int TSDB_DATA_TYPE_USMALLINT = 12; //unsigned smallint public static final int TSDB_DATA_TYPE_UINT = 13; //unsigned int @@ -57,6 +57,47 @@ public abstract class TSDBConstants { // nchar column max length public static final int maxFieldSize = 16 * 1024; + // precision for data types + public static final int BOOLEAN_PRECISION = 1; + public static final int TINYINT_PRECISION = 4; + public static final int SMALLINT_PRECISION = 6; + public static final int INT_PRECISION = 11; + public static final int BIGINT_PRECISION = 20; + public static final int FLOAT_PRECISION = 12; + public static final int DOUBLE_PRECISION = 22; + public static final int TIMESTAMP_MS_PRECISION = 23; + public static final int TIMESTAMP_US_PRECISION = 26; + // scale for data types + public static final int FLOAT_SCALE = 31; + public static final int DOUBLE_SCALE = 31; + + public static int typeName2JdbcType(String type) { + switch (type.toUpperCase()) { + case "TIMESTAMP": + return Types.TIMESTAMP; + case "INT": + return Types.INTEGER; + case "BIGINT": + return Types.BIGINT; + case "FLOAT": + return Types.FLOAT; + case "DOUBLE": + return Types.DOUBLE; + case "BINARY": + return Types.BINARY; + case "SMALLINT": + return Types.SMALLINT; + case "TINYINT": + return Types.TINYINT; + case "BOOL": + return Types.BOOLEAN; + case "NCHAR": + return Types.NCHAR; + default: + return Types.NULL; + } + } + public static int taosType2JdbcType(int taosType) throws SQLException { switch (taosType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: @@ -88,7 +129,7 @@ public abstract class TSDBConstants { } public static String taosType2JdbcTypeName(int taosType) throws SQLException { - switch (taosType){ + switch (taosType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return "BOOL"; case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: @@ -119,7 +160,7 @@ public abstract class TSDBConstants { } public static int jdbcType2TaosType(int jdbcType) throws SQLException { - switch (jdbcType){ + switch (jdbcType) { case Types.BOOLEAN: return TSDBConstants.TSDB_DATA_TYPE_BOOL; case Types.TINYINT: @@ -145,7 +186,7 @@ public abstract class TSDBConstants { } public static String jdbcType2TaosTypeName(int jdbcType) throws SQLException { - switch (jdbcType){ + switch (jdbcType) { case Types.BOOLEAN: return "BOOL"; case Types.TINYINT: 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 256e735285bd493f37c9e369a49b369e9e6b4b38..92792d97517c98f9a5402aaae557d01e09bbca30 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 @@ -16,13 +16,13 @@ */ package com.taosdata.jdbc; +import com.taosdata.jdbc.utils.TaosInfo; + import java.nio.ByteBuffer; import java.sql.SQLException; import java.sql.SQLWarning; import java.util.List; -import com.taosdata.jdbc.utils.TaosInfo; - /** * JNI connector */ @@ -30,10 +30,10 @@ public class TSDBJNIConnector { private static volatile Boolean isInitialized = false; private TaosInfo taosInfo = TaosInfo.getInstance(); - + // Connection pointer used in C private long taos = TSDBConstants.JNI_NULL_POINTER; - + // result set status in current connection private boolean isResultsetClosed; @@ -194,7 +194,9 @@ public class TSDBJNIConnector { * Get schema metadata */ public int getSchemaMetaData(long resultSet, List columnMetaData) { - return this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData); + int ret = this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData); + columnMetaData.stream().forEach(column -> column.setColIndex(column.getColIndex() + 1)); + return ret; } private native int getSchemaMetaDataImp(long connection, long resultSet, List columnMetaData); @@ -221,7 +223,7 @@ public class TSDBJNIConnector { */ public void closeConnection() throws SQLException { int code = this.closeConnectionImp(this.taos); - + if (code < 0) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); } else if (code == 0) { @@ -229,7 +231,7 @@ public class TSDBJNIConnector { } else { throw new SQLException("Undefined error code returned by TDengine when closing a connection"); } - + // invoke closeConnectionImpl only here taosInfo.connect_close_increment(); } @@ -274,67 +276,76 @@ public class TSDBJNIConnector { } private native int validateCreateTableSqlImp(long connection, byte[] sqlBytes); - - public long prepareStmt(String sql) throws SQLException { - Long stmt = prepareStmtImp(sql.getBytes(), this.taos); - if (stmt == TSDBConstants.JNI_TDENGINE_ERROR) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL); - } else if (stmt == TSDBConstants.JNI_CONNECTION_NULL) { + + public long prepareStmt(String sql) throws SQLException { + Long stmt; + try { + stmt = prepareStmtImp(sql.getBytes(), this.taos); + } catch (Exception e) { + e.printStackTrace(); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING); + } + + if (stmt == TSDBConstants.JNI_CONNECTION_NULL) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); - } else if (stmt == TSDBConstants.JNI_SQL_NULL) { + } + + if (stmt == TSDBConstants.JNI_SQL_NULL) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL); - } else if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) { + } + + if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY); } - - return stmt; + + return stmt; } - + private native long prepareStmtImp(byte[] sql, long con); - + public void setBindTableName(long stmt, String tableName) throws SQLException { - int code = setBindTableNameImp(stmt, tableName, this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { + int code = setBindTableNameImp(stmt, tableName, this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to set table name"); - } - } - + } + } + private native int setBindTableNameImp(long stmt, String name, long conn); - + public void setBindTableNameAndTags(long stmt, String tableName, int numOfTags, ByteBuffer tags, ByteBuffer typeList, ByteBuffer lengthList, ByteBuffer nullList) throws SQLException { - int code = setTableNameTagsImp(stmt, tableName, numOfTags, tags.array(), typeList.array(), lengthList.array(), - nullList.array(), this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind table name and corresponding tags"); - } + int code = setTableNameTagsImp(stmt, tableName, numOfTags, tags.array(), typeList.array(), lengthList.array(), + nullList.array(), this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind table name and corresponding tags"); + } } - + private native int setTableNameTagsImp(long stmt, String name, int numOfTags, byte[] tags, byte[] typeList, byte[] lengthList, byte[] nullList, long conn); - - public void bindColumnDataArray(long stmt, ByteBuffer colDataList, ByteBuffer lengthList, ByteBuffer isNullList, int type, int bytes, int numOfRows,int columnIndex) throws SQLException { - int code = bindColDataImp(stmt, colDataList.array(), lengthList.array(), isNullList.array(), type, bytes, numOfRows, columnIndex, this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { + + public void bindColumnDataArray(long stmt, ByteBuffer colDataList, ByteBuffer lengthList, ByteBuffer isNullList, int type, int bytes, int numOfRows, int columnIndex) throws SQLException { + int code = bindColDataImp(stmt, colDataList.array(), lengthList.array(), isNullList.array(), type, bytes, numOfRows, columnIndex, this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind column data"); - } - } - + } + } + private native int bindColDataImp(long stmt, byte[] colDataList, byte[] lengthList, byte[] isNullList, int type, int bytes, int numOfRows, int columnIndex, long conn); - + public void executeBatch(long stmt) throws SQLException { - int code = executeBatchImp(stmt, this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { + int code = executeBatchImp(stmt, this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to execute batch bind"); - } + } } - + private native int executeBatchImp(long stmt, long con); - + public void closeBatch(long stmt) throws SQLException { - int code = closeStmt(stmt, this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { + int code = closeStmt(stmt, this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to close batch bind"); - } + } } - + private native int closeStmt(long stmt, long con); } 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 f6810237c097a62a4c8f0f63d6e435bfb0354125..c3d5abf35c7304f86f9cc4dc4449d8c88d144e3d 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 @@ -39,18 +39,18 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat private String rawSql; private Object[] parameters; private boolean isPrepared; - + private ArrayList colData; private ArrayList tableTags; private int tagValueLength; - + private String tableName; private long nativeStmtHandle = 0; - + private volatile TSDBParameterMetaData parameterMetaData; TSDBPreparedStatement(TSDBConnection connection, String sql) { - super(connection); + super(connection); init(sql); int parameterCnt = 0; @@ -64,11 +64,11 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat this.isPrepared = true; } - if (parameterCnt > 1) { - // the table name is also a parameter, so ignore it. - this.colData = new ArrayList(); - this.tableTags = new ArrayList(); - } + if (parameterCnt > 1) { + // the table name is also a parameter, so ignore it. + this.colData = new ArrayList(); + this.tableTags = new ArrayList(); + } } private void init(String sql) { @@ -205,9 +205,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + setObject(parameterIndex, x.doubleValue()); } @Override @@ -222,16 +220,12 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public void setDate(int parameterIndex, Date x) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + setObject(parameterIndex, new Timestamp(x.getTime())); } @Override public void setTime(int parameterIndex, Time x) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + setObject(parameterIndex, new Timestamp(x.getTime())); } @Override @@ -279,11 +273,10 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat if (isClosed()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); } - + if (parameterIndex < 1 && parameterIndex >= parameters.length) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE); } - parameters[parameterIndex - 1] = x; } @@ -323,7 +316,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat if (isClosed()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); } - + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); } @@ -350,9 +343,9 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public ResultSetMetaData getMetaData() throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + if (this.getResultSet() == null) + return null; + return getResultSet().getMetaData(); } @Override @@ -396,10 +389,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat if (isClosed()) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - if (parameterMetaData == null) { - this.parameterMetaData = new TSDBParameterMetaData(parameters); - } - return this.parameterMetaData; + return new TSDBParameterMetaData(parameters); } @Override @@ -411,9 +401,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public void setNString(int parameterIndex, String value) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + setString(parameterIndex, value); } @Override @@ -536,489 +524,495 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); } - + /////////////////////////////////////////////////////////////////////// // NOTE: the following APIs are not JDBC compatible // set the bind table name private static class ColumnInfo { - @SuppressWarnings("rawtypes") - private ArrayList data; - private int type; - private int bytes; - private boolean typeIsSet; - - public ColumnInfo() { - this.typeIsSet = false; - } - - public void setType(int type) throws SQLException { - if (this.isTypeSet()) { + @SuppressWarnings("rawtypes") + private ArrayList data; + private int type; + private int bytes; + private boolean typeIsSet; + + public ColumnInfo() { + this.typeIsSet = false; + } + + public void setType(int type) throws SQLException { + if (this.isTypeSet()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data type has been set"); - } - - this.typeIsSet = true; - this.type = type; - } - - public boolean isTypeSet() { - return this.typeIsSet; - } - }; - + } + + this.typeIsSet = true; + this.type = type; + } + + public boolean isTypeSet() { + return this.typeIsSet; + } + } + + ; + private static class TableTagInfo { - private boolean isNull; - private Object value; - private int type; - public TableTagInfo(Object value, int type) { - this.value = value; - this.type = type; - } - - public static TableTagInfo createNullTag(int type) { - TableTagInfo info = new TableTagInfo(null, type); - info.isNull = true; - return info; - } - }; - + private boolean isNull; + private Object value; + private int type; + + public TableTagInfo(Object value, int type) { + this.value = value; + this.type = type; + } + + public static TableTagInfo createNullTag(int type) { + TableTagInfo info = new TableTagInfo(null, type); + info.isNull = true; + return info; + } + } + + ; + public void setTableName(String name) { - this.tableName = name; + this.tableName = name; } - + private void ensureTagCapacity(int index) { - if (this.tableTags.size() < index + 1) { - int delta = index + 1 - this.tableTags.size(); - this.tableTags.addAll(Collections.nCopies(delta, null)); - } + if (this.tableTags.size() < index + 1) { + int delta = index + 1 - this.tableTags.size(); + this.tableTags.addAll(Collections.nCopies(delta, null)); + } } - + public void setTagNull(int index, int type) { - ensureTagCapacity(index); - this.tableTags.set(index, TableTagInfo.createNullTag(type)); + ensureTagCapacity(index); + this.tableTags.set(index, TableTagInfo.createNullTag(type)); } - + public void setTagBoolean(int index, boolean value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BOOL)); - this.tagValueLength += Byte.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BOOL)); + this.tagValueLength += Byte.BYTES; } - + public void setTagInt(int index, int value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_INT)); - this.tagValueLength += Integer.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_INT)); + this.tagValueLength += Integer.BYTES; } - + public void setTagByte(int index, byte value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TINYINT)); - this.tagValueLength += Byte.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TINYINT)); + this.tagValueLength += Byte.BYTES; } - + public void setTagShort(int index, short value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_SMALLINT)); - this.tagValueLength += Short.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_SMALLINT)); + this.tagValueLength += Short.BYTES; } - + public void setTagLong(int index, long value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BIGINT)); - this.tagValueLength += Long.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BIGINT)); + this.tagValueLength += Long.BYTES; } - + public void setTagTimestamp(int index, long value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP)); - this.tagValueLength += Long.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP)); + this.tagValueLength += Long.BYTES; } - + public void setTagFloat(int index, float value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_FLOAT)); - this.tagValueLength += Float.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_FLOAT)); + this.tagValueLength += Float.BYTES; } - + public void setTagDouble(int index, double value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_DOUBLE)); - this.tagValueLength += Double.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_DOUBLE)); + this.tagValueLength += Double.BYTES; } - + public void setTagString(int index, String value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BINARY)); - this.tagValueLength += value.getBytes().length; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BINARY)); + this.tagValueLength += value.getBytes().length; } - + public void setTagNString(int index, String value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_NCHAR)); - - String charset = TaosGlobalConfig.getCharset(); - try { - this.tagValueLength += value.getBytes(charset).length; - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_NCHAR)); + + String charset = TaosGlobalConfig.getCharset(); + try { + this.tagValueLength += value.getBytes(charset).length; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + public void setValueImpl(int columnIndex, ArrayList list, int type, int bytes) throws SQLException { - if (this.colData.size() == 0) { - this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null)); - - } - ColumnInfo col = (ColumnInfo) this.colData.get(columnIndex); - if (col == null) { - ColumnInfo p = new ColumnInfo(); - p.setType(type); - p.bytes = bytes; - p.data = (ArrayList) list.clone(); - this.colData.set(columnIndex, p); - } else { - if (col.type != type) { + if (this.colData.size() == 0) { + this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null)); + } + + ColumnInfo col = (ColumnInfo) this.colData.get(columnIndex); + if (col == null) { + ColumnInfo p = new ColumnInfo(); + p.setType(type); + p.bytes = bytes; + p.data = (ArrayList) list.clone(); + this.colData.set(columnIndex, p); + } else { + if (col.type != type) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data type mismatch"); - } - col.data.addAll(list); - } + } + col.data.addAll(list); + } } - + public void setInt(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_INT, Integer.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_INT, Integer.BYTES); } - + public void setFloat(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_FLOAT, Float.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_FLOAT, Float.BYTES); } - + public void setTimestamp(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP, Long.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP, Long.BYTES); } - + public void setLong(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BIGINT, Long.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BIGINT, Long.BYTES); } - + public void setDouble(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_DOUBLE, Double.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_DOUBLE, Double.BYTES); } - + public void setBoolean(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BOOL, Byte.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BOOL, Byte.BYTES); } - + public void setByte(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TINYINT, Byte.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TINYINT, Byte.BYTES); } - + public void setShort(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_SMALLINT, Short.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_SMALLINT, Short.BYTES); } - + public void setString(int columnIndex, ArrayList list, int size) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BINARY, size); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BINARY, size); } - + // note: expand the required space for each NChar character public void setNString(int columnIndex, ArrayList list, int size) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_NCHAR, size * Integer.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_NCHAR, size * Integer.BYTES); } - + public void columnDataAddBatch() throws SQLException { - // pass the data block to native code - if (rawSql == null) { + // pass the data block to native code + if (rawSql == null) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "sql statement not set yet"); - } - - // table name is not set yet, abort - if (this.tableName == null) { + } + + // table name is not set yet, abort + if (this.tableName == null) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "table name not set yet"); - } - - int numOfCols = this.colData.size(); - if (numOfCols == 0) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); - } - - TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); - this.nativeStmtHandle = connector.prepareStmt(rawSql); - - if (this.tableTags == null) { - connector.setBindTableName(this.nativeStmtHandle, this.tableName); - } else { - int num = this.tableTags.size(); - ByteBuffer tagDataList = ByteBuffer.allocate(this.tagValueLength); - tagDataList.order(ByteOrder.LITTLE_ENDIAN); - - ByteBuffer typeList = ByteBuffer.allocate(num); - typeList.order(ByteOrder.LITTLE_ENDIAN); - - ByteBuffer lengthList = ByteBuffer.allocate(num * Long.BYTES); - lengthList.order(ByteOrder.LITTLE_ENDIAN); - - ByteBuffer isNullList = ByteBuffer.allocate(num * Integer.BYTES); - isNullList.order(ByteOrder.LITTLE_ENDIAN); - - for (int i = 0; i < num; ++i) { - TableTagInfo tag = this.tableTags.get(i); - if (tag.isNull) { - typeList.put((byte) tag.type); - isNullList.putInt(1); - lengthList.putLong(0); - continue; - } - - switch (tag.type) { - case TSDBConstants.TSDB_DATA_TYPE_INT: { - Integer val = (Integer) tag.value; - tagDataList.putInt(val); - lengthList.putLong(Integer.BYTES); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { - Byte val = (Byte) tag.value; - tagDataList.put(val); - lengthList.putLong(Byte.BYTES); - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_BOOL: { - Boolean val = (Boolean) tag.value; - tagDataList.put((byte) (val ? 1 : 0)); - lengthList.putLong(Byte.BYTES); - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { - Short val = (Short) tag.value; - tagDataList.putShort(val); - lengthList.putLong(Short.BYTES); - - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: - case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { - Long val = (Long) tag.value; - tagDataList.putLong(val == null ? 0 : val); - lengthList.putLong(Long.BYTES); - - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { - Float val = (Float) tag.value; - tagDataList.putFloat(val == null ? 0 : val); - lengthList.putLong(Float.BYTES); - - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { - Double val = (Double) tag.value; - tagDataList.putDouble(val == null ? 0 : val); - lengthList.putLong(Double.BYTES); - - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_NCHAR: - case TSDBConstants.TSDB_DATA_TYPE_BINARY: { - String charset = TaosGlobalConfig.getCharset(); - String val = (String) tag.value; - - byte[] b = null; - try { - if (tag.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) { - b = val.getBytes(); - } else { - b = val.getBytes(charset); - } - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - tagDataList.put(b); - lengthList.putLong(b.length); - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: - case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: - case TSDBConstants.TSDB_DATA_TYPE_UINT: - case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types"); - } - } - - typeList.put((byte) tag.type); - isNullList.putInt(tag.isNull? 1 : 0); - } - - connector.setBindTableNameAndTags(this.nativeStmtHandle, this.tableName, this.tableTags.size(), tagDataList, - typeList, lengthList, isNullList); - } - - ColumnInfo colInfo = (ColumnInfo) this.colData.get(0); - if (colInfo == null) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); - } - - int rows = colInfo.data.size(); - for (int i = 0; i < numOfCols; ++i) { - ColumnInfo col1 = this.colData.get(i); - if (col1 == null || !col1.isTypeSet()) { + } + + int numOfCols = this.colData.size(); + if (numOfCols == 0) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); + } + + TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); + this.nativeStmtHandle = connector.prepareStmt(rawSql); + + if (this.tableTags == null) { + connector.setBindTableName(this.nativeStmtHandle, this.tableName); + } else { + int num = this.tableTags.size(); + ByteBuffer tagDataList = ByteBuffer.allocate(this.tagValueLength); + tagDataList.order(ByteOrder.LITTLE_ENDIAN); + + ByteBuffer typeList = ByteBuffer.allocate(num); + typeList.order(ByteOrder.LITTLE_ENDIAN); + + ByteBuffer lengthList = ByteBuffer.allocate(num * Long.BYTES); + lengthList.order(ByteOrder.LITTLE_ENDIAN); + + ByteBuffer isNullList = ByteBuffer.allocate(num * Integer.BYTES); + isNullList.order(ByteOrder.LITTLE_ENDIAN); + + for (int i = 0; i < num; ++i) { + TableTagInfo tag = this.tableTags.get(i); + if (tag.isNull) { + typeList.put((byte) tag.type); + isNullList.putInt(1); + lengthList.putLong(0); + continue; + } + + switch (tag.type) { + case TSDBConstants.TSDB_DATA_TYPE_INT: { + Integer val = (Integer) tag.value; + tagDataList.putInt(val); + lengthList.putLong(Integer.BYTES); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { + Byte val = (Byte) tag.value; + tagDataList.put(val); + lengthList.putLong(Byte.BYTES); + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_BOOL: { + Boolean val = (Boolean) tag.value; + tagDataList.put((byte) (val ? 1 : 0)); + lengthList.putLong(Byte.BYTES); + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { + Short val = (Short) tag.value; + tagDataList.putShort(val); + lengthList.putLong(Short.BYTES); + + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { + Long val = (Long) tag.value; + tagDataList.putLong(val == null ? 0 : val); + lengthList.putLong(Long.BYTES); + + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { + Float val = (Float) tag.value; + tagDataList.putFloat(val == null ? 0 : val); + lengthList.putLong(Float.BYTES); + + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { + Double val = (Double) tag.value; + tagDataList.putDouble(val == null ? 0 : val); + lengthList.putLong(Double.BYTES); + + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + case TSDBConstants.TSDB_DATA_TYPE_BINARY: { + String charset = TaosGlobalConfig.getCharset(); + String val = (String) tag.value; + + byte[] b = null; + try { + if (tag.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) { + b = val.getBytes(); + } else { + b = val.getBytes(charset); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + tagDataList.put(b); + lengthList.putLong(b.length); + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: + case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: + case TSDBConstants.TSDB_DATA_TYPE_UINT: + case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types"); + } + } + + typeList.put((byte) tag.type); + isNullList.putInt(tag.isNull ? 1 : 0); + } + + connector.setBindTableNameAndTags(this.nativeStmtHandle, this.tableName, this.tableTags.size(), tagDataList, + typeList, lengthList, isNullList); + } + + ColumnInfo colInfo = (ColumnInfo) this.colData.get(0); + if (colInfo == null) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); + } + + int rows = colInfo.data.size(); + for (int i = 0; i < numOfCols; ++i) { + ColumnInfo col1 = this.colData.get(i); + if (col1 == null || !col1.isTypeSet()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); - } - - if (rows != col1.data.size()) { + } + + if (rows != col1.data.size()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "the rows in column data not identical"); - } - - ByteBuffer colDataList = ByteBuffer.allocate(rows * col1.bytes); - colDataList.order(ByteOrder.LITTLE_ENDIAN); - + } + + ByteBuffer colDataList = ByteBuffer.allocate(rows * col1.bytes); + colDataList.order(ByteOrder.LITTLE_ENDIAN); + ByteBuffer lengthList = ByteBuffer.allocate(rows * Integer.BYTES); lengthList.order(ByteOrder.LITTLE_ENDIAN); - + ByteBuffer isNullList = ByteBuffer.allocate(rows * Byte.BYTES); isNullList.order(ByteOrder.LITTLE_ENDIAN); - - switch (col1.type) { - case TSDBConstants.TSDB_DATA_TYPE_INT: { - for (int j = 0; j < rows; ++j) { - Integer val = (Integer) col1.data.get(j); - colDataList.putInt(val == null? Integer.MIN_VALUE:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { - for (int j = 0; j < rows; ++j) { - Byte val = (Byte) col1.data.get(j); - colDataList.put(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_BOOL: { - for (int j = 0; j < rows; ++j) { - Boolean val = (Boolean) col1.data.get(j); - if (val == null) { - colDataList.put((byte) 0); - } else { - colDataList.put((byte) (val? 1:0)); - } - - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { - for (int j = 0; j < rows; ++j) { - Short val = (Short) col1.data.get(j); - colDataList.putShort(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: - case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { - for (int j = 0; j < rows; ++j) { - Long val = (Long) col1.data.get(j); - colDataList.putLong(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { - for (int j = 0; j < rows; ++j) { - Float val = (Float) col1.data.get(j); - colDataList.putFloat(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { - for (int j = 0; j < rows; ++j) { - Double val = (Double) col1.data.get(j); - colDataList.putDouble(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_NCHAR: - case TSDBConstants.TSDB_DATA_TYPE_BINARY: { - String charset = TaosGlobalConfig.getCharset(); - for (int j = 0; j < rows; ++j) { - String val = (String) col1.data.get(j); - - colDataList.position(j * col1.bytes); // seek to the correct position - if (val != null) { - byte[] b = null; - try { - if (col1.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) { - b = val.getBytes(); - } else { - b = val.getBytes(charset); - } - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - if (val.length() > col1.bytes) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "string data too long"); - } - - colDataList.put(b); - lengthList.putInt(b.length); - isNullList.put((byte) 0); - } else { - lengthList.putInt(0); - isNullList.put((byte) 1); - } - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: - case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: - case TSDBConstants.TSDB_DATA_TYPE_UINT: - case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types"); - } - }; - - connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i); - } - } - - public void columnDataExecuteBatch() throws SQLException { - TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); - connector.executeBatch(this.nativeStmtHandle); - this.columnDataClearBatch(); - } - + + switch (col1.type) { + case TSDBConstants.TSDB_DATA_TYPE_INT: { + for (int j = 0; j < rows; ++j) { + Integer val = (Integer) col1.data.get(j); + colDataList.putInt(val == null ? Integer.MIN_VALUE : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { + for (int j = 0; j < rows; ++j) { + Byte val = (Byte) col1.data.get(j); + colDataList.put(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_BOOL: { + for (int j = 0; j < rows; ++j) { + Boolean val = (Boolean) col1.data.get(j); + if (val == null) { + colDataList.put((byte) 0); + } else { + colDataList.put((byte) (val ? 1 : 0)); + } + + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { + for (int j = 0; j < rows; ++j) { + Short val = (Short) col1.data.get(j); + colDataList.putShort(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { + for (int j = 0; j < rows; ++j) { + Long val = (Long) col1.data.get(j); + colDataList.putLong(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { + for (int j = 0; j < rows; ++j) { + Float val = (Float) col1.data.get(j); + colDataList.putFloat(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { + for (int j = 0; j < rows; ++j) { + Double val = (Double) col1.data.get(j); + colDataList.putDouble(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + case TSDBConstants.TSDB_DATA_TYPE_BINARY: { + String charset = TaosGlobalConfig.getCharset(); + for (int j = 0; j < rows; ++j) { + String val = (String) col1.data.get(j); + + colDataList.position(j * col1.bytes); // seek to the correct position + if (val != null) { + byte[] b = null; + try { + if (col1.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) { + b = val.getBytes(); + } else { + b = val.getBytes(charset); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + if (val.length() > col1.bytes) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "string data too long"); + } + + colDataList.put(b); + lengthList.putInt(b.length); + isNullList.put((byte) 0); + } else { + lengthList.putInt(0); + isNullList.put((byte) 1); + } + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: + case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: + case TSDBConstants.TSDB_DATA_TYPE_UINT: + case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types"); + } + } + ; + + connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i); + } + } + + public void columnDataExecuteBatch() throws SQLException { + TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); + connector.executeBatch(this.nativeStmtHandle); + this.columnDataClearBatch(); + } + public void columnDataClearBatch() { - int size = this.colData.size(); - this.colData.clear(); - + int size = this.colData.size(); + this.colData.clear(); + this.colData.addAll(Collections.nCopies(size, null)); this.tableName = null; // clear the table name } - + public void columnDataCloseBatch() throws SQLException { - TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); - connector.closeBatch(this.nativeStmtHandle); - - this.nativeStmtHandle = 0L; - this.tableName = null; + TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); + connector.closeBatch(this.nativeStmtHandle); + + this.nativeStmtHandle = 0L; + this.tableName = null; } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java index aba29d602b8900d3bedee49ee94e7d226b3bd1f0..59a64ad520f01c8c7f2b85f95057365e2410ecb6 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java @@ -133,9 +133,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getString(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getString(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getString(columnIndex, nativeType); } return res; } @@ -147,9 +148,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getBoolean(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getBoolean(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getBoolean(columnIndex, nativeType); } return res; } @@ -161,9 +163,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return (byte) this.blockData.getInt(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = (byte) this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = (byte) this.rowData.getInt(columnIndex, nativeType); } return res; } @@ -175,9 +178,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return (short) this.blockData.getInt(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = (short) this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = (short) this.rowData.getInt(columnIndex, nativeType); } return res; } @@ -189,9 +193,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getInt(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getInt(columnIndex, nativeType); } return res; } @@ -203,13 +209,15 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getLong(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - Object value = this.rowData.get(columnIndex - 1); - if (value instanceof Timestamp) + Object value = this.rowData.getObject(columnIndex); + if (value instanceof Timestamp) { res = ((Timestamp) value).getTime(); - else - res = this.rowData.getLong(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + } else { + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getLong(columnIndex, nativeType); + } } return res; } @@ -221,9 +229,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return (float) this.blockData.getDouble(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); - if (!lastWasNull) - res = this.rowData.getFloat(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + this.lastWasNull = this.rowData.wasNull(columnIndex); + if (!lastWasNull) { + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getFloat(columnIndex, nativeType); + } return res; } @@ -235,9 +245,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getDouble(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getDouble(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getDouble(columnIndex, nativeType); } return res; } @@ -245,34 +256,27 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { public byte[] getBytes(int columnIndex) throws SQLException { checkAvailability(columnIndex, this.columnMetaDataList.size()); - Object value = this.rowData.get(columnIndex - 1); + Object value = this.rowData.getObject(columnIndex); if (value == null) return null; - int colType = this.columnMetaDataList.get(columnIndex - 1).getColType(); - switch (colType) { + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BIGINT: - return Longs.toByteArray((Long) value); + return Longs.toByteArray((long) value); case TSDBConstants.TSDB_DATA_TYPE_INT: return Ints.toByteArray((int) value); case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: - return Shorts.toByteArray((Short) value); + return Shorts.toByteArray((short) value); case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return new byte[]{(byte) value}; + case TSDBConstants.TSDB_DATA_TYPE_BINARY: + return (byte[]) value; + case TSDBConstants.TSDB_DATA_TYPE_BOOL: + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + default: + return value.toString().getBytes(); } - return value.toString().getBytes(); - } - - @Override - public Date getDate(int columnIndex) throws SQLException { - Timestamp timestamp = getTimestamp(columnIndex); - return timestamp == null ? null : new Date(timestamp.getTime()); - } - - @Override - public Time getTime(int columnIndex) throws SQLException { - Timestamp timestamp = getTimestamp(columnIndex); - return timestamp == null ? null : new Time(timestamp.getTime()); } public Timestamp getTimestamp(int columnIndex) throws SQLException { @@ -282,9 +286,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getTimestamp(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getTimestamp(columnIndex - 1); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getTimestamp(columnIndex, nativeType); } return res; } @@ -304,13 +309,9 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.get(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - int colType = this.columnMetaDataList.get(columnIndex - 1).getColType(); - if (colType == TSDBConstants.TSDB_DATA_TYPE_BINARY) - res = ((String) this.rowData.get(columnIndex - 1)).getBytes(); - else - res = this.rowData.get(columnIndex - 1); + res = this.rowData.getObject(columnIndex); } return res; } @@ -318,7 +319,7 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { public int findColumn(String columnLabel) throws SQLException { for (ColumnMetaData colMetaData : this.columnMetaDataList) { if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) { - return colMetaData.getColIndex() + 1; + return colMetaData.getColIndex(); } } throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); @@ -329,25 +330,25 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return new BigDecimal(this.blockData.getLong(columnIndex - 1)); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); BigDecimal res = null; if (!lastWasNull) { - int colType = this.columnMetaDataList.get(columnIndex - 1).getColType(); - switch (colType) { + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_TINYINT: case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: case TSDBConstants.TSDB_DATA_TYPE_INT: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: - res = new BigDecimal(Long.valueOf(this.rowData.get(columnIndex - 1).toString())); + res = new BigDecimal(Long.valueOf(this.rowData.getObject(columnIndex).toString())); break; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: - res = new BigDecimal(Double.valueOf(this.rowData.get(columnIndex - 1).toString())); + res = new BigDecimal(Double.valueOf(this.rowData.getObject(columnIndex).toString())); break; case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: - return new BigDecimal(((Timestamp) this.rowData.get(columnIndex - 1)).getTime()); + return new BigDecimal(((Timestamp) this.rowData.getObject(columnIndex)).getTime()); default: - res = new BigDecimal(this.rowData.get(columnIndex - 1).toString()); + res = new BigDecimal(this.rowData.getObject(columnIndex).toString()); } } return res; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java index e4ac5303d09f132279e29039bf6b5b812b6c5404..48d42473926b638401cf5d9dd97466695ba452ab 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java @@ -113,6 +113,7 @@ public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaD ColumnMetaData columnMetaData = this.colMetaDataList.get(column - 1); switch (columnMetaData.getColType()) { + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return 5; case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: 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 618e896a6ddfe43d63f631b663a356f485575b06..01104440ab00c974aa021f10b4168c3f1332e91a 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 @@ -14,6 +14,8 @@ *****************************************************************************/ package com.taosdata.jdbc; +import com.taosdata.jdbc.utils.NullType; + import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Timestamp; @@ -22,11 +24,13 @@ import java.util.ArrayList; import java.util.Collections; public class TSDBResultSetRowData { + private ArrayList data; - private int colSize = 0; + private int colSize; public TSDBResultSetRowData(int colSize) { - this.setColSize(colSize); + this.colSize = colSize; + this.clear(); } public void clear() { @@ -41,68 +45,104 @@ public class TSDBResultSetRowData { } public boolean wasNull(int col) { - return data.get(col) == null; + return data.get(col - 1) == null; + } + + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setBooleanValue(int col, boolean value) { + setBoolean(col - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setBoolean(int col, boolean value) { data.set(col, value); } - public boolean getBoolean(int col, int srcType) throws SQLException { - Object obj = data.get(col); + public boolean getBoolean(int col, int nativeType) throws SQLException { + Object obj = data.get(col - 1); - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return (Boolean) obj; - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: - return ((Float) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE; - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: - return ((Double) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE; case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return ((Byte) obj) == 1 ? Boolean.TRUE : Boolean.FALSE; case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return ((Short) obj) == 1 ? Boolean.TRUE : Boolean.FALSE; case TSDBConstants.TSDB_DATA_TYPE_INT: return ((Integer) obj) == 1 ? Boolean.TRUE : Boolean.FALSE; - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj) == 1L ? Boolean.TRUE : Boolean.FALSE; + case TSDBConstants.TSDB_DATA_TYPE_BINARY: + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: { + return obj.toString().contains("1"); + } default: return false; } } + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setByteValue(int colIndex, byte value) { + setByte(colIndex - 1, value); + } + + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setByte(int col, byte value) { data.set(col, value); } + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setShortValue(int colIndex, short value) { + setShort(colIndex - 1, value); + } + + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setShort(int col, short value) { data.set(col, value); } + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setIntValue(int colIndex, int value) { + setInt(colIndex - 1, value); + } + + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setInt(int col, int value) { data.set(col, value); } - @SuppressWarnings("deprecation") - public int getInt(int col, int srcType) throws SQLException { - Object obj = data.get(col); + public int getInt(int col, int nativeType) throws SQLException { + Object obj = data.get(col - 1); + if (obj == null) + return NullType.getIntNull(); - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj) ? 1 : 0; - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: - return ((Float) obj).intValue(); - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: - return ((Double) obj).intValue(); case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return (Short) obj; case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: return ((Long) obj).intValue(); case TSDBConstants.TSDB_DATA_TYPE_NCHAR: case TSDBConstants.TSDB_DATA_TYPE_BINARY: @@ -131,33 +171,46 @@ public class TSDBResultSetRowData { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); return Long.valueOf(value).intValue(); } + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: + return ((Float) obj).intValue(); + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: + return ((Double) obj).intValue(); + default: + return 0; } + } - return 0; + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setLongValue(int colIndex, long value) { + setLong(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setLong(int col, long value) { data.set(col, value); } - public long getLong(int col, int srcType) throws SQLException { - Object obj = data.get(col); + public long getLong(int col, int nativeType) throws SQLException { + Object obj = data.get(col - 1); + if (obj == null) { + return NullType.getBigIntNull(); + } - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj) ? 1 : 0; - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: - return ((Float) obj).longValue(); - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: - return ((Double) obj).longValue(); case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return (Short) obj; case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: return (Long) obj; case TSDBConstants.TSDB_DATA_TYPE_NCHAR: case TSDBConstants.TSDB_DATA_TYPE_BINARY: @@ -186,19 +239,35 @@ public class TSDBResultSetRowData { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); return value; } + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: + return ((Float) obj).longValue(); + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: + return ((Double) obj).longValue(); + default: + return 0; } + } - return 0; + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setFloatValue(int colIndex, float value) { + setFloat(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setFloat(int col, float value) { data.set(col, value); } - public float getFloat(int col, int srcType) { - Object obj = data.get(col); + public float getFloat(int col, int nativeType) { + Object obj = data.get(col - 1); + if (obj == null) + return NullType.getFloatNull(); - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj) ? 1 : 0; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: @@ -214,19 +283,31 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; + default: + return NullType.getFloatNull(); } + } - return 0; + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setDoubleValue(int colIndex, double value) { + setDouble(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setDouble(int col, double value) { data.set(col, value); } - public double getDouble(int col, int srcType) { - Object obj = data.get(col); + public double getDouble(int col, int nativeType) { + Object obj = data.get(col - 1); + if (obj == null) + return NullType.getDoubleNull(); - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj) ? 1 : 0; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: @@ -242,16 +323,46 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; + default: + return NullType.getDoubleNull(); } + } - return 0; + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setStringValue(int colIndex, String value) { + data.set(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setString(int col, String value) { - data.set(col, value); + // TODO: + // !!!NOTE!!! + // this is very confusing problem which related to JNI-method implementation, + // the JNI method return a String(encoded in UTF) for BINARY value, which means the JNI method will invoke + // this setString(int, String) to handle BINARY value, we need to build a byte[] with default charsetEncoding + data.set(col, value == null ? null : value.getBytes()); + } + + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setByteArrayValue(int colIndex, byte[] value) { + setByteArray(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setByteArray(int col, byte[] value) { + // TODO: + // !!!NOTE!!! + // this is very confusing problem which related to JNI-method implementation, + // the JNI method return a byte[] for NCHAR value, which means the JNI method will invoke + // this setByteArr(int, byte[]) to handle NCHAR value, we need to build a String with charsetEncoding by TaosGlobalConfig try { data.set(col, new String(value, TaosGlobalConfig.getCharset())); } catch (Exception e) { @@ -259,47 +370,56 @@ public class TSDBResultSetRowData { } } - /** - * The original type may not be a string type, but will be converted to by calling this method - * - * @param col column index - * @return - */ - public String getString(int col, int srcType) { - switch (srcType) { - case TSDBConstants.TSDB_DATA_TYPE_BINARY: - case TSDBConstants.TSDB_DATA_TYPE_NCHAR: - return (String) data.get(col); + public String getString(int col, int nativeType) { + Object obj = data.get(col - 1); + if (obj == null) + return null; + + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: { - Byte value = new Byte(String.valueOf(data.get(col))); + Byte value = new Byte(String.valueOf(obj)); if (value >= 0) return value.toString(); return Integer.toString(value & 0xff); } case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: { - Short value = new Short(String.valueOf(data.get(col))); + Short value = new Short(String.valueOf(obj)); if (value >= 0) return value.toString(); return Integer.toString(value & 0xffff); } case TSDBConstants.TSDB_DATA_TYPE_UINT: { - Integer value = new Integer(String.valueOf(data.get(col))); + Integer value = new Integer(String.valueOf(obj)); if (value >= 0) return value.toString(); return Long.toString(value & 0xffffffffl); } case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { - Long value = new Long(String.valueOf(data.get(col))); + Long value = new Long(String.valueOf(obj)); if (value >= 0) return value.toString(); long lowValue = value & 0x7fffffffffffffffL; return BigDecimal.valueOf(lowValue).add(BigDecimal.valueOf(Long.MAX_VALUE)).add(BigDecimal.valueOf(1)).toString(); } + case TSDBConstants.TSDB_DATA_TYPE_BINARY: + return new String((byte[]) obj); + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + return (String) obj; default: - return String.valueOf(data.get(col)); + return String.valueOf(obj); } } + /** + * $$$ 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); + } + + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setTimestamp(int col, long ts) { //TODO: this implementation contains logical error // when precision is us the (long ts) is 16 digital number @@ -316,28 +436,20 @@ public class TSDBResultSetRowData { } } - public Timestamp getTimestamp(int col) { - return (Timestamp) data.get(col); - } - - public Object get(int col) { - return data.get(col); - } - - public int getColSize() { - return colSize; - } - - private void setColSize(int colSize) { - this.colSize = colSize; - this.clear(); + public Timestamp getTimestamp(int col, int nativeType) { + Object obj = data.get(col - 1); + if (obj == null) + return null; + switch (nativeType) { + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: + return new Timestamp((Long) obj); + default: + return (Timestamp) obj; + } } - public ArrayList getData() { - return data; + public Object getObject(int col) { + return data.get(col - 1); } - public void setData(ArrayList data) { - this.data = (ArrayList) data.clone(); - } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index d8ba67576d069a6aec0a5bb17e9549e41b8cf31e..e1ebc4ab3cf498168181dbea08a3ac28194a5c7d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -32,14 +32,15 @@ public class TSDBStatement extends AbstractStatement { } public ResultSet executeQuery(String sql) throws SQLException { - // check if closed if (isClosed()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); } - - //TODO: 如果在executeQuery方法中执行insert语句,那么先执行了SQL,再通过pSql来检查是否为一个insert语句,但这个insert SQL已经执行成功了 - - // execute query + //TODO: + // this is an unreasonable implementation, if the paratemer is a insert statement, + // the JNI connector will execute the sql at first and return a pointer: pSql, + // we use this pSql and invoke the isUpdateQuery(long pSql) method to decide . + // but the insert sql is already executed in database. + //execute query long pSql = this.connection.getConnector().executeQuery(sql); // if pSql is create/insert/update/delete/alter SQL if (this.connection.getConnector().isUpdateQuery(pSql)) { 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 eeb936a1d0843c56e0de63a6c4b113fb644b778f..8ab610fec6541e96d8b4b997c6883dddc01f1549 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 @@ -95,16 +95,7 @@ public class Utils { public static String getNativeSql(String rawSql, Object[] parameters) { // toLowerCase String preparedSql = rawSql.trim().toLowerCase(); - - String[] clause = new String[0]; - if (SqlSyntaxValidator.isInsertSql(preparedSql)) { - // insert or import - clause = new String[]{"values\\s*\\(.*?\\)", "tags\\s*\\(.*?\\)"}; - } - if (SqlSyntaxValidator.isSelectSql(preparedSql)) { - // select - clause = new String[]{"where\\s*.*"}; - } + String[] clause = new String[]{"values\\s*\\(.*?\\)", "tags\\s*\\(.*?\\)", "where\\s*.*"}; Map placeholderPositions = new HashMap<>(); RangeSet clauseRangeSet = TreeRangeSet.create(); findPlaceholderPosition(preparedSql, placeholderPositions); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java index ca7251bb0eac306d6a21872699918e18b2447e6e..dc6d0d322af5c90dc0eb9d42328c9864714838a1 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java @@ -32,20 +32,34 @@ public class TSDBConnectionTest { } @Test - public void subscribe() { + public void runSubscribe() { try { + // given TSDBConnection unwrap = conn.unwrap(TSDBConnection.class); TSDBSubscribe subscribe = unwrap.subscribe("topic1", "select * from log.log", false); + // when TSDBResultSet rs = subscribe.consume(); ResultSetMetaData metaData = rs.getMetaData(); - for (int count = 0; count < 10 && rs.next(); count++) { - for (int i = 1; i <= metaData.getColumnCount(); i++) { - String value = rs.getString(i); - System.out.print(metaData.getColumnLabel(i) + ":" + value + "\t"); - } - System.out.println(); - } + + // then Assert.assertNotNull(rs); + Assert.assertEquals(4, metaData.getColumnCount()); + Assert.assertEquals("ts", metaData.getColumnLabel(1)); + Assert.assertEquals("level", metaData.getColumnLabel(2)); + Assert.assertEquals("content", metaData.getColumnLabel(3)); + Assert.assertEquals("ipaddr", metaData.getColumnLabel(4)); + rs.next(); + // row 1 + { + Assert.assertNotNull(rs.getTimestamp(1)); + Assert.assertNotNull(rs.getTimestamp("ts")); + Assert.assertNotNull(rs.getByte(2)); + Assert.assertNotNull(rs.getByte("level")); + Assert.assertNotNull(rs.getString(3)); + Assert.assertNotNull(rs.getString("content")); + Assert.assertNotNull(rs.getString(4)); + Assert.assertNotNull(rs.getString("ipaddr")); + } subscribe.close(false); } catch (SQLException e) { e.printStackTrace(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java index a7657fa3e581c96cf85555b16fca5f8b4c7f8ebb..cb6133015c0256de99ea4db02bedeb982ce7491d 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java @@ -7,9 +7,11 @@ import java.util.Properties; public class TSDBDatabaseMetaDataTest { private static final String host = "127.0.0.1"; + private static final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; private static Connection connection; private static TSDBDatabaseMetaData metaData; + @Test public void unwrap() throws SQLException { TSDBDatabaseMetaData unwrap = metaData.unwrap(TSDBDatabaseMetaData.class); @@ -33,7 +35,7 @@ public class TSDBDatabaseMetaDataTest { @Test public void getURL() throws SQLException { - Assert.assertEquals("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", metaData.getURL()); + Assert.assertEquals(url, metaData.getURL()); } @Test @@ -627,17 +629,32 @@ public class TSDBDatabaseMetaDataTest { @Test public void getTables() throws SQLException { - System.out.println("****************************************************"); - ResultSet tables = metaData.getTables("log", "", null, null); - ResultSetMetaData metaData = tables.getMetaData(); - while (tables.next()) { - System.out.print(metaData.getColumnLabel(1) + ":" + tables.getString(1) + "\t"); - System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t"); - System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t"); - System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n"); + ResultSet rs = metaData.getTables("log", "", null, null); + ResultSetMetaData meta = rs.getMetaData(); + Assert.assertNotNull(rs); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_SCHEM + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertNotNull(rs.getString(3)); + Assert.assertNotNull(rs.getString("TABLE_NAME")); + // TABLE_TYPE + Assert.assertEquals("TABLE_TYPE", meta.getColumnLabel(4)); + Assert.assertEquals("TABLE", rs.getString(4)); + Assert.assertEquals("TABLE", rs.getString("TABLE_TYPE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(5)); + Assert.assertEquals("", rs.getString(5)); + Assert.assertEquals("", rs.getString("REMARKS")); } - System.out.println(); - Assert.assertNotNull(tables); } @Test @@ -647,46 +664,130 @@ public class TSDBDatabaseMetaDataTest { @Test public void getCatalogs() throws SQLException { - System.out.println("****************************************************"); - - ResultSet catalogs = metaData.getCatalogs(); - ResultSetMetaData meta = catalogs.getMetaData(); - while (catalogs.next()) { - for (int i = 1; i <= meta.getColumnCount(); i++) { - System.out.print(meta.getColumnLabel(i) + ": " + catalogs.getString(i)); - } - System.out.println(); + ResultSet rs = metaData.getCatalogs(); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertNotNull(rs.getString(1)); + Assert.assertNotNull(rs.getString("TABLE_CAT")); } } @Test public void getTableTypes() throws SQLException { - System.out.println("****************************************************"); - ResultSet tableTypes = metaData.getTableTypes(); - while (tableTypes.next()) { - System.out.println(tableTypes.getString("TABLE_TYPE")); + tableTypes.next(); + // tableTypes: table + { + Assert.assertEquals("TABLE", tableTypes.getString(1)); + Assert.assertEquals("TABLE", tableTypes.getString("TABLE_TYPE")); + } + tableTypes.next(); + // tableTypes: stable + { + Assert.assertEquals("STABLE", tableTypes.getString(1)); + Assert.assertEquals("STABLE", tableTypes.getString("TABLE_TYPE")); } - Assert.assertNotNull(metaData.getTableTypes()); } @Test public void getColumns() throws SQLException { - System.out.println("****************************************************"); - + // when ResultSet columns = metaData.getColumns("log", "", "dn", ""); + // then ResultSetMetaData meta = columns.getMetaData(); - while (columns.next()) { - System.out.print(meta.getColumnLabel(1) + ": " + columns.getString(1) + "\t"); - System.out.print(meta.getColumnLabel(3) + ": " + columns.getString(3) + "\t"); - System.out.print(meta.getColumnLabel(4) + ": " + columns.getString(4) + "\t"); - System.out.print(meta.getColumnLabel(5) + ": " + columns.getString(5) + "\t"); - System.out.print(meta.getColumnLabel(6) + ": " + columns.getString(6) + "\t"); - System.out.print(meta.getColumnLabel(7) + ": " + columns.getString(7) + "\t"); - System.out.print(meta.getColumnLabel(9) + ": " + columns.getString(9) + "\t"); - System.out.print(meta.getColumnLabel(10) + ": " + columns.getString(10) + "\t"); - System.out.print(meta.getColumnLabel(11) + ": " + columns.getString(11) + "\n"); - System.out.print(meta.getColumnLabel(12) + ": " + columns.getString(12) + "\n"); + columns.next(); + // column: 1 + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", columns.getString(1)); + Assert.assertEquals("log", columns.getString("TABLE_CAT")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn", columns.getString(3)); + Assert.assertEquals("dn", columns.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("ts", columns.getString(4)); + Assert.assertEquals("ts", columns.getString("COLUMN_NAME")); + // DATA_TYPE + Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5)); + Assert.assertEquals(Types.TIMESTAMP, columns.getInt(5)); + Assert.assertEquals(Types.TIMESTAMP, columns.getInt("DATA_TYPE")); + // TYPE_NAME + Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("TIMESTAMP", columns.getString(6)); + Assert.assertEquals("TIMESTAMP", columns.getString("TYPE_NAME")); + // COLUMN_SIZE + Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7)); + Assert.assertEquals(26, columns.getInt(7)); + Assert.assertEquals(26, columns.getInt("COLUMN_SIZE")); + // DECIMAL_DIGITS + Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS")); + Assert.assertEquals(null, columns.getString(9)); + Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS")); + // NUM_PREC_RADIX + Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10)); + Assert.assertEquals(10, columns.getInt(10)); + Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX")); + // NULLABLE + Assert.assertEquals("NULLABLE", meta.getColumnLabel(11)); + Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt(11)); + Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt("NULLABLE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(12)); + Assert.assertEquals(null, columns.getString(12)); + Assert.assertEquals(null, columns.getString("REMARKS")); + } + columns.next(); + // column: 2 + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", columns.getString(1)); + Assert.assertEquals("log", columns.getString("TABLE_CAT")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn", columns.getString(3)); + Assert.assertEquals("dn", columns.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("cpu_taosd", columns.getString(4)); + Assert.assertEquals("cpu_taosd", columns.getString("COLUMN_NAME")); + // DATA_TYPE + Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5)); + Assert.assertEquals(Types.FLOAT, columns.getInt(5)); + Assert.assertEquals(Types.FLOAT, columns.getInt("DATA_TYPE")); + // TYPE_NAME + Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("FLOAT", columns.getString(6)); + Assert.assertEquals("FLOAT", columns.getString("TYPE_NAME")); + // COLUMN_SIZE + Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7)); + Assert.assertEquals(12, columns.getInt(7)); + Assert.assertEquals(12, columns.getInt("COLUMN_SIZE")); + // DECIMAL_DIGITS + Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS")); + Assert.assertEquals(null, columns.getString(9)); + Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS")); + // NUM_PREC_RADIX + Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10)); + Assert.assertEquals(10, columns.getInt(10)); + Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX")); + // NULLABLE + Assert.assertEquals("NULLABLE", meta.getColumnLabel(11)); + Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt(11)); + Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt("NULLABLE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(12)); + Assert.assertEquals(null, columns.getString(12)); } } @@ -712,17 +813,35 @@ public class TSDBDatabaseMetaDataTest { @Test public void getPrimaryKeys() throws SQLException { - System.out.println("****************************************************"); - ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1"); - while (rs.next()) { - System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME")); - System.out.println("COLUMN_NAME: " + rs.getString("COLUMN_NAME")); - System.out.println("KEY_SEQ: " + rs.getString("KEY_SEQ")); - System.out.println("PK_NAME: " + rs.getString("PK_NAME")); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_SCHEM + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn1", rs.getString(3)); + Assert.assertEquals("dn1", rs.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("ts", rs.getString(4)); + Assert.assertEquals("ts", rs.getString("COLUMN_NAME")); + // KEY_SEQ + Assert.assertEquals("KEY_SEQ", meta.getColumnLabel(5)); + Assert.assertEquals(1, rs.getShort(5)); + Assert.assertEquals(1, rs.getShort("KEY_SEQ")); + // DATA_TYPE + Assert.assertEquals("PK_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("ts", rs.getString(6)); + Assert.assertEquals("ts", rs.getString("PK_NAME")); } - - Assert.assertNotNull(rs); } @Test @@ -847,14 +966,27 @@ public class TSDBDatabaseMetaDataTest { @Test public void getSuperTables() throws SQLException { - System.out.println("****************************************************"); - ResultSet rs = metaData.getSuperTables("log", "", "dn1"); - while (rs.next()) { - System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME")); - System.out.println("SUPERTABLE_NAME: " + rs.getString("SUPERTABLE_NAME")); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_CAT + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_CAT + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn1", rs.getString(3)); + Assert.assertEquals("dn1", rs.getString("TABLE_NAME")); + // TABLE_CAT + Assert.assertEquals("SUPERTABLE_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("dn", rs.getString(4)); + Assert.assertEquals("dn", rs.getString("SUPERTABLE_NAME")); } - Assert.assertNotNull(rs); } @Test @@ -951,15 +1083,12 @@ public class TSDBDatabaseMetaDataTest { @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); 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"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties); + connection = DriverManager.getConnection(url, properties); metaData = connection.getMetaData().unwrap(TSDBDatabaseMetaData.class); - } catch (ClassNotFoundException e) { - e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } 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 161539962da5e26e928a669083954cc0817483a2..66078ef5036d7105ae9882508b635819bac99089 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 @@ -45,9 +45,9 @@ 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(); +// System.out.println("col[" + i + "] size: " + rowData.getColSize()); +// rowData.getData().stream().forEach(col -> System.out.print(col + "\t")); +// System.out.println(); } // close resultSet code = connector.freeResultSet(pSql); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java index 12bcc4391767e129289fae0a945d048570a18bc5..83caf1bebb72ec813683b083388e51b9dab2afc9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java @@ -54,16 +54,17 @@ public class TSDBParameterMetaDataTest { @Test public void getPrecision() throws SQLException { - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(1)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(2)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(3)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(4)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(5)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(6)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(7)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(8)); - Assert.assertEquals(5, parameterMetaData_insert.getPrecision(9)); - Assert.assertEquals(5, parameterMetaData_insert.getPrecision(10)); + //create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) + Assert.assertEquals(TSDBConstants.TIMESTAMP_MS_PRECISION, parameterMetaData_insert.getPrecision(1)); + Assert.assertEquals(TSDBConstants.INT_PRECISION, parameterMetaData_insert.getPrecision(2)); + Assert.assertEquals(TSDBConstants.BIGINT_PRECISION, parameterMetaData_insert.getPrecision(3)); + Assert.assertEquals(TSDBConstants.FLOAT_PRECISION, parameterMetaData_insert.getPrecision(4)); + Assert.assertEquals(TSDBConstants.DOUBLE_PRECISION, parameterMetaData_insert.getPrecision(5)); + Assert.assertEquals(TSDBConstants.SMALLINT_PRECISION, parameterMetaData_insert.getPrecision(6)); + Assert.assertEquals(TSDBConstants.TINYINT_PRECISION, parameterMetaData_insert.getPrecision(7)); + Assert.assertEquals(TSDBConstants.BOOLEAN_PRECISION, parameterMetaData_insert.getPrecision(8)); + Assert.assertEquals("hello".getBytes().length, parameterMetaData_insert.getPrecision(9)); + Assert.assertEquals("涛思数据".length(), parameterMetaData_insert.getPrecision(10)); } @Test @@ -71,8 +72,8 @@ public class TSDBParameterMetaDataTest { Assert.assertEquals(0, parameterMetaData_insert.getScale(1)); Assert.assertEquals(0, parameterMetaData_insert.getScale(2)); Assert.assertEquals(0, parameterMetaData_insert.getScale(3)); - Assert.assertEquals(0, parameterMetaData_insert.getScale(4)); - Assert.assertEquals(0, parameterMetaData_insert.getScale(5)); + Assert.assertEquals(31, parameterMetaData_insert.getScale(4)); + Assert.assertEquals(31, parameterMetaData_insert.getScale(5)); Assert.assertEquals(0, parameterMetaData_insert.getScale(6)); Assert.assertEquals(0, parameterMetaData_insert.getScale(7)); Assert.assertEquals(0, parameterMetaData_insert.getScale(8)); @@ -124,10 +125,16 @@ public class TSDBParameterMetaDataTest { @Test public void getParameterMode() throws SQLException { - for (int i = 1; i <= parameterMetaData_insert.getParameterCount(); i++) { - int parameterMode = parameterMetaData_insert.getParameterMode(i); - Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMode); - } + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(1)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(2)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(3)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(4)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(5)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(6)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(7)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(8)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(9)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(10)); } @Test @@ -144,7 +151,6 @@ public class TSDBParameterMetaDataTest { @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) { stmt.execute("drop database if exists test_pstmt"); @@ -164,7 +170,7 @@ public class TSDBParameterMetaDataTest { pstmt_insert.setObject(7, Byte.MAX_VALUE); pstmt_insert.setObject(8, true); pstmt_insert.setObject(9, "hello".getBytes()); - pstmt_insert.setObject(10, "Hello"); + pstmt_insert.setObject(10, "涛思数据"); parameterMetaData_insert = pstmt_insert.getParameterMetaData(); pstmt_select = conn.prepareStatement(sql_select); @@ -173,7 +179,7 @@ public class TSDBParameterMetaDataTest { pstmt_select.setInt(3, 0); parameterMetaData_select = pstmt_select.getParameterMetaData(); - } catch (ClassNotFoundException | SQLException e) { + } catch (SQLException e) { e.printStackTrace(); } } 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 277ca447f5efcead8cf3b1d6a3d32017aac3036d..3ad51479d6dece8d4d717a3609615b9ba2f93349 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 @@ -1,523 +1,652 @@ package com.taosdata.jdbc; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import java.io.IOException; -import java.io.Serializable; +import java.math.BigDecimal; import java.sql.*; -import java.util.ArrayList; -import java.util.Random; +import java.time.LocalTime; public class TSDBPreparedStatementTest { + private static final String host = "127.0.0.1"; private static Connection conn; private static final String sql_insert = "insert into t1 values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - private static PreparedStatement pstmt_insert; - private static final String sql_select = "select * from t1 where ts > ? and ts <= ? and f1 >= ?"; - private static PreparedStatement pstmt_select; + private static final String sql_select = "select * from t1 where ts >= ? and ts < ? and f1 >= ?"; + + private PreparedStatement pstmt_insert; + private PreparedStatement pstmt_select; + //create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64)) @Test public void executeQuery() throws SQLException { - long end = System.currentTimeMillis(); - long start = end - 1000 * 60 * 60; + // given + long ts = System.currentTimeMillis(); + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setInt(2, 2); + pstmt_insert.setLong(3, 3l); + pstmt_insert.setFloat(4, 3.14f); + pstmt_insert.setDouble(5, 3.1415); + pstmt_insert.setShort(6, (short) 6); + pstmt_insert.setByte(7, (byte) 7); + pstmt_insert.setBoolean(8, true); + pstmt_insert.setBytes(9, "abc".getBytes()); + pstmt_insert.setString(10, "涛思数据"); + pstmt_insert.executeUpdate(); + long start = ts - 1000 * 60 * 60; + long end = ts + 1000 * 60 * 60; pstmt_select.setTimestamp(1, new Timestamp(start)); pstmt_select.setTimestamp(2, new Timestamp(end)); pstmt_select.setInt(3, 0); + // when ResultSet rs = pstmt_select.executeQuery(); - Assert.assertNotNull(rs); ResultSetMetaData meta = rs.getMetaData(); - while (rs.next()) { - for (int i = 1; i <= meta.getColumnCount(); i++) { - System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t"); - } - System.out.println(); + rs.next(); + + // then + assertMetaData(meta); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(2, rs.getInt(2)); + Assert.assertEquals(2, rs.getInt("f1")); + Assert.assertEquals(3l, rs.getLong(3)); + Assert.assertEquals(3l, rs.getLong("f2")); + Assert.assertEquals(3.14f, rs.getFloat(4), 0.0); + Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0); + Assert.assertEquals(3.1415, rs.getDouble(5), 0.0); + Assert.assertEquals(3.1415, rs.getDouble("f4"), 0.0); + Assert.assertEquals((short) 6, rs.getShort(6)); + Assert.assertEquals((short) 6, rs.getShort("f5")); + Assert.assertEquals((byte) 7, rs.getByte(7)); + Assert.assertEquals((byte) 7, rs.getByte("f6")); + Assert.assertTrue(rs.getBoolean(8)); + Assert.assertTrue(rs.getBoolean("f7")); + Assert.assertArrayEquals("abc".getBytes(), rs.getBytes(9)); + Assert.assertArrayEquals("abc".getBytes(), rs.getBytes("f8")); + Assert.assertEquals("涛思数据", rs.getString(10)); + Assert.assertEquals("涛思数据", rs.getString("f9")); } } - @Test - public void executeUpdate() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setFloat(4, 3.14f); - int result = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, result); + private void assertMetaData(ResultSetMetaData meta) throws SQLException { + Assert.assertEquals(10, meta.getColumnCount()); + Assert.assertEquals("ts", meta.getColumnLabel(1)); + Assert.assertEquals("f1", meta.getColumnLabel(2)); + Assert.assertEquals("f2", meta.getColumnLabel(3)); + Assert.assertEquals("f3", meta.getColumnLabel(4)); + Assert.assertEquals("f4", meta.getColumnLabel(5)); + Assert.assertEquals("f5", meta.getColumnLabel(6)); + Assert.assertEquals("f6", meta.getColumnLabel(7)); + Assert.assertEquals("f7", meta.getColumnLabel(8)); + Assert.assertEquals("f8", meta.getColumnLabel(9)); + Assert.assertEquals("f9", meta.getColumnLabel(10)); } @Test - public void setNull() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + public void setNullForTimestamp() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(2, Types.INTEGER); int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + private void assertAllNullExceptTimestamp(ResultSet rs, long ts) throws SQLException { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(0, rs.getInt(2)); + Assert.assertEquals(0, rs.getInt("f1")); + Assert.assertEquals(0, rs.getLong(3)); + Assert.assertEquals(0, rs.getLong("f2")); + Assert.assertEquals(0, rs.getFloat(4), 0.0); + Assert.assertEquals(0, rs.getFloat("f3"), 0.0); + Assert.assertEquals(0, rs.getDouble(5), 0.0); + Assert.assertEquals(0, rs.getDouble("f4"), 0.0); + Assert.assertEquals(0, rs.getShort(6)); + Assert.assertEquals(0, rs.getShort("f5")); + Assert.assertEquals(0, rs.getByte(7)); + Assert.assertEquals(0, rs.getByte("f6")); + Assert.assertFalse(rs.getBoolean(8)); + Assert.assertFalse(rs.getBoolean("f7")); + Assert.assertNull(rs.getBytes(9)); + Assert.assertNull(rs.getBytes("f8")); + Assert.assertNull(rs.getString(10)); + Assert.assertNull(rs.getString("f9")); + } + + @Test + public void setNullForInteger() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(3, Types.BIGINT); - result = pstmt_insert.executeUpdate(); + int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + @Test + public void setNullForFloat() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(4, Types.FLOAT); - result = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, result); + int result = pstmt_insert.executeUpdate(); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setNull(5, Types.DOUBLE); - result = pstmt_insert.executeUpdate(); + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setNull(6, Types.SMALLINT); - result = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, result); + @Test + public void setNullForDouble() throws SQLException { + // given + long ts = System.currentTimeMillis(); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setNull(7, Types.TINYINT); - result = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, result); + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setNull(5, Types.DOUBLE); + int result = pstmt_insert.executeUpdate(); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setNull(8, Types.BOOLEAN); - result = pstmt_insert.executeUpdate(); + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setNull(9, Types.BINARY); - result = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, result); + @Test + public void setNullForSmallInt() throws SQLException { + // given + long ts = System.currentTimeMillis(); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setNull(10, Types.NCHAR); - result = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, result); + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setNull(6, Types.SMALLINT); + int result = pstmt_insert.executeUpdate(); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setNull(10, Types.OTHER); - result = pstmt_insert.executeUpdate(); + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } } @Test - public void executeTest() throws SQLException { - Statement stmt = conn.createStatement(); - - int numOfRows = 1000; - - 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))"); - - 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++) { - 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) { - s2.add(null); - }else{ - s2.add("分支" + i % 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) { - s3.add(null); - }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) { - s4.add(null); - }else{ - s4.add(r.nextDouble()); - } - } - s.setDouble(3, s4); - - random = 10 + r.nextInt(5); - ArrayList ts2 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { - ts2.add(null); - }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) { - vals.add(null); - }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) { - sb.add(null); - }else{ - sb.add(i % 2 == 0 ? true : false); - } - } - s.setBoolean(6, sb); - - random = 10 + r.nextInt(5); - ArrayList s5 = new ArrayList(); - for(int i = 0; i < numOfRows; i++) { - if(i % random == 0) { - s5.add(null); - }else{ - s5.add("test" + i % 10); - } - } - s.setString(7, s5, 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()) { - rows++; - } - Assert.assertEquals(numOfRows, rows); + public void setNullForTinyInt() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setNull(7, Types.TINYINT); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); } } @Test - public void bindDataSelectColumnTest() throws SQLException { - Statement stmt = conn.createStatement(); - - int numOfRows = 1000; - - 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))"); - - 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++) { - 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) { - s2.add(null); - }else{ - s2.add("分支" + i % 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) { - s3.add(null); - }else{ - s3.add("test" + i % 10); - } - } - 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()) { - rows++; - } - Assert.assertEquals(numOfRows, rows); + public void setNullForBoolean() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setNull(8, Types.BOOLEAN); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); } } @Test - public void bindDataWithSingleTagTest() throws SQLException { - Statement stmt = conn.createStatement(); + public void setNullForBinary() throws SQLException { + // given + long ts = System.currentTimeMillis(); - 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 + ")"); + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setNull(9, Types.BINARY); + int result = pstmt_insert.executeUpdate(); - int numOfRows = 1; - - TSDBPreparedStatement s = (TSDBPreparedStatement) conn.prepareStatement("insert into ? using weather_test tags(?) values(?, ?, ?)"); - Random r = new Random(); - s.setTableName("w1"); - - switch(type) { - case "tinyint": - case "smallint": - case "int": - case "bigint": - s.setTagInt(0, 1); - break; - case "float": - s.setTagFloat(0, 1.23f); - break; - case "double": - s.setTagDouble(0, 3.14159265); - break; - case "bool": - s.setTagBoolean(0, true); - break; - case "binary(10)": - s.setTagString(0, "test"); - break; - case "nchar(10)": - s.setTagNString(0, "test"); - break; - default: - break; - } - - - ArrayList ts = new ArrayList(); - 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); - } - 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); - } - 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()) { - rows++; - } - Assert.assertEquals(numOfRows, rows); + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); } } - @Test - 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"); - s.setTagInt(0, 1); - s.setTagString(1, "test"); - - - ArrayList ts = new ArrayList(); - 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++) { - s2.add("test" + i % 4); + public void setNullForNchar() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setNull(10, Types.NCHAR); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); } - s.setString(1, s2, 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()) { - rows++; - } - Assert.assertEquals(numOfRows, rows); - + @Test + public void createTwoSameDbTest() throws SQLException { + Statement stmt = conn.createStatement(); + + stmt.execute("create database dbtest"); + Assert.assertThrows(SQLException.class, () -> stmt.execute("create database dbtest")); } @Test public void setBoolean() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setBoolean(8, true); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertTrue(rs.getBoolean(8)); + Assert.assertTrue(rs.getBoolean("f7")); + } + } } @Test public void setByte() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setByte(7, (byte) 0x001); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals((byte) 0x001, rs.getByte(7)); + Assert.assertEquals((byte) 0x001, rs.getByte("f6")); + } + } } @Test public void setShort() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setShort(6, (short) 2); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals((short) 2, rs.getByte(6)); + Assert.assertEquals((short) 2, rs.getByte("f5")); + } + } } @Test public void setInt() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setInt(2, 10086); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(10086, rs.getInt(2)); + Assert.assertEquals(10086, rs.getInt("f1")); + } + } } @Test public void setLong() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setLong(3, Long.MAX_VALUE); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(Long.MAX_VALUE, rs.getLong(3)); + Assert.assertEquals(Long.MAX_VALUE, rs.getLong("f2")); + } + } } @Test public void setFloat() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setFloat(4, 3.14f); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(3.14f, rs.getFloat(4), 0.0f); + Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0f); + } + } } @Test public void setDouble() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setDouble(5, 3.14444); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - } + int result = pstmt_insert.executeUpdate(); - @Test(expected = SQLFeatureNotSupportedException.class) - public void setBigDecimal() throws SQLException { - pstmt_insert.setBigDecimal(1, null); + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(3.14444, rs.getDouble(5), 0.0); + Assert.assertEquals(3.14444, rs.getDouble("f4"), 0.0); + } + } } @Test - public void setString() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setString(10, "aaaa"); - boolean execute = pstmt_insert.execute(); - Assert.assertFalse(execute); + public void setBigDecimal() throws SQLException { + // given + long ts = System.currentTimeMillis(); + BigDecimal bigDecimal = new BigDecimal(3.14444); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setString(10, new Person("john", 33, true).toString()); - Assert.assertFalse(pstmt_insert.execute()); + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setBigDecimal(5, bigDecimal); + int result = pstmt_insert.executeUpdate(); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setString(10, new Person("john", 33, true).toString().replaceAll("'", "\"")); - Assert.assertFalse(pstmt_insert.execute()); + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(3.14444, rs.getDouble(5), 0.0); + Assert.assertEquals(3.14444, rs.getDouble("f4"), 0.0); + } + } } - class Person { - String name; - int age; - boolean sex; + @Test + public void setString() throws SQLException { + // given + long ts = System.currentTimeMillis(); + String f9 = "{\"name\": \"john\", \"age\": 10, \"address\": \"192.168.1.100\"}"; - public Person(String name, int age, boolean sex) { - this.name = name; - this.age = age; - this.sex = sex; - } + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setString(10, f9); + int result = pstmt_insert.executeUpdate(); - @Override - public String toString() { - return "Person{" + - "name='" + name + '\'' + - ", age=" + age + - ", sex=" + sex + - '}'; + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(f9, rs.getString(10)); + Assert.assertEquals(f9, rs.getString("f9")); + } } } @Test public void setBytes() throws SQLException, IOException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + byte[] f8 = "{\"name\": \"john\", \"age\": 10, \"address\": \"192.168.1.100\"}".getBytes(); -// ByteArrayOutputStream baos = new ByteArrayOutputStream(); -// ObjectOutputStream oos = new ObjectOutputStream(baos); -// oos.writeObject(new Person("john", 33, true)); -// oos.flush(); -// byte[] bytes = baos.toByteArray(); -// pstmt_insert.setBytes(9, bytes); + // when + pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + pstmt_insert.setBytes(9, f8); + int result = pstmt_insert.executeUpdate(); - pstmt_insert.setBytes(9, new Person("john", 33, true).toString().getBytes()); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertArrayEquals(f8, rs.getBytes(9)); + Assert.assertArrayEquals(f8, rs.getBytes("f8")); + } + } } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test public void setDate() throws SQLException { - pstmt_insert.setDate(1, new Date(System.currentTimeMillis())); + // given + long ts = new java.util.Date().getTime(); + + // when + pstmt_insert.setDate(1, new Date(ts)); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + } + } } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test public void setTime() throws SQLException { - pstmt_insert.setTime(1, new Time(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTime(1, new Time(ts)); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + } + } } @Test public void setTimestamp() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + } + } } @Test(expected = SQLFeatureNotSupportedException.class) @@ -530,72 +659,6 @@ public class TSDBPreparedStatementTest { pstmt_insert.setBinaryStream(1, null); } - @Test - public void clearParameters() throws SQLException { - pstmt_insert.clearParameters(); - } - - @Test - public void setObject() throws SQLException { - pstmt_insert.setObject(1, new Timestamp(System.currentTimeMillis())); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(2, 111); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(3, Long.MAX_VALUE); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(4, 3.14159265354f); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(5, Double.MAX_VALUE); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(6, Short.MAX_VALUE); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(7, Byte.MAX_VALUE); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(8, true); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(9, "hello".getBytes()); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(10, "Hello"); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - } - - @Test - public void execute() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - executeQuery(); - } - @Test(expected = SQLFeatureNotSupportedException.class) public void setCharacterStream() throws SQLException { pstmt_insert.setCharacterStream(1, null); @@ -621,9 +684,17 @@ public class TSDBPreparedStatementTest { pstmt_insert.setArray(1, null); } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test public void getMetaData() throws SQLException { - pstmt_insert.getMetaData(); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + ResultSetMetaData metaData = pstmt_insert.getMetaData(); + + // then + Assert.assertNull(metaData); } @Test(expected = SQLFeatureNotSupportedException.class) @@ -633,9 +704,46 @@ public class TSDBPreparedStatementTest { @Test public void getParameterMetaData() throws SQLException { + // given + long ts = System.currentTimeMillis(); + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setInt(2, 2); + pstmt_insert.setLong(3, 3l); + pstmt_insert.setFloat(4, 3.14f); + pstmt_insert.setDouble(5, 3.1415); + pstmt_insert.setShort(6, (short) 6); + pstmt_insert.setByte(7, (byte) 7); + pstmt_insert.setBoolean(8, true); + pstmt_insert.setBytes(9, "abc".getBytes()); + pstmt_insert.setString(10, "涛思数据"); + + // when ParameterMetaData parameterMetaData = pstmt_insert.getParameterMetaData(); + + // then Assert.assertNotNull(parameterMetaData); - //TODO: modify the test case + Assert.assertEquals(10, parameterMetaData.getParameterCount()); + Assert.assertEquals(Types.TIMESTAMP, parameterMetaData.getParameterType(1)); + Assert.assertEquals(Types.INTEGER, parameterMetaData.getParameterType(2)); + Assert.assertEquals(Types.BIGINT, parameterMetaData.getParameterType(3)); + Assert.assertEquals(Types.FLOAT, parameterMetaData.getParameterType(4)); + Assert.assertEquals(Types.DOUBLE, parameterMetaData.getParameterType(5)); + Assert.assertEquals(Types.SMALLINT, parameterMetaData.getParameterType(6)); + Assert.assertEquals(Types.TINYINT, parameterMetaData.getParameterType(7)); + Assert.assertEquals(Types.BOOLEAN, parameterMetaData.getParameterType(8)); + Assert.assertEquals(Types.BINARY, parameterMetaData.getParameterType(9)); + Assert.assertEquals(Types.NCHAR, parameterMetaData.getParameterType(10)); + + Assert.assertEquals("TIMESTAMP", parameterMetaData.getParameterTypeName(1)); + Assert.assertEquals("INT", parameterMetaData.getParameterTypeName(2)); + Assert.assertEquals("BIGINT", parameterMetaData.getParameterTypeName(3)); + Assert.assertEquals("FLOAT", parameterMetaData.getParameterTypeName(4)); + Assert.assertEquals("DOUBLE", parameterMetaData.getParameterTypeName(5)); + Assert.assertEquals("SMALLINT", parameterMetaData.getParameterTypeName(6)); + Assert.assertEquals("TINYINT", parameterMetaData.getParameterTypeName(7)); + Assert.assertEquals("BOOL", parameterMetaData.getParameterTypeName(8)); + Assert.assertEquals("BINARY", parameterMetaData.getParameterTypeName(9)); + Assert.assertEquals("NCHAR", parameterMetaData.getParameterTypeName(10)); } @Test(expected = SQLFeatureNotSupportedException.class) @@ -643,9 +751,9 @@ public class TSDBPreparedStatementTest { pstmt_insert.setRowId(1, null); } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test public void setNString() throws SQLException { - pstmt_insert.setNString(1, null); + setString(); } @Test(expected = SQLFeatureNotSupportedException.class) @@ -663,22 +771,45 @@ public class TSDBPreparedStatementTest { pstmt_insert.setSQLXML(1, null); } + @Before + public void before() { + try { + Statement stmt = conn.createStatement(); + stmt.execute("drop table if exists weather"); + stmt.execute("create table if not exists weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"); + stmt.execute("create table if not exists t1 using weather tags('beijing')"); + stmt.close(); + + pstmt_insert = conn.prepareStatement(sql_insert); + pstmt_select = conn.prepareStatement(sql_select); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @After + public void after() { + try { + if (pstmt_insert != null) + pstmt_insert.close(); + if (pstmt_select != null) + pstmt_select.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + } @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); 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("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"); - stmt.execute("create table t1 using weather tags('beijing')"); } - pstmt_insert = conn.prepareStatement(sql_insert); - pstmt_select = conn.prepareStatement(sql_select); - } catch (ClassNotFoundException | SQLException e) { + } catch (SQLException e) { e.printStackTrace(); } } @@ -686,10 +817,6 @@ public class TSDBPreparedStatementTest { @AfterClass public static void afterClass() { try { - if (pstmt_insert != null) - pstmt_insert.close(); - if (pstmt_select != null) - pstmt_select.close(); if (conn != null) conn.close(); } catch (SQLException e) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java index f304fd687406ccf919ea1b1e457cd218239e765f..31ee35899c57c074ac5a5012b542b9710d6816d4 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java @@ -14,6 +14,7 @@ import java.math.BigDecimal; import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Arrays; public class TSDBResultSetTest { @@ -133,7 +134,7 @@ public class TSDBResultSetTest { Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f); byte[] f6 = rs.getBytes("f6"); - Assert.assertEquals("abc", new String(f6)); + Assert.assertTrue(Arrays.equals("abc".getBytes(), f6)); byte[] f7 = rs.getBytes("f7"); Assert.assertEquals((short) 10, Shorts.fromByteArray(f7)); @@ -176,8 +177,7 @@ public class TSDBResultSetTest { rs.getAsciiStream("f1"); } - @SuppressWarnings("deprecation") - @Test(expected = SQLFeatureNotSupportedException.class) + @Test(expected = SQLFeatureNotSupportedException.class) public void getUnicodeStream() throws SQLException { rs.getUnicodeStream("f1"); } @@ -646,7 +646,6 @@ public class TSDBResultSetTest { @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); stmt = conn.createStatement(); stmt.execute("create database if not exists restful_test"); @@ -656,10 +655,9 @@ public class TSDBResultSetTest { stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"); rs = stmt.executeQuery("select * from restful_test.weather"); rs.next(); - } catch (ClassNotFoundException | SQLException e) { + } catch (SQLException e) { e.printStackTrace(); } - } @AfterClass diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java index 671551c42639620b09ace1ae315da6f25ea278d4..51535bc886aa0c3114a5a5bb74190300977a9ec9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java @@ -387,15 +387,12 @@ public class TSDBStatementTest { @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); 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("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties); stmt = conn.createStatement(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java index a052fbbdcbc241a18cb7dd73b8b4ade053533541..85007db0e555634b25dee4f10446b1041bf19b21 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java @@ -10,6 +10,7 @@ import java.sql.*; import java.util.Properties; public class RestfulDatabaseMetaDataTest { + private static final String host = "127.0.0.1"; private static final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; private static Connection connection; @@ -632,17 +633,32 @@ public class RestfulDatabaseMetaDataTest { @Test public void getTables() throws SQLException { - System.out.println("****************************************************"); - ResultSet tables = metaData.getTables("log", "", null, null); - ResultSetMetaData metaData = tables.getMetaData(); - while (tables.next()) { - System.out.print(metaData.getColumnLabel(1) + ":" + tables.getString(1) + "\t"); - System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t"); - System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t"); - System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n"); + ResultSet rs = metaData.getTables("log", "", null, null); + ResultSetMetaData meta = rs.getMetaData(); + Assert.assertNotNull(rs); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_SCHEM + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertNotNull(rs.getString(3)); + Assert.assertNotNull(rs.getString("TABLE_NAME")); + // TABLE_TYPE + Assert.assertEquals("TABLE_TYPE", meta.getColumnLabel(4)); + Assert.assertEquals("TABLE", rs.getString(4)); + Assert.assertEquals("TABLE", rs.getString("TABLE_TYPE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(5)); + Assert.assertEquals("", rs.getString(5)); + Assert.assertEquals("", rs.getString("REMARKS")); } - System.out.println(); - Assert.assertNotNull(tables); } @Test @@ -652,46 +668,130 @@ public class RestfulDatabaseMetaDataTest { @Test public void getCatalogs() throws SQLException { - System.out.println("****************************************************"); - - ResultSet catalogs = metaData.getCatalogs(); - ResultSetMetaData meta = catalogs.getMetaData(); - while (catalogs.next()) { - for (int i = 1; i <= meta.getColumnCount(); i++) { - System.out.print(meta.getColumnLabel(i) + ": " + catalogs.getString(i)); - } - System.out.println(); + ResultSet rs = metaData.getCatalogs(); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertNotNull(rs.getString(1)); + Assert.assertNotNull(rs.getString("TABLE_CAT")); } } @Test public void getTableTypes() throws SQLException { - System.out.println("****************************************************"); - ResultSet tableTypes = metaData.getTableTypes(); - while (tableTypes.next()) { - System.out.println(tableTypes.getString("TABLE_TYPE")); + tableTypes.next(); + // tableTypes: table + { + Assert.assertEquals("TABLE", tableTypes.getString(1)); + Assert.assertEquals("TABLE", tableTypes.getString("TABLE_TYPE")); + } + tableTypes.next(); + // tableTypes: stable + { + Assert.assertEquals("STABLE", tableTypes.getString(1)); + Assert.assertEquals("STABLE", tableTypes.getString("TABLE_TYPE")); } - Assert.assertNotNull(metaData.getTableTypes()); } @Test public void getColumns() throws SQLException { - System.out.println("****************************************************"); - + // when ResultSet columns = metaData.getColumns("log", "", "dn", ""); + // then ResultSetMetaData meta = columns.getMetaData(); - while (columns.next()) { - System.out.print(meta.getColumnLabel(1) + ": " + columns.getString(1) + "\t"); - System.out.print(meta.getColumnLabel(3) + ": " + columns.getString(3) + "\t"); - System.out.print(meta.getColumnLabel(4) + ": " + columns.getString(4) + "\t"); - System.out.print(meta.getColumnLabel(5) + ": " + columns.getString(5) + "\t"); - System.out.print(meta.getColumnLabel(6) + ": " + columns.getString(6) + "\t"); - System.out.print(meta.getColumnLabel(7) + ": " + columns.getString(7) + "\t"); - System.out.print(meta.getColumnLabel(9) + ": " + columns.getString(9) + "\t"); - System.out.print(meta.getColumnLabel(10) + ": " + columns.getString(10) + "\t"); - System.out.print(meta.getColumnLabel(11) + ": " + columns.getString(11) + "\n"); - System.out.print(meta.getColumnLabel(12) + ": " + columns.getString(12) + "\n"); + columns.next(); + // column: 1 + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", columns.getString(1)); + Assert.assertEquals("log", columns.getString("TABLE_CAT")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn", columns.getString(3)); + Assert.assertEquals("dn", columns.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("ts", columns.getString(4)); + Assert.assertEquals("ts", columns.getString("COLUMN_NAME")); + // DATA_TYPE + Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5)); + Assert.assertEquals(Types.TIMESTAMP, columns.getInt(5)); + Assert.assertEquals(Types.TIMESTAMP, columns.getInt("DATA_TYPE")); + // TYPE_NAME + Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("TIMESTAMP", columns.getString(6)); + Assert.assertEquals("TIMESTAMP", columns.getString("TYPE_NAME")); + // COLUMN_SIZE + Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7)); + Assert.assertEquals(26, columns.getInt(7)); + Assert.assertEquals(26, columns.getInt("COLUMN_SIZE")); + // DECIMAL_DIGITS + Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS")); + Assert.assertEquals(null, columns.getString(9)); + Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS")); + // NUM_PREC_RADIX + Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10)); + Assert.assertEquals(10, columns.getInt(10)); + Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX")); + // NULLABLE + Assert.assertEquals("NULLABLE", meta.getColumnLabel(11)); + Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt(11)); + Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt("NULLABLE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(12)); + Assert.assertEquals(null, columns.getString(12)); + Assert.assertEquals(null, columns.getString("REMARKS")); + } + columns.next(); + // column: 2 + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", columns.getString(1)); + Assert.assertEquals("log", columns.getString("TABLE_CAT")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn", columns.getString(3)); + Assert.assertEquals("dn", columns.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("cpu_taosd", columns.getString(4)); + Assert.assertEquals("cpu_taosd", columns.getString("COLUMN_NAME")); + // DATA_TYPE + Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5)); + Assert.assertEquals(Types.FLOAT, columns.getInt(5)); + Assert.assertEquals(Types.FLOAT, columns.getInt("DATA_TYPE")); + // TYPE_NAME + Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("FLOAT", columns.getString(6)); + Assert.assertEquals("FLOAT", columns.getString("TYPE_NAME")); + // COLUMN_SIZE + Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7)); + Assert.assertEquals(12, columns.getInt(7)); + Assert.assertEquals(12, columns.getInt("COLUMN_SIZE")); + // DECIMAL_DIGITS + Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS")); + Assert.assertEquals(null, columns.getString(9)); + Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS")); + // NUM_PREC_RADIX + Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10)); + Assert.assertEquals(10, columns.getInt(10)); + Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX")); + // NULLABLE + Assert.assertEquals("NULLABLE", meta.getColumnLabel(11)); + Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt(11)); + Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt("NULLABLE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(12)); + Assert.assertEquals(null, columns.getString(12)); } } @@ -717,17 +817,35 @@ public class RestfulDatabaseMetaDataTest { @Test public void getPrimaryKeys() throws SQLException { - System.out.println("****************************************************"); - ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1"); - while (rs.next()) { - System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME")); - System.out.println("COLUMN_NAME: " + rs.getString("COLUMN_NAME")); - System.out.println("KEY_SEQ: " + rs.getString("KEY_SEQ")); - System.out.println("PK_NAME: " + rs.getString("PK_NAME")); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_SCHEM + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn1", rs.getString(3)); + Assert.assertEquals("dn1", rs.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("ts", rs.getString(4)); + Assert.assertEquals("ts", rs.getString("COLUMN_NAME")); + // KEY_SEQ + Assert.assertEquals("KEY_SEQ", meta.getColumnLabel(5)); + Assert.assertEquals(1, rs.getShort(5)); + Assert.assertEquals(1, rs.getShort("KEY_SEQ")); + // DATA_TYPE + Assert.assertEquals("PK_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("ts", rs.getString(6)); + Assert.assertEquals("ts", rs.getString("PK_NAME")); } - - Assert.assertNotNull(rs); } @Test @@ -852,14 +970,27 @@ public class RestfulDatabaseMetaDataTest { @Test public void getSuperTables() throws SQLException { - System.out.println("****************************************************"); - ResultSet rs = metaData.getSuperTables("log", "", "dn1"); - while (rs.next()) { - System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME")); - System.out.println("SUPERTABLE_NAME: " + rs.getString("SUPERTABLE_NAME")); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_CAT + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_CAT + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn1", rs.getString(3)); + Assert.assertEquals("dn1", rs.getString("TABLE_NAME")); + // TABLE_CAT + Assert.assertEquals("SUPERTABLE_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("dn", rs.getString(4)); + Assert.assertEquals("dn", rs.getString("SUPERTABLE_NAME")); } - Assert.assertNotNull(rs); } @Test diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java index 8bb2532ce82e24e4015746e04b5b2dea18f530e4..81d7f5b56c4b4e67b9573522ee031006a7e11a2b 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java @@ -54,16 +54,17 @@ public class RestfulParameterMetaDataTest { @Test public void getPrecision() throws SQLException { - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(1)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(2)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(3)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(4)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(5)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(6)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(7)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(8)); - Assert.assertEquals(5, parameterMetaData_insert.getPrecision(9)); - Assert.assertEquals(5, parameterMetaData_insert.getPrecision(10)); + //create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) + Assert.assertEquals(TSDBConstants.TIMESTAMP_MS_PRECISION, parameterMetaData_insert.getPrecision(1)); + Assert.assertEquals(TSDBConstants.INT_PRECISION, parameterMetaData_insert.getPrecision(2)); + Assert.assertEquals(TSDBConstants.BIGINT_PRECISION, parameterMetaData_insert.getPrecision(3)); + Assert.assertEquals(TSDBConstants.FLOAT_PRECISION, parameterMetaData_insert.getPrecision(4)); + Assert.assertEquals(TSDBConstants.DOUBLE_PRECISION, parameterMetaData_insert.getPrecision(5)); + Assert.assertEquals(TSDBConstants.SMALLINT_PRECISION, parameterMetaData_insert.getPrecision(6)); + Assert.assertEquals(TSDBConstants.TINYINT_PRECISION, parameterMetaData_insert.getPrecision(7)); + Assert.assertEquals(TSDBConstants.BOOLEAN_PRECISION, parameterMetaData_insert.getPrecision(8)); + Assert.assertEquals("hello".getBytes().length, parameterMetaData_insert.getPrecision(9)); + Assert.assertEquals("涛思数据".length(), parameterMetaData_insert.getPrecision(10)); } @Test @@ -71,8 +72,8 @@ public class RestfulParameterMetaDataTest { Assert.assertEquals(0, parameterMetaData_insert.getScale(1)); Assert.assertEquals(0, parameterMetaData_insert.getScale(2)); Assert.assertEquals(0, parameterMetaData_insert.getScale(3)); - Assert.assertEquals(0, parameterMetaData_insert.getScale(4)); - Assert.assertEquals(0, parameterMetaData_insert.getScale(5)); + Assert.assertEquals(31, parameterMetaData_insert.getScale(4)); + Assert.assertEquals(31, parameterMetaData_insert.getScale(5)); Assert.assertEquals(0, parameterMetaData_insert.getScale(6)); Assert.assertEquals(0, parameterMetaData_insert.getScale(7)); Assert.assertEquals(0, parameterMetaData_insert.getScale(8)); @@ -164,7 +165,7 @@ public class RestfulParameterMetaDataTest { pstmt_insert.setObject(7, Byte.MAX_VALUE); pstmt_insert.setObject(8, true); pstmt_insert.setObject(9, "hello".getBytes()); - pstmt_insert.setObject(10, "Hello"); + pstmt_insert.setObject(10, "涛思数据"); parameterMetaData_insert = pstmt_insert.getParameterMetaData(); pstmt_select = conn.prepareStatement(sql_select); diff --git a/src/connector/python/taos/cinterface.py b/src/connector/python/taos/cinterface.py index b8824327b017fc0bb7f9639942e20e72891ac808..0f690aeb27ce81d867d1727c50ba948afd9493a8 100644 --- a/src/connector/python/taos/cinterface.py +++ b/src/connector/python/taos/cinterface.py @@ -242,7 +242,7 @@ def _load_taos_linux(): def _load_taos_darwin(): - return ctypes.cDLL('libtaos.dylib') + return ctypes.CDLL('libtaos.dylib') def _load_taos_windows(): diff --git a/src/inc/taos.h b/src/inc/taos.h index d27828fc364fd795e238b33df464fdc3548b60e2..9f72945ef03f28fb54ab05f84be810a0f9d5a66a 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -124,6 +124,7 @@ int taos_stmt_add_batch(TAOS_STMT *stmt); int taos_stmt_execute(TAOS_STMT *stmt); TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt); int taos_stmt_close(TAOS_STMT *stmt); +char * taos_stmt_errstr(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res); diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 05d29daad52c2eeeeee080b411ebedf4b7e8233f..79d9029dbc1603fe145e8b12553e2d03c028ac60 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -94,7 +94,7 @@ STsdbRepo *tsdbOpenRepo(STsdbCfg *pCfg, STsdbAppH *pAppH); int tsdbCloseRepo(STsdbRepo *repo, int toCommit); int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg); int tsdbGetState(STsdbRepo *repo); - +bool tsdbInCompact(STsdbRepo *repo); // --------- TSDB TABLE DEFINITION typedef struct { uint64_t uid; // the unique table ID diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index ac453472feef4c0fc6ed856481099f20fffc64aa..fb860137f3ee612a7bfb7966c2bb245b46a35fcd 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -212,8 +212,6 @@ - - #define TK_SPACE 300 #define TK_COMMENT 301 #define TK_ILLEGAL 302 diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 6f5d407a7348b2fa7768f0266c5dcd79a6b4653f..6ab0ad95a466fedd7066ac34048e9a7ff704787e 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -625,6 +625,10 @@ static int64_t g_totalChildTables = 0; static SQueryMetaInfo g_queryInfo; static FILE * g_fpOfInsertResult = NULL; +#if _MSC_VER <= 1900 +#define __func__ __FUNCTION__ +#endif + #define debugPrint(fmt, ...) \ do { if (g_args.debug_print || g_args.verbose_print) \ fprintf(stderr, "DEBG: "fmt, __VA_ARGS__); } while(0) @@ -1209,7 +1213,6 @@ static void fetchResult(TAOS_RES *res, threadInfo* pThreadInfo) { } int totalLen = 0; - char temp[16000]; // fetch the records row by row while((row = taos_fetch_row(res))) { @@ -1220,6 +1223,7 @@ static void fetchResult(TAOS_RES *res, threadInfo* pThreadInfo) { memset(databuf, 0, 100*1024*1024); } num_rows++; + char temp[16000] = {0}; int len = taos_print_row(temp, row, fields, num_fields); len += sprintf(temp + len, "\n"); //printf("query result:%s\n", temp); diff --git a/src/os/src/detail/osString.c b/src/os/src/detail/osString.c index 2c49797d83dd4bb53b2fef69091e28be7194461e..fdc70b667e08face21554c99e2109bc49cf41cbf 100644 --- a/src/os/src/detail/osString.c +++ b/src/os/src/detail/osString.c @@ -59,6 +59,9 @@ bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len iconv_close(cd); if (len != NULL) { *len = (int32_t)(ucs4_max_len - outLeft); + if (*len < 0) { + return false; + } } return true; diff --git a/src/query/inc/qAggMain.h b/src/query/inc/qAggMain.h index 47c61fc4446973b04bd558559e0a335fb944dbd2..57e7d2982f73432b9559c4ec231cf72e9680363e 100644 --- a/src/query/inc/qAggMain.h +++ b/src/query/inc/qAggMain.h @@ -66,17 +66,19 @@ extern "C" { #define TSDB_FUNC_RATE 29 #define TSDB_FUNC_IRATE 30 #define TSDB_FUNC_TID_TAG 31 -#define TSDB_FUNC_BLKINFO 32 - -#define TSDB_FUNC_HISTOGRAM 33 -#define TSDB_FUNC_HLL 34 -#define TSDB_FUNC_MODE 35 -#define TSDB_FUNC_SAMPLE 36 -#define TSDB_FUNC_CEIL 37 -#define TSDB_FUNC_FLOOR 38 -#define TSDB_FUNC_ROUND 39 -#define TSDB_FUNC_MAVG 40 -#define TSDB_FUNC_CSUM 41 +#define TSDB_FUNC_DERIVATIVE 32 +#define TSDB_FUNC_BLKINFO 33 + + +#define TSDB_FUNC_HISTOGRAM 34 +#define TSDB_FUNC_HLL 35 +#define TSDB_FUNC_MODE 36 +#define TSDB_FUNC_SAMPLE 37 +#define TSDB_FUNC_CEIL 38 +#define TSDB_FUNC_FLOOR 39 +#define TSDB_FUNC_ROUND 40 +#define TSDB_FUNC_MAVG 41 +#define TSDB_FUNC_CSUM 42 #define TSDB_FUNCSTATE_SO 0x1u // single output #define TSDB_FUNCSTATE_MO 0x2u // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index b5b4fb58548f5067c26644cf63e0a5911b69ad8b..955dd734cf58582ecfe1bbf9871525be0ebc161c 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -113,6 +113,7 @@ typedef struct SColumnFilterElem { int16_t bytes; // column length __filter_func_t fp; SColumnFilterInfo filterInfo; + void *q; } SColumnFilterElem; typedef struct SSingleColumnFilterInfo { @@ -185,6 +186,7 @@ typedef struct SQueryAttr { bool queryBlockDist; // if query data block distribution bool stabledev; // super table stddev query bool tsCompQuery; // is tscomp query + bool diffQuery; // is diff query bool simpleAgg; bool pointInterpQuery; // point interpolation query bool needReverseScan; // need reverse scan @@ -245,6 +247,7 @@ typedef struct SQueryRuntimeEnv { void* pQueryHandle; int32_t prevGroupId; // previous executed group id + bool enableGroupData; SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file SHashObj* pResultRowHashTable; // quick locate the window object for each result char* keyBuf; // window key buffer @@ -386,6 +389,7 @@ typedef struct STableScanInfo { int64_t elapsedTime; int32_t tableIndex; + int32_t prevGroupId; // previous table group id } STableScanInfo; typedef struct STagScanInfo { @@ -460,6 +464,7 @@ typedef struct SSWindowOperatorInfo { TSKEY prevTs; // previous timestamp int32_t numOfRows; // number of rows int32_t start; // start row index + bool reptScan; // next round scan } SSWindowOperatorInfo; typedef struct SStateWindowOperatorInfo { @@ -469,7 +474,7 @@ typedef struct SStateWindowOperatorInfo { int32_t colIndex; // start row index int32_t start; char* prevData; // previous data - + bool reptScan; } SStateWindowOperatorInfo ; typedef struct SDistinctOperatorInfo { diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index 4fc252b644efab0c6bfdb97b19c3af3ef9c68920..1fd78ed324597ca338824931999bb6c1fa5e1219 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -138,6 +138,7 @@ typedef struct SQueryInfo { bool hasFilter; bool onlyTagQuery; bool orderProjectQuery; + bool diffQuery; bool stateWindow; } SQueryInfo; diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 117a2bd27f898e8c1dc38efc38fba652f4d1bc40..fbb59e4a728724fd2fc2638d6d754cf2347350b6 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -568,10 +568,8 @@ session_option(X) ::= SESSION LP ids(V) cpxName(Z) COMMA tmvar(Y) RP. { X.gap = Y; } %type windowstate_option {SWindowStateVal} -windowstate_option(X) ::= . {X.col.n = 0;} -windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP. { - X.col = V; -} +windowstate_option(X) ::= . { X.col.n = 0; X.col.z = NULL;} +windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP. { X.col = V; } %type fill_opt {SArray*} %destructor fill_opt {taosArrayDestroy($$);} diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index ba6efcabb2f0788908485d3af246a6e0855ed2a1..2fc6f332df3c4f0cbb26339c7ea1ac85b61870ba 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -161,6 +161,14 @@ typedef struct SRateInfo { bool isIRate; // true for IRate functions, false for Rate functions } SRateInfo; +typedef struct SDerivInfo { + double prevValue; // previous value + TSKEY prevTs; // previous timestamp + bool ignoreNegative;// ignore the negative value + int64_t tsWindow; // time window for derivative + bool valueSet; // the value has been set already +} SDerivInfo; + int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) { if (!isValidDataType(dataType)) { @@ -189,7 +197,9 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI *bytes = (int16_t)(dataBytes + sizeof(int16_t) + sizeof(int64_t) + sizeof(int32_t) + sizeof(int32_t) + VARSTR_HEADER_SIZE); *interBytes = 0; return TSDB_CODE_SUCCESS; - } else if (functionId == TSDB_FUNC_BLKINFO) { + } + + if (functionId == TSDB_FUNC_BLKINFO) { *type = TSDB_DATA_TYPE_BINARY; *bytes = 16384; *interBytes = 0; @@ -216,7 +226,14 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI *interBytes = POINTER_BYTES; return TSDB_CODE_SUCCESS; } - + + if (functionId == TSDB_FUNC_DERIVATIVE) { + *type = TSDB_DATA_TYPE_DOUBLE; + *bytes = sizeof(double); // this results is compressed ts data, only one byte + *interBytes = sizeof(SDerivInfo); + return TSDB_CODE_SUCCESS; + } + if (isSuperTable) { if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) { *type = TSDB_DATA_TYPE_BINARY; @@ -3393,7 +3410,7 @@ enum { }; static bool diff_function_setup(SQLFunctionCtx *pCtx) { - if (function_setup(pCtx)) { + if (!function_setup(pCtx)) { return false; } @@ -3402,16 +3419,234 @@ static bool diff_function_setup(SQLFunctionCtx *pCtx) { return false; } +static bool deriv_function_setup(SQLFunctionCtx *pCtx) { + if (!function_setup(pCtx)) { + return false; + } + + // diff function require the value is set to -1 + SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); + SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo); + + pDerivInfo->ignoreNegative = pCtx->param[1].i64; + pDerivInfo->prevTs = -1; + pDerivInfo->tsWindow = pCtx->param[0].i64; + pDerivInfo->valueSet = false; + return false; +} + +static void deriv_function(SQLFunctionCtx *pCtx) { + SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); + SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo); + + void *data = GET_INPUT_DATA_LIST(pCtx); + + int32_t notNullElems = 0; + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order); + int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1; + + TSKEY *pTimestamp = pCtx->ptsOutputBuf; + TSKEY *tsList = GET_TS_LIST(pCtx); + + double *pOutput = (double *)pCtx->pOutput; + + switch (pCtx->inputType) { + case TSDB_DATA_TYPE_INT: { + int32_t *pData = (int32_t *)data; + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + + break; + }; + + case TSDB_DATA_TYPE_BIGINT: { + int64_t *pData = (int64_t *)data; + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = (double) pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + double *pData = (double *)data; + + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + + case TSDB_DATA_TYPE_FLOAT: { + float *pData = (float *)data; + + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + + case TSDB_DATA_TYPE_SMALLINT: { + int16_t *pData = (int16_t *)data; + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + + case TSDB_DATA_TYPE_TINYINT: { + int8_t *pData = (int8_t *)data; + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + default: + 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; + } +} + +#define DIFF_IMPL(ctx, d, type) \ + do { \ + if ((ctx)->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { \ + (ctx)->param[1].nType = (ctx)->inputType; \ + *(type *)&(ctx)->param[1].i64 = *(type *)(d); \ + } else { \ + *(type *)(ctx)->pOutput = *(type *)(d) - (*(type *)(&(ctx)->param[1].i64)); \ + *(type *)(&(ctx)->param[1].i64) = *(type *)(d); \ + *(int64_t *)(ctx)->ptsOutputBuf = GET_TS_DATA(ctx, index); \ + } \ + } while (0); + // TODO difference in date column static void diff_function(SQLFunctionCtx *pCtx) { void *data = GET_INPUT_DATA_LIST(pCtx); bool isFirstBlock = (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED); - + int32_t notNullElems = 0; - + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order); int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1; - + TSKEY* pTimestamp = pCtx->ptsOutputBuf; TSKEY* tsList = GET_TS_LIST(pCtx); @@ -3419,29 +3654,19 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_INT: { int32_t *pData = (int32_t *)data; int32_t *pOutput = (int32_t *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].i64 = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); - *pTimestamp = tsList[i]; - - pOutput += 1; - pTimestamp += 1; - } else { + + 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]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].i64 = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3451,29 +3676,19 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_BIGINT: { int64_t *pData = (int64_t *)data; int64_t *pOutput = (int64_t *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].i64 = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = pData[i] - pCtx->param[1].i64; - *pTimestamp = tsList[i]; - - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = pData[i] - pCtx->param[1].i64; + + 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]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].i64 = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3483,27 +3698,19 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_DOUBLE: { double *pData = (double *)data; double *pOutput = (double *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].dKey = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = pData[i] - pCtx->param[1].dKey; - *pTimestamp = tsList[i]; - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = pData[i] - pCtx->param[1].dKey; + + 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]; - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].dKey = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3513,30 +3720,19 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_FLOAT: { float *pData = (float *)data; float *pOutput = (float *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].dKey = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = (float)(pData[i] - pCtx->param[1].dKey); - *pTimestamp = tsList[i]; - - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = (float)(pData[i] - pCtx->param[1].dKey); + + 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]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - - // keep the last value, the remain may be all null + pCtx->param[1].dKey = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3546,60 +3742,42 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_SMALLINT: { int16_t *pData = (int16_t *)data; int16_t *pOutput = (int16_t *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].i64 = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); + + 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]; - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); - *pTimestamp = tsList[i]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].i64 = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; } break; } + case TSDB_DATA_TYPE_TINYINT: { int8_t *pData = (int8_t *)data; int8_t *pOutput = (int8_t *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((char *)&pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].i64 = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); - *pTimestamp = tsList[i]; - - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); + + 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]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].i64 = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3609,7 +3787,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { default: qError("error input type"); } - + // initial value is not set yet if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED || notNullElems <= 0) { /* @@ -3619,36 +3797,24 @@ static void diff_function(SQLFunctionCtx *pCtx) { assert(pCtx->hasNull); } else { int32_t forwardStep = (isFirstBlock) ? notNullElems - 1 : notNullElems; - + GET_RES_INFO(pCtx)->numOfRes += forwardStep; } } -#define DIFF_IMPL(ctx, d, type) \ - do { \ - if ((ctx)->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { \ - (ctx)->param[1].nType = (ctx)->inputType; \ - *(type *)&(ctx)->param[1].i64 = *(type *)(d); \ - } else { \ - *(type *)(ctx)->pOutput = *(type *)(d) - (*(type *)(&(ctx)->param[1].i64)); \ - *(type *)(&(ctx)->param[1].i64) = *(type *)(d); \ - *(int64_t *)(ctx)->ptsOutputBuf = GET_TS_DATA(ctx, index); \ - } \ - } while (0); - static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) { char *pData = GET_INPUT_DATA(pCtx, index); if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { return; } - + // the output start from the second source element if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is set GET_RES_INFO(pCtx)->numOfRes += 1; } - + int32_t step = 1/*GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/; - + switch (pCtx->inputType) { case TSDB_DATA_TYPE_INT: { if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet @@ -3684,7 +3850,7 @@ static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) { default: qError("error input type"); } - + if (GET_RES_INFO(pCtx)->numOfRes > 0) { pCtx->pOutput += pCtx->outputBytes * step; pCtx->ptsOutputBuf = (char *)pCtx->ptsOutputBuf + TSDB_KEYSIZE * step; @@ -4518,8 +4684,8 @@ static bool rate_function_setup(SQLFunctionCtx *pCtx) { pInfo->correctionValue = 0; pInfo->firstKey = INT64_MIN; pInfo->lastKey = INT64_MIN; - pInfo->firstValue = INT64_MIN; - pInfo->lastValue = INT64_MIN; + pInfo->firstValue = (double) INT64_MIN; + pInfo->lastValue = (double) INT64_MIN; pInfo->hasResult = 0; pInfo->isIRate = (pCtx->functionId == TSDB_FUNC_IRATE); @@ -4606,7 +4772,7 @@ static void rate_function_f(SQLFunctionCtx *pCtx, int32_t index) { pRateInfo->lastValue = v; pRateInfo->lastKey = primaryKey[index]; - + SET_VAL(pCtx, 1, 1); // set has result flag @@ -4630,7 +4796,7 @@ static void rate_func_copy(SQLFunctionCtx *pCtx) { static void rate_finalizer(SQLFunctionCtx *pCtx) { SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SRateInfo *pRateInfo = (SRateInfo *)GET_ROWCELL_INTERBUF(pResInfo); - + if (pRateInfo->hasResult != DATA_SET_FLAG) { setNull(pCtx->pOutput, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); return; @@ -4834,6 +5000,19 @@ void generateBlockDistResult(STableBlockDist *pTableBlockDist, char* result) { min = totalBlocks > 0 ? pTableBlockDist->minRows : 0; max = totalBlocks > 0 ? pTableBlockDist->maxRows : 0; + double stdDev = 0; + if (totalBlocks > 0) { + double variance = 0; + for (int32_t i = 0; i < numSteps; i++) { + SFileBlockInfo *blockInfo = taosArrayGet(blockInfos, i); + int64_t blocks = blockInfo->numBlocksOfStep; + int32_t rows = (i * TSDB_BLOCK_DIST_STEP_ROWS + TSDB_BLOCK_DIST_STEP_ROWS / 2); + variance += blocks * (rows - avg) * (rows - avg); + } + variance = variance / totalBlocks; + stdDev = sqrt(variance); + } + double percents[] = {0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 0.95, 0.99}; int32_t percentiles[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; assert(sizeof(percents)/sizeof(double) == sizeof(percentiles)/sizeof(int32_t)); @@ -4848,12 +5027,12 @@ void generateBlockDistResult(STableBlockDist *pTableBlockDist, char* result) { "60th=[%d], 70th=[%d], 80th=[%d], 90th=[%d], 95th=[%d], 99th=[%d]\n\t " "Min=[%"PRId64"(Rows)] Max=[%"PRId64"(Rows)] Avg=[%"PRId64"(Rows)] Stddev=[%.2f] \n\t " "Rows=[%"PRIu64"], Blocks=[%"PRId64"], Size=[%.3f(Kb)] Comp=[%.2f]\n\t " - "RowsInMem=[%d] \n\t SeekHeaderTime=[%d(us)]", + "RowsInMem=[%d] \n\t", percentiles[0], percentiles[1], percentiles[2], percentiles[3], percentiles[4], percentiles[5], percentiles[6], percentiles[7], percentiles[8], percentiles[9], percentiles[10], percentiles[11], - min, max, avg, 0.0, + min, max, avg, stdDev, totalRows, totalBlocks, totalLen/1024.0, compRatio, - pTableBlockDist->numOfRowsInMemTable, pTableBlockDist->firstSeekTimeUs); + pTableBlockDist->numOfRowsInMemTable); varDataSetLen(result, sz); UNUSED(sz); } @@ -5121,7 +5300,7 @@ SAggFunctionInfo aAggs[] = {{ }, { // 17 - "ts_dummy", + "ts", TSDB_FUNC_TS_DUMMY, TSDB_FUNC_TS_DUMMY, TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS, @@ -5215,7 +5394,7 @@ SAggFunctionInfo aAggs[] = {{ "diff", TSDB_FUNC_DIFF, TSDB_FUNC_INVALID_ID, - TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_NEED_TS, + TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS, diff_function_setup, diff_function, diff_function_f, @@ -5315,8 +5494,20 @@ SAggFunctionInfo aAggs[] = {{ noop1, dataBlockRequired, }, + { //32 + "derivative", // return table id and the corresponding tags for join match and subscribe + TSDB_FUNC_DERIVATIVE, + TSDB_FUNC_INVALID_ID, + TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS, + deriv_function_setup, + deriv_function, + noop2, + doFinalizer, + noop1, + dataBlockRequired, + }, { - // 32 + // 33 "_block_dist", // return table id and the corresponding tags for join match and subscribe TSDB_FUNC_BLKINFO, TSDB_FUNC_BLKINFO, diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 698a1c749b45e23f7303c6eb186bd9d859ca8a56..9e78354c19befd0d01b5c06f44f2e3d6afc837c2 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -30,6 +30,7 @@ #define IS_MASTER_SCAN(runtime) ((runtime)->scanFlag == MASTER_SCAN) #define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN) +#define IS_REPEAT_SCAN(runtime) ((runtime)->scanFlag == REPEAT_SCAN) #define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN) #define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = REVERSE_SCAN) @@ -735,6 +736,7 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx if (pCtx[k].preAggVals.isSet && forwardStep < numOfTotal) { pCtx[k].preAggVals.isSet = false; } + if (functionNeedToExecute(pRuntimeEnv, &pCtx[k], functionId)) { aAggs[functionId].xFunction(&pCtx[k]); } @@ -918,7 +920,7 @@ void setInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SSDataBlo doSetInputDataBlockInfo(pOperator, pCtx, pBlock, order); } } else { - if (pCtx[0].pInput == NULL && pBlock->pDataBlock != NULL) { + if (/*pCtx[0].pInput == NULL && */pBlock->pDataBlock != NULL) { doSetInputDataBlock(pOperator, pCtx, pBlock, order); } else { doSetInputDataBlockInfo(pOperator, pCtx, pBlock, order); @@ -1169,7 +1171,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul SQueryRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; int32_t numOfOutput = pOperatorInfo->numOfOutput; - SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); @@ -1336,6 +1338,10 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf int64_t gap = pOperator->pRuntimeEnv->pQueryAttr->sw.gap; pInfo->numOfRows = 0; + if (IS_REPEAT_SCAN(pRuntimeEnv) && !pInfo->reptScan) { + pInfo->reptScan = true; + pInfo->prevTs = INT64_MIN; + } TSKEY* tsList = (TSKEY*)pColInfoData->pData; for (int32_t j = 0; j < pSDataBlock->info.rows; ++j) { @@ -1345,7 +1351,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf pInfo->prevTs = tsList[j]; pInfo->numOfRows = 1; pInfo->start = j; - } else if (tsList[j] - pInfo->prevTs <= gap) { + } else if (tsList[j] - pInfo->prevTs <= gap && (tsList[j] - pInfo->prevTs) >= 0) { pInfo->curWindow.ekey = tsList[j]; pInfo->prevTs = tsList[j]; pInfo->numOfRows += 1; @@ -1681,6 +1687,8 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf SQueryAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; pRuntimeEnv->prevGroupId = INT32_MIN; + pRuntimeEnv->enableGroupData = false; + pRuntimeEnv->pQueryAttr = pQueryAttr; pRuntimeEnv->pResultRowHashTable = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); @@ -2652,7 +2660,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa pTableScanInfo->rowCellInfoOffset) != TSDB_CODE_SUCCESS) { longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - } else if (pQueryAttr->stableQuery && (!pQueryAttr->tsCompQuery)) { // stable aggregate, not interval aggregate or normal column aggregate + } else if (pQueryAttr->stableQuery && (!pQueryAttr->tsCompQuery) && (!pQueryAttr->diffQuery)) { // stable aggregate, not interval aggregate or normal column aggregate doSetTableGroupOutputBuf(pRuntimeEnv, pTableScanInfo->pResultRowInfo, pTableScanInfo->pCtx, pTableScanInfo->rowCellInfoOffset, pTableScanInfo->numOfOutput, pRuntimeEnv->current->groupIndex); @@ -3092,7 +3100,7 @@ int32_t initResultRow(SResultRow *pResultRow) { * +------------+-----------------result column 1-----------+-----------------result column 2-----------+ * + SResultRow | SResultRowCellInfo | intermediate buffer1 | SResultRowCellInfo | intermediate buffer 2| * +------------+-------------------------------------------+-------------------------------------------+ - * offset[0] offset[1] + * offset[0] offset[1] offset[2] */ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, int64_t uid, int32_t stage) { SQLFunctionCtx* pCtx = pInfo->pCtx; @@ -3119,8 +3127,8 @@ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, i assert(pCtx[i].pOutput != NULL); // set the timestamp output buffer for top/bottom/diff query - int32_t functionId = pCtx[i].functionId; - if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { + int32_t fid = pCtx[i].functionId; + if (fid == TSDB_FUNC_TOP || fid == TSDB_FUNC_BOTTOM || fid == TSDB_FUNC_DIFF || fid == TSDB_FUNC_DERIVATIVE) { pCtx[i].ptsOutputBuf = pCtx[0].pOutput; } } @@ -3321,7 +3329,7 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe offset += pCtx[i].outputBytes; int32_t functionId = pCtx[i].functionId; - if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { + if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) { pCtx[i].ptsOutputBuf = pCtx[0].pOutput; } @@ -3379,7 +3387,7 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF offset += pCtx[i].outputBytes; int32_t functionId = pCtx[i].functionId; - if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { + if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) { pCtx[i].ptsOutputBuf = pCtx[0].pOutput; } @@ -3587,6 +3595,8 @@ static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo* int32_t step = -1; qDebug("QInfo:0x%"PRIx64" start to copy data from windowResInfo to output buf", GET_QID(pRuntimeEnv)); + assert(orderType == TSDB_ORDER_ASC || orderType == TSDB_ORDER_DESC); + if (orderType == TSDB_ORDER_ASC) { start = pGroupResInfo->index; step = 1; @@ -4271,6 +4281,14 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) { pRuntimeEnv->current = *pTableQueryInfo; doTableQueryInfoTimeWindowCheck(pQueryAttr, *pTableQueryInfo); + + if (pRuntimeEnv->enableGroupData) { + if(pTableScanInfo->prevGroupId != -1 && pTableScanInfo->prevGroupId != (*pTableQueryInfo)->groupIndex) { + *newgroup = true; + } + } + + pTableScanInfo->prevGroupId = (*pTableQueryInfo)->groupIndex; } // this function never returns error? @@ -4417,6 +4435,7 @@ SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pInfo->reverseTimes = 0; pInfo->order = pRuntimeEnv->pQueryAttr->order.order; pInfo->current = 0; +// pInfo->prevGroupId = -1; SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); pOperator->name = "TableScanOperator"; @@ -4439,6 +4458,8 @@ SOperatorInfo* createTableSeqScanOperator(void* pTsdbQueryHandle, SQueryRuntimeE pInfo->reverseTimes = 0; pInfo->order = pRuntimeEnv->pQueryAttr->order.order; pInfo->current = 0; + pInfo->prevGroupId = -1; + pRuntimeEnv->enableGroupData = true; SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); pOperator->name = "TableSeqScanOperator"; @@ -4543,6 +4564,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime pInfo->reverseTimes = reverseTime; pInfo->current = 0; pInfo->order = pRuntimeEnv->pQueryAttr->order.order; +// pInfo->prevGroupId = -1; SOperatorInfo* pOptr = calloc(1, sizeof(SOperatorInfo)); pOptr->name = "DataBlocksOptimizedScanOperator"; @@ -4556,7 +4578,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime } SArray* getOrderCheckColumns(SQueryAttr* pQuery) { - int32_t numOfCols = pQuery->pGroupbyExpr->numOfGroupCols; + int32_t numOfCols = pQuery->pGroupbyExpr == NULL? 0: pQuery->pGroupbyExpr->numOfGroupCols; SArray* pOrderColumns = NULL; if (numOfCols > 0) { @@ -4595,7 +4617,7 @@ SArray* getOrderCheckColumns(SQueryAttr* pQuery) { } SArray* getResultGroupCheckColumns(SQueryAttr* pQuery) { - int32_t numOfCols = pQuery->pGroupbyExpr->numOfGroupCols; + int32_t numOfCols = pQuery->pGroupbyExpr == NULL? 0 : pQuery->pGroupbyExpr->numOfGroupCols; SArray* pOrderColumns = NULL; if (numOfCols > 0) { @@ -4921,10 +4943,17 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) { } // Return result of the previous group in the firstly. - if (*newgroup && pRes->info.rows > 0) { - pArithInfo->existDataBlock = pBlock; - clearNumOfRes(pInfo->pCtx, pOperator->numOfOutput); - return pInfo->pRes; + if (*newgroup) { + if (pRes->info.rows > 0) { + pArithInfo->existDataBlock = pBlock; + clearNumOfRes(pInfo->pCtx, pOperator->numOfOutput); + return pInfo->pRes; + } else { // init output buffer for a new group data + for (int32_t j = 0; j < pOperator->numOfOutput; ++j) { + aAggs[pInfo->pCtx[j].functionId].xFinalize(&pInfo->pCtx[j]); + } + initCtxOutputBuffer(pInfo->pCtx, pOperator->numOfOutput); + } } STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; @@ -5154,6 +5183,10 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI SColumnInfoData* pTsColInfoData = taosArrayGet(pSDataBlock->pDataBlock, 0); TSKEY* tsList = (TSKEY*)pTsColInfoData->pData; + if (IS_REPEAT_SCAN(pRuntimeEnv) && !pInfo->reptScan) { + pInfo->reptScan = true; + tfree(pInfo->prevData); + } pInfo->numOfRows = 0; for (int32_t j = 0; j < pSDataBlock->info.rows; ++j) { @@ -5740,6 +5773,7 @@ SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOp SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SStateWindowOperatorInfo* pInfo = calloc(1, sizeof(SStateWindowOperatorInfo)); pInfo->colIndex = -1; + pInfo->reptScan = false; pInfo->binfo.pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8, TSDB_DATA_TYPE_INT); @@ -5767,7 +5801,8 @@ SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8, TSDB_DATA_TYPE_INT); - pInfo->prevTs = INT64_MIN; + pInfo->prevTs = INT64_MIN; + pInfo->reptScan = false; SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); pOperator->name = "SessionWindowAggOperator"; @@ -6921,6 +6956,10 @@ int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfF } pSingleColFilter->bytes = pCols[i].bytes; + + if (lower == TSDB_RELATION_IN) { + buildFilterSetFromBinary(&pSingleColFilter->q, (char *)(pSingleColFilter->filterInfo.pz), (int32_t)(pSingleColFilter->filterInfo.len)); + } } j++; @@ -6933,6 +6972,9 @@ int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfF void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols) { for (int32_t i = 0; i < numOfFilterCols; ++i) { if (pFilterInfo[i].numOfFilters > 0) { + if (pFilterInfo[i].pFilters->filterInfo.lowerRelOptr == TSDB_RELATION_IN) { + taosHashCleanup((SHashObj *)(pFilterInfo[i].pFilters->q)); + } tfree(pFilterInfo[i].pFilters); } } @@ -7185,7 +7227,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S // todo refactor pQInfo->query.queryBlockDist = (numOfOutput == 1 && pExprs[0].base.functionId == TSDB_FUNC_BLKINFO); - qDebug("qmsg:%p QInfo:0x%" PRIx64 "-%p created", pQueryMsg, pQInfo->qId, pQInfo); + qDebug("qmsg:%p vgId:%d, QInfo:0x%" PRIx64 "-%p created", pQueryMsg, pQInfo->query.vgId, pQInfo->qId, pQInfo); return pQInfo; _cleanup_qinfo: @@ -7442,7 +7484,6 @@ int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { doCopyQueryResultToMsg(pQInfo, (int32_t)pRuntimeEnv->outputBuf->info.rows, data); } - pRuntimeEnv->resultInfo.total += pRuntimeEnv->outputBuf->info.rows; qDebug("QInfo:0x%"PRIx64" current numOfRes rows:%d, total:%" PRId64, pQInfo->qId, pRuntimeEnv->outputBuf->info.rows, pRuntimeEnv->resultInfo.total); diff --git a/src/query/src/qFilterfunc.c b/src/query/src/qFilterfunc.c index dabce88423f762029a4b27dc3fb4731fd28e6406..663f8814a0d57eb8cecad7f2d62944425510f029 100644 --- a/src/query/src/qFilterfunc.c +++ b/src/query/src/qFilterfunc.c @@ -253,6 +253,27 @@ bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* bool notNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type) { return true; } +bool inOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type) { + if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { + int64_t minv = -1, maxv = -1; + GET_TYPED_DATA(minv, int64_t, type, minval); + GET_TYPED_DATA(maxv, int64_t, type, maxval); + if (minv == maxv) { + return NULL != taosHashGet((SHashObj *)pFilter->q, (char *)&minv, sizeof(minv)); + } + return true; + } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_DOUBLE) { + double v; + GET_TYPED_DATA(v, double, type, minval); + return NULL != taosHashGet((SHashObj *)pFilter->q, (char *)&v, sizeof(v)); + } else if (type == TSDB_DATA_TYPE_BINARY) { + return NULL != taosHashGet((SHashObj *)pFilter->q, varDataVal(minval), varDataLen(minval)); + } else if (type == TSDB_DATA_TYPE_NCHAR){ + return NULL != taosHashGet((SHashObj *)pFilter->q, varDataVal(minval), varDataLen(minval)); + } + + return false; +} /////////////////////////////////////////////////////////////////////////////// bool rangeFilter_ii(SColumnFilterElem *pFilter, const char *minval, const char *maxval, int16_t type) { @@ -389,6 +410,7 @@ bool (*filterOperators[])(SColumnFilterElem *pFilter, const char* minval, const likeOperator, isNullOperator, notNullOperator, + inOperator, }; bool (*rangeFilterOperators[])(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type) = { @@ -397,6 +419,7 @@ bool (*rangeFilterOperators[])(SColumnFilterElem *pFilter, const char* minval, c rangeFilter_ie, rangeFilter_ei, rangeFilter_ii, + }; __filter_func_t getFilterOperator(int32_t lowerOptr, int32_t upperOptr) { diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index 24531c7f4e6e9486cb2ad388ec50fa422606de52..ee587a515dca39559bc6d061501d4e3397c0781a 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -531,7 +531,7 @@ SArray* createTableScanPlan(SQueryAttr* pQueryAttr) { } else { if (pQueryAttr->queryBlockDist) { op = OP_TableBlockInfoScan; - } else if (pQueryAttr->tsCompQuery || pQueryAttr->pointInterpQuery) { + } else if (pQueryAttr->tsCompQuery || pQueryAttr->pointInterpQuery || pQueryAttr->diffQuery) { op = OP_TableSeqScan; } else if (pQueryAttr->needReverseScan) { op = OP_DataBlocksOptScan; @@ -605,7 +605,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { taosArrayPush(plan, &op); } } else if (pQueryAttr->simpleAgg) { - if (pQueryAttr->stableQuery && !pQueryAttr->tsCompQuery) { + if (pQueryAttr->stableQuery && !pQueryAttr->tsCompQuery && !pQueryAttr->diffQuery) { op = OP_MultiTableAggregate; } else { op = OP_Aggregate; diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index f00d5ceb41aad443911036925ef92a6fc3fd4030..38ef81e7938a3635273c0cfa2cb4e86ca2e35c1e 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -132,7 +132,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi numOfGroupByCols = 0; } - qDebug("qmsg:%p query stable, uid:%"PRId64", tid:%d", pQueryMsg, id->uid, id->tid); + qDebug("qmsg:%p query stable, uid:%"PRIu64", tid:%d", pQueryMsg, id->uid, id->tid); code = tsdbQuerySTableByTagCond(tsdb, id->uid, pQueryMsg->window.skey, param.tagCond, pQueryMsg->tagCondLen, pQueryMsg->tagNameRelType, param.tbnameCond, &tableGroupInfo, param.pGroupColIndex, numOfGroupByCols); @@ -162,7 +162,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi assert(pQueryMsg->stableQuery == isSTableQuery); (*pQInfo) = createQInfoImpl(pQueryMsg, param.pGroupbyExpr, param.pExprs, param.pSecExprs, &tableGroupInfo, - param.pTagColumnInfo, vgId, param.sql, qId); + param.pTagColumnInfo, vgId, param.sql, qId); param.sql = NULL; param.pExprs = NULL; @@ -241,15 +241,16 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId) { bool newgroup = false; pRuntimeEnv->outputBuf = pRuntimeEnv->proot->exec(pRuntimeEnv->proot, &newgroup); + pRuntimeEnv->resultInfo.total += GET_NUM_OF_RESULTS(pRuntimeEnv); if (isQueryKilled(pQInfo)) { qDebug("QInfo:0x%"PRIx64" query is killed", pQInfo->qId); } else if (GET_NUM_OF_RESULTS(pRuntimeEnv) == 0) { - qDebug("QInfo:0x%"PRIx64" over, %u tables queried, %"PRId64" rows are returned", pQInfo->qId, pRuntimeEnv->tableqinfoGroupInfo.numOfTables, + qDebug("QInfo:0x%"PRIx64" over, %u tables queried, total %"PRId64" rows returned", pQInfo->qId, pRuntimeEnv->tableqinfoGroupInfo.numOfTables, pRuntimeEnv->resultInfo.total); } else { - qDebug("QInfo:0x%"PRIx64" query paused, %d rows returned, numOfTotal:%" PRId64 " rows", - pQInfo->qId, GET_NUM_OF_RESULTS(pRuntimeEnv), pRuntimeEnv->resultInfo.total + GET_NUM_OF_RESULTS(pRuntimeEnv)); + qDebug("QInfo:0x%"PRIx64" query paused, %d rows returned, total:%" PRId64 " rows", pQInfo->qId, + GET_NUM_OF_RESULTS(pRuntimeEnv), pRuntimeEnv->resultInfo.total); } return doBuildResCheck(pQInfo); diff --git a/src/query/src/sql.c b/src/query/src/sql.c index 44428d151715708e458322c01f7893582348edd5..83deb641f51d412d7f3e4175391942623c995f7e 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -23,7 +23,6 @@ ** input grammar file: */ #include -#include /************ Begin %include sections from the grammar ************************/ #include @@ -77,10 +76,8 @@ ** zero the stack is dynamically sized using realloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument -** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter ** ParseARG_STORE Code to store %extra_argument into yypParser ** ParseARG_FETCH Code to extract %extra_argument from yypParser -** ParseCTX_* As ParseARG_ except for %extra_context ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. ** YYNSTATE the combined number of states. @@ -100,46 +97,39 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 268 +#define YYNOCODE 270 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SStrToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SCreateDbInfo yy22; - TAOS_FIELD yy47; - SRelationInfo* yy52; - SCreateAcctInfo yy83; - SSessionWindowVal yy84; - tSqlExpr* yy162; - SWindowStateVal yy176; - int yy196; - SLimitVal yy230; - SArray* yy325; - SIntervalVal yy328; - int64_t yy373; - SCreateTableSql* yy422; - tVariant yy442; - SCreatedTableInfo yy504; - SSqlNode* yy536; + SSessionWindowVal yy15; + SIntervalVal yy42; + tSqlExpr* yy68; + SCreateAcctInfo yy77; + SArray* yy93; + int yy150; + SSqlNode* yy224; + SWindowStateVal yy274; + int64_t yy279; + SLimitVal yy284; + TAOS_FIELD yy325; + SRelationInfo* yy330; + SCreateDbInfo yy372; + tVariant yy518; + SCreatedTableInfo yy528; + SCreateTableSql* yy532; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 #endif #define ParseARG_SDECL SSqlInfo* pInfo; #define ParseARG_PDECL ,SSqlInfo* pInfo -#define ParseARG_PARAM ,pInfo -#define ParseARG_FETCH SSqlInfo* pInfo=yypParser->pInfo; -#define ParseARG_STORE yypParser->pInfo=pInfo; -#define ParseCTX_SDECL -#define ParseCTX_PDECL -#define ParseCTX_PARAM -#define ParseCTX_FETCH -#define ParseCTX_STORE +#define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo +#define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 #define YYNSTATE 342 #define YYNRULE 283 -#define YYNRULE_WITH_ACTION 283 #define YYNTOKEN 189 #define YY_MAX_SHIFT 341 #define YY_MIN_SHIFTREDUCE 542 @@ -150,7 +140,6 @@ typedef union { #define YY_MIN_REDUCE 828 #define YY_MAX_REDUCE 1110 /************* End control #defines *******************************************/ -#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. @@ -215,240 +204,240 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (724) +#define YY_ACTTAB_COUNT (725) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 22, 590, 193, 999, 195, 144, 218, 339, 195, 591, - /* 10 */ 622, 826, 341, 52, 53, 1086, 56, 57, 227, 1087, - /* 20 */ 230, 46, 590, 55, 283, 60, 58, 62, 59, 964, - /* 30 */ 591, 199, 224, 51, 50, 195, 978, 49, 48, 47, + /* 0 */ 224, 590, 235, 999, 978, 144, 978, 590, 195, 591, + /* 10 */ 964, 826, 341, 52, 53, 591, 56, 57, 227, 1087, + /* 20 */ 230, 46, 246, 55, 283, 60, 58, 62, 59, 218, + /* 30 */ 339, 622, 237, 51, 50, 195, 978, 49, 48, 47, /* 40 */ 52, 53, 34, 56, 57, 226, 1087, 230, 46, 590, - /* 50 */ 55, 283, 60, 58, 62, 59, 151, 591, 235, 990, - /* 60 */ 51, 50, 978, 151, 49, 48, 47, 53, 996, 56, + /* 50 */ 55, 283, 60, 58, 62, 59, 151, 591, 976, 990, + /* 60 */ 51, 50, 228, 151, 49, 48, 47, 53, 996, 56, /* 70 */ 57, 266, 265, 230, 46, 259, 55, 283, 60, 58, - /* 80 */ 62, 59, 1083, 75, 220, 151, 51, 50, 975, 151, + /* 80 */ 62, 59, 299, 75, 220, 151, 51, 50, 975, 299, /* 90 */ 49, 48, 47, 543, 544, 545, 546, 547, 548, 549, - /* 100 */ 550, 551, 552, 553, 554, 555, 340, 246, 299, 219, - /* 110 */ 76, 52, 53, 237, 56, 57, 963, 978, 230, 46, - /* 120 */ 94, 55, 283, 60, 58, 62, 59, 1036, 990, 278, - /* 130 */ 299, 51, 50, 763, 1035, 49, 48, 47, 52, 54, - /* 140 */ 82, 56, 57, 976, 221, 230, 46, 41, 55, 283, - /* 150 */ 60, 58, 62, 59, 280, 966, 87, 874, 51, 50, - /* 160 */ 88, 178, 49, 48, 47, 325, 40, 297, 334, 333, + /* 100 */ 550, 551, 552, 553, 554, 555, 340, 6, 94, 219, + /* 110 */ 76, 52, 53, 82, 56, 57, 963, 195, 230, 46, + /* 120 */ 41, 55, 283, 60, 58, 62, 59, 1036, 1086, 278, + /* 130 */ 325, 51, 50, 763, 1035, 49, 48, 47, 52, 54, + /* 140 */ 22, 56, 57, 966, 990, 230, 46, 35, 55, 283, + /* 150 */ 60, 58, 62, 59, 280, 193, 87, 874, 51, 50, + /* 160 */ 221, 178, 49, 48, 47, 260, 40, 297, 334, 333, /* 170 */ 296, 295, 294, 332, 293, 331, 330, 329, 292, 328, /* 180 */ 327, 938, 926, 927, 928, 929, 930, 931, 932, 933, - /* 190 */ 934, 935, 936, 937, 939, 940, 56, 57, 34, 990, - /* 200 */ 230, 46, 972, 55, 283, 60, 58, 62, 59, 49, - /* 210 */ 48, 47, 23, 51, 50, 222, 977, 49, 48, 47, - /* 220 */ 229, 778, 1082, 34, 767, 769, 770, 772, 773, 204, - /* 230 */ 34, 229, 778, 335, 907, 767, 205, 770, 672, 773, - /* 240 */ 233, 128, 127, 203, 975, 1081, 236, 34, 40, 115, - /* 250 */ 334, 333, 215, 216, 325, 332, 282, 331, 330, 329, - /* 260 */ 89, 328, 327, 215, 216, 213, 315, 314, 946, 974, - /* 270 */ 944, 945, 234, 82, 77, 947, 975, 949, 950, 948, - /* 280 */ 41, 951, 952, 60, 58, 62, 59, 711, 768, 304, - /* 290 */ 771, 51, 50, 975, 590, 49, 48, 47, 34, 113, - /* 300 */ 107, 118, 591, 258, 1106, 74, 117, 123, 126, 116, - /* 310 */ 240, 696, 212, 251, 693, 120, 694, 245, 695, 5, - /* 320 */ 37, 168, 255, 254, 61, 214, 167, 101, 96, 100, - /* 330 */ 779, 34, 1, 166, 91, 61, 775, 776, 3, 179, - /* 340 */ 305, 779, 242, 243, 975, 197, 284, 775, 187, 185, - /* 350 */ 183, 744, 745, 774, 1098, 182, 131, 130, 129, 34, - /* 360 */ 708, 34, 34, 765, 774, 715, 961, 962, 33, 965, - /* 370 */ 51, 50, 198, 306, 49, 48, 47, 975, 35, 34, - /* 380 */ 241, 34, 239, 200, 303, 302, 67, 247, 8, 244, - /* 390 */ 13, 310, 309, 883, 93, 90, 260, 178, 28, 766, - /* 400 */ 777, 307, 875, 311, 312, 975, 178, 975, 975, 338, - /* 410 */ 337, 136, 142, 140, 139, 146, 64, 79, 25, 80, - /* 420 */ 697, 313, 24, 317, 262, 975, 262, 975, 24, 228, - /* 430 */ 68, 70, 194, 727, 735, 35, 736, 35, 201, 64, - /* 440 */ 799, 92, 782, 15, 64, 14, 780, 32, 202, 106, - /* 450 */ 289, 105, 44, 682, 17, 286, 16, 684, 19, 288, - /* 460 */ 18, 700, 683, 701, 112, 698, 111, 699, 73, 208, - /* 470 */ 671, 125, 124, 71, 6, 21, 1046, 20, 209, 207, - /* 480 */ 192, 206, 1045, 196, 231, 1042, 256, 143, 1041, 232, - /* 490 */ 316, 998, 1009, 1006, 1007, 1011, 1028, 145, 149, 991, - /* 500 */ 263, 141, 1027, 973, 272, 162, 163, 942, 971, 164, - /* 510 */ 165, 726, 886, 291, 42, 190, 38, 988, 300, 281, - /* 520 */ 153, 882, 152, 156, 301, 1105, 72, 103, 267, 223, - /* 530 */ 1104, 1101, 69, 169, 269, 276, 63, 308, 1097, 279, - /* 540 */ 109, 154, 277, 275, 1096, 155, 1093, 170, 273, 904, - /* 550 */ 39, 36, 43, 191, 157, 271, 871, 119, 869, 121, - /* 560 */ 122, 268, 867, 866, 248, 181, 864, 863, 862, 861, - /* 570 */ 860, 859, 184, 186, 856, 854, 852, 850, 188, 847, - /* 580 */ 189, 45, 261, 78, 83, 270, 1029, 326, 114, 318, - /* 590 */ 319, 320, 321, 322, 323, 217, 324, 238, 290, 336, - /* 600 */ 824, 249, 210, 211, 97, 98, 250, 823, 252, 253, - /* 610 */ 822, 257, 805, 804, 285, 262, 9, 173, 177, 865, - /* 620 */ 905, 171, 172, 174, 176, 175, 132, 133, 858, 906, - /* 630 */ 2, 134, 857, 4, 135, 849, 81, 848, 703, 29, - /* 640 */ 264, 84, 160, 158, 159, 161, 148, 728, 147, 85, - /* 650 */ 954, 731, 733, 86, 225, 274, 30, 737, 31, 150, - /* 660 */ 10, 11, 781, 95, 7, 12, 783, 26, 27, 287, - /* 670 */ 635, 631, 629, 93, 628, 627, 624, 594, 298, 99, - /* 680 */ 65, 35, 674, 102, 66, 673, 670, 616, 104, 614, - /* 690 */ 108, 606, 612, 608, 610, 604, 602, 638, 110, 637, + /* 190 */ 934, 935, 936, 937, 939, 940, 56, 57, 146, 990, + /* 200 */ 230, 46, 199, 55, 283, 60, 58, 62, 59, 49, + /* 210 */ 48, 47, 23, 51, 50, 222, 727, 49, 48, 47, + /* 220 */ 229, 778, 972, 883, 767, 115, 770, 178, 773, 204, + /* 230 */ 325, 229, 778, 335, 907, 767, 205, 770, 769, 773, + /* 240 */ 772, 128, 127, 203, 338, 337, 136, 15, 40, 14, + /* 250 */ 334, 333, 215, 216, 151, 332, 282, 331, 330, 329, + /* 260 */ 977, 328, 327, 215, 216, 946, 236, 944, 945, 590, + /* 270 */ 1083, 34, 947, 82, 949, 950, 948, 591, 951, 952, + /* 280 */ 41, 60, 58, 62, 59, 34, 768, 251, 771, 51, + /* 290 */ 50, 1, 166, 49, 48, 47, 255, 254, 34, 113, + /* 300 */ 107, 118, 1082, 258, 240, 74, 117, 123, 126, 116, + /* 310 */ 245, 696, 212, 233, 693, 120, 694, 975, 695, 5, + /* 320 */ 37, 168, 91, 672, 61, 88, 167, 101, 96, 100, + /* 330 */ 779, 974, 711, 51, 50, 61, 775, 49, 48, 47, + /* 340 */ 234, 779, 242, 243, 975, 34, 34, 775, 34, 284, + /* 350 */ 776, 315, 314, 774, 961, 962, 33, 965, 187, 185, + /* 360 */ 183, 89, 34, 34, 774, 182, 131, 130, 129, 34, + /* 370 */ 34, 34, 1081, 28, 241, 77, 239, 1106, 303, 302, + /* 380 */ 247, 700, 244, 701, 310, 309, 708, 304, 305, 875, + /* 390 */ 306, 975, 975, 178, 975, 13, 3, 179, 777, 93, + /* 400 */ 90, 142, 140, 139, 307, 311, 1098, 64, 975, 975, + /* 410 */ 715, 312, 313, 317, 8, 975, 975, 975, 744, 745, + /* 420 */ 697, 79, 80, 25, 24, 735, 24, 765, 262, 262, + /* 430 */ 67, 70, 35, 35, 64, 92, 64, 32, 125, 124, + /* 440 */ 289, 736, 799, 213, 780, 782, 106, 17, 105, 16, + /* 450 */ 682, 286, 684, 288, 683, 698, 19, 699, 18, 112, + /* 460 */ 73, 111, 671, 766, 21, 214, 20, 197, 198, 200, + /* 470 */ 194, 201, 202, 71, 68, 208, 1046, 209, 207, 192, + /* 480 */ 206, 196, 1045, 231, 1042, 1041, 991, 256, 232, 316, + /* 490 */ 143, 44, 998, 1028, 1009, 1006, 1007, 1011, 263, 145, + /* 500 */ 973, 141, 267, 149, 272, 1027, 162, 163, 223, 726, + /* 510 */ 269, 276, 155, 152, 971, 164, 165, 886, 988, 291, + /* 520 */ 42, 190, 38, 300, 882, 72, 301, 63, 69, 153, + /* 530 */ 1105, 281, 154, 103, 1104, 277, 279, 156, 275, 157, + /* 540 */ 273, 271, 1101, 169, 308, 1097, 109, 1096, 268, 1093, + /* 550 */ 170, 904, 39, 36, 43, 161, 191, 871, 119, 869, + /* 560 */ 121, 122, 867, 866, 248, 181, 864, 863, 862, 45, + /* 570 */ 861, 860, 859, 184, 186, 856, 854, 852, 850, 188, + /* 580 */ 847, 189, 326, 261, 78, 83, 114, 270, 1029, 318, + /* 590 */ 319, 320, 321, 322, 323, 217, 238, 290, 324, 336, + /* 600 */ 824, 210, 249, 250, 97, 98, 211, 823, 252, 253, + /* 610 */ 822, 257, 805, 804, 262, 264, 9, 285, 177, 172, + /* 620 */ 905, 175, 173, 171, 132, 865, 174, 176, 133, 858, + /* 630 */ 4, 857, 942, 134, 135, 703, 906, 849, 848, 81, + /* 640 */ 2, 158, 29, 159, 160, 84, 148, 728, 147, 225, + /* 650 */ 731, 954, 85, 30, 733, 86, 274, 10, 737, 150, + /* 660 */ 31, 781, 11, 95, 7, 12, 26, 783, 27, 635, + /* 670 */ 287, 631, 629, 93, 628, 627, 624, 594, 298, 99, + /* 680 */ 65, 35, 674, 102, 66, 673, 104, 108, 670, 616, + /* 690 */ 110, 614, 606, 612, 608, 610, 604, 602, 638, 637, /* 700 */ 636, 634, 633, 632, 630, 626, 625, 180, 592, 559, - /* 710 */ 557, 828, 827, 827, 137, 827, 827, 827, 827, 827, - /* 720 */ 827, 827, 827, 138, + /* 710 */ 557, 828, 827, 827, 827, 827, 827, 827, 827, 827, + /* 720 */ 827, 827, 827, 137, 138, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 256, 1, 256, 192, 256, 192, 191, 192, 256, 9, - /* 10 */ 5, 189, 190, 13, 14, 267, 16, 17, 266, 267, - /* 20 */ 20, 21, 1, 23, 24, 25, 26, 27, 28, 0, - /* 30 */ 9, 256, 235, 33, 34, 256, 239, 37, 38, 39, - /* 40 */ 13, 14, 192, 16, 17, 266, 267, 20, 21, 1, - /* 50 */ 23, 24, 25, 26, 27, 28, 192, 9, 235, 237, - /* 60 */ 33, 34, 239, 192, 37, 38, 39, 14, 257, 16, - /* 70 */ 17, 258, 259, 20, 21, 253, 23, 24, 25, 26, - /* 80 */ 27, 28, 256, 198, 234, 192, 33, 34, 238, 192, + /* 0 */ 236, 1, 236, 193, 240, 193, 240, 1, 257, 9, + /* 10 */ 0, 190, 191, 13, 14, 9, 16, 17, 267, 268, + /* 20 */ 20, 21, 193, 23, 24, 25, 26, 27, 28, 192, + /* 30 */ 193, 5, 236, 33, 34, 257, 240, 37, 38, 39, + /* 40 */ 13, 14, 193, 16, 17, 267, 268, 20, 21, 1, + /* 50 */ 23, 24, 25, 26, 27, 28, 193, 9, 229, 238, + /* 60 */ 33, 34, 60, 193, 37, 38, 39, 14, 258, 16, + /* 70 */ 17, 259, 260, 20, 21, 254, 23, 24, 25, 26, + /* 80 */ 27, 28, 79, 199, 235, 193, 33, 34, 239, 79, /* 90 */ 37, 38, 39, 45, 46, 47, 48, 49, 50, 51, - /* 100 */ 52, 53, 54, 55, 56, 57, 58, 192, 79, 61, - /* 110 */ 110, 13, 14, 235, 16, 17, 231, 239, 20, 21, - /* 120 */ 198, 23, 24, 25, 26, 27, 28, 263, 237, 265, - /* 130 */ 79, 33, 34, 106, 263, 37, 38, 39, 13, 14, - /* 140 */ 105, 16, 17, 228, 253, 20, 21, 112, 23, 24, - /* 150 */ 25, 26, 27, 28, 261, 233, 263, 197, 33, 34, - /* 160 */ 263, 201, 37, 38, 39, 81, 89, 90, 91, 92, + /* 100 */ 52, 53, 54, 55, 56, 57, 58, 105, 199, 61, + /* 110 */ 110, 13, 14, 105, 16, 17, 232, 257, 20, 21, + /* 120 */ 112, 23, 24, 25, 26, 27, 28, 264, 268, 266, + /* 130 */ 81, 33, 34, 106, 264, 37, 38, 39, 13, 14, + /* 140 */ 257, 16, 17, 234, 238, 20, 21, 88, 23, 24, + /* 150 */ 25, 26, 27, 28, 262, 257, 264, 198, 33, 34, + /* 160 */ 254, 202, 37, 38, 39, 106, 89, 90, 91, 92, /* 170 */ 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, - /* 180 */ 103, 212, 213, 214, 215, 216, 217, 218, 219, 220, - /* 190 */ 221, 222, 223, 224, 225, 226, 16, 17, 192, 237, - /* 200 */ 20, 21, 192, 23, 24, 25, 26, 27, 28, 37, - /* 210 */ 38, 39, 44, 33, 34, 253, 239, 37, 38, 39, - /* 220 */ 1, 2, 256, 192, 5, 5, 7, 7, 9, 61, - /* 230 */ 192, 1, 2, 210, 211, 5, 68, 7, 5, 9, - /* 240 */ 234, 73, 74, 75, 238, 256, 236, 192, 89, 76, - /* 250 */ 91, 92, 33, 34, 81, 96, 37, 98, 99, 100, - /* 260 */ 240, 102, 103, 33, 34, 256, 33, 34, 212, 238, - /* 270 */ 214, 215, 234, 105, 254, 219, 238, 221, 222, 223, - /* 280 */ 112, 225, 226, 25, 26, 27, 28, 37, 5, 234, - /* 290 */ 7, 33, 34, 238, 1, 37, 38, 39, 192, 62, - /* 300 */ 63, 64, 9, 135, 239, 137, 69, 70, 71, 72, - /* 310 */ 68, 2, 144, 136, 5, 78, 7, 68, 9, 62, - /* 320 */ 63, 64, 145, 146, 105, 256, 69, 70, 71, 72, - /* 330 */ 111, 192, 199, 200, 198, 105, 117, 117, 195, 196, - /* 340 */ 234, 111, 33, 34, 238, 256, 15, 117, 62, 63, - /* 350 */ 64, 125, 126, 134, 239, 69, 70, 71, 72, 192, - /* 360 */ 88, 192, 192, 1, 134, 115, 230, 231, 232, 233, - /* 370 */ 33, 34, 256, 234, 37, 38, 39, 238, 88, 192, - /* 380 */ 138, 192, 140, 256, 142, 143, 88, 138, 116, 140, - /* 390 */ 105, 142, 143, 197, 109, 110, 106, 201, 105, 37, - /* 400 */ 117, 234, 197, 234, 234, 238, 201, 238, 238, 65, - /* 410 */ 66, 67, 62, 63, 64, 88, 88, 106, 88, 106, - /* 420 */ 111, 234, 88, 234, 113, 238, 113, 238, 88, 60, - /* 430 */ 132, 88, 256, 106, 106, 88, 106, 88, 256, 88, - /* 440 */ 106, 88, 111, 139, 88, 141, 106, 105, 256, 139, - /* 450 */ 108, 141, 255, 106, 139, 106, 141, 106, 139, 106, - /* 460 */ 141, 5, 106, 7, 139, 5, 141, 7, 105, 256, - /* 470 */ 107, 76, 77, 130, 105, 139, 229, 141, 256, 256, - /* 480 */ 256, 256, 229, 256, 229, 229, 192, 192, 229, 229, - /* 490 */ 229, 192, 192, 192, 192, 192, 264, 192, 192, 237, - /* 500 */ 237, 60, 264, 237, 192, 241, 192, 227, 192, 192, - /* 510 */ 192, 117, 192, 192, 192, 192, 192, 252, 192, 123, - /* 520 */ 250, 192, 251, 247, 192, 192, 129, 192, 260, 260, - /* 530 */ 192, 192, 131, 192, 260, 260, 128, 192, 192, 127, - /* 540 */ 192, 249, 122, 121, 192, 248, 192, 192, 120, 192, - /* 550 */ 192, 192, 192, 192, 246, 119, 192, 192, 192, 192, - /* 560 */ 192, 118, 192, 192, 192, 192, 192, 192, 192, 192, - /* 570 */ 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, - /* 580 */ 192, 133, 193, 193, 193, 193, 193, 104, 87, 86, - /* 590 */ 50, 83, 85, 54, 84, 193, 82, 193, 193, 79, - /* 600 */ 5, 147, 193, 193, 198, 198, 5, 5, 147, 5, - /* 610 */ 5, 136, 91, 90, 108, 113, 105, 203, 202, 193, - /* 620 */ 209, 208, 207, 206, 205, 204, 194, 194, 193, 211, - /* 630 */ 199, 194, 193, 195, 194, 193, 114, 193, 106, 105, - /* 640 */ 88, 88, 243, 245, 244, 242, 88, 106, 105, 105, - /* 650 */ 227, 106, 106, 105, 1, 105, 88, 106, 88, 105, - /* 660 */ 124, 124, 106, 76, 105, 105, 111, 105, 105, 108, - /* 670 */ 9, 5, 5, 109, 5, 5, 5, 80, 15, 76, - /* 680 */ 16, 88, 5, 141, 16, 5, 106, 5, 141, 5, - /* 690 */ 141, 5, 5, 5, 5, 5, 5, 5, 141, 5, + /* 180 */ 103, 213, 214, 215, 216, 217, 218, 219, 220, 221, + /* 190 */ 222, 223, 224, 225, 226, 227, 16, 17, 88, 238, + /* 200 */ 20, 21, 257, 23, 24, 25, 26, 27, 28, 37, + /* 210 */ 38, 39, 44, 33, 34, 254, 106, 37, 38, 39, + /* 220 */ 1, 2, 193, 198, 5, 76, 7, 202, 9, 61, + /* 230 */ 81, 1, 2, 211, 212, 5, 68, 7, 5, 9, + /* 240 */ 7, 73, 74, 75, 65, 66, 67, 139, 89, 141, + /* 250 */ 91, 92, 33, 34, 193, 96, 37, 98, 99, 100, + /* 260 */ 240, 102, 103, 33, 34, 213, 237, 215, 216, 1, + /* 270 */ 257, 193, 220, 105, 222, 223, 224, 9, 226, 227, + /* 280 */ 112, 25, 26, 27, 28, 193, 5, 136, 7, 33, + /* 290 */ 34, 200, 201, 37, 38, 39, 145, 146, 193, 62, + /* 300 */ 63, 64, 257, 135, 68, 137, 69, 70, 71, 72, + /* 310 */ 68, 2, 144, 235, 5, 78, 7, 239, 9, 62, + /* 320 */ 63, 64, 199, 5, 105, 264, 69, 70, 71, 72, + /* 330 */ 111, 239, 37, 33, 34, 105, 117, 37, 38, 39, + /* 340 */ 235, 111, 33, 34, 239, 193, 193, 117, 193, 15, + /* 350 */ 117, 33, 34, 134, 231, 232, 233, 234, 62, 63, + /* 360 */ 64, 241, 193, 193, 134, 69, 70, 71, 72, 193, + /* 370 */ 193, 193, 257, 105, 138, 255, 140, 240, 142, 143, + /* 380 */ 138, 5, 140, 7, 142, 143, 88, 235, 235, 198, + /* 390 */ 235, 239, 239, 202, 239, 105, 196, 197, 117, 109, + /* 400 */ 110, 62, 63, 64, 235, 235, 240, 88, 239, 239, + /* 410 */ 115, 235, 235, 235, 116, 239, 239, 239, 125, 126, + /* 420 */ 111, 106, 106, 88, 88, 106, 88, 1, 113, 113, + /* 430 */ 88, 88, 88, 88, 88, 88, 88, 105, 76, 77, + /* 440 */ 108, 106, 106, 257, 106, 111, 139, 139, 141, 141, + /* 450 */ 106, 106, 106, 106, 106, 5, 139, 7, 141, 139, + /* 460 */ 105, 141, 107, 37, 139, 257, 141, 257, 257, 257, + /* 470 */ 257, 257, 257, 130, 132, 257, 230, 257, 257, 257, + /* 480 */ 257, 257, 230, 230, 230, 230, 238, 193, 230, 230, + /* 490 */ 193, 256, 193, 265, 193, 193, 193, 193, 238, 193, + /* 500 */ 238, 60, 261, 193, 193, 265, 242, 193, 261, 117, + /* 510 */ 261, 261, 249, 252, 193, 193, 193, 193, 253, 193, + /* 520 */ 193, 193, 193, 193, 193, 129, 193, 128, 131, 251, + /* 530 */ 193, 123, 250, 193, 193, 122, 127, 248, 121, 247, + /* 540 */ 120, 119, 193, 193, 193, 193, 193, 193, 118, 193, + /* 550 */ 193, 193, 193, 193, 193, 243, 193, 193, 193, 193, + /* 560 */ 193, 193, 193, 193, 193, 193, 193, 193, 193, 133, + /* 570 */ 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, + /* 580 */ 193, 193, 104, 194, 194, 194, 87, 194, 194, 86, + /* 590 */ 50, 83, 85, 54, 84, 194, 194, 194, 82, 79, + /* 600 */ 5, 194, 147, 5, 199, 199, 194, 5, 147, 5, + /* 610 */ 5, 136, 91, 90, 113, 88, 105, 108, 203, 208, + /* 620 */ 210, 205, 204, 209, 195, 194, 207, 206, 195, 194, + /* 630 */ 196, 194, 228, 195, 195, 106, 212, 194, 194, 114, + /* 640 */ 200, 246, 105, 245, 244, 88, 88, 106, 105, 1, + /* 650 */ 106, 228, 105, 88, 106, 105, 105, 124, 106, 105, + /* 660 */ 88, 106, 124, 76, 105, 105, 105, 111, 105, 9, + /* 670 */ 108, 5, 5, 109, 5, 5, 5, 80, 15, 76, + /* 680 */ 16, 88, 5, 141, 16, 5, 141, 141, 106, 5, + /* 690 */ 141, 5, 5, 5, 5, 5, 5, 5, 5, 5, /* 700 */ 5, 5, 5, 5, 5, 5, 5, 88, 80, 60, - /* 710 */ 59, 0, 268, 268, 21, 268, 268, 268, 268, 268, - /* 720 */ 268, 268, 268, 21, 268, 268, 268, 268, 268, 268, - /* 730 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 740 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 750 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 760 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 770 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 780 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 790 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 800 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 810 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 820 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 830 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 840 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 850 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 860 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 870 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 880 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 890 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 900 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 910 */ 268, 268, 268, + /* 710 */ 59, 0, 269, 269, 269, 269, 269, 269, 269, 269, + /* 720 */ 269, 269, 269, 21, 21, 269, 269, 269, 269, 269, + /* 730 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 740 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 750 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 760 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 770 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 780 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 790 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 800 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 810 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 820 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 830 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 840 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 850 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 860 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 870 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 880 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 890 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 900 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 910 */ 269, 269, 269, 269, }; #define YY_SHIFT_COUNT (341) #define YY_SHIFT_MIN (0) #define YY_SHIFT_MAX (711) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 168, 77, 77, 159, 159, 51, 219, 230, 293, 21, - /* 10 */ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - /* 20 */ 21, 21, 0, 48, 230, 309, 309, 309, 35, 35, - /* 30 */ 21, 21, 21, 29, 21, 21, 173, 51, 84, 84, - /* 40 */ 5, 724, 724, 724, 230, 230, 230, 230, 230, 230, + /* 0 */ 168, 77, 77, 159, 159, 3, 219, 230, 268, 6, + /* 10 */ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + /* 20 */ 6, 6, 0, 48, 230, 309, 309, 309, 8, 8, + /* 30 */ 6, 6, 6, 10, 6, 6, 149, 3, 49, 49, + /* 40 */ 26, 725, 725, 725, 230, 230, 230, 230, 230, 230, /* 50 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, - /* 60 */ 230, 230, 230, 230, 309, 309, 309, 233, 233, 233, - /* 70 */ 233, 233, 233, 233, 21, 21, 21, 250, 21, 21, - /* 80 */ 21, 35, 35, 21, 21, 21, 21, 226, 226, 272, - /* 90 */ 35, 21, 21, 21, 21, 21, 21, 21, 21, 21, - /* 100 */ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - /* 110 */ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - /* 120 */ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - /* 130 */ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - /* 140 */ 21, 21, 21, 441, 441, 441, 394, 394, 394, 441, - /* 150 */ 394, 441, 397, 401, 408, 396, 412, 420, 422, 428, - /* 160 */ 436, 443, 448, 441, 441, 441, 483, 51, 51, 441, - /* 170 */ 441, 501, 503, 540, 508, 507, 539, 510, 514, 483, - /* 180 */ 5, 441, 520, 520, 441, 520, 441, 520, 441, 441, - /* 190 */ 724, 724, 27, 98, 125, 98, 98, 53, 180, 258, - /* 200 */ 258, 258, 258, 237, 257, 286, 337, 337, 337, 337, - /* 210 */ 242, 249, 177, 172, 172, 220, 283, 285, 344, 350, - /* 220 */ 290, 311, 313, 327, 328, 330, 334, 340, 362, 369, - /* 230 */ 331, 298, 343, 347, 349, 351, 353, 356, 342, 304, - /* 240 */ 310, 315, 456, 460, 319, 325, 363, 336, 395, 595, - /* 250 */ 454, 601, 602, 461, 604, 605, 521, 523, 475, 502, - /* 260 */ 506, 511, 522, 532, 534, 552, 553, 541, 543, 545, - /* 270 */ 558, 544, 546, 548, 653, 550, 551, 554, 568, 536, - /* 280 */ 570, 537, 556, 559, 555, 560, 506, 562, 561, 563, - /* 290 */ 564, 587, 661, 666, 667, 669, 670, 671, 597, 663, - /* 300 */ 603, 664, 542, 547, 593, 593, 593, 593, 668, 549, - /* 310 */ 557, 593, 593, 593, 677, 680, 580, 593, 682, 684, - /* 320 */ 686, 687, 688, 689, 690, 691, 692, 694, 695, 696, - /* 330 */ 697, 698, 699, 700, 701, 619, 628, 693, 702, 649, + /* 60 */ 230, 230, 230, 230, 309, 309, 309, 318, 318, 318, + /* 70 */ 318, 318, 318, 318, 6, 6, 6, 295, 6, 6, + /* 80 */ 6, 8, 8, 6, 6, 6, 6, 293, 293, 298, + /* 90 */ 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, + /* 100 */ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + /* 110 */ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + /* 120 */ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + /* 130 */ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + /* 140 */ 6, 6, 6, 441, 441, 441, 392, 392, 392, 441, + /* 150 */ 392, 441, 396, 397, 399, 408, 409, 413, 417, 420, + /* 160 */ 422, 430, 436, 441, 441, 441, 478, 3, 3, 441, + /* 170 */ 441, 499, 503, 540, 508, 507, 539, 510, 516, 478, + /* 180 */ 26, 441, 520, 520, 441, 520, 441, 520, 441, 441, + /* 190 */ 725, 725, 27, 98, 125, 98, 98, 53, 180, 256, + /* 200 */ 256, 256, 256, 237, 257, 296, 300, 300, 300, 300, + /* 210 */ 236, 242, 151, 172, 172, 233, 281, 290, 179, 339, + /* 220 */ 59, 315, 316, 110, 319, 335, 336, 338, 426, 2, + /* 230 */ 334, 342, 343, 344, 345, 346, 347, 348, 332, 108, + /* 240 */ 307, 308, 376, 450, 317, 320, 355, 325, 362, 595, + /* 250 */ 455, 598, 602, 461, 604, 605, 521, 523, 475, 501, + /* 260 */ 509, 511, 525, 529, 537, 527, 557, 541, 543, 544, + /* 270 */ 558, 547, 548, 550, 648, 551, 552, 554, 565, 533, + /* 280 */ 572, 538, 555, 559, 556, 560, 509, 561, 562, 563, + /* 290 */ 564, 587, 660, 666, 667, 669, 670, 671, 597, 663, + /* 300 */ 603, 664, 542, 545, 593, 593, 593, 593, 668, 546, + /* 310 */ 549, 593, 593, 593, 677, 680, 582, 593, 684, 686, + /* 320 */ 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, + /* 330 */ 697, 698, 699, 700, 701, 619, 628, 702, 703, 649, /* 340 */ 651, 711, }; #define YY_REDUCE_COUNT (191) -#define YY_REDUCE_MIN (-256) +#define YY_REDUCE_MIN (-249) #define YY_REDUCE_MAX (444) static const short yy_reduce_ofst[] = { - /* 0 */ -178, -31, -31, 56, 56, 136, -248, -221, -187, -150, - /* 10 */ -136, -107, 6, 38, 55, 106, 139, 167, 169, 170, - /* 20 */ 187, 189, -189, -185, -252, -203, -177, -122, -109, -38, - /* 30 */ -129, -103, 10, -78, -85, 31, -40, -115, 196, 205, - /* 40 */ 23, 20, 133, 143, -256, -254, -225, -174, -34, -11, - /* 50 */ 9, 69, 89, 116, 127, 176, 182, 192, 213, 222, - /* 60 */ 223, 224, 225, 227, -23, 65, 115, 247, 253, 255, - /* 70 */ 256, 259, 260, 261, 294, 295, 299, 197, 300, 301, - /* 80 */ 302, 262, 263, 303, 305, 306, 312, 232, 238, 264, - /* 90 */ 266, 314, 316, 317, 318, 320, 321, 322, 323, 324, - /* 100 */ 326, 329, 332, 333, 335, 338, 339, 341, 345, 346, - /* 110 */ 348, 352, 354, 355, 357, 358, 359, 360, 361, 364, - /* 120 */ 365, 366, 367, 368, 370, 371, 372, 373, 374, 375, - /* 130 */ 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, - /* 140 */ 386, 387, 388, 389, 390, 391, 268, 269, 274, 392, - /* 150 */ 275, 393, 265, 271, 270, 292, 297, 276, 308, 398, - /* 160 */ 400, 399, 403, 402, 404, 405, 280, 406, 407, 409, - /* 170 */ 410, 411, 413, 415, 414, 417, 421, 419, 416, 423, - /* 180 */ 418, 426, 432, 433, 435, 437, 439, 440, 442, 444, - /* 190 */ 431, 438, + /* 0 */ -179, -32, -32, 52, 52, 123, -249, -222, -188, -151, + /* 10 */ -137, -108, 78, 105, 152, 153, 155, 169, 170, 176, + /* 20 */ 177, 178, -190, -163, -140, -236, -234, -204, -94, -39, + /* 30 */ -130, 61, 29, -91, -171, 92, -41, -116, 25, 191, + /* 40 */ 22, 120, 91, 200, -117, -102, -55, 13, 45, 115, + /* 50 */ 186, 208, 210, 211, 212, 213, 214, 215, 218, 220, + /* 60 */ 221, 222, 223, 224, 20, 137, 166, 246, 252, 253, + /* 70 */ 254, 255, 258, 259, 294, 297, 299, 235, 301, 302, + /* 80 */ 303, 248, 260, 304, 306, 310, 311, 228, 240, 264, + /* 90 */ 262, 314, 321, 322, 323, 324, 326, 327, 328, 329, + /* 100 */ 330, 331, 333, 337, 340, 341, 349, 350, 351, 352, + /* 110 */ 353, 354, 356, 357, 358, 359, 360, 361, 363, 364, + /* 120 */ 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + /* 130 */ 375, 377, 378, 379, 380, 381, 382, 383, 384, 385, + /* 140 */ 386, 387, 388, 389, 390, 391, 241, 247, 249, 393, + /* 150 */ 250, 394, 265, 261, 278, 282, 263, 289, 292, 395, + /* 160 */ 398, 400, 312, 401, 402, 403, 404, 405, 406, 407, + /* 170 */ 412, 410, 414, 411, 418, 419, 416, 421, 415, 423, + /* 180 */ 424, 431, 429, 433, 435, 438, 437, 439, 443, 444, + /* 190 */ 440, 434, }; static const YYACTIONTYPE yy_default[] = { /* 0 */ 825, 941, 884, 953, 872, 881, 1089, 1089, 825, 825, @@ -733,7 +722,6 @@ struct yyParser { int yyerrcnt; /* Shifts left before out of the error */ #endif ParseARG_SDECL /* A place to hold %extra_argument */ - ParseCTX_SDECL /* A place to hold %extra_context */ #if YYSTACKDEPTH<=0 int yystksz; /* Current side of the stack */ yyStackEntry *yystack; /* The parser's stack */ @@ -970,85 +958,86 @@ static const char *const yyTokenName[] = { /* 186 */ "INSERT", /* 187 */ "INTO", /* 188 */ "VALUES", - /* 189 */ "program", - /* 190 */ "cmd", - /* 191 */ "dbPrefix", - /* 192 */ "ids", - /* 193 */ "cpxName", - /* 194 */ "ifexists", - /* 195 */ "alter_db_optr", - /* 196 */ "alter_topic_optr", - /* 197 */ "acct_optr", - /* 198 */ "ifnotexists", - /* 199 */ "db_optr", - /* 200 */ "topic_optr", - /* 201 */ "pps", - /* 202 */ "tseries", - /* 203 */ "dbs", - /* 204 */ "streams", - /* 205 */ "storage", - /* 206 */ "qtime", - /* 207 */ "users", - /* 208 */ "conns", - /* 209 */ "state", - /* 210 */ "intitemlist", - /* 211 */ "intitem", - /* 212 */ "keep", - /* 213 */ "cache", - /* 214 */ "replica", - /* 215 */ "quorum", - /* 216 */ "days", - /* 217 */ "minrows", - /* 218 */ "maxrows", - /* 219 */ "blocks", - /* 220 */ "ctime", - /* 221 */ "wal", - /* 222 */ "fsync", - /* 223 */ "comp", - /* 224 */ "prec", - /* 225 */ "update", - /* 226 */ "cachelast", - /* 227 */ "partitions", - /* 228 */ "typename", - /* 229 */ "signed", - /* 230 */ "create_table_args", - /* 231 */ "create_stable_args", - /* 232 */ "create_table_list", - /* 233 */ "create_from_stable", - /* 234 */ "columnlist", - /* 235 */ "tagitemlist", - /* 236 */ "tagNamelist", - /* 237 */ "select", - /* 238 */ "column", - /* 239 */ "tagitem", - /* 240 */ "selcollist", - /* 241 */ "from", - /* 242 */ "where_opt", - /* 243 */ "interval_opt", - /* 244 */ "session_option", - /* 245 */ "windowstate_option", - /* 246 */ "fill_opt", - /* 247 */ "sliding_opt", - /* 248 */ "groupby_opt", - /* 249 */ "orderby_opt", - /* 250 */ "having_opt", - /* 251 */ "slimit_opt", - /* 252 */ "limit_opt", - /* 253 */ "union", - /* 254 */ "sclp", - /* 255 */ "distinct", - /* 256 */ "expr", - /* 257 */ "as", - /* 258 */ "tablelist", - /* 259 */ "sub", - /* 260 */ "tmvar", - /* 261 */ "sortlist", - /* 262 */ "sortitem", - /* 263 */ "item", - /* 264 */ "sortorder", - /* 265 */ "grouplist", - /* 266 */ "exprlist", - /* 267 */ "expritem", + /* 189 */ "error", + /* 190 */ "program", + /* 191 */ "cmd", + /* 192 */ "dbPrefix", + /* 193 */ "ids", + /* 194 */ "cpxName", + /* 195 */ "ifexists", + /* 196 */ "alter_db_optr", + /* 197 */ "alter_topic_optr", + /* 198 */ "acct_optr", + /* 199 */ "ifnotexists", + /* 200 */ "db_optr", + /* 201 */ "topic_optr", + /* 202 */ "pps", + /* 203 */ "tseries", + /* 204 */ "dbs", + /* 205 */ "streams", + /* 206 */ "storage", + /* 207 */ "qtime", + /* 208 */ "users", + /* 209 */ "conns", + /* 210 */ "state", + /* 211 */ "intitemlist", + /* 212 */ "intitem", + /* 213 */ "keep", + /* 214 */ "cache", + /* 215 */ "replica", + /* 216 */ "quorum", + /* 217 */ "days", + /* 218 */ "minrows", + /* 219 */ "maxrows", + /* 220 */ "blocks", + /* 221 */ "ctime", + /* 222 */ "wal", + /* 223 */ "fsync", + /* 224 */ "comp", + /* 225 */ "prec", + /* 226 */ "update", + /* 227 */ "cachelast", + /* 228 */ "partitions", + /* 229 */ "typename", + /* 230 */ "signed", + /* 231 */ "create_table_args", + /* 232 */ "create_stable_args", + /* 233 */ "create_table_list", + /* 234 */ "create_from_stable", + /* 235 */ "columnlist", + /* 236 */ "tagitemlist", + /* 237 */ "tagNamelist", + /* 238 */ "select", + /* 239 */ "column", + /* 240 */ "tagitem", + /* 241 */ "selcollist", + /* 242 */ "from", + /* 243 */ "where_opt", + /* 244 */ "interval_opt", + /* 245 */ "session_option", + /* 246 */ "windowstate_option", + /* 247 */ "fill_opt", + /* 248 */ "sliding_opt", + /* 249 */ "groupby_opt", + /* 250 */ "orderby_opt", + /* 251 */ "having_opt", + /* 252 */ "slimit_opt", + /* 253 */ "limit_opt", + /* 254 */ "union", + /* 255 */ "sclp", + /* 256 */ "distinct", + /* 257 */ "expr", + /* 258 */ "as", + /* 259 */ "tablelist", + /* 260 */ "sub", + /* 261 */ "tmvar", + /* 262 */ "sortlist", + /* 263 */ "sortitem", + /* 264 */ "item", + /* 265 */ "sortorder", + /* 266 */ "grouplist", + /* 267 */ "exprlist", + /* 268 */ "expritem", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1387,29 +1376,28 @@ static int yyGrowStack(yyParser *p){ /* Initialize a new parser that has already been allocated. */ -void ParseInit(void *yypRawParser ParseCTX_PDECL){ - yyParser *yypParser = (yyParser*)yypRawParser; - ParseCTX_STORE +void ParseInit(void *yypParser){ + yyParser *pParser = (yyParser*)yypParser; #ifdef YYTRACKMAXSTACKDEPTH - yypParser->yyhwm = 0; + pParser->yyhwm = 0; #endif #if YYSTACKDEPTH<=0 - yypParser->yytos = NULL; - yypParser->yystack = NULL; - yypParser->yystksz = 0; - if( yyGrowStack(yypParser) ){ - yypParser->yystack = &yypParser->yystk0; - yypParser->yystksz = 1; + pParser->yytos = NULL; + pParser->yystack = NULL; + pParser->yystksz = 0; + if( yyGrowStack(pParser) ){ + pParser->yystack = &pParser->yystk0; + pParser->yystksz = 1; } #endif #ifndef YYNOERRORRECOVERY - yypParser->yyerrcnt = -1; + pParser->yyerrcnt = -1; #endif - yypParser->yytos = yypParser->yystack; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; + pParser->yytos = pParser->yystack; + pParser->yystack[0].stateno = 0; + pParser->yystack[0].major = 0; #if YYSTACKDEPTH>0 - yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; + pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1]; #endif } @@ -1426,14 +1414,11 @@ void ParseInit(void *yypRawParser ParseCTX_PDECL){ ** A pointer to a parser. This pointer is used in subsequent calls ** to Parse and ParseFree. */ -void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){ - yyParser *yypParser; - yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); - if( yypParser ){ - ParseCTX_STORE - ParseInit(yypParser ParseCTX_PARAM); - } - return (void*)yypParser; +void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ + yyParser *pParser; + pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); + if( pParser ) ParseInit(pParser); + return pParser; } #endif /* Parse_ENGINEALWAYSONSTACK */ @@ -1450,8 +1435,7 @@ static void yy_destructor( YYCODETYPE yymajor, /* Type code for object to destroy */ YYMINORTYPE *yypminor /* The object to be destroyed */ ){ - ParseARG_FETCH - ParseCTX_FETCH + ParseARG_FETCH; switch( yymajor ){ /* Here is inserted the actions which take place when a ** terminal or non-terminal is destroyed. This can happen @@ -1464,60 +1448,60 @@ static void yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 210: /* intitemlist */ - case 212: /* keep */ - case 234: /* columnlist */ - case 235: /* tagitemlist */ - case 236: /* tagNamelist */ - case 246: /* fill_opt */ - case 248: /* groupby_opt */ - case 249: /* orderby_opt */ - case 261: /* sortlist */ - case 265: /* grouplist */ -{ -taosArrayDestroy((yypminor->yy325)); + case 211: /* intitemlist */ + case 213: /* keep */ + case 235: /* columnlist */ + case 236: /* tagitemlist */ + case 237: /* tagNamelist */ + case 247: /* fill_opt */ + case 249: /* groupby_opt */ + case 250: /* orderby_opt */ + case 262: /* sortlist */ + case 266: /* grouplist */ +{ +taosArrayDestroy((yypminor->yy93)); } break; - case 232: /* create_table_list */ + case 233: /* create_table_list */ { -destroyCreateTableSql((yypminor->yy422)); +destroyCreateTableSql((yypminor->yy532)); } break; - case 237: /* select */ + case 238: /* select */ { -destroySqlNode((yypminor->yy536)); +destroySqlNode((yypminor->yy224)); } break; - case 240: /* selcollist */ - case 254: /* sclp */ - case 266: /* exprlist */ + case 241: /* selcollist */ + case 255: /* sclp */ + case 267: /* exprlist */ { -tSqlExprListDestroy((yypminor->yy325)); +tSqlExprListDestroy((yypminor->yy93)); } break; - case 241: /* from */ - case 258: /* tablelist */ - case 259: /* sub */ + case 242: /* from */ + case 259: /* tablelist */ + case 260: /* sub */ { -destroyRelationInfo((yypminor->yy52)); +destroyRelationInfo((yypminor->yy330)); } break; - case 242: /* where_opt */ - case 250: /* having_opt */ - case 256: /* expr */ - case 267: /* expritem */ + case 243: /* where_opt */ + case 251: /* having_opt */ + case 257: /* expr */ + case 268: /* expritem */ { -tSqlExprDestroy((yypminor->yy162)); +tSqlExprDestroy((yypminor->yy68)); } break; - case 253: /* union */ + case 254: /* union */ { -destroyAllSqlNode((yypminor->yy325)); +destroyAllSqlNode((yypminor->yy93)); } break; - case 262: /* sortitem */ + case 263: /* sortitem */ { -tVariantDestroy(&(yypminor->yy442)); +tVariantDestroy(&(yypminor->yy518)); } break; /********* End destructor definitions *****************************************/ @@ -1629,12 +1613,13 @@ int ParseCoverage(FILE *out){ ** Find the appropriate action for a parser given the terminal ** look-ahead token iLookAhead. */ -static YYACTIONTYPE yy_find_shift_action( - YYCODETYPE iLookAhead, /* The look-ahead token */ - YYACTIONTYPE stateno /* Current state number */ +static unsigned int yy_find_shift_action( + yyParser *pParser, /* The parser */ + YYCODETYPE iLookAhead /* The look-ahead token */ ){ int i; - + int stateno = pParser->yytos->stateno; + if( stateno>YY_MAX_SHIFT ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); #if defined(YYCOVERAGE) @@ -1642,19 +1627,15 @@ static YYACTIONTYPE yy_find_shift_action( #endif do{ i = yy_shift_ofst[stateno]; - assert( i>=0 ); - assert( i<=YY_ACTTAB_COUNT ); - assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); + assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); assert( iLookAhead!=YYNOCODE ); assert( iLookAhead < YYNTOKEN ); i += iLookAhead; - assert( i<(int)YY_NLOOKAHEAD ); if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ - assert( iLookAhead %s\n", @@ -1669,8 +1650,15 @@ static YYACTIONTYPE yy_find_shift_action( #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; - assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); - if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ + if( +#if YY_SHIFT_MIN+YYWILDCARD<0 + j>=0 && +#endif +#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT + j0 + ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", @@ -1684,7 +1672,6 @@ static YYACTIONTYPE yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ - assert( i>=0 && iyytos; - yytos->stateno = yyNewState; - yytos->major = yyMajor; + yytos->stateno = (YYACTIONTYPE)yyNewState; + yytos->major = (YYCODETYPE)yyMajor; yytos->minor.yy0 = yyMinor; yyTraceShift(yypParser, yyNewState, "Shift"); } -/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side -** of that rule */ -static const YYCODETYPE yyRuleInfoLhs[] = { - 189, /* (0) program ::= cmd */ - 190, /* (1) cmd ::= SHOW DATABASES */ - 190, /* (2) cmd ::= SHOW TOPICS */ - 190, /* (3) cmd ::= SHOW MNODES */ - 190, /* (4) cmd ::= SHOW DNODES */ - 190, /* (5) cmd ::= SHOW ACCOUNTS */ - 190, /* (6) cmd ::= SHOW USERS */ - 190, /* (7) cmd ::= SHOW MODULES */ - 190, /* (8) cmd ::= SHOW QUERIES */ - 190, /* (9) cmd ::= SHOW CONNECTIONS */ - 190, /* (10) cmd ::= SHOW STREAMS */ - 190, /* (11) cmd ::= SHOW VARIABLES */ - 190, /* (12) cmd ::= SHOW SCORES */ - 190, /* (13) cmd ::= SHOW GRANTS */ - 190, /* (14) cmd ::= SHOW VNODES */ - 190, /* (15) cmd ::= SHOW VNODES IPTOKEN */ - 191, /* (16) dbPrefix ::= */ - 191, /* (17) dbPrefix ::= ids DOT */ - 193, /* (18) cpxName ::= */ - 193, /* (19) cpxName ::= DOT ids */ - 190, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */ - 190, /* (21) cmd ::= SHOW CREATE STABLE ids cpxName */ - 190, /* (22) cmd ::= SHOW CREATE DATABASE ids */ - 190, /* (23) cmd ::= SHOW dbPrefix TABLES */ - 190, /* (24) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - 190, /* (25) cmd ::= SHOW dbPrefix STABLES */ - 190, /* (26) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - 190, /* (27) cmd ::= SHOW dbPrefix VGROUPS */ - 190, /* (28) cmd ::= SHOW dbPrefix VGROUPS ids */ - 190, /* (29) cmd ::= DROP TABLE ifexists ids cpxName */ - 190, /* (30) cmd ::= DROP STABLE ifexists ids cpxName */ - 190, /* (31) cmd ::= DROP DATABASE ifexists ids */ - 190, /* (32) cmd ::= DROP TOPIC ifexists ids */ - 190, /* (33) cmd ::= DROP DNODE ids */ - 190, /* (34) cmd ::= DROP USER ids */ - 190, /* (35) cmd ::= DROP ACCOUNT ids */ - 190, /* (36) cmd ::= USE ids */ - 190, /* (37) cmd ::= DESCRIBE ids cpxName */ - 190, /* (38) cmd ::= ALTER USER ids PASS ids */ - 190, /* (39) cmd ::= ALTER USER ids PRIVILEGE ids */ - 190, /* (40) cmd ::= ALTER DNODE ids ids */ - 190, /* (41) cmd ::= ALTER DNODE ids ids ids */ - 190, /* (42) cmd ::= ALTER LOCAL ids */ - 190, /* (43) cmd ::= ALTER LOCAL ids ids */ - 190, /* (44) cmd ::= ALTER DATABASE ids alter_db_optr */ - 190, /* (45) cmd ::= ALTER TOPIC ids alter_topic_optr */ - 190, /* (46) cmd ::= ALTER ACCOUNT ids acct_optr */ - 190, /* (47) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - 192, /* (48) ids ::= ID */ - 192, /* (49) ids ::= STRING */ - 194, /* (50) ifexists ::= IF EXISTS */ - 194, /* (51) ifexists ::= */ - 198, /* (52) ifnotexists ::= IF NOT EXISTS */ - 198, /* (53) ifnotexists ::= */ - 190, /* (54) cmd ::= CREATE DNODE ids */ - 190, /* (55) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - 190, /* (56) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - 190, /* (57) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ - 190, /* (58) cmd ::= CREATE USER ids PASS ids */ - 201, /* (59) pps ::= */ - 201, /* (60) pps ::= PPS INTEGER */ - 202, /* (61) tseries ::= */ - 202, /* (62) tseries ::= TSERIES INTEGER */ - 203, /* (63) dbs ::= */ - 203, /* (64) dbs ::= DBS INTEGER */ - 204, /* (65) streams ::= */ - 204, /* (66) streams ::= STREAMS INTEGER */ - 205, /* (67) storage ::= */ - 205, /* (68) storage ::= STORAGE INTEGER */ - 206, /* (69) qtime ::= */ - 206, /* (70) qtime ::= QTIME INTEGER */ - 207, /* (71) users ::= */ - 207, /* (72) users ::= USERS INTEGER */ - 208, /* (73) conns ::= */ - 208, /* (74) conns ::= CONNS INTEGER */ - 209, /* (75) state ::= */ - 209, /* (76) state ::= STATE ids */ - 197, /* (77) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - 210, /* (78) intitemlist ::= intitemlist COMMA intitem */ - 210, /* (79) intitemlist ::= intitem */ - 211, /* (80) intitem ::= INTEGER */ - 212, /* (81) keep ::= KEEP intitemlist */ - 213, /* (82) cache ::= CACHE INTEGER */ - 214, /* (83) replica ::= REPLICA INTEGER */ - 215, /* (84) quorum ::= QUORUM INTEGER */ - 216, /* (85) days ::= DAYS INTEGER */ - 217, /* (86) minrows ::= MINROWS INTEGER */ - 218, /* (87) maxrows ::= MAXROWS INTEGER */ - 219, /* (88) blocks ::= BLOCKS INTEGER */ - 220, /* (89) ctime ::= CTIME INTEGER */ - 221, /* (90) wal ::= WAL INTEGER */ - 222, /* (91) fsync ::= FSYNC INTEGER */ - 223, /* (92) comp ::= COMP INTEGER */ - 224, /* (93) prec ::= PRECISION STRING */ - 225, /* (94) update ::= UPDATE INTEGER */ - 226, /* (95) cachelast ::= CACHELAST INTEGER */ - 227, /* (96) partitions ::= PARTITIONS INTEGER */ - 199, /* (97) db_optr ::= */ - 199, /* (98) db_optr ::= db_optr cache */ - 199, /* (99) db_optr ::= db_optr replica */ - 199, /* (100) db_optr ::= db_optr quorum */ - 199, /* (101) db_optr ::= db_optr days */ - 199, /* (102) db_optr ::= db_optr minrows */ - 199, /* (103) db_optr ::= db_optr maxrows */ - 199, /* (104) db_optr ::= db_optr blocks */ - 199, /* (105) db_optr ::= db_optr ctime */ - 199, /* (106) db_optr ::= db_optr wal */ - 199, /* (107) db_optr ::= db_optr fsync */ - 199, /* (108) db_optr ::= db_optr comp */ - 199, /* (109) db_optr ::= db_optr prec */ - 199, /* (110) db_optr ::= db_optr keep */ - 199, /* (111) db_optr ::= db_optr update */ - 199, /* (112) db_optr ::= db_optr cachelast */ - 200, /* (113) topic_optr ::= db_optr */ - 200, /* (114) topic_optr ::= topic_optr partitions */ - 195, /* (115) alter_db_optr ::= */ - 195, /* (116) alter_db_optr ::= alter_db_optr replica */ - 195, /* (117) alter_db_optr ::= alter_db_optr quorum */ - 195, /* (118) alter_db_optr ::= alter_db_optr keep */ - 195, /* (119) alter_db_optr ::= alter_db_optr blocks */ - 195, /* (120) alter_db_optr ::= alter_db_optr comp */ - 195, /* (121) alter_db_optr ::= alter_db_optr wal */ - 195, /* (122) alter_db_optr ::= alter_db_optr fsync */ - 195, /* (123) alter_db_optr ::= alter_db_optr update */ - 195, /* (124) alter_db_optr ::= alter_db_optr cachelast */ - 196, /* (125) alter_topic_optr ::= alter_db_optr */ - 196, /* (126) alter_topic_optr ::= alter_topic_optr partitions */ - 228, /* (127) typename ::= ids */ - 228, /* (128) typename ::= ids LP signed RP */ - 228, /* (129) typename ::= ids UNSIGNED */ - 229, /* (130) signed ::= INTEGER */ - 229, /* (131) signed ::= PLUS INTEGER */ - 229, /* (132) signed ::= MINUS INTEGER */ - 190, /* (133) cmd ::= CREATE TABLE create_table_args */ - 190, /* (134) cmd ::= CREATE TABLE create_stable_args */ - 190, /* (135) cmd ::= CREATE STABLE create_stable_args */ - 190, /* (136) cmd ::= CREATE TABLE create_table_list */ - 232, /* (137) create_table_list ::= create_from_stable */ - 232, /* (138) create_table_list ::= create_table_list create_from_stable */ - 230, /* (139) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - 231, /* (140) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - 233, /* (141) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ - 233, /* (142) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ - 236, /* (143) tagNamelist ::= tagNamelist COMMA ids */ - 236, /* (144) tagNamelist ::= ids */ - 230, /* (145) create_table_args ::= ifnotexists ids cpxName AS select */ - 234, /* (146) columnlist ::= columnlist COMMA column */ - 234, /* (147) columnlist ::= column */ - 238, /* (148) column ::= ids typename */ - 235, /* (149) tagitemlist ::= tagitemlist COMMA tagitem */ - 235, /* (150) tagitemlist ::= tagitem */ - 239, /* (151) tagitem ::= INTEGER */ - 239, /* (152) tagitem ::= FLOAT */ - 239, /* (153) tagitem ::= STRING */ - 239, /* (154) tagitem ::= BOOL */ - 239, /* (155) tagitem ::= NULL */ - 239, /* (156) tagitem ::= MINUS INTEGER */ - 239, /* (157) tagitem ::= MINUS FLOAT */ - 239, /* (158) tagitem ::= PLUS INTEGER */ - 239, /* (159) tagitem ::= PLUS FLOAT */ - 237, /* (160) select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ - 237, /* (161) select ::= LP select RP */ - 253, /* (162) union ::= select */ - 253, /* (163) union ::= union UNION ALL select */ - 190, /* (164) cmd ::= union */ - 237, /* (165) select ::= SELECT selcollist */ - 254, /* (166) sclp ::= selcollist COMMA */ - 254, /* (167) sclp ::= */ - 240, /* (168) selcollist ::= sclp distinct expr as */ - 240, /* (169) selcollist ::= sclp STAR */ - 257, /* (170) as ::= AS ids */ - 257, /* (171) as ::= ids */ - 257, /* (172) as ::= */ - 255, /* (173) distinct ::= DISTINCT */ - 255, /* (174) distinct ::= */ - 241, /* (175) from ::= FROM tablelist */ - 241, /* (176) from ::= FROM sub */ - 259, /* (177) sub ::= LP union RP */ - 259, /* (178) sub ::= LP union RP ids */ - 259, /* (179) sub ::= sub COMMA LP union RP ids */ - 258, /* (180) tablelist ::= ids cpxName */ - 258, /* (181) tablelist ::= ids cpxName ids */ - 258, /* (182) tablelist ::= tablelist COMMA ids cpxName */ - 258, /* (183) tablelist ::= tablelist COMMA ids cpxName ids */ - 260, /* (184) tmvar ::= VARIABLE */ - 243, /* (185) interval_opt ::= INTERVAL LP tmvar RP */ - 243, /* (186) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ - 243, /* (187) interval_opt ::= */ - 244, /* (188) session_option ::= */ - 244, /* (189) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - 245, /* (190) windowstate_option ::= */ - 245, /* (191) windowstate_option ::= STATE_WINDOW LP ids RP */ - 246, /* (192) fill_opt ::= */ - 246, /* (193) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - 246, /* (194) fill_opt ::= FILL LP ID RP */ - 247, /* (195) sliding_opt ::= SLIDING LP tmvar RP */ - 247, /* (196) sliding_opt ::= */ - 249, /* (197) orderby_opt ::= */ - 249, /* (198) orderby_opt ::= ORDER BY sortlist */ - 261, /* (199) sortlist ::= sortlist COMMA item sortorder */ - 261, /* (200) sortlist ::= item sortorder */ - 263, /* (201) item ::= ids cpxName */ - 264, /* (202) sortorder ::= ASC */ - 264, /* (203) sortorder ::= DESC */ - 264, /* (204) sortorder ::= */ - 248, /* (205) groupby_opt ::= */ - 248, /* (206) groupby_opt ::= GROUP BY grouplist */ - 265, /* (207) grouplist ::= grouplist COMMA item */ - 265, /* (208) grouplist ::= item */ - 250, /* (209) having_opt ::= */ - 250, /* (210) having_opt ::= HAVING expr */ - 252, /* (211) limit_opt ::= */ - 252, /* (212) limit_opt ::= LIMIT signed */ - 252, /* (213) limit_opt ::= LIMIT signed OFFSET signed */ - 252, /* (214) limit_opt ::= LIMIT signed COMMA signed */ - 251, /* (215) slimit_opt ::= */ - 251, /* (216) slimit_opt ::= SLIMIT signed */ - 251, /* (217) slimit_opt ::= SLIMIT signed SOFFSET signed */ - 251, /* (218) slimit_opt ::= SLIMIT signed COMMA signed */ - 242, /* (219) where_opt ::= */ - 242, /* (220) where_opt ::= WHERE expr */ - 256, /* (221) expr ::= LP expr RP */ - 256, /* (222) expr ::= ID */ - 256, /* (223) expr ::= ID DOT ID */ - 256, /* (224) expr ::= ID DOT STAR */ - 256, /* (225) expr ::= INTEGER */ - 256, /* (226) expr ::= MINUS INTEGER */ - 256, /* (227) expr ::= PLUS INTEGER */ - 256, /* (228) expr ::= FLOAT */ - 256, /* (229) expr ::= MINUS FLOAT */ - 256, /* (230) expr ::= PLUS FLOAT */ - 256, /* (231) expr ::= STRING */ - 256, /* (232) expr ::= NOW */ - 256, /* (233) expr ::= VARIABLE */ - 256, /* (234) expr ::= PLUS VARIABLE */ - 256, /* (235) expr ::= MINUS VARIABLE */ - 256, /* (236) expr ::= BOOL */ - 256, /* (237) expr ::= NULL */ - 256, /* (238) expr ::= ID LP exprlist RP */ - 256, /* (239) expr ::= ID LP STAR RP */ - 256, /* (240) expr ::= expr IS NULL */ - 256, /* (241) expr ::= expr IS NOT NULL */ - 256, /* (242) expr ::= expr LT expr */ - 256, /* (243) expr ::= expr GT expr */ - 256, /* (244) expr ::= expr LE expr */ - 256, /* (245) expr ::= expr GE expr */ - 256, /* (246) expr ::= expr NE expr */ - 256, /* (247) expr ::= expr EQ expr */ - 256, /* (248) expr ::= expr BETWEEN expr AND expr */ - 256, /* (249) expr ::= expr AND expr */ - 256, /* (250) expr ::= expr OR expr */ - 256, /* (251) expr ::= expr PLUS expr */ - 256, /* (252) expr ::= expr MINUS expr */ - 256, /* (253) expr ::= expr STAR expr */ - 256, /* (254) expr ::= expr SLASH expr */ - 256, /* (255) expr ::= expr REM expr */ - 256, /* (256) expr ::= expr LIKE expr */ - 256, /* (257) expr ::= expr IN LP exprlist RP */ - 266, /* (258) exprlist ::= exprlist COMMA expritem */ - 266, /* (259) exprlist ::= expritem */ - 267, /* (260) expritem ::= expr */ - 267, /* (261) expritem ::= */ - 190, /* (262) cmd ::= RESET QUERY CACHE */ - 190, /* (263) cmd ::= SYNCDB ids REPLICA */ - 190, /* (264) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - 190, /* (265) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - 190, /* (266) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - 190, /* (267) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - 190, /* (268) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - 190, /* (269) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - 190, /* (270) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - 190, /* (271) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - 190, /* (272) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - 190, /* (273) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - 190, /* (274) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - 190, /* (275) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - 190, /* (276) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - 190, /* (277) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - 190, /* (278) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - 190, /* (279) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - 190, /* (280) cmd ::= KILL CONNECTION INTEGER */ - 190, /* (281) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - 190, /* (282) cmd ::= KILL QUERY INTEGER COLON INTEGER */ -}; - -/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number -** of symbols on the right-hand side of that rule. */ -static const signed char yyRuleInfoNRhs[] = { - -1, /* (0) program ::= cmd */ - -2, /* (1) cmd ::= SHOW DATABASES */ - -2, /* (2) cmd ::= SHOW TOPICS */ - -2, /* (3) cmd ::= SHOW MNODES */ - -2, /* (4) cmd ::= SHOW DNODES */ - -2, /* (5) cmd ::= SHOW ACCOUNTS */ - -2, /* (6) cmd ::= SHOW USERS */ - -2, /* (7) cmd ::= SHOW MODULES */ - -2, /* (8) cmd ::= SHOW QUERIES */ - -2, /* (9) cmd ::= SHOW CONNECTIONS */ - -2, /* (10) cmd ::= SHOW STREAMS */ - -2, /* (11) cmd ::= SHOW VARIABLES */ - -2, /* (12) cmd ::= SHOW SCORES */ - -2, /* (13) cmd ::= SHOW GRANTS */ - -2, /* (14) cmd ::= SHOW VNODES */ - -3, /* (15) cmd ::= SHOW VNODES IPTOKEN */ - 0, /* (16) dbPrefix ::= */ - -2, /* (17) dbPrefix ::= ids DOT */ - 0, /* (18) cpxName ::= */ - -2, /* (19) cpxName ::= DOT ids */ - -5, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */ - -5, /* (21) cmd ::= SHOW CREATE STABLE ids cpxName */ - -4, /* (22) cmd ::= SHOW CREATE DATABASE ids */ - -3, /* (23) cmd ::= SHOW dbPrefix TABLES */ - -5, /* (24) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - -3, /* (25) cmd ::= SHOW dbPrefix STABLES */ - -5, /* (26) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - -3, /* (27) cmd ::= SHOW dbPrefix VGROUPS */ - -4, /* (28) cmd ::= SHOW dbPrefix VGROUPS ids */ - -5, /* (29) cmd ::= DROP TABLE ifexists ids cpxName */ - -5, /* (30) cmd ::= DROP STABLE ifexists ids cpxName */ - -4, /* (31) cmd ::= DROP DATABASE ifexists ids */ - -4, /* (32) cmd ::= DROP TOPIC ifexists ids */ - -3, /* (33) cmd ::= DROP DNODE ids */ - -3, /* (34) cmd ::= DROP USER ids */ - -3, /* (35) cmd ::= DROP ACCOUNT ids */ - -2, /* (36) cmd ::= USE ids */ - -3, /* (37) cmd ::= DESCRIBE ids cpxName */ - -5, /* (38) cmd ::= ALTER USER ids PASS ids */ - -5, /* (39) cmd ::= ALTER USER ids PRIVILEGE ids */ - -4, /* (40) cmd ::= ALTER DNODE ids ids */ - -5, /* (41) cmd ::= ALTER DNODE ids ids ids */ - -3, /* (42) cmd ::= ALTER LOCAL ids */ - -4, /* (43) cmd ::= ALTER LOCAL ids ids */ - -4, /* (44) cmd ::= ALTER DATABASE ids alter_db_optr */ - -4, /* (45) cmd ::= ALTER TOPIC ids alter_topic_optr */ - -4, /* (46) cmd ::= ALTER ACCOUNT ids acct_optr */ - -6, /* (47) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - -1, /* (48) ids ::= ID */ - -1, /* (49) ids ::= STRING */ - -2, /* (50) ifexists ::= IF EXISTS */ - 0, /* (51) ifexists ::= */ - -3, /* (52) ifnotexists ::= IF NOT EXISTS */ - 0, /* (53) ifnotexists ::= */ - -3, /* (54) cmd ::= CREATE DNODE ids */ - -6, /* (55) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - -5, /* (56) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - -5, /* (57) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ - -5, /* (58) cmd ::= CREATE USER ids PASS ids */ - 0, /* (59) pps ::= */ - -2, /* (60) pps ::= PPS INTEGER */ - 0, /* (61) tseries ::= */ - -2, /* (62) tseries ::= TSERIES INTEGER */ - 0, /* (63) dbs ::= */ - -2, /* (64) dbs ::= DBS INTEGER */ - 0, /* (65) streams ::= */ - -2, /* (66) streams ::= STREAMS INTEGER */ - 0, /* (67) storage ::= */ - -2, /* (68) storage ::= STORAGE INTEGER */ - 0, /* (69) qtime ::= */ - -2, /* (70) qtime ::= QTIME INTEGER */ - 0, /* (71) users ::= */ - -2, /* (72) users ::= USERS INTEGER */ - 0, /* (73) conns ::= */ - -2, /* (74) conns ::= CONNS INTEGER */ - 0, /* (75) state ::= */ - -2, /* (76) state ::= STATE ids */ - -9, /* (77) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - -3, /* (78) intitemlist ::= intitemlist COMMA intitem */ - -1, /* (79) intitemlist ::= intitem */ - -1, /* (80) intitem ::= INTEGER */ - -2, /* (81) keep ::= KEEP intitemlist */ - -2, /* (82) cache ::= CACHE INTEGER */ - -2, /* (83) replica ::= REPLICA INTEGER */ - -2, /* (84) quorum ::= QUORUM INTEGER */ - -2, /* (85) days ::= DAYS INTEGER */ - -2, /* (86) minrows ::= MINROWS INTEGER */ - -2, /* (87) maxrows ::= MAXROWS INTEGER */ - -2, /* (88) blocks ::= BLOCKS INTEGER */ - -2, /* (89) ctime ::= CTIME INTEGER */ - -2, /* (90) wal ::= WAL INTEGER */ - -2, /* (91) fsync ::= FSYNC INTEGER */ - -2, /* (92) comp ::= COMP INTEGER */ - -2, /* (93) prec ::= PRECISION STRING */ - -2, /* (94) update ::= UPDATE INTEGER */ - -2, /* (95) cachelast ::= CACHELAST INTEGER */ - -2, /* (96) partitions ::= PARTITIONS INTEGER */ - 0, /* (97) db_optr ::= */ - -2, /* (98) db_optr ::= db_optr cache */ - -2, /* (99) db_optr ::= db_optr replica */ - -2, /* (100) db_optr ::= db_optr quorum */ - -2, /* (101) db_optr ::= db_optr days */ - -2, /* (102) db_optr ::= db_optr minrows */ - -2, /* (103) db_optr ::= db_optr maxrows */ - -2, /* (104) db_optr ::= db_optr blocks */ - -2, /* (105) db_optr ::= db_optr ctime */ - -2, /* (106) db_optr ::= db_optr wal */ - -2, /* (107) db_optr ::= db_optr fsync */ - -2, /* (108) db_optr ::= db_optr comp */ - -2, /* (109) db_optr ::= db_optr prec */ - -2, /* (110) db_optr ::= db_optr keep */ - -2, /* (111) db_optr ::= db_optr update */ - -2, /* (112) db_optr ::= db_optr cachelast */ - -1, /* (113) topic_optr ::= db_optr */ - -2, /* (114) topic_optr ::= topic_optr partitions */ - 0, /* (115) alter_db_optr ::= */ - -2, /* (116) alter_db_optr ::= alter_db_optr replica */ - -2, /* (117) alter_db_optr ::= alter_db_optr quorum */ - -2, /* (118) alter_db_optr ::= alter_db_optr keep */ - -2, /* (119) alter_db_optr ::= alter_db_optr blocks */ - -2, /* (120) alter_db_optr ::= alter_db_optr comp */ - -2, /* (121) alter_db_optr ::= alter_db_optr wal */ - -2, /* (122) alter_db_optr ::= alter_db_optr fsync */ - -2, /* (123) alter_db_optr ::= alter_db_optr update */ - -2, /* (124) alter_db_optr ::= alter_db_optr cachelast */ - -1, /* (125) alter_topic_optr ::= alter_db_optr */ - -2, /* (126) alter_topic_optr ::= alter_topic_optr partitions */ - -1, /* (127) typename ::= ids */ - -4, /* (128) typename ::= ids LP signed RP */ - -2, /* (129) typename ::= ids UNSIGNED */ - -1, /* (130) signed ::= INTEGER */ - -2, /* (131) signed ::= PLUS INTEGER */ - -2, /* (132) signed ::= MINUS INTEGER */ - -3, /* (133) cmd ::= CREATE TABLE create_table_args */ - -3, /* (134) cmd ::= CREATE TABLE create_stable_args */ - -3, /* (135) cmd ::= CREATE STABLE create_stable_args */ - -3, /* (136) cmd ::= CREATE TABLE create_table_list */ - -1, /* (137) create_table_list ::= create_from_stable */ - -2, /* (138) create_table_list ::= create_table_list create_from_stable */ - -6, /* (139) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - -10, /* (140) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - -10, /* (141) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ - -13, /* (142) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ - -3, /* (143) tagNamelist ::= tagNamelist COMMA ids */ - -1, /* (144) tagNamelist ::= ids */ - -5, /* (145) create_table_args ::= ifnotexists ids cpxName AS select */ - -3, /* (146) columnlist ::= columnlist COMMA column */ - -1, /* (147) columnlist ::= column */ - -2, /* (148) column ::= ids typename */ - -3, /* (149) tagitemlist ::= tagitemlist COMMA tagitem */ - -1, /* (150) tagitemlist ::= tagitem */ - -1, /* (151) tagitem ::= INTEGER */ - -1, /* (152) tagitem ::= FLOAT */ - -1, /* (153) tagitem ::= STRING */ - -1, /* (154) tagitem ::= BOOL */ - -1, /* (155) tagitem ::= NULL */ - -2, /* (156) tagitem ::= MINUS INTEGER */ - -2, /* (157) tagitem ::= MINUS FLOAT */ - -2, /* (158) tagitem ::= PLUS INTEGER */ - -2, /* (159) tagitem ::= PLUS FLOAT */ - -14, /* (160) select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ - -3, /* (161) select ::= LP select RP */ - -1, /* (162) union ::= select */ - -4, /* (163) union ::= union UNION ALL select */ - -1, /* (164) cmd ::= union */ - -2, /* (165) select ::= SELECT selcollist */ - -2, /* (166) sclp ::= selcollist COMMA */ - 0, /* (167) sclp ::= */ - -4, /* (168) selcollist ::= sclp distinct expr as */ - -2, /* (169) selcollist ::= sclp STAR */ - -2, /* (170) as ::= AS ids */ - -1, /* (171) as ::= ids */ - 0, /* (172) as ::= */ - -1, /* (173) distinct ::= DISTINCT */ - 0, /* (174) distinct ::= */ - -2, /* (175) from ::= FROM tablelist */ - -2, /* (176) from ::= FROM sub */ - -3, /* (177) sub ::= LP union RP */ - -4, /* (178) sub ::= LP union RP ids */ - -6, /* (179) sub ::= sub COMMA LP union RP ids */ - -2, /* (180) tablelist ::= ids cpxName */ - -3, /* (181) tablelist ::= ids cpxName ids */ - -4, /* (182) tablelist ::= tablelist COMMA ids cpxName */ - -5, /* (183) tablelist ::= tablelist COMMA ids cpxName ids */ - -1, /* (184) tmvar ::= VARIABLE */ - -4, /* (185) interval_opt ::= INTERVAL LP tmvar RP */ - -6, /* (186) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ - 0, /* (187) interval_opt ::= */ - 0, /* (188) session_option ::= */ - -7, /* (189) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - 0, /* (190) windowstate_option ::= */ - -4, /* (191) windowstate_option ::= STATE_WINDOW LP ids RP */ - 0, /* (192) fill_opt ::= */ - -6, /* (193) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - -4, /* (194) fill_opt ::= FILL LP ID RP */ - -4, /* (195) sliding_opt ::= SLIDING LP tmvar RP */ - 0, /* (196) sliding_opt ::= */ - 0, /* (197) orderby_opt ::= */ - -3, /* (198) orderby_opt ::= ORDER BY sortlist */ - -4, /* (199) sortlist ::= sortlist COMMA item sortorder */ - -2, /* (200) sortlist ::= item sortorder */ - -2, /* (201) item ::= ids cpxName */ - -1, /* (202) sortorder ::= ASC */ - -1, /* (203) sortorder ::= DESC */ - 0, /* (204) sortorder ::= */ - 0, /* (205) groupby_opt ::= */ - -3, /* (206) groupby_opt ::= GROUP BY grouplist */ - -3, /* (207) grouplist ::= grouplist COMMA item */ - -1, /* (208) grouplist ::= item */ - 0, /* (209) having_opt ::= */ - -2, /* (210) having_opt ::= HAVING expr */ - 0, /* (211) limit_opt ::= */ - -2, /* (212) limit_opt ::= LIMIT signed */ - -4, /* (213) limit_opt ::= LIMIT signed OFFSET signed */ - -4, /* (214) limit_opt ::= LIMIT signed COMMA signed */ - 0, /* (215) slimit_opt ::= */ - -2, /* (216) slimit_opt ::= SLIMIT signed */ - -4, /* (217) slimit_opt ::= SLIMIT signed SOFFSET signed */ - -4, /* (218) slimit_opt ::= SLIMIT signed COMMA signed */ - 0, /* (219) where_opt ::= */ - -2, /* (220) where_opt ::= WHERE expr */ - -3, /* (221) expr ::= LP expr RP */ - -1, /* (222) expr ::= ID */ - -3, /* (223) expr ::= ID DOT ID */ - -3, /* (224) expr ::= ID DOT STAR */ - -1, /* (225) expr ::= INTEGER */ - -2, /* (226) expr ::= MINUS INTEGER */ - -2, /* (227) expr ::= PLUS INTEGER */ - -1, /* (228) expr ::= FLOAT */ - -2, /* (229) expr ::= MINUS FLOAT */ - -2, /* (230) expr ::= PLUS FLOAT */ - -1, /* (231) expr ::= STRING */ - -1, /* (232) expr ::= NOW */ - -1, /* (233) expr ::= VARIABLE */ - -2, /* (234) expr ::= PLUS VARIABLE */ - -2, /* (235) expr ::= MINUS VARIABLE */ - -1, /* (236) expr ::= BOOL */ - -1, /* (237) expr ::= NULL */ - -4, /* (238) expr ::= ID LP exprlist RP */ - -4, /* (239) expr ::= ID LP STAR RP */ - -3, /* (240) expr ::= expr IS NULL */ - -4, /* (241) expr ::= expr IS NOT NULL */ - -3, /* (242) expr ::= expr LT expr */ - -3, /* (243) expr ::= expr GT expr */ - -3, /* (244) expr ::= expr LE expr */ - -3, /* (245) expr ::= expr GE expr */ - -3, /* (246) expr ::= expr NE expr */ - -3, /* (247) expr ::= expr EQ expr */ - -5, /* (248) expr ::= expr BETWEEN expr AND expr */ - -3, /* (249) expr ::= expr AND expr */ - -3, /* (250) expr ::= expr OR expr */ - -3, /* (251) expr ::= expr PLUS expr */ - -3, /* (252) expr ::= expr MINUS expr */ - -3, /* (253) expr ::= expr STAR expr */ - -3, /* (254) expr ::= expr SLASH expr */ - -3, /* (255) expr ::= expr REM expr */ - -3, /* (256) expr ::= expr LIKE expr */ - -5, /* (257) expr ::= expr IN LP exprlist RP */ - -3, /* (258) exprlist ::= exprlist COMMA expritem */ - -1, /* (259) exprlist ::= expritem */ - -1, /* (260) expritem ::= expr */ - 0, /* (261) expritem ::= */ - -3, /* (262) cmd ::= RESET QUERY CACHE */ - -3, /* (263) cmd ::= SYNCDB ids REPLICA */ - -7, /* (264) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - -7, /* (265) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - -7, /* (266) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - -7, /* (267) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - -7, /* (268) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - -8, /* (269) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - -9, /* (270) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - -7, /* (271) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - -7, /* (272) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - -7, /* (273) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - -7, /* (274) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - -7, /* (275) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - -7, /* (276) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - -8, /* (277) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - -9, /* (278) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - -7, /* (279) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - -3, /* (280) cmd ::= KILL CONNECTION INTEGER */ - -5, /* (281) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - -5, /* (282) cmd ::= KILL QUERY INTEGER COLON INTEGER */ +/* The following table contains information about every rule that +** is used during the reduce. +*/ +static const struct { + YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + signed char nrhs; /* Negative of the number of RHS symbols in the rule */ +} yyRuleInfo[] = { + { 190, -1 }, /* (0) program ::= cmd */ + { 191, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 191, -2 }, /* (2) cmd ::= SHOW TOPICS */ + { 191, -2 }, /* (3) cmd ::= SHOW MNODES */ + { 191, -2 }, /* (4) cmd ::= SHOW DNODES */ + { 191, -2 }, /* (5) cmd ::= SHOW ACCOUNTS */ + { 191, -2 }, /* (6) cmd ::= SHOW USERS */ + { 191, -2 }, /* (7) cmd ::= SHOW MODULES */ + { 191, -2 }, /* (8) cmd ::= SHOW QUERIES */ + { 191, -2 }, /* (9) cmd ::= SHOW CONNECTIONS */ + { 191, -2 }, /* (10) cmd ::= SHOW STREAMS */ + { 191, -2 }, /* (11) cmd ::= SHOW VARIABLES */ + { 191, -2 }, /* (12) cmd ::= SHOW SCORES */ + { 191, -2 }, /* (13) cmd ::= SHOW GRANTS */ + { 191, -2 }, /* (14) cmd ::= SHOW VNODES */ + { 191, -3 }, /* (15) cmd ::= SHOW VNODES IPTOKEN */ + { 192, 0 }, /* (16) dbPrefix ::= */ + { 192, -2 }, /* (17) dbPrefix ::= ids DOT */ + { 194, 0 }, /* (18) cpxName ::= */ + { 194, -2 }, /* (19) cpxName ::= DOT ids */ + { 191, -5 }, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */ + { 191, -5 }, /* (21) cmd ::= SHOW CREATE STABLE ids cpxName */ + { 191, -4 }, /* (22) cmd ::= SHOW CREATE DATABASE ids */ + { 191, -3 }, /* (23) cmd ::= SHOW dbPrefix TABLES */ + { 191, -5 }, /* (24) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 191, -3 }, /* (25) cmd ::= SHOW dbPrefix STABLES */ + { 191, -5 }, /* (26) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 191, -3 }, /* (27) cmd ::= SHOW dbPrefix VGROUPS */ + { 191, -4 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS ids */ + { 191, -5 }, /* (29) cmd ::= DROP TABLE ifexists ids cpxName */ + { 191, -5 }, /* (30) cmd ::= DROP STABLE ifexists ids cpxName */ + { 191, -4 }, /* (31) cmd ::= DROP DATABASE ifexists ids */ + { 191, -4 }, /* (32) cmd ::= DROP TOPIC ifexists ids */ + { 191, -3 }, /* (33) cmd ::= DROP DNODE ids */ + { 191, -3 }, /* (34) cmd ::= DROP USER ids */ + { 191, -3 }, /* (35) cmd ::= DROP ACCOUNT ids */ + { 191, -2 }, /* (36) cmd ::= USE ids */ + { 191, -3 }, /* (37) cmd ::= DESCRIBE ids cpxName */ + { 191, -5 }, /* (38) cmd ::= ALTER USER ids PASS ids */ + { 191, -5 }, /* (39) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 191, -4 }, /* (40) cmd ::= ALTER DNODE ids ids */ + { 191, -5 }, /* (41) cmd ::= ALTER DNODE ids ids ids */ + { 191, -3 }, /* (42) cmd ::= ALTER LOCAL ids */ + { 191, -4 }, /* (43) cmd ::= ALTER LOCAL ids ids */ + { 191, -4 }, /* (44) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 191, -4 }, /* (45) cmd ::= ALTER TOPIC ids alter_topic_optr */ + { 191, -4 }, /* (46) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 191, -6 }, /* (47) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 193, -1 }, /* (48) ids ::= ID */ + { 193, -1 }, /* (49) ids ::= STRING */ + { 195, -2 }, /* (50) ifexists ::= IF EXISTS */ + { 195, 0 }, /* (51) ifexists ::= */ + { 199, -3 }, /* (52) ifnotexists ::= IF NOT EXISTS */ + { 199, 0 }, /* (53) ifnotexists ::= */ + { 191, -3 }, /* (54) cmd ::= CREATE DNODE ids */ + { 191, -6 }, /* (55) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 191, -5 }, /* (56) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 191, -5 }, /* (57) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ + { 191, -5 }, /* (58) cmd ::= CREATE USER ids PASS ids */ + { 202, 0 }, /* (59) pps ::= */ + { 202, -2 }, /* (60) pps ::= PPS INTEGER */ + { 203, 0 }, /* (61) tseries ::= */ + { 203, -2 }, /* (62) tseries ::= TSERIES INTEGER */ + { 204, 0 }, /* (63) dbs ::= */ + { 204, -2 }, /* (64) dbs ::= DBS INTEGER */ + { 205, 0 }, /* (65) streams ::= */ + { 205, -2 }, /* (66) streams ::= STREAMS INTEGER */ + { 206, 0 }, /* (67) storage ::= */ + { 206, -2 }, /* (68) storage ::= STORAGE INTEGER */ + { 207, 0 }, /* (69) qtime ::= */ + { 207, -2 }, /* (70) qtime ::= QTIME INTEGER */ + { 208, 0 }, /* (71) users ::= */ + { 208, -2 }, /* (72) users ::= USERS INTEGER */ + { 209, 0 }, /* (73) conns ::= */ + { 209, -2 }, /* (74) conns ::= CONNS INTEGER */ + { 210, 0 }, /* (75) state ::= */ + { 210, -2 }, /* (76) state ::= STATE ids */ + { 198, -9 }, /* (77) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 211, -3 }, /* (78) intitemlist ::= intitemlist COMMA intitem */ + { 211, -1 }, /* (79) intitemlist ::= intitem */ + { 212, -1 }, /* (80) intitem ::= INTEGER */ + { 213, -2 }, /* (81) keep ::= KEEP intitemlist */ + { 214, -2 }, /* (82) cache ::= CACHE INTEGER */ + { 215, -2 }, /* (83) replica ::= REPLICA INTEGER */ + { 216, -2 }, /* (84) quorum ::= QUORUM INTEGER */ + { 217, -2 }, /* (85) days ::= DAYS INTEGER */ + { 218, -2 }, /* (86) minrows ::= MINROWS INTEGER */ + { 219, -2 }, /* (87) maxrows ::= MAXROWS INTEGER */ + { 220, -2 }, /* (88) blocks ::= BLOCKS INTEGER */ + { 221, -2 }, /* (89) ctime ::= CTIME INTEGER */ + { 222, -2 }, /* (90) wal ::= WAL INTEGER */ + { 223, -2 }, /* (91) fsync ::= FSYNC INTEGER */ + { 224, -2 }, /* (92) comp ::= COMP INTEGER */ + { 225, -2 }, /* (93) prec ::= PRECISION STRING */ + { 226, -2 }, /* (94) update ::= UPDATE INTEGER */ + { 227, -2 }, /* (95) cachelast ::= CACHELAST INTEGER */ + { 228, -2 }, /* (96) partitions ::= PARTITIONS INTEGER */ + { 200, 0 }, /* (97) db_optr ::= */ + { 200, -2 }, /* (98) db_optr ::= db_optr cache */ + { 200, -2 }, /* (99) db_optr ::= db_optr replica */ + { 200, -2 }, /* (100) db_optr ::= db_optr quorum */ + { 200, -2 }, /* (101) db_optr ::= db_optr days */ + { 200, -2 }, /* (102) db_optr ::= db_optr minrows */ + { 200, -2 }, /* (103) db_optr ::= db_optr maxrows */ + { 200, -2 }, /* (104) db_optr ::= db_optr blocks */ + { 200, -2 }, /* (105) db_optr ::= db_optr ctime */ + { 200, -2 }, /* (106) db_optr ::= db_optr wal */ + { 200, -2 }, /* (107) db_optr ::= db_optr fsync */ + { 200, -2 }, /* (108) db_optr ::= db_optr comp */ + { 200, -2 }, /* (109) db_optr ::= db_optr prec */ + { 200, -2 }, /* (110) db_optr ::= db_optr keep */ + { 200, -2 }, /* (111) db_optr ::= db_optr update */ + { 200, -2 }, /* (112) db_optr ::= db_optr cachelast */ + { 201, -1 }, /* (113) topic_optr ::= db_optr */ + { 201, -2 }, /* (114) topic_optr ::= topic_optr partitions */ + { 196, 0 }, /* (115) alter_db_optr ::= */ + { 196, -2 }, /* (116) alter_db_optr ::= alter_db_optr replica */ + { 196, -2 }, /* (117) alter_db_optr ::= alter_db_optr quorum */ + { 196, -2 }, /* (118) alter_db_optr ::= alter_db_optr keep */ + { 196, -2 }, /* (119) alter_db_optr ::= alter_db_optr blocks */ + { 196, -2 }, /* (120) alter_db_optr ::= alter_db_optr comp */ + { 196, -2 }, /* (121) alter_db_optr ::= alter_db_optr wal */ + { 196, -2 }, /* (122) alter_db_optr ::= alter_db_optr fsync */ + { 196, -2 }, /* (123) alter_db_optr ::= alter_db_optr update */ + { 196, -2 }, /* (124) alter_db_optr ::= alter_db_optr cachelast */ + { 197, -1 }, /* (125) alter_topic_optr ::= alter_db_optr */ + { 197, -2 }, /* (126) alter_topic_optr ::= alter_topic_optr partitions */ + { 229, -1 }, /* (127) typename ::= ids */ + { 229, -4 }, /* (128) typename ::= ids LP signed RP */ + { 229, -2 }, /* (129) typename ::= ids UNSIGNED */ + { 230, -1 }, /* (130) signed ::= INTEGER */ + { 230, -2 }, /* (131) signed ::= PLUS INTEGER */ + { 230, -2 }, /* (132) signed ::= MINUS INTEGER */ + { 191, -3 }, /* (133) cmd ::= CREATE TABLE create_table_args */ + { 191, -3 }, /* (134) cmd ::= CREATE TABLE create_stable_args */ + { 191, -3 }, /* (135) cmd ::= CREATE STABLE create_stable_args */ + { 191, -3 }, /* (136) cmd ::= CREATE TABLE create_table_list */ + { 233, -1 }, /* (137) create_table_list ::= create_from_stable */ + { 233, -2 }, /* (138) create_table_list ::= create_table_list create_from_stable */ + { 231, -6 }, /* (139) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 232, -10 }, /* (140) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 234, -10 }, /* (141) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + { 234, -13 }, /* (142) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + { 237, -3 }, /* (143) tagNamelist ::= tagNamelist COMMA ids */ + { 237, -1 }, /* (144) tagNamelist ::= ids */ + { 231, -5 }, /* (145) create_table_args ::= ifnotexists ids cpxName AS select */ + { 235, -3 }, /* (146) columnlist ::= columnlist COMMA column */ + { 235, -1 }, /* (147) columnlist ::= column */ + { 239, -2 }, /* (148) column ::= ids typename */ + { 236, -3 }, /* (149) tagitemlist ::= tagitemlist COMMA tagitem */ + { 236, -1 }, /* (150) tagitemlist ::= tagitem */ + { 240, -1 }, /* (151) tagitem ::= INTEGER */ + { 240, -1 }, /* (152) tagitem ::= FLOAT */ + { 240, -1 }, /* (153) tagitem ::= STRING */ + { 240, -1 }, /* (154) tagitem ::= BOOL */ + { 240, -1 }, /* (155) tagitem ::= NULL */ + { 240, -2 }, /* (156) tagitem ::= MINUS INTEGER */ + { 240, -2 }, /* (157) tagitem ::= MINUS FLOAT */ + { 240, -2 }, /* (158) tagitem ::= PLUS INTEGER */ + { 240, -2 }, /* (159) tagitem ::= PLUS FLOAT */ + { 238, -14 }, /* (160) select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + { 238, -3 }, /* (161) select ::= LP select RP */ + { 254, -1 }, /* (162) union ::= select */ + { 254, -4 }, /* (163) union ::= union UNION ALL select */ + { 191, -1 }, /* (164) cmd ::= union */ + { 238, -2 }, /* (165) select ::= SELECT selcollist */ + { 255, -2 }, /* (166) sclp ::= selcollist COMMA */ + { 255, 0 }, /* (167) sclp ::= */ + { 241, -4 }, /* (168) selcollist ::= sclp distinct expr as */ + { 241, -2 }, /* (169) selcollist ::= sclp STAR */ + { 258, -2 }, /* (170) as ::= AS ids */ + { 258, -1 }, /* (171) as ::= ids */ + { 258, 0 }, /* (172) as ::= */ + { 256, -1 }, /* (173) distinct ::= DISTINCT */ + { 256, 0 }, /* (174) distinct ::= */ + { 242, -2 }, /* (175) from ::= FROM tablelist */ + { 242, -2 }, /* (176) from ::= FROM sub */ + { 260, -3 }, /* (177) sub ::= LP union RP */ + { 260, -4 }, /* (178) sub ::= LP union RP ids */ + { 260, -6 }, /* (179) sub ::= sub COMMA LP union RP ids */ + { 259, -2 }, /* (180) tablelist ::= ids cpxName */ + { 259, -3 }, /* (181) tablelist ::= ids cpxName ids */ + { 259, -4 }, /* (182) tablelist ::= tablelist COMMA ids cpxName */ + { 259, -5 }, /* (183) tablelist ::= tablelist COMMA ids cpxName ids */ + { 261, -1 }, /* (184) tmvar ::= VARIABLE */ + { 244, -4 }, /* (185) interval_opt ::= INTERVAL LP tmvar RP */ + { 244, -6 }, /* (186) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + { 244, 0 }, /* (187) interval_opt ::= */ + { 245, 0 }, /* (188) session_option ::= */ + { 245, -7 }, /* (189) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 246, 0 }, /* (190) windowstate_option ::= */ + { 246, -4 }, /* (191) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 247, 0 }, /* (192) fill_opt ::= */ + { 247, -6 }, /* (193) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 247, -4 }, /* (194) fill_opt ::= FILL LP ID RP */ + { 248, -4 }, /* (195) sliding_opt ::= SLIDING LP tmvar RP */ + { 248, 0 }, /* (196) sliding_opt ::= */ + { 250, 0 }, /* (197) orderby_opt ::= */ + { 250, -3 }, /* (198) orderby_opt ::= ORDER BY sortlist */ + { 262, -4 }, /* (199) sortlist ::= sortlist COMMA item sortorder */ + { 262, -2 }, /* (200) sortlist ::= item sortorder */ + { 264, -2 }, /* (201) item ::= ids cpxName */ + { 265, -1 }, /* (202) sortorder ::= ASC */ + { 265, -1 }, /* (203) sortorder ::= DESC */ + { 265, 0 }, /* (204) sortorder ::= */ + { 249, 0 }, /* (205) groupby_opt ::= */ + { 249, -3 }, /* (206) groupby_opt ::= GROUP BY grouplist */ + { 266, -3 }, /* (207) grouplist ::= grouplist COMMA item */ + { 266, -1 }, /* (208) grouplist ::= item */ + { 251, 0 }, /* (209) having_opt ::= */ + { 251, -2 }, /* (210) having_opt ::= HAVING expr */ + { 253, 0 }, /* (211) limit_opt ::= */ + { 253, -2 }, /* (212) limit_opt ::= LIMIT signed */ + { 253, -4 }, /* (213) limit_opt ::= LIMIT signed OFFSET signed */ + { 253, -4 }, /* (214) limit_opt ::= LIMIT signed COMMA signed */ + { 252, 0 }, /* (215) slimit_opt ::= */ + { 252, -2 }, /* (216) slimit_opt ::= SLIMIT signed */ + { 252, -4 }, /* (217) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 252, -4 }, /* (218) slimit_opt ::= SLIMIT signed COMMA signed */ + { 243, 0 }, /* (219) where_opt ::= */ + { 243, -2 }, /* (220) where_opt ::= WHERE expr */ + { 257, -3 }, /* (221) expr ::= LP expr RP */ + { 257, -1 }, /* (222) expr ::= ID */ + { 257, -3 }, /* (223) expr ::= ID DOT ID */ + { 257, -3 }, /* (224) expr ::= ID DOT STAR */ + { 257, -1 }, /* (225) expr ::= INTEGER */ + { 257, -2 }, /* (226) expr ::= MINUS INTEGER */ + { 257, -2 }, /* (227) expr ::= PLUS INTEGER */ + { 257, -1 }, /* (228) expr ::= FLOAT */ + { 257, -2 }, /* (229) expr ::= MINUS FLOAT */ + { 257, -2 }, /* (230) expr ::= PLUS FLOAT */ + { 257, -1 }, /* (231) expr ::= STRING */ + { 257, -1 }, /* (232) expr ::= NOW */ + { 257, -1 }, /* (233) expr ::= VARIABLE */ + { 257, -2 }, /* (234) expr ::= PLUS VARIABLE */ + { 257, -2 }, /* (235) expr ::= MINUS VARIABLE */ + { 257, -1 }, /* (236) expr ::= BOOL */ + { 257, -1 }, /* (237) expr ::= NULL */ + { 257, -4 }, /* (238) expr ::= ID LP exprlist RP */ + { 257, -4 }, /* (239) expr ::= ID LP STAR RP */ + { 257, -3 }, /* (240) expr ::= expr IS NULL */ + { 257, -4 }, /* (241) expr ::= expr IS NOT NULL */ + { 257, -3 }, /* (242) expr ::= expr LT expr */ + { 257, -3 }, /* (243) expr ::= expr GT expr */ + { 257, -3 }, /* (244) expr ::= expr LE expr */ + { 257, -3 }, /* (245) expr ::= expr GE expr */ + { 257, -3 }, /* (246) expr ::= expr NE expr */ + { 257, -3 }, /* (247) expr ::= expr EQ expr */ + { 257, -5 }, /* (248) expr ::= expr BETWEEN expr AND expr */ + { 257, -3 }, /* (249) expr ::= expr AND expr */ + { 257, -3 }, /* (250) expr ::= expr OR expr */ + { 257, -3 }, /* (251) expr ::= expr PLUS expr */ + { 257, -3 }, /* (252) expr ::= expr MINUS expr */ + { 257, -3 }, /* (253) expr ::= expr STAR expr */ + { 257, -3 }, /* (254) expr ::= expr SLASH expr */ + { 257, -3 }, /* (255) expr ::= expr REM expr */ + { 257, -3 }, /* (256) expr ::= expr LIKE expr */ + { 257, -5 }, /* (257) expr ::= expr IN LP exprlist RP */ + { 267, -3 }, /* (258) exprlist ::= exprlist COMMA expritem */ + { 267, -1 }, /* (259) exprlist ::= expritem */ + { 268, -1 }, /* (260) expritem ::= expr */ + { 268, 0 }, /* (261) expritem ::= */ + { 191, -3 }, /* (262) cmd ::= RESET QUERY CACHE */ + { 191, -3 }, /* (263) cmd ::= SYNCDB ids REPLICA */ + { 191, -7 }, /* (264) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 191, -7 }, /* (265) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 191, -7 }, /* (266) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + { 191, -7 }, /* (267) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 191, -7 }, /* (268) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 191, -8 }, /* (269) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 191, -9 }, /* (270) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 191, -7 }, /* (271) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + { 191, -7 }, /* (272) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 191, -7 }, /* (273) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 191, -7 }, /* (274) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + { 191, -7 }, /* (275) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 191, -7 }, /* (276) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 191, -8 }, /* (277) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 191, -9 }, /* (278) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + { 191, -7 }, /* (279) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + { 191, -3 }, /* (280) cmd ::= KILL CONNECTION INTEGER */ + { 191, -5 }, /* (281) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 191, -5 }, /* (282) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2391,34 +2092,30 @@ static void yy_accept(yyParser*); /* Forward Declaration */ ** only called from one place, optimizing compilers will in-line it, which ** means that the extra parameters have no performance impact. */ -static YYACTIONTYPE yy_reduce( +static void yy_reduce( yyParser *yypParser, /* The parser */ unsigned int yyruleno, /* Number of the rule by which to reduce */ int yyLookahead, /* Lookahead token, or YYNOCODE if none */ ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ - ParseCTX_PDECL /* %extra_context */ ){ int yygoto; /* The next state */ - YYACTIONTYPE yyact; /* The next action */ + int yyact; /* The next action */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ - ParseARG_FETCH + ParseARG_FETCH; (void)yyLookahead; (void)yyLookaheadToken; yymsp = yypParser->yytos; #ifndef NDEBUG if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - yysize = yyRuleInfoNRhs[yyruleno]; + yysize = yyRuleInfo[yyruleno].nrhs; if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", + fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", yyTracePrompt, - yyruleno, yyRuleName[yyruleno], - yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; @@ -2436,19 +2133,13 @@ static YYACTIONTYPE yy_reduce( #if YYSTACKDEPTH>0 if( yypParser->yytos>=yypParser->yystackEnd ){ yyStackOverflow(yypParser); - /* The call to yyStackOverflow() above pops the stack until it is - ** empty, causing the main parser loop to exit. So the return value - ** is never used and does not matter. */ - return 0; + return; } #else if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ if( yyGrowStack(yypParser) ){ yyStackOverflow(yypParser); - /* The call to yyStackOverflow() above pops the stack until it is - ** empty, causing the main parser loop to exit. So the return value - ** is never used and does not matter. */ - return 0; + return; } yymsp = yypParser->yytos; } @@ -2639,13 +2330,13 @@ static YYACTIONTYPE yy_reduce( break; case 44: /* cmd ::= ALTER DATABASE ids alter_db_optr */ case 45: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==45); -{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy22, &t);} +{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy372, &t);} break; case 46: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy83);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy77);} break; case 47: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy83);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy77);} break; case 48: /* ids ::= ID */ case 49: /* ids ::= STRING */ yytestcase(yyruleno==49); @@ -2667,11 +2358,11 @@ static YYACTIONTYPE yy_reduce( { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; case 55: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy83);} +{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy77);} break; case 56: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ case 57: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==57); -{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy22, &yymsp[-2].minor.yy0);} +{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy372, &yymsp[-2].minor.yy0);} break; case 58: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} @@ -2700,38 +2391,38 @@ static YYACTIONTYPE yy_reduce( break; case 77: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { - yylhsminor.yy83.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yylhsminor.yy83.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yylhsminor.yy83.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yylhsminor.yy83.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yylhsminor.yy83.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yylhsminor.yy83.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy83.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy83.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yylhsminor.yy83.stat = yymsp[0].minor.yy0; + yylhsminor.yy77.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy77.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy77.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy77.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy77.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy77.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy77.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy77.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy77.stat = yymsp[0].minor.yy0; } - yymsp[-8].minor.yy83 = yylhsminor.yy83; + yymsp[-8].minor.yy77 = yylhsminor.yy77; break; case 78: /* intitemlist ::= intitemlist COMMA intitem */ case 149: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==149); -{ yylhsminor.yy325 = tVariantListAppend(yymsp[-2].minor.yy325, &yymsp[0].minor.yy442, -1); } - yymsp[-2].minor.yy325 = yylhsminor.yy325; +{ yylhsminor.yy93 = tVariantListAppend(yymsp[-2].minor.yy93, &yymsp[0].minor.yy518, -1); } + yymsp[-2].minor.yy93 = yylhsminor.yy93; break; case 79: /* intitemlist ::= intitem */ case 150: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==150); -{ yylhsminor.yy325 = tVariantListAppend(NULL, &yymsp[0].minor.yy442, -1); } - yymsp[0].minor.yy325 = yylhsminor.yy325; +{ yylhsminor.yy93 = tVariantListAppend(NULL, &yymsp[0].minor.yy518, -1); } + yymsp[0].minor.yy93 = yylhsminor.yy93; break; case 80: /* intitem ::= INTEGER */ case 151: /* tagitem ::= INTEGER */ yytestcase(yyruleno==151); case 152: /* tagitem ::= FLOAT */ yytestcase(yyruleno==152); case 153: /* tagitem ::= STRING */ yytestcase(yyruleno==153); case 154: /* tagitem ::= BOOL */ yytestcase(yyruleno==154); -{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy442, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy442 = yylhsminor.yy442; +{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy518, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy518 = yylhsminor.yy518; break; case 81: /* keep ::= KEEP intitemlist */ -{ yymsp[-1].minor.yy325 = yymsp[0].minor.yy325; } +{ yymsp[-1].minor.yy93 = yymsp[0].minor.yy93; } break; case 82: /* cache ::= CACHE INTEGER */ case 83: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==83); @@ -2751,219 +2442,219 @@ static YYACTIONTYPE yy_reduce( { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 97: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy22); yymsp[1].minor.yy22.dbType = TSDB_DB_TYPE_DEFAULT;} +{setDefaultCreateDbOption(&yymsp[1].minor.yy372); yymsp[1].minor.yy372.dbType = TSDB_DB_TYPE_DEFAULT;} break; case 98: /* db_optr ::= db_optr cache */ -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 99: /* db_optr ::= db_optr replica */ case 116: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==116); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 100: /* db_optr ::= db_optr quorum */ case 117: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==117); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 101: /* db_optr ::= db_optr days */ -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 102: /* db_optr ::= db_optr minrows */ -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 103: /* db_optr ::= db_optr maxrows */ -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 104: /* db_optr ::= db_optr blocks */ case 119: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==119); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 105: /* db_optr ::= db_optr ctime */ -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 106: /* db_optr ::= db_optr wal */ case 121: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==121); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 107: /* db_optr ::= db_optr fsync */ case 122: /* alter_db_optr ::= alter_db_optr fsync */ yytestcase(yyruleno==122); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 108: /* db_optr ::= db_optr comp */ case 120: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==120); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 109: /* db_optr ::= db_optr prec */ -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.precision = yymsp[0].minor.yy0; } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 110: /* db_optr ::= db_optr keep */ case 118: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==118); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.keep = yymsp[0].minor.yy325; } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.keep = yymsp[0].minor.yy93; } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 111: /* db_optr ::= db_optr update */ case 123: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==123); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 112: /* db_optr ::= db_optr cachelast */ case 124: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==124); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 113: /* topic_optr ::= db_optr */ case 125: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==125); -{ yylhsminor.yy22 = yymsp[0].minor.yy22; yylhsminor.yy22.dbType = TSDB_DB_TYPE_TOPIC; } - yymsp[0].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[0].minor.yy372; yylhsminor.yy372.dbType = TSDB_DB_TYPE_TOPIC; } + yymsp[0].minor.yy372 = yylhsminor.yy372; break; case 114: /* topic_optr ::= topic_optr partitions */ case 126: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==126); -{ yylhsminor.yy22 = yymsp[-1].minor.yy22; yylhsminor.yy22.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy22 = yylhsminor.yy22; +{ yylhsminor.yy372 = yymsp[-1].minor.yy372; yylhsminor.yy372.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy372 = yylhsminor.yy372; break; case 115: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy22); yymsp[1].minor.yy22.dbType = TSDB_DB_TYPE_DEFAULT;} +{ setDefaultCreateDbOption(&yymsp[1].minor.yy372); yymsp[1].minor.yy372.dbType = TSDB_DB_TYPE_DEFAULT;} break; case 127: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yylhsminor.yy47, &yymsp[0].minor.yy0); + tSetColumnType (&yylhsminor.yy325, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy47 = yylhsminor.yy47; + yymsp[0].minor.yy325 = yylhsminor.yy325; break; case 128: /* typename ::= ids LP signed RP */ { - if (yymsp[-1].minor.yy373 <= 0) { + if (yymsp[-1].minor.yy279 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yylhsminor.yy47, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy325, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy373; // negative value of name length - tSetColumnType(&yylhsminor.yy47, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy279; // negative value of name length + tSetColumnType(&yylhsminor.yy325, &yymsp[-3].minor.yy0); } } - yymsp[-3].minor.yy47 = yylhsminor.yy47; + yymsp[-3].minor.yy325 = yylhsminor.yy325; break; case 129: /* typename ::= ids UNSIGNED */ { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); - tSetColumnType (&yylhsminor.yy47, &yymsp[-1].minor.yy0); + tSetColumnType (&yylhsminor.yy325, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy47 = yylhsminor.yy47; + yymsp[-1].minor.yy325 = yylhsminor.yy325; break; case 130: /* signed ::= INTEGER */ -{ yylhsminor.yy373 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[0].minor.yy373 = yylhsminor.yy373; +{ yylhsminor.yy279 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy279 = yylhsminor.yy279; break; case 131: /* signed ::= PLUS INTEGER */ -{ yymsp[-1].minor.yy373 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy279 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; case 132: /* signed ::= MINUS INTEGER */ -{ yymsp[-1].minor.yy373 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} +{ yymsp[-1].minor.yy279 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; case 136: /* cmd ::= CREATE TABLE create_table_list */ -{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy422;} +{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy532;} break; case 137: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); - taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy504); + taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy528); pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE; - yylhsminor.yy422 = pCreateTable; + yylhsminor.yy532 = pCreateTable; } - yymsp[0].minor.yy422 = yylhsminor.yy422; + yymsp[0].minor.yy532 = yylhsminor.yy532; break; case 138: /* create_table_list ::= create_table_list create_from_stable */ { - taosArrayPush(yymsp[-1].minor.yy422->childTableInfo, &yymsp[0].minor.yy504); - yylhsminor.yy422 = yymsp[-1].minor.yy422; + taosArrayPush(yymsp[-1].minor.yy532->childTableInfo, &yymsp[0].minor.yy528); + yylhsminor.yy532 = yymsp[-1].minor.yy532; } - yymsp[-1].minor.yy422 = yylhsminor.yy422; + yymsp[-1].minor.yy532 = yylhsminor.yy532; break; case 139: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yylhsminor.yy422 = tSetCreateTableInfo(yymsp[-1].minor.yy325, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yylhsminor.yy422, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy532 = tSetCreateTableInfo(yymsp[-1].minor.yy93, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy532, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0); } - yymsp[-5].minor.yy422 = yylhsminor.yy422; + yymsp[-5].minor.yy532 = yylhsminor.yy532; break; case 140: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yylhsminor.yy422 = tSetCreateTableInfo(yymsp[-5].minor.yy325, yymsp[-1].minor.yy325, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy422, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy532 = tSetCreateTableInfo(yymsp[-5].minor.yy93, yymsp[-1].minor.yy93, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy532, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy422 = yylhsminor.yy422; + yymsp[-9].minor.yy532 = yylhsminor.yy532; break; case 141: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; - yylhsminor.yy504 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy325, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yylhsminor.yy528 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy93, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy504 = yylhsminor.yy504; + yymsp[-9].minor.yy528 = yylhsminor.yy528; break; case 142: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; - yylhsminor.yy504 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy325, yymsp[-1].minor.yy325, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yylhsminor.yy528 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy93, yymsp[-1].minor.yy93, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } - yymsp[-12].minor.yy504 = yylhsminor.yy504; + yymsp[-12].minor.yy528 = yylhsminor.yy528; break; case 143: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy325, &yymsp[0].minor.yy0); yylhsminor.yy325 = yymsp[-2].minor.yy325; } - yymsp[-2].minor.yy325 = yylhsminor.yy325; +{taosArrayPush(yymsp[-2].minor.yy93, &yymsp[0].minor.yy0); yylhsminor.yy93 = yymsp[-2].minor.yy93; } + yymsp[-2].minor.yy93 = yylhsminor.yy93; break; case 144: /* tagNamelist ::= ids */ -{yylhsminor.yy325 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy325, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy325 = yylhsminor.yy325; +{yylhsminor.yy93 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy93, &yymsp[0].minor.yy0);} + yymsp[0].minor.yy93 = yylhsminor.yy93; break; case 145: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yylhsminor.yy422 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy536, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy422, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy532 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy224, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yylhsminor.yy532, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } - yymsp[-4].minor.yy422 = yylhsminor.yy422; + yymsp[-4].minor.yy532 = yylhsminor.yy532; break; case 146: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy325, &yymsp[0].minor.yy47); yylhsminor.yy325 = yymsp[-2].minor.yy325; } - yymsp[-2].minor.yy325 = yylhsminor.yy325; +{taosArrayPush(yymsp[-2].minor.yy93, &yymsp[0].minor.yy325); yylhsminor.yy93 = yymsp[-2].minor.yy93; } + yymsp[-2].minor.yy93 = yylhsminor.yy93; break; case 147: /* columnlist ::= column */ -{yylhsminor.yy325 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy325, &yymsp[0].minor.yy47);} - yymsp[0].minor.yy325 = yylhsminor.yy325; +{yylhsminor.yy93 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy93, &yymsp[0].minor.yy325);} + yymsp[0].minor.yy93 = yylhsminor.yy93; break; case 148: /* column ::= ids typename */ { - tSetColumnInfo(&yylhsminor.yy47, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy47); + tSetColumnInfo(&yylhsminor.yy325, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy325); } - yymsp[-1].minor.yy47 = yylhsminor.yy47; + yymsp[-1].minor.yy325 = yylhsminor.yy325; break; case 155: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy442, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy442 = yylhsminor.yy442; +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy518, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy518 = yylhsminor.yy518; break; case 156: /* tagitem ::= MINUS INTEGER */ case 157: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==157); @@ -2973,56 +2664,56 @@ static YYACTIONTYPE yy_reduce( yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - tVariantCreate(&yylhsminor.yy442, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy518, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy442 = yylhsminor.yy442; + yymsp[-1].minor.yy518 = yylhsminor.yy518; break; case 160: /* select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ { - yylhsminor.yy536 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy325, yymsp[-11].minor.yy52, yymsp[-10].minor.yy162, yymsp[-4].minor.yy325, yymsp[-3].minor.yy325, &yymsp[-9].minor.yy328, &yymsp[-8].minor.yy84, &yymsp[-7].minor.yy176, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy325, &yymsp[0].minor.yy230, &yymsp[-1].minor.yy230, yymsp[-2].minor.yy162); + yylhsminor.yy224 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy93, yymsp[-11].minor.yy330, yymsp[-10].minor.yy68, yymsp[-4].minor.yy93, yymsp[-3].minor.yy93, &yymsp[-9].minor.yy42, &yymsp[-8].minor.yy15, &yymsp[-7].minor.yy274, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy93, &yymsp[0].minor.yy284, &yymsp[-1].minor.yy284, yymsp[-2].minor.yy68); } - yymsp[-13].minor.yy536 = yylhsminor.yy536; + yymsp[-13].minor.yy224 = yylhsminor.yy224; break; case 161: /* select ::= LP select RP */ -{yymsp[-2].minor.yy536 = yymsp[-1].minor.yy536;} +{yymsp[-2].minor.yy224 = yymsp[-1].minor.yy224;} break; case 162: /* union ::= select */ -{ yylhsminor.yy325 = setSubclause(NULL, yymsp[0].minor.yy536); } - yymsp[0].minor.yy325 = yylhsminor.yy325; +{ yylhsminor.yy93 = setSubclause(NULL, yymsp[0].minor.yy224); } + yymsp[0].minor.yy93 = yylhsminor.yy93; break; case 163: /* union ::= union UNION ALL select */ -{ yylhsminor.yy325 = appendSelectClause(yymsp[-3].minor.yy325, yymsp[0].minor.yy536); } - yymsp[-3].minor.yy325 = yylhsminor.yy325; +{ yylhsminor.yy93 = appendSelectClause(yymsp[-3].minor.yy93, yymsp[0].minor.yy224); } + yymsp[-3].minor.yy93 = yylhsminor.yy93; break; case 164: /* cmd ::= union */ -{ setSqlInfo(pInfo, yymsp[0].minor.yy325, NULL, TSDB_SQL_SELECT); } +{ setSqlInfo(pInfo, yymsp[0].minor.yy93, NULL, TSDB_SQL_SELECT); } break; case 165: /* select ::= SELECT selcollist */ { - yylhsminor.yy536 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy325, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy224 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy93, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - yymsp[-1].minor.yy536 = yylhsminor.yy536; + yymsp[-1].minor.yy224 = yylhsminor.yy224; break; case 166: /* sclp ::= selcollist COMMA */ -{yylhsminor.yy325 = yymsp[-1].minor.yy325;} - yymsp[-1].minor.yy325 = yylhsminor.yy325; +{yylhsminor.yy93 = yymsp[-1].minor.yy93;} + yymsp[-1].minor.yy93 = yylhsminor.yy93; break; case 167: /* sclp ::= */ case 197: /* orderby_opt ::= */ yytestcase(yyruleno==197); -{yymsp[1].minor.yy325 = 0;} +{yymsp[1].minor.yy93 = 0;} break; case 168: /* selcollist ::= sclp distinct expr as */ { - yylhsminor.yy325 = tSqlExprListAppend(yymsp[-3].minor.yy325, yymsp[-1].minor.yy162, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy93 = tSqlExprListAppend(yymsp[-3].minor.yy93, yymsp[-1].minor.yy68, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } - yymsp[-3].minor.yy325 = yylhsminor.yy325; + yymsp[-3].minor.yy93 = yylhsminor.yy93; break; case 169: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); - yylhsminor.yy325 = tSqlExprListAppend(yymsp[-1].minor.yy325, pNode, 0, 0); + yylhsminor.yy93 = tSqlExprListAppend(yymsp[-1].minor.yy93, pNode, 0, 0); } - yymsp[-1].minor.yy325 = yylhsminor.yy325; + yymsp[-1].minor.yy93 = yylhsminor.yy93; break; case 170: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } @@ -3040,79 +2731,77 @@ static YYACTIONTYPE yy_reduce( break; case 175: /* from ::= FROM tablelist */ case 176: /* from ::= FROM sub */ yytestcase(yyruleno==176); -{yymsp[-1].minor.yy52 = yymsp[0].minor.yy52;} +{yymsp[-1].minor.yy330 = yymsp[0].minor.yy330;} break; case 177: /* sub ::= LP union RP */ -{yymsp[-2].minor.yy52 = addSubqueryElem(NULL, yymsp[-1].minor.yy325, NULL);} +{yymsp[-2].minor.yy330 = addSubqueryElem(NULL, yymsp[-1].minor.yy93, NULL);} break; case 178: /* sub ::= LP union RP ids */ -{yymsp[-3].minor.yy52 = addSubqueryElem(NULL, yymsp[-2].minor.yy325, &yymsp[0].minor.yy0);} +{yymsp[-3].minor.yy330 = addSubqueryElem(NULL, yymsp[-2].minor.yy93, &yymsp[0].minor.yy0);} break; case 179: /* sub ::= sub COMMA LP union RP ids */ -{yylhsminor.yy52 = addSubqueryElem(yymsp[-5].minor.yy52, yymsp[-2].minor.yy325, &yymsp[0].minor.yy0);} - yymsp[-5].minor.yy52 = yylhsminor.yy52; +{yylhsminor.yy330 = addSubqueryElem(yymsp[-5].minor.yy330, yymsp[-2].minor.yy93, &yymsp[0].minor.yy0);} + yymsp[-5].minor.yy330 = yylhsminor.yy330; break; case 180: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy52 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy330 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } - yymsp[-1].minor.yy52 = yylhsminor.yy52; + yymsp[-1].minor.yy330 = yylhsminor.yy330; break; case 181: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy52 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy330 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy52 = yylhsminor.yy52; + yymsp[-2].minor.yy330 = yylhsminor.yy330; break; case 182: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy52 = setTableNameList(yymsp[-3].minor.yy52, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy330 = setTableNameList(yymsp[-3].minor.yy330, &yymsp[-1].minor.yy0, NULL); } - yymsp[-3].minor.yy52 = yylhsminor.yy52; + yymsp[-3].minor.yy330 = yylhsminor.yy330; break; case 183: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy52 = setTableNameList(yymsp[-4].minor.yy52, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy330 = setTableNameList(yymsp[-4].minor.yy330, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-4].minor.yy52 = yylhsminor.yy52; + yymsp[-4].minor.yy330 = yylhsminor.yy330; break; case 184: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 185: /* interval_opt ::= INTERVAL LP tmvar RP */ -{yymsp[-3].minor.yy328.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy328.offset.n = 0;} +{yymsp[-3].minor.yy42.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy42.offset.n = 0;} break; case 186: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ -{yymsp[-5].minor.yy328.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy328.offset = yymsp[-1].minor.yy0;} +{yymsp[-5].minor.yy42.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy42.offset = yymsp[-1].minor.yy0;} break; case 187: /* interval_opt ::= */ -{memset(&yymsp[1].minor.yy328, 0, sizeof(yymsp[1].minor.yy328));} +{memset(&yymsp[1].minor.yy42, 0, sizeof(yymsp[1].minor.yy42));} break; case 188: /* session_option ::= */ -{yymsp[1].minor.yy84.col.n = 0; yymsp[1].minor.yy84.gap.n = 0;} +{yymsp[1].minor.yy15.col.n = 0; yymsp[1].minor.yy15.gap.n = 0;} break; case 189: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - yymsp[-6].minor.yy84.col = yymsp[-4].minor.yy0; - yymsp[-6].minor.yy84.gap = yymsp[-1].minor.yy0; + yymsp[-6].minor.yy15.col = yymsp[-4].minor.yy0; + yymsp[-6].minor.yy15.gap = yymsp[-1].minor.yy0; } break; case 190: /* windowstate_option ::= */ -{yymsp[1].minor.yy176.col.n = 0;} +{ yymsp[1].minor.yy274.col.n = 0; yymsp[1].minor.yy274.col.z = NULL;} break; case 191: /* windowstate_option ::= STATE_WINDOW LP ids RP */ -{ - yymsp[-3].minor.yy176.col = yymsp[-1].minor.yy0; -} +{ yymsp[-3].minor.yy274.col = yymsp[-1].minor.yy0; } break; case 192: /* fill_opt ::= */ -{ yymsp[1].minor.yy325 = 0; } +{ yymsp[1].minor.yy93 = 0; } break; case 193: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { @@ -3120,14 +2809,14 @@ static YYACTIONTYPE yy_reduce( toTSDBType(yymsp[-3].minor.yy0.type); tVariantCreate(&A, &yymsp[-3].minor.yy0); - tVariantListInsert(yymsp[-1].minor.yy325, &A, -1, 0); - yymsp[-5].minor.yy325 = yymsp[-1].minor.yy325; + tVariantListInsert(yymsp[-1].minor.yy93, &A, -1, 0); + yymsp[-5].minor.yy93 = yymsp[-1].minor.yy93; } break; case 194: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yymsp[-3].minor.yy325 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy93 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; case 195: /* sliding_opt ::= SLIDING LP tmvar RP */ @@ -3137,235 +2826,235 @@ static YYACTIONTYPE yy_reduce( {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; case 198: /* orderby_opt ::= ORDER BY sortlist */ -{yymsp[-2].minor.yy325 = yymsp[0].minor.yy325;} +{yymsp[-2].minor.yy93 = yymsp[0].minor.yy93;} break; case 199: /* sortlist ::= sortlist COMMA item sortorder */ { - yylhsminor.yy325 = tVariantListAppend(yymsp[-3].minor.yy325, &yymsp[-1].minor.yy442, yymsp[0].minor.yy196); + yylhsminor.yy93 = tVariantListAppend(yymsp[-3].minor.yy93, &yymsp[-1].minor.yy518, yymsp[0].minor.yy150); } - yymsp[-3].minor.yy325 = yylhsminor.yy325; + yymsp[-3].minor.yy93 = yylhsminor.yy93; break; case 200: /* sortlist ::= item sortorder */ { - yylhsminor.yy325 = tVariantListAppend(NULL, &yymsp[-1].minor.yy442, yymsp[0].minor.yy196); + yylhsminor.yy93 = tVariantListAppend(NULL, &yymsp[-1].minor.yy518, yymsp[0].minor.yy150); } - yymsp[-1].minor.yy325 = yylhsminor.yy325; + yymsp[-1].minor.yy93 = yylhsminor.yy93; break; case 201: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yylhsminor.yy442, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy518, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy442 = yylhsminor.yy442; + yymsp[-1].minor.yy518 = yylhsminor.yy518; break; case 202: /* sortorder ::= ASC */ -{ yymsp[0].minor.yy196 = TSDB_ORDER_ASC; } +{ yymsp[0].minor.yy150 = TSDB_ORDER_ASC; } break; case 203: /* sortorder ::= DESC */ -{ yymsp[0].minor.yy196 = TSDB_ORDER_DESC;} +{ yymsp[0].minor.yy150 = TSDB_ORDER_DESC;} break; case 204: /* sortorder ::= */ -{ yymsp[1].minor.yy196 = TSDB_ORDER_ASC; } +{ yymsp[1].minor.yy150 = TSDB_ORDER_ASC; } break; case 205: /* groupby_opt ::= */ -{ yymsp[1].minor.yy325 = 0;} +{ yymsp[1].minor.yy93 = 0;} break; case 206: /* groupby_opt ::= GROUP BY grouplist */ -{ yymsp[-2].minor.yy325 = yymsp[0].minor.yy325;} +{ yymsp[-2].minor.yy93 = yymsp[0].minor.yy93;} break; case 207: /* grouplist ::= grouplist COMMA item */ { - yylhsminor.yy325 = tVariantListAppend(yymsp[-2].minor.yy325, &yymsp[0].minor.yy442, -1); + yylhsminor.yy93 = tVariantListAppend(yymsp[-2].minor.yy93, &yymsp[0].minor.yy518, -1); } - yymsp[-2].minor.yy325 = yylhsminor.yy325; + yymsp[-2].minor.yy93 = yylhsminor.yy93; break; case 208: /* grouplist ::= item */ { - yylhsminor.yy325 = tVariantListAppend(NULL, &yymsp[0].minor.yy442, -1); + yylhsminor.yy93 = tVariantListAppend(NULL, &yymsp[0].minor.yy518, -1); } - yymsp[0].minor.yy325 = yylhsminor.yy325; + yymsp[0].minor.yy93 = yylhsminor.yy93; break; case 209: /* having_opt ::= */ case 219: /* where_opt ::= */ yytestcase(yyruleno==219); case 261: /* expritem ::= */ yytestcase(yyruleno==261); -{yymsp[1].minor.yy162 = 0;} +{yymsp[1].minor.yy68 = 0;} break; case 210: /* having_opt ::= HAVING expr */ case 220: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==220); -{yymsp[-1].minor.yy162 = yymsp[0].minor.yy162;} +{yymsp[-1].minor.yy68 = yymsp[0].minor.yy68;} break; case 211: /* limit_opt ::= */ case 215: /* slimit_opt ::= */ yytestcase(yyruleno==215); -{yymsp[1].minor.yy230.limit = -1; yymsp[1].minor.yy230.offset = 0;} +{yymsp[1].minor.yy284.limit = -1; yymsp[1].minor.yy284.offset = 0;} break; case 212: /* limit_opt ::= LIMIT signed */ case 216: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==216); -{yymsp[-1].minor.yy230.limit = yymsp[0].minor.yy373; yymsp[-1].minor.yy230.offset = 0;} +{yymsp[-1].minor.yy284.limit = yymsp[0].minor.yy279; yymsp[-1].minor.yy284.offset = 0;} break; case 213: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yymsp[-3].minor.yy230.limit = yymsp[-2].minor.yy373; yymsp[-3].minor.yy230.offset = yymsp[0].minor.yy373;} +{ yymsp[-3].minor.yy284.limit = yymsp[-2].minor.yy279; yymsp[-3].minor.yy284.offset = yymsp[0].minor.yy279;} break; case 214: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yymsp[-3].minor.yy230.limit = yymsp[0].minor.yy373; yymsp[-3].minor.yy230.offset = yymsp[-2].minor.yy373;} +{ yymsp[-3].minor.yy284.limit = yymsp[0].minor.yy279; yymsp[-3].minor.yy284.offset = yymsp[-2].minor.yy279;} break; case 217: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yymsp[-3].minor.yy230.limit = yymsp[-2].minor.yy373; yymsp[-3].minor.yy230.offset = yymsp[0].minor.yy373;} +{yymsp[-3].minor.yy284.limit = yymsp[-2].minor.yy279; yymsp[-3].minor.yy284.offset = yymsp[0].minor.yy279;} break; case 218: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yymsp[-3].minor.yy230.limit = yymsp[0].minor.yy373; yymsp[-3].minor.yy230.offset = yymsp[-2].minor.yy373;} +{yymsp[-3].minor.yy284.limit = yymsp[0].minor.yy279; yymsp[-3].minor.yy284.offset = yymsp[-2].minor.yy279;} break; case 221: /* expr ::= LP expr RP */ -{yylhsminor.yy162 = yymsp[-1].minor.yy162; yylhsminor.yy162->token.z = yymsp[-2].minor.yy0.z; yylhsminor.yy162->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = yymsp[-1].minor.yy68; yylhsminor.yy68->token.z = yymsp[-2].minor.yy0.z; yylhsminor.yy68->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 222: /* expr ::= ID */ -{ yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} - yymsp[0].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 223: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 224: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 225: /* expr ::= INTEGER */ -{ yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} - yymsp[0].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 226: /* expr ::= MINUS INTEGER */ case 227: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==227); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} - yymsp[-1].minor.yy162 = yylhsminor.yy162; +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy68 = yylhsminor.yy68; break; case 228: /* expr ::= FLOAT */ -{ yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} - yymsp[0].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 229: /* expr ::= MINUS FLOAT */ case 230: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==230); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} - yymsp[-1].minor.yy162 = yylhsminor.yy162; +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy68 = yylhsminor.yy68; break; case 231: /* expr ::= STRING */ -{ yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} - yymsp[0].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 232: /* expr ::= NOW */ -{ yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } - yymsp[0].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 233: /* expr ::= VARIABLE */ -{ yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} - yymsp[0].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 234: /* expr ::= PLUS VARIABLE */ case 235: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==235); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} - yymsp[-1].minor.yy162 = yylhsminor.yy162; +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} + yymsp[-1].minor.yy68 = yylhsminor.yy68; break; case 236: /* expr ::= BOOL */ -{ yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} - yymsp[0].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 237: /* expr ::= NULL */ -{ yylhsminor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} - yymsp[0].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 238: /* expr ::= ID LP exprlist RP */ -{ yylhsminor.yy162 = tSqlExprCreateFunction(yymsp[-1].minor.yy325, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateFunction(yymsp[-1].minor.yy93, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy68 = yylhsminor.yy68; break; case 239: /* expr ::= ID LP STAR RP */ -{ yylhsminor.yy162 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy162 = yylhsminor.yy162; +{ yylhsminor.yy68 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy68 = yylhsminor.yy68; break; case 240: /* expr ::= expr IS NULL */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, NULL, TK_ISNULL);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, NULL, TK_ISNULL);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 241: /* expr ::= expr IS NOT NULL */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-3].minor.yy162, NULL, TK_NOTNULL);} - yymsp[-3].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-3].minor.yy68, NULL, TK_NOTNULL);} + yymsp[-3].minor.yy68 = yylhsminor.yy68; break; case 242: /* expr ::= expr LT expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_LT);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_LT);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 243: /* expr ::= expr GT expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_GT);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_GT);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 244: /* expr ::= expr LE expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_LE);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_LE);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 245: /* expr ::= expr GE expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_GE);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_GE);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 246: /* expr ::= expr NE expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_NE);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_NE);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 247: /* expr ::= expr EQ expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_EQ);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_EQ);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 248: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy162); yylhsminor.yy162 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy162, yymsp[-2].minor.yy162, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy162, TK_LE), TK_AND);} - yymsp[-4].minor.yy162 = yylhsminor.yy162; +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy68); yylhsminor.yy68 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy68, yymsp[-2].minor.yy68, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy68, TK_LE), TK_AND);} + yymsp[-4].minor.yy68 = yylhsminor.yy68; break; case 249: /* expr ::= expr AND expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_AND);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_AND);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 250: /* expr ::= expr OR expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_OR); } - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_OR); } + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 251: /* expr ::= expr PLUS expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_PLUS); } - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_PLUS); } + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 252: /* expr ::= expr MINUS expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_MINUS); } - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_MINUS); } + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 253: /* expr ::= expr STAR expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_STAR); } - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_STAR); } + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 254: /* expr ::= expr SLASH expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_DIVIDE);} - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_DIVIDE);} + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 255: /* expr ::= expr REM expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_REM); } - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_REM); } + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 256: /* expr ::= expr LIKE expr */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_LIKE); } - yymsp[-2].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-2].minor.yy68, yymsp[0].minor.yy68, TK_LIKE); } + yymsp[-2].minor.yy68 = yylhsminor.yy68; break; case 257: /* expr ::= expr IN LP exprlist RP */ -{yylhsminor.yy162 = tSqlExprCreate(yymsp[-4].minor.yy162, (tSqlExpr*)yymsp[-1].minor.yy325, TK_IN); } - yymsp[-4].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = tSqlExprCreate(yymsp[-4].minor.yy68, (tSqlExpr*)yymsp[-1].minor.yy93, TK_IN); } + yymsp[-4].minor.yy68 = yylhsminor.yy68; break; case 258: /* exprlist ::= exprlist COMMA expritem */ -{yylhsminor.yy325 = tSqlExprListAppend(yymsp[-2].minor.yy325,yymsp[0].minor.yy162,0, 0);} - yymsp[-2].minor.yy325 = yylhsminor.yy325; +{yylhsminor.yy93 = tSqlExprListAppend(yymsp[-2].minor.yy93,yymsp[0].minor.yy68,0, 0);} + yymsp[-2].minor.yy93 = yylhsminor.yy93; break; case 259: /* exprlist ::= expritem */ -{yylhsminor.yy325 = tSqlExprListAppend(0,yymsp[0].minor.yy162,0, 0);} - yymsp[0].minor.yy325 = yylhsminor.yy325; +{yylhsminor.yy93 = tSqlExprListAppend(0,yymsp[0].minor.yy68,0, 0);} + yymsp[0].minor.yy93 = yylhsminor.yy93; break; case 260: /* expritem ::= expr */ -{yylhsminor.yy162 = yymsp[0].minor.yy162;} - yymsp[0].minor.yy162 = yylhsminor.yy162; +{yylhsminor.yy68 = yymsp[0].minor.yy68;} + yymsp[0].minor.yy68 = yylhsminor.yy68; break; case 262: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} @@ -3376,7 +3065,7 @@ static YYACTIONTYPE yy_reduce( case 264: /* 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.yy325, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy93, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; @@ -3394,14 +3083,14 @@ static YYACTIONTYPE yy_reduce( case 266: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy93, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; case 267: /* 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.yy325, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy93, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; @@ -3436,7 +3125,7 @@ static YYACTIONTYPE yy_reduce( toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tVariantListAppend(A, &yymsp[0].minor.yy442, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy518, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); @@ -3445,14 +3134,14 @@ static YYACTIONTYPE yy_reduce( case 271: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy93, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; case 272: /* 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.yy325, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy93, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; @@ -3470,14 +3159,14 @@ static YYACTIONTYPE yy_reduce( case 274: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy93, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; case 275: /* 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.yy325, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy93, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; @@ -3512,7 +3201,7 @@ static YYACTIONTYPE yy_reduce( toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tVariantListAppend(A, &yymsp[0].minor.yy442, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy518, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); @@ -3521,7 +3210,7 @@ static YYACTIONTYPE yy_reduce( case 279: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy93, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; @@ -3538,9 +3227,9 @@ static YYACTIONTYPE yy_reduce( break; /********** End reduce actions ************************************************/ }; - assert( yyrulenostateno = (YYACTIONTYPE)yyact; yymsp->major = (YYCODETYPE)yygoto; yyTraceShift(yypParser, yyact, "... then shift"); - return yyact; } /* @@ -3565,8 +3253,7 @@ static YYACTIONTYPE yy_reduce( static void yy_parse_failed( yyParser *yypParser /* The parser */ ){ - ParseARG_FETCH - ParseCTX_FETCH + ParseARG_FETCH; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); @@ -3577,8 +3264,7 @@ static void yy_parse_failed( ** parser fails */ /************ Begin %parse_failure code ***************************************/ /************ End %parse_failure code *****************************************/ - ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ - ParseCTX_STORE + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } #endif /* YYNOERRORRECOVERY */ @@ -3590,8 +3276,7 @@ static void yy_syntax_error( int yymajor, /* The major type of the error token */ ParseTOKENTYPE yyminor /* The minor type of the error token */ ){ - ParseARG_FETCH - ParseCTX_FETCH + ParseARG_FETCH; #define TOKEN yyminor /************ Begin %syntax_error code ****************************************/ @@ -3617,8 +3302,7 @@ static void yy_syntax_error( assert(len <= outputBufLen); /************ End %syntax_error code ******************************************/ - ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ - ParseCTX_STORE + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } /* @@ -3627,8 +3311,7 @@ static void yy_syntax_error( static void yy_accept( yyParser *yypParser /* The parser */ ){ - ParseARG_FETCH - ParseCTX_FETCH + ParseARG_FETCH; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); @@ -3643,8 +3326,7 @@ static void yy_accept( /*********** Begin %parse_accept code *****************************************/ /*********** End %parse_accept code *******************************************/ - ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ - ParseCTX_STORE + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } /* The main parser program. @@ -3673,47 +3355,45 @@ void Parse( ParseARG_PDECL /* Optional %extra_argument parameter */ ){ YYMINORTYPE yyminorunion; - YYACTIONTYPE yyact; /* The parser action. */ + unsigned int yyact; /* The parser action. */ #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ #endif #ifdef YYERRORSYMBOL int yyerrorhit = 0; /* True if yymajor has invoked an error */ #endif - yyParser *yypParser = (yyParser*)yyp; /* The parser */ - ParseCTX_FETCH - ParseARG_STORE + yyParser *yypParser; /* The parser */ + yypParser = (yyParser*)yyp; assert( yypParser->yytos!=0 ); #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); #endif + ParseARG_STORE; - yyact = yypParser->yytos->stateno; #ifndef NDEBUG if( yyTraceFILE ){ - if( yyact < YY_MIN_REDUCE ){ + int stateno = yypParser->yytos->stateno; + if( stateno < YY_MIN_REDUCE ){ fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", - yyTracePrompt,yyTokenName[yymajor],yyact); + yyTracePrompt,yyTokenName[yymajor],stateno); }else{ fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", - yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE); + yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE); } } #endif do{ - assert( yyact==yypParser->yytos->stateno ); - yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); + yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); if( yyact >= YY_MIN_REDUCE ){ - yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor, - yyminor ParseCTX_PARAM); + yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor); }else if( yyact <= YY_MAX_SHIFTREDUCE ){ - yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor); + yy_shift(yypParser,yyact,yymajor,yyminor); #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt--; #endif - break; + yymajor = YYNOCODE; }else if( yyact==YY_ACCEPT_ACTION ){ yypParser->yytos--; yy_accept(yypParser); @@ -3764,9 +3444,10 @@ void Parse( yymajor = YYNOCODE; }else{ while( yypParser->yytos >= yypParser->yystack + && yymx != YYERRORSYMBOL && (yyact = yy_find_reduce_action( yypParser->yytos->stateno, - YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE + YYERRORSYMBOL)) >= YY_MIN_REDUCE ){ yy_pop_parser_stack(yypParser); } @@ -3783,8 +3464,6 @@ void Parse( } yypParser->yyerrcnt = 3; yyerrorhit = 1; - if( yymajor==YYNOCODE ) break; - yyact = yypParser->yytos->stateno; #elif defined(YYNOERRORRECOVERY) /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to ** do any kind of error recovery. Instead, simply invoke the syntax @@ -3795,7 +3474,8 @@ void Parse( */ yy_syntax_error(yypParser,yymajor, yyminor); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - break; + yymajor = YYNOCODE; + #else /* YYERRORSYMBOL is not defined */ /* This is what we do if the grammar does not define ERROR: ** @@ -3817,10 +3497,10 @@ void Parse( yypParser->yyerrcnt = -1; #endif } - break; + yymajor = YYNOCODE; #endif } - }while( yypParser->yytos>yypParser->yystack ); + }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack ); #ifndef NDEBUG if( yyTraceFILE ){ yyStackEntry *i; @@ -3835,17 +3515,3 @@ void Parse( #endif return; } - -/* -** Return the fallback token corresponding to canonical token iToken, or -** 0 if iToken has no fallback. -*/ -int ParseFallback(int iToken){ -#ifdef YYFALLBACK - assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) ); - return yyFallback[iToken]; -#else - (void)iToken; - return 0; -#endif -} diff --git a/src/tsdb/inc/tsdbint.h b/src/tsdb/inc/tsdbint.h index 7cf88826319b0b4ad8a7d128b19264d2b67434d0..dd43e393102c40d4b12a948a9b4d6d72f30f6dad 100644 --- a/src/tsdb/inc/tsdbint.h +++ b/src/tsdb/inc/tsdbint.h @@ -92,6 +92,7 @@ struct STsdbRepo { pthread_mutex_t mutex; bool repoLocked; int32_t code; // Commit code + bool inCompact; // is in compact process? }; #define REPO_ID(r) (r)->config.tsdbId diff --git a/src/tsdb/src/tsdbCompact.c b/src/tsdb/src/tsdbCompact.c index 635bba388a6063868ca002859044d0845cb5c163..2e8e81b65e565e2b09b5a70685ddfe0c85cd500b 100644 --- a/src/tsdb/src/tsdbCompact.c +++ b/src/tsdb/src/tsdbCompact.c @@ -12,11 +12,516 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "tsdb.h" +#include "tsdbint.h" #ifndef _TSDB_PLUGINS -int tsdbCompact(STsdbRepo *pRepo) { return 0; } -void *tsdbCompactImpl(STsdbRepo *pRepo) { return NULL; } +typedef struct { + STable * pTable; + SBlockIdx * pBlkIdx; + SBlockIdx bindex; + SBlockInfo *pInfo; +} STableCompactH; + +typedef struct { + SRtn rtn; + SFSIter fsIter; + SArray * tbArray; // table array to cache table obj and block indexes + SReadH readh; + SDFileSet wSet; + SArray * aBlkIdx; + SArray * aSupBlk; + SDataCols *pDataCols; +} SCompactH; + +#define TSDB_COMPACT_WSET(pComph) (&((pComph)->wSet)) +#define TSDB_COMPACT_REPO(pComph) TSDB_READ_REPO(&((pComph)->readh)) +#define TSDB_COMPACT_HEAD_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_HEAD) +#define TSDB_COMPACT_DATA_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_DATA) +#define TSDB_COMPACT_LAST_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_LAST) +#define TSDB_COMPACT_BUF(pComph) TSDB_READ_BUF(&((pComph)->readh)) +#define TSDB_COMPACT_COMP_BUF(pComph) TSDB_READ_COMP_BUF(&((pComph)->readh)) + +static int tsdbAsyncCompact(STsdbRepo *pRepo); +static void tsdbStartCompact(STsdbRepo *pRepo); +static void tsdbEndCompact(STsdbRepo *pRepo, int eno); +static int tsdbCompactMeta(STsdbRepo *pRepo); +static int tsdbCompactTSData(STsdbRepo *pRepo); +static int tsdbCompactFSet(SCompactH *pComph, SDFileSet *pSet); +static bool tsdbShouldCompact(SCompactH *pComph); +static int tsdbInitCompactH(SCompactH *pComph, STsdbRepo *pRepo); +static void tsdbDestroyCompactH(SCompactH *pComph); +static int tsdbInitCompTbArray(SCompactH *pComph); +static void tsdbDestroyCompTbArray(SCompactH *pComph); +static int tsdbCacheFSetIndex(SCompactH *pComph); +static int tsdbCompactFSetInit(SCompactH *pComph, SDFileSet *pSet); +static void tsdbCompactFSetEnd(SCompactH *pComph); +static int tsdbCompactFSetImpl(SCompactH *pComph); +static int tsdbWriteBlockToRightFile(SCompactH *pComph, STable *pTable, SDataCols *pDataCols, void **ppBuf, + void **ppCBuf); + +int tsdbCompact(STsdbRepo *pRepo) { return tsdbAsyncCompact(pRepo); } + +void *tsdbCompactImpl(STsdbRepo *pRepo) { + // Check if there are files in TSDB FS to compact + if (REPO_FS(pRepo)->cstatus->pmf == NULL) { + tsdbInfo("vgId:%d no file to compact in FS", REPO_ID(pRepo)); + return NULL; + } + + tsdbStartCompact(pRepo); + + if (tsdbCompactMeta(pRepo) < 0) { + tsdbError("vgId:%d failed to compact META data since %s", REPO_ID(pRepo), tstrerror(terrno)); + goto _err; + } + + if (tsdbCompactTSData(pRepo) < 0) { + tsdbError("vgId:%d failed to compact TS data since %s", REPO_ID(pRepo), tstrerror(terrno)); + goto _err; + } + + tsdbEndCompact(pRepo, TSDB_CODE_SUCCESS); + return NULL; + +_err: + pRepo->code = terrno; + tsdbEndCompact(pRepo, terrno); + return NULL; +} + +static int tsdbAsyncCompact(STsdbRepo *pRepo) { + tsem_wait(&(pRepo->readyToCommit)); + return tsdbScheduleCommit(pRepo, COMPACT_REQ); +} + +static void tsdbStartCompact(STsdbRepo *pRepo) { + ASSERT(!pRepo->inCompact); + tsdbInfo("vgId:%d start to compact!", REPO_ID(pRepo)); + tsdbStartFSTxn(pRepo, 0, 0); + pRepo->code = TSDB_CODE_SUCCESS; + pRepo->inCompact = true; +} + +static void tsdbEndCompact(STsdbRepo *pRepo, int eno) { + if (eno != TSDB_CODE_SUCCESS) { + tsdbEndFSTxnWithError(REPO_FS(pRepo)); + } else { + tsdbEndFSTxn(pRepo); + } + pRepo->inCompact = false; + tsdbInfo("vgId:%d compact over, %s", REPO_ID(pRepo), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed"); + tsem_post(&(pRepo->readyToCommit)); +} + +static int tsdbCompactMeta(STsdbRepo *pRepo) { + STsdbFS *pfs = REPO_FS(pRepo); + tsdbUpdateMFile(pfs, pfs->cstatus->pmf); + return 0; +} + +static int tsdbCompactTSData(STsdbRepo *pRepo) { + SCompactH compactH; + SDFileSet *pSet = NULL; + + tsdbDebug("vgId:%d start to compact TS data", REPO_ID(pRepo)); + + // If no file, just return 0; + if (taosArrayGetSize(REPO_FS(pRepo)->cstatus->df) <= 0) { + tsdbDebug("vgId:%d no TS data file to compact, compact over", REPO_ID(pRepo)); + return 0; + } + + if (tsdbInitCompactH(&compactH, pRepo) < 0) { + return -1; + } + + while ((pSet = tsdbFSIterNext(&(compactH.fsIter)))) { + // Remove those expired files + if (pSet->fid < compactH.rtn.minFid) { + tsdbInfo("vgId:%d FSET %d on level %d disk id %d expires, remove it", REPO_ID(pRepo), pSet->fid, + TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet)); + continue; + } + + if (TSDB_FSET_LEVEL(pSet) == TFS_MAX_LEVEL) { + tsdbDebug("vgId:%d FSET %d on level %d, should not compact", REPO_ID(pRepo), pSet->fid, TFS_MAX_LEVEL); + tsdbUpdateDFileSet(REPO_FS(pRepo), pSet); + continue; + } + + if (tsdbCompactFSet(&compactH, pSet) < 0) { + tsdbDestroyCompactH(&compactH); + tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno)); + return -1; + } + } + + tsdbDestroyCompactH(&compactH); + tsdbDebug("vgId:%d compact TS data over", REPO_ID(pRepo)); + return 0; +} + +static int tsdbCompactFSet(SCompactH *pComph, SDFileSet *pSet) { + STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph); + SDiskID did; + + tsdbDebug("vgId:%d start to compact FSET %d on level %d id %d", REPO_ID(pRepo), pSet->fid, TSDB_FSET_LEVEL(pSet), + TSDB_FSET_ID(pSet)); + + if (tsdbCompactFSetInit(pComph, pSet) < 0) { + return -1; + } + + if (!tsdbShouldCompact(pComph)) { + tsdbDebug("vgId:%d no need to compact FSET %d", REPO_ID(pRepo), pSet->fid); + if (tsdbApplyRtnOnFSet(TSDB_COMPACT_REPO(pComph), pSet, &(pComph->rtn)) < 0) { + tsdbCompactFSetEnd(pComph); + return -1; + } + } else { + // Create new fset as compacted fset + tfsAllocDisk(tsdbGetFidLevel(pSet->fid, &(pComph->rtn)), &(did.level), &(did.id)); + if (did.level == TFS_UNDECIDED_LEVEL) { + terrno = TSDB_CODE_TDB_NO_AVAIL_DISK; + tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno)); + tsdbCompactFSetEnd(pComph); + return -1; + } + + tsdbInitDFileSet(TSDB_COMPACT_WSET(pComph), did, REPO_ID(pRepo), TSDB_FSET_FID(pSet), + FS_TXN_VERSION(REPO_FS(pRepo))); + if (tsdbCreateDFileSet(TSDB_COMPACT_WSET(pComph), true) < 0) { + tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno)); + tsdbCompactFSetEnd(pComph); + return -1; + } + + if (tsdbCompactFSetImpl(pComph) < 0) { + tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph)); + tsdbRemoveDFileSet(TSDB_COMPACT_WSET(pComph)); + tsdbCompactFSetEnd(pComph); + return -1; + } + + tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph)); + tsdbUpdateDFileSet(REPO_FS(pRepo), TSDB_COMPACT_WSET(pComph)); + tsdbDebug("vgId:%d FSET %d compact over", REPO_ID(pRepo), pSet->fid); + } + + tsdbCompactFSetEnd(pComph); + return 0; +} + +static bool tsdbShouldCompact(SCompactH *pComph) { + STsdbRepo * pRepo = TSDB_COMPACT_REPO(pComph); + STsdbCfg * pCfg = REPO_CFG(pRepo); + SReadH * pReadh = &(pComph->readh); + STableCompactH *pTh; + SBlock * pBlock; + int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); + SDFile * pDataF = TSDB_READ_DATA_FILE(pReadh); + SDFile * pLastF = TSDB_READ_LAST_FILE(pReadh); + + int tblocks = 0; // total blocks + int nSubBlocks = 0; // # of blocks with sub-blocks + int nSmallBlocks = 0; // # of blocks with rows < defaultRows + int64_t tsize = 0; + + for (size_t i = 0; i < taosArrayGetSize(pComph->tbArray); i++) { + pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, i); + + if (pTh->pTable == NULL || pTh->pBlkIdx == NULL) continue; + + for (size_t bidx = 0; bidx < pTh->pBlkIdx->numOfBlocks; bidx++) { + tblocks++; + pBlock = pTh->pInfo->blocks + bidx; + + if (pBlock->numOfRows < defaultRows) { + nSmallBlocks++; + } + + if (pBlock->numOfSubBlocks > 1) { + nSubBlocks++; + for (int k = 0; k < pBlock->numOfSubBlocks; k++) { + SBlock *iBlock = ((SBlock *)POINTER_SHIFT(pTh->pInfo, pBlock->offset)) + k; + tsize = tsize + iBlock->len; + } + } else if (pBlock->numOfSubBlocks == 1) { + tsize += pBlock->len; + } else { + ASSERT(0); + } + } + } + + return (((nSubBlocks * 1.0 / tblocks) > 0.33) || ((nSmallBlocks * 1.0 / tblocks) > 0.33) || + (tsize * 1.0 / (pDataF->info.size + pLastF->info.size - 2 * TSDB_FILE_HEAD_SIZE) < 0.85)); +} + +static int tsdbInitCompactH(SCompactH *pComph, STsdbRepo *pRepo) { + STsdbCfg *pCfg = REPO_CFG(pRepo); + + memset(pComph, 0, sizeof(*pComph)); + + TSDB_FSET_SET_CLOSED(TSDB_COMPACT_WSET(pComph)); + + tsdbGetRtnSnap(pRepo, &(pComph->rtn)); + tsdbFSIterInit(&(pComph->fsIter), REPO_FS(pRepo), TSDB_FS_ITER_FORWARD); + + if (tsdbInitReadH(&(pComph->readh), pRepo) < 0) { + return -1; + } + + if (tsdbInitCompTbArray(pComph) < 0) { + tsdbDestroyCompactH(pComph); + return -1; + } + + pComph->aBlkIdx = taosArrayInit(1024, sizeof(SBlockIdx)); + if (pComph->aBlkIdx == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbDestroyCompactH(pComph); + return -1; + } + + pComph->aSupBlk = taosArrayInit(1024, sizeof(SBlock)); + if (pComph->aSupBlk == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbDestroyCompactH(pComph); + return -1; + } + + pComph->pDataCols = tdNewDataCols(0, 0, pCfg->maxRowsPerFileBlock); + if (pComph->pDataCols == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbDestroyCompactH(pComph); + return -1; + } + + return 0; +} + +static void tsdbDestroyCompactH(SCompactH *pComph) { + pComph->pDataCols = tdFreeDataCols(pComph->pDataCols); + pComph->aSupBlk = taosArrayDestroy(pComph->aSupBlk); + pComph->aBlkIdx = taosArrayDestroy(pComph->aBlkIdx); + tsdbDestroyCompTbArray(pComph); + tsdbDestroyReadH(&(pComph->readh)); + tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph)); +} + +static int tsdbInitCompTbArray(SCompactH *pComph) { // Init pComp->tbArray + STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph); + STsdbMeta *pMeta = pRepo->tsdbMeta; + + if (tsdbRLockRepoMeta(pRepo) < 0) return -1; + + pComph->tbArray = taosArrayInit(pMeta->maxTables, sizeof(STableCompactH)); + if (pComph->tbArray == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbUnlockRepoMeta(pRepo); + return -1; + } + + // Note here must start from 0 + for (int i = 0; i < pMeta->maxTables; i++) { + STableCompactH ch = {0}; + if (pMeta->tables[i] != NULL) { + tsdbRefTable(pMeta->tables[i]); + ch.pTable = pMeta->tables[i]; + } + + if (taosArrayPush(pComph->tbArray, &ch) == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbUnlockRepoMeta(pRepo); + return -1; + } + } + + if (tsdbUnlockRepoMeta(pRepo) < 0) return -1; + return 0; +} + +static void tsdbDestroyCompTbArray(SCompactH *pComph) { + STableCompactH *pTh; + + if (pComph->tbArray == NULL) return; + + for (size_t i = 0; i < taosArrayGetSize(pComph->tbArray); i++) { + pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, i); + if (pTh->pTable) { + tsdbUnRefTable(pTh->pTable); + } + + pTh->pInfo = taosTZfree(pTh->pInfo); + } + + pComph->tbArray = taosArrayDestroy(pComph->tbArray); +} + +static int tsdbCacheFSetIndex(SCompactH *pComph) { + SReadH *pReadH = &(pComph->readh); + + if (tsdbLoadBlockIdx(pReadH) < 0) { + return -1; + } + + for (int tid = 1; tid < taosArrayGetSize(pComph->tbArray); tid++) { + STableCompactH *pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, tid); + pTh->pBlkIdx = NULL; + + if (pTh->pTable == NULL) continue; + if (tsdbSetReadTable(pReadH, pTh->pTable) < 0) { + return -1; + } + + if (pReadH->pBlkIdx == NULL) continue; + pTh->bindex = *(pReadH->pBlkIdx); + pTh->pBlkIdx = &(pTh->bindex); + + if (tsdbMakeRoom((void **)(&(pTh->pInfo)), pTh->pBlkIdx->len) < 0) { + return -1; + } + + if (tsdbLoadBlockInfo(pReadH, (void *)(pTh->pInfo)) < 0) { + return -1; + } + } + + return 0; +} + +static int tsdbCompactFSetInit(SCompactH *pComph, SDFileSet *pSet) { + taosArrayClear(pComph->aBlkIdx); + taosArrayClear(pComph->aSupBlk); + + if (tsdbSetAndOpenReadFSet(&(pComph->readh), pSet) < 0) { + return -1; + } + + if (tsdbCacheFSetIndex(pComph) < 0) { + tsdbCloseAndUnsetFSet(&(pComph->readh)); + return -1; + } + + return 0; +} + +static void tsdbCompactFSetEnd(SCompactH *pComph) { tsdbCloseAndUnsetFSet(&(pComph->readh)); } + +static int tsdbCompactFSetImpl(SCompactH *pComph) { + STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph); + STsdbCfg * pCfg = REPO_CFG(pRepo); + SReadH * pReadh = &(pComph->readh); + SBlockIdx blkIdx; + void ** ppBuf = &(TSDB_COMPACT_BUF(pComph)); + void ** ppCBuf = &(TSDB_COMPACT_COMP_BUF(pComph)); + int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); + + taosArrayClear(pComph->aBlkIdx); + + for (int tid = 1; tid < taosArrayGetSize(pComph->tbArray); tid++) { + STableCompactH *pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, tid); + STSchema * pSchema; + + if (pTh->pTable == NULL || pTh->pBlkIdx == NULL) continue; + + pSchema = tsdbGetTableSchemaImpl(pTh->pTable, true, true, -1); + taosArrayClear(pComph->aSupBlk); + if ((tdInitDataCols(pComph->pDataCols, pSchema) < 0) || (tdInitDataCols(pReadh->pDCols[0], pSchema) < 0) || + (tdInitDataCols(pReadh->pDCols[1], pSchema) < 0)) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + return -1; + } + tdFreeSchema(pSchema); + + // Loop to compact each block data + for (int i = 0; i < pTh->pBlkIdx->numOfBlocks; i++) { + SBlock *pBlock = pTh->pInfo->blocks + i; + + // Load the block data + if (tsdbLoadBlockData(pReadh, pBlock, pTh->pInfo) < 0) { + return -1; + } + + // Merge pComph->pDataCols and pReadh->pDCols[0] and write data to file + if (pComph->pDataCols->numOfRows == 0 && pBlock->numOfRows >= defaultRows) { + if (tsdbWriteBlockToRightFile(pComph, pTh->pTable, pReadh->pDCols[0], ppBuf, ppCBuf) < 0) { + return -1; + } + } else { + int ridx = 0; + + while (true) { + if (pReadh->pDCols[0]->numOfRows - ridx == 0) break; + int rowsToMerge = MIN(pReadh->pDCols[0]->numOfRows - ridx, defaultRows - pComph->pDataCols->numOfRows); + + tdMergeDataCols(pComph->pDataCols, pReadh->pDCols[0], rowsToMerge, &ridx); + + if (pComph->pDataCols->numOfRows < defaultRows) { + break; + } + + if (tsdbWriteBlockToRightFile(pComph, pTh->pTable, pComph->pDataCols, ppBuf, ppCBuf) < 0) { + return -1; + } + tdResetDataCols(pComph->pDataCols); + } + } + } + + if (pComph->pDataCols->numOfRows > 0 && + tsdbWriteBlockToRightFile(pComph, pTh->pTable, pComph->pDataCols, ppBuf, ppCBuf) < 0) { + return -1; + } + + if (tsdbWriteBlockInfoImpl(TSDB_COMPACT_HEAD_FILE(pComph), pTh->pTable, pComph->aSupBlk, NULL, ppBuf, &blkIdx) < + 0) { + return -1; + } + + if ((blkIdx.numOfBlocks > 0) && (taosArrayPush(pComph->aBlkIdx, (void *)(&blkIdx)) == NULL)) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + return -1; + } + } + + if (tsdbWriteBlockIdx(TSDB_COMPACT_HEAD_FILE(pComph), pComph->aBlkIdx, ppBuf) < 0) { + return -1; + } + + return 0; +} + +static int tsdbWriteBlockToRightFile(SCompactH *pComph, STable *pTable, SDataCols *pDataCols, void **ppBuf, + void **ppCBuf) { + STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph); + STsdbCfg * pCfg = REPO_CFG(pRepo); + SDFile * pDFile; + bool isLast; + SBlock block; + + ASSERT(pDataCols->numOfRows > 0); + + if (pDataCols->numOfRows < pCfg->minRowsPerFileBlock) { + pDFile = TSDB_COMPACT_LAST_FILE(pComph); + isLast = true; + } else { + pDFile = TSDB_COMPACT_DATA_FILE(pComph); + isLast = false; + } + + if (tsdbWriteBlockImpl(pRepo, pTable, pDFile, pDataCols, &block, isLast, true, ppBuf, ppCBuf) < 0) { + return -1; + } + + if (taosArrayPush(pComph->aSupBlk, (void *)(&block)) == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + return -1; + } + + return 0; +} #endif \ No newline at end of file diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index bb02e0128337dbd0436e3c8b83894097b1c21c4c..0cbabb8909814bc15e949f224cab4e21e2427660 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -195,6 +195,8 @@ STsdbRepoInfo *tsdbGetStatus(STsdbRepo *pRepo) { return NULL; } int tsdbGetState(STsdbRepo *repo) { return repo->state; } +bool tsdbInCompact(STsdbRepo *repo) { return repo->inCompact; } + void tsdbReportStat(void *repo, int64_t *totalPoints, int64_t *totalStorage, int64_t *compStorage) { ASSERT(repo != NULL); STsdbRepo *pRepo = repo; @@ -533,6 +535,7 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) { pRepo->state = TSDB_STATE_OK; pRepo->code = TSDB_CODE_SUCCESS; + pRepo->inCompact = false; pRepo->config = *pCfg; if (pAppH) { pRepo->appH = *pAppH; diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index c333294179f215890f06ae8d30bf6316f379f875..cd86f13d4b4263a9ef321d32cef1a5b6531803f0 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -218,11 +218,6 @@ static void tsdbMayUnTakeMemSnapshot(STsdbQueryHandle* pQueryHandle) { int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT* pHandle) { STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle; - size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo); - assert(pQueryHandle->activeIndex < size && pQueryHandle->activeIndex >= 0 && size >= 1); - STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex); - - int64_t rows = 0; SMemRef* pMemRef = pQueryHandle->pMemRef; if (pMemRef == NULL) { return rows; } @@ -233,15 +228,19 @@ int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT* pHandle) { SMemTable* pMemT = pMemRef->snapshot.mem; SMemTable* pIMemT = pMemRef->snapshot.imem; - if (pMemT && pCheckInfo->tableId.tid < pMemT->maxTables) { - pMem = pMemT->tData[pCheckInfo->tableId.tid]; - rows += (pMem && pMem->uid == pCheckInfo->tableId.uid) ? pMem->numOfRows: 0; - } - if (pIMemT && pCheckInfo->tableId.tid < pIMemT->maxTables) { - pIMem = pIMemT->tData[pCheckInfo->tableId.tid]; - rows += (pIMem && pIMem->uid == pCheckInfo->tableId.uid) ? pIMem->numOfRows: 0; + size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo); + for (int32_t i = 0; i < size; ++i) { + STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i); + + if (pMemT && pCheckInfo->tableId.tid < pMemT->maxTables) { + pMem = pMemT->tData[pCheckInfo->tableId.tid]; + rows += (pMem && pMem->uid == pCheckInfo->tableId.uid) ? pMem->numOfRows : 0; + } + if (pIMemT && pCheckInfo->tableId.tid < pIMemT->maxTables) { + pIMem = pIMemT->tData[pCheckInfo->tableId.tid]; + rows += (pIMem && pIMem->uid == pCheckInfo->tableId.uid) ? pIMem->numOfRows : 0; + } } - return rows; } @@ -1088,7 +1087,11 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p assert(cur->pos >= 0 && cur->pos <= binfo.rows); TSKEY key = (row != NULL)? dataRowKey(row):TSKEY_INITIAL_VAL; - tsdbDebug("%p key in mem:%"PRId64", 0x%"PRIx64, pQueryHandle, key, pQueryHandle->qId); + if (key != TSKEY_INITIAL_VAL) { + tsdbDebug("%p key in mem:%"PRId64", 0x%"PRIx64, pQueryHandle, key, pQueryHandle->qId); + } else { + tsdbDebug("%p no data in mem, 0x%"PRIx64, pQueryHandle, pQueryHandle->qId); + } if ((ASCENDING_TRAVERSE(pQueryHandle->order) && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) || (!ASCENDING_TRAVERSE(pQueryHandle->order) && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) { @@ -1152,8 +1155,14 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p } assert(cur->blockCompleted); - tsdbDebug("create data block from remain file block, brange:%"PRId64"-%"PRId64", rows:%d, lastKey:%"PRId64", %p", - cur->win.skey, cur->win.ekey, cur->rows, cur->lastKey, pQueryHandle); + if (cur->rows == binfo.rows) { + tsdbDebug("%p whole file block qualified, brange:%"PRId64"-%"PRId64", rows:%d, lastKey:%"PRId64", %"PRIx64, + pQueryHandle, cur->win.skey, cur->win.ekey, cur->rows, cur->lastKey, pQueryHandle->qId); + } else { + tsdbDebug("%p create data block from remain file block, brange:%"PRId64"-%"PRId64", rows:%d, total:%d, lastKey:%"PRId64", %"PRIx64, + pQueryHandle, cur->win.skey, cur->win.ekey, cur->rows, binfo.rows, cur->lastKey, pQueryHandle->qId); + } + } return code; @@ -2397,6 +2406,8 @@ static void destroyHelper(void* param) { tQueryInfo* pInfo = (tQueryInfo*)param; if (pInfo->optr != TSDB_RELATION_IN) { tfree(pInfo->q); + } else { + taosHashCleanup((SHashObj *)(pInfo->q)); } free(param); @@ -3155,11 +3166,23 @@ void filterPrepare(void* expr, void* param) { pInfo->sch = *pSchema; pInfo->optr = pExpr->_node.optr; - pInfo->compare = getComparFunc(pSchema->type, pInfo->optr); + pInfo->compare = getComparFunc(pInfo->sch.type, pInfo->optr); pInfo->indexed = pTSSchema->columns->colId == pInfo->sch.colId; if (pInfo->optr == TSDB_RELATION_IN) { - pInfo->q = (char*) pCond->arr; + int dummy = -1; + SHashObj *pObj = NULL; + if (pInfo->sch.colId == TSDB_TBNAME_COLUMN_INDEX) { + pObj = taosHashInit(256, taosGetDefaultHashFunction(pInfo->sch.type), true, false); + SArray *arr = (SArray *)(pCond->arr); + for (size_t i = 0; i < taosArrayGetSize(arr); i++) { + char* p = taosArrayGetP(arr, i); + taosHashPut(pObj, varDataVal(p),varDataLen(p), &dummy, sizeof(dummy)); + } + } else { + buildFilterSetFromBinary((void **)&pObj, pCond->pz, pCond->nLen); + } + pInfo->q = (char *)pObj; } else if (pCond != NULL) { uint32_t size = pCond->nLen * TSDB_NCHAR_SIZE; if (size < (uint32_t)pSchema->bytes) { @@ -3330,6 +3353,20 @@ static bool tableFilterFp(const void* pNode, void* param) { } else if (pInfo->optr == TSDB_RELATION_NOTNULL) { return (val != NULL) && (!isNull(val, pInfo->sch.type)); } + } else if (pInfo->optr == TSDB_RELATION_IN) { + int type = pInfo->sch.type; + if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { + int64_t v; + GET_TYPED_DATA(v, int64_t, pInfo->sch.type, val); + return NULL != taosHashGet((SHashObj *)pInfo->q, (char *)&v, sizeof(v)); + } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_DOUBLE) { + double v; + GET_TYPED_DATA(v, double, pInfo->sch.type, val); + return NULL != taosHashGet((SHashObj *)pInfo->q, (char *)&v, sizeof(v)); + } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR){ + return NULL != taosHashGet((SHashObj *)pInfo->q, varDataVal(val), varDataLen(val)); + } + } int32_t ret = 0; @@ -3672,14 +3709,18 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) { if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL || optr == TSDB_RELATION_EQUAL || optr == TSDB_RELATION_NOT_EQUAL) { - pCond->start = calloc(1, sizeof(SEndPoint)); + pCond->start = calloc(1, sizeof(SEndPoint)); pCond->start->optr = queryColInfo->optr; - pCond->start->v = queryColInfo->q; + pCond->start->v = queryColInfo->q; } else if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) { - pCond->end = calloc(1, sizeof(SEndPoint)); + pCond->end = calloc(1, sizeof(SEndPoint)); pCond->end->optr = queryColInfo->optr; - pCond->end->v = queryColInfo->q; - } else if (optr == TSDB_RELATION_IN || optr == TSDB_RELATION_LIKE) { + pCond->end->v = queryColInfo->q; + } else if (optr == TSDB_RELATION_IN) { + pCond->start = calloc(1, sizeof(SEndPoint)); + pCond->start->optr = queryColInfo->optr; + pCond->start->v = queryColInfo->q; + } else if (optr == TSDB_RELATION_LIKE) { assert(0); } @@ -3764,6 +3805,19 @@ static void queryIndexedColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SAr taosArrayPush(result, &info); } + } else if (optr == TSDB_RELATION_IN) { + while(tSkipListIterNext(iter)) { + SSkipListNode* pNode = tSkipListIterGet(iter); + + int32_t ret = pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v); + if (ret != 0) { + break; + } + + STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; + taosArrayPush(result, &info); + } + } else { assert(0); } @@ -3857,7 +3911,7 @@ void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *re param->setupInfoFn(pExpr, param->pExtInfo); tQueryInfo *pQueryInfo = pExpr->_node.info; - if (pQueryInfo->indexed && pQueryInfo->optr != TSDB_RELATION_LIKE) { + if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE && pQueryInfo->optr != TSDB_RELATION_IN)) { queryIndexedColumn(pSkipList, pQueryInfo, result); } else { queryIndexlessColumn(pSkipList, pQueryInfo, result, param->nodeFilterFn); diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 09199eaee36a7233a3b31494ea3a515aa9ff78be..f91d13e6d0a4310181594b840631249bd1bcade8 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -17,6 +17,7 @@ #include "ttype.h" #include "tcompare.h" #include "tarray.h" +#include "hash.h" int32_t compareInt32Val(const void *pLeft, const void *pRight) { int32_t left = GET_INT32_VAL(pLeft), right = GET_INT32_VAL(pRight); @@ -291,9 +292,12 @@ int32_t taosArrayCompareString(const void* a, const void* b) { return compareLenPrefixedStr(x, y); } -static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) { - const SArray* arr = (const SArray*) pRight; - return taosArraySearchString(arr, pLeft, taosArrayCompareString, TD_EQ) == NULL ? 0 : 1; +//static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) { +// const SArray* arr = (const SArray*) pRight; +// return taosArraySearchString(arr, pLeft, taosArrayCompareString, TD_EQ) == NULL ? 0 : 1; +//} +static int32_t compareFindItemInSet(const void *pLeft, const void* pRight) { + return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0; } static int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { @@ -325,7 +329,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ comparFn = compareStrPatternComp; } else if (optr == TSDB_RELATION_IN) { - comparFn = compareFindStrInArray; + comparFn = compareFindItemInSet; } else { /* normal relational comparFn */ comparFn = compareLenPrefixedStr; } diff --git a/tests/comparisonTest/opentsdb/opentsdbtest/pom.xml b/tests/comparisonTest/opentsdb/opentsdbtest/pom.xml index 29c2a90f1080f81abe54597aded28e9530e14859..e0ada8b763eca8208260ebde73ce8fb192e917db 100644 --- a/tests/comparisonTest/opentsdb/opentsdbtest/pom.xml +++ b/tests/comparisonTest/opentsdb/opentsdbtest/pom.xml @@ -216,13 +216,13 @@ ch.qos.logback logback-core - 1.0.13 + 1.2.0 ch.qos.logback logback-classic - 1.0.13 + 1.2.0 diff --git a/tests/examples/c/apitest.c b/tests/examples/c/apitest.c index 2961750efce3f1e746aa2e82ecb5160488065681..0f24df0f4767fe1cdace072425768473ffcaa88f 100644 --- a/tests/examples/c/apitest.c +++ b/tests/examples/c/apitest.c @@ -86,7 +86,7 @@ static int print_result(TAOS_RES* res, int blockFetch) { } } else { while ((row = taos_fetch_row(res))) { - char temp[256]; + char temp[256] = {0}; taos_print_row(temp, row, fields, num_fields); puts(temp); nRows++; @@ -342,7 +342,9 @@ void verify_prepare(TAOS* taos) { sql = "insert into m1 values(?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); if (code != 0){ - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } v.ts = 1591060628000; for (int i = 0; i < 10; ++i) { @@ -365,8 +367,8 @@ void verify_prepare(TAOS* taos) { taos_stmt_add_batch(stmt); } if (taos_stmt_execute(stmt) != 0) { + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); taos_stmt_close(stmt); - printf("\033[31mfailed to execute insert statement.\033[0m\n"); return; } taos_stmt_close(stmt); @@ -378,8 +380,8 @@ void verify_prepare(TAOS* taos) { v.v2 = 15; taos_stmt_bind_param(stmt, params + 2); if (taos_stmt_execute(stmt) != 0) { + printf("\033[31mfailed to execute select statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); taos_stmt_close(stmt); - printf("\033[31mfailed to execute select statement.\033[0m\n"); return; } @@ -389,10 +391,10 @@ void verify_prepare(TAOS* taos) { int rows = 0; int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; // fetch the records row by row while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); @@ -530,12 +532,16 @@ void verify_prepare2(TAOS* taos) { sql = "insert into ? (ts, b, v1, v2, v4, v8, f4, f8, bin, blob) values(?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); if (code != 0) { - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } code = taos_stmt_set_tbname(stmt, "m1"); if (code != 0){ - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } int64_t ts = 1591060628000; @@ -569,7 +575,8 @@ void verify_prepare2(TAOS* taos) { taos_stmt_add_batch(stmt); if (taos_stmt_execute(stmt) != 0) { - printf("\033[31mfailed to execute insert statement.\033[0m\n"); + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); return; } @@ -596,7 +603,8 @@ void verify_prepare2(TAOS* taos) { taos_stmt_bind_param(stmt, qparams); if (taos_stmt_execute(stmt) != 0) { - printf("\033[31mfailed to execute select statement.\033[0m\n"); + printf("\033[31mfailed to execute select statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); return; } @@ -606,10 +614,10 @@ void verify_prepare2(TAOS* taos) { int rows = 0; int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; // fetch the records row by row while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); @@ -776,12 +784,16 @@ void verify_prepare3(TAOS* taos) { sql = "insert into ? using st1 tags(?,?) values(?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); if (code != 0){ - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } code = taos_stmt_set_tbname_tags(stmt, "m1", tags); if (code != 0){ - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } int64_t ts = 1591060628000; @@ -815,7 +827,8 @@ void verify_prepare3(TAOS* taos) { taos_stmt_add_batch(stmt); if (taos_stmt_execute(stmt) != 0) { - printf("\033[31mfailed to execute insert statement.\033[0m\n"); + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); return; } taos_stmt_close(stmt); @@ -842,7 +855,8 @@ void verify_prepare3(TAOS* taos) { taos_stmt_bind_param(stmt, qparams); if (taos_stmt_execute(stmt) != 0) { - printf("\033[31mfailed to execute select statement.\033[0m\n"); + printf("\033[31mfailed to execute select statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); return; } @@ -852,12 +866,10 @@ void verify_prepare3(TAOS* taos) { int rows = 0; int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256] = {0}; // fetch the records row by row while ((row = taos_fetch_row(result))) { - memset(temp, 0, sizeof(temp)/sizeof(temp[0])); - + char temp[256] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); diff --git a/tests/examples/c/demo.c b/tests/examples/c/demo.c index 0b1cd7b5d2d304a89656c98e88b2a620e16ae5a1..f8c69d0043591afa8f5e32e80bd35e9413e60e76 100644 --- a/tests/examples/c/demo.c +++ b/tests/examples/c/demo.c @@ -116,12 +116,12 @@ void Test(TAOS *taos, char *qstr, int index) { int rows = 0; int num_fields = taos_field_count(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[1024]; printf("num_fields = %d\n", num_fields); printf("select * from table, result:\n"); // fetch the records row by row while ((row = taos_fetch_row(result))) { + char temp[1024] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); diff --git a/tests/examples/c/prepare.c b/tests/examples/c/prepare.c index 13d71beea6156aa32677c20ccc2d222d28826b24..723b340a923c0bf326599e8090f8c6142a249053 100644 --- a/tests/examples/c/prepare.c +++ b/tests/examples/c/prepare.c @@ -184,10 +184,10 @@ int main(int argc, char *argv[]) int rows = 0; int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; // fetch the records row by row while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); diff --git a/tests/examples/c/subscribe.c b/tests/examples/c/subscribe.c index 1d3533fa5ee89f7425a9b0563e738b4e0703e6c8..ad12f0e7a55b0f471f249f92f30cf659c94586a5 100644 --- a/tests/examples/c/subscribe.c +++ b/tests/examples/c/subscribe.c @@ -14,8 +14,6 @@ void print_result(TAOS_RES* res, int blockFetch) { int num_fields = taos_num_fields(res); TAOS_FIELD* fields = taos_fetch_fields(res); int nRows = 0; - char buf[4096]; - if (blockFetch) { nRows = taos_fetch_block(res, &row); @@ -25,6 +23,7 @@ void print_result(TAOS_RES* res, int blockFetch) { //} } else { while ((row = taos_fetch_row(res))) { + char buf[4096] = {0}; taos_print_row(buf, row, fields, num_fields); puts(buf); nRows++; diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 8fed9aa81cc00029daab06df8a1652d79bae230f..68d7bbefee89527b71bbd02ff93f4101d4d19d9c 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -229,7 +229,7 @@ python3 ./test.py -f query/queryFilterTswithDateUnit.py python3 ./test.py -f query/queryTscomputWithNow.py python3 ./test.py -f query/computeErrorinWhere.py python3 ./test.py -f query/queryTsisNull.py - +python3 ./test.py -f query/subqueryFilter.py #stream @@ -283,6 +283,7 @@ python3 ./test.py -f topic/topicQuery.py python3 ./test.py -f update/merge_commit_data-0.py # wal python3 ./test.py -f wal/addOldWalTest.py +python3 ./test.py -f wal/sdbComp.py # function python3 ./test.py -f functions/all_null_value.py diff --git a/tests/pytest/query/in.py b/tests/pytest/query/in.py new file mode 100644 index 0000000000000000000000000000000000000000..8644b74a45099fcaa7c7608d8d33140b0a30f82f --- /dev/null +++ b/tests/pytest/query/in.py @@ -0,0 +1,163 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.ts = 1538548685000 + + def run(self): + tdSql.prepare() + + print("==============step1") + tdSql.execute( + "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50))") + tdSql.execute( + 'CREATE TABLE if not exists dev_001 using st tags("dev_01")') + tdSql.execute( + 'CREATE TABLE if not exists dev_002 using st tags("dev_02")') + + print("==============step2") + tdSql.error("select * from db.st where ts in ('2020-05-13 10:00:00.000')") + + tdSql.execute( + """INSERT INTO dev_001(ts, tagtype) VALUES('2020-05-13 10:00:00.000', 1), + ('2020-05-13 10:00:00.001', 1) + dev_002 VALUES('2020-05-13 10:00:00.001', 1)""") + + # TAG nchar + tdSql.query('select count(ts) from db.st where dev in ("dev_01")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + + tdSql.query('select count(ts) from db.st where dev in ("dev_01", "dev_01")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + + tdSql.query('select count(ts) from db.st where dev in ("dev_01", "dev_01", "dev_02")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + + + # colume int + tdSql.query("select count(ts) from db.st where tagtype in (1)") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + + tdSql.query("select count(ts) from db.st where tagtype in (1, 2)") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + tdSql.execute( + """INSERT INTO dev_001(ts, tagtype) VALUES('2020-05-13 10:00:01.000', 2), + ('2020-05-13 10:00:02.001', 2) + dev_002 VALUES('2020-05-13 10:00:03.001', 2)""") + + tdSql.query("select count(ts) from db.st where tagtype in (1, 2)") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 6) + + tdSql.execute("create table tb(ts timestamp, c1 int, c2 binary(10), c3 nchar(10), c4 float, c5 bool)") + for i in range(10): + tdSql.execute("insert into tb values(%d, %d, 'binary%d', 'nchar%d', %f, %d)" % (self.ts + i, i, i, i, i + 0.1, i % 2)) + + #binary + tdSql.query('select count(ts) from db.tb where c2 in ("binary1")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select count(ts) from db.tb where c2 in ("binary1", "binary2", "binary1")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + + #bool + #tdSql.query('select count(ts) from db.tb where c5 in (true)') + #tdSql.checkRows(1) + #tdSql.checkData(0, 0, 5) + + #float + #tdSql.query('select count(ts) from db.tb where c4 in (0.1)') + #tdSql.checkRows(1) + #tdSql.checkData(0, 0, 1) + + #nchar + tdSql.query('select count(ts) from db.tb where c3 in ("nchar0")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + + #tdSql.query("select tbname, dev from dev_001") + #tdSql.checkRows(1) + #tdSql.checkData(0, 0, 'dev_001') + #tdSql.checkData(0, 1, 'dev_01') + + #tdSql.query("select tbname, dev, tagtype from dev_001") + #tdSql.checkRows(2) + + ### test case for https://jira.taosdata.com:18080/browse/TD-1930 + #tdSql.execute("create table tb(ts timestamp, c1 int, c2 binary(10), c3 nchar(10), c4 float, c5 bool)") + #for i in range(10): + # tdSql.execute("insert into tb values(%d, %d, 'binary%d', 'nchar%d', %f, %d)" % (self.ts + i, i, i, i, i + 0.1, i % 2)) + # + #tdSql.error("select * from tb where c2 = binary2") + #tdSql.error("select * from tb where c3 = nchar2") + + #tdSql.query("select * from tb where c2 = 'binary2' ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c3 = 'nchar2' ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c1 = '2' ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c1 = 2 ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c4 = '0.1' ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c4 = 0.1 ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c5 = true ") + #tdSql.checkRows(5) + + #tdSql.query("select * from tb where c5 = 'true' ") + #tdSql.checkRows(5) + + ## For jira: https://jira.taosdata.com:18080/browse/TD-2850 + #tdSql.execute("create database 'Test' ") + #tdSql.execute("use 'Test' ") + #tdSql.execute("create table 'TB'(ts timestamp, 'Col1' int) tags('Tag1' int)") + #tdSql.execute("insert into 'Tb0' using tb tags(1) values(now, 1)") + #tdSql.query("select * from tb") + #tdSql.checkRows(1) + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/query/last_row_cache.py b/tests/pytest/query/last_row_cache.py index 4aae4ce487d386b4963af32bca803d2feeb584d7..83153841496b9ef4e0b7d919b44cf0a9e05b02c6 100644 --- a/tests/pytest/query/last_row_cache.py +++ b/tests/pytest/query/last_row_cache.py @@ -141,7 +141,7 @@ class TDTestCase: def run(self): tdSql.prepare() - print("============== last_row_cache_0.sim") + print("============== Step1: last_row_cache_0.sim") tdSql.execute("create database test1 cachelast 0") tdSql.execute("use test1") self.insertData() @@ -149,43 +149,48 @@ class TDTestCase: self.insertData2() self.executeQueries2() - print("============== alter last cache") + print("============== Step2: alter database test1 cachelast 1") tdSql.execute("alter database test1 cachelast 1") self.executeQueries2() + print("============== Step3: alter database test1 cachelast 2") tdSql.execute("alter database test1 cachelast 2") self.executeQueries2() + print("============== Step4: alter database test1 cachelast 3") tdSql.execute("alter database test1 cachelast 3") self.executeQueries2() - print("============== alter last cache") + print("============== Step5: alter database test1 cachelast 0 and restart taosd") tdSql.execute("alter database test1 cachelast 0") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() + print("============== Step6: alter database test1 cachelast 1 and restart taosd") tdSql.execute("alter database test1 cachelast 1") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() + print("============== Step7: alter database test1 cachelast 2 and restart taosd") tdSql.execute("alter database test1 cachelast 2") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() + print("============== Step8: alter database test1 cachelast 3 and restart taosd") tdSql.execute("alter database test1 cachelast 3") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() - print("============== last_row_cache_1.sim") + print("============== Step9: create database test2 cachelast 1") tdSql.execute("create database test2 cachelast 1") tdSql.execute("use test2") self.insertData() @@ -196,42 +201,51 @@ class TDTestCase: tdDnodes.start(1) self.executeQueries2() + print("============== Step8: alter database test2 cachelast 0") tdSql.execute("alter database test2 cachelast 0") self.executeQueries2() + print("============== Step9: alter database test2 cachelast 1") tdSql.execute("alter database test2 cachelast 1") self.executeQueries2() + print("============== Step10: alter database test2 cachelast 2") tdSql.execute("alter database test2 cachelast 2") self.executeQueries2() + print("============== Step11: alter database test2 cachelast 3") tdSql.execute("alter database test2 cachelast 3") self.executeQueries2() + print("============== Step12: alter database test2 cachelast 0 and restart taosd") tdSql.execute("alter database test2 cachelast 0") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() + print("============== Step13: alter database test2 cachelast 1 and restart taosd") tdSql.execute("alter database test2 cachelast 1") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() + print("============== Step14: alter database test2 cachelast 2 and restart taosd") tdSql.execute("alter database test2 cachelast 2") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() + print("============== Step15: alter database test2 cachelast 3 and restart taosd") tdSql.execute("alter database test2 cachelast 3") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() + print("============== Step16: select last_row(*) from st group by tbname") tdSql.query("select last_row(*) from st group by tbname") tdSql.checkRows(10) diff --git a/tests/pytest/query/querySession.py b/tests/pytest/query/querySession.py new file mode 100644 index 0000000000000000000000000000000000000000..9c8fc747dfbdbb07561a13a27257cc3bab1a2df3 --- /dev/null +++ b/tests/pytest/query/querySession.py @@ -0,0 +1,126 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import * +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()) + + def run(self): + tdSql.prepare() + + print("==============step1") + tdSql.execute( + "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50), tag2 binary(16))") + tdSql.execute( + 'CREATE TABLE if not exists dev_001 using st tags("dev_01", "tag_01")') + tdSql.execute( + 'CREATE TABLE if not exists dev_002 using st tags("dev_02", "tag_02")') + + print("==============step2") + + tdSql.execute( + """INSERT INTO dev_001 VALUES('2020-05-13 10:00:00.000', 1)('2020-05-13 10:00:00.005', 2)('2020-05-13 10:00:00.011', 3) + ('2020-05-13 10:00:01.011', 4)('2020-05-13 10:00:01.611', 5)('2020-05-13 10:00:02.612', 6) + ('2020-05-13 10:01:02.612', 7)('2020-05-13 10:02:02.612', 8)('2020-05-13 10:03:02.613', 9) + ('2020-05-13 11:00:00.000', 10)('2020-05-13 12:00:00.000', 11)('2020-05-13 13:00:00.001', 12) + ('2020-05-14 13:00:00.001', 13)('2020-05-15 14:00:00.000', 14)('2020-05-20 10:00:00.000', 15) + ('2020-05-27 10:00:00.001', 16) dev_002 VALUES('2020-05-13 10:00:00.000', 1)('2020-05-13 10:00:00.005', 2)('2020-05-13 10:00:00.009', 3)('2020-05-13 10:00:00.0021', 4) + ('2020-05-13 10:00:00.031', 5)('2020-05-13 10:00:00.036', 6)('2020-05-13 10:00:00.51', 7) + """) + + # session(ts,5a) + tdSql.query("select count(*) from dev_001 session(ts,5a)") + tdSql.checkRows(15) + tdSql.checkData(0, 1, 2) + + + # session(ts,1s) + tdSql.query("select count(*) from dev_001 session(ts,1s)") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 5) + + tdSql.query("select count(*) from dev_001 session(ts,1000a)") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 5) + + # session(ts,1m) + tdSql.query("select count(*) from dev_001 session(ts,1m)") + tdSql.checkRows(9) + tdSql.checkData(0, 1, 8) + + # session(ts,1h) + tdSql.query("select count(*) from dev_001 session(ts,1h)") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 11) + + # session(ts,1d) + tdSql.query("select count(*) from dev_001 session(ts,1d)") + tdSql.checkRows(4) + tdSql.checkData(0, 1, 13) + + # session(ts,1w) + tdSql.query("select count(*) from dev_001 session(ts,1w)") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 15) + + # session with where + tdSql.query("select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d)") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 13) + tdSql.checkData(0, 2, 1) + tdSql.checkData(0, 3, 13) + tdSql.checkData(0, 4, 7) + tdSql.checkData(0, 5, 91) + tdSql.checkData(0, 6, 1) + tdSql.checkData(0, 7, 13) + tdSql.checkData(0, 8, '{slop:1.000000, intercept:0.000000}') + tdSql.checkData(0, 9, 12) + + # tdsql err + tdSql.error("select * from dev_001 session(ts,1w)") + tdSql.error("select count(*) from st session(ts,1w)") + tdSql.error("select count(*) from dev_001 group by tagtype session(ts,1w) ") + tdSql.error("select count(*) from dev_001 session(ts,1n)") + tdSql.error("select count(*) from dev_001 session(ts,1y)") + tdSql.error("select count(*) from dev_001 session(ts,0s)") + tdSql.error("select count(*) from dev_001 session(i,1y)") + tdSql.error("select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0'") + + #test precision us + tdSql.execute("create database test precision 'us'") + tdSql.execute("use test") + tdSql.execute("create table dev_001 (ts timestamp ,i timestamp ,j int)") + tdSql.execute("insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4)") + + # session(ts,1u) + tdSql.query("select count(*) from dev_001 session(ts,1u)") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 3) + tdSql.error("select count(*) from dev_001 session(i,1s)") + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/query/subqueryFilter.py b/tests/pytest/query/subqueryFilter.py new file mode 100644 index 0000000000000000000000000000000000000000..5dca08b458dbe33a33dc3c93fd72478758c96915 --- /dev/null +++ b/tests/pytest/query/subqueryFilter.py @@ -0,0 +1,123 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.ts = 1601481600000 + self.tables = 10 + self.perfix = 'dev' + + def insertData(self): + print("==============step1") + tdSql.execute( + "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50))") + + for i in range(self.tables): + tdSql.execute("create table %s%d using st tags(%d)" % (self.perfix, i, i)) + rows = 15 + i + for j in range(rows): + tdSql.execute("insert into %s%d values(%d, %d)" %(self.perfix, i, self.ts + i * 20 * 10000 + j * 10000, j)) + + def run(self): + tdSql.prepare() + + self.insertData() + + tdSql.query("select count(*) val from st group by tbname") + tdSql.checkRows(10) + + tdSql.query("select * from (select count(*) val from st group by tbname)") + tdSql.checkRows(10) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val < 20") + tdSql.checkRows(5) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val > 20") + tdSql.checkRows(4) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val = 20") + tdSql.checkRows(1) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val <= 20") + tdSql.checkRows(6) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val >= 20") + tdSql.checkRows(5) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val > 20") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val >= 20") + tdSql.checkData(0, 0, 2) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val < 20") + tdSql.checkData(0, 0, 63) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val <= 20") + tdSql.checkData(0, 0, 64) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val = 20") + tdSql.checkData(0, 0, 1) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val > 20") + tdSql.checkData(0, 0, 1) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val >= 20") + tdSql.checkData(0, 0, 2) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val < 20") + tdSql.checkData(0, 0, 63) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val <= 20") + tdSql.checkData(0, 0, 64) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val = 20") + tdSql.checkData(0, 0, 1) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val > 20") + tdSql.checkData(0, 0, 3) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val >= 20") + tdSql.checkData(0, 0, 5) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val < 20") + tdSql.checkData(0, 0, 60) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val <= 20") + tdSql.checkData(0, 0, 62) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val = 20") + tdSql.checkData(0, 0, 2) + + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/wal/insertDataDb1.json b/tests/pytest/wal/insertDataDb1.json new file mode 100644 index 0000000000000000000000000000000000000000..1dce00a4d55aae732ae9c85033f49398a0b1a9be --- /dev/null +++ b/tests/pytest/wal/insertDataDb1.json @@ -0,0 +1,87 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 10, + "num_of_records_per_req": 1000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db1", + "drop": "yes", + "replica": 1, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 1000, + "childtable_prefix": "stb00_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 100, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 1000, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 200, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} + diff --git a/tests/pytest/wal/insertDataDb1Replica2.json b/tests/pytest/wal/insertDataDb1Replica2.json new file mode 100644 index 0000000000000000000000000000000000000000..fec38bcdecd9b441ad1c31891e66e7245c43889f --- /dev/null +++ b/tests/pytest/wal/insertDataDb1Replica2.json @@ -0,0 +1,87 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 10, + "num_of_records_per_req": 1000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db1", + "drop": "yes", + "replica": 2, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 1000, + "childtable_prefix": "stb00_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 100, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 1000, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 200, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} + diff --git a/tests/pytest/wal/insertDataDb2.json b/tests/pytest/wal/insertDataDb2.json new file mode 100644 index 0000000000000000000000000000000000000000..2cf8af580570ac66049ca2248a916337517a6507 --- /dev/null +++ b/tests/pytest/wal/insertDataDb2.json @@ -0,0 +1,86 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db2", + "drop": "yes", + "replica": 1, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 2000, + "childtable_prefix": "stb0_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 2000, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 2, + "childtable_prefix": "stb1_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 5, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/wal/insertDataDb2Newstab.json b/tests/pytest/wal/insertDataDb2Newstab.json new file mode 100644 index 0000000000000000000000000000000000000000..f9d0713385265282e938838a10b485ca9cfdd603 --- /dev/null +++ b/tests/pytest/wal/insertDataDb2Newstab.json @@ -0,0 +1,86 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db2", + "drop": "no", + "replica": 1, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 1, + "childtable_prefix": "stb0_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 0, + "childtable_limit": -1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"yes", + "childtable_count": 1, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 10, + "childtable_limit": -1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-11-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/wal/insertDataDb2NewstabReplica2.json b/tests/pytest/wal/insertDataDb2NewstabReplica2.json new file mode 100644 index 0000000000000000000000000000000000000000..e052f2850fc2fe1e15c651f6150b79fa65c531c1 --- /dev/null +++ b/tests/pytest/wal/insertDataDb2NewstabReplica2.json @@ -0,0 +1,86 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db2", + "drop": "no", + "replica": 2, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 1, + "childtable_prefix": "stb0_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 0, + "childtable_limit": -1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"yes", + "childtable_count": 1, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 10, + "childtable_limit": -1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-11-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/wal/insertDataDb2Replica2.json b/tests/pytest/wal/insertDataDb2Replica2.json new file mode 100644 index 0000000000000000000000000000000000000000..121f70956a8f1eff31f92bc7fb904835f6bcd0de --- /dev/null +++ b/tests/pytest/wal/insertDataDb2Replica2.json @@ -0,0 +1,86 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db2", + "drop": "yes", + "replica": 2, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 2000, + "childtable_prefix": "stb0_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 2000, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 2, + "childtable_prefix": "stb1_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 5, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/wal/sdbComp.py b/tests/pytest/wal/sdbComp.py new file mode 100644 index 0000000000000000000000000000000000000000..c0ac02610f94dbe7c6bfb4ccd7aacd5ada03f205 --- /dev/null +++ b/tests/pytest/wal/sdbComp.py @@ -0,0 +1,124 @@ +################################################################### +# 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 -*- + +from distutils.log import debug +import sys +import os +import taos +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * +import subprocess + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root)-len("/build/bin")] + break + return buildPath + + def run(self): + + # set path para + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + + binPath = buildPath+ "/build/bin/" + testPath = buildPath[:buildPath.find("debug")] + walFilePath = testPath + "/sim/dnode1/data/mnode_bak/wal/" + + #new db and insert data + os.system("rm -rf %s/sim/dnode1/data/mnode_tmp/" % testPath) + os.system("rm -rf %s/sim/dnode1/data/mnode_bak/" % testPath) + tdSql.execute("drop database if exists db2") + os.system("%staosdemo -f wal/insertDataDb1.json -y " % binPath) + tdSql.execute("drop database if exists db1") + os.system("%staosdemo -f wal/insertDataDb2.json -y " % binPath) + tdSql.execute("drop table if exists db2.stb0") + os.system("%staosdemo -f wal/insertDataDb2Newstab.json -y " % binPath) + query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid1) + tdSql.execute("use db2") + tdSql.execute("drop table if exists stb1_0") + tdSql.execute("drop table if exists stb1_1") + tdSql.execute("insert into stb0_0 values(1614218412000,8637,78.861045,'R','bf3')(1614218422000,8637,98.861045,'R','bf3')") + tdSql.execute("alter table db2.stb0 add column col4 int") + tdSql.execute("alter table db2.stb0 drop column col2") + tdSql.execute("alter table db2.stb0 add tag t3 int;") + tdSql.execute("alter table db2.stb0 drop tag t1") + tdSql.execute("create table if not exists stb2_0 (ts timestamp, col0 int, col1 float) ") + tdSql.execute("insert into stb2_0 values(1614218412000,8637,78.861045)") + tdSql.execute("alter table stb2_0 add column col2 binary(4)") + tdSql.execute("alter table stb2_0 drop column col1") + tdSql.execute("insert into stb2_0 values(1614218422000,8638,'R')") + + # stop taosd and compact wal file + tdDnodes.stop(1) + sleep(10) + os.system("nohup %s/taosd --compact-mnode-wal -c %s/sim/dnode1/cfg/ & " %(binPath,testPath) ) + sleep(5) + assert os.path.exists(walFilePath) , "%s is not generated, compact didn't take effect " % walFilePath + + # use new wal file to start taosd + tdDnodes.start(1) + sleep(5) + tdSql.execute("reset query cache") + query_pid2 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid2) + + # verify that the data is correct + tdSql.execute("use db2") + tdSql.query("select count (tbname) from stb0") + tdSql.checkData(0, 0, 1) + tdSql.query("select count (tbname) from stb1") + tdSql.checkRows(0) + tdSql.query("select count(*) from stb0_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb2_0") + tdSql.checkData(0, 0, 2) + + # delete useless file + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf wal/%s.sql" % testcaseFilename ) + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/wal/sdbCompCluster.py b/tests/pytest/wal/sdbCompCluster.py new file mode 100644 index 0000000000000000000000000000000000000000..4fa84817ec01c9e5adfdb4a76bc29a4a6c49abfc --- /dev/null +++ b/tests/pytest/wal/sdbCompCluster.py @@ -0,0 +1,135 @@ +################################################################### +# 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 os +import sys +sys.path.insert(0, os.getcwd()) +from util.log import * +from util.sql import * +from util.dnodes import * +import taos +import threading + + +class TwoClients: + def initConnection(self): + self.host = "chenhaoran02" + self.user = "root" + self.password = "taosdata" + self.config = "/etc/taos/" + self.port =6030 + self.rowNum = 10 + self.ts = 1537146000000 + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root)-len("/build/bin")] + break + return buildPath + + def run(self): + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + binPath = buildPath+ "/build/bin/" + walFilePath = "/var/lib/taos/mnode_bak/wal/" + + # new taos client + conn1 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config ) + print(conn1) + cur1 = conn1.cursor() + tdSql.init(cur1, True) + + # new db and insert data + os.system("rm -rf /var/lib/taos/mnode_bak/") + os.system("rm -rf /var/lib/taos/mnode_temp/") + tdSql.execute("drop database if exists db2") + os.system("%staosdemo -f wal/insertDataDb1.json -y " % binPath) + tdSql.execute("drop database if exists db1") + os.system("%staosdemo -f wal/insertDataDb2.json -y " % binPath) + tdSql.execute("drop table if exists db2.stb0") + os.system("%staosdemo -f wal/insertDataDb2Newstab.json -y " % binPath) + query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid1) + tdSql.execute("use db2") + tdSql.execute("drop table if exists stb1_0") + tdSql.execute("drop table if exists stb1_1") + tdSql.execute("insert into stb0_0 values(1614218412000,8637,78.861045,'R','bf3')(1614218422000,8637,98.861045,'R','bf3')") + tdSql.execute("alter table db2.stb0 add column col4 int") + tdSql.execute("alter table db2.stb0 drop column col2") + tdSql.execute("alter table db2.stb0 add tag t3 int") + tdSql.execute("alter table db2.stb0 drop tag t1") + tdSql.execute("create table if not exists stb2_0 (ts timestamp, col0 int, col1 float) ") + tdSql.execute("insert into stb2_0 values(1614218412000,8637,78.861045)") + tdSql.execute("alter table stb2_0 add column col2 binary(4)") + tdSql.execute("alter table stb2_0 drop column col1") + tdSql.execute("insert into stb2_0 values(1614218422000,8638,'R')") + + # stop taosd and compact wal file + os.system("ps -ef |grep taosd |grep -v 'grep' |awk '{print $2}'|xargs kill -2") + sleep(10) + os.system("nohup taosd --compact-mnode-wal -c /etc/taos & ") + sleep(10) + os.system("nohup /usr/bin/taosd > /dev/null 2>&1 &") + sleep(4) + tdSql.execute("reset query cache") + query_pid2 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid2) + assert os.path.exists(walFilePath) , "%s is not generated " % walFilePath + + # new taos connecting to server + conn2 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config ) + print(conn2) + cur2 = conn2.cursor() + tdSql.init(cur2, True) + + # use new wal file to start up tasod + tdSql.query("show databases") + for i in range(tdSql.queryRows): + if tdSql.queryResult[i][0]=="db2": + assert tdSql.queryResult[i][4]==1 , "replica is wrong" + tdSql.execute("use db2") + tdSql.query("select count (tbname) from stb0") + tdSql.checkData(0, 0, 1) + tdSql.query("select count (tbname) from stb1") + tdSql.checkRows(0) + tdSql.query("select count(*) from stb0_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb2_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select * from stb2_0") + tdSql.checkData(1, 2, 'R') + + # delete useless file + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf wal/%s.sql" % testcaseFilename ) + +clients = TwoClients() +clients.initConnection() +# clients.getBuildPath() +clients.run() \ No newline at end of file diff --git a/tests/pytest/wal/sdbCompClusterReplica2.py b/tests/pytest/wal/sdbCompClusterReplica2.py new file mode 100644 index 0000000000000000000000000000000000000000..117da8ca2ffd046e3cf23399174184b1f64e856b --- /dev/null +++ b/tests/pytest/wal/sdbCompClusterReplica2.py @@ -0,0 +1,136 @@ +################################################################### +# 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 os +import sys +sys.path.insert(0, os.getcwd()) +from util.log import * +from util.sql import * +from util.dnodes import * +import taos +import threading + + +class TwoClients: + def initConnection(self): + self.host = "chenhaoran02" + self.user = "root" + self.password = "taosdata" + self.config = "/etc/taos/" + self.port =6030 + self.rowNum = 10 + self.ts = 1537146000000 + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root)-len("/build/bin")] + break + return buildPath + + def run(self): + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + binPath = buildPath+ "/build/bin/" + walFilePath = "/var/lib/taos/mnode_bak/wal/" + + # new taos client + conn1 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config ) + print(conn1) + cur1 = conn1.cursor() + tdSql.init(cur1, True) + + # new db and insert data + os.system("rm -rf /var/lib/taos/mnode_bak/") + os.system("rm -rf /var/lib/taos/mnode_temp/") + tdSql.execute("drop database if exists db2") + os.system("%staosdemo -f wal/insertDataDb1Replica2.json -y " % binPath) + tdSql.execute("drop database if exists db1") + os.system("%staosdemo -f wal/insertDataDb2Replica2.json -y " % binPath) + tdSql.execute("drop table if exists db2.stb0") + os.system("%staosdemo -f wal/insertDataDb2NewstabReplica2.json -y " % binPath) + query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid1) + tdSql.execute("use db2") + tdSql.execute("drop table if exists stb1_0") + tdSql.execute("drop table if exists stb1_1") + tdSql.execute("insert into stb0_0 values(1614218412000,8637,78.861045,'R','bf3')(1614218422000,8637,98.861045,'R','bf3')") + tdSql.execute("alter table db2.stb0 add column col4 int") + tdSql.execute("alter table db2.stb0 drop column col2") + tdSql.execute("alter table db2.stb0 add tag t3 int") + tdSql.execute("alter table db2.stb0 drop tag t1") + tdSql.execute("create table if not exists stb2_0 (ts timestamp, col0 int, col1 float) ") + tdSql.execute("insert into stb2_0 values(1614218412000,8637,78.861045)") + tdSql.execute("alter table stb2_0 add column col2 binary(4)") + tdSql.execute("alter table stb2_0 drop column col1") + tdSql.execute("insert into stb2_0 values(1614218422000,8638,'R')") + + + # stop taosd and compact wal file + os.system("ps -ef |grep taosd |grep -v 'grep' |awk '{print $2}'|xargs kill -2") + sleep(10) + os.system("nohup taosd --compact-mnode-wal -c /etc/taos & ") + sleep(10) + os.system("nohup /usr/bin/taosd > /dev/null 2>&1 &") + sleep(4) + tdSql.execute("reset query cache") + query_pid2 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid2) + assert os.path.exists(walFilePath) , "%s is not generated " % walFilePath + + # new taos connecting to server + conn2 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config ) + print(conn2) + cur2 = conn2.cursor() + tdSql.init(cur2, True) + + # use new wal file to start up tasod + tdSql.query("show databases") + for i in range(tdSql.queryRows): + if tdSql.queryResult[i][0]=="db2": + assert tdSql.queryResult[i][4]==2 , "replica is wrong" + tdSql.execute("use db2") + tdSql.query("select count (tbname) from stb0") + tdSql.checkData(0, 0, 1) + tdSql.query("select count (tbname) from stb1") + tdSql.checkRows(0) + tdSql.query("select count(*) from stb0_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb2_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select * from stb2_0") + tdSql.checkData(1, 2, 'R') + + # delete useless file + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf wal/%s.sql" % testcaseFilename ) + +clients = TwoClients() +clients.initConnection() +# clients.getBuildPath() +clients.run() \ No newline at end of file diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 55eb62d9bb4272fe7ab85a96561ebd9c87343ed0..72bb9471db8e2c3043306c332c608f1b4f1df836 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -1458,8 +1458,783 @@ int stmt_funcb_autoctb3(TAOS_STMT *stmt) { + +//1 tables 10 records +int stmt_funcb_autoctb4(TAOS_STMT *stmt) { + struct { + int64_t *ts; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + } v = {0}; + + v.ts = malloc(sizeof(int64_t) * 1 * 10); + + int *lb = malloc(10 * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*5); + +// int one_null = 1; + int one_not_null = 0; + + char* is_null = malloc(sizeof(char) * 10); + char* no_null = malloc(sizeof(char) * 10); + + for (int i = 0; i < 10; ++i) { + lb[i] = 40; + 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); + memset(v.bin[i], '0'+i%10, 40); + } + + for (int i = 0; i < 5; i+=5) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v.ts[10*i/10]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = 10; + + 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 = 10; + + 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 = 10; + + params[i+3].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[i+3].buffer_length = sizeof(int64_t); + params[i+3].buffer = v.v8; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = 10; + + params[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[i+4].buffer_length = sizeof(double); + params[i+4].buffer = v.f8; + params[i+4].length = NULL; + params[i+4].is_null = is_null; + params[i+4].num = 10; + } + + int64_t tts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = tts + i; + } + + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+0].buffer = v.b; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+1].buffer = v.v2; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+2].buffer = v.f4; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+3].buffer = v.bin; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + + char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') (ts,b,v4,v8,f8) values(?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + exit(1); + } + + int id = 0; + for (int zz = 0; zz < 1; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); + } + + taos_stmt_bind_param_batch(stmt, params + id * 5); + taos_stmt_add_batch(stmt); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + + ++id; + + unsigned long long endtime = getCurrentTime(); + printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); + + free(v.ts); + free(lb); + free(params); + free(is_null); + free(no_null); + free(tags); + + return 0; +} + + + + + +//1 tables 10 records +int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { + struct { + int64_t *ts; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + } v = {0}; + + v.ts = malloc(sizeof(int64_t) * 1 * 10); + + int *lb = malloc(10 * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + +// int one_null = 1; + int one_not_null = 0; + + char* is_null = malloc(sizeof(char) * 10); + char* no_null = malloc(sizeof(char) * 10); + + for (int i = 0; i < 10; ++i) { + lb[i] = 40; + 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); + memset(v.bin[i], '0'+i%10, 40); + } + + for (int i = 0; i < 10; i+=10) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v.ts[10*i/10]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = 10; + + 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 = 10; + + params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[i+2].buffer_length = sizeof(int8_t); + params[i+2].buffer = v.v1; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = 10; + + params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[i+3].buffer_length = sizeof(int16_t); + params[i+3].buffer = v.v2; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = 10; + + params[i+4].buffer_type = TSDB_DATA_TYPE_INT; + params[i+4].buffer_length = sizeof(int32_t); + params[i+4].buffer = v.v4; + params[i+4].length = NULL; + params[i+4].is_null = is_null; + params[i+4].num = 10; + + params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[i+5].buffer_length = sizeof(int64_t); + params[i+5].buffer = v.v8; + params[i+5].length = NULL; + params[i+5].is_null = is_null; + params[i+5].num = 10; + + params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+6].buffer_length = sizeof(float); + params[i+6].buffer = v.f4; + params[i+6].length = NULL; + params[i+6].is_null = is_null; + params[i+6].num = 10; + + params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[i+7].buffer_length = sizeof(double); + params[i+7].buffer = v.f8; + params[i+7].length = NULL; + params[i+7].is_null = is_null; + params[i+7].num = 10; + + params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+8].buffer_length = 40; + params[i+8].buffer = v.bin; + params[i+8].length = lb; + params[i+8].is_null = is_null; + params[i+8].num = 10; + + params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+9].buffer_length = 40; + params[i+9].buffer = v.bin; + params[i+9].length = lb; + params[i+9].is_null = is_null; + params[i+9].num = 10; + + } + + int64_t tts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = tts + i; + } + + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+0].buffer = v.b; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+1].buffer = v.v2; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+2].buffer = v.f4; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+3].buffer = v.bin; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + + char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + return -1; + } + + int id = 0; + for (int zz = 0; zz < 1; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); + } + + taos_stmt_bind_param_batch(stmt, params + id * 10); + taos_stmt_add_batch(stmt); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + + ++id; + + unsigned long long endtime = getCurrentTime(); + printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); + + free(v.ts); + free(lb); + free(params); + free(is_null); + free(no_null); + free(tags); + + return 0; +} + + + + + +//1 tables 10 records +int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { + struct { + int64_t *ts; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + } v = {0}; + + v.ts = malloc(sizeof(int64_t) * 1 * 10); + + int *lb = malloc(10 * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + +// int one_null = 1; + int one_not_null = 0; + + char* is_null = malloc(sizeof(char) * 10); + char* no_null = malloc(sizeof(char) * 10); + + for (int i = 0; i < 10; ++i) { + lb[i] = 40; + 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); + memset(v.bin[i], '0'+i%10, 40); + } + + for (int i = 0; i < 10; i+=10) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v.ts[10*i/10]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = 10; + + 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 = 10; + + params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[i+2].buffer_length = sizeof(int8_t); + params[i+2].buffer = v.v1; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = 10; + + params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[i+3].buffer_length = sizeof(int16_t); + params[i+3].buffer = v.v2; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = 10; + + params[i+4].buffer_type = TSDB_DATA_TYPE_INT; + params[i+4].buffer_length = sizeof(int32_t); + params[i+4].buffer = v.v4; + params[i+4].length = NULL; + params[i+4].is_null = is_null; + params[i+4].num = 10; + + params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[i+5].buffer_length = sizeof(int64_t); + params[i+5].buffer = v.v8; + params[i+5].length = NULL; + params[i+5].is_null = is_null; + params[i+5].num = 10; + + params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+6].buffer_length = sizeof(float); + params[i+6].buffer = v.f4; + params[i+6].length = NULL; + params[i+6].is_null = is_null; + params[i+6].num = 10; + + params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[i+7].buffer_length = sizeof(double); + params[i+7].buffer = v.f8; + params[i+7].length = NULL; + params[i+7].is_null = is_null; + params[i+7].num = 10; + + params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+8].buffer_length = 40; + params[i+8].buffer = v.bin; + params[i+8].length = lb; + params[i+8].is_null = is_null; + params[i+8].num = 10; + + params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+9].buffer_length = 40; + params[i+9].buffer = v.bin; + params[i+9].length = lb; + params[i+9].is_null = is_null; + params[i+9].num = 10; + + } + + int64_t tts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = tts + i; + } + + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v.v4; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v.b; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v.v1; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v.v2; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v.v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v.f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v.f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v.bin; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v.bin; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + + char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + exit(1); + } + + int id = 0; + for (int zz = 0; zz < 1; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, NULL); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname_tags. code:%s\n", taos_stmt_errstr(stmt)); + return -1; + } + + taos_stmt_bind_param_batch(stmt, params + id * 10); + taos_stmt_add_batch(stmt); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + + ++id; + + unsigned long long endtime = getCurrentTime(); + printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); + + free(v.ts); + free(lb); + free(params); + free(is_null); + free(no_null); + free(tags); + + return 0; +} + + + + + + + +//1 tables 10 records +int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) { + struct { + int64_t *ts; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + } v = {0}; + + v.ts = malloc(sizeof(int64_t) * 1 * 10); + + int *lb = malloc(10 * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + +// int one_null = 1; + int one_not_null = 0; + + char* is_null = malloc(sizeof(char) * 10); + char* no_null = malloc(sizeof(char) * 10); + + for (int i = 0; i < 10; ++i) { + lb[i] = 40; + 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); + memset(v.bin[i], '0'+i%10, 40); + } + + for (int i = 0; i < 10; i+=10) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v.ts[10*i/10]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = 10; + + 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 = 10; + + params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[i+2].buffer_length = sizeof(int8_t); + params[i+2].buffer = v.v1; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = 10; + + params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[i+3].buffer_length = sizeof(int16_t); + params[i+3].buffer = v.v2; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = 10; + + params[i+4].buffer_type = TSDB_DATA_TYPE_INT; + params[i+4].buffer_length = sizeof(int32_t); + params[i+4].buffer = v.v4; + params[i+4].length = NULL; + params[i+4].is_null = is_null; + params[i+4].num = 10; + + params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[i+5].buffer_length = sizeof(int64_t); + params[i+5].buffer = v.v8; + params[i+5].length = NULL; + params[i+5].is_null = is_null; + params[i+5].num = 10; + + params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+6].buffer_length = sizeof(float); + params[i+6].buffer = v.f4; + params[i+6].length = NULL; + params[i+6].is_null = is_null; + params[i+6].num = 10; + + params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[i+7].buffer_length = sizeof(double); + params[i+7].buffer = v.f8; + params[i+7].length = NULL; + params[i+7].is_null = is_null; + params[i+7].num = 10; + + params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+8].buffer_length = 40; + params[i+8].buffer = v.bin; + params[i+8].length = lb; + params[i+8].is_null = is_null; + params[i+8].num = 10; + + params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+9].buffer_length = 40; + params[i+9].buffer = v.bin; + params[i+9].length = lb; + params[i+9].is_null = is_null; + params[i+9].num = 10; + + } + + int64_t tts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = tts + i; + } + + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v.v4; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v.b; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v.v1; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v.v2; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v.v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v.f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v.f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v.bin; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v.bin; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + + char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt)); + return -1; + //exit(1); + } + + int id = 0; + for (int zz = 0; zz < 1; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, NULL); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); + return -1; + } + + taos_stmt_bind_param_batch(stmt, params + id * 10); + taos_stmt_add_batch(stmt); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + + ++id; + + unsigned long long endtime = getCurrentTime(); + printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); + + free(v.ts); + free(lb); + free(params); + free(is_null); + free(no_null); + free(tags); + + return 0; +} + + + + //1 tables 10 records -int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { +int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) { struct { int64_t *ts; int8_t b[10]; @@ -1579,35 +2354,60 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { for (int i = 0; i < 1; ++i) { - tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL; - tags[i+0].buffer = v.b; + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v.v4; tags[i+0].is_null = &one_not_null; tags[i+0].length = NULL; - tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT; - tags[i+1].buffer = v.v2; + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v.b; tags[i+1].is_null = &one_not_null; tags[i+1].length = NULL; - tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT; - tags[i+2].buffer = v.f4; + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v.v1; tags[i+2].is_null = &one_not_null; tags[i+2].length = NULL; - tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY; - tags[i+3].buffer = v.bin; + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v.v2; tags[i+3].is_null = &one_not_null; - tags[i+3].length = (uintptr_t *)lb; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v.v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v.f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v.f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v.bin; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v.bin; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; } unsigned long long starttime = getCurrentTime(); - char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)"; + char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - return -1; + printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt)); + exit(1); } int id = 0; @@ -1616,10 +2416,22 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { sprintf(buf, "m%d", zz); code = taos_stmt_set_tbname_tags(stmt, buf, tags); if (code != 0){ - printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); + printf("failed to execute taos_stmt_set_tbname_tags. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } - taos_stmt_bind_param_batch(stmt, params + id * 10); + code = taos_stmt_bind_param_batch(stmt, params + id * 10); + if (code != 0) { + printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + code = taos_stmt_bind_param_batch(stmt, params + id * 10); + if (code != 0) { + printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt)); + return -1; + } + taos_stmt_add_batch(stmt); } @@ -1647,8 +2459,9 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { + //1 tables 10 records -int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { +int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { struct { int64_t *ts; int8_t b[10]; @@ -1818,23 +2631,34 @@ int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { unsigned long long starttime = getCurrentTime(); char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); + int code = taos_stmt_prepare(NULL, sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - exit(1); + printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(NULL)); + return -1; } int id = 0; for (int zz = 0; zz < 1; zz++) { char buf[32]; sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname_tags(stmt, buf, NULL); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); if (code != 0){ - printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); - return -1; + printf("failed to execute taos_stmt_set_tbname_tags. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } - taos_stmt_bind_param_batch(stmt, params + id * 10); + code = taos_stmt_bind_param_batch(stmt, params + id * 10); + if (code != 0) { + printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + code = taos_stmt_bind_param_batch(stmt, params + id * 10); + if (code != 0) { + printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt)); + return -1; + } + taos_stmt_add_batch(stmt); } @@ -3375,6 +4199,9 @@ void check_result(TAOS *taos, char *tname, int printr, int expected) { char sql[255] = "SELECT * FROM "; TAOS_RES *result; + //FORCE NO PRINT + printr = 0; + strcat(sql, tname); result = taos_query(taos, sql); @@ -3835,7 +4662,7 @@ void* runcase(void *par) { #endif -#if 1 +#if 1 prepare(taos, 1, 1); stmt = taos_stmt_init(taos); @@ -3859,9 +4686,9 @@ void* runcase(void *par) { stmt = taos_stmt_init(taos); - printf("1t+10r+bm+autoctb start\n"); + printf("1t+10r+bm+autoctb1 start\n"); stmt_funcb_autoctb1(stmt); - printf("1t+10r+bm+autoctb end\n"); + printf("1t+10r+bm+autoctb1 end\n"); printf("check result start\n"); check_result(taos, "m0", 1, 10); printf("check result end\n"); @@ -3874,9 +4701,9 @@ void* runcase(void *par) { stmt = taos_stmt_init(taos); - printf("1t+10r+bm+autoctb start\n"); + printf("1t+10r+bm+autoctb2 start\n"); stmt_funcb_autoctb2(stmt); - printf("1t+10r+bm+autoctb end\n"); + printf("1t+10r+bm+autoctb2 end\n"); printf("check result start\n"); check_result(taos, "m0", 1, 10); printf("check result end\n"); @@ -3890,9 +4717,9 @@ void* runcase(void *par) { stmt = taos_stmt_init(taos); - printf("1t+10r+bm+autoctb start\n"); + printf("1t+10r+bm+autoctb3 start\n"); stmt_funcb_autoctb3(stmt); - printf("1t+10r+bm+autoctb end\n"); + printf("1t+10r+bm+autoctb3 end\n"); printf("check result start\n"); check_result(taos, "m0", 1, 10); printf("check result end\n"); @@ -3900,11 +4727,27 @@ void* runcase(void *par) { #endif + #if 1 prepare(taos, 1, 0); stmt = taos_stmt_init(taos); + printf("1t+10r+bm+autoctb4 start\n"); + stmt_funcb_autoctb4(stmt); + printf("1t+10r+bm+autoctb4 end\n"); + printf("check result start\n"); + check_result(taos, "m0", 1, 10); + printf("check result end\n"); + taos_stmt_close(stmt); +#endif + + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + printf("1t+10r+bm+autoctb+e1 start\n"); stmt_funcb_autoctb_e1(stmt); printf("1t+10r+bm+autoctb+e1 end\n"); @@ -3930,6 +4773,52 @@ void* runcase(void *par) { #endif +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("1t+10r+bm+autoctb+e3 start\n"); + stmt_funcb_autoctb_e3(stmt); + printf("1t+10r+bm+autoctb+e3 end\n"); + printf("check result start\n"); + //check_result(taos, "m0", 1, 0); + printf("check result end\n"); + taos_stmt_close(stmt); + +#endif + + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("1t+10r+bm+autoctb+e4 start\n"); + stmt_funcb_autoctb_e4(stmt); + printf("1t+10r+bm+autoctb+e4 end\n"); + printf("check result start\n"); + //check_result(taos, "m0", 1, 0); + printf("check result end\n"); + taos_stmt_close(stmt); + +#endif + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("1t+10r+bm+autoctb+e5 start\n"); + stmt_funcb_autoctb_e5(stmt); + printf("1t+10r+bm+autoctb+e5 end\n"); + printf("check result start\n"); + //check_result(taos, "m0", 1, 0); + printf("check result end\n"); + taos_stmt_close(stmt); + +#endif + #if 1 prepare(taos, 1, 1); @@ -4138,6 +5027,8 @@ void* runcase(void *par) { #endif + printf("test end\n"); + return NULL; } diff --git a/tests/script/general/db/alter_option.sim b/tests/script/general/db/alter_option.sim index c3bb23855fceb877c1ed39c01524231d27edb4f4..bd68ddd859142b0904b92b2b8116b328d158cb83 100644 --- a/tests/script/general/db/alter_option.sim +++ b/tests/script/general/db/alter_option.sim @@ -177,7 +177,7 @@ sql alter database db blocks 20 sql alter database db blocks 10 sql_error alter database db blocks 2 sql_error alter database db blocks 1 -sql alter database db blocks 0 +sql_error alter database db blocks 0 sql_error alter database db blocks -1 sql_error alter database db blocks 10001 diff --git a/tests/script/general/db/topic1.sim b/tests/script/general/db/topic1.sim index 2b4cce5e64bf7076eeb2f0f0e3c1dfbaa224b116..63cae8dffd24d9c292166ed0892a2416805131b2 100644 --- a/tests/script/general/db/topic1.sim +++ b/tests/script/general/db/topic1.sim @@ -455,7 +455,7 @@ sql alter database db blocks 20 sql alter database db blocks 10 sql_error alter database db blocks 2 sql_error alter database db blocks 1 -sql alter database db blocks 0 +sql_error alter database db blocks 0 sql_error alter database db blocks -1 sql_error alter database db blocks 10001 diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 591d5d15351c5b110470287d05127f630d7d1979..bec4267b8b0bc1907c0215469d4a935e6aa38747 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -932,3 +932,125 @@ if $data32 != 0.000144445 then return -1 endi +print ===========================> derivative +sql drop table t1 +sql drop table tx; +sql drop table m1; +sql drop table if exists tm0; +sql drop table if exists tm1; +sql create table tm0(ts timestamp, k double) +sql insert into tm0 values('2015-08-18T00:00:00Z', 2.064) ('2015-08-18T00:06:00Z', 2.116) ('2015-08-18T00:12:00Z', 2.028) +sql insert into tm0 values('2015-08-18T00:18:00Z', 2.126) ('2015-08-18T00:24:00Z', 2.041) ('2015-08-18T00:30:00Z', 2.051) + +sql_error select derivative(ts) from tm0; +sql_error select derivative(k) from tm0; +sql_error select derivative(k, 0, 0) from tm0; +sql_error select derivative(k, 1, 911) from tm0; +sql_error select derivative(kx, 1s, 1) from tm0; +sql_error select derivative(k, -20s, 1) from tm0; +sql_error select derivative(k, 20a, 0) from tm0; +sql_error select derivative(k, 200a, 0) from tm0; +sql_error select derivative(k, 999a, 0) from tm0; +sql_error select derivative(k, 20s, -12) from tm0; + +sql select derivative(k, 1s, 0) from tm0 +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.000144444 then + print expect 0.000144444, actual: $data01 + return -1 +endi + +if $data10 != @15-08-18 08:12:00.000@ then + return -1 +endi + +if $data11 != -0.000244444 then + return -1 +endi + +if $data20 != @15-08-18 08:18:00.000@ then + return -1 +endi + +if $data21 != 0.000272222 then + print expect 0.000272222, actual: $data21 + return -1 +endi + +if $data30 != @15-08-18 08:24:00.000@ then + return -1 +endi + +if $data31 != -0.000236111 then + print expect 0.000236111, actual: $data31 + return -1 +endi + +sql select derivative(k, 6m, 0) from tm0; +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.052000000 then + print expect 0.052000000, actual: $data01 + return -1 +endi + +if $data10 != @15-08-18 08:12:00.000@ then + return -1 +endi + +if $data11 != -0.088000000 then + return -1 +endi + +if $data20 != @15-08-18 08:18:00.000@ then + return -1 +endi + +if $data21 != 0.098000000 then + return -1 +endi + +if $data30 != @15-08-18 08:24:00.000@ then + return -1 +endi + +if $data31 != -0.085000000 then + return -1 +endi + +sql select derivative(k, 12m, 0) from tm0; +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.104000000 then + print expect 0.104000000, actual: $data01 + return -1 +endi + +sql select derivative(k, 6m, 1) from tm0; +if $rows != 3 then + return -1 +endi + +sql_error select derivative(k, 6m, 1) from tm0 interval(1s); +sql_error select derivative(k, 6m, 1) from tm0 session(ts, 1s); +sql_error select derivative(k, 6m, 1) from tm0 group by k; +sql_error select derivative(k, 6m, 1) from \ No newline at end of file diff --git a/tests/script/general/parser/join_multitables.sim b/tests/script/general/parser/join_multitables.sim index acb8be10e7cf0f4a3f70828b1054d9552ca864c4..d675499640b890398859243d49cfb04d9e1e7579 100644 --- a/tests/script/general/parser/join_multitables.sim +++ b/tests/script/general/parser/join_multitables.sim @@ -1811,10 +1811,6 @@ if $data09 != 3 then return -1 endi - - - - sql select st0.*,st1.* from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1 order by st0.ts limit 5 offset 5 if $rows != 5 then return -1 @@ -2294,7 +2290,6 @@ if $data19 != 9925 then return -1 endi - sql_error select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.f1=tb1_1.f1; sql_error select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.ts=tb1_1.ts and tb0_1.id1=tb1_1.id2; sql_error select tb0_5.*, tb1_5.*,tb2_5.*,tb3_5.*,tb4_5.*,tb5_5.*, tb6_5.*,tb7_5.*,tb8_5.*,tb9_5.*,tba_5.* from tb0_5, tb1_5, tb2_5, tb3_5, tb4_5,tb5_5, tb6_5, tb7_5, tb8_5, tb9_5, tba_5 where tb9_5.ts=tb8_5.ts and tb8_5.ts=tb7_5.ts and tb7_5.ts=tb6_5.ts and tb6_5.ts=tb5_5.ts and tb5_5.ts=tb4_5.ts and tb4_5.ts=tb3_5.ts and tb3_5.ts=tb2_5.ts and tb2_5.ts=tb1_5.ts and tb1_5.ts=tb0_5.ts and tb0_5.ts=tba_5.ts; @@ -2317,10 +2312,4 @@ sql_error select last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 g sql_error select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9 where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1; sql_error select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9,sta where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.ts=st1.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1 and st0.id1=st1.id1 and st0.id1=sta.id1 and st0.ts=sta.ts; - - - - - - system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/last_cache.sim b/tests/script/general/parser/last_cache.sim index 9d7da9ddbabbd668382740a230ecc9582c27fe84..4b3285871b8e9414877a53aa205ba2e747e9d8e1 100644 --- a/tests/script/general/parser/last_cache.sim +++ b/tests/script/general/parser/last_cache.sim @@ -9,7 +9,7 @@ sql connect print ======================== dnode1 start $db = testdb - +sql drop database if exists $db sql create database $db cachelast 2 sql use $db diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim index 6265fc3a02822f3a5d2f5a8d52fcd1e7252c8585..bb220049af0e219c18d0fc3fd6e8ad69f5cd1612 100644 --- a/tests/script/general/parser/testSuite.sim +++ b/tests/script/general/parser/testSuite.sim @@ -39,6 +39,7 @@ run general/parser/slimit1.sim run general/parser/slimit_alter_tags.sim run general/parser/tbnameIn.sim run general/parser/join.sim +#run general/parser/join_multitables.sim run general/parser/join_multivnode.sim run general/parser/join_manyblocks.sim run general/parser/projection_limit_offset.sim diff --git a/tests/script/general/parser/where.sim b/tests/script/general/parser/where.sim index 157c41ce58ddf4775c0715f35ccd77e46a7dd221..6dfea3d2e70e75f82fd7bd48cd5578971e158de4 100644 --- a/tests/script/general/parser/where.sim +++ b/tests/script/general/parser/where.sim @@ -151,18 +151,12 @@ sql_error select last(*) from wh_mt1 where c5 in ('1') sql_error select last(*) from wh_mt1_tb1 where c5 in ('1') sql_error select last(*) from wh_mt1 where c6 in ('1') sql_error select last(*) from wh_mt1_tb1 where c6 in ('1') -sql_error select last(*) from wh_mt1 where c7 in ('binary') -sql_error select last(*) from wh_mt1_tb1 where c7 in ('binary') -sql_error select last(*) from wh_mt1 where c8 in ('nchar') -sql_error select last(*) from wh_mt1_tb1 where c9 in (true, false) +#sql_error select last(*) from wh_mt1 where c7 in ('binary') +#sql_error select last(*) from wh_mt1_tb1 where c7 in ('binary') +#sql_error select last(*) from wh_mt1 where c8 in ('nchar') +#sql_error select last(*) from wh_mt1_tb1 where c9 in (true, false) sql_error select last(*) from wh_mt1 where c10 in ('2019-01-01 00:00:00.000') sql_error select last(*) from wh_mt1_tb1 where c10 in ('2019-01-01 00:00:00.000') -sql_error select last(*) from wh_mt1 where t1 in ('binary') -sql_error select last(*) from wh_mt1 where t2 in (1) -sql_error select last(*) from wh_mt1 where t3 in (1) -sql_error select last(*) from wh_mt1 where t4 in (1) -sql_error select last(*) from wh_mt1 where t5 in (1) -sql_error select last(*) from wh_mt1 where t6 in (1) sql select last(*) from wh_mt1 where c1 = 1 if $rows != 1 then return -1 @@ -359,4 +353,4 @@ if $rows != 0 then endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT