diff --git a/cmake/define.inc b/cmake/define.inc index 96a406cfb47a969fe99eb73eeb5c1bf7ecdb1e7c..6c466fee026097b0bdeb89c7a4fc54fc382c2726 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -83,6 +83,8 @@ IF (TD_ARM_64) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "arm64 is defined") SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lua/src) ENDIF () IF (TD_ARM_32) @@ -91,6 +93,8 @@ IF (TD_ARM_32) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "arm32 is defined") SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ") + + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lua/src) ENDIF () IF (TD_MIPS_64) @@ -143,6 +147,7 @@ IF (TD_LINUX) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lua/src) ENDIF () IF (TD_DARWIN_64) @@ -164,6 +169,7 @@ IF (TD_DARWIN_64) SET(RELEASE_FLAGS "-Og") INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lua/src) ENDIF () IF (TD_WINDOWS) @@ -194,6 +200,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) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lua/src) ENDIF () IF (TD_WINDOWS_64) diff --git a/packaging/tools/install_client.sh b/packaging/tools/install_client.sh index 9044f2367214510d33e35ce6569ec204f2845f81..aa09013e538253b8740a0aaf70d04358320a6dd8 100755 --- a/packaging/tools/install_client.sh +++ b/packaging/tools/install_client.sh @@ -182,7 +182,13 @@ function install_jemalloc() { ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi - ${csudo} ldconfig + + if [ -d /etc/ld.so.conf.d ]; then + ${csudo} echo "/usr/local/lib" > /etc/ld.so.conf.d/jemalloc.conf + ${csudo} ldconfig + else + echo "/etc/ld.so.conf.d not found!" + fi fi } diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index 2c36e859707a3816d768a958a1a4887e47a026d0..a7dc931882ad1f3a642b27e8132c0dd9fc09dcfe 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -41,10 +41,10 @@ fi if [ "$osType" != "Darwin" ]; then if [ "$pagMode" == "lite" ]; then - #strip ${build_dir}/bin/taosd + #strip ${build_dir}/bin/taosd strip ${build_dir}/bin/taos bin_files="${build_dir}/bin/taos ${script_dir}/remove_client.sh" - else + else bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo \ ${script_dir}/remove_client.sh ${script_dir}/set_core.sh ${script_dir}/get_client.sh ${script_dir}/taosd-dump-cfg.gdb" fi @@ -139,7 +139,7 @@ if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then cp -r ${examples_dir}/C# ${install_dir}/examples fi # Copy driver -mkdir -p ${install_dir}/driver +mkdir -p ${install_dir}/driver cp ${lib_files} ${install_dir}/driver # Copy connector @@ -168,7 +168,7 @@ fi # exit 1 -cd ${release_dir} +cd ${release_dir} # install_dir has been distinguishes cluster from edege, so comments this code pkg_name=${install_dir}-${osType}-${cpuType} @@ -195,6 +195,15 @@ if [ "$pagMode" == "lite" ]; then pkg_name=${pkg_name}-Lite fi +if [ "$verType" == "beta" ]; then + pkg_name=${pkg_name}-${verType} +elif [ "$verType" == "stable" ]; then + pkg_name=${pkg_name} +else + echo "unknow verType, nor stable or beta" + exit 1 +fi + if [ "$osType" != "Darwin" ]; then tar -zcv -f "$(basename ${pkg_name}).tar.gz" $(basename ${install_dir}) --remove-files || : else diff --git a/packaging/tools/makeclient_power.sh b/packaging/tools/makeclient_power.sh index 6d10245b4f45761dee268dbf48a0679285d43342..89591cac234b190f55d144ccf98cb2d5c70a7936 100755 --- a/packaging/tools/makeclient_power.sh +++ b/packaging/tools/makeclient_power.sh @@ -41,10 +41,10 @@ fi if [ "$osType" != "Darwin" ]; then # if [ "$pagMode" == "lite" ]; then -# strip ${build_dir}/bin/powerd +# strip ${build_dir}/bin/powerd # strip ${build_dir}/bin/power # bin_files="${build_dir}/bin/power ${script_dir}/remove_client_power.sh" -# else +# else # bin_files="${build_dir}/bin/power ${build_dir}/bin/powerdemo ${script_dir}/remove_client_power.sh ${script_dir}/set_core.sh" # fi lib_files="${build_dir}/lib/libtaos.so.${version}" @@ -67,6 +67,39 @@ mkdir -p ${install_dir} mkdir -p ${install_dir}/inc && cp ${header_files} ${install_dir}/inc mkdir -p ${install_dir}/cfg && cp ${cfg_dir}/taos.cfg ${install_dir}/cfg/taos.cfg +if [ -f ${build_dir}/bin/jemalloc-config ]; then + mkdir -p ${install_dir}/jemalloc/{bin,lib,lib/pkgconfig,include/jemalloc,share/doc/jemalloc,share/man/man3} + cp ${build_dir}/bin/jemalloc-config ${install_dir}/jemalloc/bin + if [ -f ${build_dir}/bin/jemalloc.sh ]; then + cp ${build_dir}/bin/jemalloc.sh ${install_dir}/jemalloc/bin + fi + if [ -f ${build_dir}/bin/jeprof ]; then + cp ${build_dir}/bin/jeprof ${install_dir}/jemalloc/bin + fi + if [ -f ${build_dir}/include/jemalloc/jemalloc.h ]; then + cp ${build_dir}/include/jemalloc/jemalloc.h ${install_dir}/jemalloc/include/jemalloc + fi + if [ -f ${build_dir}/lib/libjemalloc.so.2 ]; then + cp ${build_dir}/lib/libjemalloc.so.2 ${install_dir}/jemalloc/lib + ln -sf libjemalloc.so.2 ${install_dir}/jemalloc/lib/libjemalloc.so + fi + if [ -f ${build_dir}/lib/libjemalloc.a ]; then + cp ${build_dir}/lib/libjemalloc.a ${install_dir}/jemalloc/lib + fi + if [ -f ${build_dir}/lib/libjemalloc_pic.a ]; then + cp ${build_dir}/lib/libjemalloc_pic.a ${install_dir}/jemalloc/lib + fi + if [ -f ${build_dir}/lib/pkgconfig/jemalloc.pc ]; then + cp ${build_dir}/lib/pkgconfig/jemalloc.pc ${install_dir}/jemalloc/lib/pkgconfig + fi + if [ -f ${build_dir}/share/doc/jemalloc/jemalloc.html ]; then + cp ${build_dir}/share/doc/jemalloc/jemalloc.html ${install_dir}/jemalloc/share/doc/jemalloc + fi + if [ -f ${build_dir}/share/man/man3/jemalloc.3 ]; then + cp ${build_dir}/share/man/man3/jemalloc.3 ${install_dir}/jemalloc/share/man/man3 + fi +fi + sed -i '/dataDir/ {s/taos/power/g}' ${install_dir}/cfg/taos.cfg sed -i '/logDir/ {s/taos/power/g}' ${install_dir}/cfg/taos.cfg sed -i "s/TDengine/PowerDB/g" ${install_dir}/cfg/taos.cfg @@ -77,11 +110,11 @@ if [ "$osType" != "Darwin" ]; then strip ${build_dir}/bin/taos cp ${build_dir}/bin/taos ${install_dir}/bin/power cp ${script_dir}/remove_power.sh ${install_dir}/bin - else + else cp ${build_dir}/bin/taos ${install_dir}/bin/power cp ${script_dir}/remove_power.sh ${install_dir}/bin - cp ${build_dir}/bin/taosdemo ${install_dir}/bin/powerdemo - cp ${build_dir}/bin/taosdump ${install_dir}/bin/powerdump + cp ${build_dir}/bin/taosdemo ${install_dir}/bin/powerdemo + cp ${build_dir}/bin/taosdump ${install_dir}/bin/powerdump cp ${script_dir}/set_core.sh ${install_dir}/bin cp ${script_dir}/get_client.sh ${install_dir}/bin cp ${script_dir}/taosd-dump-cfg.gdb ${install_dir}/bin @@ -158,15 +191,15 @@ if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then cp -r ${examples_dir}/JDBC ${install_dir}/examples cp -r ${examples_dir}/matlab ${install_dir}/examples sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/examples/matlab/TDengineDemo.m - cp -r ${examples_dir}/python ${install_dir}/examples + cp -r ${examples_dir}/python ${install_dir}/examples sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/examples/python/read_example.py cp -r ${examples_dir}/R ${install_dir}/examples sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/examples/R/command.txt - cp -r ${examples_dir}/go ${install_dir}/examples + cp -r ${examples_dir}/go ${install_dir}/examples sed -i '/root/ {s/taosdata/powerdb/g}' ${install_dir}/examples/go/taosdemo.go fi # Copy driver -mkdir -p ${install_dir}/driver +mkdir -p ${install_dir}/driver cp ${lib_files} ${install_dir}/driver # Copy connector @@ -188,11 +221,11 @@ if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then echo "WARNING: go connector not found, please check if want to use it!" fi cp -r ${connector_dir}/python ${install_dir}/connector - + sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/cinterface.py - + sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/subscription.py - + sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/connection.py fi # Copy release note @@ -200,7 +233,7 @@ fi # exit 1 -cd ${release_dir} +cd ${release_dir} if [ "$verMode" == "cluster" ]; then pkg_name=${install_dir}-${osType}-${cpuType} @@ -217,8 +250,8 @@ fi if [ "$verType" == "beta" ]; then pkg_name=${pkg_name}-${verType} -elif [ "$verType" == "stable" ]; then - pkg_name=${pkg_name} +elif [ "$verType" == "stable" ]; then + pkg_name=${pkg_name} else echo "unknow verType, nor stable or beta" exit 1 diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index bdd42cb457875fe2d554fc4c65636910806af382..b84525dedbeea6ad42f0c26da979b5987b5a9e60 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -21,7 +21,7 @@ IF (TD_LINUX) IF (TD_LINUX_64) TARGET_LINK_LIBRARIES(taos lua) ENDIF () - + SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1) #set version of .so @@ -37,13 +37,13 @@ ELSEIF (TD_DARWIN) # set the static lib name ADD_LIBRARY(taos_static STATIC ${SRC}) - TARGET_LINK_LIBRARIES(taos_static common query trpc tutil pthread m) + TARGET_LINK_LIBRARIES(taos_static common query trpc tutil pthread m lua) SET_TARGET_PROPERTIES(taos_static PROPERTIES OUTPUT_NAME "taos_static") SET_TARGET_PROPERTIES(taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) # generate dynamic library (*.dylib) ADD_LIBRARY(taos SHARED ${SRC}) - TARGET_LINK_LIBRARIES(taos common query trpc tutil pthread m) + TARGET_LINK_LIBRARIES(taos common query trpc tutil pthread m lua) SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1) #set version of .dylib @@ -68,19 +68,19 @@ ELSEIF (TD_WINDOWS) IF (NOT TD_GODLL) SET_TARGET_PROPERTIES(taos PROPERTIES LINK_FLAGS /DEF:${TD_COMMUNITY_DIR}/src/client/src/taos.def) ENDIF () - TARGET_LINK_LIBRARIES(taos trpc tutil query) + TARGET_LINK_LIBRARIES(taos trpc tutil query lua) ELSEIF (TD_DARWIN) SET(CMAKE_MACOSX_RPATH 1) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux) ADD_LIBRARY(taos_static STATIC ${SRC}) - TARGET_LINK_LIBRARIES(taos_static query trpc tutil pthread m) + TARGET_LINK_LIBRARIES(taos_static query trpc tutil pthread m lua) SET_TARGET_PROPERTIES(taos_static PROPERTIES OUTPUT_NAME "taos_static") # generate dynamic library (*.dylib) ADD_LIBRARY(taos SHARED ${SRC}) - TARGET_LINK_LIBRARIES(taos query trpc tutil pthread m) + TARGET_LINK_LIBRARIES(taos query trpc tutil pthread m lua) SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 1fb00bc0d78d25e20ab5b7900e47f779b26a31a0..ae2998f9e4a9beaef0bf6b121d2e15aca7a30e4f 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -94,11 +94,21 @@ typedef struct SVgroupTableInfo { SArray *itemList; // SArray } SVgroupTableInfo; +typedef struct SBlockKeyTuple { + TSKEY skey; + void* payloadAddr; +} SBlockKeyTuple; + +typedef struct SBlockKeyInfo { + int32_t maxBytesAlloc; + SBlockKeyTuple* pKeyTuple; +} SBlockKeyInfo; + int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *len); int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, SName* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks); void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta); -void tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf); +int tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo); int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows); void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo); @@ -108,6 +118,7 @@ SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint uint32_t offset); void* tscDestroyBlockArrayList(SArray* pDataBlockList); +void* tscDestroyUdfArrayList(SArray* pUdfList); void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable, bool removeMeta); int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock); @@ -262,6 +273,7 @@ void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo); int tscGetSTableVgroupInfo(SSqlObj* pSql, SQueryInfo* pQueryInfo); int tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo); int tscGetTableMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool createIfNotExists); +int32_t tscGetUdfFromNode(SSqlObj *pSql, SQueryInfo* pQueryInfo); void tscResetForNextRetrieve(SSqlRes* pRes); void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo); @@ -308,10 +320,9 @@ bool hasMoreClauseToTry(SSqlObj* pSql); void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeMeta); void tscTryQueryNextVnode(SSqlObj *pSql, __async_cb_func_t fp); -void tscAsyncQuerySingleRowForNextVnode(void *param, TAOS_RES *tres, int numOfRows); void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp); int tscSetMgmtEpSetFromCfg(const char *first, const char *second, SRpcCorEpSet *corEpSet); -int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVgroupNameList, __async_cb_func_t fp); +int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVgroupNameList, SArray* pUdfList, __async_cb_func_t fp, bool metaClone); int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t length, SArray* pNameArray); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 5f9da6e3bab351c22c7d2f8a1bf8cc8220b3c1c2..ec2a60d768287a8d1e5050ee0c21354a75450593 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -88,13 +88,43 @@ typedef struct SBoundColumn { int32_t offset; // all column offset value } SBoundColumn; +typedef struct { + uint16_t schemaColIdx; + uint16_t boundIdx; + uint16_t finalIdx; +} SBoundIdxInfo; + +typedef enum _COL_ORDER_STATUS { + ORDER_STATUS_UNKNOWN = 0, + ORDER_STATUS_ORDERED = 1, + ORDER_STATUS_DISORDERED = 2, +} EOrderStatus; + typedef struct SParsedDataColInfo { - int16_t numOfCols; - int16_t numOfBound; - int32_t *boundedColumns; - SBoundColumn *cols; + int16_t numOfCols; + int16_t numOfBound; + int32_t * boundedColumns; // bounded column idx according to schema + SBoundColumn * cols; + SBoundIdxInfo *colIdxInfo; + int8_t orderStatus; // bounded columns: } SParsedDataColInfo; +#define IS_DATA_COL_ORDERED(s) ((s) == (int8_t)ORDER_STATUS_ORDERED) + +typedef struct { + SSchema * pSchema; + int16_t sversion; + int32_t flen; + uint16_t nCols; + void * buf; + void * pDataBlock; + SSubmitBlk *pSubmitBlk; +} SMemRowBuilder; + +typedef struct { + TDRowLenT allNullLen; +} SMemRowHelper; + typedef struct STableDataBlocks { SName tableName; int8_t tsSource; // where does the UNIX timestamp come from, server or client @@ -110,12 +140,13 @@ typedef struct STableDataBlocks { char *pData; bool cloned; - SParsedDataColInfo boundColumnInfo; + SParsedDataColInfo boundColumnInfo; // for parameter ('?') binding - uint32_t numOfAllocedParams; - uint32_t numOfParams; - SParamInfo *params; + uint32_t numOfAllocedParams; + uint32_t numOfParams; + SParamInfo * params; + SMemRowHelper rowHelper; } STableDataBlocks; typedef struct { @@ -147,6 +178,7 @@ typedef struct { SInsertStatementParam insertParam; char reserve1[3]; // fix bus error on arm32 int32_t count; // todo remove it + bool subCmd; char reserve2[3]; // fix bus error on arm32 int16_t numOfCols; @@ -243,6 +275,7 @@ typedef struct SSqlObj { void * pStream; void * pSubscription; char * sqlstr; + void * pBuf; // table meta buffer char parseRetry; char retry; char maxRetry; @@ -382,10 +415,15 @@ extern int tscRefId; extern int tscNumOfObj; // number of existed sqlObj in current process. extern int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo); - + void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArray* tables); int16_t getNewResColId(SSqlCmd* pCmd); +int32_t schemaIdxCompar(const void *lhs, const void *rhs); +int32_t boundIdxCompar(const void *lhs, const void *rhs); +int initSMemRowHelper(SMemRowHelper *pHelper, SSchema *pSSchema, uint16_t nCols, uint16_t allNullColsLen); +int32_t getExtendedRowSize(STableComInfo *tinfo); + #ifdef __cplusplus } #endif diff --git a/src/client/src/tscGlobalmerge.c b/src/client/src/tscGlobalmerge.c index ffec03b65adc38db15d3e57bb11dccb8b0f93a92..8ca8c688f0ebdb89295471d5ec09add5580dd9b3 100644 --- a/src/client/src/tscGlobalmerge.c +++ b/src/client/src/tscGlobalmerge.c @@ -602,6 +602,15 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { continue; } + + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pInfo->udfInfo, -1 * functionId - 1); + + doInvokeUdf(pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_MERGE); + + continue; + } + aAggs[functionId].mergeFunc(&pCtx[j]); } } else { @@ -610,6 +619,15 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { continue; } + + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pInfo->udfInfo, -1 * functionId - 1); + + doInvokeUdf(pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_FINALIZE); + + continue; + } + aAggs[functionId].xFinalize(&pCtx[j]); } @@ -626,7 +644,11 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD } for(int32_t j = 0; j < numOfExpr; ++j) { - aAggs[pCtx[j].functionId].init(&pCtx[j]); + if (pCtx[j].functionId < 0) { + continue; + } + + aAggs[pCtx[j].functionId].init(&pCtx[j], pCtx[j].resultInfo); } for (int32_t j = 0; j < numOfExpr; ++j) { @@ -638,6 +660,15 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { continue; } + + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pInfo->udfInfo, -1 * functionId - 1); + + doInvokeUdf(pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_MERGE); + + continue; + } + aAggs[functionId].mergeFunc(&pCtx[j]); } } @@ -651,6 +682,15 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { continue; } + + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pInfo->udfInfo, -1 * functionId - 1); + + doInvokeUdf(pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_MERGE); + + continue; + } + aAggs[functionId].mergeFunc(&pCtx[j]); } } @@ -871,7 +911,6 @@ SSDataBlock* doGlobalAggregate(void* param, bool* newgroup) { { if (pAggInfo->hasDataBlockForNewGroup) { - pAggInfo->binfo.pRes->info.rows = 0; pAggInfo->hasPrev = false; // now we start from a new group data set. // not belongs to the same group, return the result of current group; @@ -880,7 +919,13 @@ SSDataBlock* doGlobalAggregate(void* param, bool* newgroup) { { // reset output buffer for(int32_t j = 0; j < pOperator->numOfOutput; ++j) { - aAggs[pAggInfo->binfo.pCtx[j].functionId].init(&pAggInfo->binfo.pCtx[j]); + SQLFunctionCtx* pCtx = &pAggInfo->binfo.pCtx[j]; + if (pCtx->functionId < 0) { + clearOutputBuf(&pAggInfo->binfo, &pAggInfo->bufCapacity); + continue; + } + + aAggs[pCtx->functionId].init(pCtx, pCtx->resultInfo); } } @@ -933,6 +978,14 @@ SSDataBlock* doGlobalAggregate(void* param, bool* newgroup) { continue; } + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pAggInfo->udfInfo, -1 * functionId - 1); + + doInvokeUdf(pUdfInfo, &pAggInfo->binfo.pCtx[j], 0, TSDB_UDF_FUNC_FINALIZE); + + continue; + } + aAggs[functionId].xFinalize(&pAggInfo->binfo.pCtx[j]); } diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 8d064ed5834dbaf7338a4657b4d87041056f8f74..ba6a9778ddb25a7fd07227466bb371071e5b75b5 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -38,10 +38,33 @@ enum { TSDB_USE_CLI_TS = 1, }; +static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE; +static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE; + static int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t *numOfRows); static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDataColInfo *pColInfo, SSchema *pSchema, char *str, char **end); +int32_t getExtendedRowSize(STableComInfo *tinfo) { + return tinfo->rowSize + PAYLOAD_HEADER_LEN + PAYLOAD_COL_HEAD_LEN * tinfo->numOfColumns; +} +int initSMemRowHelper(SMemRowHelper *pHelper, SSchema *pSSchema, uint16_t nCols, uint16_t allNullColsLen) { + pHelper->allNullLen = allNullColsLen; // TODO: get allNullColsLen when creating or altering table meta + if (pHelper->allNullLen == 0) { + for (uint16_t i = 0; i < nCols; ++i) { + uint8_t type = pSSchema[i].type; + int32_t typeLen = TYPE_BYTES[type]; + pHelper->allNullLen += typeLen; + if (TSDB_DATA_TYPE_BINARY == type) { + pHelper->allNullLen += (VARSTR_HEADER_SIZE + CHAR_BYTES); + } else if (TSDB_DATA_TYPE_NCHAR == type) { + int len = VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE; + pHelper->allNullLen += len; + } + } + } + return 0; +} static int32_t tscToDouble(SStrToken *pToken, double *value, char **endPtr) { errno = 0; *value = strtold(pToken->z, endPtr); @@ -378,6 +401,342 @@ int32_t tsParseOneColumn(SSchema *pSchema, SStrToken *pToken, char *payload, cha return TSDB_CODE_SUCCESS; } +static FORCE_INLINE TDRowLenT tsSetPayloadColValue(char *payloadStart, char *payload, int16_t columnId, + uint8_t columnType, const void *value, uint16_t valueLen, TDRowTLenT tOffset) { + payloadColSetId(payload, columnId); + payloadColSetType(payload, columnType); + memcpy(POINTER_SHIFT(payloadStart,tOffset), value, valueLen); + return valueLen; +} + +static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *payloadStart, char *primaryKeyStart, + char *payload, char *msg, char **str, bool primaryKey, int16_t timePrec, + TDRowTLenT tOffset, TDRowLenT *sizeAppend, TDRowLenT *dataRowColDeltaLen, + TDRowLenT *kvRowColLen) { + int64_t iv; + int32_t ret; + char * endptr = NULL; + + if (IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) { + return tscInvalidOperationMsg(msg, "invalid numeric data", pToken->z); + } + + switch (pSchema->type) { + case TSDB_DATA_TYPE_BOOL: { // bool + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_BOOL), TYPE_BYTES[TSDB_DATA_TYPE_BOOL], tOffset); + } else { + if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) { + if (strncmp(pToken->z, "true", pToken->n) == 0) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &TRUE_VALUE, + TYPE_BYTES[TSDB_DATA_TYPE_BOOL], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_BOOL]); + } else if (strncmp(pToken->z, "false", pToken->n) == 0) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &FALSE_VALUE, + TYPE_BYTES[TSDB_DATA_TYPE_BOOL], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_BOOL]); + } else { + return tscSQLSyntaxErrMsg(msg, "invalid bool data", pToken->z); + } + } else if (pToken->type == TK_INTEGER) { + iv = strtoll(pToken->z, NULL, 10); + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + ((iv == 0) ? &FALSE_VALUE : &TRUE_VALUE), TYPE_BYTES[TSDB_DATA_TYPE_BOOL], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_BOOL]); + } else if (pToken->type == TK_FLOAT) { + double dv = strtod(pToken->z, NULL); + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + ((dv == 0) ? &FALSE_VALUE : &TRUE_VALUE), TYPE_BYTES[TSDB_DATA_TYPE_BOOL], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_BOOL]); + } else { + return tscInvalidOperationMsg(msg, "invalid bool data", pToken->z); + } + } + break; + } + + case TSDB_DATA_TYPE_TINYINT: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_TINYINT), TYPE_BYTES[TSDB_DATA_TYPE_TINYINT], tOffset); + } else { + ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true); + if (ret != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid tinyint data", pToken->z); + } else if (!IS_VALID_TINYINT(iv)) { + return tscInvalidOperationMsg(msg, "data overflow", pToken->z); + } + + uint8_t tmpVal = (uint8_t)iv; + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_TINYINT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_TINYINT]); + } + + break; + + case TSDB_DATA_TYPE_UTINYINT: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_UTINYINT), TYPE_BYTES[TSDB_DATA_TYPE_UTINYINT], tOffset); + } else { + ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); + if (ret != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid unsigned tinyint data", pToken->z); + } else if (!IS_VALID_UTINYINT(iv)) { + return tscInvalidOperationMsg(msg, "unsigned tinyint data overflow", pToken->z); + } + + uint8_t tmpVal = (uint8_t)iv; + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_UTINYINT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_UTINYINT]); + } + + break; + + case TSDB_DATA_TYPE_SMALLINT: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_SMALLINT), TYPE_BYTES[TSDB_DATA_TYPE_SMALLINT], tOffset); + } else { + ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true); + if (ret != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid smallint data", pToken->z); + } else if (!IS_VALID_SMALLINT(iv)) { + return tscInvalidOperationMsg(msg, "smallint data overflow", pToken->z); + } + + int16_t tmpVal = (int16_t)iv; + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_SMALLINT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_SMALLINT]); + } + + break; + + case TSDB_DATA_TYPE_USMALLINT: + if (isNullStr(pToken)) { + *sizeAppend = + tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_USMALLINT), TYPE_BYTES[TSDB_DATA_TYPE_USMALLINT], tOffset); + } else { + ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); + if (ret != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid unsigned smallint data", pToken->z); + } else if (!IS_VALID_USMALLINT(iv)) { + return tscInvalidOperationMsg(msg, "unsigned smallint data overflow", pToken->z); + } + + uint16_t tmpVal = (uint16_t)iv; + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_USMALLINT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_USMALLINT]); + } + + break; + + case TSDB_DATA_TYPE_INT: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_INT), TYPE_BYTES[TSDB_DATA_TYPE_INT], tOffset); + } else { + ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true); + if (ret != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid int data", pToken->z); + } else if (!IS_VALID_INT(iv)) { + return tscInvalidOperationMsg(msg, "int data overflow", pToken->z); + } + + int32_t tmpVal = (int32_t)iv; + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_INT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_INT]); + } + + break; + + case TSDB_DATA_TYPE_UINT: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_UINT), TYPE_BYTES[TSDB_DATA_TYPE_UINT], tOffset); + } else { + ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); + if (ret != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid unsigned int data", pToken->z); + } else if (!IS_VALID_UINT(iv)) { + return tscInvalidOperationMsg(msg, "unsigned int data overflow", pToken->z); + } + + uint32_t tmpVal = (uint32_t)iv; + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_UINT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_UINT]); + } + + break; + + case TSDB_DATA_TYPE_BIGINT: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_BIGINT), TYPE_BYTES[TSDB_DATA_TYPE_BIGINT], tOffset); + } else { + ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true); + if (ret != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid bigint data", pToken->z); + } else if (!IS_VALID_BIGINT(iv)) { + return tscInvalidOperationMsg(msg, "bigint data overflow", pToken->z); + } + + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &iv, + TYPE_BYTES[TSDB_DATA_TYPE_BIGINT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_BIGINT]); + } + break; + + case TSDB_DATA_TYPE_UBIGINT: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_UBIGINT), TYPE_BYTES[TSDB_DATA_TYPE_UBIGINT], tOffset); + } else { + ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); + if (ret != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid unsigned bigint data", pToken->z); + } else if (!IS_VALID_UBIGINT((uint64_t)iv)) { + return tscInvalidOperationMsg(msg, "unsigned bigint data overflow", pToken->z); + } + + uint64_t tmpVal = (uint64_t)iv; + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_UBIGINT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_UBIGINT]); + } + break; + + case TSDB_DATA_TYPE_FLOAT: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + getNullValue(TSDB_DATA_TYPE_FLOAT), TYPE_BYTES[TSDB_DATA_TYPE_FLOAT], tOffset); + } else { + double dv; + if (TK_ILLEGAL == tscToDouble(pToken, &dv, &endptr)) { + return tscInvalidOperationMsg(msg, "illegal float data", pToken->z); + } + + if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || dv > FLT_MAX || dv < -FLT_MAX || isinf(dv) || + isnan(dv)) { + return tscInvalidOperationMsg(msg, "illegal float data", pToken->z); + } + + float tmpVal = (float)dv; + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_FLOAT], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_FLOAT]); + } + break; + + case TSDB_DATA_TYPE_DOUBLE: + if (isNullStr(pToken)) { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_DOUBLE), TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE], tOffset); + } else { + double dv; + if (TK_ILLEGAL == tscToDouble(pToken, &dv, &endptr)) { + return tscInvalidOperationMsg(msg, "illegal double data", pToken->z); + } + + if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) { + return tscInvalidOperationMsg(msg, "illegal double data", pToken->z); + } + + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, &dv, + TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE]); + } + break; + + case TSDB_DATA_TYPE_BINARY: + // binary data cannot be null-terminated char string, otherwise the last char of the string is lost + if (pToken->type == TK_NULL) { + payloadColSetId(payload, pSchema->colId); + payloadColSetType(payload, pSchema->type); + memcpy(POINTER_SHIFT(payloadStart, tOffset), tdGetNullVal(TSDB_DATA_TYPE_BINARY), VARSTR_HEADER_SIZE + CHAR_BYTES); + *sizeAppend = (TDRowLenT)(VARSTR_HEADER_SIZE + CHAR_BYTES); + } else { // too long values will return invalid sql, not be truncated automatically + if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { // todo refactor + return tscInvalidOperationMsg(msg, "string data overflow", pToken->z); + } + // STR_WITH_SIZE_TO_VARSTR(payload, pToken->z, pToken->n); + + payloadColSetId(payload, pSchema->colId); + payloadColSetType(payload, pSchema->type); + varDataSetLen(POINTER_SHIFT(payloadStart,tOffset), pToken->n); + memcpy(varDataVal(POINTER_SHIFT(payloadStart,tOffset)), pToken->z, pToken->n); + *sizeAppend = (TDRowLenT)(VARSTR_HEADER_SIZE + pToken->n); + *dataRowColDeltaLen += (TDRowLenT)(pToken->n - CHAR_BYTES); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + VARSTR_HEADER_SIZE + pToken->n); + } + + break; + + case TSDB_DATA_TYPE_NCHAR: + if (pToken->type == TK_NULL) { + payloadColSetId(payload, pSchema->colId); + payloadColSetType(payload, pSchema->type); + memcpy(POINTER_SHIFT(payloadStart,tOffset), tdGetNullVal(TSDB_DATA_TYPE_NCHAR), VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); + *sizeAppend = (TDRowLenT)(VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); + } else { + // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' + int32_t output = 0; + payloadColSetId(payload, pSchema->colId); + payloadColSetType(payload, pSchema->type); + if (!taosMbsToUcs4(pToken->z, pToken->n, varDataVal(POINTER_SHIFT(payloadStart,tOffset)), + pSchema->bytes - VARSTR_HEADER_SIZE, &output)) { + char buf[512] = {0}; + snprintf(buf, tListLen(buf), "%s", strerror(errno)); + return tscInvalidOperationMsg(msg, buf, pToken->z); + } + + varDataSetLen(POINTER_SHIFT(payloadStart,tOffset), output); + + *sizeAppend = (TDRowLenT)(VARSTR_HEADER_SIZE + output); + *dataRowColDeltaLen += (TDRowLenT)(output - sizeof(uint32_t)); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + VARSTR_HEADER_SIZE + output); + } + break; + + case TSDB_DATA_TYPE_TIMESTAMP: { + if (pToken->type == TK_NULL) { + if (primaryKey) { + // When building SKVRow primaryKey, we should not skip even with NULL value. + int64_t tmpVal = 0; + *sizeAppend = tsSetPayloadColValue(payloadStart, primaryKeyStart, pSchema->colId, pSchema->type, &tmpVal, + TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP]); + } else { + *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, + tdGetNullVal(TSDB_DATA_TYPE_TIMESTAMP), + TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], tOffset); + } + } else { + int64_t tmpVal; + if (tsParseTime(pToken, &tmpVal, str, msg, timePrec) != TSDB_CODE_SUCCESS) { + return tscInvalidOperationMsg(msg, "invalid timestamp", pToken->z); + } + + *sizeAppend = tsSetPayloadColValue(payloadStart, primaryKey ? primaryKeyStart : payload, pSchema->colId, + pSchema->type, &tmpVal, TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], tOffset); + *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP]); + } + + break; + } + } + + return TSDB_CODE_SUCCESS; +} + /* * The server time/client time should not be mixed up in one sql string * Do not employ sort operation is not involved if server time is used. @@ -414,24 +773,38 @@ int32_t tsCheckTimestamp(STableDataBlocks *pDataBlocks, const char *start) { return TSDB_CODE_SUCCESS; } -int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, int32_t *len, - char *tmpTokenBuf, SInsertStatementParam* pInsertParam) { - int32_t index = 0; - SStrToken sToken = {0}; - char *payload = pDataBlocks->pData + pDataBlocks->size; +int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, int32_t *len, char *tmpTokenBuf, + SInsertStatementParam *pInsertParam) { + int32_t index = 0; + SStrToken sToken = {0}; + + SMemRowHelper *pHelper = &pDataBlocks->rowHelper; + char * payload = pDataBlocks->pData + pDataBlocks->size; SParsedDataColInfo *spd = &pDataBlocks->boundColumnInfo; - SSchema *schema = tscGetTableSchema(pDataBlocks->pTableMeta); + SSchema * schema = tscGetTableSchema(pDataBlocks->pTableMeta); + + TDRowTLenT dataRowLen = pHelper->allNullLen; + TDRowTLenT kvRowLen = TD_MEM_ROW_KV_VER_SIZE; + TDRowTLenT payloadValOffset = 0; + TDRowLenT colValOffset = 0; + ASSERT(dataRowLen > 0); + + payloadSetNCols(payload, spd->numOfBound); + payloadValOffset = payloadValuesOffset(payload); // rely on payloadNCols + // payloadSetTLen(payload, payloadValOffset); + + char *kvPrimaryKeyStart = payload + PAYLOAD_HEADER_LEN; // primaryKey in 1st column tuple + char *kvStart = kvPrimaryKeyStart + PAYLOAD_COL_HEAD_LEN; // the column tuple behind the primaryKey // 1. set the parsed value from sql string - int32_t rowSize = 0; for (int i = 0; i < spd->numOfBound; ++i) { // the start position in data block buffer of current value in sql int32_t colIndex = spd->boundedColumns[i]; - char *start = payload + spd->cols[colIndex].offset; - SSchema *pSchema = &schema[colIndex]; - rowSize += pSchema->bytes; + char *start = payload + spd->cols[colIndex].offset; + + SSchema *pSchema = &schema[colIndex]; // get colId here index = 0; sToken = tStrGetToken(*str, &index, true); @@ -453,7 +826,8 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i int16_t type = sToken.type; if ((type != TK_NOW && type != TK_INTEGER && type != TK_STRING && type != TK_FLOAT && type != TK_BOOL && - type != TK_NULL && type != TK_HEX && type != TK_OCT && type != TK_BIN) || (sToken.n == 0) || (type == TK_RP)) { + type != TK_NULL && type != TK_HEX && type != TK_OCT && type != TK_BIN) || + (sToken.n == 0) || (type == TK_RP)) { return tscSQLSyntaxErrMsg(pInsertParam->msg, "invalid data or symbol", sToken.z); } @@ -467,10 +841,10 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i if (sToken.n >= TSDB_MAX_BYTES_PER_ROW) { return tscSQLSyntaxErrMsg(pInsertParam->msg, "too long string", sToken.z); } - + for (uint32_t k = 1; k < sToken.n - 1; ++k) { if (sToken.z[k] == '\\' || (sToken.z[k] == delim && sToken.z[k + 1] == delim)) { - tmpTokenBuf[j] = sToken.z[k + 1]; + tmpTokenBuf[j] = sToken.z[k + 1]; cnt++; j++; @@ -487,42 +861,54 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i sToken.n -= 2 + cnt; } - bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX); - int32_t ret = tsParseOneColumn(pSchema, &sToken, start, pInsertParam->msg, str, isPrimaryKey, timePrec); + bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX); + TDRowLenT dataRowDeltaColLen = 0; // When combine the data as SDataRow, the delta len between all NULL columns. + TDRowLenT kvRowColLen = 0; + TDRowLenT colValAppended = 0; + + if (!IS_DATA_COL_ORDERED(spd->orderStatus)) { + ASSERT(spd->colIdxInfo != NULL); + if(!isPrimaryKey) { + kvStart = POINTER_SHIFT(kvPrimaryKeyStart, spd->colIdxInfo[i].finalIdx * PAYLOAD_COL_HEAD_LEN); + } else { + ASSERT(spd->colIdxInfo[i].finalIdx == 0); + } + } + // the primary key locates in 1st column + int32_t ret = tsParseOneColumnKV(pSchema, &sToken, payload, kvPrimaryKeyStart, kvStart, pInsertParam->msg, str, + isPrimaryKey, timePrec, payloadValOffset + colValOffset, &colValAppended, + &dataRowDeltaColLen, &kvRowColLen); if (ret != TSDB_CODE_SUCCESS) { return ret; } - if (isPrimaryKey && tsCheckTimestamp(pDataBlocks, start) != TSDB_CODE_SUCCESS) { - tscInvalidOperationMsg(pInsertParam->msg, "client time/server time can not be mixed up", sToken.z); - return TSDB_CODE_TSC_INVALID_TIME_STAMP; - } - } - - // 2. set the null value for the columns that do not assign values - if (spd->numOfBound < spd->numOfCols) { - char *ptr = payload; - - for (int32_t i = 0; i < spd->numOfCols; ++i) { - if (!spd->cols[i].hasVal) { // current column do not have any value to insert, set it to null - if (schema[i].type == TSDB_DATA_TYPE_BINARY) { - varDataSetLen(ptr, sizeof(int8_t)); - *(uint8_t*) varDataVal(ptr) = TSDB_DATA_BINARY_NULL; - } else if (schema[i].type == TSDB_DATA_TYPE_NCHAR) { - varDataSetLen(ptr, sizeof(int32_t)); - *(uint32_t*) varDataVal(ptr) = TSDB_DATA_NCHAR_NULL; - } else { - setNull(ptr, schema[i].type, schema[i].bytes); - } + if (isPrimaryKey) { + if (tsCheckTimestamp(pDataBlocks, payloadValues(payload)) != TSDB_CODE_SUCCESS) { + tscInvalidOperationMsg(pInsertParam->msg, "client time/server time can not be mixed up", sToken.z); + return TSDB_CODE_TSC_INVALID_TIME_STAMP; + } + payloadColSetOffset(kvPrimaryKeyStart, colValOffset); + } else { + payloadColSetOffset(kvStart, colValOffset); + if (IS_DATA_COL_ORDERED(spd->orderStatus)) { + kvStart += PAYLOAD_COL_HEAD_LEN; // move to next column } - - ptr += schema[i].bytes; } + + colValOffset += colValAppended; + kvRowLen += kvRowColLen; + dataRowLen += dataRowDeltaColLen; + } - rowSize = (int32_t)(ptr - payload); + if (kvRowLen < dataRowLen) { + payloadSetType(payload, SMEM_ROW_KV); + } else { + payloadSetType(payload, SMEM_ROW_DATA); } - *len = rowSize; + *len = (int32_t)(payloadValOffset + colValOffset); + payloadSetTLen(payload, *len); + return TSDB_CODE_SUCCESS; } @@ -536,6 +922,27 @@ static int32_t rowDataCompar(const void *lhs, const void *rhs) { return left > right ? 1 : -1; } } +int32_t schemaIdxCompar(const void *lhs, const void *rhs) { + uint16_t left = *(uint16_t *)lhs; + uint16_t right = *(uint16_t *)rhs; + + if (left == right) { + return 0; + } else { + return left > right ? 1 : -1; + } +} + +int32_t boundIdxCompar(const void *lhs, const void *rhs) { + uint16_t left = *(uint16_t *)POINTER_SHIFT(lhs, sizeof(uint16_t)); + uint16_t right = *(uint16_t *)POINTER_SHIFT(rhs, sizeof(uint16_t)); + + if (left == right) { + return 0; + } else { + return left > right ? 1 : -1; + } +} int32_t tsParseValues(char **str, STableDataBlocks *pDataBlock, int maxRows, SInsertStatementParam *pInsertParam, int32_t* numOfRows, char *tmpTokenBuf) { @@ -551,21 +958,26 @@ int32_t tsParseValues(char **str, STableDataBlocks *pDataBlock, int maxRows, SIn int32_t precision = tinfo.precision; + int32_t extendedRowSize = getExtendedRowSize(&tinfo); + + initSMemRowHelper(&pDataBlock->rowHelper, tscGetTableSchema(pDataBlock->pTableMeta), + tscGetNumOfColumns(pDataBlock->pTableMeta), 0); + while (1) { index = 0; sToken = tStrGetToken(*str, &index, false); if (sToken.n == 0 || sToken.type != TK_LP) break; *str += index; - if ((*numOfRows) >= maxRows || pDataBlock->size + tinfo.rowSize >= pDataBlock->nAllocSize) { + if ((*numOfRows) >= maxRows || pDataBlock->size + extendedRowSize >= pDataBlock->nAllocSize) { int32_t tSize; - code = tscAllocateMemIfNeed(pDataBlock, tinfo.rowSize, &tSize); + code = tscAllocateMemIfNeed(pDataBlock, extendedRowSize, &tSize); if (code != TSDB_CODE_SUCCESS) { //TODO pass the correct error code to client strcpy(pInsertParam->msg, "client out of memory"); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - ASSERT(tSize > maxRows); + ASSERT(tSize >= maxRows); maxRows = tSize; } @@ -601,9 +1013,10 @@ int32_t tsParseValues(char **str, STableDataBlocks *pDataBlock, int maxRows, SIn void tscSetBoundColumnInfo(SParsedDataColInfo *pColInfo, SSchema *pSchema, int32_t numOfCols) { pColInfo->numOfCols = numOfCols; pColInfo->numOfBound = numOfCols; - + pColInfo->orderStatus = ORDER_STATUS_ORDERED; pColInfo->boundedColumns = calloc(pColInfo->numOfCols, sizeof(int32_t)); pColInfo->cols = calloc(pColInfo->numOfCols, sizeof(SBoundColumn)); + pColInfo->colIdxInfo = NULL; for (int32_t i = 0; i < pColInfo->numOfCols; ++i) { if (i > 0) { @@ -656,8 +1069,9 @@ int32_t FORCE_INLINE tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTabl } } +#if 0 // data block is disordered, sort it in ascending order -void tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf) { +static void tscSortRemoveDataBlockDupRowsOld(STableDataBlocks *dataBuf) { SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData; // size is less than the total size, since duplicated rows may be removed yet. @@ -700,12 +1114,91 @@ void tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf) { dataBuf->prevTS = INT64_MIN; } +#endif + +// data block is disordered, sort it in ascending order +int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKeyInfo) { + SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData; + int16_t nRows = pBlocks->numOfRows; + + // size is less than the total size, since duplicated rows may be removed yet. + + // if use server time, this block must be ordered + if (dataBuf->tsSource == TSDB_USE_SERVER_TS) { + assert(dataBuf->ordered); + } + // allocate memory + size_t nAlloc = nRows * sizeof(SBlockKeyTuple); + if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) { + size_t nRealAlloc = nAlloc + 10 * sizeof(SBlockKeyTuple); + char * tmp = trealloc(pBlkKeyInfo->pKeyTuple, nRealAlloc); + if (tmp == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple *)tmp; + pBlkKeyInfo->maxBytesAlloc = (int32_t)nRealAlloc; + } + memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc); + + SBlockKeyTuple *pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; + char * pBlockData = pBlocks->data; + TDRowTLenT totolPayloadTLen = 0; + TDRowTLenT payloadTLen = 0; + int n = 0; + while (n < nRows) { + pBlkKeyTuple->skey = payloadTSKey(pBlockData); + pBlkKeyTuple->payloadAddr = pBlockData; + payloadTLen = payloadTLen(pBlockData); +#if 0 + ASSERT(payloadNCols(pBlockData) <= 4096); + ASSERT(payloadTLen(pBlockData) < 65536); +#endif + totolPayloadTLen += payloadTLen; + // next loop + pBlockData += payloadTLen; + ++pBlkKeyTuple; + ++n; + } + + if (!dataBuf->ordered) { + pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; + qsort(pBlkKeyTuple, nRows, sizeof(SBlockKeyTuple), rowDataCompar); + + pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; + int32_t i = 0; + int32_t j = 1; + while (j < nRows) { + TSKEY ti = (pBlkKeyTuple + i)->skey; + TSKEY tj = (pBlkKeyTuple + j)->skey; + + if (ti == tj) { + totolPayloadTLen -= payloadTLen(pBlkKeyTuple + j); + ++j; + continue; + } + + int32_t nextPos = (++i); + if (nextPos != j) { + memmove(pBlkKeyTuple + nextPos, pBlkKeyTuple + j, sizeof(SBlockKeyTuple)); + } + ++j; + } + + dataBuf->ordered = true; + pBlocks->numOfRows = i + 1; + } + + dataBuf->size = sizeof(SSubmitBlk) + totolPayloadTLen; + dataBuf->prevTS = INT64_MIN; + + return 0; +} static int32_t doParseInsertStatement(SInsertStatementParam *pInsertParam, char **str, STableDataBlocks* dataBuf, int32_t *totalNum) { STableComInfo tinfo = tscGetTableInfo(dataBuf->pTableMeta); int32_t maxNumOfRows; - int32_t code = tscAllocateMemIfNeed(dataBuf, tinfo.rowSize, &maxNumOfRows); + int32_t code = tscAllocateMemIfNeed(dataBuf, getExtendedRowSize(&tinfo), &maxNumOfRows); if (TSDB_CODE_SUCCESS != code) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1038,10 +1531,11 @@ static int32_t validateDataSource(SInsertStatementParam *pInsertParam, int32_t t static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDataColInfo* pColInfo, SSchema* pSchema, char* str, char **end) { - pColInfo->numOfBound = 0; + int32_t nCols = pColInfo->numOfCols; - memset(pColInfo->boundedColumns, 0, sizeof(int32_t) * pColInfo->numOfCols); - for(int32_t i = 0; i < pColInfo->numOfCols; ++i) { + pColInfo->numOfBound = 0; + memset(pColInfo->boundedColumns, 0, sizeof(int32_t) * nCols); + for (int32_t i = 0; i < nCols; ++i) { pColInfo->cols[i].hasVal = false; } @@ -1056,6 +1550,8 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat goto _clean; } + bool isOrdered = true; + int32_t lastColIdx = -1; // last column found while (1) { index = 0; sToken = tStrGetToken(str, &index, false); @@ -1076,7 +1572,8 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat bool findColumnIndex = false; // todo speedup by using hash list - for (int32_t t = 0; t < pColInfo->numOfCols; ++t) { + int32_t nScanned = 0, t = lastColIdx + 1; + while (t < nCols) { if (strncmp(sToken.z, pSchema[t].name, sToken.n) == 0 && strlen(pSchema[t].name) == sToken.n) { if (pColInfo->cols[t].hasVal == true) { code = tscInvalidOperationMsg(pInsertParam->msg, "duplicated column name", sToken.z); @@ -1085,10 +1582,39 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat pColInfo->cols[t].hasVal = true; pColInfo->boundedColumns[pColInfo->numOfBound] = t; - pColInfo->numOfBound += 1; + ++pColInfo->numOfBound; findColumnIndex = true; + if (isOrdered && (lastColIdx > t)) { + isOrdered = false; + } + lastColIdx = t; break; } + ++t; + ++nScanned; + } + if (!findColumnIndex) { + t = 0; + int32_t nRemain = nCols - nScanned; + while (t < nRemain) { + if (strncmp(sToken.z, pSchema[t].name, sToken.n) == 0 && strlen(pSchema[t].name) == sToken.n) { + if (pColInfo->cols[t].hasVal == true) { + code = tscInvalidOperationMsg(pInsertParam->msg, "duplicated column name", sToken.z); + goto _clean; + } + + pColInfo->cols[t].hasVal = true; + pColInfo->boundedColumns[pColInfo->numOfBound] = t; + ++pColInfo->numOfBound; + findColumnIndex = true; + if (isOrdered && (lastColIdx > t)) { + isOrdered = false; + } + lastColIdx = t; + break; + } + ++t; + } } if (!findColumnIndex) { @@ -1097,10 +1623,32 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat } } - memset(&pColInfo->boundedColumns[pColInfo->numOfBound], 0 , sizeof(int32_t) * (pColInfo->numOfCols - pColInfo->numOfBound)); + pColInfo->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED; + + if (!isOrdered) { + pColInfo->colIdxInfo = tcalloc(pColInfo->numOfBound, sizeof(SBoundIdxInfo)); + if (pColInfo->colIdxInfo == NULL) { + code = TSDB_CODE_TSC_OUT_OF_MEMORY; + goto _clean; + } + SBoundIdxInfo *pColIdx = pColInfo->colIdxInfo; + for (uint16_t i = 0; i < pColInfo->numOfBound; ++i) { + pColIdx[i].schemaColIdx = (uint16_t)pColInfo->boundedColumns[i]; + pColIdx[i].boundIdx = i; + } + qsort(pColIdx, pColInfo->numOfBound, sizeof(SBoundIdxInfo), schemaIdxCompar); + for (uint16_t i = 0; i < pColInfo->numOfBound; ++i) { + pColIdx[i].finalIdx = i; + } + qsort(pColIdx, pColInfo->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar); + } + + memset(&pColInfo->boundedColumns[pColInfo->numOfBound], 0, + sizeof(int32_t) * (pColInfo->numOfCols - pColInfo->numOfBound)); + return TSDB_CODE_SUCCESS; - _clean: +_clean: pInsertParam->sql = NULL; return code; } @@ -1494,21 +2042,24 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow } STableDataBlocks *pTableDataBlock = NULL; - int32_t ret = - tscGetDataBlockFromList(pInsertParam->pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, sizeof(SSubmitBlk), - tinfo.rowSize, &pTableMetaInfo->name, pTableMeta, &pTableDataBlock, NULL); + int32_t ret = tscGetDataBlockFromList(pInsertParam->pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, + sizeof(SSubmitBlk), tinfo.rowSize, &pTableMetaInfo->name, pTableMeta, + &pTableDataBlock, NULL); if (ret != TSDB_CODE_SUCCESS) { pParentSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; } - tscAllocateMemIfNeed(pTableDataBlock, tinfo.rowSize, &maxRows); + tscAllocateMemIfNeed(pTableDataBlock, getExtendedRowSize(&tinfo), &maxRows); tokenBuf = calloc(1, TSDB_MAX_BYTES_PER_ROW); if (tokenBuf == NULL) { code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; } + initSMemRowHelper(&pTableDataBlock->rowHelper, tscGetTableSchema(pTableDataBlock->pTableMeta), + tscGetNumOfColumns(pTableDataBlock->pTableMeta), 0); + while ((readLen = tgetline(&line, &n, fp)) != -1) { if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) { line[--readLen] = 0; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 830560438244e604cf4aa2a6fe87d79a8f2da83e..2900fb668df0a033066d75ad7b907f94e9e70c37 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -293,6 +293,7 @@ static char* normalStmtBuildSql(STscStmt* stmt) { return taosStringBuilderGetResult(&sb, NULL); } +#if 0 static int fillColumnsNull(STableDataBlocks* pBlock, int32_t rowNum) { SParsedDataColInfo* spd = &pBlock->boundColumnInfo; int32_t offset = 0; @@ -320,8 +321,129 @@ static int fillColumnsNull(STableDataBlocks* pBlock, int32_t rowNum) { return TSDB_CODE_SUCCESS; } +#endif + +/** + * input: + * - schema: + * - payload: + * - spd: + * output: + * - pBlock with data block replaced by K-V format + */ +static int refactorPayload(STableDataBlocks* pBlock, int32_t rowNum) { + SParsedDataColInfo* spd = &pBlock->boundColumnInfo; + SSchema* schema = (SSchema*)pBlock->pTableMeta->schema; + SMemRowHelper* pHelper = &pBlock->rowHelper; + STableMeta* pTableMeta = pBlock->pTableMeta; + STableComInfo tinfo = tscGetTableInfo(pTableMeta); + int code = TSDB_CODE_SUCCESS; + int32_t extendedRowSize = getExtendedRowSize(&tinfo); + TDRowTLenT destPayloadSize = sizeof(SSubmitBlk); + + ASSERT(pHelper->allNullLen >= 8); + + TDRowTLenT destAllocSize = sizeof(SSubmitBlk) + rowNum * extendedRowSize; + SSubmitBlk* pDestBlock = tcalloc(destAllocSize, 1); + if (pDestBlock == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + memcpy(pDestBlock, pBlock->pData, sizeof(SSubmitBlk)); + char* destPayload = (char*)pDestBlock + sizeof(SSubmitBlk); + + char* srcPayload = (char*)pBlock->pData + sizeof(SSubmitBlk); + + for (int n = 0; n < rowNum; ++n) { + payloadSetNCols(destPayload, spd->numOfBound); + + TDRowTLenT dataRowLen = pHelper->allNullLen; + TDRowTLenT kvRowLen = TD_MEM_ROW_KV_VER_SIZE + sizeof(SColIdx) * spd->numOfBound; + TDRowTLenT payloadValOffset = payloadValuesOffset(destPayload); // rely on payloadNCols + TDRowLenT colValOffset = 0; + + char* kvPrimaryKeyStart = destPayload + PAYLOAD_HEADER_LEN; // primaryKey in 1st column tuple + char* kvStart = kvPrimaryKeyStart + PAYLOAD_COL_HEAD_LEN; // the column tuple behind the primaryKey + + for (int32_t i = 0; i < spd->numOfBound; ++i) { + int32_t colIndex = spd->boundedColumns[i]; + ASSERT(spd->cols[colIndex].hasVal); + char* start = srcPayload + spd->cols[colIndex].offset; + SSchema* pSchema = &schema[colIndex]; // get colId here + bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX); + + // the primary key locates in 1st column + if (!IS_DATA_COL_ORDERED(spd->orderStatus)) { + ASSERT(spd->colIdxInfo != NULL); + if (!isPrimaryKey) { + kvStart = POINTER_SHIFT(kvPrimaryKeyStart, spd->colIdxInfo[i].finalIdx * PAYLOAD_COL_HEAD_LEN); + } else { + ASSERT(spd->colIdxInfo[i].finalIdx == 0); + } + } + if (isPrimaryKey) { + payloadColSetId(kvPrimaryKeyStart, pSchema->colId); + payloadColSetType(kvPrimaryKeyStart, pSchema->type); + payloadColSetOffset(kvPrimaryKeyStart, colValOffset); + memcpy(POINTER_SHIFT(destPayload, payloadValOffset + colValOffset), start, TYPE_BYTES[pSchema->type]); + colValOffset += TYPE_BYTES[pSchema->type]; + kvRowLen += TYPE_BYTES[pSchema->type]; + } else { + payloadColSetId(kvStart, pSchema->colId); + payloadColSetType(kvStart, pSchema->type); + payloadColSetOffset(kvStart, colValOffset); + if (IS_VAR_DATA_TYPE(pSchema->type)) { + varDataCopy(POINTER_SHIFT(destPayload, payloadValOffset + colValOffset), start); + colValOffset += varDataTLen(start); + kvRowLen += varDataTLen(start); + if (pSchema->type == TSDB_DATA_TYPE_BINARY) { + dataRowLen += (varDataLen(start) - CHAR_BYTES); + } else if (pSchema->type == TSDB_DATA_TYPE_NCHAR) { + dataRowLen += (varDataLen(start) - TSDB_NCHAR_SIZE); + } else { + ASSERT(0); + } + } else { + memcpy(POINTER_SHIFT(destPayload, payloadValOffset + colValOffset), start, TYPE_BYTES[pSchema->type]); + colValOffset += TYPE_BYTES[pSchema->type]; + kvRowLen += TYPE_BYTES[pSchema->type]; + } + + if (IS_DATA_COL_ORDERED(spd->orderStatus)) { + kvStart += PAYLOAD_COL_HEAD_LEN; // move to next column + } + } + + + } // end of column + + if (kvRowLen < dataRowLen) { + payloadSetType(destPayload, SMEM_ROW_KV); + } else { + payloadSetType(destPayload, SMEM_ROW_DATA); + } + + ASSERT(colValOffset <= TSDB_MAX_BYTES_PER_ROW); + + TDRowTLenT len = payloadValOffset + colValOffset; + payloadSetTLen(destPayload, len); + // next loop + srcPayload += pBlock->rowSize; + destPayload += len; + destPayloadSize += len; + } // end of row + + ASSERT(destPayloadSize <= destAllocSize); + + tfree(pBlock->pData); + pBlock->pData = (char*)pDestBlock; + pBlock->nAllocSize = destAllocSize; + pBlock->size = destPayloadSize; + + return code; +} +#if 0 int32_t fillTablesColumnsNull(SSqlObj* pSql) { SSqlCmd* pCmd = &pSql->cmd; @@ -344,16 +466,97 @@ int32_t fillTablesColumnsNull(SSqlObj* pSql) { return TSDB_CODE_SUCCESS; } +#endif + +/** + * check and sort + */ +static int initPayloadEnv(STableDataBlocks* pBlock, int32_t rowNum) { + SParsedDataColInfo* spd = &pBlock->boundColumnInfo; + if (spd->orderStatus != ORDER_STATUS_UNKNOWN) { + return TSDB_CODE_SUCCESS; + } + + bool isOrdered = true; + int32_t lastColIdx = -1; + for (int32_t i = 0; i < spd->numOfBound; ++i) { + ASSERT(spd->cols[i].hasVal); + int32_t colIdx = spd->boundedColumns[i]; + if (isOrdered) { + if (lastColIdx > colIdx) { + isOrdered = false; + break; + } else { + lastColIdx = colIdx; + } + } + } + + spd->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED; + + if (isOrdered) { + spd->colIdxInfo = NULL; + } else { + spd->colIdxInfo = calloc(spd->numOfBound, sizeof(SBoundIdxInfo)); + if (spd->colIdxInfo == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + SBoundIdxInfo* pColIdx = spd->colIdxInfo; + for (uint16_t i = 0; i < spd->numOfBound; ++i) { + pColIdx[i].schemaColIdx = (uint16_t)spd->boundedColumns[i]; + pColIdx[i].boundIdx = i; + } + qsort(pColIdx, spd->numOfBound, sizeof(SBoundIdxInfo), schemaIdxCompar); + for (uint16_t i = 0; i < spd->numOfBound; ++i) { + pColIdx[i].finalIdx = i; + } + qsort(pColIdx, spd->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar); + } + + return TSDB_CODE_SUCCESS; +} + +/** + * Refactor the raw payload structure to K-V format as the in tsParseOneRow() + */ +int32_t fillTablesPayload(SSqlObj* pSql) { + SSqlCmd* pCmd = &pSql->cmd; + int code = TSDB_CODE_SUCCESS; + STableDataBlocks** p = taosHashIterate(pCmd->insertParam.pTableBlockHashList, NULL); + STableDataBlocks* pOneTableBlock = *p; + while (pOneTableBlock) { + SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData; + if (pBlocks->numOfRows > 0) { + initSMemRowHelper(&pOneTableBlock->rowHelper, tscGetTableSchema(pOneTableBlock->pTableMeta), + tscGetNumOfColumns(pOneTableBlock->pTableMeta), 0); + if ((code = initPayloadEnv(pOneTableBlock, pBlocks->numOfRows)) != TSDB_CODE_SUCCESS) { + return code; + } + if ((code = refactorPayload(pOneTableBlock, pBlocks->numOfRows)) != TSDB_CODE_SUCCESS) { + return code; + }; + } + + p = taosHashIterate(pCmd->insertParam.pTableBlockHashList, p); + if (p == NULL) { + break; + } + + pOneTableBlock = *p; + } + + return code; +} //////////////////////////////////////////////////////////////////////////////// // functions for insertion statement preparation static FORCE_INLINE int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, TAOS_BIND* bind, int32_t colNum) { - if (bind->is_null != NULL && *(bind->is_null)) { - setNull(data + param->offset, param->type, param->bytes); - return TSDB_CODE_SUCCESS; - } + if (bind->is_null != NULL && *(bind->is_null)) { + setNull(data + param->offset, param->type, param->bytes); + return TSDB_CODE_SUCCESS; + } #if 0 if (0) { @@ -1202,9 +1405,12 @@ static int insertStmtExecute(STscStmt* stmt) { pBlk->uid = pTableMeta->id.uid; pBlk->tid = pTableMeta->id.tid; - fillTablesColumnsNull(stmt->pSql); + int code = fillTablesPayload(stmt->pSql); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - int code = tscMergeTableDataBlocks(&stmt->pSql->cmd.insertParam, false); + code = tscMergeTableDataBlocks(&stmt->pSql->cmd.insertParam, false); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -1269,8 +1475,6 @@ static void insertBatchClean(STscStmt* pStmt) { static int insertBatchStmtExecute(STscStmt* pStmt) { int32_t code = 0; - int64_t st1 = taosGetTimestampUs(); - if(pStmt->mtb.nameSet == false) { tscError("0x%"PRIx64" no table name set", pStmt->pSql->self); return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no table name set"); @@ -1283,37 +1487,25 @@ static int insertBatchStmtExecute(STscStmt* pStmt) { return TSDB_CODE_TSC_APP_ERROR; } - fillTablesColumnsNull(pStmt->pSql); - - int64_t st2 = taosGetTimestampUs(); + fillTablesPayload(pStmt->pSql); if ((code = tscMergeTableDataBlocks(&pStmt->pSql->cmd.insertParam, false)) != TSDB_CODE_SUCCESS) { return code; } - int64_t st3 = taosGetTimestampUs(); - code = tscHandleMultivnodeInsert(pStmt->pSql); if (code != TSDB_CODE_SUCCESS) { return code; } - int64_t st4 = taosGetTimestampUs(); - // wait for the callback function to post the semaphore tsem_wait(&pStmt->pSql->rspSem); - int64_t st5 = taosGetTimestampUs(); - code = pStmt->pSql->res.code; insertBatchClean(pStmt); - int64_t st6 = taosGetTimestampUs(); - - tscDebug("use time:%"PRId64 ",%"PRId64 ",%"PRId64 ",%"PRId64 ",%"PRId64, st2-st1, st3-st2, st4-st3, st5-st4, st6-st5); - return code; } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 50d6d72e17658adeba1ea20a3a4e404b06dfa159..af9f13df4e5c533a46c2610f000e7c72ef55f741 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -37,6 +37,7 @@ #include "tstrbuild.h" #include "ttoken.h" #include "ttokendef.h" +#include "qScript.h" #include "ttype.h" #define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0" @@ -77,7 +78,8 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC static int32_t setObjFullName(char* fullName, const char* account, SStrToken* pDB, SStrToken* tableName, int32_t* len); static void getColumnName(tSqlExprItem* pItem, char* resultFieldName, char* rawName, int32_t nameLength); -static int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, bool finalResult); +static int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, + bool finalResult, SUdfInfo* pUdfInfo); static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnList* pIdList, int16_t bytes, int8_t type, char* fieldName, SExprInfo* pSqlExpr); @@ -177,15 +179,15 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType, // check all the exprToken type in expr list same or not if (firstVarType != var->nType) { break; - } + } if ((colType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(colType))) { if (var->nType != TSDB_DATA_TYPE_BOOL && !IS_SIGNED_NUMERIC_TYPE(var->nType)) { break; - } - tbufWriteInt64(&bw, var->i64); + } + tbufWriteInt64(&bw, var->i64); } else if (IS_UNSIGNED_NUMERIC_TYPE(colType)) { if (IS_SIGNED_NUMERIC_TYPE(var->nType) || IS_UNSIGNED_NUMERIC_TYPE(var->nType)) { - tbufWriteUint64(&bw, var->u64); + tbufWriteUint64(&bw, var->u64); } else { break; } @@ -216,19 +218,19 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType, } else if (colType == TSDB_DATA_TYPE_TIMESTAMP) { if (var->nType == TSDB_DATA_TYPE_BINARY) { if (convertTimestampStrToInt64(var, precision) < 0) { - break; - } - tbufWriteInt64(&bw, var->i64); + break; + } + tbufWriteInt64(&bw, var->i64); } else if (var->nType == TSDB_DATA_TYPE_BIGINT) { - tbufWriteInt64(&bw, var->i64); + tbufWriteInt64(&bw, var->i64); } else { break; - } + } } else { - break; + break; } if (i == (int32_t)(pList->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); @@ -327,7 +329,7 @@ static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, SQueryInfo* pQueryInfo STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); if (convertTimestampStrToInt64(pVar, tinfo.precision) < -1) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); - } + } return TSDB_CODE_SUCCESS; } @@ -386,6 +388,137 @@ static int32_t normalizeVarDataTypeLength(SSqlCmd* pCmd) { return TSDB_CODE_SUCCESS; } +int32_t readFromFile(char *name, uint32_t *len, void **buf) { + struct stat fileStat; + if (stat(name, &fileStat) < 0) { + tscError("stat file %s failed, error:%s", name, strerror(errno)); + return TAOS_SYSTEM_ERROR(errno); + } + + *len = fileStat.st_size; + + if (*len <= 0) { + tscError("file %s is empty", name); + return TSDB_CODE_TSC_FILE_EMPTY; + } + + *buf = calloc(1, *len); + if (*buf == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + int fd = open(name, O_RDONLY); + if (fd < 0) { + tscError("open file %s failed, error:%s", name, strerror(errno)); + tfree(*buf); + return TAOS_SYSTEM_ERROR(errno); + } + + int64_t s = taosRead(fd, *buf, *len); + if (s != *len) { + tscError("read file %s failed, error:%s", name, strerror(errno)); + close(fd); + tfree(*buf); + return TSDB_CODE_TSC_APP_ERROR; + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { + const char *msg1 = "function name is too long"; + const char *msg2 = "path is too long"; + const char *msg3 = "invalid outputtype"; + const char *msg4 = "invalid script"; + SSqlCmd *pCmd = &pSql->cmd; + + switch (pInfo->type) { + case TSDB_SQL_CREATE_FUNCTION: { + SCreateFuncInfo *createInfo = &pInfo->pMiscInfo->funcOpt; + uint32_t len = 0; + void *buf = NULL; + + if (createInfo->output.type == (uint8_t)-1 || createInfo->output.bytes < 0) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + } + + createInfo->name.z[createInfo->name.n] = 0; + + strdequote(createInfo->name.z); + + if (strlen(createInfo->name.z) >= TSDB_FUNC_NAME_LEN) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + + createInfo->path.z[createInfo->path.n] = 0; + + strdequote(createInfo->path.z); + + if (strlen(createInfo->path.z) >= PATH_MAX) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + + int32_t ret = readFromFile(createInfo->path.z, &len, &buf); + if (ret) { + return ret; + } + //distinguish *.lua and *.so + int32_t pathLen = (int32_t)strlen(createInfo->path.z); + if ((pathLen > 3) && (0 == strncmp(createInfo->path.z + pathLen - 3, "lua", 3)) && !isValidScript(buf, len)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + } + + //TODO CHECK CODE + if (len + sizeof(SCreateFuncMsg) > pSql->cmd.allocSize) { + ret = tscAllocPayload(&pSql->cmd, len + sizeof(SCreateFuncMsg)); + if (ret) { + tfree(buf); + return ret; + } + } + + SCreateFuncMsg *pMsg = (SCreateFuncMsg *)pSql->cmd.payload; + + strcpy(pMsg->name, createInfo->name.z); + strcpy(pMsg->path, createInfo->path.z); + + pMsg->funcType = htonl(createInfo->type); + pMsg->bufSize = htonl(createInfo->bufSize); + + pMsg->outputType = createInfo->output.type; + pMsg->outputLen = htons(createInfo->output.bytes); + + pMsg->codeLen = htonl(len); + memcpy(pMsg->code, buf, len); + tfree(buf); + + break; + } + case TSDB_SQL_DROP_FUNCTION: { + SStrToken* t0 = taosArrayGet(pInfo->pMiscInfo->a, 0); + + SDropFuncMsg *pMsg = (SDropFuncMsg *)pSql->cmd.payload; + + t0->z[t0->n] = 0; + + strdequote(t0->z); + + if (strlen(t0->z) >= TSDB_FUNC_NAME_LEN) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + + strcpy(pMsg->name, t0->z); + + break; + } + default: + return TSDB_CODE_TSC_APP_ERROR; + } + + return TSDB_CODE_SUCCESS; +} + int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pInfo == NULL || pSql == NULL) { return TSDB_CODE_TSC_APP_ERROR; @@ -486,6 +619,16 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { break; } + case TSDB_SQL_CREATE_FUNCTION: + case TSDB_SQL_DROP_FUNCTION: { + code = handleUserDefinedFunc(pSql, pInfo); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + break; + } + case TSDB_SQL_ALTER_DB: case TSDB_SQL_CREATE_DB: { const char* msg1 = "invalid db name"; @@ -769,7 +912,15 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return code; } + SArray *pUdfInfo = NULL; + if (pQueryInfo->pUdfInfo) { + pUdfInfo = taosArrayDup(pQueryInfo->pUdfInfo); + } + pQueryInfo = pCmd->active; + pQueryInfo->pUdfInfo = pUdfInfo; + pQueryInfo->udfCopy = true; + } } @@ -1018,7 +1169,7 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS } SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, index.columnIndex); - if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP || pSchema->type == TSDB_DATA_TYPE_FLOAT + if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP || pSchema->type == TSDB_DATA_TYPE_FLOAT || pSchema->type == TSDB_DATA_TYPE_DOUBLE || pSchema->type == TSDB_DATA_TYPE_NCHAR || pSchema->type == TSDB_DATA_TYPE_BINARY) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); @@ -1245,12 +1396,16 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) { const char* msg4 = "invalid data type"; const char* msg5 = "invalid binary/nchar column length"; const char* msg6 = "invalid column name"; + const char* msg7 = "too many columns"; // number of fields no less than 2 size_t numOfCols = taosArrayGetSize(pFieldList); - if (numOfCols <= 1 || numOfCols > TSDB_MAX_COLUMNS) { + if (numOfCols <= 1 ) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); return false; + } else if (numOfCols > TSDB_MAX_COLUMNS) { + invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); + return false; } // first column must be timestamp @@ -1385,13 +1540,20 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) { const char* msg4 = "invalid tag name"; const char* msg5 = "invalid binary/nchar tag length"; const char* msg6 = "invalid data type in tags"; + const char* msg7 = "too many columns"; STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; int32_t numOfTags = tscGetNumOfTags(pTableMeta); int32_t numOfCols = tscGetNumOfColumns(pTableMeta); - + + // no more max columns + if (numOfTags + numOfCols >= TSDB_MAX_COLUMNS) { + invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); + return false; + } + // no more than 6 tags if (numOfTags == TSDB_MAX_TAGS) { char msg[128] = {0}; @@ -1809,6 +1971,69 @@ static bool hasNoneUserDefineExpr(SQueryInfo* pQueryInfo) { return false; } +void genUdfList(SArray* pUdfInfo, tSqlExpr *pNode) { + if (pNode == NULL) { + return; + } + + if (pNode->type == SQL_NODE_EXPR) { + genUdfList(pUdfInfo, pNode->pLeft); + genUdfList(pUdfInfo, pNode->pRight); + return; + } + + if (pNode->type == SQL_NODE_SQLFUNCTION) { + pNode->functionId = isValidFunction(pNode->Expr.operand.z, pNode->Expr.operand.n); + if (pNode->functionId < 0) { // extract all possible user defined function + struct SUdfInfo info = {0}; + info.name = strndup(pNode->Expr.operand.z, pNode->Expr.operand.n); + int32_t functionId = (int32_t)taosArrayGetSize(pUdfInfo) * (-1) - 1; + info.functionId = functionId; + + taosArrayPush(pUdfInfo, &info); + } + } +} + +/* +static int32_t checkForUdf(SSqlObj* pSql, SQueryInfo* pQueryInfo, SArray* pSelection) { + if (pQueryInfo->pUdfInfo != NULL) { + return TSDB_CODE_SUCCESS; + } + + pQueryInfo->pUdfInfo = taosArrayInit(4, sizeof(struct SUdfInfo)); + + size_t nExpr = taosArrayGetSize(pSelection); + + for (int32_t i = 0; i < nExpr; ++i) { + tSqlExprItem* pItem = taosArrayGet(pSelection, i); + + int32_t type = pItem->pNode->type; + if (type == SQL_NODE_EXPR || type == SQL_NODE_SQLFUNCTION) { + genUdfList(pQueryInfo->pUdfInfo, pItem->pNode); + } + } + + if (taosArrayGetSize(pQueryInfo->pUdfInfo) > 0) { + return tscGetUdfFromNode(pSql, pQueryInfo); + } else { + return TSDB_CODE_SUCCESS; + } +} +*/ + +static SUdfInfo* isValidUdf(SArray* pUdfInfo, const char* name, int32_t len) { + size_t t = taosArrayGetSize(pUdfInfo); + for(int32_t i = 0; i < t; ++i) { + SUdfInfo* pUdf = taosArrayGet(pUdfInfo, i); + if (strlen(pUdf->name) == len && strncasecmp(pUdf->name, name, len) == 0) { + return pUdf; + } + } + + return NULL; +} + int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelNodeList, bool joinQuery, bool timeWindowQuery, bool outerQuery) { assert(pSelNodeList != NULL && pCmd != NULL); @@ -1841,12 +2066,18 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS int32_t type = pItem->pNode->type; if (type == SQL_NODE_SQLFUNCTION) { pItem->pNode->functionId = isValidFunction(pItem->pNode->Expr.operand.z, pItem->pNode->Expr.operand.n); + SUdfInfo* pUdfInfo = NULL; if (pItem->pNode->functionId < 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); + pUdfInfo = isValidUdf(pQueryInfo->pUdfInfo, pItem->pNode->Expr.operand.z, pItem->pNode->Expr.operand.n); + if (pUdfInfo == NULL) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); + } + + pItem->pNode->functionId = pUdfInfo->functionId; } // sql function in selection clause, append sql function info in pSqlCmd structure sequentially - if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, pItem, true) != TSDB_CODE_SUCCESS) { + if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, pItem, true, pUdfInfo) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } } else if (type == SQL_NODE_TABLE_COLUMN || type == SQL_NODE_VALUE) { @@ -2101,7 +2332,8 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t } static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSchema* pSchema, SConvertFunc cvtFunc, - const char* name, int32_t resColIdx, SColumnIndex* pColIndex, bool finalResult) { + const char* name, int32_t resColIdx, SColumnIndex* pColIndex, bool finalResult, + SUdfInfo* pUdfInfo) { const char* msg1 = "not support column types"; int32_t f = cvtFunc.execFuncId; @@ -2117,7 +2349,7 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS int16_t resBytes = 0; int32_t interBufSize = 0; - getResultDataInfo(pSchema->type, pSchema->bytes, f, 0, &resType, &resBytes, &interBufSize, 0, false); + getResultDataInfo(pSchema->type, pSchema->bytes, f, 0, &resType, &resBytes, &interBufSize, 0, false, pUdfInfo); SExprInfo* pExpr = tscExprAppend(pQueryInfo, f, pColIndex, resType, resBytes, getNewResColId(pCmd), interBufSize, false); tstrncpy(pExpr->base.aliasName, name, tListLen(pExpr->base.aliasName)); @@ -2189,18 +2421,19 @@ static void updateLastScanOrderIfNeeded(SQueryInfo* pQueryInfo) { } } -static UNUSED_FUNC void updateFunctionInterBuf(SQueryInfo* pQueryInfo, bool superTable) { +static UNUSED_FUNC void updateFunctionInterBuf(SQueryInfo* pQueryInfo, bool superTable, SUdfInfo* pUdfInfo) { size_t numOfExpr = tscNumOfExprs(pQueryInfo); for (int32_t i = 0; i < numOfExpr; ++i) { SExprInfo* pExpr = tscExprGet(pQueryInfo, i); int32_t param = (int32_t)pExpr->base.param[0].i64; getResultDataInfo(pExpr->base.colType, pExpr->base.colBytes, pExpr->base.functionId, param, &pExpr->base.resType, &pExpr->base.resBytes, - &pExpr->base.interBytes, 0, superTable); + &pExpr->base.interBytes, 0, superTable, pUdfInfo); } } -int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, bool finalResult) { +int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, bool finalResult, + SUdfInfo* pUdfInfo) { STableMetaInfo* pTableMetaInfo = NULL; int32_t functionId = pItem->pNode->functionId; @@ -2349,7 +2582,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col int32_t intermediateResSize = 0; if (getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &resultType, &resultSize, - &intermediateResSize, 0, false) != TSDB_CODE_SUCCESS) { + &intermediateResSize, 0, false, NULL) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -2483,7 +2716,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col SStrToken t = {.z = pSchema[j].name, .n = (uint32_t)strnlen(pSchema[j].name, TSDB_COL_NAME_LEN)}; setResultColName(name, pItem, cvtFunc.originFuncId, &t, true); - if (setExprInfoForFunctions(pCmd, pQueryInfo, &pSchema[j], cvtFunc, name, colIndex++, &index, finalResult) != 0) { + if (setExprInfoForFunctions(pCmd, pQueryInfo, &pSchema[j], cvtFunc, name, colIndex++, &index, + finalResult, pUdfInfo) != 0) { return TSDB_CODE_TSC_INVALID_OPERATION; } } @@ -2506,7 +2740,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col bool multiColOutput = taosArrayGetSize(pItem->pNode->Expr.paramList) > 1; setResultColName(name, pItem, cvtFunc.originFuncId, &pParamElem->pNode->columnName, multiColOutput); - if (setExprInfoForFunctions(pCmd, pQueryInfo, pSchema, cvtFunc, name, colIndex++, &index, finalResult) != 0) { + if (setExprInfoForFunctions(pCmd, pQueryInfo, pSchema, cvtFunc, name, colIndex++, &index, finalResult, pUdfInfo) != 0) { return TSDB_CODE_TSC_INVALID_OPERATION; } } @@ -2531,7 +2765,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col SStrToken t = {.z = pSchema[i].name, .n = (uint32_t)strnlen(pSchema[i].name, TSDB_COL_NAME_LEN)}; setResultColName(name, pItem, cvtFunc.originFuncId, &t, true); - if (setExprInfoForFunctions(pCmd, pQueryInfo, &pSchema[index.columnIndex], cvtFunc, name, colIndex, &index, finalResult) != 0) { + if (setExprInfoForFunctions(pCmd, pQueryInfo, &pSchema[index.columnIndex], cvtFunc, name, colIndex, &index, + finalResult, pUdfInfo) != 0) { return TSDB_CODE_TSC_INVALID_OPERATION; } colIndex++; @@ -2602,7 +2837,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } - getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &resultType, &resultSize, &interResult, 0, false); + getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &resultType, &resultSize, &interResult, 0, false, + pUdfInfo); /* * sql function transformation @@ -2715,7 +2951,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col int16_t type = 0; int32_t inter = 0; - int32_t ret = getResultDataInfo(s.type, s.bytes, TSDB_FUNC_TID_TAG, 0, &type, &bytes, &inter, 0, 0); + int32_t ret = getResultDataInfo(s.type, s.bytes, TSDB_FUNC_TID_TAG, 0, &type, &bytes, &inter, 0, 0, NULL); assert(ret == TSDB_CODE_SUCCESS); s.type = (uint8_t)type; @@ -2739,7 +2975,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col int32_t inter = 0; int16_t resType = 0; int16_t bytes = 0; - getResultDataInfo(TSDB_DATA_TYPE_INT, 4, TSDB_FUNC_BLKINFO, 0, &resType, &bytes, &inter, 0, 0); + + getResultDataInfo(TSDB_DATA_TYPE_INT, 4, TSDB_FUNC_BLKINFO, 0, &resType, &bytes, &inter, 0, 0, NULL); SSchema s = {.name = "block_dist", .type = TSDB_DATA_TYPE_BINARY, .bytes = bytes}; @@ -2757,10 +2994,64 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return TSDB_CODE_SUCCESS; } - default: - return TSDB_CODE_TSC_INVALID_OPERATION; + default: { + pUdfInfo = isValidUdf(pQueryInfo->pUdfInfo, pItem->pNode->Expr.operand.z, pItem->pNode->Expr.operand.n); + if (pUdfInfo == NULL) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9); + } + + tSqlExprItem* pParamElem = taosArrayGet(pItem->pNode->Expr.paramList, 0);; + if (pParamElem->pNode->tokenId != TK_ID) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + + SColumnIndex index = COLUMN_INDEX_INITIALIZER; + if (getColumnIndexByName(&pParamElem->pNode->columnName, pQueryInfo, &index, tscGetErrorMsgPayload(pCmd)) != TSDB_CODE_SUCCESS) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + } + + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); + } + + pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); + + // functions can not be applied to tags + if (index.columnIndex >= tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); + } + + int32_t inter = 0; + int16_t resType = 0; + int16_t bytes = 0; + getResultDataInfo(TSDB_DATA_TYPE_INT, 4, functionId, 0, &resType, &bytes, &inter, 0, false, pUdfInfo); + + SExprInfo* pExpr = tscExprAppend(pQueryInfo, functionId, &index, resType, bytes, getNewResColId(pCmd), inter, false); + + memset(pExpr->base.aliasName, 0, tListLen(pExpr->base.aliasName)); + getColumnName(pItem, pExpr->base.aliasName, pExpr->base.token, sizeof(pExpr->base.aliasName) - 1); + + SSchema s = {0}; + s.type = (uint8_t)resType; + s.bytes = bytes; + s.colId = pExpr->base.colInfo.colId; + + uint64_t uid = pTableMetaInfo->pTableMeta->id.uid; + SColumnList ids = createColumnList(1, index.tableIndex, index.columnIndex); + if (finalResult) { + insertResultField(pQueryInfo, colIndex, &ids, pUdfInfo->resBytes, pUdfInfo->resType, pExpr->base.aliasName, pExpr); + } else { + for (int32_t i = 0; i < ids.num; ++i) { + tscColumnListInsert(pQueryInfo->colList, index.columnIndex, uid, &s); + } + } + + tscInsertPrimaryTsSourceColumn(pQueryInfo, pTableMetaInfo->pTableMeta->id.uid); + return TSDB_CODE_SUCCESS; + } } - + + return TSDB_CODE_TSC_INVALID_OPERATION; } // todo refactor @@ -2826,7 +3117,7 @@ int32_t doGetColumnIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColum if (isTablenameToken(pToken)) { pIndex->columnIndex = TSDB_TBNAME_COLUMN_INDEX; - } else if (strlen(DEFAULT_PRIMARY_TIMESTAMP_COL_NAME) == pToken->n && + } else if (strlen(DEFAULT_PRIMARY_TIMESTAMP_COL_NAME) == pToken->n && strncasecmp(pToken->z, DEFAULT_PRIMARY_TIMESTAMP_COL_NAME, pToken->n) == 0) { pIndex->columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX; // just make runtime happy, need fix java test case InsertSpecialCharacterJniTest } else if (pToken->n == 0) { @@ -3074,7 +3365,7 @@ int32_t tscTansformFuncForSTableQuery(SQueryInfo* pQueryInfo) { (functionId >= TSDB_FUNC_FIRST_DST && functionId <= TSDB_FUNC_STDDEV_DST) || (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_IRATE)) { if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, (int32_t)pExpr->base.param[0].i64, &type, &bytes, - &interBytes, 0, true) != TSDB_CODE_SUCCESS) { + &interBytes, 0, true, NULL) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -3105,6 +3396,10 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) { int32_t inter = 0; int32_t functionId = pExpr->base.functionId; + if (functionId < 0) { + continue; + } + if (functionId >= TSDB_FUNC_TS && functionId <= TSDB_FUNC_DIFF) { continue; } @@ -3116,9 +3411,9 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) { } else if (functionId == TSDB_FUNC_STDDEV_DST) { functionId = TSDB_FUNC_STDDEV; } - - getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &pExpr->base.resType, &pExpr->base.resBytes, - &inter, 0, false); + + getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &pExpr->base.resType, &pExpr->base.resBytes, &inter, + 0, false, NULL); } } @@ -3131,6 +3426,10 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) size_t size = tscNumOfExprs(pQueryInfo); for (int32_t i = 0; i < size; ++i) { int32_t functionId = tscExprGet(pQueryInfo, i)->base.functionId; + if (functionId < 0) { + continue; + } + if ((aAggs[functionId].status & TSDB_FUNCSTATE_STABLE) == 0) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return true; @@ -3175,45 +3474,54 @@ static bool groupbyTagsOrNull(SQueryInfo* pQueryInfo) { static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool twQuery) { int32_t startIdx = 0; + int32_t aggUdf = 0; + int32_t scalarUdf = 0; + int32_t prjNum = 0; + int32_t aggNum = 0; size_t numOfExpr = tscNumOfExprs(pQueryInfo); assert(numOfExpr > 0); - SExprInfo* pExpr = tscExprGet(pQueryInfo, startIdx); - - // ts function can be simultaneously used with any other functions. - int32_t functionID = pExpr->base.functionId; - if (functionID == TSDB_FUNC_TS || functionID == TSDB_FUNC_TS_DUMMY) { - startIdx++; - } - - int32_t factor = functionCompatList[tscExprGet(pQueryInfo, startIdx)->base.functionId]; - - if (tscExprGet(pQueryInfo, 0)->base.functionId == TSDB_FUNC_LAST_ROW && (joinQuery || twQuery || !groupbyTagsOrNull(pQueryInfo))) { - return false; - } + int32_t factor = INT32_MAX; // diff function cannot be executed with other function // arithmetic function can be executed with other arithmetic functions size_t size = tscNumOfExprs(pQueryInfo); - for (int32_t i = startIdx + 1; i < size; ++i) { + for (int32_t i = startIdx; i < size; ++i) { SExprInfo* pExpr1 = tscExprGet(pQueryInfo, i); int16_t functionId = pExpr1->base.functionId; - if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS) { + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1); + pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE ? ++aggUdf : ++scalarUdf; + + continue; + } + + if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY) { + ++prjNum; + continue; } + if (functionId == TSDB_FUNC_PRJ) { + ++prjNum; + } + if (functionId == TSDB_FUNC_PRJ && (pExpr1->base.colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX || TSDB_COL_IS_UD_COL(pExpr1->base.colInfo.flag))) { continue; } - if (functionCompatList[functionId] != factor) { - return false; + if (factor == INT32_MAX) { + factor = functionCompatList[functionId]; } else { - if (factor == -1) { // two functions with the same -1 flag + if (functionCompatList[functionId] != factor) { return false; + } else { + if (factor == -1) { // two functions with the same -1 flag + return false; + } } } @@ -3222,6 +3530,18 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool } } + aggNum = (int32_t)size - prjNum - aggUdf - scalarUdf; + + assert(aggNum >= 0); + + if (aggUdf > 0 && (prjNum > 0 || aggNum > 0 || scalarUdf > 0)) { + return false; + } + + if (scalarUdf > 0 && aggNum > 0) { + return false; + } + return true; } @@ -3287,7 +3607,7 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { pSchema = tGetTbnameColumnSchema(); } else { @@ -3296,7 +3616,7 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd int32_t numOfCols = tscGetNumOfColumns(pTableMeta); bool groupTag = (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX || index.columnIndex >= numOfCols); - + if (groupTag) { if (!UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); @@ -3399,9 +3719,9 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, * make memory sanitizer happy; */ if (pRight->value.nLen == 0) { - bufLen = pRight->value.nLen + 2; + bufLen = pRight->value.nLen + 2; } else { - bufLen = pRight->value.nLen + 1; + bufLen = pRight->value.nLen + 1; } } @@ -3417,7 +3737,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, 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); + memcpy((char *)(pColumnFilter->pz), (char *)(pVal->pz), pVal->nLen); tVariantDestroy(pVal); free(pVal); @@ -3830,7 +4150,7 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQuer return TSDB_CODE_TSC_INVALID_OPERATION; } - if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, &item, false) != TSDB_CODE_SUCCESS) { + if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, &item, false, NULL) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -4841,7 +5161,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq int32_t type = 0; if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; + goto PARSE_WHERE_EXIT; } tSqlExprCompact(pExpr); @@ -4851,7 +5171,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq // 1. check if it is a join query if ((ret = validateJoinExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; + goto PARSE_WHERE_EXIT; } // 2. get the query time range @@ -4873,7 +5193,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq if ((ret = getColumnQueryCondInfo(&pSql->cmd, pQueryInfo, condExpr.pColumnCond, TK_AND)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } - + if (taosArrayGetSize(pQueryInfo->pUpstream) > 0 ) { if ((ret = getColumnQueryCondInfo(&pSql->cmd, pQueryInfo, condExpr.pTimewindow, TK_AND)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; @@ -5233,14 +5553,14 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq if (PRIMARYKEY_TIMESTAMP_COL_INDEX == index.columnIndex) { orderByTS = true; } - + SArray *columnInfo = pQueryInfo->groupbyExpr.columnInfo; if (columnInfo != NULL && taosArrayGetSize(columnInfo) > 0) { SColIndex* pColIndex = taosArrayGet(columnInfo, 0); if (PRIMARYKEY_TIMESTAMP_COL_INDEX != index.columnIndex && pColIndex->colIndex == index.columnIndex) { - orderByGroupbyCol = true; + orderByGroupbyCol = true; } - } + } if (!(orderByTags || orderByTS || orderByGroupbyCol) && !isTopBottomQuery(pQueryInfo)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } else { // order by top/bottom result value column is not supported in case of interval query. @@ -5324,15 +5644,15 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq SArray *columnInfo = pQueryInfo->groupbyExpr.columnInfo; if (columnInfo != NULL && taosArrayGetSize(columnInfo) > 0) { SColIndex* pColIndex = taosArrayGet(columnInfo, 0); - validOrder = (pColIndex->colIndex == index.columnIndex); - } + validOrder = (pColIndex->colIndex == index.columnIndex); + } if (!validOrder) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); - } + } tVariantListItem* p1 = taosArrayGet(pSqlNode->pSortOrder, 0); - pQueryInfo->groupbyExpr.orderIndex = pSchema[index.columnIndex].colId; - pQueryInfo->groupbyExpr.orderType = p1->sortOrder; - + pQueryInfo->groupbyExpr.orderIndex = pSchema[index.columnIndex].colId; + pQueryInfo->groupbyExpr.orderType = p1->sortOrder; + } if (isTopBottomQuery(pQueryInfo)) { @@ -5340,7 +5660,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq SArray *columnInfo = pQueryInfo->groupbyExpr.columnInfo; if (columnInfo != NULL && taosArrayGetSize(columnInfo) > 0) { SColIndex* pColIndex = taosArrayGet(columnInfo, 0); - validOrder = (pColIndex->colIndex == index.columnIndex); + validOrder = (pColIndex->colIndex == index.columnIndex); } else { /* order of top/bottom query in interval is not valid */ SExprInfo* pExpr = tscExprGet(pQueryInfo, 0); @@ -5350,16 +5670,16 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq if (pExpr->base.colInfo.colIndex != index.columnIndex && index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } - validOrder = true; - } + validOrder = true; + } if (!validOrder) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); - } + } tVariantListItem* pItem = taosArrayGet(pSqlNode->pSortOrder, 0); pQueryInfo->order.order = pItem->sortOrder; - + pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId; return TSDB_CODE_SUCCESS; } @@ -5771,6 +6091,16 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu for (int32_t k = 0; k < size; ++k) { SExprInfo* pExpr = tscExprGet(pQueryInfo, k); + if (pExpr->base.functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * pExpr->base.functionId - 1); + if (pUdfInfo->funcType == TSDB_UDF_TYPE_SCALAR) { + isProjectionFunction = true; + break; + } else { + continue; + } + } + // projection query on primary timestamp, the selectivity function needs to be present. if (pExpr->base.functionId == TSDB_FUNC_PRJ && pExpr->base.colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { bool hasSelectivity = false; @@ -5790,6 +6120,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu 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; + break; } } @@ -6275,11 +6606,15 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) { for (int32_t i = 0; i < size; ++i) { SExprInfo* pExpr = tscExprGet(pQueryInfo, i); + if (pExpr->base.functionId < 0) { + continue; + } + if ((pExpr->base.functionId != TSDB_FUNC_TAG_DUMMY && pExpr->base.functionId != TSDB_FUNC_TS_DUMMY) && !(pExpr->base.functionId == TSDB_FUNC_PRJ && TSDB_COL_IS_UD_COL(pExpr->base.colInfo.flag))) { SSchema* pColSchema = &pSchema[pExpr->base.colInfo.colIndex]; getResultDataInfo(pColSchema->type, pColSchema->bytes, pExpr->base.functionId, (int32_t)pExpr->base.param[0].i64, &pExpr->base.resType, - &pExpr->base.resBytes, &pExpr->base.interBytes, tagLength, isSTable); + &pExpr->base.resBytes, &pExpr->base.interBytes, tagLength, isSTable, NULL); } } } @@ -6407,6 +6742,14 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { continue; } + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1); + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + ++numOfAggregation; + } + + continue; + } if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) { numOfSelectivity++; @@ -6634,6 +6977,10 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* } } + if (f < 0) { + continue; + } + if ((!pQueryInfo->stateWindow) && (f == TSDB_FUNC_DIFF || f == TSDB_FUNC_DERIVATIVE || f == TSDB_FUNC_TWA || f == TSDB_FUNC_IRATE)) { for (int32_t j = 0; j < pQueryInfo->groupbyExpr.numOfGroupCols; ++j) { SColIndex* pColIndex = taosArrayGet(pQueryInfo->groupbyExpr.columnInfo, j); @@ -6642,13 +6989,13 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* return invalidOperationMsg(msg, msg6); } } else if (!TSDB_COL_IS_TAG(pColIndex->flag)) { - return invalidOperationMsg(msg, msg6); + return invalidOperationMsg(msg, msg6); } } } - if (IS_MULTIOUTPUT(aAggs[f].status) && f != TSDB_FUNC_TOP && f != TSDB_FUNC_BOTTOM && - f != TSDB_FUNC_DIFF && f != TSDB_FUNC_DERIVATIVE && f != TSDB_FUNC_TAGPRJ && f != TSDB_FUNC_PRJ) { + if (IS_MULTIOUTPUT(aAggs[f].status) && f != TSDB_FUNC_TOP && f != TSDB_FUNC_BOTTOM && f != TSDB_FUNC_DIFF && + f != TSDB_FUNC_DERIVATIVE && f != TSDB_FUNC_TAGPRJ && f != TSDB_FUNC_PRJ) { return invalidOperationMsg(msg, msg1); } @@ -6675,6 +7022,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* return checkUpdateTagPrjFunctions(pQueryInfo, msg); } } + int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode) { const char* msg1 = "only one expression allowed"; const char* msg2 = "invalid expression in select clause"; @@ -6853,9 +7201,17 @@ void tscPrintSelNodeList(SSqlObj* pSql, int32_t subClauseIndex) { char tmpBuf[1024] = {0}; int32_t tmpLen = 0; + char *name = NULL; + + if (pExpr->base.functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * pExpr->base.functionId - 1); + name = pUdfInfo->name; + } else { + name = aAggs[pExpr->base.functionId].name; + } + tmpLen = - sprintf(tmpBuf, "%s(uid:%" PRIu64 ", %d)", aAggs[pExpr->base.functionId].name, pExpr->base.uid, - pExpr->base.colInfo.colId); + sprintf(tmpBuf, "%s(uid:%" PRId64 ", %d)", name, pExpr->base.uid, pExpr->base.colInfo.colId); if (tmpLen + offset >= totalBufSize - 1) break; @@ -6947,7 +7303,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { const int32_t STABLE_INDEX = 1; STableMetaInfo* pStableMetaInfo = tscGetMetaInfo(pQueryInfo, STABLE_INDEX); - + // super table name, create table by using dst int32_t numOfTables = (int32_t) taosArrayGetSize(pCreateTable->childTableInfo); for(int32_t j = 0; j < numOfTables; ++j) { @@ -7033,7 +7389,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); } } else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) { - pItem->pVar.i64 = convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); + pItem->pVar.i64 = convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); } } @@ -7088,10 +7444,10 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); } } else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) { - pItem->pVar.i64 = convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); + pItem->pVar.i64 = convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); } } - + ret = tVariantDump(&(pItem->pVar), tagVal, pSchema->type, true); @@ -7384,7 +7740,7 @@ int32_t tscGetExprFilters(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelect int32_t outputIndex = (int32_t)tscNumOfExprs(pQueryInfo); // ADD TRUE FOR TEST - if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, &item, true) != TSDB_CODE_SUCCESS) { + if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, &item, true, NULL) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -7674,6 +8030,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { SArray* pVgroupList = NULL; SArray* plist = NULL; STableMeta* pTableMeta = NULL; + SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); pCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); @@ -7702,8 +8059,12 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { uint32_t maxSize = tscGetTableMetaMaxSize(); char name[TSDB_TABLE_FNAME_LEN] = {0}; - char buf[80 * 1024] = {0}; - assert(maxSize < 80 * 1024); + assert(maxSize < 80 * TSDB_MAX_COLUMNS); + if (!pSql->pBuf) { + if (NULL == (pSql->pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + } pTableMeta = calloc(1, maxSize); plist = taosArrayInit(4, POINTER_BYTES); @@ -7720,7 +8081,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pTableMeta->id.uid > 0) { if (pTableMeta->tableType == TSDB_CHILD_TABLE) { - code = tscCreateTableMetaFromSTableMeta(pTableMeta, name, buf); + code = tscCreateTableMetaFromSTableMeta(pTableMeta, name, pSql->pBuf); // create the child table meta from super table failed, try load it from mnode if (code != TSDB_CODE_SUCCESS) { @@ -7743,7 +8104,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { // avoid mem leak, may should update pTableMeta const char* px = tNameGetTableName(pname); if (taosHashGet(pCmd->pTableMetaMap, px, strlen(px)) == NULL) { - STableMeta* pMeta = tscTableMetaDup(pTableMeta); + STableMeta* pMeta = tscTableMetaDup(pTableMeta); STableMetaVgroupInfo p = { .pTableMeta = pMeta, .pVgroupInfo = NULL}; taosHashPut(pCmd->pTableMetaMap, px, strlen(px), &p, sizeof(STableMetaVgroupInfo)); } @@ -7753,9 +8114,41 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { } } + size_t funcSize = 0; + if (pInfo->funcs) { + funcSize = taosArrayGetSize(pInfo->funcs); + } + if (funcSize > 0) { + for (size_t i = 0; i < funcSize; ++i) { + SStrToken* t = taosArrayGet(pInfo->funcs, i); + if (NULL == t) { + continue; + } + + if (t->n >= TSDB_FUNC_NAME_LEN) { + code = tscSQLSyntaxErrMsg(tscGetErrorMsgPayload(pCmd), "too long function name", t->z); + if (code != TSDB_CODE_SUCCESS) { + goto _end; + } + } + + int32_t functionId = isValidFunction(t->z, t->n); + if (functionId < 0) { + struct SUdfInfo info = {0}; + info.name = strndup(t->z, t->n); + if (pQueryInfo->pUdfInfo == NULL) { + pQueryInfo->pUdfInfo = taosArrayInit(4, sizeof(struct SUdfInfo)); + } + + info.functionId = (int32_t)taosArrayGetSize(pQueryInfo->pUdfInfo) * (-1) - 1;; + taosArrayPush(pQueryInfo->pUdfInfo, &info); + } + } + } + // load the table meta for a given table name list - if (taosArrayGetSize(plist) > 0 || taosArrayGetSize(pVgroupList) > 0) { - code = getMultiTableMetaFromMnode(pSql, plist, pVgroupList, tscTableMetaCallBack); + if (taosArrayGetSize(plist) > 0 || taosArrayGetSize(pVgroupList) > 0 || (pQueryInfo->pUdfInfo && taosArrayGetSize(pQueryInfo->pUdfInfo) > 0)) { + code = getMultiTableMetaFromMnode(pSql, plist, pVgroupList, pQueryInfo->pUdfInfo, tscTableMetaCallBack, true); } _end: @@ -7884,12 +8277,21 @@ static int32_t doValidateSubquery(SSqlNode* pSqlNode, int32_t index, SSqlObj* pS // union all is not support currently SSqlNode* p = taosArrayGetP(subInfo->pSubquery, 0); - + if (taosArrayGetSize(subInfo->pSubquery) >= 2) { + return invalidOperationMsg(msgBuf, "not support union in subquery"); + } SQueryInfo* pSub = calloc(1, sizeof(SQueryInfo)); tscInitQueryInfo(pSub); + SArray *pUdfInfo = NULL; + if (pQueryInfo->pUdfInfo) { + pUdfInfo = taosArrayDup(pQueryInfo->pUdfInfo); + } + + pSub->pUdfInfo = pUdfInfo; + pSub->udfCopy = true; + int32_t code = validateSqlNode(pSql, p, pSub); - assert(code != TSDB_CODE_TSC_ACTION_IN_PROGRESS); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -8226,11 +8628,12 @@ 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->globalMerge = tscIsTwoStageSTableQuery(pQueryInfo, 0); pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo); pQueryInfo->orderProjectQuery = tscOrderedProjectionQueryOnSTable(pQueryInfo, 0); @@ -8244,7 +8647,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } taosArrayAddBatch(pQueryInfo->exprList1, (void*) p, numOfExpr); - tfree(p); + tfree(p); } #if 0 @@ -8286,7 +8689,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS assert(pSqlExpr->pRight == NULL); if (pSqlExpr->type == SQL_NODE_VALUE) { - int32_t ret = TSDB_CODE_SUCCESS; + int32_t ret = TSDB_CODE_SUCCESS; *pExpr = calloc(1, sizeof(tExprNode)); (*pExpr)->nodeType = TSQL_NODE_VALUE; (*pExpr)->pVal = calloc(1, sizeof(tVariant)); @@ -8296,12 +8699,12 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS if (pCols != NULL && taosArrayGetSize(pCols) > 0) { SColIndex* idx = taosArrayGet(pCols, 0); SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); - // convert time by precision + // convert time by precision if (pSchema != NULL && TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && TSDB_DATA_TYPE_BINARY == (*pExpr)->pVal->nType) { ret = setColumnFilterInfoForTimestamp(pCmd, pQueryInfo, (*pExpr)->pVal); } } - return ret; + return ret; } else if (pSqlExpr->type == SQL_NODE_SQLFUNCTION) { // arithmetic expression on the results of aggregation functions *pExpr = calloc(1, sizeof(tExprNode)); @@ -8460,9 +8863,7 @@ void normalizeSqlNode(SSqlNode* pSqlNode, const char* dbName) { // 2. pSqlNode->pWhere // 3. pSqlNode->pHaving // 4. pSqlNode->pSortOrder - // pSqlNode->from - } #endif diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 8788dc8c582b05f4595f14668f20fe7d222c0ad7..e975dd7b06caa973077935d3bc60796576ef5aa7 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -503,6 +503,7 @@ int doBuildAndSendMsg(SSqlObj *pSql) { pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_CONNECT || pCmd->command == TSDB_SQL_HB || + pCmd->command == TSDB_SQL_RETRIEVE_FUNC || pCmd->command == TSDB_SQL_STABLEVGROUP) { pRes->code = tscBuildMsg[pCmd->command](pSql, NULL); } @@ -545,7 +546,7 @@ int tscBuildAndSendRequest(SSqlObj *pSql, SQueryInfo* pQueryInfo) { type = pQueryInfo->type; // while numOfTables equals to 0, it must be Heartbeat - assert((pQueryInfo->numOfTables == 0 && pQueryInfo->command == TSDB_SQL_HB) || pQueryInfo->numOfTables > 0); + assert((pQueryInfo->numOfTables == 0 && (pQueryInfo->command == TSDB_SQL_HB || pSql->cmd.command == TSDB_SQL_RETRIEVE_FUNC)) || pQueryInfo->numOfTables > 0); } tscDebug("0x%"PRIx64" SQL cmd:%s will be processed, name:%s, type:%d", pSql->self, sqlCmd[pCmd->command], name, type); @@ -1032,6 +1033,34 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pMsg += sizeof(int32_t); } + // support only one udf + if (pQueryInfo->pUdfInfo != NULL && taosArrayGetSize(pQueryInfo->pUdfInfo) > 0) { + pQueryMsg->udfContentOffset = htonl((int32_t) (pMsg - pCmd->payload)); + for(int32_t i = 0; i < taosArrayGetSize(pQueryInfo->pUdfInfo); ++i) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, i); + *(int8_t*) pMsg = pUdfInfo->resType; + pMsg += sizeof(pUdfInfo->resType); + + *(int16_t*) pMsg = htons(pUdfInfo->resBytes); + pMsg += sizeof(pUdfInfo->resBytes); + + STR_TO_VARSTR(pMsg, pUdfInfo->name); + + pMsg += varDataTLen(pMsg); + + *(int32_t*) pMsg = htonl(pUdfInfo->funcType); + pMsg += sizeof(pUdfInfo->funcType); + + *(int32_t*) pMsg = htonl(pUdfInfo->bufSize); + pMsg += sizeof(pUdfInfo->bufSize); + + pQueryMsg->udfContentLen = htonl(pUdfInfo->contLen); + memcpy(pMsg, pUdfInfo->content, pUdfInfo->contLen); + + pMsg += pUdfInfo->contLen; + } + } + memcpy(pMsg, pSql->sqlstr, sqlLen); pMsg += sqlLen; @@ -1067,6 +1096,18 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_SUCCESS; } +int32_t tscBuildCreateFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SSqlCmd *pCmd = &pSql->cmd; + SCreateFuncMsg *pCreateFuncMsg = (SCreateFuncMsg *)pCmd->payload; + + pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_FUNCTION; + + pCmd->payloadLen = sizeof(SCreateFuncMsg) + htonl(pCreateFuncMsg->codeLen); + + return TSDB_CODE_SUCCESS; +} + + int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCreateDnodeMsg); @@ -1191,6 +1232,17 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_SUCCESS; } +int32_t tscBuildDropFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SSqlCmd *pCmd = &pSql->cmd; + + pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_FUNCTION; + + pCmd->payloadLen = sizeof(SDropFuncMsg); + + return TSDB_CODE_SUCCESS; +} + + int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCMDropTableMsg); @@ -1294,11 +1346,19 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SShowMsg *pShowMsg = (SShowMsg *)pCmd->payload; + SShowInfo *pShowInfo = &pInfo->pMiscInfo->showOpt; + SShowMsg *pShowMsg = (SShowMsg *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); + if (pShowInfo->showType == TSDB_MGMT_TABLE_FUNCTION) { + pShowMsg->type = pShowInfo->showType; + pShowMsg->payloadLen = 0; + pCmd->payloadLen = sizeof(SShowMsg); - if (tNameIsEmpty(&pTableMetaInfo->name)) { + return TSDB_CODE_SUCCESS; + } + + if (tNameIsEmpty(&pTableMetaInfo->name)) { pthread_mutex_lock(&pObj->mutex); tstrncpy(pShowMsg->db, pObj->db, sizeof(pShowMsg->db)); pthread_mutex_unlock(&pObj->mutex); @@ -1306,7 +1366,6 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { tNameGetFullDbName(&pTableMetaInfo->name, pShowMsg->db); } - SShowInfo *pShowInfo = &pInfo->pMiscInfo->showOpt; pShowMsg->type = pShowInfo->showType; if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { @@ -1819,6 +1878,29 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_SUCCESS; } +int tscBuildRetrieveFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SSqlCmd *pCmd = &pSql->cmd; + + char *pMsg = pCmd->payload; + SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); + int32_t numOfFuncs = (int32_t)taosArrayGetSize(pQueryInfo->pUdfInfo); + + SRetrieveFuncMsg *pRetrieveFuncMsg = (SRetrieveFuncMsg *)pMsg; + pRetrieveFuncMsg->num = htonl(numOfFuncs); + + pMsg += sizeof(SRetrieveFuncMsg); + for(int32_t i = 0; i < numOfFuncs; ++i) { + SUdfInfo* pUdf = taosArrayGet(pQueryInfo->pUdfInfo, i); + STR_TO_NET_VARSTR(pMsg, pUdf->name); + pMsg += varDataNetTLen(pMsg); + } + + pCmd->msgType = TSDB_MSG_TYPE_CM_RETRIEVE_FUNC; + pCmd->payloadLen = (int32_t)(pMsg - pCmd->payload); + + return TSDB_CODE_SUCCESS; +} + int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; STscObj *pObj = pSql->pTscObj; @@ -1873,7 +1955,6 @@ static int32_t tableMetaMsgConvert(STableMetaMsg* pMetaMsg) { pMetaMsg->vgroup.vgId = htonl(pMetaMsg->vgroup.vgId); pMetaMsg->uid = htobe64(pMetaMsg->uid); -// pMetaMsg->contLen = htonl(pMetaMsg->contLen); pMetaMsg->numOfColumns = htons(pMetaMsg->numOfColumns); if ((pMetaMsg->tableType != TSDB_SUPER_TABLE) && @@ -1938,13 +2019,14 @@ static void doAddTableMetaToLocalBuf(STableMeta* pTableMeta, STableMetaMsg* pMet int32_t len = (int32_t) strnlen(pTableMeta->sTableName, TSDB_TABLE_FNAME_LEN); // The super tableMeta already exists, create it according to tableMeta and add it to hash map - STableMeta* pSupTableMeta = createSuperTableMeta(pMetaMsg); - - uint32_t size = tscGetTableMetaSize(pSupTableMeta); - int32_t code = taosHashPut(tscTableMetaInfo, pTableMeta->sTableName, len, pSupTableMeta, size); - assert(code == TSDB_CODE_SUCCESS); + if (updateSTable) { + STableMeta* pSupTableMeta = createSuperTableMeta(pMetaMsg); + uint32_t size = tscGetTableMetaSize(pSupTableMeta); + int32_t code = taosHashPut(tscTableMetaInfo, pTableMeta->sTableName, len, pSupTableMeta, size); + assert(code == TSDB_CODE_SUCCESS); - tfree(pSupTableMeta); + tfree(pSupTableMeta); + } CChildTableMeta* cMeta = tscCreateChildMeta(pTableMeta); taosHashPut(tscTableMetaInfo, pMetaMsg->tableFname, strlen(pMetaMsg->tableFname), cMeta, sizeof(CChildTableMeta)); @@ -2034,12 +2116,64 @@ static SVgroupsInfo* createVgroupInfoFromMsg(char* pMsg, int32_t* size, uint64_t return pVgroupInfo; } +int tscProcessRetrieveFuncRsp(SSqlObj* pSql) { + SSqlCmd* pCmd = &pSql->cmd; + SUdfFuncMsg* pFuncMsg = (SUdfFuncMsg *)pSql->res.pRsp; + SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); + + pFuncMsg->num = htonl(pFuncMsg->num); + assert(pFuncMsg->num == taosArrayGetSize(pQueryInfo->pUdfInfo)); + + char* pMsg = pFuncMsg->content; + for(int32_t i = 0; i < pFuncMsg->num; ++i) { + SFunctionInfoMsg* pFunc = (SFunctionInfoMsg*) pMsg; + + for(int32_t j = 0; j < pFuncMsg->num; ++j) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, j); + if (strcmp(pUdfInfo->name, pFunc->name) != 0) { + continue; + } + + if (pUdfInfo->content) { + continue; + } + + pUdfInfo->resBytes = htons(pFunc->resBytes); + pUdfInfo->resType = pFunc->resType; + pUdfInfo->funcType = htonl(pFunc->funcType); + pUdfInfo->contLen = htonl(pFunc->len); + pUdfInfo->bufSize = htonl(pFunc->bufSize); + + pUdfInfo->content = malloc(pUdfInfo->contLen); + memcpy(pUdfInfo->content, pFunc->content, pUdfInfo->contLen); + + pMsg += sizeof(SFunctionInfoMsg) + pUdfInfo->contLen; + } + } + + // master sqlObj locates in param + SSqlObj* parent = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)pSql->param); + if(parent == NULL) { + return pSql->res.code; + } + + SQueryInfo* parQueryInfo = tscGetQueryInfo(&parent->cmd); + + assert(parent->signature == parent && (int64_t)pSql->param == parent->self); + taosArrayDestroy(parQueryInfo->pUdfInfo); + + parQueryInfo->pUdfInfo = pQueryInfo->pUdfInfo; // assigned to parent sql obj. + pQueryInfo->pUdfInfo = NULL; + return TSDB_CODE_SUCCESS; +} + int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { char *rsp = pSql->res.pRsp; SMultiTableMeta *pMultiMeta = (SMultiTableMeta *)rsp; pMultiMeta->numOfTables = htonl(pMultiMeta->numOfTables); pMultiMeta->numOfVgroup = htonl(pMultiMeta->numOfVgroup); + pMultiMeta->numOfUdf = htonl(pMultiMeta->numOfUdf); rsp += sizeof(SMultiTableMeta); @@ -2049,10 +2183,10 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { } SSqlCmd *pParentCmd = &pParentSql->cmd; - SHashObj *pSet = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + SHashObj *pSet = taosHashInit(pMultiMeta->numOfVgroup, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); - char* pMsg = pMultiMeta->meta; char* buf = NULL; + char* pMsg = pMultiMeta->meta; if (pMultiMeta->compressed) { buf = malloc(pMultiMeta->rawLen - sizeof(SMultiTableMeta)); int32_t len = tsDecompressString(pMultiMeta->meta, pMultiMeta->contLen - sizeof(SMultiTableMeta), 1, @@ -2073,6 +2207,7 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { return code; } + bool freeMeta = false; STableMeta* pTableMeta = tscCreateTableMetaFromMsg(pMetaMsg); if (!tIsValidSchema(pTableMeta->schema, pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.numOfTags)) { tscError("0x%"PRIx64" invalid table meta from mnode, name:%s", pSql->self, pMetaMsg->tableFname); @@ -2087,22 +2222,27 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { SName sn = {0}; tNameFromString(&sn, pMetaMsg->tableFname, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - const char* tableName = tNameGetTableName(&sn); - size_t keyLen = strlen(tableName); + if (pMultiMeta->metaClone == 1 || pTableMeta->tableType == TSDB_SUPER_TABLE) { + STableMetaVgroupInfo p = {.pTableMeta = pTableMeta,}; - STableMetaVgroupInfo p = {.pTableMeta = pTableMeta,}; - taosHashPut(pParentCmd->pTableMetaMap, tableName, keyLen, &p, sizeof(STableMetaVgroupInfo)); + const char* tableName = tNameGetTableName(&sn); + size_t keyLen = strlen(tableName); + taosHashPut(pParentCmd->pTableMetaMap, tableName, keyLen, &p, sizeof(STableMetaVgroupInfo)); + } else { + freeMeta = true; + } - bool addToBuf = false; - if (taosHashGet(pSet, &pMetaMsg->uid, sizeof(pMetaMsg->uid)) == NULL) { - addToBuf = true; - taosHashPut(pSet, &pMetaMsg->uid, sizeof(pMetaMsg->uid), "", 0); + // for each super table, only update meta information once + bool updateStableMeta = false; + if (pTableMeta->tableType == TSDB_CHILD_TABLE && taosHashGet(pSet, &pMetaMsg->suid, sizeof(pMetaMsg->suid)) == NULL) { + updateStableMeta = true; + taosHashPut(pSet, &pTableMeta->suid, sizeof(pMetaMsg->suid), "", 0); } // create the tableMeta and add it into the TableMeta map - doAddTableMetaToLocalBuf(pTableMeta, pMetaMsg, addToBuf); + doAddTableMetaToLocalBuf(pTableMeta, pMetaMsg, updateStableMeta); - // if the vgroup is not updated in current process, update it. + // for each vgroup, only update the information once. int64_t vgId = pMetaMsg->vgroup.vgId; if (pTableMeta->tableType != TSDB_SUPER_TABLE && taosHashGet(pSet, &vgId, sizeof(vgId)) == NULL) { doUpdateVgroupInfo(pTableMeta, &pMetaMsg->vgroup); @@ -2110,6 +2250,9 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { } pMsg += pMetaMsg->contLen; + if (freeMeta) { + tfree(pTableMeta); + } } for(int32_t i = 0; i < pMultiMeta->numOfVgroup; ++i) { @@ -2128,6 +2271,37 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { pMsg += size; } + SQueryInfo* pQueryInfo = tscGetQueryInfo(pParentCmd); + if (pMultiMeta->numOfUdf > 0) { + assert(pQueryInfo->pUdfInfo != NULL); + } + + for(int32_t i = 0; i < pMultiMeta->numOfUdf; ++i) { + SFunctionInfoMsg* pFunc = (SFunctionInfoMsg*) pMsg; + + for(int32_t j = 0; j < pMultiMeta->numOfUdf; ++j) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, j); + if (strcmp(pUdfInfo->name, pFunc->name) != 0) { + continue; + } + + if (pUdfInfo->content) { + continue; + } + + pUdfInfo->resBytes = htons(pFunc->resBytes); + pUdfInfo->resType = pFunc->resType; + pUdfInfo->funcType = htonl(pFunc->funcType); + pUdfInfo->contLen = htonl(pFunc->len); + pUdfInfo->bufSize = htonl(pFunc->bufSize); + + pUdfInfo->content = malloc(pUdfInfo->contLen); + memcpy(pUdfInfo->content, pFunc->content, pUdfInfo->contLen); + + pMsg += sizeof(SFunctionInfoMsg) + pUdfInfo->contLen; + } + } + pSql->res.code = TSDB_CODE_SUCCESS; pSql->res.numOfTotal = pMultiMeta->numOfTables; tscDebug("0x%"PRIx64" load multi-tableMeta from mnode, numOfTables:%d", pSql->self, pMultiMeta->numOfTables); @@ -2518,7 +2692,7 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn return code; } -int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVgroupNameList, __async_cb_func_t fp) { +int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVgroupNameList, SArray* pUdfList, __async_cb_func_t fp, bool metaClone) { SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); if (NULL == pNew) { tscError("0x%"PRIx64" failed to allocate sqlobj to get multiple table meta", pSql->self); @@ -2531,8 +2705,9 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg int32_t numOfTable = (int32_t) taosArrayGetSize(pNameList); int32_t numOfVgroupList = (int32_t) taosArrayGetSize(pVgroupNameList); + int32_t numOfUdf = pUdfList ? (int32_t)taosArrayGetSize(pUdfList) : 0; - int32_t size = (numOfTable + numOfVgroupList) * TSDB_TABLE_FNAME_LEN + sizeof(SMultiTableInfoMsg); + int32_t size = (numOfTable + numOfVgroupList) * TSDB_TABLE_FNAME_LEN + TSDB_FUNC_NAME_LEN * numOfUdf + sizeof(SMultiTableInfoMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, size)) { tscError("0x%"PRIx64" malloc failed for payload to get table meta", pSql->self); tscFreeSqlObj(pNew); @@ -2540,14 +2715,16 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg } SMultiTableInfoMsg* pInfo = (SMultiTableInfoMsg*) pNew->cmd.payload; + pInfo->metaClone = metaClone? 1:0; pInfo->numOfTables = htonl((uint32_t) taosArrayGetSize(pNameList)); pInfo->numOfVgroups = htonl((uint32_t) taosArrayGetSize(pVgroupNameList)); + pInfo->numOfUdfs = htonl(numOfUdf); char* start = pInfo->tableNames; int32_t len = 0; for(int32_t i = 0; i < numOfTable; ++i) { char* name = taosArrayGetP(pNameList, i); - if (i < numOfTable - 1 || numOfVgroupList > 0) { + if (i < numOfTable - 1 || numOfVgroupList > 0 || numOfUdf > 0) { len = sprintf(start, "%s,", name); } else { len = sprintf(start, "%s", name); @@ -2558,7 +2735,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg for(int32_t i = 0; i < numOfVgroupList; ++i) { char* name = taosArrayGetP(pVgroupNameList, i); - if (i < numOfVgroupList - 1) { + if (i < numOfVgroupList - 1 || numOfUdf > 0) { len = sprintf(start, "%s,", name); } else { len = sprintf(start, "%s", name); @@ -2567,12 +2744,23 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg start += len; } + for(int32_t i = 0; i < numOfUdf; ++i) { + SUdfInfo * u = taosArrayGet(pUdfList, i); + if (i < numOfUdf - 1) { + len = sprintf(start, "%s,", u->name); + } else { + len = sprintf(start, "%s", u->name); + } + + start += len; + } + pNew->cmd.payloadLen = (int32_t) ((start - pInfo->tableNames) + sizeof(SMultiTableInfoMsg)); pNew->cmd.msgType = TSDB_MSG_TYPE_CM_TABLES_META; registerSqlObj(pNew); - tscDebug("0x%"PRIx64" new pSqlObj:0x%"PRIx64" to get %d tableMeta, vgroupInfo:%d, msg size:%d", pSql->self, - pNew->self, numOfTable, numOfVgroupList, pNew->cmd.payloadLen); + tscDebug("0x%"PRIx64" new pSqlObj:0x%"PRIx64" to get %d tableMeta, vgroupInfo:%d, udf:%d, msg size:%d", pSql->self, + pNew->self, numOfTable, numOfVgroupList, numOfUdf, pNew->cmd.payloadLen); pNew->fp = fp; pNew->param = (void *)pSql->self; @@ -2616,22 +2804,24 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool taosHashGetClone(tscTableMetaInfo, name, len, NULL, pTableMetaInfo->pTableMeta, -1); // TODO resize the tableMeta - char buf[80*1024] = {0}; - assert(size < 80*1024); + assert(size < 80 * TSDB_MAX_COLUMNS); + if (!pSql->pBuf) { + if (NULL == (pSql->pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + } STableMeta* pMeta = pTableMetaInfo->pTableMeta; if (pMeta->id.uid > 0) { // in case of child table, here only get the if (pMeta->tableType == TSDB_CHILD_TABLE) { - int32_t code = tscCreateTableMetaFromSTableMeta(pTableMetaInfo->pTableMeta, name, buf); + int32_t code = tscCreateTableMetaFromSTableMeta(pTableMetaInfo->pTableMeta, name, pSql->pBuf); if (code != TSDB_CODE_SUCCESS) { return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); } } - return TSDB_CODE_SUCCESS; } - return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); } @@ -2643,6 +2833,60 @@ int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool create return tscGetTableMetaImpl(pSql, pTableMetaInfo, createIfNotExists); } +int32_t tscGetUdfFromNode(SSqlObj *pSql, SQueryInfo* pQueryInfo) { + SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); + if (NULL == pNew) { + tscError("%p malloc failed for new sqlobj to get user-defined functions", pSql); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + pNew->pTscObj = pSql->pTscObj; + pNew->signature = pNew; + pNew->cmd.command = TSDB_SQL_RETRIEVE_FUNC; + + if (tscAddQueryInfo(&pNew->cmd) != TSDB_CODE_SUCCESS) { + tscError("%p malloc failed for new queryinfo", pSql); + tscFreeSqlObj(pNew); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + SQueryInfo *pNewQueryInfo = tscGetQueryInfo(&pNew->cmd); + + pNewQueryInfo->pUdfInfo = taosArrayInit(4, sizeof(SUdfInfo)); + for(int32_t i = 0; i < taosArrayGetSize(pQueryInfo->pUdfInfo); ++i) { + SUdfInfo info = {0}; + SUdfInfo* p1 = taosArrayGet(pQueryInfo->pUdfInfo, i); + info = *p1; + info.name = strdup(p1->name); + taosArrayPush(pNewQueryInfo->pUdfInfo, &info); + } + + pNew->cmd.active = pNewQueryInfo; + + if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE + pSql->cmd.payloadLen)) { + tscError("%p malloc failed for payload to get table meta", pSql); + tscFreeSqlObj(pNew); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + tscDebug("%p new pSqlObj:%p to retrieve udf", pSql, pNew); + registerSqlObj(pNew); + + pNew->fp = tscTableMetaCallBack; + pNew->param = (void *)pSql->self; + + tscDebug("%p metaRid from %" PRId64 " to %" PRId64 , pSql, pSql->metaRid, pNew->self); + + pSql->metaRid = pNew->self; + + int32_t code = tscBuildAndSendRequest(pNew, NULL); + if (code == TSDB_CODE_SUCCESS) { + code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; // notify application that current process needs to be terminated + } + + return code; +} + /** * retrieve table meta from mnode, and then update the local table meta hashmap. * @param pSql sql object @@ -2692,7 +2936,6 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, SQueryInfo* pQueryInfo) { if (allVgroupInfoRetrieved(pQueryInfo)) { return TSDB_CODE_SUCCESS; } - SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); pNew->pTscObj = pSql->pTscObj; pNew->signature = pNew; @@ -2744,6 +2987,7 @@ void tscInitMsgsFp() { tscBuildMsg[TSDB_SQL_CREATE_DB] = tscBuildCreateDbMsg; tscBuildMsg[TSDB_SQL_CREATE_USER] = tscBuildUserMsg; + tscBuildMsg[TSDB_SQL_CREATE_FUNCTION] = tscBuildCreateFuncMsg; tscBuildMsg[TSDB_SQL_CREATE_ACCT] = tscBuildAcctMsg; tscBuildMsg[TSDB_SQL_ALTER_ACCT] = tscBuildAcctMsg; @@ -2752,6 +2996,7 @@ void tscInitMsgsFp() { tscBuildMsg[TSDB_SQL_DROP_USER] = tscBuildDropUserAcctMsg; tscBuildMsg[TSDB_SQL_DROP_ACCT] = tscBuildDropUserAcctMsg; tscBuildMsg[TSDB_SQL_DROP_DB] = tscBuildDropDbMsg; + tscBuildMsg[TSDB_SQL_DROP_FUNCTION] = tscBuildDropFuncMsg; tscBuildMsg[TSDB_SQL_SYNC_DB_REPLICA] = tscBuildSyncDbReplicaMsg; tscBuildMsg[TSDB_SQL_DROP_TABLE] = tscBuildDropTableMsg; tscBuildMsg[TSDB_SQL_ALTER_USER] = tscBuildUserMsg; @@ -2767,6 +3012,7 @@ void tscInitMsgsFp() { tscBuildMsg[TSDB_SQL_USE_DB] = tscBuildUseDbMsg; // tscBuildMsg[TSDB_SQL_META] = tscBuildTableMetaMsg; tscBuildMsg[TSDB_SQL_STABLEVGROUP] = tscBuildSTableVgroupMsg; + tscBuildMsg[TSDB_SQL_RETRIEVE_FUNC] = tscBuildRetrieveFuncMsg; tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg; tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg; @@ -2785,6 +3031,7 @@ void tscInitMsgsFp() { tscProcessMsgRsp[TSDB_SQL_META] = tscProcessTableMetaRsp; tscProcessMsgRsp[TSDB_SQL_STABLEVGROUP] = tscProcessSTableVgroupRsp; tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiTableMetaRsp; + tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp; tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function. @@ -2814,3 +3061,4 @@ void tscInitMsgsFp() { tscKeepConn[TSDB_SQL_FETCH] = 1; tscKeepConn[TSDB_SQL_HB] = 1; } + diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 60261368f4c32d07a685d59c815fcc0b1d5af251..7675bded65bf75a860932e2ac15375c257493d5a 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -566,7 +566,7 @@ static bool tscKillQueryInDnode(SSqlObj* pSql) { SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - if ((pQueryInfo == NULL) || tscIsTwoStageSTableQuery(pQueryInfo, 0)) { + if ((pQueryInfo == NULL) || pQueryInfo->globalMerge) { return true; } @@ -679,7 +679,7 @@ static void tscKillSTableQuery(SSqlObj *pSql) { SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); - if (!tscIsTwoStageSTableQuery(pQueryInfo, 0)) { + if (!pQueryInfo->globalMerge) { return; } @@ -730,7 +730,7 @@ void taos_stop_query(TAOS_RES *res) { SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { + if (pQueryInfo->globalMerge) { assert(pSql->rpcRid <= 0); tscKillSTableQuery(pSql); } else { @@ -945,28 +945,35 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { return TSDB_CODE_TSC_DISCONNECTED; } - SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); - pSql->pTscObj = taos; - pSql->signature = pSql; - pSql->cmd.pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - int32_t length = (int32_t)strlen(tableNameList); + if (length == 0) { + return TSDB_CODE_SUCCESS; + } + if (length > MAX_TABLE_NAME_LENGTH) { - tscError("0x%"PRIx64" tableNameList too long, length:%d, maximum allowed:%d", pSql->self, length, MAX_TABLE_NAME_LENGTH); - tscFreeSqlObj(pSql); + tscError("tableNameList too long, length:%d, maximum allowed:%d", length, MAX_TABLE_NAME_LENGTH); return TSDB_CODE_TSC_INVALID_OPERATION; } char *str = calloc(1, length + 1); if (str == NULL) { - tscError("0x%"PRIx64" failed to allocate sql string buffer", pSql->self); - tscFreeSqlObj(pSql); + tscError("failed to allocate sql string buffer, size:%d", length); return TSDB_CODE_TSC_OUT_OF_MEMORY; } strtolower(str, tableNameList); SArray* plist = taosArrayInit(4, POINTER_BYTES); SArray* vgroupList = taosArrayInit(4, POINTER_BYTES); + if (plist == NULL || vgroupList == NULL) { + tfree(str); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); + tscAllocPayload(&pSql->cmd, 1024); + + pSql->pTscObj = taos; + pSql->signature = pSql; int32_t code = (uint8_t) tscTransferTableNameList(pSql, str, length, plist); free(str); @@ -976,10 +983,11 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { return code; } + pSql->cmd.pTableMetaMap = taosHashInit(taosArrayGetSize(plist), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); registerSqlObj(pSql); tscDebug("0x%"PRIx64" load multiple table meta, tableNameList: %s pObj:%p", pSql->self, tableNameList, pObj); - code = getMultiTableMetaFromMnode(pSql, plist, vgroupList, loadMultiTableMetaCallback); + code = getMultiTableMetaFromMnode(pSql, plist, vgroupList, NULL, loadMultiTableMetaCallback, false); if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { code = TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 8d87f54f054c3b99bc35b0c3f08db6af00c41007..b72bd78b1b81eb9acc908f38f0aa232207d07783 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -23,6 +23,7 @@ #include "tscSubquery.h" #include "qTableMeta.h" #include "tsclient.h" +#include "qUdf.h" #include "qUtil.h" #include "qPlan.h" @@ -32,7 +33,7 @@ typedef struct SInsertSupporter { } SInsertSupporter; static void freeJoinSubqueryObj(SSqlObj* pSql); -static bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql); +//static bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql); static int32_t tsCompare(int32_t order, int64_t left, int64_t right) { if (left == right) { @@ -711,6 +712,15 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, STimeWindow* win) { pQueryInfo->window = *win; } +int32_t tagValCompar(const void* p1, const void* p2) { + const STidTags* t1 = (const STidTags*) varDataVal(p1); + const STidTags* t2 = (const STidTags*) varDataVal(p2); + + __compar_fn_t func = getComparFunc(t1->padding, 0); + + return func(t1->tag, t2->tag); +} + int32_t tidTagsCompar(const void* p1, const void* p2) { const STidTags* t1 = (const STidTags*) (p1); const STidTags* t2 = (const STidTags*) (p2); @@ -719,28 +729,7 @@ int32_t tidTagsCompar(const void* p1, const void* p2) { return (t1->vgId > t2->vgId) ? 1 : -1; } - tstr* tag1 = (tstr*) t1->tag; - tstr* tag2 = (tstr*) t2->tag; - - if (tag1->len != tag2->len) { - return (tag1->len > tag2->len)? 1: -1; - } - - return strncmp(tag1->data, tag2->data, tag1->len); -} - -int32_t tagValCompar(const void* p1, const void* p2) { - const STidTags* t1 = (const STidTags*) varDataVal(p1); - const STidTags* t2 = (const STidTags*) varDataVal(p2); - - tstr* tag1 = (tstr*) t1->tag; - tstr* tag2 = (tstr*) t2->tag; - - if (tag1->len != tag2->len) { - return (tag1->len > tag2->len)? 1: -1; - } - - return memcmp(tag1->data, tag2->data, tag1->len); + return tagValCompar(p1, p2); } void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArray* tables) { @@ -870,6 +859,12 @@ static bool checkForDuplicateTagVal(SSchema* pColSchema, SJoinSupporter* p1, SSq return true; } +static void setTidTagType(SJoinSupporter* p, uint8_t type) { + for (int32_t i = 0; i < p->num; ++i) { + STidTags * tag = (STidTags*) varDataVal(p->pIdTagList + i * p->tagSize); + tag->padding = type; + } +} static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray* resList) { int16_t joinNum = pParentSql->subState.numOfSub; @@ -889,6 +884,8 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar for (int32_t i = 0; i < joinNum; i++) { SJoinSupporter* p = pParentSql->pSubs[i]->param; + setTidTagType(p, pColSchema->type); + ctxlist[i].p = p; ctxlist[i].res = taosArrayInit(p->num, size); @@ -1896,7 +1893,7 @@ int32_t tscCreateJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter int16_t type = 0; int32_t inter = 0; - getResultDataInfo(s->type, s->bytes, TSDB_FUNC_TID_TAG, 0, &type, &bytes, &inter, 0, 0); + getResultDataInfo(s->type, s->bytes, TSDB_FUNC_TID_TAG, 0, &type, &bytes, &inter, 0, 0, NULL); SSchema s1 = {.colId = s->colId, .type = (uint8_t)type, .bytes = bytes}; pSupporter->tagSize = s1.bytes; @@ -2295,6 +2292,7 @@ int32_t tscHandleFirstRoundStableQuery(SSqlObj *pSql) { SArray* pColList = pNewQueryInfo->colList; pNewQueryInfo->colList = NULL; + pNewQueryInfo->fillType = TSDB_FILL_NONE; tscClearSubqueryInfo(pCmd); tscFreeSqlResult(pSql); @@ -2438,9 +2436,9 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { tOrderDescriptor *pDesc = NULL; pRes->qId = 0x1; // hack the qhandle check - - const uint32_t nBufferSize = (1u << 16u); // 64KB - + + const uint32_t nBufferSize = (1u << 18u); // 256KB + SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); SSubqueryState *pState = &pSql->subState; @@ -2801,6 +2799,28 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p tscFreeRetrieveSup(pSql); + // set the command flag must be after the semaphore been correctly set. + if (pParentSql->cmd.command != TSDB_SQL_RETRIEVE_EMPTY_RESULT) { + pParentSql->cmd.command = TSDB_SQL_RETRIEVE_GLOBALMERGE; + + SQueryInfo *pQueryInfo2 = tscGetQueryInfo(&pParentSql->cmd); + + size_t size = tscNumOfExprs(pQueryInfo); + for (int32_t j = 0; j < size; ++j) { + SExprInfo* pExprInfo = tscExprGet(pQueryInfo2, j); + + int32_t functionId = pExprInfo->base.functionId; + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo2->pUdfInfo, -1 * functionId - 1); + code = initUdfInfo(pUdfInfo); + if (code != TSDB_CODE_SUCCESS) { + pParentSql->res.code = code; + tscAsyncResultOnError(pParentSql); + } + } + } + } + if (pParentSql->res.code == TSDB_CODE_SUCCESS) { (*pParentSql->fp)(pParentSql->param, pParentSql, 0); } else { @@ -3469,20 +3489,20 @@ static UNUSED_FUNC bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) { SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) { bool allSubqueryExhausted = true; - + for (int32_t i = 0; i < pSql->subState.numOfSub; ++i) { if (pSql->pSubs[i] == NULL) { continue; } - + SSqlRes *pRes1 = &pSql->pSubs[i]->res; SSqlCmd *pCmd1 = &pSql->pSubs[i]->cmd; - + SQueryInfo *pQueryInfo1 = tscGetQueryInfo(pCmd1); assert(pQueryInfo1->numOfTables == 1); - + STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo1, 0); - + /* * if the global limitation is not reached, and current result has not exhausted, or next more vnodes are * available, goes on @@ -3493,14 +3513,14 @@ static UNUSED_FUNC bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) { break; } } - + hasData = !allSubqueryExhausted; } else { // otherwise, in case inner join, if any subquery exhausted, query completed. for (int32_t i = 0; i < pSql->subState.numOfSub; ++i) { if (pSql->pSubs[i] == 0) { continue; } - + SSqlRes * pRes1 = &pSql->pSubs[i]->res; SQueryInfo *pQueryInfo1 = tscGetQueryInfo(&pSql->pSubs[i]->cmd); diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 87296c70559b8a8cf4e9d9c3ff7d6acb04da132e..7b8f24a093eb48f8a0f06b3b93f4fe1d33edcca5 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -28,6 +28,7 @@ #include "tconfig.h" #include "ttimezone.h" #include "tlocale.h" +#include "qScript.h" // global, not configurable #define TSC_VAR_NOT_RELEASE 1 @@ -148,6 +149,8 @@ void taos_init_imp(void) { taosInitNotes(); rpcInit(); + + scriptEnvPoolInit(); tscDebug("starting to initialize TAOS client ..."); tscDebug("Local End Point is:%s", tsLocalEp); } @@ -202,7 +205,9 @@ void taos_cleanup(void) { if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) { return; } - + if (tscEmbedded == 0) { + scriptEnvPoolCleanup(); + } taosHashCleanup(tscTableMetaInfo); tscTableMetaInfo = NULL; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 020b71d9b8a0e306fe08cbc87707ad50e82306c2..65e7dfec16dd67b150db20e252094467e7258a40 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -34,54 +34,54 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo); int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *len) { int32_t n = 0; - + switch (type) { case TSDB_DATA_TYPE_NULL: n = sprintf(str, "null"); break; - + case TSDB_DATA_TYPE_BOOL: n = sprintf(str, (*(int8_t*)buf) ? "true" : "false"); break; - + case TSDB_DATA_TYPE_TINYINT: n = sprintf(str, "%d", *(int8_t*)buf); break; - + case TSDB_DATA_TYPE_SMALLINT: n = sprintf(str, "%d", *(int16_t*)buf); break; - + case TSDB_DATA_TYPE_INT: n = sprintf(str, "%d", *(int32_t*)buf); break; - + case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: n = sprintf(str, "%" PRId64, *(int64_t*)buf); break; - + case TSDB_DATA_TYPE_FLOAT: n = sprintf(str, "%f", GET_FLOAT_VAL(buf)); break; - + case TSDB_DATA_TYPE_DOUBLE: n = sprintf(str, "%f", GET_DOUBLE_VAL(buf)); break; - + case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: if (bufSize < 0) { tscError("invalid buf size"); return TSDB_CODE_TSC_INVALID_VALUE; } - + *str = '"'; memcpy(str + 1, buf, bufSize); *(str + bufSize + 1) = '"'; n = bufSize + 2; break; - + default: tscError("unsupported type:%d", type); return TSDB_CODE_TSC_INVALID_VALUE; @@ -216,6 +216,15 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { for (int32_t i = 0; i < numOfExprs; ++i) { int32_t functionId = tscExprGet(pQueryInfo, i)->base.functionId; + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1); + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + return false; + } + + continue; + } + if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG && @@ -266,6 +275,16 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) { f != TSDB_FUNC_DERIVATIVE) { return false; } + + if (f < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * f - 1); + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + return false; + } + + continue; + } + } return true; @@ -338,6 +357,10 @@ bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo) { } } + if (tscIsProjectionQuery(pQueryInfo)) { + return false; + } + return false; } @@ -526,6 +549,15 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) { } int32_t functionId = pExpr->base.functionId; + if (functionId < 0) { + SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1); + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + return true; + } + + continue; + } + if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY) { continue; } @@ -1186,7 +1218,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue SOperatorInfo* pSourceOperator = createDummyInputOperator(pSqlObjList[0], pSchema, numOfCol1, pFilterInfo, numOfFilterCols); pOutput->precision = pSqlObjList[0]->res.precision; - + SSchema* schema = NULL; if (px->numOfTables > 1) { SOperatorInfo** p = calloc(px->numOfTables, POINTER_BYTES); @@ -1302,6 +1334,12 @@ void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeMeta) { tfree(pUpQueryInfo); } + if (pQueryInfo->udfCopy) { + pQueryInfo->pUdfInfo = taosArrayDestroy(pQueryInfo->pUdfInfo); + } else { + pQueryInfo->pUdfInfo = tscDestroyUdfArrayList(pQueryInfo->pUdfInfo); + } + freeQueryInfoImpl(pQueryInfo); clearAllTableMetaInfo(pQueryInfo, removeMeta); @@ -1450,6 +1488,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { pSql->signature = NULL; pSql->fp = NULL; tfree(pSql->sqlstr); + tfree(pSql->pBuf); tfree(pSql->pSubs); pSql->subState.numOfSub = 0; @@ -1461,7 +1500,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { memset(pCmd->payload, 0, (size_t)pCmd->allocSize); tfree(pCmd->payload); pCmd->allocSize = 0; - + tsem_destroy(&pSql->rspSem); memset(pSql, 0, sizeof(*pSql)); free(pSql); @@ -1470,6 +1509,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo) { tfree(pColInfo->boundedColumns); tfree(pColInfo->cols); + tfree(pColInfo->colIdxInfo); } void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) { @@ -1539,6 +1579,47 @@ void* tscDestroyBlockArrayList(SArray* pDataBlockList) { return NULL; } + +void freeUdfInfo(SUdfInfo* pUdfInfo) { + if (pUdfInfo == NULL) { + return; + } + + if (pUdfInfo->funcs[TSDB_UDF_FUNC_DESTROY]) { + (*(udfDestroyFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_DESTROY])(&pUdfInfo->init); + } + + tfree(pUdfInfo->name); + + if (pUdfInfo->path) { + unlink(pUdfInfo->path); + } + + tfree(pUdfInfo->path); + + tfree(pUdfInfo->content); + + taosCloseDll(pUdfInfo->handle); +} + + +void* tscDestroyUdfArrayList(SArray* pUdfList) { + if (pUdfList == NULL) { + return NULL; + } + + size_t size = taosArrayGetSize(pUdfList); + for (int32_t i = 0; i < size; i++) { + SUdfInfo* udf = taosArrayGet(pUdfList, i); + freeUdfInfo(udf); + } + + taosArrayDestroy(pUdfList); + return NULL; +} + + + void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable, bool removeMeta) { if (pBlockHashTable == NULL) { return NULL; @@ -1689,11 +1770,107 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i return TSDB_CODE_SUCCESS; } -static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bool includeSchema) { +static SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) { + SSchema* pSchema = pBuilder->pSchema; + char* p = (char*)pBuilder->buf; + int toffset = 0; + uint16_t nCols = pBuilder->nCols; + + uint8_t memRowType = payloadType(p); + uint16_t nColsBound = payloadNCols(p); + if (pBuilder->nCols <= 0 || nColsBound <= 0) { + return NULL; + } + char* pVals = POINTER_SHIFT(p, payloadValuesOffset(p)); + SMemRow* memRow = (SMemRow)pBuilder->pDataBlock; + memRowSetType(memRow, memRowType); + + // ----------------- Raw payload structure for row: + /* |<------------ Head ------------->|<----------- body of column data tuple ------------------->| + * | |<----------------- flen ------------->|<--- value part --->| + * |SMemRowType| dataTLen | nCols | colId | colType | offset | ... | value |...|...|... | + * +-----------+----------+----------+--------------------------------------|--------------------| + * | uint8_t | uint32_t | uint16_t | int16_t | uint8_t | uint16_t | ... |.......|...|...|... | + * +-----------+----------+----------+--------------------------------------+--------------------| + * 1. offset in column data tuple starts from the value part in case of uint16_t overflow. + * 2. dataTLen: total length including the header and body. + */ + + if (memRowType == SMEM_ROW_DATA) { + SDataRow trow = (SDataRow)memRowDataBody(memRow); + dataRowSetLen(trow, (TDRowLenT)(TD_DATA_ROW_HEAD_SIZE + pBuilder->flen)); + dataRowSetVersion(trow, pBuilder->sversion); + + p = (char*)payloadBody(pBuilder->buf); + uint16_t i = 0, j = 0; + while (j < nCols) { + if (i >= nColsBound) { + break; + } + int16_t colId = payloadColId(p); + if (colId == pSchema[j].colId) { + // ASSERT(payloadColType(p) == pSchema[j].type); + tdAppendColVal(trow, POINTER_SHIFT(pVals, payloadColOffset(p)), pSchema[j].type, toffset); + toffset += TYPE_BYTES[pSchema[j].type]; + p = payloadNextCol(p); + ++i; + ++j; + } else if (colId < pSchema[j].colId) { + p = payloadNextCol(p); + ++i; + } else { + tdAppendColVal(trow, tdGetNullVal(pSchema[j].type), pSchema[j].type, toffset); + toffset += TYPE_BYTES[pSchema[j].type]; + ++j; + } + } + + while (j < nCols) { + tdAppendColVal(trow, tdGetNullVal(pSchema[j].type), pSchema[j].type, toffset); + toffset += TYPE_BYTES[pSchema[j].type]; + ++j; + } + + #if 0 // no need anymore + while (i < nColsBound) { + p = payloadNextCol(p); + ++i; + } + #endif + + } else if (memRowType == SMEM_ROW_KV) { + SKVRow kvRow = (SKVRow)memRowKvBody(memRow); + kvRowSetLen(kvRow, (TDRowLenT)(TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nColsBound)); + kvRowSetNCols(kvRow, nColsBound); + memRowSetKvVersion(memRow, pBuilder->sversion); + + p = (char*)payloadBody(pBuilder->buf); + int i = 0; + while (i < nColsBound) { + int16_t colId = payloadColId(p); + uint8_t colType = payloadColType(p); + tdAppendKvColVal(kvRow, POINTER_SHIFT(pVals,payloadColOffset(p)), colId, colType, toffset); + toffset += sizeof(SColIdx); + p = payloadNextCol(p); + ++i; + } + + } else { + ASSERT(0); + } + int32_t rowTLen = memRowTLen(memRow); + pBuilder->pDataBlock = (char*)pBuilder->pDataBlock + rowTLen; // next row + pBuilder->pSubmitBlk->dataLen += rowTLen; + + return memRow; +} + +// Erase the empty space reserved for binary data +static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bool includeSchema, SBlockKeyTuple *blkKeyTuple) { // TODO: optimize this function, handle the case while binary is not presented - STableMeta* pTableMeta = pTableDataBlock->pTableMeta; - STableComInfo tinfo = tscGetTableInfo(pTableMeta); - SSchema* pSchema = tscGetTableSchema(pTableMeta); + STableMeta* pTableMeta = pTableDataBlock->pTableMeta; + STableComInfo tinfo = tscGetTableInfo(pTableMeta); + SSchema* pSchema = tscGetTableSchema(pTableMeta); SSubmitBlk* pBlock = pDataBlock; memcpy(pDataBlock, pTableDataBlock->pData, sizeof(SSubmitBlk)); @@ -1728,21 +1905,19 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo char* p = pTableDataBlock->pData + sizeof(SSubmitBlk); pBlock->dataLen = 0; int32_t numOfRows = htons(pBlock->numOfRows); - - for (int32_t i = 0; i < numOfRows; ++i) { - SDataRow trow = (SDataRow) pDataBlock; - dataRowSetLen(trow, (uint16_t)(TD_DATA_ROW_HEAD_SIZE + flen)); - dataRowSetVersion(trow, pTableMeta->sversion); - int toffset = 0; - for (int32_t j = 0; j < tinfo.numOfColumns; j++) { - tdAppendColVal(trow, p, pSchema[j].type, pSchema[j].bytes, toffset); - toffset += TYPE_BYTES[pSchema[j].type]; - p += pSchema[j].bytes; - } + SMemRowBuilder rowBuilder; + rowBuilder.pSchema = pSchema; + rowBuilder.sversion = pTableMeta->sversion; + rowBuilder.flen = flen; + rowBuilder.nCols = tinfo.numOfColumns; + rowBuilder.pDataBlock = pDataBlock; + rowBuilder.pSubmitBlk = pBlock; + rowBuilder.buf = p; - pDataBlock = (char*)pDataBlock + dataRowLen(trow); - pBlock->dataLen += dataRowLen(trow); + for (int32_t i = 0; i < numOfRows; ++i) { + rowBuilder.buf = (blkKeyTuple + i)->payloadAddr; + tdGenMemRowFromBuilder(&rowBuilder); } int32_t len = pBlock->dataLen + pBlock->schemaLen; @@ -1753,7 +1928,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo } static int32_t getRowExpandSize(STableMeta* pTableMeta) { - int32_t result = TD_DATA_ROW_HEAD_SIZE; + int32_t result = TD_MEM_ROW_DATA_HEAD_SIZE; int32_t columns = tscGetNumOfColumns(pTableMeta); SSchema* pSchema = tscGetTableSchema(pTableMeta); for(int32_t i = 0; i < columns; i++) { @@ -1786,14 +1961,17 @@ static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeB } int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBlockMap) { - const int INSERT_HEAD_SIZE = sizeof(SMsgDesc) + sizeof(SSubmitMsg); - - void* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); - SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES); + const int INSERT_HEAD_SIZE = sizeof(SMsgDesc) + sizeof(SSubmitMsg); + int code = 0; + void* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); + SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES); STableDataBlocks** p = taosHashIterate(pInsertParam->pTableBlockHashList, NULL); STableDataBlocks* pOneTableBlock = *p; + + SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock + while(pOneTableBlock) { SSubmitBlk* pBlocks = (SSubmitBlk*) pOneTableBlock->pData; if (pBlocks->numOfRows > 0) { @@ -1807,6 +1985,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl tscError("0x%"PRIx64" failed to prepare the data block buffer for merging table data, code:%d", pInsertParam->objectId, ret); taosHashCleanup(pVnodeDataBlockHashList); tscDestroyBlockArrayList(pVnodeDataBlockList); + tfree(blkKeyInfo.pKeyTuple); return ret; } @@ -1825,16 +2004,26 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl taosHashCleanup(pVnodeDataBlockHashList); tscDestroyBlockArrayList(pVnodeDataBlockList); tfree(dataBuf->pData); + tfree(blkKeyInfo.pKeyTuple); return TSDB_CODE_TSC_OUT_OF_MEMORY; } } - tscSortRemoveDataBlockDupRows(pOneTableBlock); - char* ekey = (char*)pBlocks->data + pOneTableBlock->rowSize*(pBlocks->numOfRows-1); + if ((code = tscSortRemoveDataBlockDupRows(pOneTableBlock, &blkKeyInfo)) != 0) { + taosHashCleanup(pVnodeDataBlockHashList); + tscDestroyBlockArrayList(pVnodeDataBlockList); + tfree(dataBuf->pData); + tfree(blkKeyInfo.pKeyTuple); + return code; + } + + ASSERT(blkKeyInfo.pKeyTuple != NULL && pBlocks->numOfRows > 0); - tscDebug("0x%"PRIx64" name:%s, tid:%d rows:%d sversion:%d skey:%" PRId64 ", ekey:%" PRId64, pInsertParam->objectId, tNameGetTableName(&pOneTableBlock->tableName), - pBlocks->tid, pBlocks->numOfRows, pBlocks->sversion, GET_INT64_VAL(pBlocks->data), GET_INT64_VAL(ekey)); + SBlockKeyTuple* pLastKeyTuple = blkKeyInfo.pKeyTuple + pBlocks->numOfRows - 1; + tscDebug("0x%" PRIx64 " name:%s, tid:%d rows:%d sversion:%d skey:%" PRId64 ", ekey:%" PRId64, + pInsertParam->objectId, tNameGetTableName(&pOneTableBlock->tableName), pBlocks->tid, pBlocks->numOfRows, + pBlocks->sversion, blkKeyInfo.pKeyTuple->skey, pLastKeyTuple->skey); int32_t len = pBlocks->numOfRows * (pOneTableBlock->rowSize + expandSize) + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta); @@ -1845,7 +2034,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl pBlocks->schemaLen = 0; // erase the empty space reserved for binary data - int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, pInsertParam->schemaAttached); + int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, pInsertParam->schemaAttached, blkKeyInfo.pKeyTuple); assert(finalLen <= len); dataBuf->size += (finalLen + sizeof(SSubmitBlk)); @@ -1873,6 +2062,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl // free the table data blocks; pInsertParam->pDataBlocks = pVnodeDataBlockList; taosHashCleanup(pVnodeDataBlockHashList); + tfree(blkKeyInfo.pKeyTuple); return TSDB_CODE_SUCCESS; } @@ -2128,7 +2318,7 @@ void tscFieldInfoCopy(SFieldInfo* pFieldInfo, const SFieldInfo* pSrc, const SArr assert(pfield->pExpr->pExpr != NULL); p.pExpr = calloc(1, sizeof(SExprInfo)); tscExprAssign(p.pExpr, pfield->pExpr); - } + } taosArrayPush(pFieldInfo->internalField, &p); } @@ -2989,7 +3179,7 @@ int32_t tscQueryInfoCopy(SQueryInfo* pQueryInfo, const SQueryInfo* pSrc) { pQueryInfo->fillVal = NULL; pQueryInfo->numOfFillVal = 0;; pQueryInfo->clauseLimit = pSrc->clauseLimit; - pQueryInfo->prjOffset = pSrc->prjOffset; + pQueryInfo->prjOffset = pSrc->prjOffset; pQueryInfo->numOfTables = 0; pQueryInfo->window = pSrc->window; pQueryInfo->sessionWindow = pSrc->sessionWindow; @@ -3060,6 +3250,14 @@ int32_t tscQueryInfoCopy(SQueryInfo* pQueryInfo, const SQueryInfo* pSrc) { tscAddTableMetaInfo(pQueryInfo, &p1->name, pMeta, p1->vgroupList, p1->tagColList, p1->pVgroupTables); } + SArray *pUdfInfo = NULL; + if (pSrc->pUdfInfo) { + pUdfInfo = taosArrayDup(pSrc->pUdfInfo); + } + + pQueryInfo->pUdfInfo = pUdfInfo; + pQueryInfo->udfCopy = true; + _error: return code; } @@ -3106,7 +3304,9 @@ void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo) { info->vgInfo.epAddr[j].fqdn = strdup(pInfo->vgInfo.epAddr[j].fqdn); } - info->itemList = taosArrayDup(pInfo->itemList); + if (pInfo->itemList) { + info->itemList = taosArrayDup(pInfo->itemList); + } } SArray* tscVgroupTableInfoDup(SArray* pVgroupTables) { @@ -3357,6 +3557,11 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t SQueryInfo* pNewQueryInfo = tscGetQueryInfo(pnCmd); + if (pQueryInfo->pUdfInfo) { + pNewQueryInfo->pUdfInfo = taosArrayDup(pQueryInfo->pUdfInfo); + pNewQueryInfo->udfCopy = true; + } + pNewQueryInfo->command = pQueryInfo->command; pnCmd->active = pNewQueryInfo; @@ -3376,6 +3581,7 @@ 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; @@ -4218,7 +4424,7 @@ int32_t createProjectionExpr(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaI int32_t inter = 0; getResultDataInfo(pSource->base.colType, pSource->base.colBytes, functionId, 0, &pse->resType, - &pse->resBytes, &inter, 0, false); + &pse->resBytes, &inter, 0, false, NULL); pse->colType = pse->resType; pse->colBytes = pse->resBytes; @@ -4285,8 +4491,14 @@ static int32_t createGlobalAggregateExpr(SQueryAttr* pQueryAttr, SQueryInfo* pQu functionId = TSDB_FUNC_STDDEV; } + SUdfInfo* pUdfInfo = NULL; + + if (functionId < 0) { + pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1); + } + getResultDataInfo(pExpr->base.colType, pExpr->base.colBytes, functionId, 0, &pse->resType, &pse->resBytes, &inter, - 0, false); + 0, false, pUdfInfo); } } @@ -4362,7 +4574,8 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->order = pQueryInfo->order; pQueryAttr->fillType = pQueryInfo->fillType; pQueryAttr->havingNum = pQueryInfo->havingFieldNum; - + pQueryAttr->pUdfInfo = pQueryInfo->pUdfInfo; + if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor pQueryAttr->window = pQueryInfo->window; } else { @@ -4474,8 +4687,13 @@ static int32_t doAddTableName(char* nextStr, char** str, SArray* pNameArray, SSq strncpy(tablename, *str, TSDB_TABLE_FNAME_LEN); len = (int32_t) strlen(tablename); } else { - memcpy(tablename, *str, nextStr - (*str)); len = (int32_t)(nextStr - (*str)); + if (len >= TSDB_TABLE_NAME_LEN) { + sprintf(pCmd->payload, "table name too long"); + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + memcpy(tablename, *str, nextStr - (*str)); tablename[len] = '\0'; } @@ -4487,9 +4705,8 @@ static int32_t doAddTableName(char* nextStr, char** str, SArray* pNameArray, SSq // Check if the table name available or not if (tscValidateName(&sToken) != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; sprintf(pCmd->payload, "table name is invalid"); - return code; + return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; } SName name = {0}; @@ -4505,6 +4722,15 @@ static int32_t doAddTableName(char* nextStr, char** str, SArray* pNameArray, SSq return TSDB_CODE_SUCCESS; } +int32_t nameComparFn(const void* n1, const void* n2) { + int32_t ret = strcmp(*(char**)n1, *(char**)n2); + if (ret == 0) { + return 0; + } else { + return ret > 0? 1:-1; + } +} + int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t length, SArray* pNameArray) { SSqlCmd *pCmd = &pSql->cmd; @@ -4540,12 +4766,44 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt } } - if (taosArrayGetSize(pNameArray) > TSDB_MULTI_TABLEMETA_MAX_NUM) { + size_t len = taosArrayGetSize(pNameArray); + if (len == 1) { + return TSDB_CODE_SUCCESS; + } + + if (len > TSDB_MULTI_TABLEMETA_MAX_NUM) { code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; sprintf(pCmd->payload, "tables over the max number"); return code; } + taosArraySort(pNameArray, nameComparFn); + + int32_t pos = 0; + for(int32_t i = 1; i < len; ++i) { + char** p1 = taosArrayGet(pNameArray, pos); + char** p2 = taosArrayGet(pNameArray, i); + + if (strcmp(*p1, *p2) == 0) { + // do nothing + } else { + if (pos + 1 != i) { + char* p = taosArrayGetP(pNameArray, pos + 1); + tfree(p); + taosArraySet(pNameArray, pos + 1, p2); + pos += 1; + } else { + pos += 1; + } + } + } + + for(int32_t i = pos + 1; i < pNameArray->size; ++i) { + char* p = taosArrayGetP(pNameArray, i); + tfree(p); + } + + pNameArray->size = pos + 1; return TSDB_CODE_SUCCESS; } diff --git a/src/common/inc/tcmdtype.h b/src/common/inc/tcmdtype.h index 4331ddbf8923ee758ebaf3116740db8e24df29a9..bd2c2e46f8546eb74bb32f1ef007aada14a397a0 100644 --- a/src/common/inc/tcmdtype.h +++ b/src/common/inc/tcmdtype.h @@ -41,8 +41,10 @@ enum { TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MGMT, "mgmt" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_DB, "create-db" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_TABLE, "create-table" ) + TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_FUNCTION, "create-function" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_DB, "drop-db" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_TABLE, "drop-table" ) + TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_FUNCTION, "drop-function" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_ACCT, "create-acct" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_USER, "create-user" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_ACCT, "drop-acct" ) @@ -74,6 +76,7 @@ enum { TSDB_DEFINE_SQL_TYPE( TSDB_SQL_STABLEVGROUP, "stable-vgroup" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MULTI_META, "multi-meta" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_HB, "heart-beat" ) + TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_FUNC, "retrieve-function" ) // SQL below for client local TSDB_DEFINE_SQL_TYPE( TSDB_SQL_LOCAL, "local" ) diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index e3989a1deb5fa4817bd459916ad238e58a88577b..22f721d9e0eeec24a782fff4e785828e9ee0d21b 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -24,6 +24,35 @@ extern "C" { #endif +#pragma pack(push, 1) +typedef struct { + VarDataLenT len; + uint8_t data; +} SBinaryNullT; + +typedef struct { + VarDataLenT len; + uint32_t data; +} SNCharNullT; +#pragma pack(pop) + +extern const uint8_t BoolNull; +extern const uint8_t TinyintNull; +extern const uint16_t SmallintNull; +extern const uint32_t IntNull; +extern const uint64_t BigintNull; +extern const uint64_t TimestampNull; +extern const uint8_t UTinyintNull; +extern const uint16_t USmallintNull; +extern const uint32_t UIntNull; +extern const uint64_t UBigintNull; +extern const uint32_t FloatNull; +extern const uint64_t DoubleNull; +extern const SBinaryNullT BinaryNull; +extern const SNCharNullT NcharNull; + +const void *tdGetNullVal(int8_t type); + #define STR_TO_VARSTR(x, str) \ do { \ VarDataLenT __len = (VarDataLenT)strlen(str); \ @@ -31,6 +60,14 @@ extern "C" { memcpy(varDataVal(x), (str), __len); \ } while (0); +#define STR_TO_NET_VARSTR(x, str) \ + do { \ + VarDataLenT __len = (VarDataLenT)strlen(str); \ + *(VarDataLenT *)(x) = htons(__len); \ + memcpy(varDataVal(x), (str), __len); \ + } while (0); + + #define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \ do { \ char *_e = stpncpy(varDataVal(x), (str), (_maxs)-VARSTR_HEADER_SIZE); \ @@ -45,10 +82,10 @@ extern "C" { // ----------------- TSDB COLUMN DEFINITION typedef struct { - int8_t type; // Column type - int16_t colId; // column ID - int16_t bytes; // column bytes - int16_t offset; // point offset in SDataRow after the header part + int8_t type; // Column type + int16_t colId; // column ID + uint16_t bytes; // column bytes + uint16_t offset; // point offset in SDataRow after the header part. } STColumn; #define colType(col) ((col)->type) @@ -159,10 +196,11 @@ static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) { return 0; } } + // ----------------- Data row structure /* A data row, the format is like below: - * |<--------------------+--------------------------- len ---------------------------------->| + * |<------------------------------------------------ len ---------------------------------->| * |<-- Head -->|<--------- flen -------------->| | * +---------------------+---------------------------------+---------------------------------+ * | uint16_t | int16_t | | | @@ -176,8 +214,8 @@ typedef void *SDataRow; #define TD_DATA_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t)) -#define dataRowLen(r) (*(uint16_t *)(r)) -#define dataRowVersion(r) *(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)) +#define dataRowLen(r) (*(TDRowLenT *)(r)) // 0~65535 +#define dataRowVersion(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t))) #define dataRowTuple(r) POINTER_SHIFT(r, TD_DATA_ROW_HEAD_SIZE) #define dataRowTKey(r) (*(TKEY *)(dataRowTuple(r))) #define dataRowKey(r) tdGetKey(dataRowTKey(r)) @@ -193,20 +231,19 @@ void tdInitDataRow(SDataRow row, STSchema *pSchema); SDataRow tdDataRowDup(SDataRow row); // offset here not include dataRow header length -static FORCE_INLINE int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_t offset) { +static FORCE_INLINE int tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) { ASSERT(value != NULL); int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE; - char * ptr = (char *)POINTER_SHIFT(row, dataRowLen(row)); if (IS_VAR_DATA_TYPE(type)) { *(VarDataOffsetT *)POINTER_SHIFT(row, toffset) = dataRowLen(row); - memcpy(ptr, value, varDataTLen(value)); + memcpy(POINTER_SHIFT(row, dataRowLen(row)), value, varDataTLen(value)); dataRowLen(row) += varDataTLen(value); } else { if (offset == 0) { ASSERT(type == TSDB_DATA_TYPE_TIMESTAMP); TKEY tvalue = tdGetTKEY(*(TSKEY *)value); - memcpy(POINTER_SHIFT(row, toffset), (void *)(&tvalue), TYPE_BYTES[type]); + memcpy(POINTER_SHIFT(row, toffset), (const void *)(&tvalue), TYPE_BYTES[type]); } else { memcpy(POINTER_SHIFT(row, toffset), value, TYPE_BYTES[type]); } @@ -237,17 +274,21 @@ typedef struct SDataCol { TSKEY ts; // only used in last NULL column } SDataCol; +#define isAllRowsNull(pCol) ((pCol)->len == 0) static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; } void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints); -void dataColAppendVal(SDataCol *pCol, void *value, int numOfRows, int maxPoints); +void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints); void dataColSetOffset(SDataCol *pCol, int nEle); bool isNEleNull(SDataCol *pCol, int nEle); void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints); // Get the data pointer from a column-wised data -static FORCE_INLINE void *tdGetColDataOfRow(SDataCol *pCol, int row) { +static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int row) { + if (isAllRowsNull(pCol)) { + return tdGetNullVal(pCol->type); + } if (IS_VAR_DATA_TYPE(pCol->type)) { return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]); } else { @@ -279,7 +320,7 @@ typedef struct { } SDataCols; #define keyCol(pCols) (&((pCols)->cols[0])) // Key column -#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)] +#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)] // the idx row of column-wised data #define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx)) static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) { if (pCols->numOfRows) { @@ -323,13 +364,13 @@ void tdResetDataCols(SDataCols *pCols); int tdInitDataCols(SDataCols *pCols, STSchema *pSchema); SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData); SDataCols *tdFreeDataCols(SDataCols *pCols); -void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols); int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset); // ----------------- K-V data row structure -/* +/* |<-------------------------------------- len -------------------------------------------->| + * |<----- header ----->|<--------------------------- body -------------------------------->| * +----------+----------+---------------------------------+---------------------------------+ - * | int16_t | int16_t | | | + * | uint16_t | int16_t | | | * +----------+----------+---------------------------------+---------------------------------+ * | len | ncols | cols index | data part | * +----------+----------+---------------------------------+---------------------------------+ @@ -337,14 +378,14 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge typedef void *SKVRow; typedef struct { - int16_t colId; - int16_t offset; + int16_t colId; + uint16_t offset; } SColIdx; -#define TD_KV_ROW_HEAD_SIZE (2 * sizeof(int16_t)) +#define TD_KV_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t)) -#define kvRowLen(r) (*(int16_t *)(r)) -#define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t))) +#define kvRowLen(r) (*(TDRowLenT *)(r)) +#define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(uint16_t))) #define kvRowSetLen(r, len) kvRowLen(r) = (len) #define kvRowSetNCols(r, n) kvRowNCols(r) = (n) #define kvRowColIdx(r) (SColIdx *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE) @@ -354,6 +395,9 @@ typedef struct { #define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i)) #define kvRowFree(r) tfree(r) #define kvRowEnd(r) POINTER_SHIFT(r, kvRowLen(r)) +#define kvRowTKey(r) (*(TKEY *)(kvRowValues(r))) +#define kvRowKey(r) tdGetKey(kvRowTKey(r)) +#define kvRowDeleted(r) TKEY_IS_DELETED(kvRowTKey(r)) SKVRow tdKVRowDup(SKVRow row); int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value); @@ -377,13 +421,44 @@ static FORCE_INLINE void *tdGetKVRowValOfCol(SKVRow row, int16_t colId) { return kvRowColVal(row, (SColIdx *)ret); } +static FORCE_INLINE void *tdGetKVRowIdxOfCol(SKVRow row, int16_t colId) { + return taosbsearch(&colId, kvRowColIdx(row), kvRowNCols(row), sizeof(SColIdx), comparTagId, TD_EQ); +} + +// offset here not include kvRow header length +static FORCE_INLINE int tdAppendKvColVal(SKVRow row, const void *value, int16_t colId, int8_t type, int32_t offset) { + ASSERT(value != NULL); + int32_t toffset = offset + TD_KV_ROW_HEAD_SIZE; + SColIdx *pColIdx = (SColIdx *)POINTER_SHIFT(row, toffset); + char * ptr = (char *)POINTER_SHIFT(row, kvRowLen(row)); + + pColIdx->colId = colId; + pColIdx->offset = kvRowLen(row); // offset of pColIdx including the TD_KV_ROW_HEAD_SIZE + + if (IS_VAR_DATA_TYPE(type)) { + memcpy(ptr, value, varDataTLen(value)); + kvRowLen(row) += varDataTLen(value); + } else { + if (offset == 0) { + ASSERT(type == TSDB_DATA_TYPE_TIMESTAMP); + TKEY tvalue = tdGetTKEY(*(TSKEY *)value); + memcpy(ptr, (void *)(&tvalue), TYPE_BYTES[type]); + } else { + memcpy(ptr, value, TYPE_BYTES[type]); + } + kvRowLen(row) += TYPE_BYTES[type]; + } + + return 0; +} + // ----------------- K-V data row builder typedef struct { int16_t tCols; int16_t nCols; SColIdx *pColIdx; - int16_t alloc; - int16_t size; + uint16_t alloc; + uint16_t size; void * buf; } SKVRowBuilder; @@ -419,8 +494,146 @@ static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, return 0; } +// ----------------- SMemRow appended with sequential data row structure +/* + * |---------|------------------------------------------------- len ---------------------------------->| + * |<-------- Head ------>|<--------- flen -------------->| | + * |---------+---------------------+---------------------------------+---------------------------------+ + * | uint8_t | uint16_t | int16_t | | | + * |---------+----------+----------+---------------------------------+---------------------------------+ + * | flag | len | sversion | First part | Second part | + * +---------+----------+----------+---------------------------------+---------------------------------+ + * + * NOTE: timestamp in this row structure is TKEY instead of TSKEY + */ + +// ----------------- SMemRow appended with extended K-V data row structure +/* |--------------------|------------------------------------------------ len ---------------------------------->| + * |<------------- Head ------------>|<--------- flen -------------->| | + * |--------------------+----------+--------------------------------------------+---------------------------------+ + * | uint8_t | int16_t | uint16_t | int16_t | | | + * |---------+----------+----------+----------+---------------------------------+---------------------------------+ + * | flag | sversion | len | ncols | cols index | data part | + * |---------+----------+----------+----------+---------------------------------+---------------------------------+ + */ + +typedef void *SMemRow; + +#define TD_MEM_ROW_TYPE_SIZE sizeof(uint8_t) +#define TD_MEM_ROW_KV_VER_SIZE sizeof(int16_t) +#define TD_MEM_ROW_KV_TYPE_VER_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_MEM_ROW_KV_VER_SIZE) +#define TD_MEM_ROW_DATA_HEAD_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_DATA_ROW_HEAD_SIZE) +// #define TD_MEM_ROW_KV_HEAD_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_MEM_ROW_KV_VER_SIZE + TD_KV_ROW_HEAD_SIZE) + +#define SMEM_ROW_DATA 0U // SDataRow +#define SMEM_ROW_KV 1U // SKVRow + +#define memRowType(r) (*(uint8_t *)(r)) +#define isDataRow(r) (SMEM_ROW_DATA == memRowType(r)) +#define isKvRow(r) (SMEM_ROW_KV == memRowType(r)) + +#define memRowDataBody(r) POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE) // section after flag +#define memRowKvBody(r) \ + POINTER_SHIFT(r, TD_MEM_ROW_KV_TYPE_VER_SIZE) // section after flag + sversion as to reuse SKVRow + +#define memRowDataLen(r) (*(TDRowLenT *)memRowDataBody(r)) // 0~65535 +#define memRowKvLen(r) (*(TDRowLenT *)memRowKvBody(r)) // 0~65535 + +#define memRowDataTLen(r) \ + ((TDRowTLenT)(memRowDataLen(r) + TD_MEM_ROW_TYPE_SIZE)) // using uint32_t/int32_t to store the TLen + +#define memRowKvTLen(r) ((TDRowTLenT)(memRowKvLen(r) + TD_MEM_ROW_KV_TYPE_VER_SIZE)) + +#define memRowLen(r) (isDataRow(r) ? memRowDataLen(r) : memRowKvLen(r)) +#define memRowTLen(r) (isDataRow(r) ? memRowDataTLen(r) : memRowKvTLen(r)) // using uint32_t/int32_t to store the TLen + +#define memRowDataVersion(r) dataRowVersion(memRowDataBody(r)) +#define memRowKvVersion(r) (*(int16_t *)POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE)) +#define memRowVersion(r) (isDataRow(r) ? memRowDataVersion(r) : memRowKvVersion(r)) // schema version +#define memRowSetKvVersion(r, v) (memRowKvVersion(r) = (v)) +#define memRowTuple(r) (isDataRow(r) ? dataRowTuple(memRowDataBody(r)) : kvRowValues(memRowKvBody(r))) + +#define memRowTKey(r) (isDataRow(r) ? dataRowTKey(memRowDataBody(r)) : kvRowTKey(memRowKvBody(r))) +#define memRowKey(r) (isDataRow(r) ? dataRowKey(memRowDataBody(r)) : kvRowKey(memRowKvBody(r))) +#define memRowSetTKey(r, k) \ + do { \ + if (isDataRow(r)) { \ + dataRowTKey(memRowDataBody(r)) = (k); \ + } else { \ + kvRowTKey(memRowKvBody(r)) = (k); \ + } \ + } while (0) + +#define memRowSetType(r, t) (memRowType(r) = (t)) +#define memRowSetLen(r, l) (isDataRow(r) ? memRowDataLen(r) = (l) : memRowKvLen(r) = (l)) +#define memRowSetVersion(r, v) (isDataRow(r) ? dataRowSetVersion(memRowDataBody(r), v) : memRowKvSetVersion(r, v)) +#define memRowCpy(dst, r) memcpy((dst), (r), memRowTLen(r)) +#define memRowMaxBytesFromSchema(s) (schemaTLen(s) + TD_MEM_ROW_DATA_HEAD_SIZE) +#define memRowDeleted(r) TKEY_IS_DELETED(memRowTKey(r)) + +SMemRow tdMemRowDup(SMemRow row); +void tdAppendMemRowToDataCol(SMemRow row, STSchema *pSchema, SDataCols *pCols); +// NOTE: offset here including the header size +static FORCE_INLINE void *tdGetKvRowDataOfCol(void *row, int32_t offset) { return POINTER_SHIFT(row, offset); } +// NOTE: offset here including the header size +static FORCE_INLINE void *tdGetMemRowDataOfCol(void *row, int8_t type, int32_t offset) { + if (isDataRow(row)) { + return tdGetRowDataOfCol(row, type, offset); + } else if (isKvRow(row)) { + return tdGetKvRowDataOfCol(row, offset); + } else { + ASSERT(0); + } + return NULL; +} + +// ----------------- Raw payload structure for row: +/* |<------------ Head ------------->|<----------- body of column data tuple ------------------->| + * | |<----------------- flen ------------->|<--- value part --->| + * |SMemRowType| dataTLen | nCols | colId | colType | offset | ... | value |...|...|... | + * +-----------+----------+----------+--------------------------------------|--------------------| + * | uint8_t | uint32_t | uint16_t | int16_t | uint8_t | uint16_t | ... |.......|...|...|... | + * +-----------+----------+----------+--------------------------------------+--------------------| + * 1. offset in column data tuple starts from the value part in case of uint16_t overflow. + * 2. dataTLen: total length including the header and body. + */ + +#define PAYLOAD_NCOLS_LEN sizeof(uint16_t) +#define PAYLOAD_NCOLS_OFFSET (sizeof(uint8_t) + sizeof(TDRowTLenT)) +#define PAYLOAD_HEADER_LEN (PAYLOAD_NCOLS_OFFSET + PAYLOAD_NCOLS_LEN) +#define PAYLOAD_ID_LEN sizeof(int16_t) +#define PAYLOAD_ID_TYPE_LEN (sizeof(int16_t) + sizeof(uint8_t)) +#define PAYLOAD_COL_HEAD_LEN (PAYLOAD_ID_TYPE_LEN + sizeof(uint16_t)) +#define PAYLOAD_PRIMARY_COL_LEN (PAYLOAD_ID_TYPE_LEN + sizeof(TSKEY)) + +#define payloadBody(r) POINTER_SHIFT(r, PAYLOAD_HEADER_LEN) +#define payloadType(r) (*(uint8_t *)(r)) +#define payloadSetType(r, t) (payloadType(r) = (t)) +#define payloadTLen(r) (*(TDRowTLenT *)POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE)) // including total header +#define payloadSetTLen(r, l) (payloadTLen(r) = (l)) +#define payloadNCols(r) (*(TDRowLenT *)POINTER_SHIFT(r, PAYLOAD_NCOLS_OFFSET)) +#define payloadSetNCols(r, n) (payloadNCols(r) = (n)) +#define payloadValuesOffset(r) \ + (PAYLOAD_HEADER_LEN + payloadNCols(r) * PAYLOAD_COL_HEAD_LEN) // avoid using the macro in loop +#define payloadValues(r) POINTER_SHIFT(r, payloadValuesOffset(r)) // avoid using the macro in loop +#define payloadColId(c) (*(int16_t *)(c)) +#define payloadColType(c) (*(uint8_t *)POINTER_SHIFT(c, PAYLOAD_ID_LEN)) +#define payloadColOffset(c) (*(uint16_t *)POINTER_SHIFT(c, PAYLOAD_ID_TYPE_LEN)) +#define payloadColValue(c) POINTER_SHIFT(c, payloadColOffset(c)) + +#define payloadColSetId(c, i) (payloadColId(c) = (i)) +#define payloadColSetType(c, t) (payloadColType(c) = (t)) +#define payloadColSetOffset(c, o) (payloadColOffset(c) = (o)) + +#define payloadTSKey(r) (*(TSKEY *)POINTER_SHIFT(r, payloadValuesOffset(r))) +#define payloadTKey(r) (*(TKEY *)POINTER_SHIFT(r, payloadValuesOffset(r))) +#define payloadKey(r) tdGetKey(payloadTKey(r)) + + +static FORCE_INLINE char *payloadNextCol(char *pCol) { return (char *)POINTER_SHIFT(pCol, PAYLOAD_COL_HEAD_LEN); } + #ifdef __cplusplus } #endif -#endif // _TD_DATA_FORMAT_H_ +#endif // _TD_DATA_FORMAT_H_ \ No newline at end of file diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index 94c429cfc0d24937020ff77513b168a3e6811ca9..04d70e7aa080e5935de1ef3c7538076cf805bd59 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -18,6 +18,21 @@ #include "tcoding.h" #include "wchar.h" +const uint8_t BoolNull = TSDB_DATA_BOOL_NULL; +const uint8_t TinyintNull = TSDB_DATA_TINYINT_NULL; +const uint16_t SmallintNull = TSDB_DATA_SMALLINT_NULL; +const uint32_t IntNull = TSDB_DATA_INT_NULL; +const uint64_t BigintNull = TSDB_DATA_BIGINT_NULL; +const uint64_t TimestampNull = TSDB_DATA_BIGINT_NULL; +const uint8_t UTinyintNull = TSDB_DATA_UTINYINT_NULL; +const uint16_t USmallintNull = TSDB_DATA_USMALLINT_NULL; +const uint32_t UIntNull = TSDB_DATA_UINT_NULL; +const uint64_t UBigintNull = TSDB_DATA_UBIGINT_NULL; +const uint32_t FloatNull = TSDB_DATA_FLOAT_NULL; +const uint64_t DoubleNull = TSDB_DATA_DOUBLE_NULL; +const SBinaryNullT BinaryNull = {1, TSDB_DATA_BINARY_NULL}; +const SNCharNullT NcharNull = {4, TSDB_DATA_NCHAR_NULL}; + static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2, int limit2, int tRows); @@ -198,6 +213,14 @@ SDataRow tdDataRowDup(SDataRow row) { return trow; } +SMemRow tdMemRowDup(SMemRow row) { + SMemRow trow = malloc(memRowTLen(row)); + if (trow == NULL) return NULL; + + memRowCpy(trow, row); + return trow; +} + void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints) { pDataCol->type = colType(pCol); pDataCol->colId = colColId(pCol); @@ -217,11 +240,22 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints) *pBuf = POINTER_SHIFT(*pBuf, pDataCol->spaceSize); } } - // value from timestamp should be TKEY here instead of TSKEY -void dataColAppendVal(SDataCol *pCol, void *value, int numOfRows, int maxPoints) { +void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints) { ASSERT(pCol != NULL && value != NULL); + if (isAllRowsNull(pCol)) { + if (isNull(value, pCol->type)) { + // all null value yet, just return + return; + } + + if (numOfRows > 0) { + // Find the first not null value, fill all previouse values as NULL + dataColSetNEleNull(pCol, numOfRows, maxPoints); + } + } + if (IS_VAR_DATA_TYPE(pCol->type)) { // set offset pCol->dataOff[numOfRows] = pCol->len; @@ -243,7 +277,7 @@ bool isNEleNull(SDataCol *pCol, int nEle) { return true; } -void dataColSetNullAt(SDataCol *pCol, int index) { +FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index) { if (IS_VAR_DATA_TYPE(pCol->type)) { pCol->dataOff[index] = pCol->len; char *ptr = POINTER_SHIFT(pCol->pData, pCol->len); @@ -399,8 +433,7 @@ void tdResetDataCols(SDataCols *pCols) { } } } - -void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) { +static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) { ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < dataRowKey(row)); int rcol = 0; @@ -419,7 +452,8 @@ void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) while (dcol < pCols->numOfCols) { SDataCol *pDataCol = &(pCols->cols[dcol]); if (rcol >= schemaNCols(pSchema)) { - dataColSetNullAt(pDataCol, pCols->numOfRows); + // dataColSetNullAt(pDataCol, pCols->numOfRows); + dataColAppendVal(pDataCol, tdGetNullVal(pDataCol->type), pCols->numOfRows, pCols->maxPoints); dcol++; continue; } @@ -433,7 +467,8 @@ void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) } else if (pRowCol->colId < pDataCol->colId) { rcol++; } else { - dataColSetNullAt(pDataCol, pCols->numOfRows); + // dataColSetNullAt(pDataCol, pCols->numOfRows); + dataColAppendVal(pDataCol, tdGetNullVal(pDataCol->type), pCols->numOfRows, pCols->maxPoints); dcol++; } } @@ -441,6 +476,62 @@ void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) pCols->numOfRows++; } +static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCols) { + ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < kvRowKey(row)); + + int rcol = 0; + int dcol = 0; + + if (kvRowDeleted(row)) { + for (; dcol < pCols->numOfCols; dcol++) { + SDataCol *pDataCol = &(pCols->cols[dcol]); + if (dcol == 0) { + dataColAppendVal(pDataCol, kvRowValues(row), pCols->numOfRows, pCols->maxPoints); + } else { + dataColSetNullAt(pDataCol, pCols->numOfRows); + } + } + } else { + int nRowCols = kvRowNCols(row); + + while (dcol < pCols->numOfCols) { + SDataCol *pDataCol = &(pCols->cols[dcol]); + if (rcol >= nRowCols || rcol >= schemaNCols(pSchema)) { + // dataColSetNullAt(pDataCol, pCols->numOfRows); + dataColAppendVal(pDataCol, tdGetNullVal(pDataCol->type), pCols->numOfRows, pCols->maxPoints); + ++dcol; + continue; + } + + SColIdx *colIdx = kvRowColIdxAt(row, rcol); + + if (colIdx->colId == pDataCol->colId) { + void *value = tdGetKvRowDataOfCol(row, colIdx->offset); + dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints); + ++dcol; + ++rcol; + } else if (colIdx->colId < pDataCol->colId) { + ++rcol; + } else { + // dataColSetNullAt(pDataCol, pCols->numOfRows); + dataColAppendVal(pDataCol, tdGetNullVal(pDataCol->type), pCols->numOfRows, pCols->maxPoints); + ++dcol; + } + } + } + pCols->numOfRows++; +} + +void tdAppendMemRowToDataCol(SMemRow row, STSchema *pSchema, SDataCols *pCols) { + if (isDataRow(row)) { + tdAppendDataRowToDataCol(memRowDataBody(row), pSchema, pCols); + } else if (isKvRow(row)) { + tdAppendKvRowToDataCol(memRowKvBody(row), pSchema, pCols); + } else { + ASSERT(0); + } +} + int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset) { ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows); ASSERT(target->numOfCols == source->numOfCols); @@ -563,7 +654,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { nrow = malloc(kvRowLen(row) + sizeof(SColIdx) + diff); if (nrow == NULL) return -1; - kvRowSetLen(nrow, kvRowLen(row) + (int16_t)sizeof(SColIdx) + diff); + kvRowSetLen(nrow, kvRowLen(row) + (uint16_t)sizeof(SColIdx) + diff); kvRowSetNCols(nrow, kvRowNCols(row) + 1); if (ptr == NULL) { @@ -605,8 +696,8 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { if (varDataTLen(value) == varDataTLen(pOldVal)) { // just update the column value in place memcpy(pOldVal, value, varDataTLen(value)); } else { // need to reallocate the memory - int16_t diff = varDataTLen(value) - varDataTLen(pOldVal); - int16_t nlen = kvRowLen(row) + diff; + uint16_t diff = varDataTLen(value) - varDataTLen(pOldVal); + uint16_t nlen = kvRowLen(row) + diff; ASSERT(nlen > 0); nrow = malloc(nlen); if (nrow == NULL) return -1; @@ -709,3 +800,39 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) { return row; } + +const void *tdGetNullVal(int8_t type) { + switch (type) { + case TSDB_DATA_TYPE_BOOL: + return &BoolNull; + case TSDB_DATA_TYPE_TINYINT: + return &TinyintNull; + case TSDB_DATA_TYPE_SMALLINT: + return &SmallintNull; + case TSDB_DATA_TYPE_INT: + return &IntNull; + case TSDB_DATA_TYPE_BIGINT: + return &BigintNull; + case TSDB_DATA_TYPE_FLOAT: + return &FloatNull; + case TSDB_DATA_TYPE_DOUBLE: + return &DoubleNull; + case TSDB_DATA_TYPE_BINARY: + return &BinaryNull; + case TSDB_DATA_TYPE_TIMESTAMP: + return &TimestampNull; + case TSDB_DATA_TYPE_NCHAR: + return &NcharNull; + case TSDB_DATA_TYPE_UTINYINT: + return &UTinyintNull; + case TSDB_DATA_TYPE_USMALLINT: + return &USmallintNull; + case TSDB_DATA_TYPE_UINT: + return &UIntNull; + case TSDB_DATA_TYPE_UBIGINT: + return &UBigintNull; + default: + ASSERT(0); + return NULL; + } +} \ No newline at end of file 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 b91fe88dfacd7c6e414aa842184b2c349b3e33b9..2ff0d86c920aa0aae67f71448bf9112564293350 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 @@ -19,6 +19,7 @@ import com.taosdata.jdbc.utils.NullType; import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Timestamp; +import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -463,6 +464,25 @@ public class TSDBResultSetRowData { data.set(col, tsObj); } + /** + * this implementation is used for TDengine old version + */ + public void setTimestamp(int col, long ts) { + //TODO: this implementation contains logical error + // when precision is us the (long ts) is 16 digital number + // when precision is ms, the (long ts) is 13 digital number + // we need a JNI function like this: + // public void setTimestamp(int col, long epochSecond, long nanoAdjustment) + if (ts < 1_0000_0000_0000_0L) { + data.set(col, new Timestamp(ts)); + } else { + long epochSec = ts / 1000_000L; + long nanoAdjustment = ts % 1000_000L * 1000L; + Timestamp timestamp = Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + data.set(col, timestamp); + } + } + public Timestamp getTimestamp(int col, int nativeType) { Object obj = data.get(col - 1); if (obj == null) 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 efe3303bd950e49f40e55b61bbca2cddf807b14f..c91bacbfdc7435e35a6be7cc1f756381de968424 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 @@ -5,7 +5,6 @@ import com.google.common.collect.RangeSet; import com.google.common.collect.TreeRangeSet; import com.taosdata.jdbc.enums.TimestampPrecision; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.sql.Date; import java.sql.Time; @@ -110,15 +109,27 @@ public class Utils { return rawSql; // toLowerCase String preparedSql = rawSql.trim().toLowerCase(); - String[] clause = new String[]{"values\\s*\\([\\s\\S]*?\\)", "tags\\s*\\([\\s\\S]*?\\)", "where[\\s\\S]*"}; + String[] clause = new String[]{"tags\\s*\\([\\s\\S]*?\\)", "where[\\s\\S]*"}; Map placeholderPositions = new HashMap<>(); RangeSet clauseRangeSet = TreeRangeSet.create(); findPlaceholderPosition(preparedSql, placeholderPositions); + // find tags and where clause's position findClauseRangeSet(preparedSql, clause, clauseRangeSet); + // find values clause's position + findValuesClauseRangeSet(preparedSql, clauseRangeSet); return transformSql(rawSql, parameters, placeholderPositions, clauseRangeSet); } + private static void findValuesClauseRangeSet(String preparedSql, RangeSet clauseRangeSet) { + Matcher matcher = Pattern.compile("(values|,)\\s*(\\([^)]*\\))").matcher(preparedSql); + while (matcher.find()) { + int start = matcher.start(2); + int end = matcher.end(2); + clauseRangeSet.add(Range.closedOpen(start, end)); + } + } + private static void findClauseRangeSet(String preparedSql, String[] regexArr, RangeSet clauseRangeSet) { clauseRangeSet.clear(); for (String regex : regexArr) { @@ -126,7 +137,7 @@ public class Utils { while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); - clauseRangeSet.add(Range.closed(start, end)); + clauseRangeSet.add(Range.closedOpen(start, end)); } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java index ee83f6ceb2d412613129611e2a575a7ad4922db0..4b8ec61078e8dbb812940d62737c638dc9a49f41 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/UtilsTest.java @@ -3,6 +3,8 @@ package com.taosdata.jdbc.utils; import org.junit.Assert; import org.junit.Test; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Stream; public class UtilsTest { @@ -32,7 +34,7 @@ public class UtilsTest { } @Test - public void getNativeSqlReplaceQuestionMarks() { + public void lowerCase() { // given String nativeSql = "insert into ?.? (ts, temperature, humidity) using ?.? tags(?,?) values(now, ?, ?)"; Object[] parameters = Stream.of("test", "t1", "test", "weather", "beijing", 1, 12.2, 4).toArray(); @@ -46,7 +48,7 @@ public class UtilsTest { } @Test - public void getNativeSqlReplaceQuestionMarks2() { + public void upperCase() { // given String nativeSql = "INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,?,?)"; Object[] parameters = Stream.of("d1", 1, 123, 3.14, 220, 4).toArray(); @@ -59,9 +61,49 @@ public class UtilsTest { Assert.assertEquals(expected, actual); } + @Test + public void multiValues() { + // given + String nativeSql = "INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,?,?),(?,?,?,?)"; + Object[] parameters = Stream.of("d1", 1, 100, 3.14, "abc", 4, 200, 3.1415, "xyz", 5).toArray(); + + // when + String actual = Utils.getNativeSql(nativeSql, parameters); + + // then + String expected = "INSERT INTO d1 (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (1) VALUES (100,3.14,'abc',4),(200,3.1415,'xyz',5)"; + Assert.assertEquals(expected, actual); + } + + @Test + public void lineTerminator() { + // given + String nativeSql = "INSERT INTO ? (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (?) VALUES (?,?,\r\n?,?),(?,?,?,?)"; + Object[] parameters = Stream.of("d1", 1, 100, 3.14, "abc", 4, 200, 3.1415, "xyz", 5).toArray(); + + // when + String actual = Utils.getNativeSql(nativeSql, parameters); + + // then + String expected = "INSERT INTO d1 (TS,CURRENT,VOLTAGE,PHASE) USING METERS TAGS (1) VALUES (100,3.14,\r\n'abc',4),(200,3.1415,'xyz',5)"; + Assert.assertEquals(expected, actual); + } + + @Test + public void lineTerminatorAndMultiValues() { + String nativeSql = "INSERT Into ? TAGS(?) VALUES(?,?,\r\n?,?),(?,? ,\r\n?,?) t? tags (?) Values (?,?,?\r\n,?),(?,?,?,?) t? Tags(?) values (?,?,?,?) , (?,?,?,?)"; + Object[] parameters = Stream.of("t1", "abc", 100, 1.1, "xxx", "xxx", 200, 2.2, "xxx", "xxx", 2, "bcd", 300, 3.3, "xxx", "xxx", 400, 4.4, "xxx", "xxx", 3, "cde", 500, 5.5, "xxx", "xxx", 600, 6.6, "xxx", "xxx").toArray(); + + // when + String actual = Utils.getNativeSql(nativeSql, parameters); + + // then + String expected = "INSERT Into t1 TAGS('abc') VALUES(100,1.1,\r\n'xxx','xxx'),(200,2.2 ,\r\n'xxx','xxx') t2 tags ('bcd') Values (300,3.3,'xxx'\r\n,'xxx'),(400,4.4,'xxx','xxx') t3 Tags('cde') values (500,5.5,'xxx','xxx') , (600,6.6,'xxx','xxx')"; + Assert.assertEquals(expected, actual); + } @Test - public void getNativeSqlReplaceNothing() { + public void replaceNothing() { // given String nativeSql = "insert into test.t1 (ts, temperature, humidity) using test.weather tags('beijing',1) values(now, 12.2, 4)"; @@ -73,7 +115,7 @@ public class UtilsTest { } @Test - public void getNativeSqlReplaceNothing2() { + public void replaceNothing2() { // given String nativeSql = "insert into test.t1 (ts, temperature, humidity) using test.weather tags('beijing',1) values(now, 12.2, 4)"; Object[] parameters = Stream.of("test", "t1", "test", "weather", "beijing", 1, 12.2, 4).toArray(); @@ -86,7 +128,7 @@ public class UtilsTest { } @Test - public void getNativeSqlReplaceNothing3() { + public void replaceNothing3() { // given String nativeSql = "insert into ?.? (ts, temperature, humidity) using ?.? tags(?,?) values(now, ?, ?)"; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index f539e7725315d2358767624ce74a8e9609a0b425..cd762f311075e7d315cf3ad9811056a909be50dc 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -476,15 +476,17 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { cDebug("vgId:%d, id:%d CQ:%s stream result is ready", pContext->vgId, pObj->tid, pObj->sqlStr); - int32_t size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + TD_DATA_ROW_HEAD_SIZE + pObj->rowSize; + int32_t size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + TD_MEM_ROW_DATA_HEAD_SIZE + pObj->rowSize; char *buffer = calloc(size, 1); SWalHead *pHead = (SWalHead *)buffer; SSubmitMsg *pMsg = (SSubmitMsg *) (buffer + sizeof(SWalHead)); SSubmitBlk *pBlk = (SSubmitBlk *) (buffer + sizeof(SWalHead) + sizeof(SSubmitMsg)); - SDataRow trow = (SDataRow)pBlk->data; - tdInitDataRow(trow, pSchema); + SMemRow trow = (SMemRow)pBlk->data; + SDataRow dataRow = (SDataRow)memRowDataBody(trow); + memRowSetType(trow, SMEM_ROW_DATA); + tdInitDataRow(dataRow, pSchema); for (int32_t i = 0; i < pSchema->numOfCols; i++) { STColumn *c = pSchema->columns + i; @@ -500,9 +502,9 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { memcpy((char *)val + sizeof(VarDataLenT), buf, len); varDataLen(val) = len; } - tdAppendColVal(trow, val, c->type, c->bytes, c->offset); + tdAppendColVal(dataRow, val, c->type, c->offset); } - pBlk->dataLen = htonl(dataRowLen(trow)); + pBlk->dataLen = htonl(memRowDataTLen(trow)); pBlk->schemaLen = 0; pBlk->uid = htobe64(pObj->uid); @@ -511,7 +513,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { pBlk->sversion = htonl(pSchema->version); pBlk->padding = 0; - pHead->len = sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + dataRowLen(trow); + pHead->len = sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + memRowDataTLen(trow); pMsg->header.vgId = htonl(pContext->vgId); pMsg->header.contLen = htonl(pHead->len); diff --git a/src/dnode/CMakeLists.txt b/src/dnode/CMakeLists.txt index e7ac1be5b1160df447271eeec78e2939923b6d53..47186130ead0d1ee3f4593b7ef346f8cc47f7cba 100644 --- a/src/dnode/CMakeLists.txt +++ b/src/dnode/CMakeLists.txt @@ -18,7 +18,7 @@ ELSE () ENDIF () ADD_EXECUTABLE(taosd ${SRC}) -TARGET_LINK_LIBRARIES(taosd mnode monitor http tsdb twal vnode cJson lz4 balance sync ${LINK_JEMALLOC}) +TARGET_LINK_LIBRARIES(taosd mnode monitor http tsdb twal vnode cJson lua lz4 balance sync ${LINK_JEMALLOC}) IF (TD_SOMODE_STATIC) TARGET_LINK_LIBRARIES(taosd taos_static) diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 61b11579bf8da901697df3202c872caf7d6c7371..7723b6221b1ad769ae5b1a4b4571a5506ba23e12 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -40,6 +40,7 @@ #include "dnodeShell.h" #include "dnodeTelemetry.h" #include "module.h" +#include "qScript.h" #include "mnode.h" #if !defined(_MODULE) || !defined(_TD_LINUX) @@ -84,6 +85,7 @@ static SStep tsDnodeSteps[] = { {"dnode-shell", dnodeInitShell, dnodeCleanupShell}, {"dnode-statustmr", dnodeInitStatusTimer,dnodeCleanupStatusTimer}, {"dnode-telemetry", dnodeInitTelemetry, dnodeCleanupTelemetry}, + {"dnode-script", scriptEnvPoolInit, scriptEnvPoolCleanup}, }; static SStep tsDnodeCompactSteps[] = { @@ -266,7 +268,7 @@ static int32_t dnodeInitStorage() { return -1; } } - //TODO(dengyihao): no need to init here + //TODO(dengyihao): no need to init here if (dnodeCreateDir(tsMnodeDir) < 0) { dError("failed to create dir: %s, reason: %s", tsMnodeDir, strerror(errno)); return -1; diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 2f83e5f6dc96f660162fdbda7fea034658b8cab7..5606681f0f931070e9cbf21d6b98b0d2eb51bdfa 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -48,9 +48,11 @@ int32_t dnodeInitShell() { dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_DROP_DNODE] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_CREATE_DB] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_CREATE_TP] = dnodeDispatchToMWriteQueue; + dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_CREATE_FUNCTION] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_DROP_DB] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_SYNC_DB] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_DROP_TP] = dnodeDispatchToMWriteQueue; + dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_DROP_FUNCTION] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_ALTER_DB] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_ALTER_TP] = dnodeDispatchToMWriteQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_CREATE_TABLE]= dnodeDispatchToMWriteQueue; @@ -72,6 +74,7 @@ int32_t dnodeInitShell() { dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_TABLES_META] = dnodeDispatchToMReadQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_SHOW] = dnodeDispatchToMReadQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE] = dnodeDispatchToMReadQueue; + dnodeProcessShellMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE_FUNC] = dnodeDispatchToMReadQueue; dnodeProcessShellMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeSendStartupStep; diff --git a/src/dnode/src/dnodeVWrite.c b/src/dnode/src/dnodeVWrite.c index bbf257ff953779fd9d097ba82e1b42c0b91d1531..ff2d12f001710b5ddcd310cff03929fd3c038782 100644 --- a/src/dnode/src/dnodeVWrite.c +++ b/src/dnode/src/dnodeVWrite.c @@ -202,12 +202,12 @@ static void *dnodeProcessVWriteQueue(void *wparam) { for (int32_t i = 0; i < numOfMsgs; ++i) { taosGetQitem(pWorker->qall, &qtype, (void **)&pWrite); dTrace("msg:%p, app:%p type:%s will be processed in vwrite queue, qtype:%s hver:%" PRIu64, pWrite, - pWrite->rpcMsg.ahandle, taosMsg[pWrite->pHead.msgType], qtypeStr[qtype], pWrite->pHead.version); + pWrite->rpcMsg.ahandle, taosMsg[pWrite->walHead.msgType], qtypeStr[qtype], pWrite->walHead.version); - pWrite->code = vnodeProcessWrite(pVnode, &pWrite->pHead, qtype, pWrite); + pWrite->code = vnodeProcessWrite(pVnode, &pWrite->walHead, qtype, pWrite); if (pWrite->code <= 0) atomic_add_fetch_32(&pWrite->processedCount, 1); if (pWrite->code > 0) pWrite->code = 0; - if (pWrite->code == 0 && pWrite->pHead.msgType != TSDB_MSG_TYPE_SUBMIT) forceFsync = true; + if (pWrite->code == 0 && pWrite->walHead.msgType != TSDB_MSG_TYPE_SUBMIT) forceFsync = true; dTrace("msg:%p is processed in vwrite queue, code:0x%x", pWrite, pWrite->code); } @@ -222,7 +222,7 @@ static void *dnodeProcessVWriteQueue(void *wparam) { dnodeSendRpcVWriteRsp(pVnode, pWrite, pWrite->code); } else { if (qtype == TAOS_QTYPE_FWD) { - vnodeConfirmForward(pVnode, pWrite->pHead.version, pWrite->code, pWrite->pHead.msgType != TSDB_MSG_TYPE_SUBMIT); + vnodeConfirmForward(pVnode, pWrite->walHead.version, pWrite->code, pWrite->walHead.msgType != TSDB_MSG_TYPE_SUBMIT); } if (pWrite->rspRet.rsp) { rpcFreeCont(pWrite->rspRet.rsp); diff --git a/src/inc/query.h b/src/inc/query.h index 38078cf21fcededd96dad833bbf1d22de55bb8ac..fb9cbff8584892b4a6bc6e4a6ce046a7500aef39 100644 --- a/src/inc/query.h +++ b/src/inc/query.h @@ -28,7 +28,7 @@ typedef void* qinfo_t; * @param qinfo * @return */ -int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryTableMsg, qinfo_t* qinfo, uint64_t *qId); +int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryTableMsg, qinfo_t* qinfo, uint64_t qId); /** diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index d5c13885d55052346d0e25f9d2dea116ec13b7a8..ca8ad3cc09f99d06c1f0406bb7124a8aad6fef55 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -180,12 +180,16 @@ do { \ // this is the length of its string representation, including the terminator zero #define TSDB_ACCT_ID_LEN 11 -#define TSDB_MAX_COLUMNS 1024 +#define TSDB_MAX_COLUMNS 4096 #define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns #define TSDB_NODE_NAME_LEN 64 #define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string #define TSDB_DB_NAME_LEN 33 +#define TSDB_FUNC_NAME_LEN 65 +#define TSDB_FUNC_CODE_LEN (65535 - 512) +#define TSDB_FUNC_BUF_SIZE 512 +#define TSDB_TYPE_STR_MAX_LEN 32 #define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN) #define TSDB_COL_NAME_LEN 65 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 @@ -195,7 +199,13 @@ do { \ #define TSDB_APPNAME_LEN TSDB_UNI_LEN -#define TSDB_MAX_BYTES_PER_ROW 16384 + /** + * In some scenarios uint16_t (0~65535) is used to store the row len. + * - Firstly, we use 65531(65535 - 4), as the SDataRow/SKVRow contains 4 bits header. + * - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus + * the final value is 65531-(4096-1)*4 = 49151. + */ +#define TSDB_MAX_BYTES_PER_ROW 49151 #define TSDB_MAX_TAGS_LEN 16384 #define TSDB_MAX_TAGS 128 #define TSDB_MAX_TAG_CONDITIONS 1024 @@ -323,8 +333,9 @@ do { \ #define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_UNION_CLAUSE 5 -#define TSDB_MAX_BINARY_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE) -#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE) +#define TSDB_MAX_FIELD_LEN 16384 +#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384 +#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384 #define PRIMARYKEY_TIMESTAMP_COL_INDEX 0 #define TSDB_MAX_RPC_THREADS 5 @@ -332,6 +343,10 @@ do { \ #define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type #define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode +#define TSDB_UDF_TYPE_SCALAR 1 +#define TSDB_UDF_TYPE_AGGREGATE 2 + + /* * 1. ordinary sub query for select * from super_table * 2. all sqlobj generated by createSubqueryObj with this flag diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index b18aa2c2d9200212baa93b6bb314ca1228360b11..fbb29014e0aa17368b88b76237e49d6ada9ce0f9 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -100,6 +100,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TSC_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0217) //"Database not specified or available") #define TSDB_CODE_TSC_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0218) //"Table does not exist") #define TSDB_CODE_TSC_EXCEED_SQL_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0219) //"SQL statement too long check maxSQLLength config") +#define TSDB_CODE_TSC_FILE_EMPTY TAOS_DEF_ERROR_CODE(0, 0x021A) //"File is empty") // mnode #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed") @@ -174,6 +175,13 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_INVALID_STABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x036D) //"Super table does not exist") #define TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG TAOS_DEF_ERROR_CODE(0, 0x036E) //"Invalid create table message") +#define TSDB_CODE_MND_INVALID_FUNC_NAME TAOS_DEF_ERROR_CODE(0, 0x0370) //"Invalid func name") +#define TSDB_CODE_MND_INVALID_FUNC_LEN TAOS_DEF_ERROR_CODE(0, 0x0371) //"Invalid func length") +#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x0372) //"Invalid func code") +#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0373) //"Func already exists") +#define TSDB_CODE_MND_INVALID_FUNC TAOS_DEF_ERROR_CODE(0, 0x0374) //"Invalid func") +#define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x0375) //"Invalid func bufSize") + #define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380) //"Database not specified or available") #define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381) //"Database already exists") #define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0382) //"Invalid database options") @@ -261,6 +269,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW TAOS_DEF_ERROR_CODE(0, 0x070A) //"Too many time window in query") #define TSDB_CODE_QRY_NOT_ENOUGH_BUFFER TAOS_DEF_ERROR_CODE(0, 0x070B) //"Query buffer limit has reached") #define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistency in replica") +#define TSDB_CODE_QRY_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x070D) //"System error") // grant diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 4e76b6dcc1fb0682e69de5a0e7e0f35440e7e40b..9ee241efc1840b522919ec123dff25ee625d9bff 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -77,8 +77,10 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_USER, "drop-user" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_DNODE, "create-dnode" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_DNODE, "drop-dnode" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_DB, "create-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_DB, "drop-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_USE_DB, "use-db" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_FUNCTION, "create-function" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_DB, "drop-db" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_FUNCTION, "drop-function" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_USE_DB, "use-db" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_ALTER_DB, "alter-db" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_SYNC_DB, "sync-db-replica" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_TABLE, "create-table" ) @@ -96,7 +98,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_KILL_STREAM, "kill-stream" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_KILL_CONN, "kill-conn" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CONFIG_DNODE, "cm-config-dnode" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_HEARTBEAT, "heartbeat" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY8, "dummy8" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_RETRIEVE_FUNC, "retrieve-func" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY9, "dummy9" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY10, "dummy10" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY11, "dummy11" ) @@ -153,6 +155,7 @@ enum _mgmt_table { TSDB_MGMT_TABLE_STREAMTABLES, TSDB_MGMT_TABLE_CLUSTER, TSDB_MGMT_TABLE_TP, + TSDB_MGMT_TABLE_FUNCTION, TSDB_MGMT_TABLE_MAX, }; @@ -507,6 +510,9 @@ typedef struct { int32_t prevResultLen; // previous result length int32_t numOfOperator; int32_t tableScanOperator;// table scan operator. -1 means no scan operator + int32_t udfNum; // number of udf function + int32_t udfContentOffset; + int32_t udfContentLen; SColumnInfo tableCols[]; } SQueryTableMsg; @@ -571,6 +577,41 @@ typedef struct { int8_t reserve[5]; } SCreateDbMsg, SAlterDbMsg; +typedef struct { + char name[TSDB_FUNC_NAME_LEN]; + char path[PATH_MAX]; + int32_t funcType; + uint8_t outputType; + int16_t outputLen; + int32_t bufSize; + int32_t codeLen; + char code[]; +} SCreateFuncMsg; + +typedef struct { + int32_t num; + char name[]; +} SRetrieveFuncMsg; + +typedef struct { + char name[TSDB_FUNC_NAME_LEN]; + int32_t funcType; + int8_t resType; + int16_t resBytes; + int32_t bufSize; + int32_t len; + char content[]; +} SFunctionInfoMsg; + +typedef struct { + int32_t num; + char content[]; +} SUdfFuncMsg; + +typedef struct { + char name[TSDB_FUNC_NAME_LEN]; +} SDropFuncMsg; + typedef struct { char db[TSDB_TABLE_FNAME_LEN]; uint8_t ignoreNotExists; @@ -710,8 +751,10 @@ typedef struct { } STableInfoMsg; typedef struct { + uint8_t metaClone; // create local clone of the cached table meta int32_t numOfVgroups; int32_t numOfTables; + int32_t numOfUdfs; char tableNames[]; } SMultiTableInfoMsg; @@ -760,12 +803,14 @@ typedef struct STableMetaMsg { } STableMetaMsg; typedef struct SMultiTableMeta { - int32_t numOfTables; - int32_t numOfVgroup; - uint32_t contLen:31; - uint8_t compressed:1; // denote if compressed or not - uint32_t rawLen; // size before compress - char meta[]; + int32_t numOfTables; + int32_t numOfVgroup; + int32_t numOfUdf; + int32_t contLen; + uint8_t compressed; // denote if compressed or not + uint32_t rawLen; // size before compress + uint8_t metaClone; // make meta clone after retrieve meta from mnode + char meta[]; } SMultiTableMeta; typedef struct { diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index d15f044b6505555f9c3bca61f653f13a43b0bcfc..e89fed628262eb78067c63e0f74347dc29123378 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -62,149 +62,154 @@ #define TK_SHOW 44 #define TK_DATABASES 45 #define TK_TOPICS 46 -#define TK_MNODES 47 -#define TK_DNODES 48 -#define TK_ACCOUNTS 49 -#define TK_USERS 50 -#define TK_MODULES 51 -#define TK_QUERIES 52 -#define TK_CONNECTIONS 53 -#define TK_STREAMS 54 -#define TK_VARIABLES 55 -#define TK_SCORES 56 -#define TK_GRANTS 57 -#define TK_VNODES 58 -#define TK_IPTOKEN 59 -#define TK_DOT 60 -#define TK_CREATE 61 -#define TK_TABLE 62 -#define TK_STABLE 63 -#define TK_DATABASE 64 -#define TK_TABLES 65 -#define TK_STABLES 66 -#define TK_VGROUPS 67 -#define TK_DROP 68 -#define TK_TOPIC 69 -#define TK_DNODE 70 -#define TK_USER 71 -#define TK_ACCOUNT 72 -#define TK_USE 73 -#define TK_DESCRIBE 74 -#define TK_ALTER 75 -#define TK_PASS 76 -#define TK_PRIVILEGE 77 -#define TK_LOCAL 78 -#define TK_COMPACT 79 -#define TK_LP 80 -#define TK_RP 81 -#define TK_IF 82 -#define TK_EXISTS 83 -#define TK_PPS 84 -#define TK_TSERIES 85 -#define TK_DBS 86 -#define TK_STORAGE 87 -#define TK_QTIME 88 -#define TK_CONNS 89 -#define TK_STATE 90 -#define TK_COMMA 91 -#define TK_KEEP 92 -#define TK_CACHE 93 -#define TK_REPLICA 94 -#define TK_QUORUM 95 -#define TK_DAYS 96 -#define TK_MINROWS 97 -#define TK_MAXROWS 98 -#define TK_BLOCKS 99 -#define TK_CTIME 100 -#define TK_WAL 101 -#define TK_FSYNC 102 -#define TK_COMP 103 -#define TK_PRECISION 104 -#define TK_UPDATE 105 -#define TK_CACHELAST 106 -#define TK_PARTITIONS 107 -#define TK_UNSIGNED 108 -#define TK_TAGS 109 -#define TK_USING 110 -#define TK_AS 111 -#define TK_NULL 112 -#define TK_NOW 113 -#define TK_SELECT 114 -#define TK_UNION 115 -#define TK_ALL 116 -#define TK_DISTINCT 117 -#define TK_FROM 118 -#define TK_VARIABLE 119 -#define TK_INTERVAL 120 -#define TK_SESSION 121 -#define TK_STATE_WINDOW 122 -#define TK_FILL 123 -#define TK_SLIDING 124 -#define TK_ORDER 125 -#define TK_BY 126 -#define TK_ASC 127 -#define TK_DESC 128 -#define TK_GROUP 129 -#define TK_HAVING 130 -#define TK_LIMIT 131 -#define TK_OFFSET 132 -#define TK_SLIMIT 133 -#define TK_SOFFSET 134 -#define TK_WHERE 135 -#define TK_RESET 136 -#define TK_QUERY 137 -#define TK_SYNCDB 138 -#define TK_ADD 139 -#define TK_COLUMN 140 -#define TK_MODIFY 141 -#define TK_TAG 142 -#define TK_CHANGE 143 -#define TK_SET 144 -#define TK_KILL 145 -#define TK_CONNECTION 146 -#define TK_STREAM 147 -#define TK_COLON 148 -#define TK_ABORT 149 -#define TK_AFTER 150 -#define TK_ATTACH 151 -#define TK_BEFORE 152 -#define TK_BEGIN 153 -#define TK_CASCADE 154 -#define TK_CLUSTER 155 -#define TK_CONFLICT 156 -#define TK_COPY 157 -#define TK_DEFERRED 158 -#define TK_DELIMITERS 159 -#define TK_DETACH 160 -#define TK_EACH 161 -#define TK_END 162 -#define TK_EXPLAIN 163 -#define TK_FAIL 164 -#define TK_FOR 165 -#define TK_IGNORE 166 -#define TK_IMMEDIATE 167 -#define TK_INITIALLY 168 -#define TK_INSTEAD 169 -#define TK_MATCH 170 -#define TK_KEY 171 -#define TK_OF 172 -#define TK_RAISE 173 -#define TK_REPLACE 174 -#define TK_RESTRICT 175 -#define TK_ROW 176 -#define TK_STATEMENT 177 -#define TK_TRIGGER 178 -#define TK_VIEW 179 -#define TK_SEMI 180 -#define TK_NONE 181 -#define TK_PREV 182 -#define TK_LINEAR 183 -#define TK_IMPORT 184 -#define TK_TBNAME 185 -#define TK_JOIN 186 -#define TK_INSERT 187 -#define TK_INTO 188 -#define TK_VALUES 189 +#define TK_FUNCTIONS 47 +#define TK_MNODES 48 +#define TK_DNODES 49 +#define TK_ACCOUNTS 50 +#define TK_USERS 51 +#define TK_MODULES 52 +#define TK_QUERIES 53 +#define TK_CONNECTIONS 54 +#define TK_STREAMS 55 +#define TK_VARIABLES 56 +#define TK_SCORES 57 +#define TK_GRANTS 58 +#define TK_VNODES 59 +#define TK_IPTOKEN 60 +#define TK_DOT 61 +#define TK_CREATE 62 +#define TK_TABLE 63 +#define TK_STABLE 64 +#define TK_DATABASE 65 +#define TK_TABLES 66 +#define TK_STABLES 67 +#define TK_VGROUPS 68 +#define TK_DROP 69 +#define TK_TOPIC 70 +#define TK_FUNCTION 71 +#define TK_DNODE 72 +#define TK_USER 73 +#define TK_ACCOUNT 74 +#define TK_USE 75 +#define TK_DESCRIBE 76 +#define TK_ALTER 77 +#define TK_PASS 78 +#define TK_PRIVILEGE 79 +#define TK_LOCAL 80 +#define TK_COMPACT 81 +#define TK_LP 82 +#define TK_RP 83 +#define TK_IF 84 +#define TK_EXISTS 85 +#define TK_AS 86 +#define TK_OUTPUTTYPE 87 +#define TK_AGGREGATE 88 +#define TK_BUFSIZE 89 +#define TK_PPS 90 +#define TK_TSERIES 91 +#define TK_DBS 92 +#define TK_STORAGE 93 +#define TK_QTIME 94 +#define TK_CONNS 95 +#define TK_STATE 96 +#define TK_COMMA 97 +#define TK_KEEP 98 +#define TK_CACHE 99 +#define TK_REPLICA 100 +#define TK_QUORUM 101 +#define TK_DAYS 102 +#define TK_MINROWS 103 +#define TK_MAXROWS 104 +#define TK_BLOCKS 105 +#define TK_CTIME 106 +#define TK_WAL 107 +#define TK_FSYNC 108 +#define TK_COMP 109 +#define TK_PRECISION 110 +#define TK_UPDATE 111 +#define TK_CACHELAST 112 +#define TK_PARTITIONS 113 +#define TK_UNSIGNED 114 +#define TK_TAGS 115 +#define TK_USING 116 +#define TK_NULL 117 +#define TK_NOW 118 +#define TK_SELECT 119 +#define TK_UNION 120 +#define TK_ALL 121 +#define TK_DISTINCT 122 +#define TK_FROM 123 +#define TK_VARIABLE 124 +#define TK_INTERVAL 125 +#define TK_SESSION 126 +#define TK_STATE_WINDOW 127 +#define TK_FILL 128 +#define TK_SLIDING 129 +#define TK_ORDER 130 +#define TK_BY 131 +#define TK_ASC 132 +#define TK_DESC 133 +#define TK_GROUP 134 +#define TK_HAVING 135 +#define TK_LIMIT 136 +#define TK_OFFSET 137 +#define TK_SLIMIT 138 +#define TK_SOFFSET 139 +#define TK_WHERE 140 +#define TK_RESET 141 +#define TK_QUERY 142 +#define TK_SYNCDB 143 +#define TK_ADD 144 +#define TK_COLUMN 145 +#define TK_MODIFY 146 +#define TK_TAG 147 +#define TK_CHANGE 148 +#define TK_SET 149 +#define TK_KILL 150 +#define TK_CONNECTION 151 +#define TK_STREAM 152 +#define TK_COLON 153 +#define TK_ABORT 154 +#define TK_AFTER 155 +#define TK_ATTACH 156 +#define TK_BEFORE 157 +#define TK_BEGIN 158 +#define TK_CASCADE 159 +#define TK_CLUSTER 160 +#define TK_CONFLICT 161 +#define TK_COPY 162 +#define TK_DEFERRED 163 +#define TK_DELIMITERS 164 +#define TK_DETACH 165 +#define TK_EACH 166 +#define TK_END 167 +#define TK_EXPLAIN 168 +#define TK_FAIL 169 +#define TK_FOR 170 +#define TK_IGNORE 171 +#define TK_IMMEDIATE 172 +#define TK_INITIALLY 173 +#define TK_INSTEAD 174 +#define TK_MATCH 175 +#define TK_KEY 176 +#define TK_OF 177 +#define TK_RAISE 178 +#define TK_REPLACE 179 +#define TK_RESTRICT 180 +#define TK_ROW 181 +#define TK_STATEMENT 182 +#define TK_TRIGGER 183 +#define TK_VIEW 184 +#define TK_SEMI 185 +#define TK_NONE 186 +#define TK_PREV 187 +#define TK_LINEAR 188 +#define TK_IMPORT 189 +#define TK_TBNAME 190 +#define TK_JOIN 191 +#define TK_INSERT 192 +#define TK_INTO 193 +#define TK_VALUES 194 #define TK_SPACE 300 diff --git a/src/inc/ttype.h b/src/inc/ttype.h index 9949f31c59f5805e381fbfbd8d5a65ba24eb40eb..8def1cefe2f3b873f7138e92b4b6fb0767d6724e 100644 --- a/src/inc/ttype.h +++ b/src/inc/ttype.h @@ -10,8 +10,10 @@ extern "C" { #include "taosdef.h" // ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR -typedef int32_t VarDataOffsetT; -typedef int16_t VarDataLenT; +typedef int32_t VarDataOffsetT; +typedef int16_t VarDataLenT; // maxVarDataLen: 32767 +typedef uint16_t TDRowLenT; // not including overhead: 0 ~ 65535 +typedef uint32_t TDRowTLenT; // total length, including overhead typedef struct tstr { VarDataLenT len; @@ -28,6 +30,10 @@ typedef struct tstr { #define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT) (_len)) #define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR)) +#define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0])) +#define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v)) + + // this data type is internally used only in 'in' query to hold the values #define TSDB_DATA_TYPE_ARRAY (1000) diff --git a/src/inc/vnode.h b/src/inc/vnode.h index f31a5e36e8ba95ec12e9166471c1edd7098e58ce..b3291645c00be17283f7d078acb2d4c9a2629ece 100644 --- a/src/inc/vnode.h +++ b/src/inc/vnode.h @@ -49,7 +49,7 @@ typedef struct { SRpcMsg rpcMsg; SRspRet rspRet; char reserveForSync[24]; - SWalHead pHead; + SWalHead walHead; } SVWriteMsg; // vnodeStatus diff --git a/src/kit/shell/CMakeLists.txt b/src/kit/shell/CMakeLists.txt index 794ca5e2de1820035524cc4180558b9f290c22c6..bf2bbca14d25aff3b3717c7b9785f1dc470a013a 100644 --- a/src/kit/shell/CMakeLists.txt +++ b/src/kit/shell/CMakeLists.txt @@ -19,9 +19,9 @@ ELSE () ENDIF () IF (TD_SOMODE_STATIC) - TARGET_LINK_LIBRARIES(shell taos_static ${LINK_JEMALLOC}) + TARGET_LINK_LIBRARIES(shell taos_static lua ${LINK_JEMALLOC}) ELSE () - TARGET_LINK_LIBRARIES(shell taos ${LINK_JEMALLOC}) + TARGET_LINK_LIBRARIES(shell taos lua ${LINK_JEMALLOC}) ENDIF () SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) diff --git a/src/kit/taosdemo/CMakeLists.txt b/src/kit/taosdemo/CMakeLists.txt index 584de340947035457abd985ac93697ed51c305af..2034093ad5841c267b722930681127d745d27153 100644 --- a/src/kit/taosdemo/CMakeLists.txt +++ b/src/kit/taosdemo/CMakeLists.txt @@ -67,7 +67,7 @@ IF (TD_LINUX) ADD_EXECUTABLE(taosdemo ${SRC}) IF (TD_SOMODE_STATIC) - TARGET_LINK_LIBRARIES(taosdemo taos_static cJson ${LINK_JEMALLOC}) + TARGET_LINK_LIBRARIES(taosdemo taos_static cJson lua ${LINK_JEMALLOC}) ELSE () TARGET_LINK_LIBRARIES(taosdemo taos cJson ${LINK_JEMALLOC}) ENDIF () @@ -76,9 +76,9 @@ ELSEIF (TD_WINDOWS) ADD_EXECUTABLE(taosdemo ${SRC}) SET_SOURCE_FILES_PROPERTIES(./taosdemo.c PROPERTIES COMPILE_FLAGS -w) IF (TD_SOMODE_STATIC) - TARGET_LINK_LIBRARIES(taosdemo taos_static cJson) + TARGET_LINK_LIBRARIES(taosdemo taos_static cJson lua) ELSE () - TARGET_LINK_LIBRARIES(taosdemo taos cJson) + TARGET_LINK_LIBRARIES(taosdemo taos cJson lua) ENDIF () ELSEIF (TD_DARWIN) # missing a few dependencies, such as @@ -86,9 +86,9 @@ ELSEIF (TD_DARWIN) ADD_EXECUTABLE(taosdemo ${SRC}) IF (TD_SOMODE_STATIC) - TARGET_LINK_LIBRARIES(taosdemo taos_static cJson) + TARGET_LINK_LIBRARIES(taosdemo taos_static cJson lua) ELSE () - TARGET_LINK_LIBRARIES(taosdemo taos cJson) + TARGET_LINK_LIBRARIES(taosdemo taos cJson lua) ENDIF () ENDIF () diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 0327df5a624a2f69a0aa962390bf2835ebe35370..964f1a1d0f3811f461d5e408a8cc456a205f5b98 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -54,6 +54,7 @@ #include "tutil.h" #define STMT_IFACE_ENABLED 1 +#define NANO_SECOND_ENABLED 1 #define REQ_EXTRA_BUF_LEN 1024 #define RESP_BUF_LEN 4096 @@ -66,13 +67,6 @@ extern char configDir[]; #define STR_INSERT_INTO "INSERT INTO " -enum TEST_MODE { - INSERT_TEST, // 0 - QUERY_TEST, // 1 - SUBSCRIBE_TEST, // 2 - INVAID_TEST -}; - #define MAX_RECORDS_PER_REQ 32766 #define HEAD_BUFF_LEN TSDB_MAX_COLUMNS*24 // 16*MAX_COLUMNS + (192+32)*2 + insert into .. @@ -105,22 +99,29 @@ enum TEST_MODE { #define DEFAULT_TIMESTAMP_STEP 1 +enum TEST_MODE { + INSERT_TEST, // 0 + QUERY_TEST, // 1 + SUBSCRIBE_TEST, // 2 + INVAID_TEST +}; + typedef enum CREATE_SUB_TALBE_MOD_EN { - PRE_CREATE_SUBTBL, - AUTO_CREATE_SUBTBL, - NO_CREATE_SUBTBL + PRE_CREATE_SUBTBL, + AUTO_CREATE_SUBTBL, + NO_CREATE_SUBTBL } CREATE_SUB_TALBE_MOD_EN; typedef enum TALBE_EXISTS_EN { - TBL_NO_EXISTS, - TBL_ALREADY_EXISTS, - TBL_EXISTS_BUTT + TBL_NO_EXISTS, + TBL_ALREADY_EXISTS, + TBL_EXISTS_BUTT } TALBE_EXISTS_EN; enum enumSYNC_MODE { - SYNC_MODE, - ASYNC_MODE, - MODE_BUT + SYNC_MODE, + ASYNC_MODE, + MODE_BUT }; enum enum_TAOS_INTERFACE { @@ -143,52 +144,52 @@ typedef enum enum_PROGRESSIVE_OR_INTERLACE { } PROG_OR_INTERLACE_MODE; typedef enum enumQUERY_TYPE { - NO_INSERT_TYPE, - INSERT_TYPE, - QUERY_TYPE_BUT + NO_INSERT_TYPE, + INSERT_TYPE, + QUERY_TYPE_BUT } QUERY_TYPE; enum _show_db_index { - TSDB_SHOW_DB_NAME_INDEX, - TSDB_SHOW_DB_CREATED_TIME_INDEX, - TSDB_SHOW_DB_NTABLES_INDEX, - TSDB_SHOW_DB_VGROUPS_INDEX, - TSDB_SHOW_DB_REPLICA_INDEX, - TSDB_SHOW_DB_QUORUM_INDEX, - TSDB_SHOW_DB_DAYS_INDEX, - TSDB_SHOW_DB_KEEP_INDEX, - TSDB_SHOW_DB_CACHE_INDEX, - TSDB_SHOW_DB_BLOCKS_INDEX, - TSDB_SHOW_DB_MINROWS_INDEX, - TSDB_SHOW_DB_MAXROWS_INDEX, - TSDB_SHOW_DB_WALLEVEL_INDEX, - TSDB_SHOW_DB_FSYNC_INDEX, - TSDB_SHOW_DB_COMP_INDEX, - TSDB_SHOW_DB_CACHELAST_INDEX, - TSDB_SHOW_DB_PRECISION_INDEX, - TSDB_SHOW_DB_UPDATE_INDEX, - TSDB_SHOW_DB_STATUS_INDEX, - TSDB_MAX_SHOW_DB + TSDB_SHOW_DB_NAME_INDEX, + TSDB_SHOW_DB_CREATED_TIME_INDEX, + TSDB_SHOW_DB_NTABLES_INDEX, + TSDB_SHOW_DB_VGROUPS_INDEX, + TSDB_SHOW_DB_REPLICA_INDEX, + TSDB_SHOW_DB_QUORUM_INDEX, + TSDB_SHOW_DB_DAYS_INDEX, + TSDB_SHOW_DB_KEEP_INDEX, + TSDB_SHOW_DB_CACHE_INDEX, + TSDB_SHOW_DB_BLOCKS_INDEX, + TSDB_SHOW_DB_MINROWS_INDEX, + TSDB_SHOW_DB_MAXROWS_INDEX, + TSDB_SHOW_DB_WALLEVEL_INDEX, + TSDB_SHOW_DB_FSYNC_INDEX, + TSDB_SHOW_DB_COMP_INDEX, + TSDB_SHOW_DB_CACHELAST_INDEX, + TSDB_SHOW_DB_PRECISION_INDEX, + TSDB_SHOW_DB_UPDATE_INDEX, + TSDB_SHOW_DB_STATUS_INDEX, + TSDB_MAX_SHOW_DB }; // -----------------------------------------SHOW TABLES CONFIGURE ------------------------------------- enum _show_stables_index { - TSDB_SHOW_STABLES_NAME_INDEX, - TSDB_SHOW_STABLES_CREATED_TIME_INDEX, - TSDB_SHOW_STABLES_COLUMNS_INDEX, - TSDB_SHOW_STABLES_METRIC_INDEX, - TSDB_SHOW_STABLES_UID_INDEX, - TSDB_SHOW_STABLES_TID_INDEX, - TSDB_SHOW_STABLES_VGID_INDEX, - TSDB_MAX_SHOW_STABLES + TSDB_SHOW_STABLES_NAME_INDEX, + TSDB_SHOW_STABLES_CREATED_TIME_INDEX, + TSDB_SHOW_STABLES_COLUMNS_INDEX, + TSDB_SHOW_STABLES_METRIC_INDEX, + TSDB_SHOW_STABLES_UID_INDEX, + TSDB_SHOW_STABLES_TID_INDEX, + TSDB_SHOW_STABLES_VGID_INDEX, + TSDB_MAX_SHOW_STABLES }; enum _describe_table_index { - TSDB_DESCRIBE_METRIC_FIELD_INDEX, - TSDB_DESCRIBE_METRIC_TYPE_INDEX, - TSDB_DESCRIBE_METRIC_LENGTH_INDEX, - TSDB_DESCRIBE_METRIC_NOTE_INDEX, - TSDB_MAX_DESCRIBE_METRIC + TSDB_DESCRIBE_METRIC_FIELD_INDEX, + TSDB_DESCRIBE_METRIC_TYPE_INDEX, + TSDB_DESCRIBE_METRIC_LENGTH_INDEX, + TSDB_DESCRIBE_METRIC_NOTE_INDEX, + TSDB_MAX_DESCRIBE_METRIC }; /* Used by main to communicate with parse_opt. */ @@ -228,7 +229,7 @@ typedef struct SArguments_S { int64_t num_of_DPT; int abort; uint32_t disorderRatio; // 0: no disorder, >0: x% - int disorderRange; // ms or us by database precision + int disorderRange; // ms, us or ns. accordig to database precision uint32_t method_of_delete; char ** arg_list; uint64_t totalInsertRows; @@ -237,191 +238,191 @@ typedef struct SArguments_S { } SArguments; typedef struct SColumn_S { - char field[TSDB_COL_NAME_LEN]; - char dataType[16]; - uint32_t dataLen; - char note[128]; + char field[TSDB_COL_NAME_LEN]; + char dataType[16]; + uint32_t dataLen; + char note[128]; } StrColumn; typedef struct SSuperTable_S { - char sTblName[TSDB_TABLE_NAME_LEN]; - char dataSource[MAX_TB_NAME_SIZE]; // rand_gen or sample - char childTblPrefix[TSDB_TABLE_NAME_LEN - 20]; // 20 characters reserved for seq - char insertMode[MAX_TB_NAME_SIZE]; // taosc, rest - uint16_t childTblExists; - int64_t childTblCount; - uint64_t batchCreateTableNum; // 0: no batch, > 0: batch table number in one sql - uint8_t autoCreateTable; // 0: create sub table, 1: auto create sub table - uint16_t iface; // 0: taosc, 1: rest, 2: stmt - int64_t childTblLimit; - uint64_t childTblOffset; - -// int multiThreadWriteOneTbl; // 0: no, 1: yes - uint32_t interlaceRows; // - int disorderRatio; // 0: no disorder, >0: x% - int disorderRange; // ms or us by database precision - uint64_t maxSqlLen; // - - uint64_t insertInterval; // insert interval, will override global insert interval - int64_t insertRows; - int64_t timeStampStep; - char startTimestamp[MAX_TB_NAME_SIZE]; - char sampleFormat[MAX_TB_NAME_SIZE]; // csv, json - char sampleFile[MAX_FILE_NAME_LEN]; - char tagsFile[MAX_FILE_NAME_LEN]; - - uint32_t columnCount; - StrColumn columns[TSDB_MAX_COLUMNS]; - uint32_t tagCount; - StrColumn tags[TSDB_MAX_TAGS]; - - char* childTblName; - char* colsOfCreateChildTable; - uint64_t lenOfOneRow; - uint64_t lenOfTagOfOneRow; - - char* sampleDataBuf; - //int sampleRowCount; - //int sampleUsePos; - - uint32_t tagSource; // 0: rand, 1: tag sample - char* tagDataBuf; - uint32_t tagSampleCount; - uint32_t tagUsePos; - - // statistics - uint64_t totalInsertRows; - uint64_t totalAffectedRows; + char sTblName[TSDB_TABLE_NAME_LEN]; + char dataSource[MAX_TB_NAME_SIZE]; // rand_gen or sample + char childTblPrefix[TSDB_TABLE_NAME_LEN - 20]; // 20 characters reserved for seq + char insertMode[MAX_TB_NAME_SIZE]; // taosc, rest + uint16_t childTblExists; + int64_t childTblCount; + uint64_t batchCreateTableNum; // 0: no batch, > 0: batch table number in one sql + uint8_t autoCreateTable; // 0: create sub table, 1: auto create sub table + uint16_t iface; // 0: taosc, 1: rest, 2: stmt + int64_t childTblLimit; + uint64_t childTblOffset; + + // int multiThreadWriteOneTbl; // 0: no, 1: yes + uint32_t interlaceRows; // + int disorderRatio; // 0: no disorder, >0: x% + int disorderRange; // ms, us or ns. according to database precision + uint64_t maxSqlLen; // + + uint64_t insertInterval; // insert interval, will override global insert interval + int64_t insertRows; + int64_t timeStampStep; + char startTimestamp[MAX_TB_NAME_SIZE]; + char sampleFormat[MAX_TB_NAME_SIZE]; // csv, json + char sampleFile[MAX_FILE_NAME_LEN]; + char tagsFile[MAX_FILE_NAME_LEN]; + + uint32_t columnCount; + StrColumn columns[TSDB_MAX_COLUMNS]; + uint32_t tagCount; + StrColumn tags[TSDB_MAX_TAGS]; + + char* childTblName; + char* colsOfCreateChildTable; + uint64_t lenOfOneRow; + uint64_t lenOfTagOfOneRow; + + char* sampleDataBuf; + //int sampleRowCount; + //int sampleUsePos; + + uint32_t tagSource; // 0: rand, 1: tag sample + char* tagDataBuf; + uint32_t tagSampleCount; + uint32_t tagUsePos; + + // statistics + uint64_t totalInsertRows; + uint64_t totalAffectedRows; } SSuperTable; typedef struct { - char name[TSDB_DB_NAME_LEN]; - char create_time[32]; - int64_t ntables; - int32_t vgroups; - int16_t replica; - int16_t quorum; - int16_t days; - char keeplist[32]; - int32_t cache; //MB - int32_t blocks; - int32_t minrows; - int32_t maxrows; - int8_t wallevel; - int32_t fsync; - int8_t comp; - int8_t cachelast; - char precision[8]; // time resolution - int8_t update; - char status[16]; + char name[TSDB_DB_NAME_LEN]; + char create_time[32]; + int64_t ntables; + int32_t vgroups; + int16_t replica; + int16_t quorum; + int16_t days; + char keeplist[32]; + int32_t cache; //MB + int32_t blocks; + int32_t minrows; + int32_t maxrows; + int8_t wallevel; + int32_t fsync; + int8_t comp; + int8_t cachelast; + char precision[8]; // time resolution + int8_t update; + char status[16]; } SDbInfo; typedef struct SDbCfg_S { -// int maxtablesPerVnode; - uint32_t minRows; // 0 means default - uint32_t maxRows; // 0 means default - int comp; - int walLevel; - int cacheLast; - int fsync; - int replica; - int update; - int keep; - int days; - int cache; - int blocks; - int quorum; - char precision[8]; + // int maxtablesPerVnode; + uint32_t minRows; // 0 means default + uint32_t maxRows; // 0 means default + int comp; + int walLevel; + int cacheLast; + int fsync; + int replica; + int update; + int keep; + int days; + int cache; + int blocks; + int quorum; + char precision[8]; } SDbCfg; typedef struct SDataBase_S { - char dbName[TSDB_DB_NAME_LEN]; - bool drop; // 0: use exists, 1: if exists, drop then new create - SDbCfg dbCfg; - uint64_t superTblCount; - SSuperTable superTbls[MAX_SUPER_TABLE_COUNT]; + char dbName[TSDB_DB_NAME_LEN]; + bool drop; // 0: use exists, 1: if exists, drop then new create + SDbCfg dbCfg; + uint64_t superTblCount; + SSuperTable superTbls[MAX_SUPER_TABLE_COUNT]; } SDataBase; typedef struct SDbs_S { - char cfgDir[MAX_FILE_NAME_LEN]; - char host[MAX_HOSTNAME_SIZE]; - struct sockaddr_in serv_addr; - - uint16_t port; - char user[MAX_USERNAME_SIZE]; - char password[MAX_PASSWORD_SIZE]; - char resultFile[MAX_FILE_NAME_LEN]; - bool use_metric; - bool insert_only; - bool do_aggreFunc; - bool asyncMode; - - uint32_t threadCount; - uint32_t threadCountByCreateTbl; - uint32_t dbCount; - SDataBase db[MAX_DB_COUNT]; - - // statistics - uint64_t totalInsertRows; - uint64_t totalAffectedRows; + char cfgDir[MAX_FILE_NAME_LEN]; + char host[MAX_HOSTNAME_SIZE]; + struct sockaddr_in serv_addr; + + uint16_t port; + char user[MAX_USERNAME_SIZE]; + char password[MAX_PASSWORD_SIZE]; + char resultFile[MAX_FILE_NAME_LEN]; + bool use_metric; + bool insert_only; + bool do_aggreFunc; + bool asyncMode; + + uint32_t threadCount; + uint32_t threadCountByCreateTbl; + uint32_t dbCount; + SDataBase db[MAX_DB_COUNT]; + + // statistics + uint64_t totalInsertRows; + uint64_t totalAffectedRows; } SDbs; typedef struct SpecifiedQueryInfo_S { - uint64_t queryInterval; // 0: unlimit > 0 loop/s - uint32_t concurrent; - int sqlCount; - uint32_t asyncMode; // 0: sync, 1: async - uint64_t subscribeInterval; // ms - uint64_t queryTimes; - bool subscribeRestart; - int subscribeKeepProgress; - char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; - char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN]; - int resubAfterConsume[MAX_QUERY_SQL_COUNT]; - int endAfterConsume[MAX_QUERY_SQL_COUNT]; - TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; - char topic[MAX_QUERY_SQL_COUNT][32]; - int consumed[MAX_QUERY_SQL_COUNT]; - TAOS_RES* res[MAX_QUERY_SQL_COUNT]; - uint64_t totalQueried; + uint64_t queryInterval; // 0: unlimit > 0 loop/s + uint32_t concurrent; + int sqlCount; + uint32_t asyncMode; // 0: sync, 1: async + uint64_t subscribeInterval; // ms + uint64_t queryTimes; + bool subscribeRestart; + int subscribeKeepProgress; + char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; + char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN]; + int resubAfterConsume[MAX_QUERY_SQL_COUNT]; + int endAfterConsume[MAX_QUERY_SQL_COUNT]; + TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; + char topic[MAX_QUERY_SQL_COUNT][32]; + int consumed[MAX_QUERY_SQL_COUNT]; + TAOS_RES* res[MAX_QUERY_SQL_COUNT]; + uint64_t totalQueried; } SpecifiedQueryInfo; typedef struct SuperQueryInfo_S { - char sTblName[TSDB_TABLE_NAME_LEN]; - uint64_t queryInterval; // 0: unlimit > 0 loop/s - uint32_t threadCnt; - uint32_t asyncMode; // 0: sync, 1: async - uint64_t subscribeInterval; // ms - bool subscribeRestart; - int subscribeKeepProgress; - uint64_t queryTimes; - int64_t childTblCount; - char childTblPrefix[TSDB_TABLE_NAME_LEN - 20]; // 20 characters reserved for seq - int sqlCount; - char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; - char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN]; - int resubAfterConsume; - int endAfterConsume; - TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; - - char* childTblName; - uint64_t totalQueried; + char sTblName[TSDB_TABLE_NAME_LEN]; + uint64_t queryInterval; // 0: unlimit > 0 loop/s + uint32_t threadCnt; + uint32_t asyncMode; // 0: sync, 1: async + uint64_t subscribeInterval; // ms + bool subscribeRestart; + int subscribeKeepProgress; + uint64_t queryTimes; + int64_t childTblCount; + char childTblPrefix[TSDB_TABLE_NAME_LEN - 20]; // 20 characters reserved for seq + int sqlCount; + char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; + char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN]; + int resubAfterConsume; + int endAfterConsume; + TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; + + char* childTblName; + uint64_t totalQueried; } SuperQueryInfo; typedef struct SQueryMetaInfo_S { - char cfgDir[MAX_FILE_NAME_LEN]; - char host[MAX_HOSTNAME_SIZE]; - uint16_t port; - struct sockaddr_in serv_addr; - char user[MAX_USERNAME_SIZE]; - char password[MAX_PASSWORD_SIZE]; - char dbName[TSDB_DB_NAME_LEN]; - char queryMode[MAX_TB_NAME_SIZE]; // taosc, rest - - SpecifiedQueryInfo specifiedQueryInfo; - SuperQueryInfo superQueryInfo; - uint64_t totalQueried; + char cfgDir[MAX_FILE_NAME_LEN]; + char host[MAX_HOSTNAME_SIZE]; + uint16_t port; + struct sockaddr_in serv_addr; + char user[MAX_USERNAME_SIZE]; + char password[MAX_PASSWORD_SIZE]; + char dbName[TSDB_DB_NAME_LEN]; + char queryMode[MAX_TB_NAME_SIZE]; // taosc, rest + + SpecifiedQueryInfo specifiedQueryInfo; + SuperQueryInfo superQueryInfo; + uint64_t totalQueried; } SQueryMetaInfo; typedef struct SThreadInfo_S { @@ -637,7 +638,7 @@ static FILE * g_fpOfInsertResult = NULL; #define performancePrint(fmt, ...) \ do { if (g_args.performance_print) \ - fprintf(stderr, "VERB: "fmt, __VA_ARGS__); } while(0) + fprintf(stderr, "PERF: "fmt, __VA_ARGS__); } while(0) #define errorPrint(fmt, ...) \ do { fprintf(stderr, "ERROR: "fmt, __VA_ARGS__); } while(0) @@ -1140,7 +1141,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { if (arguments->disorderRatio) { printf("# Data order: %d\n", arguments->disorderRatio); printf("# Data out of order rate: %d\n", arguments->disorderRange); - } printf("# Delete method: %d\n", arguments->method_of_delete); printf("# Answer yes when prompt: %d\n", arguments->answer_yes); @@ -1513,7 +1513,10 @@ static int printfInsertMeta() { } if (g_Dbs.db[i].dbCfg.precision[0] != 0) { if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", 2)) - || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "us", 2))) { +#if NANO_SECOND_ENABLED == 1 + || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "us", 2)) +#endif + || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ns", 2))) { printf(" precision: \033[33m%s\033[0m\n", g_Dbs.db[i].dbCfg.precision); } else { @@ -1703,6 +1706,9 @@ static void printfInsertMetaToFile(FILE* fp) { } if (g_Dbs.db[i].dbCfg.precision[0] != 0) { if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", 2)) +#if NANO_SECOND_ENABLED == 1 + || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ns", 2)) +#endif || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "us", 2))) { fprintf(fp, " precision: %s\n", g_Dbs.db[i].dbCfg.precision); @@ -1903,10 +1909,12 @@ static void printfQueryMeta() { static char* formatTimestamp(char* buf, int64_t val, int precision) { time_t tt; - if (precision == TSDB_TIME_PRECISION_NANO) { - tt = (time_t)(val / 1000000000); - } else if (precision == TSDB_TIME_PRECISION_MICRO) { + if (precision == TSDB_TIME_PRECISION_MICRO) { tt = (time_t)(val / 1000000); +#if NANO_SECOND_ENABLED == 1 + } if (precision == TSDB_TIME_PRECISION_NANO) { + tt = (time_t)(val / 1000000000); +#endif } else { tt = (time_t)(val / 1000); } @@ -1926,10 +1934,12 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { struct tm* ptm = localtime(&tt); size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm); - if (precision == TSDB_TIME_PRECISION_NANO) { - sprintf(buf + pos, ".%09d", (int)(val % 1000000000)); - } else if (precision == TSDB_TIME_PRECISION_MICRO) { + if (precision == TSDB_TIME_PRECISION_MICRO) { sprintf(buf + pos, ".%06d", (int)(val % 1000000)); +#if NANO_SECOND_ENABLED == 1 + } else if (precision == TSDB_TIME_PRECISION_NANO) { + sprintf(buf + pos, ".%09d", (int)(val % 1000000000)); +#endif } else { sprintf(buf + pos, ".%03d", (int)(val % 1000)); } @@ -2185,7 +2195,6 @@ static void printfQuerySystemInfo(TAOS * taos) { snprintf(buffer, MAX_QUERY_SQL_LENGTH, "show %s.stables;", dbInfos[i]->name); res = taos_query(taos, buffer); xDumpResultToFile(filename, res); - free(dbInfos[i]); } @@ -2806,7 +2815,7 @@ static int createSuperTable( if (strcasecmp(dataType, "BINARY") == 0) { if ((g_args.demo_mode) && (tagIndex == 1)) { len += snprintf(tags + len, STRING_LEN - len, - "loction BINARY(%d), ", + "location BINARY(%d), ", superTbl->tags[tagIndex].dataLen); } else { len += snprintf(tags + len, STRING_LEN - len, "t%d %s(%d), ", @@ -2875,134 +2884,138 @@ static int createSuperTable( } static int createDatabasesAndStables() { - TAOS * taos = NULL; - int ret = 0; - taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, NULL, g_Dbs.port); - if (taos == NULL) { - errorPrint( "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); - return -1; - } - char command[BUFFER_SIZE] = "\0"; - - for (int i = 0; i < g_Dbs.dbCount; i++) { - if (g_Dbs.db[i].drop) { - sprintf(command, "drop database if exists %s;", g_Dbs.db[i].dbName); - if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { - taos_close(taos); + TAOS * taos = NULL; + int ret = 0; + taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, NULL, g_Dbs.port); + if (taos == NULL) { + errorPrint( "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); return -1; - } + } + char command[BUFFER_SIZE] = "\0"; - int dataLen = 0; - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, "create database if not exists %s", g_Dbs.db[i].dbName); + for (int i = 0; i < g_Dbs.dbCount; i++) { + if (g_Dbs.db[i].drop) { + sprintf(command, "drop database if exists %s;", g_Dbs.db[i].dbName); + if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { + taos_close(taos); + return -1; + } - if (g_Dbs.db[i].dbCfg.blocks > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " blocks %d", g_Dbs.db[i].dbCfg.blocks); - } - if (g_Dbs.db[i].dbCfg.cache > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " cache %d", g_Dbs.db[i].dbCfg.cache); - } - if (g_Dbs.db[i].dbCfg.days > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " days %d", g_Dbs.db[i].dbCfg.days); - } - if (g_Dbs.db[i].dbCfg.keep > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " keep %d", g_Dbs.db[i].dbCfg.keep); - } - if (g_Dbs.db[i].dbCfg.quorum > 1) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " quorum %d", g_Dbs.db[i].dbCfg.quorum); - } - if (g_Dbs.db[i].dbCfg.replica > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " replica %d", g_Dbs.db[i].dbCfg.replica); - } - if (g_Dbs.db[i].dbCfg.update > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " update %d", g_Dbs.db[i].dbCfg.update); - } - //if (g_Dbs.db[i].dbCfg.maxtablesPerVnode > 0) { - // dataLen += snprintf(command + dataLen, - // BUFFER_SIZE - dataLen, "tables %d ", g_Dbs.db[i].dbCfg.maxtablesPerVnode); - //} - if (g_Dbs.db[i].dbCfg.minRows > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " minrows %d", g_Dbs.db[i].dbCfg.minRows); - } - if (g_Dbs.db[i].dbCfg.maxRows > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " maxrows %d", g_Dbs.db[i].dbCfg.maxRows); - } - if (g_Dbs.db[i].dbCfg.comp > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " comp %d", g_Dbs.db[i].dbCfg.comp); - } - if (g_Dbs.db[i].dbCfg.walLevel > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " wal %d", g_Dbs.db[i].dbCfg.walLevel); - } - if (g_Dbs.db[i].dbCfg.cacheLast > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " cachelast %d", g_Dbs.db[i].dbCfg.cacheLast); - } - if (g_Dbs.db[i].dbCfg.fsync > 0) { - dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, - " fsync %d", g_Dbs.db[i].dbCfg.fsync); - } - if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", strlen("ms"))) - || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, - "us", strlen("us")))) { - dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, - " precision \'%s\';", g_Dbs.db[i].dbCfg.precision); - } + int dataLen = 0; + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, "create database if not exists %s", g_Dbs.db[i].dbName); - if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { - taos_close(taos); - errorPrint( "\ncreate database %s failed!\n\n", g_Dbs.db[i].dbName); - return -1; - } - printf("\ncreate database %s success!\n\n", g_Dbs.db[i].dbName); - } + if (g_Dbs.db[i].dbCfg.blocks > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " blocks %d", g_Dbs.db[i].dbCfg.blocks); + } + if (g_Dbs.db[i].dbCfg.cache > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " cache %d", g_Dbs.db[i].dbCfg.cache); + } + if (g_Dbs.db[i].dbCfg.days > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " days %d", g_Dbs.db[i].dbCfg.days); + } + if (g_Dbs.db[i].dbCfg.keep > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " keep %d", g_Dbs.db[i].dbCfg.keep); + } + if (g_Dbs.db[i].dbCfg.quorum > 1) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " quorum %d", g_Dbs.db[i].dbCfg.quorum); + } + if (g_Dbs.db[i].dbCfg.replica > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " replica %d", g_Dbs.db[i].dbCfg.replica); + } + if (g_Dbs.db[i].dbCfg.update > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " update %d", g_Dbs.db[i].dbCfg.update); + } + //if (g_Dbs.db[i].dbCfg.maxtablesPerVnode > 0) { + // dataLen += snprintf(command + dataLen, + // BUFFER_SIZE - dataLen, "tables %d ", g_Dbs.db[i].dbCfg.maxtablesPerVnode); + //} + if (g_Dbs.db[i].dbCfg.minRows > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " minrows %d", g_Dbs.db[i].dbCfg.minRows); + } + if (g_Dbs.db[i].dbCfg.maxRows > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " maxrows %d", g_Dbs.db[i].dbCfg.maxRows); + } + if (g_Dbs.db[i].dbCfg.comp > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " comp %d", g_Dbs.db[i].dbCfg.comp); + } + if (g_Dbs.db[i].dbCfg.walLevel > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " wal %d", g_Dbs.db[i].dbCfg.walLevel); + } + if (g_Dbs.db[i].dbCfg.cacheLast > 0) { + dataLen += snprintf(command + dataLen, + BUFFER_SIZE - dataLen, " cachelast %d", g_Dbs.db[i].dbCfg.cacheLast); + } + if (g_Dbs.db[i].dbCfg.fsync > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " fsync %d", g_Dbs.db[i].dbCfg.fsync); + } + if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", strlen("ms"))) +#if NANO_SECOND_ENABLED == 1 + || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, + "ns", strlen("ns"))) +#endif + || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, + "us", strlen("us")))) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " precision \'%s\';", g_Dbs.db[i].dbCfg.precision); + } - debugPrint("%s() LN%d supertbl count:%"PRIu64"\n", - __func__, __LINE__, g_Dbs.db[i].superTblCount); + if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { + taos_close(taos); + errorPrint( "\ncreate database %s failed!\n\n", g_Dbs.db[i].dbName); + return -1; + } + printf("\ncreate database %s success!\n\n", g_Dbs.db[i].dbName); + } - int validStbCount = 0; + debugPrint("%s() LN%d supertbl count:%"PRIu64"\n", + __func__, __LINE__, g_Dbs.db[i].superTblCount); - for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { - sprintf(command, "describe %s.%s;", g_Dbs.db[i].dbName, - g_Dbs.db[i].superTbls[j].sTblName); - ret = queryDbExec(taos, command, NO_INSERT_TYPE, true); + int validStbCount = 0; - if ((ret != 0) || (g_Dbs.db[i].drop)) { - ret = createSuperTable(taos, g_Dbs.db[i].dbName, - &g_Dbs.db[i].superTbls[j]); + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { + sprintf(command, "describe %s.%s;", g_Dbs.db[i].dbName, + g_Dbs.db[i].superTbls[j].sTblName); + ret = queryDbExec(taos, command, NO_INSERT_TYPE, true); - if (0 != ret) { - errorPrint("create super table %"PRIu64" failed!\n\n", j); - continue; - } - } + if ((ret != 0) || (g_Dbs.db[i].drop)) { + ret = createSuperTable(taos, g_Dbs.db[i].dbName, + &g_Dbs.db[i].superTbls[j]); - ret = getSuperTableFromServer(taos, g_Dbs.db[i].dbName, - &g_Dbs.db[i].superTbls[j]); - if (0 != ret) { - errorPrint("\nget super table %s.%s info failed!\n\n", - g_Dbs.db[i].dbName, g_Dbs.db[i].superTbls[j].sTblName); - continue; - } + if (0 != ret) { + errorPrint("create super table %"PRIu64" failed!\n\n", j); + continue; + } + } - validStbCount ++; - } + ret = getSuperTableFromServer(taos, g_Dbs.db[i].dbName, + &g_Dbs.db[i].superTbls[j]); + if (0 != ret) { + errorPrint("\nget super table %s.%s info failed!\n\n", + g_Dbs.db[i].dbName, g_Dbs.db[i].superTbls[j].sTblName); + continue; + } - g_Dbs.db[i].superTblCount = validStbCount; - } + validStbCount ++; + } - taos_close(taos); - return 0; + g_Dbs.db[i].superTblCount = validStbCount; + } + + taos_close(taos); + return 0; } static void* createTable(void *sarg) @@ -3183,8 +3196,10 @@ static void createChildTables() { if (g_Dbs.db[i].superTblCount > 0) { // with super table for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { - if ((AUTO_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) - || (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists)) { + if ((AUTO_CREATE_SUBTBL + == g_Dbs.db[i].superTbls[j].autoCreateTable) + || (TBL_ALREADY_EXISTS + == g_Dbs.db[i].superTbls[j].childTblExists)) { continue; } verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, @@ -3528,733 +3543,733 @@ PARSE_OVER: } static bool getMetaFromInsertJsonFile(cJSON* root) { - bool ret = false; - - cJSON* cfgdir = cJSON_GetObjectItem(root, "cfgdir"); - if (cfgdir && cfgdir->type == cJSON_String && cfgdir->valuestring != NULL) { - tstrncpy(g_Dbs.cfgDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); - } - - cJSON* host = cJSON_GetObjectItem(root, "host"); - if (host && host->type == cJSON_String && host->valuestring != NULL) { - tstrncpy(g_Dbs.host, host->valuestring, MAX_HOSTNAME_SIZE); - } else if (!host) { - tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE); - } else { - printf("ERROR: failed to read json, host not found\n"); - goto PARSE_OVER; - } - - cJSON* port = cJSON_GetObjectItem(root, "port"); - if (port && port->type == cJSON_Number) { - g_Dbs.port = port->valueint; - } else if (!port) { - g_Dbs.port = 6030; - } - - cJSON* user = cJSON_GetObjectItem(root, "user"); - if (user && user->type == cJSON_String && user->valuestring != NULL) { - tstrncpy(g_Dbs.user, user->valuestring, MAX_USERNAME_SIZE); - } else if (!user) { - tstrncpy(g_Dbs.user, "root", MAX_USERNAME_SIZE); - } - - cJSON* password = cJSON_GetObjectItem(root, "password"); - if (password && password->type == cJSON_String && password->valuestring != NULL) { - tstrncpy(g_Dbs.password, password->valuestring, MAX_PASSWORD_SIZE); - } else if (!password) { - tstrncpy(g_Dbs.password, "taosdata", MAX_PASSWORD_SIZE); - } - - cJSON* resultfile = cJSON_GetObjectItem(root, "result_file"); - if (resultfile && resultfile->type == cJSON_String && resultfile->valuestring != NULL) { - tstrncpy(g_Dbs.resultFile, resultfile->valuestring, MAX_FILE_NAME_LEN); - } else if (!resultfile) { - tstrncpy(g_Dbs.resultFile, "./insert_res.txt", MAX_FILE_NAME_LEN); - } - - cJSON* threads = cJSON_GetObjectItem(root, "thread_count"); - if (threads && threads->type == cJSON_Number) { - g_Dbs.threadCount = threads->valueint; - } else if (!threads) { - g_Dbs.threadCount = 1; - } else { - printf("ERROR: failed to read json, threads not found\n"); - goto PARSE_OVER; - } - - cJSON* threads2 = cJSON_GetObjectItem(root, "thread_count_create_tbl"); - if (threads2 && threads2->type == cJSON_Number) { - g_Dbs.threadCountByCreateTbl = threads2->valueint; - } else if (!threads2) { - g_Dbs.threadCountByCreateTbl = 1; - } else { - errorPrint("%s() LN%d, failed to read json, threads2 not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } - - cJSON* gInsertInterval = cJSON_GetObjectItem(root, "insert_interval"); - if (gInsertInterval && gInsertInterval->type == cJSON_Number) { - if (gInsertInterval->valueint <0) { - errorPrint("%s() LN%d, failed to read json, insert interval input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - g_args.insert_interval = gInsertInterval->valueint; - } else if (!gInsertInterval) { - g_args.insert_interval = 0; - } else { - errorPrint("%s() LN%d, failed to read json, insert_interval input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - - cJSON* interlaceRows = cJSON_GetObjectItem(root, "interlace_rows"); - if (interlaceRows && interlaceRows->type == cJSON_Number) { - if (interlaceRows->valueint < 0) { - errorPrint("%s() LN%d, failed to read json, interlace_rows input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; + bool ret = false; + cJSON* cfgdir = cJSON_GetObjectItem(root, "cfgdir"); + if (cfgdir && cfgdir->type == cJSON_String && cfgdir->valuestring != NULL) { + tstrncpy(g_Dbs.cfgDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); } - g_args.interlace_rows = interlaceRows->valueint; - } else if (!interlaceRows) { - g_args.interlace_rows = 0; // 0 means progressive mode, > 0 mean interlace mode. max value is less or equ num_of_records_per_req - } else { - errorPrint("%s() LN%d, failed to read json, interlace_rows input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - - cJSON* maxSqlLen = cJSON_GetObjectItem(root, "max_sql_len"); - if (maxSqlLen && maxSqlLen->type == cJSON_Number) { - if (maxSqlLen->valueint < 0) { - errorPrint("%s() LN%d, failed to read json, max_sql_len input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - g_args.max_sql_len = maxSqlLen->valueint; - } else if (!maxSqlLen) { - g_args.max_sql_len = (1024*1024); - } else { - errorPrint("%s() LN%d, failed to read json, max_sql_len input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - - cJSON* numRecPerReq = cJSON_GetObjectItem(root, "num_of_records_per_req"); - if (numRecPerReq && numRecPerReq->type == cJSON_Number) { - if (numRecPerReq->valueint <= 0) { - errorPrint("%s() LN%d, failed to read json, num_of_records_per_req input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } else if (numRecPerReq->valueint > MAX_RECORDS_PER_REQ) { - printf("NOTICE: number of records per request value %"PRIu64" > %d\n\n", - numRecPerReq->valueint, MAX_RECORDS_PER_REQ); - printf(" number of records per request value will be set to %d\n\n", - MAX_RECORDS_PER_REQ); - prompt(); - numRecPerReq->valueint = MAX_RECORDS_PER_REQ; - } - g_args.num_of_RPR = numRecPerReq->valueint; - } else if (!numRecPerReq) { - g_args.num_of_RPR = MAX_RECORDS_PER_REQ; - } else { - errorPrint("%s() LN%d, failed to read json, num_of_records_per_req not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } - cJSON *answerPrompt = cJSON_GetObjectItem(root, "confirm_parameter_prompt"); // yes, no, - if (answerPrompt - && answerPrompt->type == cJSON_String - && answerPrompt->valuestring != NULL) { - if (0 == strncasecmp(answerPrompt->valuestring, "yes", 3)) { - g_args.answer_yes = false; - } else if (0 == strncasecmp(answerPrompt->valuestring, "no", 2)) { - g_args.answer_yes = true; + cJSON* host = cJSON_GetObjectItem(root, "host"); + if (host && host->type == cJSON_String && host->valuestring != NULL) { + tstrncpy(g_Dbs.host, host->valuestring, MAX_HOSTNAME_SIZE); + } else if (!host) { + tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE); } else { - g_args.answer_yes = false; - } - } else if (!answerPrompt) { - g_args.answer_yes = true; // default is no, mean answer_yes. - } else { - errorPrint("%s", "failed to read json, confirm_parameter_prompt input mistake\n"); - goto PARSE_OVER; - } - - // rows per table need be less than insert batch - if (g_args.interlace_rows > g_args.num_of_RPR) { - printf("NOTICE: interlace rows value %u > num_of_records_per_req %u\n\n", - g_args.interlace_rows, g_args.num_of_RPR); - printf(" interlace rows value will be set to num_of_records_per_req %u\n\n", - g_args.num_of_RPR); - prompt(); - g_args.interlace_rows = g_args.num_of_RPR; - } - - cJSON* dbs = cJSON_GetObjectItem(root, "databases"); - if (!dbs || dbs->type != cJSON_Array) { - printf("ERROR: failed to read json, databases not found\n"); - goto PARSE_OVER; - } - - int dbSize = cJSON_GetArraySize(dbs); - if (dbSize > MAX_DB_COUNT) { - errorPrint( - "ERROR: failed to read json, databases size overflow, max database is %d\n", - MAX_DB_COUNT); - goto PARSE_OVER; - } - - g_Dbs.dbCount = dbSize; - for (int i = 0; i < dbSize; ++i) { - cJSON* dbinfos = cJSON_GetArrayItem(dbs, i); - if (dbinfos == NULL) continue; - - // dbinfo - cJSON *dbinfo = cJSON_GetObjectItem(dbinfos, "dbinfo"); - if (!dbinfo || dbinfo->type != cJSON_Object) { - printf("ERROR: failed to read json, dbinfo not found\n"); - goto PARSE_OVER; - } - - cJSON *dbName = cJSON_GetObjectItem(dbinfo, "name"); - if (!dbName || dbName->type != cJSON_String || dbName->valuestring == NULL) { - printf("ERROR: failed to read json, db name not found\n"); - goto PARSE_OVER; + printf("ERROR: failed to read json, host not found\n"); + goto PARSE_OVER; } - tstrncpy(g_Dbs.db[i].dbName, dbName->valuestring, TSDB_DB_NAME_LEN); - cJSON *drop = cJSON_GetObjectItem(dbinfo, "drop"); - if (drop && drop->type == cJSON_String && drop->valuestring != NULL) { - if (0 == strncasecmp(drop->valuestring, "yes", strlen("yes"))) { - g_Dbs.db[i].drop = true; - } else { - g_Dbs.db[i].drop = false; - } - } else if (!drop) { - g_Dbs.db[i].drop = g_args.drop_database; - } else { - errorPrint("%s() LN%d, failed to read json, drop input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; + cJSON* port = cJSON_GetObjectItem(root, "port"); + if (port && port->type == cJSON_Number) { + g_Dbs.port = port->valueint; + } else if (!port) { + g_Dbs.port = 6030; } - cJSON *precision = cJSON_GetObjectItem(dbinfo, "precision"); - if (precision && precision->type == cJSON_String - && precision->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].dbCfg.precision, precision->valuestring, - 8); - } else if (!precision) { - memset(g_Dbs.db[i].dbCfg.precision, 0, 8); - } else { - printf("ERROR: failed to read json, precision not found\n"); - goto PARSE_OVER; + cJSON* user = cJSON_GetObjectItem(root, "user"); + if (user && user->type == cJSON_String && user->valuestring != NULL) { + tstrncpy(g_Dbs.user, user->valuestring, MAX_USERNAME_SIZE); + } else if (!user) { + tstrncpy(g_Dbs.user, "root", MAX_USERNAME_SIZE); } - cJSON* update = cJSON_GetObjectItem(dbinfo, "update"); - if (update && update->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.update = update->valueint; - } else if (!update) { - g_Dbs.db[i].dbCfg.update = -1; - } else { - printf("ERROR: failed to read json, update not found\n"); - goto PARSE_OVER; + cJSON* password = cJSON_GetObjectItem(root, "password"); + if (password && password->type == cJSON_String && password->valuestring != NULL) { + tstrncpy(g_Dbs.password, password->valuestring, MAX_PASSWORD_SIZE); + } else if (!password) { + tstrncpy(g_Dbs.password, "taosdata", MAX_PASSWORD_SIZE); } - cJSON* replica = cJSON_GetObjectItem(dbinfo, "replica"); - if (replica && replica->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.replica = replica->valueint; - } else if (!replica) { - g_Dbs.db[i].dbCfg.replica = -1; - } else { - printf("ERROR: failed to read json, replica not found\n"); - goto PARSE_OVER; + cJSON* resultfile = cJSON_GetObjectItem(root, "result_file"); + if (resultfile && resultfile->type == cJSON_String && resultfile->valuestring != NULL) { + tstrncpy(g_Dbs.resultFile, resultfile->valuestring, MAX_FILE_NAME_LEN); + } else if (!resultfile) { + tstrncpy(g_Dbs.resultFile, "./insert_res.txt", MAX_FILE_NAME_LEN); } - cJSON* keep = cJSON_GetObjectItem(dbinfo, "keep"); - if (keep && keep->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.keep = keep->valueint; - } else if (!keep) { - g_Dbs.db[i].dbCfg.keep = -1; + cJSON* threads = cJSON_GetObjectItem(root, "thread_count"); + if (threads && threads->type == cJSON_Number) { + g_Dbs.threadCount = threads->valueint; + } else if (!threads) { + g_Dbs.threadCount = 1; } else { - printf("ERROR: failed to read json, keep not found\n"); - goto PARSE_OVER; + printf("ERROR: failed to read json, threads not found\n"); + goto PARSE_OVER; } - cJSON* days = cJSON_GetObjectItem(dbinfo, "days"); - if (days && days->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.days = days->valueint; - } else if (!days) { - g_Dbs.db[i].dbCfg.days = -1; + cJSON* threads2 = cJSON_GetObjectItem(root, "thread_count_create_tbl"); + if (threads2 && threads2->type == cJSON_Number) { + g_Dbs.threadCountByCreateTbl = threads2->valueint; + } else if (!threads2) { + g_Dbs.threadCountByCreateTbl = 1; } else { - printf("ERROR: failed to read json, days not found\n"); - goto PARSE_OVER; + errorPrint("%s() LN%d, failed to read json, threads2 not found\n", + __func__, __LINE__); + goto PARSE_OVER; } - cJSON* cache = cJSON_GetObjectItem(dbinfo, "cache"); - if (cache && cache->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.cache = cache->valueint; - } else if (!cache) { - g_Dbs.db[i].dbCfg.cache = -1; + cJSON* gInsertInterval = cJSON_GetObjectItem(root, "insert_interval"); + if (gInsertInterval && gInsertInterval->type == cJSON_Number) { + if (gInsertInterval->valueint <0) { + errorPrint("%s() LN%d, failed to read json, insert interval input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + g_args.insert_interval = gInsertInterval->valueint; + } else if (!gInsertInterval) { + g_args.insert_interval = 0; } else { - printf("ERROR: failed to read json, cache not found\n"); - goto PARSE_OVER; + errorPrint("%s() LN%d, failed to read json, insert_interval input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; } - cJSON* blocks= cJSON_GetObjectItem(dbinfo, "blocks"); - if (blocks && blocks->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.blocks = blocks->valueint; - } else if (!blocks) { - g_Dbs.db[i].dbCfg.blocks = -1; - } else { - printf("ERROR: failed to read json, block not found\n"); - goto PARSE_OVER; - } - - //cJSON* maxtablesPerVnode= cJSON_GetObjectItem(dbinfo, "maxtablesPerVnode"); - //if (maxtablesPerVnode && maxtablesPerVnode->type == cJSON_Number) { - // g_Dbs.db[i].dbCfg.maxtablesPerVnode = maxtablesPerVnode->valueint; - //} else if (!maxtablesPerVnode) { - // g_Dbs.db[i].dbCfg.maxtablesPerVnode = TSDB_DEFAULT_TABLES; - //} else { - // printf("failed to read json, maxtablesPerVnode not found"); - // goto PARSE_OVER; - //} + cJSON* interlaceRows = cJSON_GetObjectItem(root, "interlace_rows"); + if (interlaceRows && interlaceRows->type == cJSON_Number) { + if (interlaceRows->valueint < 0) { + errorPrint("%s() LN%d, failed to read json, interlace_rows input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; - cJSON* minRows= cJSON_GetObjectItem(dbinfo, "minRows"); - if (minRows && minRows->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.minRows = minRows->valueint; - } else if (!minRows) { - g_Dbs.db[i].dbCfg.minRows = 0; // 0 means default + } + g_args.interlace_rows = interlaceRows->valueint; + } else if (!interlaceRows) { + g_args.interlace_rows = 0; // 0 means progressive mode, > 0 mean interlace mode. max value is less or equ num_of_records_per_req } else { - printf("ERROR: failed to read json, minRows not found\n"); - goto PARSE_OVER; + errorPrint("%s() LN%d, failed to read json, interlace_rows input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; } - cJSON* maxRows= cJSON_GetObjectItem(dbinfo, "maxRows"); - if (maxRows && maxRows->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.maxRows = maxRows->valueint; - } else if (!maxRows) { - g_Dbs.db[i].dbCfg.maxRows = 0; // 0 means default + cJSON* maxSqlLen = cJSON_GetObjectItem(root, "max_sql_len"); + if (maxSqlLen && maxSqlLen->type == cJSON_Number) { + if (maxSqlLen->valueint < 0) { + errorPrint("%s() LN%d, failed to read json, max_sql_len input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + g_args.max_sql_len = maxSqlLen->valueint; + } else if (!maxSqlLen) { + g_args.max_sql_len = (1024*1024); } else { - printf("ERROR: failed to read json, maxRows not found\n"); - goto PARSE_OVER; + errorPrint("%s() LN%d, failed to read json, max_sql_len input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; } - cJSON* comp= cJSON_GetObjectItem(dbinfo, "comp"); - if (comp && comp->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.comp = comp->valueint; - } else if (!comp) { - g_Dbs.db[i].dbCfg.comp = -1; + cJSON* numRecPerReq = cJSON_GetObjectItem(root, "num_of_records_per_req"); + if (numRecPerReq && numRecPerReq->type == cJSON_Number) { + if (numRecPerReq->valueint <= 0) { + errorPrint("%s() LN%d, failed to read json, num_of_records_per_req input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } else if (numRecPerReq->valueint > MAX_RECORDS_PER_REQ) { + printf("NOTICE: number of records per request value %"PRIu64" > %d\n\n", + numRecPerReq->valueint, MAX_RECORDS_PER_REQ); + printf(" number of records per request value will be set to %d\n\n", + MAX_RECORDS_PER_REQ); + prompt(); + numRecPerReq->valueint = MAX_RECORDS_PER_REQ; + } + g_args.num_of_RPR = numRecPerReq->valueint; + } else if (!numRecPerReq) { + g_args.num_of_RPR = MAX_RECORDS_PER_REQ; } else { - printf("ERROR: failed to read json, comp not found\n"); - goto PARSE_OVER; + errorPrint("%s() LN%d, failed to read json, num_of_records_per_req not found\n", + __func__, __LINE__); + goto PARSE_OVER; } - cJSON* walLevel= cJSON_GetObjectItem(dbinfo, "walLevel"); - if (walLevel && walLevel->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.walLevel = walLevel->valueint; - } else if (!walLevel) { - g_Dbs.db[i].dbCfg.walLevel = -1; + cJSON *answerPrompt = cJSON_GetObjectItem(root, "confirm_parameter_prompt"); // yes, no, + if (answerPrompt + && answerPrompt->type == cJSON_String + && answerPrompt->valuestring != NULL) { + if (0 == strncasecmp(answerPrompt->valuestring, "yes", 3)) { + g_args.answer_yes = false; + } else if (0 == strncasecmp(answerPrompt->valuestring, "no", 2)) { + g_args.answer_yes = true; + } else { + g_args.answer_yes = false; + } + } else if (!answerPrompt) { + g_args.answer_yes = true; // default is no, mean answer_yes. } else { - printf("ERROR: failed to read json, walLevel not found\n"); - goto PARSE_OVER; + errorPrint("%s", "failed to read json, confirm_parameter_prompt input mistake\n"); + goto PARSE_OVER; } - cJSON* cacheLast= cJSON_GetObjectItem(dbinfo, "cachelast"); - if (cacheLast && cacheLast->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.cacheLast = cacheLast->valueint; - } else if (!cacheLast) { - g_Dbs.db[i].dbCfg.cacheLast = -1; - } else { - printf("ERROR: failed to read json, cacheLast not found\n"); - goto PARSE_OVER; + // rows per table need be less than insert batch + if (g_args.interlace_rows > g_args.num_of_RPR) { + printf("NOTICE: interlace rows value %u > num_of_records_per_req %u\n\n", + g_args.interlace_rows, g_args.num_of_RPR); + printf(" interlace rows value will be set to num_of_records_per_req %u\n\n", + g_args.num_of_RPR); + prompt(); + g_args.interlace_rows = g_args.num_of_RPR; } - cJSON* quorum= cJSON_GetObjectItem(dbinfo, "quorum"); - if (quorum && quorum->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.quorum = quorum->valueint; - } else if (!quorum) { - g_Dbs.db[i].dbCfg.quorum = 1; - } else { - printf("failed to read json, quorum input mistake"); - goto PARSE_OVER; + cJSON* dbs = cJSON_GetObjectItem(root, "databases"); + if (!dbs || dbs->type != cJSON_Array) { + printf("ERROR: failed to read json, databases not found\n"); + goto PARSE_OVER; } - cJSON* fsync= cJSON_GetObjectItem(dbinfo, "fsync"); - if (fsync && fsync->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.fsync = fsync->valueint; - } else if (!fsync) { - g_Dbs.db[i].dbCfg.fsync = -1; - } else { - errorPrint("%s() LN%d, failed to read json, fsync input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; + int dbSize = cJSON_GetArraySize(dbs); + if (dbSize > MAX_DB_COUNT) { + errorPrint( + "ERROR: failed to read json, databases size overflow, max database is %d\n", + MAX_DB_COUNT); + goto PARSE_OVER; } - // super_talbes - cJSON *stables = cJSON_GetObjectItem(dbinfos, "super_tables"); - if (!stables || stables->type != cJSON_Array) { - errorPrint("%s() LN%d, failed to read json, super_tables not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } + g_Dbs.dbCount = dbSize; + for (int i = 0; i < dbSize; ++i) { + cJSON* dbinfos = cJSON_GetArrayItem(dbs, i); + if (dbinfos == NULL) continue; - int stbSize = cJSON_GetArraySize(stables); - if (stbSize > MAX_SUPER_TABLE_COUNT) { - errorPrint( - "%s() LN%d, failed to read json, supertable size overflow, max supertable is %d\n", - __func__, __LINE__, MAX_SUPER_TABLE_COUNT); - goto PARSE_OVER; - } + // dbinfo + cJSON *dbinfo = cJSON_GetObjectItem(dbinfos, "dbinfo"); + if (!dbinfo || dbinfo->type != cJSON_Object) { + printf("ERROR: failed to read json, dbinfo not found\n"); + goto PARSE_OVER; + } - g_Dbs.db[i].superTblCount = stbSize; - for (int j = 0; j < stbSize; ++j) { - cJSON* stbInfo = cJSON_GetArrayItem(stables, j); - if (stbInfo == NULL) continue; + cJSON *dbName = cJSON_GetObjectItem(dbinfo, "name"); + if (!dbName || dbName->type != cJSON_String || dbName->valuestring == NULL) { + printf("ERROR: failed to read json, db name not found\n"); + goto PARSE_OVER; + } + tstrncpy(g_Dbs.db[i].dbName, dbName->valuestring, TSDB_DB_NAME_LEN); - // dbinfo - cJSON *stbName = cJSON_GetObjectItem(stbInfo, "name"); - if (!stbName || stbName->type != cJSON_String - || stbName->valuestring == NULL) { - errorPrint("%s() LN%d, failed to read json, stb name not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } - tstrncpy(g_Dbs.db[i].superTbls[j].sTblName, stbName->valuestring, - TSDB_TABLE_NAME_LEN); + cJSON *drop = cJSON_GetObjectItem(dbinfo, "drop"); + if (drop && drop->type == cJSON_String && drop->valuestring != NULL) { + if (0 == strncasecmp(drop->valuestring, "yes", strlen("yes"))) { + g_Dbs.db[i].drop = true; + } else { + g_Dbs.db[i].drop = false; + } + } else if (!drop) { + g_Dbs.db[i].drop = g_args.drop_database; + } else { + errorPrint("%s() LN%d, failed to read json, drop input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } - cJSON *prefix = cJSON_GetObjectItem(stbInfo, "childtable_prefix"); - if (!prefix || prefix->type != cJSON_String || prefix->valuestring == NULL) { - printf("ERROR: failed to read json, childtable_prefix not found\n"); - goto PARSE_OVER; - } - tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring, - TSDB_TABLE_NAME_LEN - 20); - - cJSON *autoCreateTbl = cJSON_GetObjectItem(stbInfo, "auto_create_table"); - if (autoCreateTbl - && autoCreateTbl->type == cJSON_String - && autoCreateTbl->valuestring != NULL) { - if ((0 == strncasecmp(autoCreateTbl->valuestring, "yes", 3)) - && (TBL_ALREADY_EXISTS != g_Dbs.db[i].superTbls[j].childTblExists)) { - g_Dbs.db[i].superTbls[j].autoCreateTable = AUTO_CREATE_SUBTBL; - } else if (0 == strncasecmp(autoCreateTbl->valuestring, "no", 2)) { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } else { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } - } else if (!autoCreateTbl) { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } else { - printf("ERROR: failed to read json, auto_create_table not found\n"); - goto PARSE_OVER; - } + cJSON *precision = cJSON_GetObjectItem(dbinfo, "precision"); + if (precision && precision->type == cJSON_String + && precision->valuestring != NULL) { + tstrncpy(g_Dbs.db[i].dbCfg.precision, precision->valuestring, + 8); + } else if (!precision) { + memset(g_Dbs.db[i].dbCfg.precision, 0, 8); + } else { + printf("ERROR: failed to read json, precision not found\n"); + goto PARSE_OVER; + } - cJSON* batchCreateTbl = cJSON_GetObjectItem(stbInfo, "batch_create_tbl_num"); - if (batchCreateTbl && batchCreateTbl->type == cJSON_Number) { - g_Dbs.db[i].superTbls[j].batchCreateTableNum = batchCreateTbl->valueint; - } else if (!batchCreateTbl) { - g_Dbs.db[i].superTbls[j].batchCreateTableNum = 1000; - } else { - printf("ERROR: failed to read json, batch_create_tbl_num not found\n"); - goto PARSE_OVER; - } + cJSON* update = cJSON_GetObjectItem(dbinfo, "update"); + if (update && update->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.update = update->valueint; + } else if (!update) { + g_Dbs.db[i].dbCfg.update = -1; + } else { + printf("ERROR: failed to read json, update not found\n"); + goto PARSE_OVER; + } - cJSON *childTblExists = cJSON_GetObjectItem(stbInfo, "child_table_exists"); // yes, no - if (childTblExists - && childTblExists->type == cJSON_String - && childTblExists->valuestring != NULL) { - if ((0 == strncasecmp(childTblExists->valuestring, "yes", 3)) - && (g_Dbs.db[i].drop == false)) { - g_Dbs.db[i].superTbls[j].childTblExists = TBL_ALREADY_EXISTS; - } else if ((0 == strncasecmp(childTblExists->valuestring, "no", 2) - || (g_Dbs.db[i].drop == true))) { - g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; + cJSON* replica = cJSON_GetObjectItem(dbinfo, "replica"); + if (replica && replica->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.replica = replica->valueint; + } else if (!replica) { + g_Dbs.db[i].dbCfg.replica = -1; } else { - g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; + printf("ERROR: failed to read json, replica not found\n"); + goto PARSE_OVER; } - } else if (!childTblExists) { - g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; - } else { - errorPrint("%s() LN%d, failed to read json, child_table_exists not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } - if (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } + cJSON* keep = cJSON_GetObjectItem(dbinfo, "keep"); + if (keep && keep->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.keep = keep->valueint; + } else if (!keep) { + g_Dbs.db[i].dbCfg.keep = -1; + } else { + printf("ERROR: failed to read json, keep not found\n"); + goto PARSE_OVER; + } - cJSON* count = cJSON_GetObjectItem(stbInfo, "childtable_count"); - if (!count || count->type != cJSON_Number || 0 >= count->valueint) { - errorPrint("%s() LN%d, failed to read json, childtable_count input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - g_Dbs.db[i].superTbls[j].childTblCount = count->valueint; - - cJSON *dataSource = cJSON_GetObjectItem(stbInfo, "data_source"); - if (dataSource && dataSource->type == cJSON_String - && dataSource->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, - dataSource->valuestring, TSDB_DB_NAME_LEN); - } else if (!dataSource) { - tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, "rand", TSDB_DB_NAME_LEN); - } else { - errorPrint("%s() LN%d, failed to read json, data_source not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } + cJSON* days = cJSON_GetObjectItem(dbinfo, "days"); + if (days && days->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.days = days->valueint; + } else if (!days) { + g_Dbs.db[i].dbCfg.days = -1; + } else { + printf("ERROR: failed to read json, days not found\n"); + goto PARSE_OVER; + } - cJSON *stbIface = cJSON_GetObjectItem(stbInfo, "insert_mode"); // taosc , rest, stmt - if (stbIface && stbIface->type == cJSON_String - && stbIface->valuestring != NULL) { - if (0 == strcasecmp(stbIface->valuestring, "taosc")) { - g_Dbs.db[i].superTbls[j].iface= TAOSC_IFACE; - } else if (0 == strcasecmp(stbIface->valuestring, "rest")) { - g_Dbs.db[i].superTbls[j].iface= REST_IFACE; -#if STMT_IFACE_ENABLED == 1 - } else if (0 == strcasecmp(stbIface->valuestring, "stmt")) { - g_Dbs.db[i].superTbls[j].iface= STMT_IFACE; -#endif + cJSON* cache = cJSON_GetObjectItem(dbinfo, "cache"); + if (cache && cache->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.cache = cache->valueint; + } else if (!cache) { + g_Dbs.db[i].dbCfg.cache = -1; } else { - errorPrint("%s() LN%d, failed to read json, insert_mode %s not recognized\n", - __func__, __LINE__, stbIface->valuestring); + printf("ERROR: failed to read json, cache not found\n"); goto PARSE_OVER; } - } else if (!stbIface) { - g_Dbs.db[i].superTbls[j].iface = TAOSC_IFACE; - } else { - errorPrint("%s", "failed to read json, insert_mode not found\n"); - goto PARSE_OVER; - } - cJSON* childTbl_limit = cJSON_GetObjectItem(stbInfo, "childtable_limit"); - if ((childTbl_limit) && (g_Dbs.db[i].drop != true) - && (g_Dbs.db[i].superTbls[j].childTblExists == TBL_ALREADY_EXISTS)) { - if (childTbl_limit->type != cJSON_Number) { - printf("ERROR: failed to read json, childtable_limit\n"); + cJSON* blocks= cJSON_GetObjectItem(dbinfo, "blocks"); + if (blocks && blocks->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.blocks = blocks->valueint; + } else if (!blocks) { + g_Dbs.db[i].dbCfg.blocks = -1; + } else { + printf("ERROR: failed to read json, block not found\n"); goto PARSE_OVER; } - g_Dbs.db[i].superTbls[j].childTblLimit = childTbl_limit->valueint; - } else { - g_Dbs.db[i].superTbls[j].childTblLimit = -1; // select ... limit -1 means all query result, drop = yes mean all table need recreate, limit value is invalid. - } - cJSON* childTbl_offset = cJSON_GetObjectItem(stbInfo, "childtable_offset"); - if ((childTbl_offset) && (g_Dbs.db[i].drop != true) - && (g_Dbs.db[i].superTbls[j].childTblExists == TBL_ALREADY_EXISTS)) { - if ((childTbl_offset->type != cJSON_Number) - || (0 > childTbl_offset->valueint)) { - printf("ERROR: failed to read json, childtable_offset\n"); + //cJSON* maxtablesPerVnode= cJSON_GetObjectItem(dbinfo, "maxtablesPerVnode"); + //if (maxtablesPerVnode && maxtablesPerVnode->type == cJSON_Number) { + // g_Dbs.db[i].dbCfg.maxtablesPerVnode = maxtablesPerVnode->valueint; + //} else if (!maxtablesPerVnode) { + // g_Dbs.db[i].dbCfg.maxtablesPerVnode = TSDB_DEFAULT_TABLES; + //} else { + // printf("failed to read json, maxtablesPerVnode not found"); + // goto PARSE_OVER; + //} + + cJSON* minRows= cJSON_GetObjectItem(dbinfo, "minRows"); + if (minRows && minRows->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.minRows = minRows->valueint; + } else if (!minRows) { + g_Dbs.db[i].dbCfg.minRows = 0; // 0 means default + } else { + printf("ERROR: failed to read json, minRows not found\n"); goto PARSE_OVER; } - g_Dbs.db[i].superTbls[j].childTblOffset = childTbl_offset->valueint; - } else { - g_Dbs.db[i].superTbls[j].childTblOffset = 0; - } - cJSON *ts = cJSON_GetObjectItem(stbInfo, "start_timestamp"); - if (ts && ts->type == cJSON_String && ts->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, - ts->valuestring, TSDB_DB_NAME_LEN); - } else if (!ts) { - tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, - "now", TSDB_DB_NAME_LEN); - } else { - printf("ERROR: failed to read json, start_timestamp not found\n"); - goto PARSE_OVER; - } + cJSON* maxRows= cJSON_GetObjectItem(dbinfo, "maxRows"); + if (maxRows && maxRows->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.maxRows = maxRows->valueint; + } else if (!maxRows) { + g_Dbs.db[i].dbCfg.maxRows = 0; // 0 means default + } else { + printf("ERROR: failed to read json, maxRows not found\n"); + goto PARSE_OVER; + } - cJSON* timestampStep = cJSON_GetObjectItem(stbInfo, "timestamp_step"); - if (timestampStep && timestampStep->type == cJSON_Number) { - g_Dbs.db[i].superTbls[j].timeStampStep = timestampStep->valueint; - } else if (!timestampStep) { - g_Dbs.db[i].superTbls[j].timeStampStep = DEFAULT_TIMESTAMP_STEP; - } else { - printf("ERROR: failed to read json, timestamp_step not found\n"); - goto PARSE_OVER; - } + cJSON* comp= cJSON_GetObjectItem(dbinfo, "comp"); + if (comp && comp->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.comp = comp->valueint; + } else if (!comp) { + g_Dbs.db[i].dbCfg.comp = -1; + } else { + printf("ERROR: failed to read json, comp not found\n"); + goto PARSE_OVER; + } - cJSON *sampleFormat = cJSON_GetObjectItem(stbInfo, "sample_format"); - if (sampleFormat && sampleFormat->type - == cJSON_String && sampleFormat->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, - sampleFormat->valuestring, TSDB_DB_NAME_LEN); - } else if (!sampleFormat) { - tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, "csv", TSDB_DB_NAME_LEN); - } else { - printf("ERROR: failed to read json, sample_format not found\n"); - goto PARSE_OVER; - } + cJSON* walLevel= cJSON_GetObjectItem(dbinfo, "walLevel"); + if (walLevel && walLevel->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.walLevel = walLevel->valueint; + } else if (!walLevel) { + g_Dbs.db[i].dbCfg.walLevel = -1; + } else { + printf("ERROR: failed to read json, walLevel not found\n"); + goto PARSE_OVER; + } - cJSON *sampleFile = cJSON_GetObjectItem(stbInfo, "sample_file"); - if (sampleFile && sampleFile->type == cJSON_String - && sampleFile->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].sampleFile, - sampleFile->valuestring, MAX_FILE_NAME_LEN); - } else if (!sampleFile) { - memset(g_Dbs.db[i].superTbls[j].sampleFile, 0, MAX_FILE_NAME_LEN); - } else { - printf("ERROR: failed to read json, sample_file not found\n"); - goto PARSE_OVER; - } + cJSON* cacheLast= cJSON_GetObjectItem(dbinfo, "cachelast"); + if (cacheLast && cacheLast->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.cacheLast = cacheLast->valueint; + } else if (!cacheLast) { + g_Dbs.db[i].dbCfg.cacheLast = -1; + } else { + printf("ERROR: failed to read json, cacheLast not found\n"); + goto PARSE_OVER; + } - cJSON *tagsFile = cJSON_GetObjectItem(stbInfo, "tags_file"); - if ((tagsFile && tagsFile->type == cJSON_String) - && (tagsFile->valuestring != NULL)) { - tstrncpy(g_Dbs.db[i].superTbls[j].tagsFile, - tagsFile->valuestring, MAX_FILE_NAME_LEN); - if (0 == g_Dbs.db[i].superTbls[j].tagsFile[0]) { - g_Dbs.db[i].superTbls[j].tagSource = 0; + cJSON* quorum= cJSON_GetObjectItem(dbinfo, "quorum"); + if (quorum && quorum->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.quorum = quorum->valueint; + } else if (!quorum) { + g_Dbs.db[i].dbCfg.quorum = 1; } else { - g_Dbs.db[i].superTbls[j].tagSource = 1; + printf("failed to read json, quorum input mistake"); + goto PARSE_OVER; } - } else if (!tagsFile) { - memset(g_Dbs.db[i].superTbls[j].tagsFile, 0, MAX_FILE_NAME_LEN); - g_Dbs.db[i].superTbls[j].tagSource = 0; - } else { - printf("ERROR: failed to read json, tags_file not found\n"); - goto PARSE_OVER; - } - cJSON* stbMaxSqlLen = cJSON_GetObjectItem(stbInfo, "max_sql_len"); - if (stbMaxSqlLen && stbMaxSqlLen->type == cJSON_Number) { - int32_t len = stbMaxSqlLen->valueint; - if (len > TSDB_MAX_ALLOWED_SQL_LEN) { - len = TSDB_MAX_ALLOWED_SQL_LEN; - } else if (len < 5) { - len = 5; - } - g_Dbs.db[i].superTbls[j].maxSqlLen = len; - } else if (!maxSqlLen) { - g_Dbs.db[i].superTbls[j].maxSqlLen = g_args.max_sql_len; - } else { - errorPrint("%s() LN%d, failed to read json, stbMaxSqlLen input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } -/* - cJSON *multiThreadWriteOneTbl = - cJSON_GetObjectItem(stbInfo, "multi_thread_write_one_tbl"); // no , yes - if (multiThreadWriteOneTbl - && multiThreadWriteOneTbl->type == cJSON_String - && multiThreadWriteOneTbl->valuestring != NULL) { - if (0 == strncasecmp(multiThreadWriteOneTbl->valuestring, "yes", 3)) { - g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 1; + cJSON* fsync= cJSON_GetObjectItem(dbinfo, "fsync"); + if (fsync && fsync->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.fsync = fsync->valueint; + } else if (!fsync) { + g_Dbs.db[i].dbCfg.fsync = -1; } else { - g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; + errorPrint("%s() LN%d, failed to read json, fsync input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; } - } else if (!multiThreadWriteOneTbl) { - g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; - } else { - printf("ERROR: failed to read json, multiThreadWriteOneTbl not found\n"); - goto PARSE_OVER; - } -*/ - cJSON* stbInterlaceRows = cJSON_GetObjectItem(stbInfo, "interlace_rows"); - if (stbInterlaceRows && stbInterlaceRows->type == cJSON_Number) { - if (stbInterlaceRows->valueint < 0) { - errorPrint("%s() LN%d, failed to read json, interlace rows input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; + + // super_talbes + cJSON *stables = cJSON_GetObjectItem(dbinfos, "super_tables"); + if (!stables || stables->type != cJSON_Array) { + errorPrint("%s() LN%d, failed to read json, super_tables not found\n", + __func__, __LINE__); + goto PARSE_OVER; } - g_Dbs.db[i].superTbls[j].interlaceRows = stbInterlaceRows->valueint; - // rows per table need be less than insert batch - if (g_Dbs.db[i].superTbls[j].interlaceRows > g_args.num_of_RPR) { - printf("NOTICE: db[%d].superTbl[%d]'s interlace rows value %u > num_of_records_per_req %u\n\n", - i, j, g_Dbs.db[i].superTbls[j].interlaceRows, - g_args.num_of_RPR); - printf(" interlace rows value will be set to num_of_records_per_req %u\n\n", - g_args.num_of_RPR); - prompt(); - g_Dbs.db[i].superTbls[j].interlaceRows = g_args.num_of_RPR; - } - } else if (!stbInterlaceRows) { - g_Dbs.db[i].superTbls[j].interlaceRows = 0; // 0 means progressive mode, > 0 mean interlace mode. max value is less or equ num_of_records_per_req - } else { - errorPrint( - "%s() LN%d, failed to read json, interlace rows input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - cJSON* disorderRatio = cJSON_GetObjectItem(stbInfo, "disorder_ratio"); - if (disorderRatio && disorderRatio->type == cJSON_Number) { - if (disorderRatio->valueint > 50) - disorderRatio->valueint = 50; + int stbSize = cJSON_GetArraySize(stables); + if (stbSize > MAX_SUPER_TABLE_COUNT) { + errorPrint( + "%s() LN%d, failed to read json, supertable size overflow, max supertable is %d\n", + __func__, __LINE__, MAX_SUPER_TABLE_COUNT); + goto PARSE_OVER; + } - if (disorderRatio->valueint < 0) - disorderRatio->valueint = 0; + g_Dbs.db[i].superTblCount = stbSize; + for (int j = 0; j < stbSize; ++j) { + cJSON* stbInfo = cJSON_GetArrayItem(stables, j); + if (stbInfo == NULL) continue; - g_Dbs.db[i].superTbls[j].disorderRatio = disorderRatio->valueint; - } else if (!disorderRatio) { - g_Dbs.db[i].superTbls[j].disorderRatio = 0; - } else { - printf("ERROR: failed to read json, disorderRatio not found\n"); - goto PARSE_OVER; - } + // dbinfo + cJSON *stbName = cJSON_GetObjectItem(stbInfo, "name"); + if (!stbName || stbName->type != cJSON_String + || stbName->valuestring == NULL) { + errorPrint("%s() LN%d, failed to read json, stb name not found\n", + __func__, __LINE__); + goto PARSE_OVER; + } + tstrncpy(g_Dbs.db[i].superTbls[j].sTblName, stbName->valuestring, + TSDB_TABLE_NAME_LEN); - cJSON* disorderRange = cJSON_GetObjectItem(stbInfo, "disorder_range"); - if (disorderRange && disorderRange->type == cJSON_Number) { - g_Dbs.db[i].superTbls[j].disorderRange = disorderRange->valueint; - } else if (!disorderRange) { - g_Dbs.db[i].superTbls[j].disorderRange = 1000; - } else { - printf("ERROR: failed to read json, disorderRange not found\n"); - goto PARSE_OVER; - } + cJSON *prefix = cJSON_GetObjectItem(stbInfo, "childtable_prefix"); + if (!prefix || prefix->type != cJSON_String || prefix->valuestring == NULL) { + printf("ERROR: failed to read json, childtable_prefix not found\n"); + goto PARSE_OVER; + } + tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring, + TSDB_TABLE_NAME_LEN - 20); + + cJSON *autoCreateTbl = cJSON_GetObjectItem(stbInfo, "auto_create_table"); + if (autoCreateTbl + && autoCreateTbl->type == cJSON_String + && autoCreateTbl->valuestring != NULL) { + if ((0 == strncasecmp(autoCreateTbl->valuestring, "yes", 3)) + && (TBL_ALREADY_EXISTS != g_Dbs.db[i].superTbls[j].childTblExists)) { + g_Dbs.db[i].superTbls[j].autoCreateTable = AUTO_CREATE_SUBTBL; + } else if (0 == strncasecmp(autoCreateTbl->valuestring, "no", 2)) { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } else { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } + } else if (!autoCreateTbl) { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } else { + printf("ERROR: failed to read json, auto_create_table not found\n"); + goto PARSE_OVER; + } - cJSON* insertRows = cJSON_GetObjectItem(stbInfo, "insert_rows"); - if (insertRows && insertRows->type == cJSON_Number) { - if (insertRows->valueint < 0) { - errorPrint("%s() LN%d, failed to read json, insert_rows input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - g_Dbs.db[i].superTbls[j].insertRows = insertRows->valueint; - } else if (!insertRows) { - g_Dbs.db[i].superTbls[j].insertRows = 0x7FFFFFFFFFFFFFFF; - } else { - errorPrint("%s() LN%d, failed to read json, insert_rows input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } + cJSON* batchCreateTbl = cJSON_GetObjectItem(stbInfo, "batch_create_tbl_num"); + if (batchCreateTbl && batchCreateTbl->type == cJSON_Number) { + g_Dbs.db[i].superTbls[j].batchCreateTableNum = batchCreateTbl->valueint; + } else if (!batchCreateTbl) { + g_Dbs.db[i].superTbls[j].batchCreateTableNum = 1000; + } else { + printf("ERROR: failed to read json, batch_create_tbl_num not found\n"); + goto PARSE_OVER; + } - cJSON* insertInterval = cJSON_GetObjectItem(stbInfo, "insert_interval"); - if (insertInterval && insertInterval->type == cJSON_Number) { - g_Dbs.db[i].superTbls[j].insertInterval = insertInterval->valueint; - if (insertInterval->valueint < 0) { - errorPrint("%s() LN%d, failed to read json, insert_interval input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - } else if (!insertInterval) { - verbosePrint("%s() LN%d: stable insert interval be overrided by global %"PRIu64".\n", - __func__, __LINE__, g_args.insert_interval); - g_Dbs.db[i].superTbls[j].insertInterval = g_args.insert_interval; - } else { - errorPrint("%s() LN%d, failed to read json, insert_interval input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } + cJSON *childTblExists = cJSON_GetObjectItem(stbInfo, "child_table_exists"); // yes, no + if (childTblExists + && childTblExists->type == cJSON_String + && childTblExists->valuestring != NULL) { + if ((0 == strncasecmp(childTblExists->valuestring, "yes", 3)) + && (g_Dbs.db[i].drop == false)) { + g_Dbs.db[i].superTbls[j].childTblExists = TBL_ALREADY_EXISTS; + } else if ((0 == strncasecmp(childTblExists->valuestring, "no", 2) + || (g_Dbs.db[i].drop == true))) { + g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; + } else { + g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; + } + } else if (!childTblExists) { + g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; + } else { + errorPrint("%s() LN%d, failed to read json, child_table_exists not found\n", + __func__, __LINE__); + goto PARSE_OVER; + } - int retVal = getColumnAndTagTypeFromInsertJsonFile( - stbInfo, &g_Dbs.db[i].superTbls[j]); - if (false == retVal) { - goto PARSE_OVER; - } + if (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } + + cJSON* count = cJSON_GetObjectItem(stbInfo, "childtable_count"); + if (!count || count->type != cJSON_Number || 0 >= count->valueint) { + errorPrint("%s() LN%d, failed to read json, childtable_count input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].childTblCount = count->valueint; + + cJSON *dataSource = cJSON_GetObjectItem(stbInfo, "data_source"); + if (dataSource && dataSource->type == cJSON_String + && dataSource->valuestring != NULL) { + tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, + dataSource->valuestring, TSDB_DB_NAME_LEN); + } else if (!dataSource) { + tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, "rand", TSDB_DB_NAME_LEN); + } else { + errorPrint("%s() LN%d, failed to read json, data_source not found\n", + __func__, __LINE__); + goto PARSE_OVER; + } + + cJSON *stbIface = cJSON_GetObjectItem(stbInfo, "insert_mode"); // taosc , rest, stmt + if (stbIface && stbIface->type == cJSON_String + && stbIface->valuestring != NULL) { + if (0 == strcasecmp(stbIface->valuestring, "taosc")) { + g_Dbs.db[i].superTbls[j].iface= TAOSC_IFACE; + } else if (0 == strcasecmp(stbIface->valuestring, "rest")) { + g_Dbs.db[i].superTbls[j].iface= REST_IFACE; +#if STMT_IFACE_ENABLED == 1 + } else if (0 == strcasecmp(stbIface->valuestring, "stmt")) { + g_Dbs.db[i].superTbls[j].iface= STMT_IFACE; +#endif + } else { + errorPrint("%s() LN%d, failed to read json, insert_mode %s not recognized\n", + __func__, __LINE__, stbIface->valuestring); + goto PARSE_OVER; + } + } else if (!stbIface) { + g_Dbs.db[i].superTbls[j].iface = TAOSC_IFACE; + } else { + errorPrint("%s", "failed to read json, insert_mode not found\n"); + goto PARSE_OVER; + } + + cJSON* childTbl_limit = cJSON_GetObjectItem(stbInfo, "childtable_limit"); + if ((childTbl_limit) && (g_Dbs.db[i].drop != true) + && (g_Dbs.db[i].superTbls[j].childTblExists == TBL_ALREADY_EXISTS)) { + if (childTbl_limit->type != cJSON_Number) { + printf("ERROR: failed to read json, childtable_limit\n"); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].childTblLimit = childTbl_limit->valueint; + } else { + g_Dbs.db[i].superTbls[j].childTblLimit = -1; // select ... limit -1 means all query result, drop = yes mean all table need recreate, limit value is invalid. + } + + cJSON* childTbl_offset = cJSON_GetObjectItem(stbInfo, "childtable_offset"); + if ((childTbl_offset) && (g_Dbs.db[i].drop != true) + && (g_Dbs.db[i].superTbls[j].childTblExists == TBL_ALREADY_EXISTS)) { + if ((childTbl_offset->type != cJSON_Number) + || (0 > childTbl_offset->valueint)) { + printf("ERROR: failed to read json, childtable_offset\n"); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].childTblOffset = childTbl_offset->valueint; + } else { + g_Dbs.db[i].superTbls[j].childTblOffset = 0; + } + + cJSON *ts = cJSON_GetObjectItem(stbInfo, "start_timestamp"); + if (ts && ts->type == cJSON_String && ts->valuestring != NULL) { + tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, + ts->valuestring, TSDB_DB_NAME_LEN); + } else if (!ts) { + tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, + "now", TSDB_DB_NAME_LEN); + } else { + printf("ERROR: failed to read json, start_timestamp not found\n"); + goto PARSE_OVER; + } + + cJSON* timestampStep = cJSON_GetObjectItem(stbInfo, "timestamp_step"); + if (timestampStep && timestampStep->type == cJSON_Number) { + g_Dbs.db[i].superTbls[j].timeStampStep = timestampStep->valueint; + } else if (!timestampStep) { + g_Dbs.db[i].superTbls[j].timeStampStep = DEFAULT_TIMESTAMP_STEP; + } else { + printf("ERROR: failed to read json, timestamp_step not found\n"); + goto PARSE_OVER; + } + + cJSON *sampleFormat = cJSON_GetObjectItem(stbInfo, "sample_format"); + if (sampleFormat && sampleFormat->type + == cJSON_String && sampleFormat->valuestring != NULL) { + tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, + sampleFormat->valuestring, TSDB_DB_NAME_LEN); + } else if (!sampleFormat) { + tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, "csv", TSDB_DB_NAME_LEN); + } else { + printf("ERROR: failed to read json, sample_format not found\n"); + goto PARSE_OVER; + } + + cJSON *sampleFile = cJSON_GetObjectItem(stbInfo, "sample_file"); + if (sampleFile && sampleFile->type == cJSON_String + && sampleFile->valuestring != NULL) { + tstrncpy(g_Dbs.db[i].superTbls[j].sampleFile, + sampleFile->valuestring, MAX_FILE_NAME_LEN); + } else if (!sampleFile) { + memset(g_Dbs.db[i].superTbls[j].sampleFile, 0, MAX_FILE_NAME_LEN); + } else { + printf("ERROR: failed to read json, sample_file not found\n"); + goto PARSE_OVER; + } + + cJSON *tagsFile = cJSON_GetObjectItem(stbInfo, "tags_file"); + if ((tagsFile && tagsFile->type == cJSON_String) + && (tagsFile->valuestring != NULL)) { + tstrncpy(g_Dbs.db[i].superTbls[j].tagsFile, + tagsFile->valuestring, MAX_FILE_NAME_LEN); + if (0 == g_Dbs.db[i].superTbls[j].tagsFile[0]) { + g_Dbs.db[i].superTbls[j].tagSource = 0; + } else { + g_Dbs.db[i].superTbls[j].tagSource = 1; + } + } else if (!tagsFile) { + memset(g_Dbs.db[i].superTbls[j].tagsFile, 0, MAX_FILE_NAME_LEN); + g_Dbs.db[i].superTbls[j].tagSource = 0; + } else { + printf("ERROR: failed to read json, tags_file not found\n"); + goto PARSE_OVER; + } + + cJSON* stbMaxSqlLen = cJSON_GetObjectItem(stbInfo, "max_sql_len"); + if (stbMaxSqlLen && stbMaxSqlLen->type == cJSON_Number) { + int32_t len = stbMaxSqlLen->valueint; + if (len > TSDB_MAX_ALLOWED_SQL_LEN) { + len = TSDB_MAX_ALLOWED_SQL_LEN; + } else if (len < 5) { + len = 5; + } + g_Dbs.db[i].superTbls[j].maxSqlLen = len; + } else if (!maxSqlLen) { + g_Dbs.db[i].superTbls[j].maxSqlLen = g_args.max_sql_len; + } else { + errorPrint("%s() LN%d, failed to read json, stbMaxSqlLen input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + /* + cJSON *multiThreadWriteOneTbl = + cJSON_GetObjectItem(stbInfo, "multi_thread_write_one_tbl"); // no , yes + if (multiThreadWriteOneTbl + && multiThreadWriteOneTbl->type == cJSON_String + && multiThreadWriteOneTbl->valuestring != NULL) { + if (0 == strncasecmp(multiThreadWriteOneTbl->valuestring, "yes", 3)) { + g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 1; + } else { + g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; + } + } else if (!multiThreadWriteOneTbl) { + g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; + } else { + printf("ERROR: failed to read json, multiThreadWriteOneTbl not found\n"); + goto PARSE_OVER; + } + */ + cJSON* insertRows = cJSON_GetObjectItem(stbInfo, "insert_rows"); + if (insertRows && insertRows->type == cJSON_Number) { + if (insertRows->valueint < 0) { + errorPrint("%s() LN%d, failed to read json, insert_rows input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].insertRows = insertRows->valueint; + } else if (!insertRows) { + g_Dbs.db[i].superTbls[j].insertRows = 0x7FFFFFFFFFFFFFFF; + } else { + errorPrint("%s() LN%d, failed to read json, insert_rows input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + + cJSON* stbInterlaceRows = cJSON_GetObjectItem(stbInfo, "interlace_rows"); + if (stbInterlaceRows && stbInterlaceRows->type == cJSON_Number) { + if (stbInterlaceRows->valueint < 0) { + errorPrint("%s() LN%d, failed to read json, interlace rows input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].interlaceRows = stbInterlaceRows->valueint; + + if (g_Dbs.db[i].superTbls[j].interlaceRows > g_Dbs.db[i].superTbls[j].insertRows) { + printf("NOTICE: db[%d].superTbl[%d]'s interlace rows value %u > insert_rows %"PRId64"\n\n", + i, j, g_Dbs.db[i].superTbls[j].interlaceRows, + g_Dbs.db[i].superTbls[j].insertRows); + printf(" interlace rows value will be set to insert_rows %"PRId64"\n\n", + g_Dbs.db[i].superTbls[j].insertRows); + prompt(); + g_Dbs.db[i].superTbls[j].interlaceRows = g_Dbs.db[i].superTbls[j].insertRows; + } + } else if (!stbInterlaceRows) { + g_Dbs.db[i].superTbls[j].interlaceRows = 0; // 0 means progressive mode, > 0 mean interlace mode. max value is less or equ num_of_records_per_req + } else { + errorPrint( + "%s() LN%d, failed to read json, interlace rows input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + + cJSON* disorderRatio = cJSON_GetObjectItem(stbInfo, "disorder_ratio"); + if (disorderRatio && disorderRatio->type == cJSON_Number) { + if (disorderRatio->valueint > 50) + disorderRatio->valueint = 50; + + if (disorderRatio->valueint < 0) + disorderRatio->valueint = 0; + + g_Dbs.db[i].superTbls[j].disorderRatio = disorderRatio->valueint; + } else if (!disorderRatio) { + g_Dbs.db[i].superTbls[j].disorderRatio = 0; + } else { + printf("ERROR: failed to read json, disorderRatio not found\n"); + goto PARSE_OVER; + } + + cJSON* disorderRange = cJSON_GetObjectItem(stbInfo, "disorder_range"); + if (disorderRange && disorderRange->type == cJSON_Number) { + g_Dbs.db[i].superTbls[j].disorderRange = disorderRange->valueint; + } else if (!disorderRange) { + g_Dbs.db[i].superTbls[j].disorderRange = 1000; + } else { + printf("ERROR: failed to read json, disorderRange not found\n"); + goto PARSE_OVER; + } + + cJSON* insertInterval = cJSON_GetObjectItem(stbInfo, "insert_interval"); + if (insertInterval && insertInterval->type == cJSON_Number) { + g_Dbs.db[i].superTbls[j].insertInterval = insertInterval->valueint; + if (insertInterval->valueint < 0) { + errorPrint("%s() LN%d, failed to read json, insert_interval input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + } else if (!insertInterval) { + verbosePrint("%s() LN%d: stable insert interval be overrided by global %"PRIu64".\n", + __func__, __LINE__, g_args.insert_interval); + g_Dbs.db[i].superTbls[j].insertInterval = g_args.insert_interval; + } else { + errorPrint("%s() LN%d, failed to read json, insert_interval input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + + int retVal = getColumnAndTagTypeFromInsertJsonFile( + stbInfo, &g_Dbs.db[i].superTbls[j]); + if (false == retVal) { + goto PARSE_OVER; + } + } } - } - ret = true; + ret = true; PARSE_OVER: - return ret; + return ret; } static bool getMetaFromQueryJsonFile(cJSON* root) { @@ -4955,54 +4970,64 @@ static int64_t generateStbRowData( static int64_t generateData(char *recBuf, char **data_type, int64_t timestamp, int lenOfBinary) { - memset(recBuf, 0, MAX_DATA_SIZE); - char *pstr = recBuf; - pstr += sprintf(pstr, "(%" PRId64, timestamp); - - int columnCount = g_args.num_of_CPR; - - for (int i = 0; i < columnCount; i++) { - if (strcasecmp(data_type[i % columnCount], "TINYINT") == 0) { - pstr += sprintf(pstr, ",%d", rand_tinyint() ); - } else if (strcasecmp(data_type[i % columnCount], "SMALLINT") == 0) { - pstr += sprintf(pstr, ",%d", rand_smallint()); - } else if (strcasecmp(data_type[i % columnCount], "INT") == 0) { - pstr += sprintf(pstr, ",%d", rand_int()); - } else if (strcasecmp(data_type[i % columnCount], "BIGINT") == 0) { - pstr += sprintf(pstr, ",%" PRId64, rand_bigint()); - } else if (strcasecmp(data_type[i % columnCount], "TIMESTAMP") == 0) { - pstr += sprintf(pstr, ",%" PRId64, rand_bigint()); - } else if (strcasecmp(data_type[i % columnCount], "FLOAT") == 0) { - pstr += sprintf(pstr, ",%10.4f", rand_float()); - } else if (strcasecmp(data_type[i % columnCount], "DOUBLE") == 0) { - double t = rand_double(); - pstr += sprintf(pstr, ",%20.8f", t); - } else if (strcasecmp(data_type[i % columnCount], "BOOL") == 0) { - bool b = rand_bool() & 1; - pstr += sprintf(pstr, ",%s", b ? "true" : "false"); - } else if (strcasecmp(data_type[i % columnCount], "BINARY") == 0) { - char *s = malloc(lenOfBinary); - rand_string(s, lenOfBinary); - pstr += sprintf(pstr, ",\"%s\"", s); - free(s); - } else if (strcasecmp(data_type[i % columnCount], "NCHAR") == 0) { - char *s = malloc(lenOfBinary); - rand_string(s, lenOfBinary); - pstr += sprintf(pstr, ",\"%s\"", s); - free(s); - } - - if (strlen(recBuf) > MAX_DATA_SIZE) { - perror("column length too long, abort"); - exit(-1); + memset(recBuf, 0, MAX_DATA_SIZE); + char *pstr = recBuf; + pstr += sprintf(pstr, "(%" PRId64, timestamp); + + int columnCount = g_args.num_of_CPR; + + for (int i = 0; i < columnCount; i++) { + if (strcasecmp(data_type[i % columnCount], "TINYINT") == 0) { + pstr += sprintf(pstr, ",%d", rand_tinyint() ); + } else if (strcasecmp(data_type[i % columnCount], "SMALLINT") == 0) { + pstr += sprintf(pstr, ",%d", rand_smallint()); + } else if (strcasecmp(data_type[i % columnCount], "INT") == 0) { + pstr += sprintf(pstr, ",%d", rand_int()); + } else if (strcasecmp(data_type[i % columnCount], "BIGINT") == 0) { + pstr += sprintf(pstr, ",%" PRId64, rand_bigint()); + } else if (strcasecmp(data_type[i % columnCount], "TIMESTAMP") == 0) { + pstr += sprintf(pstr, ",%" PRId64, rand_bigint()); + } else if (strcasecmp(data_type[i % columnCount], "FLOAT") == 0) { + pstr += sprintf(pstr, ",%10.4f", rand_float()); + } else if (strcasecmp(data_type[i % columnCount], "DOUBLE") == 0) { + double t = rand_double(); + pstr += sprintf(pstr, ",%20.8f", t); + } else if (strcasecmp(data_type[i % columnCount], "BOOL") == 0) { + bool b = rand_bool() & 1; + pstr += sprintf(pstr, ",%s", b ? "true" : "false"); + } else if (strcasecmp(data_type[i % columnCount], "BINARY") == 0) { + char *s = malloc(lenOfBinary + 1); + if (s == NULL) { + errorPrint("%s() LN%d, memory allocation %d bytes failed\n", + __func__, __LINE__, lenOfBinary + 1); + exit(-1); + } + rand_string(s, lenOfBinary); + pstr += sprintf(pstr, ",\"%s\"", s); + free(s); + } else if (strcasecmp(data_type[i % columnCount], "NCHAR") == 0) { + char *s = malloc(lenOfBinary + 1); + if (s == NULL) { + errorPrint("%s() LN%d, memory allocation %d bytes failed\n", + __func__, __LINE__, lenOfBinary + 1); + exit(-1); + } + rand_string(s, lenOfBinary); + pstr += sprintf(pstr, ",\"%s\"", s); + free(s); + } + + if (strlen(recBuf) > MAX_DATA_SIZE) { + perror("column length too long, abort"); + exit(-1); + } } - } - pstr += sprintf(pstr, ")"); + pstr += sprintf(pstr, ")"); - verbosePrint("%s() LN%d, recBuf:\n\t%s\n", __func__, __LINE__, recBuf); + verbosePrint("%s() LN%d, recBuf:\n\t%s\n", __func__, __LINE__, recBuf); - return (int32_t)strlen(recBuf); + return (int32_t)strlen(recBuf); } static int prepareSampleDataForSTable(SSuperTable *superTblInfo) { @@ -5143,12 +5168,18 @@ static int32_t generateDataTailWithoutStb( char **data_type = g_args.datatype; int lenOfBinary = g_args.len_of_binary; - retLen = generateData(data, data_type, - startTime + getTSRandTail( - (int64_t) DEFAULT_TIMESTAMP_STEP, k, - g_args.disorderRatio, - g_args.disorderRange), - lenOfBinary); + if (g_args.disorderRatio) { + retLen = generateData(data, data_type, + startTime + getTSRandTail( + (int64_t) DEFAULT_TIMESTAMP_STEP, k, + g_args.disorderRatio, + g_args.disorderRange), + lenOfBinary); + } else { + retLen = generateData(data, data_type, + startTime + (int64_t) (DEFAULT_TIMESTAMP_STEP* k), + lenOfBinary); + } if (len > remainderBufLen) break; @@ -5194,63 +5225,69 @@ static int32_t generateStbDataTail( int64_t remainderBufLen, int64_t insertRows, uint64_t recordFrom, int64_t startTime, int64_t *pSamplePos, int64_t *dataLen) { - uint64_t len = 0; + uint64_t len = 0; - char *pstr = buffer; + char *pstr = buffer; - bool tsRand; - if (0 == strncasecmp(superTblInfo->dataSource, "rand", strlen("rand"))) { - tsRand = true; - } else { - tsRand = false; - } - verbosePrint("%s() LN%d batch=%u buflen=%"PRId64"\n", - __func__, __LINE__, batch, remainderBufLen); + bool tsRand; + if (0 == strncasecmp(superTblInfo->dataSource, "rand", strlen("rand"))) { + tsRand = true; + } else { + tsRand = false; + } + verbosePrint("%s() LN%d batch=%u buflen=%"PRId64"\n", + __func__, __LINE__, batch, remainderBufLen); - int32_t k = 0; - for (k = 0; k < batch;) { - char data[MAX_DATA_SIZE]; - memset(data, 0, MAX_DATA_SIZE); + int32_t k; + for (k = 0; k < batch;) { + char data[MAX_DATA_SIZE]; + memset(data, 0, MAX_DATA_SIZE); - int64_t lenOfRow = 0; + int64_t lenOfRow = 0; - if (tsRand) { - lenOfRow = generateStbRowData(superTblInfo, data, - startTime + getTSRandTail( - superTblInfo->timeStampStep, k, - superTblInfo->disorderRatio, - superTblInfo->disorderRange) - ); - } else { - lenOfRow = getRowDataFromSample( - data, - (remainderBufLen < MAX_DATA_SIZE)?remainderBufLen:MAX_DATA_SIZE, - startTime + superTblInfo->timeStampStep * k, - superTblInfo, - pSamplePos); - } + if (tsRand) { + if (superTblInfo->disorderRatio > 0) { + lenOfRow = generateStbRowData(superTblInfo, data, + startTime + getTSRandTail( + superTblInfo->timeStampStep, k, + superTblInfo->disorderRatio, + superTblInfo->disorderRange) + ); + } else { + lenOfRow = generateStbRowData(superTblInfo, data, + startTime + superTblInfo->timeStampStep * k + ); + } + } else { + lenOfRow = getRowDataFromSample( + data, + (remainderBufLen < MAX_DATA_SIZE)?remainderBufLen:MAX_DATA_SIZE, + startTime + superTblInfo->timeStampStep * k, + superTblInfo, + pSamplePos); + } - if ((lenOfRow + 1) > remainderBufLen) { - break; - } + if ((lenOfRow + 1) > remainderBufLen) { + break; + } - pstr += snprintf(pstr , lenOfRow + 1, "%s", data); - k++; - len += lenOfRow; - remainderBufLen -= lenOfRow; + pstr += snprintf(pstr , lenOfRow + 1, "%s", data); + k++; + len += lenOfRow; + remainderBufLen -= lenOfRow; - verbosePrint("%s() LN%d len=%"PRIu64" k=%u \nbuffer=%s\n", - __func__, __LINE__, len, k, buffer); + verbosePrint("%s() LN%d len=%"PRIu64" k=%u \nbuffer=%s\n", + __func__, __LINE__, len, k, buffer); - recordFrom ++; + recordFrom ++; - if (recordFrom >= insertRows) { - break; + if (recordFrom >= insertRows) { + break; + } } - } - *dataLen = len; - return k; + *dataLen = len; + return k; } @@ -5347,52 +5384,52 @@ static int32_t generateStbInterlaceData( int64_t startTime, uint64_t *pRemainderBufLen) { - assert(buffer); - char *pstr = buffer; + assert(buffer); + char *pstr = buffer; - int headLen = generateStbSQLHead( - superTblInfo, - tableName, tableSeq, pThreadInfo->db_name, - pstr, *pRemainderBufLen); + int headLen = generateStbSQLHead( + superTblInfo, + tableName, tableSeq, pThreadInfo->db_name, + pstr, *pRemainderBufLen); - if (headLen <= 0) { - return 0; - } - // generate data buffer - verbosePrint("[%d] %s() LN%d i=%"PRIu64" buffer:\n%s\n", + if (headLen <= 0) { + return 0; + } + // generate data buffer + verbosePrint("[%d] %s() LN%d i=%"PRIu64" buffer:\n%s\n", pThreadInfo->threadID, __func__, __LINE__, i, buffer); - pstr += headLen; - *pRemainderBufLen -= headLen; + pstr += headLen; + *pRemainderBufLen -= headLen; - int64_t dataLen = 0; + int64_t dataLen = 0; - verbosePrint("[%d] %s() LN%d i=%"PRIu64" batchPerTblTimes=%u batchPerTbl = %u\n", + verbosePrint("[%d] %s() LN%d i=%"PRIu64" batchPerTblTimes=%u batchPerTbl = %u\n", pThreadInfo->threadID, __func__, __LINE__, i, batchPerTblTimes, batchPerTbl); - if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { - startTime = taosGetTimestamp(pThreadInfo->time_precision); - } + if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { + startTime = taosGetTimestamp(pThreadInfo->time_precision); + } - int32_t k = generateStbDataTail( + int32_t k = generateStbDataTail( superTblInfo, batchPerTbl, pstr, *pRemainderBufLen, insertRows, 0, startTime, &(pThreadInfo->samplePos), &dataLen); - if (k == batchPerTbl) { - pstr += dataLen; - *pRemainderBufLen -= dataLen; - } else { - debugPrint("%s() LN%d, generated data tail: %u, not equal batch per table: %u\n", - __func__, __LINE__, k, batchPerTbl); - pstr -= headLen; - pstr[0] = '\0'; - k = 0; - } + if (k == batchPerTbl) { + pstr += dataLen; + *pRemainderBufLen -= dataLen; + } else { + debugPrint("%s() LN%d, generated data tail: %u, not equal batch per table: %u\n", + __func__, __LINE__, k, batchPerTbl); + pstr -= headLen; + pstr[0] = '\0'; + k = 0; + } - return k; + return k; } static int64_t generateInterlaceDataWithoutStb( @@ -5656,10 +5693,15 @@ static int32_t prepareStmtWithoutStb( bind_ts = (int64_t *)ptr; bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - *bind_ts = startTime + getTSRandTail( - (int64_t)DEFAULT_TIMESTAMP_STEP, k, - g_args.disorderRatio, - g_args.disorderRange); + + if (g_args.disorderRatio) { + *bind_ts = startTime + getTSRandTail( + (int64_t)DEFAULT_TIMESTAMP_STEP, k, + g_args.disorderRatio, + g_args.disorderRange); + } else { + *bind_ts = startTime + (int64_t)(DEFAULT_TIMESTAMP_STEP * k); + } bind->buffer_length = sizeof(int64_t); bind->buffer = bind_ts; bind->length = &bind->buffer_length; @@ -5744,7 +5786,7 @@ static int32_t prepareStbStmt( bind_ts = (int64_t *)ptr; bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - if (sourceRand) { + if (stbInfo->disorderRatio) { *bind_ts = startTime + getTSRandTail( stbInfo->timeStampStep, k, stbInfo->disorderRatio, @@ -5811,6 +5853,7 @@ static int32_t prepareStbStmt( if (!sourceRand) { (*pSamplePos) ++; } + if (recordFrom >= insertRows) { break; } @@ -5820,6 +5863,43 @@ static int32_t prepareStbStmt( free(bindArray); return k; } + +static int32_t prepareStbStmtInterlace( + SSuperTable *stbInfo, + TAOS_STMT *stmt, + char *tableName, uint32_t batch, + uint64_t insertRows, + uint64_t recordFrom, + int64_t startTime, + int64_t *pSamplePos) +{ + return prepareStbStmt( + stbInfo, + stmt, + tableName, + batch, + insertRows, 0, startTime, + pSamplePos); +} + +static int32_t prepareStbStmtProgressive( + SSuperTable *stbInfo, + TAOS_STMT *stmt, + char *tableName, uint32_t batch, + uint64_t insertRows, + uint64_t recordFrom, + int64_t startTime, + int64_t *pSamplePos) +{ + return prepareStbStmt( + stbInfo, + stmt, + tableName, + g_args.num_of_RPR, + insertRows, recordFrom, startTime, + pSamplePos); +} + #endif static int32_t generateStbProgressiveData( @@ -5831,29 +5911,29 @@ static int32_t generateStbProgressiveData( uint64_t recordFrom, int64_t startTime, int64_t *pSamplePos, int64_t *pRemainderBufLen) { - assert(buffer != NULL); - char *pstr = buffer; + assert(buffer != NULL); + char *pstr = buffer; - memset(buffer, 0, *pRemainderBufLen); + memset(buffer, 0, *pRemainderBufLen); - int64_t headLen = generateStbSQLHead( - superTblInfo, - tableName, tableSeq, dbName, - buffer, *pRemainderBufLen); + int64_t headLen = generateStbSQLHead( + superTblInfo, + tableName, tableSeq, dbName, + buffer, *pRemainderBufLen); - if (headLen <= 0) { - return 0; - } - pstr += headLen; - *pRemainderBufLen -= headLen; + if (headLen <= 0) { + return 0; + } + pstr += headLen; + *pRemainderBufLen -= headLen; - int64_t dataLen; + int64_t dataLen; - return generateStbDataTail(superTblInfo, - g_args.num_of_RPR, pstr, *pRemainderBufLen, - insertRows, recordFrom, - startTime, - pSamplePos, &dataLen); + return generateStbDataTail(superTblInfo, + g_args.num_of_RPR, pstr, *pRemainderBufLen, + insertRows, recordFrom, + startTime, + pSamplePos, &dataLen); } static int32_t generateProgressiveDataWithoutStb( @@ -5890,291 +5970,293 @@ static int32_t generateProgressiveDataWithoutStb( static void printStatPerThread(threadInfo *pThreadInfo) { fprintf(stderr, "====thread[%d] completed total inserted rows: %"PRIu64 ", total affected rows: %"PRIu64". %.2f records/second====\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows, - (pThreadInfo->totalDelay)?(double)((pThreadInfo->totalAffectedRows / (pThreadInfo->totalDelay)/1000.0)): FLT_MAX); + pThreadInfo->threadID, + pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows, + (pThreadInfo->totalDelay/1000.0)? + (double)(pThreadInfo->totalAffectedRows/(pThreadInfo->totalDelay/1000.0)): + FLT_MAX); } // sync write interlace data static void* syncWriteInterlace(threadInfo *pThreadInfo) { - debugPrint("[%d] %s() LN%d: ### interlace write\n", - pThreadInfo->threadID, __func__, __LINE__); + debugPrint("[%d] %s() LN%d: ### interlace write\n", + pThreadInfo->threadID, __func__, __LINE__); - int64_t insertRows; - uint32_t interlaceRows; - uint64_t maxSqlLen; - int64_t nTimeStampStep; - uint64_t insert_interval; + int64_t insertRows; + uint32_t interlaceRows; + uint64_t maxSqlLen; + int64_t nTimeStampStep; + uint64_t insert_interval; - SSuperTable* superTblInfo = pThreadInfo->superTblInfo; + SSuperTable* superTblInfo = pThreadInfo->superTblInfo; - if (superTblInfo) { - insertRows = superTblInfo->insertRows; + if (superTblInfo) { + insertRows = superTblInfo->insertRows; - if ((superTblInfo->interlaceRows == 0) - && (g_args.interlace_rows > 0)) { - interlaceRows = g_args.interlace_rows; + if ((superTblInfo->interlaceRows == 0) + && (g_args.interlace_rows > 0)) { + interlaceRows = g_args.interlace_rows; + } else { + interlaceRows = superTblInfo->interlaceRows; + } + maxSqlLen = superTblInfo->maxSqlLen; + nTimeStampStep = superTblInfo->timeStampStep; + insert_interval = superTblInfo->insertInterval; } else { - interlaceRows = superTblInfo->interlaceRows; + insertRows = g_args.num_of_DPT; + interlaceRows = g_args.interlace_rows; + maxSqlLen = g_args.max_sql_len; + nTimeStampStep = DEFAULT_TIMESTAMP_STEP; + insert_interval = g_args.insert_interval; } - maxSqlLen = superTblInfo->maxSqlLen; - nTimeStampStep = superTblInfo->timeStampStep; - insert_interval = superTblInfo->insertInterval; - } else { - insertRows = g_args.num_of_DPT; - interlaceRows = g_args.interlace_rows; - maxSqlLen = g_args.max_sql_len; - nTimeStampStep = DEFAULT_TIMESTAMP_STEP; - insert_interval = g_args.insert_interval; - } - debugPrint("[%d] %s() LN%d: start_table_from=%"PRIu64" ntables=%"PRId64" insertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, - pThreadInfo->start_table_from, - pThreadInfo->ntables, insertRows); + debugPrint("[%d] %s() LN%d: start_table_from=%"PRIu64" ntables=%"PRId64" insertRows=%"PRIu64"\n", + pThreadInfo->threadID, __func__, __LINE__, + pThreadInfo->start_table_from, + pThreadInfo->ntables, insertRows); - if (interlaceRows > insertRows) - interlaceRows = insertRows; + if (interlaceRows > insertRows) + interlaceRows = insertRows; - if (interlaceRows > g_args.num_of_RPR) - interlaceRows = g_args.num_of_RPR; + if (interlaceRows > g_args.num_of_RPR) + interlaceRows = g_args.num_of_RPR; - uint32_t batchPerTbl = interlaceRows; - uint32_t batchPerTblTimes; + uint32_t batchPerTbl = interlaceRows; + uint32_t batchPerTblTimes; - if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { - batchPerTblTimes = - g_args.num_of_RPR / interlaceRows; - } else { - batchPerTblTimes = 1; - } + if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { + batchPerTblTimes = + g_args.num_of_RPR / interlaceRows; + } else { + batchPerTblTimes = 1; + } - pThreadInfo->buffer = calloc(maxSqlLen, 1); - if (NULL == pThreadInfo->buffer) { - errorPrint( "%s() LN%d, Failed to alloc %"PRIu64" Bytes, reason:%s\n", - __func__, __LINE__, maxSqlLen, strerror(errno)); - return NULL; - } + pThreadInfo->buffer = calloc(maxSqlLen, 1); + if (NULL == pThreadInfo->buffer) { + errorPrint( "%s() LN%d, Failed to alloc %"PRIu64" Bytes, reason:%s\n", + __func__, __LINE__, maxSqlLen, strerror(errno)); + return NULL; + } - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; + pThreadInfo->totalInsertRows = 0; + pThreadInfo->totalAffectedRows = 0; - uint64_t st = 0; - uint64_t et = UINT64_MAX; + uint64_t st = 0; + uint64_t et = UINT64_MAX; - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - uint64_t endTs; + uint64_t lastPrintTime = taosGetTimestampMs(); + uint64_t startTs = taosGetTimestampMs(); + uint64_t endTs; - uint64_t tableSeq = pThreadInfo->start_table_from; - int64_t startTime = pThreadInfo->start_time; + uint64_t tableSeq = pThreadInfo->start_table_from; + int64_t startTime = pThreadInfo->start_time; - uint64_t generatedRecPerTbl = 0; - bool flagSleep = true; - uint64_t sleepTimeTotal = 0; + uint64_t generatedRecPerTbl = 0; + bool flagSleep = true; + uint64_t sleepTimeTotal = 0; - while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { - if ((flagSleep) && (insert_interval)) { - st = taosGetTimestampMs(); - flagSleep = false; - } - // generate data - memset(pThreadInfo->buffer, 0, maxSqlLen); - uint64_t remainderBufLen = maxSqlLen; + while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { + if ((flagSleep) && (insert_interval)) { + st = taosGetTimestampMs(); + flagSleep = false; + } + // generate data + memset(pThreadInfo->buffer, 0, maxSqlLen); + uint64_t remainderBufLen = maxSqlLen; - char *pstr = pThreadInfo->buffer; + char *pstr = pThreadInfo->buffer; - int len = snprintf(pstr, - strlen(STR_INSERT_INTO) + 1, "%s", STR_INSERT_INTO); - pstr += len; - remainderBufLen -= len; + int len = snprintf(pstr, + strlen(STR_INSERT_INTO) + 1, "%s", STR_INSERT_INTO); + pstr += len; + remainderBufLen -= len; - uint32_t recOfBatch = 0; + uint32_t recOfBatch = 0; - for (uint32_t i = 0; i < batchPerTblTimes; i ++) { - char tableName[TSDB_TABLE_NAME_LEN]; + for (uint64_t i = 0; i < batchPerTblTimes; i ++) { + char tableName[TSDB_TABLE_NAME_LEN]; - getTableName(tableName, pThreadInfo, tableSeq); - if (0 == strlen(tableName)) { - errorPrint("[%d] %s() LN%d, getTableName return null\n", - pThreadInfo->threadID, __func__, __LINE__); - free(pThreadInfo->buffer); - return NULL; - } + getTableName(tableName, pThreadInfo, tableSeq); + if (0 == strlen(tableName)) { + errorPrint("[%d] %s() LN%d, getTableName return null\n", + pThreadInfo->threadID, __func__, __LINE__); + free(pThreadInfo->buffer); + return NULL; + } - uint64_t oldRemainderLen = remainderBufLen; + uint64_t oldRemainderLen = remainderBufLen; - int32_t generated; - if (superTblInfo) { - if (superTblInfo->iface == STMT_IFACE) { + int32_t generated; + if (superTblInfo) { + if (superTblInfo->iface == STMT_IFACE) { #if STMT_IFACE_ENABLED == 1 - generated = prepareStbStmt( - superTblInfo, - pThreadInfo->stmt, - tableName, - batchPerTbl, - insertRows, i, - startTime, - &(pThreadInfo->samplePos)); + generated = prepareStbStmtInterlace( + superTblInfo, + pThreadInfo->stmt, + tableName, + batchPerTbl, + insertRows, i, + startTime, + &(pThreadInfo->samplePos)); #else - generated = -1; + generated = -1; #endif - } else { - generated = generateStbInterlaceData( - superTblInfo, - tableName, batchPerTbl, i, - batchPerTblTimes, - tableSeq, - pThreadInfo, pstr, - insertRows, - startTime, - &remainderBufLen); - } - } else { - if (g_args.iface == STMT_IFACE) { - debugPrint("[%d] %s() LN%d, tableName:%s, batch:%d startTime:%"PRId64"\n", - pThreadInfo->threadID, - __func__, __LINE__, - tableName, batchPerTbl, startTime); + } else { + generated = generateStbInterlaceData( + superTblInfo, + tableName, batchPerTbl, i, + batchPerTblTimes, + tableSeq, + pThreadInfo, pstr, + insertRows, + startTime, + &remainderBufLen); + } + } else { + if (g_args.iface == STMT_IFACE) { + debugPrint("[%d] %s() LN%d, tableName:%s, batch:%d startTime:%"PRId64"\n", + pThreadInfo->threadID, + __func__, __LINE__, + tableName, batchPerTbl, startTime); #if STMT_IFACE_ENABLED == 1 - generated = prepareStmtWithoutStb( - pThreadInfo->stmt, tableName, - batchPerTbl, - insertRows, i, - startTime); + generated = prepareStmtWithoutStb( + pThreadInfo->stmt, tableName, + batchPerTbl, + insertRows, i, + startTime); #else - generated = -1; + generated = -1; #endif - } else { - generated = generateInterlaceDataWithoutStb( - tableName, batchPerTbl, - tableSeq, - pThreadInfo->db_name, pstr, - insertRows, - startTime, - &remainderBufLen); - } - } - - debugPrint("[%d] %s() LN%d, generated records is %d\n", - pThreadInfo->threadID, __func__, __LINE__, generated); - if (generated < 0) { - errorPrint("[%d] %s() LN%d, generated records is %d\n", - pThreadInfo->threadID, __func__, __LINE__, generated); - goto free_of_interlace; - } else if (generated == 0) { - break; - } - - tableSeq ++; - recOfBatch += batchPerTbl; + } else { + generated = generateInterlaceDataWithoutStb( + tableName, batchPerTbl, + tableSeq, + pThreadInfo->db_name, pstr, + insertRows, + startTime, + &remainderBufLen); + } + } - pstr += (oldRemainderLen - remainderBufLen); - pThreadInfo->totalInsertRows += batchPerTbl; + debugPrint("[%d] %s() LN%d, generated records is %d\n", + pThreadInfo->threadID, __func__, __LINE__, generated); + if (generated < 0) { + errorPrint("[%d] %s() LN%d, generated records is %d\n", + pThreadInfo->threadID, __func__, __LINE__, generated); + goto free_of_interlace; + } else if (generated == 0) { + break; + } - verbosePrint("[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d\n", - pThreadInfo->threadID, __func__, __LINE__, - batchPerTbl, recOfBatch); + tableSeq ++; + recOfBatch += batchPerTbl; - if (tableSeq == pThreadInfo->start_table_from + pThreadInfo->ntables) { - // turn to first table - tableSeq = pThreadInfo->start_table_from; - generatedRecPerTbl += batchPerTbl; + pstr += (oldRemainderLen - remainderBufLen); + pThreadInfo->totalInsertRows += batchPerTbl; - startTime = pThreadInfo->start_time - + generatedRecPerTbl * nTimeStampStep; + verbosePrint("[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d\n", + pThreadInfo->threadID, __func__, __LINE__, + batchPerTbl, recOfBatch); - flagSleep = true; - if (generatedRecPerTbl >= insertRows) - break; + if (tableSeq == pThreadInfo->start_table_from + pThreadInfo->ntables) { + // turn to first table + tableSeq = pThreadInfo->start_table_from; + generatedRecPerTbl += batchPerTbl; - int64_t remainRows = insertRows - generatedRecPerTbl; - if ((remainRows > 0) && (batchPerTbl > remainRows)) - batchPerTbl = remainRows; + startTime = pThreadInfo->start_time + + generatedRecPerTbl * nTimeStampStep; - if (pThreadInfo->ntables * batchPerTbl < g_args.num_of_RPR) - break; - } + flagSleep = true; + if (generatedRecPerTbl >= insertRows) + break; - verbosePrint("[%d] %s() LN%d generatedRecPerTbl=%"PRId64" insertRows=%"PRId64"\n", - pThreadInfo->threadID, __func__, __LINE__, - generatedRecPerTbl, insertRows); + int64_t remainRows = insertRows - generatedRecPerTbl; + if ((remainRows > 0) && (batchPerTbl > remainRows)) + batchPerTbl = remainRows; - if ((g_args.num_of_RPR - recOfBatch) < batchPerTbl) - break; - } + if (pThreadInfo->ntables * batchPerTbl < g_args.num_of_RPR) + break; + } - verbosePrint("[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, recOfBatch, - pThreadInfo->totalInsertRows); - verbosePrint("[%d] %s() LN%d, buffer=%s\n", - pThreadInfo->threadID, __func__, __LINE__, pThreadInfo->buffer); + verbosePrint("[%d] %s() LN%d generatedRecPerTbl=%"PRId64" insertRows=%"PRId64"\n", + pThreadInfo->threadID, __func__, __LINE__, + generatedRecPerTbl, insertRows); - startTs = taosGetTimestampMs(); + if ((g_args.num_of_RPR - recOfBatch) < batchPerTbl) + break; + } - if (recOfBatch == 0) { - errorPrint("[%d] %s() LN%d Failed to insert records of batch %d\n", - pThreadInfo->threadID, __func__, __LINE__, - batchPerTbl); - if (batchPerTbl > 0) { - errorPrint("\tIf the batch is %d, the length of the SQL to insert a row must be less then %"PRId64"\n", - batchPerTbl, maxSqlLen / batchPerTbl); + verbosePrint("[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"PRIu64"\n", + pThreadInfo->threadID, __func__, __LINE__, recOfBatch, + pThreadInfo->totalInsertRows); + verbosePrint("[%d] %s() LN%d, buffer=%s\n", + pThreadInfo->threadID, __func__, __LINE__, pThreadInfo->buffer); + + startTs = taosGetTimestampMs(); + + if (recOfBatch == 0) { + errorPrint("[%d] %s() LN%d Failed to insert records of batch %d\n", + pThreadInfo->threadID, __func__, __LINE__, + batchPerTbl); + if (batchPerTbl > 0) { + errorPrint("\tIf the batch is %d, the length of the SQL to insert a row must be less then %"PRId64"\n", + batchPerTbl, maxSqlLen / batchPerTbl); + } + errorPrint("\tPlease check if the buffer length(%"PRId64") or batch(%d) is set with proper value!\n", + maxSqlLen, batchPerTbl); + goto free_of_interlace; } - errorPrint("\tPlease check if the buffer length(%"PRId64") or batch(%d) is set with proper value!\n", - maxSqlLen, batchPerTbl); - goto free_of_interlace; - } - int64_t affectedRows = execInsert(pThreadInfo, recOfBatch); + int64_t affectedRows = execInsert(pThreadInfo, recOfBatch); - endTs = taosGetTimestampMs(); - uint64_t delay = endTs - startTs; - performancePrint("%s() LN%d, insert execution time is %"PRIu64"ms\n", - __func__, __LINE__, delay); - verbosePrint("[%d] %s() LN%d affectedRows=%"PRId64"\n", - pThreadInfo->threadID, - __func__, __LINE__, affectedRows); + endTs = taosGetTimestampMs(); + uint64_t delay = endTs - startTs; + performancePrint("%s() LN%d, insert execution time is %"PRIu64"ms\n", + __func__, __LINE__, delay); + verbosePrint("[%d] %s() LN%d affectedRows=%"PRId64"\n", + pThreadInfo->threadID, + __func__, __LINE__, affectedRows); - if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; - if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; - pThreadInfo->cntDelay++; - pThreadInfo->totalDelay += delay; + if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; + if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; + pThreadInfo->cntDelay++; + pThreadInfo->totalDelay += delay; - if (recOfBatch != affectedRows) { - errorPrint("[%d] %s() LN%d execInsert insert %d, affected rows: %"PRId64"\n%s\n", - pThreadInfo->threadID, __func__, __LINE__, - recOfBatch, affectedRows, pThreadInfo->buffer); - goto free_of_interlace; - } + if (recOfBatch != affectedRows) { + errorPrint("[%d] %s() LN%d execInsert insert %d, affected rows: %"PRId64"\n%s\n", + pThreadInfo->threadID, __func__, __LINE__, + recOfBatch, affectedRows, pThreadInfo->buffer); + goto free_of_interlace; + } - pThreadInfo->totalAffectedRows += affectedRows; + pThreadInfo->totalAffectedRows += affectedRows; - int64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently inserted rows: %"PRIu64 ", affected rows: %"PRIu64 "\n", + int64_t currentPrintTime = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30*1000) { + printf("thread[%d] has currently inserted rows: %"PRIu64 ", affected rows: %"PRIu64 "\n", pThreadInfo->threadID, pThreadInfo->totalInsertRows, pThreadInfo->totalAffectedRows); - lastPrintTime = currentPrintTime; - } + lastPrintTime = currentPrintTime; + } - if ((insert_interval) && flagSleep) { - et = taosGetTimestampMs(); + if ((insert_interval) && flagSleep) { + et = taosGetTimestampMs(); - if (insert_interval > (et - st) ) { - uint64_t sleepTime = insert_interval - (et -st); - performancePrint("%s() LN%d sleep: %"PRId64" ms for insert interval\n", - __func__, __LINE__, sleepTime); - taosMsleep(sleepTime); // ms - sleepTimeTotal += insert_interval; - } + if (insert_interval > (et - st) ) { + uint64_t sleepTime = insert_interval - (et -st); + performancePrint("%s() LN%d sleep: %"PRId64" ms for insert interval\n", + __func__, __LINE__, sleepTime); + taosMsleep(sleepTime); // ms + sleepTimeTotal += insert_interval; + } + } } - } free_of_interlace: - tmfree(pThreadInfo->buffer); - printStatPerThread(pThreadInfo); - return NULL; + tmfree(pThreadInfo->buffer); + printStatPerThread(pThreadInfo); + return NULL; } // sync insertion progressive data @@ -6238,7 +6320,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { if (superTblInfo) { if (superTblInfo->iface == STMT_IFACE) { #if STMT_IFACE_ENABLED == 1 - generated = prepareStbStmt( + generated = prepareStbStmtProgressive( superTblInfo, pThreadInfo->stmt, tableName, @@ -6341,29 +6423,29 @@ free_of_progressive: static void* syncWrite(void *sarg) { - threadInfo *pThreadInfo = (threadInfo *)sarg; - SSuperTable* superTblInfo = pThreadInfo->superTblInfo; + threadInfo *pThreadInfo = (threadInfo *)sarg; + SSuperTable* superTblInfo = pThreadInfo->superTblInfo; - uint32_t interlaceRows; + uint32_t interlaceRows; - if (superTblInfo) { - if ((superTblInfo->interlaceRows == 0) - && (g_args.interlace_rows > 0)) { - interlaceRows = g_args.interlace_rows; + if (superTblInfo) { + if ((superTblInfo->interlaceRows == 0) + && (g_args.interlace_rows > 0)) { + interlaceRows = g_args.interlace_rows; + } else { + interlaceRows = superTblInfo->interlaceRows; + } } else { - interlaceRows = superTblInfo->interlaceRows; + interlaceRows = g_args.interlace_rows; } - } else { - interlaceRows = g_args.interlace_rows; - } - if (interlaceRows > 0) { - // interlace mode - return syncWriteInterlace(pThreadInfo); - } else { - // progressive mode - return syncWriteProgressive(pThreadInfo); - } + if (interlaceRows > 0) { + // interlace mode + return syncWriteInterlace(pThreadInfo); + } else { + // progressive mode + return syncWriteProgressive(pThreadInfo); + } } static void callBack(void *param, TAOS_RES *res, int code) { @@ -6474,332 +6556,353 @@ static int convertHostToServAddr(char *host, uint16_t port, struct sockaddr_in * static void startMultiThreadInsertData(int threads, char* db_name, char* precision, SSuperTable* superTblInfo) { - int32_t timePrec = TSDB_TIME_PRECISION_MILLI; - if (0 != precision[0]) { - if (0 == strncasecmp(precision, "ms", 2)) { - timePrec = TSDB_TIME_PRECISION_MILLI; - } else if (0 == strncasecmp(precision, "us", 2)) { - timePrec = TSDB_TIME_PRECISION_MICRO; - } else if (0 == strncasecmp(precision, "ns", 2)) { - timePrec = TSDB_TIME_PRECISION_NANO; - } else { - errorPrint("Not support precision: %s\n", precision); - exit(-1); + int32_t timePrec = TSDB_TIME_PRECISION_MILLI; + if (0 != precision[0]) { + if (0 == strncasecmp(precision, "ms", 2)) { + timePrec = TSDB_TIME_PRECISION_MILLI; + } else if (0 == strncasecmp(precision, "us", 2)) { + timePrec = TSDB_TIME_PRECISION_MICRO; +#if NANO_SECOND_ENABLED == 1 + } else if (0 == strncasecmp(precision, "ns", 2)) { + timePrec = TSDB_TIME_PRECISION_NANO; +#endif + } else { + errorPrint("Not support precision: %s\n", precision); + exit(-1); + } } - } - int64_t start_time; - if (superTblInfo) { - if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { - start_time = taosGetTimestamp(timePrec); + int64_t start_time; + if (superTblInfo) { + if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { + start_time = taosGetTimestamp(timePrec); + } else { + if (TSDB_CODE_SUCCESS != taosParseTime( + superTblInfo->startTimestamp, + &start_time, + strlen(superTblInfo->startTimestamp), + timePrec, 0)) { + ERROR_EXIT("failed to parse time!\n"); + } + } } else { - if (TSDB_CODE_SUCCESS != taosParseTime( - superTblInfo->startTimestamp, - &start_time, - strlen(superTblInfo->startTimestamp), - timePrec, 0)) { - ERROR_EXIT("failed to parse time!\n"); - } + start_time = 1500000000000; } - } else { - start_time = 1500000000000; - } - int64_t start = taosGetTimestampMs(); + int64_t start = taosGetTimestampMs(); - // read sample data from file first - if ((superTblInfo) && (0 == strncasecmp(superTblInfo->dataSource, - "sample", strlen("sample")))) { - if (0 != prepareSampleDataForSTable(superTblInfo)) { - errorPrint("%s() LN%d, prepare sample data for stable failed!\n", - __func__, __LINE__); - exit(-1); + // read sample data from file first + if ((superTblInfo) && (0 == strncasecmp(superTblInfo->dataSource, + "sample", strlen("sample")))) { + if (0 != prepareSampleDataForSTable(superTblInfo)) { + errorPrint("%s() LN%d, prepare sample data for stable failed!\n", + __func__, __LINE__); + exit(-1); + } } - } - TAOS* taos0 = taos_connect( - g_Dbs.host, g_Dbs.user, - g_Dbs.password, db_name, g_Dbs.port); - if (NULL == taos0) { - errorPrint("%s() LN%d, connect to server fail , reason: %s\n", + TAOS* taos0 = taos_connect( + g_Dbs.host, g_Dbs.user, + g_Dbs.password, db_name, g_Dbs.port); + if (NULL == taos0) { + errorPrint("%s() LN%d, connect to server fail , reason: %s\n", __func__, __LINE__, taos_errstr(NULL)); - exit(-1); - } + exit(-1); + } - int64_t ntables = 0; - uint64_t tableFrom; + int64_t ntables = 0; + uint64_t tableFrom; - if (superTblInfo) { - int64_t limit; - uint64_t offset; + if (superTblInfo) { + int64_t limit; + uint64_t offset; - if ((NULL != g_args.sqlFile) && (superTblInfo->childTblExists == TBL_NO_EXISTS) && - ((superTblInfo->childTblOffset != 0) || (superTblInfo->childTblLimit >= 0))) { - printf("WARNING: offset and limit will not be used since the child tables not exists!\n"); - } + if ((NULL != g_args.sqlFile) && (superTblInfo->childTblExists == TBL_NO_EXISTS) && + ((superTblInfo->childTblOffset != 0) || (superTblInfo->childTblLimit >= 0))) { + printf("WARNING: offset and limit will not be used since the child tables not exists!\n"); + } - if (superTblInfo->childTblExists == TBL_ALREADY_EXISTS) { - if ((superTblInfo->childTblLimit < 0) - || ((superTblInfo->childTblOffset + superTblInfo->childTblLimit) - > (superTblInfo->childTblCount))) { - superTblInfo->childTblLimit = - superTblInfo->childTblCount - superTblInfo->childTblOffset; - } + if (superTblInfo->childTblExists == TBL_ALREADY_EXISTS) { + if ((superTblInfo->childTblLimit < 0) + || ((superTblInfo->childTblOffset + superTblInfo->childTblLimit) + > (superTblInfo->childTblCount))) { + superTblInfo->childTblLimit = + superTblInfo->childTblCount - superTblInfo->childTblOffset; + } - offset = superTblInfo->childTblOffset; - limit = superTblInfo->childTblLimit; - } else { - limit = superTblInfo->childTblCount; - offset = 0; - } + offset = superTblInfo->childTblOffset; + limit = superTblInfo->childTblLimit; + } else { + limit = superTblInfo->childTblCount; + offset = 0; + } - ntables = limit; - tableFrom = offset; + ntables = limit; + tableFrom = offset; - if ((superTblInfo->childTblExists != TBL_NO_EXISTS) - && ((superTblInfo->childTblOffset + superTblInfo->childTblLimit ) - > superTblInfo->childTblCount)) { - printf("WARNING: specified offset + limit > child table count!\n"); - prompt(); - } + if ((superTblInfo->childTblExists != TBL_NO_EXISTS) + && ((superTblInfo->childTblOffset + superTblInfo->childTblLimit ) + > superTblInfo->childTblCount)) { + printf("WARNING: specified offset + limit > child table count!\n"); + prompt(); + } - if ((superTblInfo->childTblExists != TBL_NO_EXISTS) - && (0 == superTblInfo->childTblLimit)) { - printf("WARNING: specified limit = 0, which cannot find table name to insert or query! \n"); - prompt(); - } + if ((superTblInfo->childTblExists != TBL_NO_EXISTS) + && (0 == superTblInfo->childTblLimit)) { + printf("WARNING: specified limit = 0, which cannot find table name to insert or query! \n"); + prompt(); + } - superTblInfo->childTblName = (char*)calloc(1, - limit * TSDB_TABLE_NAME_LEN); - if (superTblInfo->childTblName == NULL) { - errorPrint("%s() LN%d, alloc memory failed!\n", __func__, __LINE__); - taos_close(taos0); - exit(-1); - } + superTblInfo->childTblName = (char*)calloc(1, + limit * TSDB_TABLE_NAME_LEN); + if (superTblInfo->childTblName == NULL) { + errorPrint("%s() LN%d, alloc memory failed!\n", __func__, __LINE__); + taos_close(taos0); + exit(-1); + } - int64_t childTblCount; - getChildNameOfSuperTableWithLimitAndOffset( - taos0, - db_name, superTblInfo->sTblName, - &superTblInfo->childTblName, &childTblCount, - limit, - offset); - } else { - ntables = g_args.num_of_tables; - tableFrom = 0; - } + int64_t childTblCount; + getChildNameOfSuperTableWithLimitAndOffset( + taos0, + db_name, superTblInfo->sTblName, + &superTblInfo->childTblName, &childTblCount, + limit, + offset); + } else { + ntables = g_args.num_of_tables; + tableFrom = 0; + } - taos_close(taos0); + taos_close(taos0); - int64_t a = ntables / threads; - if (a < 1) { - threads = ntables; - a = 1; - } + int64_t a = ntables / threads; + if (a < 1) { + threads = ntables; + a = 1; + } - int64_t b = 0; - if (threads != 0) { - b = ntables % threads; - } + int64_t b = 0; + if (threads != 0) { + b = ntables % threads; + } - if ((superTblInfo) - && (superTblInfo->iface == REST_IFACE)) { - if (convertHostToServAddr( - g_Dbs.host, g_Dbs.port, &(g_Dbs.serv_addr)) != 0) { - exit(-1); - } - } + if ((superTblInfo) + && (superTblInfo->iface == REST_IFACE)) { + if (convertHostToServAddr( + g_Dbs.host, g_Dbs.port, &(g_Dbs.serv_addr)) != 0) { + exit(-1); + } + } - pthread_t *pids = calloc(1, threads * sizeof(pthread_t)); - assert(pids != NULL); + pthread_t *pids = calloc(1, threads * sizeof(pthread_t)); + assert(pids != NULL); - threadInfo *infos = calloc(1, threads * sizeof(threadInfo)); - assert(infos != NULL); + threadInfo *infos = calloc(1, threads * sizeof(threadInfo)); + assert(infos != NULL); - memset(pids, 0, threads * sizeof(pthread_t)); - memset(infos, 0, threads * sizeof(threadInfo)); + memset(pids, 0, threads * sizeof(pthread_t)); + memset(infos, 0, threads * sizeof(threadInfo)); - for (int i = 0; i < threads; i++) { - threadInfo *pThreadInfo = infos + i; - pThreadInfo->threadID = i; - tstrncpy(pThreadInfo->db_name, db_name, TSDB_DB_NAME_LEN); - pThreadInfo->time_precision = timePrec; - pThreadInfo->superTblInfo = superTblInfo; + for (int i = 0; i < threads; i++) { + threadInfo *pThreadInfo = infos + i; + pThreadInfo->threadID = i; + tstrncpy(pThreadInfo->db_name, db_name, TSDB_DB_NAME_LEN); + pThreadInfo->time_precision = timePrec; + pThreadInfo->superTblInfo = superTblInfo; + + pThreadInfo->start_time = start_time; + pThreadInfo->minDelay = UINT64_MAX; + + if ((NULL == superTblInfo) || + (superTblInfo->iface != REST_IFACE)) { + //t_info->taos = taos; + pThreadInfo->taos = taos_connect( + g_Dbs.host, g_Dbs.user, + g_Dbs.password, db_name, g_Dbs.port); + if (NULL == pThreadInfo->taos) { + errorPrint( + "%s() LN%d, connect to server fail from insert sub thread, reason: %s\n", + __func__, __LINE__, + taos_errstr(NULL)); + free(infos); + exit(-1); + } - pThreadInfo->start_time = start_time; - pThreadInfo->minDelay = UINT64_MAX; +#if STMT_IFACE_ENABLED == 1 + if ((g_args.iface == STMT_IFACE) + || ((superTblInfo) && (superTblInfo->iface == STMT_IFACE))) { - if ((NULL == superTblInfo) || - (superTblInfo->iface != REST_IFACE)) { - //t_info->taos = taos; - pThreadInfo->taos = taos_connect( - g_Dbs.host, g_Dbs.user, - g_Dbs.password, db_name, g_Dbs.port); - if (NULL == pThreadInfo->taos) { - errorPrint( - "%s() LN%d, connect to server fail from insert sub thread, reason: %s\n", - __func__, __LINE__, - taos_errstr(NULL)); - free(infos); - exit(-1); - } + int columnCount; + if (superTblInfo) { + columnCount = superTblInfo->columnCount; + } else { + columnCount = g_args.num_of_CPR; + } -#if STMT_IFACE_ENABLED == 1 - if ((g_args.iface == STMT_IFACE) - || ((superTblInfo) && (superTblInfo->iface == STMT_IFACE))) { + pThreadInfo->stmt = taos_stmt_init(pThreadInfo->taos); + if (NULL == pThreadInfo->stmt) { + errorPrint( + "%s() LN%d, failed init stmt, reason: %s\n", + __func__, __LINE__, + taos_errstr(NULL)); + free(pids); + free(infos); + exit(-1); + } - int columnCount; - if (superTblInfo) { - columnCount = superTblInfo->columnCount; - } else { - columnCount = g_args.num_of_CPR; - } + char buffer[3000]; + char *pstr = buffer; - pThreadInfo->stmt = taos_stmt_init(pThreadInfo->taos); - if (NULL == pThreadInfo->stmt) { - errorPrint( - "%s() LN%d, failed init stmt, reason: %s\n", - __func__, __LINE__, - taos_errstr(NULL)); - free(pids); - free(infos); - exit(-1); - } + if ((superTblInfo) + && (AUTO_CREATE_SUBTBL + == superTblInfo->autoCreateTable)) { + pstr += sprintf(pstr, "INSERT INTO ? USING %s TAGS(?", + superTblInfo->sTblName); + for (int tag = 0; tag < (superTblInfo->tagCount - 1); tag ++ ) { + pstr += sprintf(pstr, ",?"); + } + pstr += sprintf(pstr, ") VALUES(?"); + } else { + pstr += sprintf(pstr, "INSERT INTO ? VALUES(?"); + } - char buffer[3000]; - char *pstr = buffer; - pstr += sprintf(pstr, "INSERT INTO ? values(?"); + for (int col = 0; col < columnCount; col ++) { + pstr += sprintf(pstr, ",?"); + } + pstr += sprintf(pstr, ")"); - for (int col = 0; col < columnCount; col ++) { - pstr += sprintf(pstr, ",?"); + debugPrint("%s() LN%d, buffer: %s", __func__, __LINE__, buffer); + int ret = taos_stmt_prepare(pThreadInfo->stmt, buffer, 0); + if (ret != 0){ + errorPrint("failed to execute taos_stmt_prepare. return 0x%x. reason: %s\n", + ret, taos_errstr(NULL)); + free(pids); + free(infos); + exit(-1); + } + } +#endif + } else { + pThreadInfo->taos = NULL; } - pstr += sprintf(pstr, ")"); - int ret = taos_stmt_prepare(pThreadInfo->stmt, buffer, 0); - if (ret != 0){ - errorPrint("failed to execute taos_stmt_prepare. return 0x%x. reason: %s\n", - ret, taos_errstr(NULL)); - free(pids); - free(infos); - exit(-1); + /* if ((NULL == superTblInfo) + || (0 == superTblInfo->multiThreadWriteOneTbl)) { + */ + pThreadInfo->start_table_from = tableFrom; + pThreadInfo->ntables = iend_table_to = i < b ? tableFrom + a : tableFrom + a - 1; + tableFrom = pThreadInfo->end_table_to + 1; + /* } else { + pThreadInfo->start_table_from = 0; + pThreadInfo->ntables = superTblInfo->childTblCount; + pThreadInfo->start_time = pThreadInfo->start_time + rand_int() % 10000 - rand_tinyint(); + } + */ + tsem_init(&(pThreadInfo->lock_sem), 0, 0); + if (ASYNC_MODE == g_Dbs.asyncMode) { + pthread_create(pids + i, NULL, asyncWrite, pThreadInfo); + } else { + pthread_create(pids + i, NULL, syncWrite, pThreadInfo); } - } -#endif - } else { - pThreadInfo->taos = NULL; } -/* if ((NULL == superTblInfo) - || (0 == superTblInfo->multiThreadWriteOneTbl)) { - */ - pThreadInfo->start_table_from = tableFrom; - pThreadInfo->ntables = iend_table_to = i < b ? tableFrom + a : tableFrom + a - 1; - tableFrom = pThreadInfo->end_table_to + 1; -/* } else { - pThreadInfo->start_table_from = 0; - pThreadInfo->ntables = superTblInfo->childTblCount; - pThreadInfo->start_time = pThreadInfo->start_time + rand_int() % 10000 - rand_tinyint(); - } -*/ - tsem_init(&(pThreadInfo->lock_sem), 0, 0); - if (ASYNC_MODE == g_Dbs.asyncMode) { - pthread_create(pids + i, NULL, asyncWrite, pThreadInfo); - } else { - pthread_create(pids + i, NULL, syncWrite, pThreadInfo); + for (int i = 0; i < threads; i++) { + pthread_join(pids[i], NULL); } - } - - for (int i = 0; i < threads; i++) { - pthread_join(pids[i], NULL); - } - uint64_t totalDelay = 0; - uint64_t maxDelay = 0; - uint64_t minDelay = UINT64_MAX; - uint64_t cntDelay = 1; - double avgDelay = 0; + uint64_t totalDelay = 0; + uint64_t maxDelay = 0; + uint64_t minDelay = UINT64_MAX; + uint64_t cntDelay = 1; + double avgDelay = 0; - for (int i = 0; i < threads; i++) { - threadInfo *pThreadInfo = infos + i; + for (int i = 0; i < threads; i++) { + threadInfo *pThreadInfo = infos + i; - tsem_destroy(&(pThreadInfo->lock_sem)); + tsem_destroy(&(pThreadInfo->lock_sem)); #if STMT_IFACE_ENABLED == 1 - if (pThreadInfo->stmt) { - taos_stmt_close(pThreadInfo->stmt); - } + if (pThreadInfo->stmt) { + taos_stmt_close(pThreadInfo->stmt); + } #endif - tsem_destroy(&(pThreadInfo->lock_sem)); - taos_close(pThreadInfo->taos); + tsem_destroy(&(pThreadInfo->lock_sem)); + taos_close(pThreadInfo->taos); - debugPrint("%s() LN%d, [%d] totalInsert=%"PRIu64" totalAffected=%"PRIu64"\n", - __func__, __LINE__, - pThreadInfo->threadID, pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - if (superTblInfo) { - superTblInfo->totalAffectedRows += pThreadInfo->totalAffectedRows; - superTblInfo->totalInsertRows += pThreadInfo->totalInsertRows; - } else { - g_args.totalAffectedRows += pThreadInfo->totalAffectedRows; - g_args.totalInsertRows += pThreadInfo->totalInsertRows; - } + debugPrint("%s() LN%d, [%d] totalInsert=%"PRIu64" totalAffected=%"PRIu64"\n", + __func__, __LINE__, + pThreadInfo->threadID, pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows); + if (superTblInfo) { + superTblInfo->totalAffectedRows += pThreadInfo->totalAffectedRows; + superTblInfo->totalInsertRows += pThreadInfo->totalInsertRows; + } else { + g_args.totalAffectedRows += pThreadInfo->totalAffectedRows; + g_args.totalInsertRows += pThreadInfo->totalInsertRows; + } - totalDelay += pThreadInfo->totalDelay; - cntDelay += pThreadInfo->cntDelay; - if (pThreadInfo->maxDelay > maxDelay) maxDelay = pThreadInfo->maxDelay; - if (pThreadInfo->minDelay < minDelay) minDelay = pThreadInfo->minDelay; - } - cntDelay -= 1; + totalDelay += pThreadInfo->totalDelay; + cntDelay += pThreadInfo->cntDelay; + if (pThreadInfo->maxDelay > maxDelay) maxDelay = pThreadInfo->maxDelay; + if (pThreadInfo->minDelay < minDelay) minDelay = pThreadInfo->minDelay; + } + cntDelay -= 1; - if (cntDelay == 0) cntDelay = 1; - avgDelay = (double)totalDelay / cntDelay; + if (cntDelay == 0) cntDelay = 1; + avgDelay = (double)totalDelay / cntDelay; - int64_t end = taosGetTimestampMs(); - int64_t t = end - start; + int64_t end = taosGetTimestampMs(); + int64_t t = end - start; - if (superTblInfo) { - fprintf(stderr, "Spent %.2f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s.%s. %.2f records/second\n\n", - t / 1000.0, superTblInfo->totalInsertRows, - superTblInfo->totalAffectedRows, - threads, db_name, superTblInfo->sTblName, - (double)superTblInfo->totalInsertRows / (t / 1000.0)); + double tInMs = t/1000.0; - if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, - "Spent %.2f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s.%s. %.2f records/second\n\n", - t / 1000.0, superTblInfo->totalInsertRows, - superTblInfo->totalAffectedRows, - threads, db_name, superTblInfo->sTblName, - (double)superTblInfo->totalInsertRows / (t / 1000.0)); + if (superTblInfo) { + fprintf(stderr, "Spent %.2f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s.%s. %.2f records/second\n\n", + tInMs, superTblInfo->totalInsertRows, + superTblInfo->totalAffectedRows, + threads, db_name, superTblInfo->sTblName, + (tInMs)? + (double)(superTblInfo->totalInsertRows/tInMs):FLT_MAX); + + if (g_fpOfInsertResult) { + fprintf(g_fpOfInsertResult, + "Spent %.2f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s.%s. %.2f records/second\n\n", + tInMs, superTblInfo->totalInsertRows, + superTblInfo->totalAffectedRows, + threads, db_name, superTblInfo->sTblName, + (tInMs)? + (double)(superTblInfo->totalInsertRows/tInMs):FLT_MAX); + } + } else { + fprintf(stderr, "Spent %.2f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s %.2f records/second\n\n", + tInMs, g_args.totalInsertRows, + g_args.totalAffectedRows, + threads, db_name, + (tInMs)? + (double)(g_args.totalInsertRows/tInMs):FLT_MAX); + if (g_fpOfInsertResult) { + fprintf(g_fpOfInsertResult, + "Spent %.2f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s %.2f records/second\n\n", + tInMs, g_args.totalInsertRows, + g_args.totalAffectedRows, + threads, db_name, + (tInMs)? + (double)(g_args.totalInsertRows/tInMs):FLT_MAX); + } } - } else { - fprintf(stderr, "Spent %.2f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s %.2f records/second\n\n", - t / 1000.0, g_args.totalInsertRows, - g_args.totalAffectedRows, - threads, db_name, - (double)g_args.totalInsertRows / (t / 1000.0)); + + fprintf(stderr, "insert delay, avg: %10.2fms, max: %"PRIu64"ms, min: %"PRIu64"ms\n\n", + avgDelay, maxDelay, minDelay); if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, - "Spent %.2f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s %.2f records/second\n\n", - t * 1000.0, g_args.totalInsertRows, - g_args.totalAffectedRows, - threads, db_name, - (double)g_args.totalInsertRows / (t / 1000.0)); + fprintf(g_fpOfInsertResult, "insert delay, avg:%10.2fms, max: %"PRIu64"ms, min: %"PRIu64"ms\n\n", + avgDelay, maxDelay, minDelay); } - } - fprintf(stderr, "insert delay, avg: %10.2fms, max: %"PRIu64"ms, min: %"PRIu64"ms\n\n", - avgDelay, maxDelay, minDelay); - if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, "insert delay, avg:%10.2fms, max: %"PRIu64"ms, min: %"PRIu64"ms\n\n", - avgDelay, maxDelay, minDelay); - } - - //taos_close(taos); + //taos_close(taos); - free(pids); - free(infos); + free(pids); + free(infos); } static void *readTable(void *sarg) { @@ -6957,98 +7060,98 @@ static void prompt() static int insertTestProcess() { - setupForAnsiEscape(); - int ret = printfInsertMeta(); - resetAfterAnsiEscape(); + setupForAnsiEscape(); + int ret = printfInsertMeta(); + resetAfterAnsiEscape(); - if (ret == -1) - exit(EXIT_FAILURE); + if (ret == -1) + exit(EXIT_FAILURE); - debugPrint("%d result file: %s\n", __LINE__, g_Dbs.resultFile); - g_fpOfInsertResult = fopen(g_Dbs.resultFile, "a"); - if (NULL == g_fpOfInsertResult) { - errorPrint( "Failed to open %s for save result\n", g_Dbs.resultFile); - return -1; - } + debugPrint("%d result file: %s\n", __LINE__, g_Dbs.resultFile); + g_fpOfInsertResult = fopen(g_Dbs.resultFile, "a"); + if (NULL == g_fpOfInsertResult) { + errorPrint( "Failed to open %s for save result\n", g_Dbs.resultFile); + return -1; + } - if (g_fpOfInsertResult) - printfInsertMetaToFile(g_fpOfInsertResult); + if (g_fpOfInsertResult) + printfInsertMetaToFile(g_fpOfInsertResult); - prompt(); + prompt(); - init_rand_data(); + init_rand_data(); - // create database and super tables - if(createDatabasesAndStables() != 0) { - if (g_fpOfInsertResult) - fclose(g_fpOfInsertResult); - return -1; - } + // create database and super tables + if(createDatabasesAndStables() != 0) { + if (g_fpOfInsertResult) + fclose(g_fpOfInsertResult); + return -1; + } - // pretreatement - if (prepareSampleData() != 0) { - if (g_fpOfInsertResult) - fclose(g_fpOfInsertResult); - return -1; - } + // pretreatement + if (prepareSampleData() != 0) { + if (g_fpOfInsertResult) + fclose(g_fpOfInsertResult); + return -1; + } - double start; - double end; + double start; + double end; - // create child tables - start = taosGetTimestampMs(); - createChildTables(); - end = taosGetTimestampMs(); + // create child tables + start = taosGetTimestampMs(); + createChildTables(); + end = taosGetTimestampMs(); - if (g_totalChildTables > 0) { - fprintf(stderr, "Spent %.4f seconds to create %"PRId64" tables with %d thread(s)\n\n", - (end - start)/1000.0, g_totalChildTables, g_Dbs.threadCountByCreateTbl); - if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, - "Spent %.4f seconds to create %"PRId64" tables with %d thread(s)\n\n", - (end - start)/1000.0, g_totalChildTables, g_Dbs.threadCountByCreateTbl); + if (g_totalChildTables > 0) { + fprintf(stderr, "Spent %.4f seconds to create %"PRId64" tables with %d thread(s)\n\n", + (end - start)/1000.0, g_totalChildTables, g_Dbs.threadCountByCreateTbl); + if (g_fpOfInsertResult) { + fprintf(g_fpOfInsertResult, + "Spent %.4f seconds to create %"PRId64" tables with %d thread(s)\n\n", + (end - start)/1000.0, g_totalChildTables, g_Dbs.threadCountByCreateTbl); + } } - } - // create sub threads for inserting data - //start = taosGetTimestampMs(); - for (int i = 0; i < g_Dbs.dbCount; i++) { - if (g_Dbs.use_metric) { - if (g_Dbs.db[i].superTblCount > 0) { - for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { + // create sub threads for inserting data + //start = taosGetTimestampMs(); + for (int i = 0; i < g_Dbs.dbCount; i++) { + if (g_Dbs.use_metric) { + if (g_Dbs.db[i].superTblCount > 0) { + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { - SSuperTable* superTblInfo = &g_Dbs.db[i].superTbls[j]; + SSuperTable* superTblInfo = &g_Dbs.db[i].superTbls[j]; - if (superTblInfo && (superTblInfo->insertRows > 0)) { + if (superTblInfo && (superTblInfo->insertRows > 0)) { + startMultiThreadInsertData( + g_Dbs.threadCount, + g_Dbs.db[i].dbName, + g_Dbs.db[i].dbCfg.precision, + superTblInfo); + } + } + } + } else { startMultiThreadInsertData( - g_Dbs.threadCount, - g_Dbs.db[i].dbName, - g_Dbs.db[i].dbCfg.precision, - superTblInfo); - } + g_Dbs.threadCount, + g_Dbs.db[i].dbName, + g_Dbs.db[i].dbCfg.precision, + NULL); } - } - } else { - startMultiThreadInsertData( - g_Dbs.threadCount, - g_Dbs.db[i].dbName, - g_Dbs.db[i].dbCfg.precision, - NULL); } - } - //end = taosGetTimestampMs(); - - //int64_t totalInsertRows = 0; - //int64_t totalAffectedRows = 0; - //for (int i = 0; i < g_Dbs.dbCount; i++) { - // for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { - // totalInsertRows+= g_Dbs.db[i].superTbls[j].totalInsertRows; - // totalAffectedRows += g_Dbs.db[i].superTbls[j].totalAffectedRows; - //} - //printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s)\n\n", end - start, totalInsertRows, totalAffectedRows, g_Dbs.threadCount); - postFreeResource(); + //end = taosGetTimestampMs(); - return 0; + //int64_t totalInsertRows = 0; + //int64_t totalAffectedRows = 0; + //for (int i = 0; i < g_Dbs.dbCount; i++) { + // for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + // totalInsertRows+= g_Dbs.db[i].superTbls[j].totalInsertRows; + // totalAffectedRows += g_Dbs.db[i].superTbls[j].totalAffectedRows; + //} + //printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s)\n\n", end - start, totalInsertRows, totalAffectedRows, g_Dbs.threadCount); + postFreeResource(); + + return 0; } static void *specifiedTableQuery(void *sarg) { @@ -7884,116 +7987,116 @@ static void initOfQueryMeta() { } static void setParaFromArg(){ - if (g_args.host) { - tstrncpy(g_Dbs.host, g_args.host, MAX_HOSTNAME_SIZE); - } else { - tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE); - } - - if (g_args.user) { - tstrncpy(g_Dbs.user, g_args.user, MAX_USERNAME_SIZE); - } + if (g_args.host) { + tstrncpy(g_Dbs.host, g_args.host, MAX_HOSTNAME_SIZE); + } else { + tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE); + } - if (g_args.password) { - tstrncpy(g_Dbs.password, g_args.password, MAX_PASSWORD_SIZE); - } + if (g_args.user) { + tstrncpy(g_Dbs.user, g_args.user, MAX_USERNAME_SIZE); + } - if (g_args.port) { - g_Dbs.port = g_args.port; - } + if (g_args.password) { + tstrncpy(g_Dbs.password, g_args.password, MAX_PASSWORD_SIZE); + } - g_Dbs.threadCount = g_args.num_of_threads; - g_Dbs.threadCountByCreateTbl = g_args.num_of_threads; + if (g_args.port) { + g_Dbs.port = g_args.port; + } - g_Dbs.dbCount = 1; - g_Dbs.db[0].drop = true; + g_Dbs.threadCount = g_args.num_of_threads; + g_Dbs.threadCountByCreateTbl = g_args.num_of_threads; - tstrncpy(g_Dbs.db[0].dbName, g_args.database, TSDB_DB_NAME_LEN); - g_Dbs.db[0].dbCfg.replica = g_args.replica; - tstrncpy(g_Dbs.db[0].dbCfg.precision, "ms", 8); + g_Dbs.dbCount = 1; + g_Dbs.db[0].drop = true; - tstrncpy(g_Dbs.resultFile, g_args.output_file, MAX_FILE_NAME_LEN); + tstrncpy(g_Dbs.db[0].dbName, g_args.database, TSDB_DB_NAME_LEN); + g_Dbs.db[0].dbCfg.replica = g_args.replica; + tstrncpy(g_Dbs.db[0].dbCfg.precision, "ms", 8); - g_Dbs.use_metric = g_args.use_metric; - g_Dbs.insert_only = g_args.insert_only; + tstrncpy(g_Dbs.resultFile, g_args.output_file, MAX_FILE_NAME_LEN); - g_Dbs.do_aggreFunc = true; + g_Dbs.use_metric = g_args.use_metric; + g_Dbs.insert_only = g_args.insert_only; - char dataString[STRING_LEN]; - char **data_type = g_args.datatype; + g_Dbs.do_aggreFunc = true; - memset(dataString, 0, STRING_LEN); + char dataString[STRING_LEN]; + char **data_type = g_args.datatype; - if (strcasecmp(data_type[0], "BINARY") == 0 - || strcasecmp(data_type[0], "BOOL") == 0 - || strcasecmp(data_type[0], "NCHAR") == 0 ) { - g_Dbs.do_aggreFunc = false; - } + memset(dataString, 0, STRING_LEN); - if (g_args.use_metric) { - g_Dbs.db[0].superTblCount = 1; - tstrncpy(g_Dbs.db[0].superTbls[0].sTblName, "meters", TSDB_TABLE_NAME_LEN); - g_Dbs.db[0].superTbls[0].childTblCount = g_args.num_of_tables; - g_Dbs.threadCount = g_args.num_of_threads; - g_Dbs.threadCountByCreateTbl = g_args.num_of_threads; - g_Dbs.asyncMode = g_args.async_mode; - - g_Dbs.db[0].superTbls[0].autoCreateTable = PRE_CREATE_SUBTBL; - g_Dbs.db[0].superTbls[0].childTblExists = TBL_NO_EXISTS; - g_Dbs.db[0].superTbls[0].disorderRange = g_args.disorderRange; - g_Dbs.db[0].superTbls[0].disorderRatio = g_args.disorderRatio; - tstrncpy(g_Dbs.db[0].superTbls[0].childTblPrefix, - g_args.tb_prefix, TSDB_TABLE_NAME_LEN - 20); - tstrncpy(g_Dbs.db[0].superTbls[0].dataSource, "rand", MAX_TB_NAME_SIZE); - - if (g_args.iface == INTERFACE_BUT) { - g_Dbs.db[0].superTbls[0].iface = TAOSC_IFACE; - } else { - g_Dbs.db[0].superTbls[0].iface = g_args.iface; + if (strcasecmp(data_type[0], "BINARY") == 0 + || strcasecmp(data_type[0], "BOOL") == 0 + || strcasecmp(data_type[0], "NCHAR") == 0 ) { + g_Dbs.do_aggreFunc = false; } - tstrncpy(g_Dbs.db[0].superTbls[0].startTimestamp, - "2017-07-14 10:40:00.000", MAX_TB_NAME_SIZE); - g_Dbs.db[0].superTbls[0].timeStampStep = DEFAULT_TIMESTAMP_STEP; - g_Dbs.db[0].superTbls[0].insertRows = g_args.num_of_DPT; - g_Dbs.db[0].superTbls[0].maxSqlLen = g_args.max_sql_len; + if (g_args.use_metric) { + g_Dbs.db[0].superTblCount = 1; + tstrncpy(g_Dbs.db[0].superTbls[0].sTblName, "meters", TSDB_TABLE_NAME_LEN); + g_Dbs.db[0].superTbls[0].childTblCount = g_args.num_of_tables; + g_Dbs.threadCount = g_args.num_of_threads; + g_Dbs.threadCountByCreateTbl = g_args.num_of_threads; + g_Dbs.asyncMode = g_args.async_mode; - g_Dbs.db[0].superTbls[0].columnCount = 0; - for (int i = 0; i < MAX_NUM_COLUMNS; i++) { - if (data_type[i] == NULL) { - break; - } + g_Dbs.db[0].superTbls[0].autoCreateTable = PRE_CREATE_SUBTBL; + g_Dbs.db[0].superTbls[0].childTblExists = TBL_NO_EXISTS; + g_Dbs.db[0].superTbls[0].disorderRange = g_args.disorderRange; + g_Dbs.db[0].superTbls[0].disorderRatio = g_args.disorderRatio; + tstrncpy(g_Dbs.db[0].superTbls[0].childTblPrefix, + g_args.tb_prefix, TSDB_TABLE_NAME_LEN - 20); + tstrncpy(g_Dbs.db[0].superTbls[0].dataSource, "rand", MAX_TB_NAME_SIZE); - tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, - data_type[i], strlen(data_type[i]) + 1); - g_Dbs.db[0].superTbls[0].columns[i].dataLen = g_args.len_of_binary; - g_Dbs.db[0].superTbls[0].columnCount++; - } + if (g_args.iface == INTERFACE_BUT) { + g_Dbs.db[0].superTbls[0].iface = TAOSC_IFACE; + } else { + g_Dbs.db[0].superTbls[0].iface = g_args.iface; + } + tstrncpy(g_Dbs.db[0].superTbls[0].startTimestamp, + "2017-07-14 10:40:00.000", MAX_TB_NAME_SIZE); + g_Dbs.db[0].superTbls[0].timeStampStep = DEFAULT_TIMESTAMP_STEP; - if (g_Dbs.db[0].superTbls[0].columnCount > g_args.num_of_CPR) { - g_Dbs.db[0].superTbls[0].columnCount = g_args.num_of_CPR; - } else { - for (int i = g_Dbs.db[0].superTbls[0].columnCount; - i < g_args.num_of_CPR; i++) { - tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, - "INT", strlen("INT") + 1); - g_Dbs.db[0].superTbls[0].columns[i].dataLen = 0; - g_Dbs.db[0].superTbls[0].columnCount++; - } - } + g_Dbs.db[0].superTbls[0].insertRows = g_args.num_of_DPT; + g_Dbs.db[0].superTbls[0].maxSqlLen = g_args.max_sql_len; - tstrncpy(g_Dbs.db[0].superTbls[0].tags[0].dataType, - "INT", strlen("INT") + 1); - g_Dbs.db[0].superTbls[0].tags[0].dataLen = 0; + g_Dbs.db[0].superTbls[0].columnCount = 0; + for (int i = 0; i < MAX_NUM_COLUMNS; i++) { + if (data_type[i] == NULL) { + break; + } - tstrncpy(g_Dbs.db[0].superTbls[0].tags[1].dataType, - "BINARY", strlen("BINARY") + 1); - g_Dbs.db[0].superTbls[0].tags[1].dataLen = g_args.len_of_binary; - g_Dbs.db[0].superTbls[0].tagCount = 2; - } else { - g_Dbs.threadCountByCreateTbl = g_args.num_of_threads; - g_Dbs.db[0].superTbls[0].tagCount = 0; - } + tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, + data_type[i], strlen(data_type[i]) + 1); + g_Dbs.db[0].superTbls[0].columns[i].dataLen = g_args.len_of_binary; + g_Dbs.db[0].superTbls[0].columnCount++; + } + + if (g_Dbs.db[0].superTbls[0].columnCount > g_args.num_of_CPR) { + g_Dbs.db[0].superTbls[0].columnCount = g_args.num_of_CPR; + } else { + for (int i = g_Dbs.db[0].superTbls[0].columnCount; + i < g_args.num_of_CPR; i++) { + tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, + "INT", strlen("INT") + 1); + g_Dbs.db[0].superTbls[0].columns[i].dataLen = 0; + g_Dbs.db[0].superTbls[0].columnCount++; + } + } + + tstrncpy(g_Dbs.db[0].superTbls[0].tags[0].dataType, + "INT", strlen("INT") + 1); + g_Dbs.db[0].superTbls[0].tags[0].dataLen = 0; + + tstrncpy(g_Dbs.db[0].superTbls[0].tags[1].dataType, + "BINARY", strlen("BINARY") + 1); + g_Dbs.db[0].superTbls[0].tags[1].dataLen = g_args.len_of_binary; + g_Dbs.db[0].superTbls[0].tagCount = 2; + } else { + g_Dbs.threadCountByCreateTbl = g_args.num_of_threads; + g_Dbs.db[0].superTbls[0].tagCount = 0; + } } /* Function to do regular expression check */ diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index e8cf7e30ac03bcfcafe5eaf9785bf0df60bf80c4..e974251d2ef024cb5977378d31c26c31fa718dcd 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -214,6 +214,23 @@ typedef struct SUserObj { struct SAcctObj * pAcct; } SUserObj; +typedef struct SFuncObj { + char name[TSDB_FUNC_NAME_LEN]; + char path[128]; + int32_t contLen; + char cont[TSDB_FUNC_CODE_LEN]; + int32_t funcType; + int32_t bufSize; + int64_t createdTime; + uint8_t resType; + int16_t resBytes; + int64_t sig; // partial md5 sign + int16_t type; // [lua script|so|js] + int8_t reserved[64]; + int8_t updateEnd[4]; + int32_t refCount; +} SFuncObj; + typedef struct { int64_t totalStorage; // Total storage wrtten from this account int64_t compStorage; // Compressed storage on disk @@ -258,7 +275,7 @@ typedef struct { void * pIter; void ** ppShow; int16_t offset[TSDB_MAX_COLUMNS]; - int16_t bytes[TSDB_MAX_COLUMNS]; + int32_t bytes[TSDB_MAX_COLUMNS]; int32_t numOfReads; int8_t maxReplica; int8_t reserved0[1]; diff --git a/src/mnode/inc/mnodeFunc.h b/src/mnode/inc/mnodeFunc.h new file mode 100644 index 0000000000000000000000000000000000000000..e33f3fb5671faeea39154a8ed98cb8923d54a501 --- /dev/null +++ b/src/mnode/inc/mnodeFunc.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_MNODE_FUNC_H +#define TDENGINE_MNODE_FUNC_H + +#ifdef __cplusplus +extern "C" { +#endif +#include "mnodeDef.h" + +int32_t mnodeInitFuncs(); +void mnodeCleanupFuncs(); + +SFuncObj *mnodeGetFunc(char *name); +void * mnodeGetNextFunc(void *pIter, SFuncObj **pFunc); +void mnodeCancelGetNextFunc(void *pIter); + +void mnodeIncFuncRef(SFuncObj *pFunc); +void mnodeDecFuncRef(SFuncObj *pFunc); + +int32_t mnodeCreateFunc(SAcctObj *pAcct, char *name, int32_t codeLen, char *code, char *path, uint8_t outputType, int16_t outputLen, int32_t funcType, int32_t bufSize, SMnodeMsg *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index 2ae0c47902677944e000bfdb564bc1d65f9daf99..25b841ef34d35c0691ead226f6be46e12e298125 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -33,7 +33,8 @@ typedef enum { SDB_TABLE_VGROUP = 6, SDB_TABLE_STABLE = 7, SDB_TABLE_CTABLE = 8, - SDB_TABLE_MAX = 9 + SDB_TABLE_FUNC = 9, + SDB_TABLE_MAX = 10 } ESdbTable; typedef enum { @@ -112,4 +113,4 @@ int32_t mnodeCompactWal(); } #endif -#endif \ No newline at end of file +#endif diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index f4fc88476f8c2ddeb32acc4f37d27f17c76af788..9602e16483f3a367117f998cc619dbe408859d93 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -554,6 +554,9 @@ void mnodeCleanupDbs() { tsDbSdb = NULL; } + + + static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { int32_t cols = 0; diff --git a/src/mnode/src/mnodeFunc.c b/src/mnode/src/mnodeFunc.c new file mode 100644 index 0000000000000000000000000000000000000000..253958efbe9a0d81d0542217447eaf750e10caf9 --- /dev/null +++ b/src/mnode/src/mnodeFunc.c @@ -0,0 +1,485 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "os.h" +#include "trpc.h" +#include "tutil.h" +#include "tglobal.h" +#include "tgrant.h" +#include "tdataformat.h" +#include "tkey.h" +#include "mnode.h" +#include "dnode.h" +#include "mnodeDef.h" +#include "mnodeInt.h" +#include "mnodeAcct.h" +#include "mnodeUser.h" +#include "mnodeMnode.h" +#include "mnodeSdb.h" +#include "mnodeShow.h" +#include "mnodeFunc.h" +#include "mnodeWrite.h" +#include "mnodeRead.h" +#include "mnodePeer.h" + +int64_t tsFuncRid = -1; +static void * tsFuncSdb = NULL; +static int32_t tsFuncUpdateSize = 0; +static int32_t mnodeGetFuncMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mnodeRetrieveFuncs(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static int32_t mnodeProcessRetrieveFuncImplMsg(SMnodeMsg *pMsg); +static int32_t mnodeProcessCreateFuncMsg(SMnodeMsg *pMsg); +static int32_t mnodeProcessDropFuncMsg(SMnodeMsg *pMsg); + +static int32_t mnodeFuncActionDestroy(SSdbRow *pRow) { + tfree(pRow->pObj); + return TSDB_CODE_SUCCESS; +} + +static int32_t mnodeFuncActionInsert(SSdbRow *pRow) { + SFuncObj *pFunc = pRow->pObj; + + mTrace("func:%s, contLen: %d, insert into sdb", pFunc->name, pFunc->contLen); + + return TSDB_CODE_SUCCESS; +} + +static int32_t mnodeFuncActionDelete(SSdbRow *pRow) { + SFuncObj *pFunc = pRow->pObj; + + mTrace("func:%s, length: %d, delete from sdb", pFunc->name, pFunc->contLen); + + return TSDB_CODE_SUCCESS; +} + +static int32_t mnodeFuncActionUpdate(SSdbRow *pRow) { + SFuncObj *pFunc = pRow->pObj; + + SFuncObj *pSaved = mnodeGetFunc(pFunc->name); + if (pFunc != pSaved) { + memcpy(pSaved, pFunc, tsFuncUpdateSize); + free(pFunc); + } + + mnodeDecFuncRef(pSaved); + return TSDB_CODE_SUCCESS; +} + +static int32_t mnodeFuncActionEncode(SSdbRow *pRow) { + SFuncObj *pFunc = pRow->pObj; + + memcpy(pRow->rowData, pFunc, tsFuncUpdateSize); + pRow->rowSize = tsFuncUpdateSize; + + return TSDB_CODE_SUCCESS; +} + +static int32_t mnodeFuncActionDecode(SSdbRow *pRow) { + SFuncObj *pFunc = (SFuncObj *)calloc(1, sizeof(SFuncObj)); + if (pFunc == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; + + memcpy(pFunc, pRow->rowData, tsFuncUpdateSize); + pRow->pObj = pFunc; + + return TSDB_CODE_SUCCESS; +} + +static int32_t mnodeFuncActionRestored() { + int64_t numOfRows = sdbGetNumOfRows(tsFuncSdb); + + if (numOfRows <= 0 && dnodeIsFirstDeploy()) { + mInfo("dnode first deploy, func restored."); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t mnodeInitFuncs() { + SFuncObj tObj; + tsFuncUpdateSize = (int32_t)((int8_t *)tObj.updateEnd - (int8_t *)&tObj); + + SSdbTableDesc desc = { + .id = SDB_TABLE_FUNC, + .name = "funcs", + .hashSessions = TSDB_DEFAULT_USERS_HASH_SIZE, + .maxRowSize = tsFuncUpdateSize, + .refCountPos = (int32_t)((int8_t *)(&tObj.refCount) - (int8_t *)&tObj), + .keyType = SDB_KEY_STRING, + .fpInsert = mnodeFuncActionInsert, + .fpDelete = mnodeFuncActionDelete, + .fpUpdate = mnodeFuncActionUpdate, + .fpEncode = mnodeFuncActionEncode, + .fpDecode = mnodeFuncActionDecode, + .fpDestroy = mnodeFuncActionDestroy, + .fpRestored = mnodeFuncActionRestored + }; + + tsFuncRid = sdbOpenTable(&desc); + tsFuncSdb = sdbGetTableByRid(tsFuncRid); + if (tsFuncSdb == NULL) { + mError("table:%s, failed to create hash", desc.name); + return -1; + } + + mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CREATE_FUNCTION, mnodeProcessCreateFuncMsg); + mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_FUNCTION, mnodeProcessDropFuncMsg); + mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_RETRIEVE_FUNC, mnodeProcessRetrieveFuncImplMsg); + + mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_FUNCTION, mnodeGetFuncMeta); + mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_FUNCTION, mnodeRetrieveFuncs); + mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_FUNCTION, mnodeCancelGetNextFunc); + + mDebug("table:%s, hash is created", desc.name); + + return 0; +} + +void mnodeCleanupFuncs() { + sdbCloseTable(tsFuncRid); + tsFuncSdb = NULL; +} + +SFuncObj *mnodeGetFunc(char *name) { + return (SFuncObj *)sdbGetRow(tsFuncSdb, name); +} + +void *mnodeGetNextFunc(void *pIter, SFuncObj **pFunc) { + return sdbFetchRow(tsFuncSdb, pIter, (void **)pFunc); +} + +void mnodeCancelGetNextFunc(void *pIter) { + sdbFreeIter(tsFuncSdb, pIter); +} + +void mnodeIncFuncRef(SFuncObj *pFunc) { + sdbIncRef(tsFuncSdb, pFunc); +} + +void mnodeDecFuncRef(SFuncObj *pFunc) { + sdbDecRef(tsFuncSdb, pFunc); +} +/* +static int32_t mnodeUpdateFunc(SFuncObj *pFunc, void *pMsg) { + SSdbRow row = { + .type = SDB_OPER_GLOBAL, + .pTable = tsFuncSdb, + .pObj = pFunc, + .pMsg = pMsg + }; + + int32_t code = sdbUpdateRow(&row); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + mError("func:%s, failed to alter by %s, reason:%s", pFunc->name, mnodeGetUserFromMsg(pMsg), tstrerror(code)); + } else { + mLInfo("func:%s, is altered by %s", pFunc->name, mnodeGetUserFromMsg(pMsg)); + } + + return code; +} +*/ +int32_t mnodeCreateFunc(SAcctObj *pAcct, char *name, int32_t codeLen, char *codeScript, char *path, uint8_t outputType, int16_t outputLen, int32_t funcType, int32_t bufSize, SMnodeMsg *pMsg) { + if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_GRANT_EXPIRED; + } + + if (!pMsg->pUser->writeAuth) { + return TSDB_CODE_MND_NO_RIGHTS; + } + + int32_t code = acctCheck(pAcct, ACCT_GRANT_USER); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + code = grantCheck(TSDB_GRANT_USER); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + if (name[0] == 0) { + return TSDB_CODE_MND_INVALID_FUNC_NAME; + } + + if (codeScript[0] == 0) { + return TSDB_CODE_MND_INVALID_FUNC_CODE; + } + + if (codeLen < 0 || codeLen > TSDB_FUNC_CODE_LEN) { + return TSDB_CODE_MND_INVALID_FUNC_CODE; + } + + if (bufSize < 0 || bufSize > TSDB_FUNC_BUF_SIZE) { + return TSDB_CODE_MND_INVALID_FUNC_BUFSIZE; + } + + SFuncObj *pFunc = mnodeGetFunc(name); + if (pFunc != NULL) { + mDebug("func:%s, is already there", name); + mnodeDecFuncRef(pFunc); + return TSDB_CODE_MND_FUNC_ALREADY_EXIST; + } + + pFunc = calloc(1, sizeof(SFuncObj)); + tstrncpy(pFunc->name, name, TSDB_FUNC_NAME_LEN); + tstrncpy(pFunc->path, path, tListLen(pFunc->path)); + memcpy(pFunc->cont, codeScript, codeLen); + pFunc->contLen = codeLen; + pFunc->createdTime = taosGetTimestampMs(); + pFunc->resType = outputType; + pFunc->resBytes = outputLen; + pFunc->funcType = funcType; + pFunc->bufSize = bufSize; + pFunc->sig = 0; + pFunc->type = 1; //lua script, refactor + + SSdbRow row = { + .type = SDB_OPER_GLOBAL, + .pTable = tsFuncSdb, + .pObj = pFunc, + .rowSize = sizeof(SFuncObj), + .pMsg = pMsg + }; + + code = sdbInsertRow(&row); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + mError("func:%s, failed to create by %s, reason:%s", pFunc->name, mnodeGetUserFromMsg(pMsg), tstrerror(code)); + tfree(pFunc); + } else { + mLInfo("func:%s, is created by %s", pFunc->name, mnodeGetUserFromMsg(pMsg)); + } + + return code; +} + +static int32_t mnodeDropFunc(SFuncObj *pFunc, void *pMsg) { + SSdbRow row = { + .type = SDB_OPER_GLOBAL, + .pTable = tsFuncSdb, + .pObj = pFunc, + .pMsg = pMsg + }; + + int32_t code = sdbDeleteRow(&row); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + mError("func:%s, failed to drop by %s, reason:%s", pFunc->name, mnodeGetUserFromMsg(pMsg), tstrerror(code)); + } else { + mLInfo("func:%s, is dropped by %s", pFunc->name, mnodeGetUserFromMsg(pMsg)); + } + + return code; +} + +static int32_t mnodeGetFuncsNum() { + return (int32_t)sdbGetNumOfRows(tsFuncSdb); +} + +static int32_t mnodeGetFuncMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { + SUserObj *pUser = mnodeGetUserFromConn(pConn); + if (pUser == NULL) { + return TSDB_CODE_MND_NO_USER_FROM_CONN; + } + + int32_t cols = 0; + SSchema *pSchema = pMeta->schema; + + pShow->bytes[cols] = TSDB_FUNC_NAME_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "name"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = PATH_MAX + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "path"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "aggregate"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_TYPE_STR_MAX_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "outputtype"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "code_len"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "bufsize"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htons(cols); + strcpy(pMeta->tableFname, "show funcs"); + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } + + pShow->numOfRows = mnodeGetFuncsNum(); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + + mnodeDecUserRef(pUser); + + return 0; +} + +static void* mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t len) { + char *msg = "unknown"; + if (type >= sizeof(tDataTypes)/sizeof(tDataTypes[0])) { + return msg; + } + + if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) { + int32_t bytes = len > 0 ? (int)(len - VARSTR_HEADER_SIZE) : len; + + snprintf(buf, buflen - 1, "%s(%d)", tDataTypes[type].name, type == TSDB_DATA_TYPE_NCHAR ? bytes/4 : bytes); + buf[buflen - 1] = 0; + + return buf; + } + + return tDataTypes[type].name; +} + +static int32_t mnodeRetrieveFuncs(SShowObj *pShow, char *data, int32_t rows, void *pConn) { + int32_t numOfRows = 0; + SFuncObj *pFunc = NULL; + int32_t cols = 0; + char *pWrite; + char buf[TSDB_TYPE_STR_MAX_LEN]; + + while (numOfRows < rows) { + pShow->pIter = mnodeGetNextFunc(pShow->pIter, &pFunc); + if (pFunc == NULL) break; + + cols = 0; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pFunc->name, pShow->bytes[cols]); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pFunc->path, pShow->bytes[cols]); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = pFunc->funcType == TSDB_UDF_TYPE_AGGREGATE ? 1 : 0; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->resType, pFunc->resBytes), pShow->bytes[cols]); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pFunc->createdTime; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = pFunc->contLen; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = pFunc->bufSize; + cols++; + + numOfRows++; + mnodeDecFuncRef(pFunc); + } + + mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + pShow->numOfReads += numOfRows; + return numOfRows; +} + +static int32_t mnodeProcessCreateFuncMsg(SMnodeMsg *pMsg) { + SCreateFuncMsg *pCreate = pMsg->rpcMsg.pCont; + pCreate->codeLen = htonl(pCreate->codeLen); + pCreate->outputLen = htons(pCreate->outputLen); + pCreate->funcType = htonl(pCreate->funcType); + pCreate->bufSize = htonl(pCreate->bufSize); + + return mnodeCreateFunc(pMsg->pUser->pAcct, pCreate->name, pCreate->codeLen, pCreate->code, pCreate->path, pCreate->outputType, pCreate->outputLen, pCreate->funcType, pCreate->bufSize, pMsg); +} + +static int32_t mnodeProcessDropFuncMsg(SMnodeMsg *pMsg) { + SDropFuncMsg *pDrop = pMsg->rpcMsg.pCont; + + SFuncObj *pFunc = mnodeGetFunc(pDrop->name); + if (pFunc == NULL) { + return TSDB_CODE_MND_INVALID_FUNC; + } + + return mnodeDropFunc(pFunc, pMsg); +} + +static int32_t mnodeProcessRetrieveFuncImplMsg(SMnodeMsg *pMsg) { + SRetrieveFuncMsg *pInfo = pMsg->rpcMsg.pCont; + pInfo->num = htonl(pInfo->num); + + int32_t t = sizeof(SUdfFuncMsg) + (sizeof(SFunctionInfoMsg) + TSDB_FUNC_CODE_LEN) * pInfo->num + 16384; + + SUdfFuncMsg *pFuncMsg = rpcMallocCont(t); + pFuncMsg->num = htonl(pInfo->num); + char* pOutput = pFuncMsg->content; + tstr* name = (tstr*) pInfo->name; + + for(int32_t i = 0; i < pInfo->num; ++i) { + char buf[TSDB_FUNC_NAME_LEN] = {0}; + tstrncpy(buf, name->data, htons(name->len) + 1); + + SFuncObj* pFuncObj = mnodeGetFunc(buf); + if (pFuncObj == NULL) { + mError("function %s does not exist", buf); + return TSDB_CODE_MND_INVALID_FUNC; + } + + SFunctionInfoMsg* pFuncInfo = (SFunctionInfoMsg*) pOutput; + + strcpy(pFuncInfo->name, buf); + pFuncInfo->len = htonl(pFuncObj->contLen); + memcpy(pFuncInfo->content, pFuncObj->cont, pFuncObj->contLen); + + pFuncInfo->funcType = htonl(pFuncObj->funcType); + pFuncInfo->resType = pFuncObj->resType; + pFuncInfo->resBytes = htons(pFuncObj->resBytes); + pFuncInfo->bufSize = htonl(pFuncObj->bufSize); + + pOutput += sizeof(SFunctionInfoMsg) + pFuncObj->contLen; + name =(tstr *)((char *)name + sizeof(*name) + htons(name->len)); + } + + pMsg->rpcRsp.rsp = pFuncMsg; + pMsg->rpcRsp.len = (int32_t)(pOutput - (char*)pFuncMsg); + return TSDB_CODE_SUCCESS; +} diff --git a/src/mnode/src/mnodeMain.c b/src/mnode/src/mnodeMain.c index 8ce798c8ec2271ecb236d49278f07f974e4bb043..df3c49165ca00262016006e4450eb1ba574a5525 100644 --- a/src/mnode/src/mnodeMain.c +++ b/src/mnode/src/mnodeMain.c @@ -32,6 +32,7 @@ #include "mnodeSdb.h" #include "mnodeVgroup.h" #include "mnodeUser.h" +#include "mnodeFunc.h" #include "mnodeTable.h" #include "mnodeCluster.h" #include "mnodeShow.h" @@ -46,6 +47,7 @@ static SStep tsMnodeSteps[] = { {"cluster", mnodeInitCluster, mnodeCleanupCluster}, {"accts", mnodeInitAccts, mnodeCleanupAccts}, {"users", mnodeInitUsers, mnodeCleanupUsers}, + {"funcs", mnodeInitFuncs, mnodeCleanupFuncs}, {"dnodes", mnodeInitDnodes, mnodeCleanupDnodes}, {"dbs", mnodeInitDbs, mnodeCleanupDbs}, {"vgroups", mnodeInitVgroups, mnodeCleanupVgroups}, diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 6dc2f8ad2851bbc9fdf6ff8a24b8cf4de502d603..3631b1e005a60168a3a2531254a5bd425b89b797 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -42,6 +42,7 @@ #include "mnodeWrite.h" #include "mnodeRead.h" #include "mnodePeer.h" +#include "mnodeFunc.h" #define ALTER_CTABLE_RETRY_TIMES 3 #define CREATE_CTABLE_RETRY_TIMES 10 @@ -104,6 +105,20 @@ static void mnodeDestroyChildTable(SCTableObj *pTable) { tfree(pTable); } +static char* mnodeGetTableShowPattern(SShowObj *pShow) { + char* pattern = NULL; + if (pShow != NULL && pShow->payloadLen > 0) { + pattern = (char*)malloc(pShow->payloadLen + 1); + if (pattern == NULL) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + return NULL; + } + memcpy(pattern, pShow->payload, pShow->payloadLen); + pattern[pShow->payloadLen] = 0; + } + return pattern; +} + static int32_t mnodeChildTableActionDestroy(SSdbRow *pRow) { mnodeDestroyChildTable(pRow->pObj); return TSDB_CODE_SUCCESS; @@ -1620,6 +1635,11 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER; char stableName[TSDB_TABLE_NAME_LEN] = {0}; + char* pattern = mnodeGetTableShowPattern(pShow); + if (pShow->payloadLen > 0 && pattern == NULL) { + return 0; + } + while (numOfRows < rows) { pShow->pIter = mnodeGetNextSuperTable(pShow->pIter, &pTable); if (pTable == NULL) break; @@ -1631,7 +1651,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, memset(stableName, 0, tListLen(stableName)); mnodeExtractTableName(pTable->info.tableId, stableName); - if (pShow->payloadLen > 0 && patternMatch(pShow->payload, stableName, sizeof(stableName) - 1, &info) != TSDB_PATTERN_MATCH) { + if (pShow->payloadLen > 0 && patternMatch(pattern, stableName, sizeof(stableName) - 1, &info) != TSDB_PATTERN_MATCH) { mnodeDecTableRef(pTable); continue; } @@ -1671,6 +1691,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); mnodeDecDbRef(pDb); + free(pattern); return numOfRows; } @@ -2906,6 +2927,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { pInfo->numOfTables = htonl(pInfo->numOfTables); pInfo->numOfVgroups = htonl(pInfo->numOfVgroups); + pInfo->numOfUdfs = htonl(pInfo->numOfUdfs); int32_t contLen = pMsg->rpcMsg.contLen - sizeof(SMultiTableInfoMsg); @@ -2914,9 +2936,9 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { char* str = strndup(pInfo->tableNames, contLen); char** nameList = strsplit(str, ",", &num); SArray* pList = taosArrayInit(4, POINTER_BYTES); - SMultiTableMeta *pMultiMeta = NULL; - if (num != pInfo->numOfTables + pInfo->numOfVgroups) { + SMultiTableMeta *pMultiMeta = NULL; + if (num != pInfo->numOfTables + pInfo->numOfVgroups + pInfo->numOfUdfs) { mError("msg:%p, app:%p, failed to get multi-tableMeta, msg inconsistent", pMsg, pMsg->rpcMsg.ahandle); code = TSDB_CODE_MND_INVALID_TABLE_NAME; goto _end; @@ -2991,8 +3013,10 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { } } + int32_t tableNum = pInfo->numOfTables + pInfo->numOfVgroups; + // add the additional super table names that needs the vgroup info - for(;t < num; ++t) { + for(;t < tableNum; ++t) { taosArrayPush(pList, &nameList[t]); } @@ -3023,6 +3047,36 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { pMultiMeta->contLen = (int32_t) (msg - (char*) pMultiMeta); pMultiMeta->numOfTables = htonl(pMultiMeta->numOfTables); + + // add the user-defined-function information + for(int32_t i = 0; i < pInfo->numOfUdfs; ++i, ++t) { + char buf[TSDB_FUNC_NAME_LEN] = {0}; + strcpy(buf, nameList[t]); + + SFuncObj* pFuncObj = mnodeGetFunc(buf); + if (pFuncObj == NULL) { + mError("function %s does not exist", buf); + code = TSDB_CODE_MND_INVALID_FUNC; + goto _end; + } + + SFunctionInfoMsg* pFuncInfo = (SFunctionInfoMsg*) msg; + + strcpy(pFuncInfo->name, buf); + pFuncInfo->len = htonl(pFuncObj->contLen); + memcpy(pFuncInfo->content, pFuncObj->cont, pFuncObj->contLen); + + pFuncInfo->funcType = htonl(pFuncObj->funcType); + pFuncInfo->resType = pFuncObj->resType; + pFuncInfo->resBytes = htons(pFuncObj->resBytes); + pFuncInfo->bufSize = htonl(pFuncObj->bufSize); + + msg += sizeof(SFunctionInfoMsg) + pFuncObj->contLen; + } + + pMultiMeta->contLen = (int32_t) (msg - (char*) pMultiMeta); + pMultiMeta->numOfUdf = htonl(pInfo->numOfUdfs); + pMsg->rpcRsp.rsp = pMultiMeta; pMsg->rpcRsp.len = pMultiMeta->contLen; code = TSDB_CODE_SUCCESS; @@ -3033,11 +3087,13 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { goto _end; } - int32_t len = tsCompressString(pMultiMeta->meta, (int32_t)pMultiMeta->contLen - sizeof(SMultiTableMeta), 1, - tmp + sizeof(SMultiTableMeta), (int32_t)pMultiMeta->contLen - sizeof(SMultiTableMeta) + 2, ONE_STAGE_COMP, NULL, 0); + int32_t dataLen = (int32_t)pMultiMeta->contLen - sizeof(SMultiTableMeta); + int32_t len = tsCompressString(pMultiMeta->meta, dataLen, 1, tmp + sizeof(SMultiTableMeta), (int32_t)dataLen + 2, + ONE_STAGE_COMP, NULL, 0); + pMultiMeta->metaClone = pInfo->metaClone; pMultiMeta->rawLen = pMultiMeta->contLen; - if (len == -1 || len + sizeof(SMultiTableMeta) >= pMultiMeta->contLen + 2) { // compress failed, do not compress this binary data + if (len == -1 || len >= dataLen + 2) { // compress failed, do not compress this binary data pMultiMeta->compressed = 0; memcpy(tmp, pMultiMeta, sizeof(SMultiTableMeta) + pMultiMeta->contLen); } else { @@ -3157,15 +3213,9 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows char prefix[64] = {0}; int32_t prefixLen = (int32_t)tableIdPrefix(pDb->name, prefix, 64); - char* pattern = NULL; - if (pShow->payloadLen > 0) { - pattern = (char*)malloc(pShow->payloadLen + 1); - if (pattern == NULL) { - terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; - return 0; - } - memcpy(pattern, pShow->payload, pShow->payloadLen); - pattern[pShow->payloadLen] = 0; + char* pattern = mnodeGetTableShowPattern(pShow); + if (pShow->payloadLen > 0 && pattern == NULL) { + return 0; } while (numOfRows < rows) { @@ -3397,6 +3447,11 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro strcat(prefix, TS_PATH_DELIMITER); int32_t prefixLen = (int32_t)strlen(prefix); + char* pattern = mnodeGetTableShowPattern(pShow); + if (pShow->payloadLen > 0 && pattern == NULL) { + return 0; + } + while (numOfRows < rows) { pShow->pIter = mnodeGetNextChildTable(pShow->pIter, &pTable); if (pTable == NULL) break; @@ -3412,7 +3467,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro // pattern compare for table name mnodeExtractTableName(pTable->info.tableId, tableName); - if (pShow->payloadLen > 0 && patternMatch(pShow->payload, tableName, sizeof(tableName) - 1, &info) != TSDB_PATTERN_MATCH) { + if (pShow->payloadLen > 0 && patternMatch(pattern, tableName, sizeof(tableName) - 1, &info) != TSDB_PATTERN_MATCH) { mnodeDecTableRef(pTable); continue; } @@ -3444,6 +3499,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); mnodeDecDbRef(pDb); + free(pattern); return numOfRows; } diff --git a/src/os/inc/os.h b/src/os/inc/os.h index 903e80d5c7f554d420eafc9224fe5e7e35fe8467..e91edaab0f4e68cd0e39b677683fbe4b48eeaa3e 100644 --- a/src/os/inc/os.h +++ b/src/os/inc/os.h @@ -37,6 +37,7 @@ extern "C" { #include "osSysinfo.h" #include "osTime.h" #include "osTimer.h" +#include "osSystem.h" void osInit(); diff --git a/src/os/inc/osArm32.h b/src/os/inc/osArm32.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/os/inc/osArm64.h b/src/os/inc/osArm64.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/os/inc/osInc.h b/src/os/inc/osInc.h index 6a3c754dcc5ff359501bb744886d8c1f216d48c2..340ff34635d6a76781d9deb5c6012f0e2c5ffa13 100644 --- a/src/os/inc/osInc.h +++ b/src/os/inc/osInc.h @@ -76,7 +76,8 @@ extern "C" { #include #include "osEok.h" #else - #include + #include + #include #include #include #include diff --git a/src/os/inc/osLinux32.h b/src/os/inc/osLinux32.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/os/inc/osLinux64.h b/src/os/inc/osLinux64.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/os/inc/osSystem.h b/src/os/inc/osSystem.h new file mode 100644 index 0000000000000000000000000000000000000000..e7a3ec13ae1b3ff9a94724a4cd28e2b4bb40ac1c --- /dev/null +++ b/src/os/inc/osSystem.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_SYSTEM_H +#define TDENGINE_OS_SYSTEM_H + +#ifdef __cplusplus +extern "C" { +#endif + +void* taosLoadDll(const char *filename); +void* taosLoadSym(void* handle, char* name); +void taosCloseDll(void *handle); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/src/darwin/darwinSystem.c b/src/os/src/darwin/darwinSystem.c new file mode 100644 index 0000000000000000000000000000000000000000..17cafdd6644ed2adbb0a402689f9f300fa615d03 --- /dev/null +++ b/src/os/src/darwin/darwinSystem.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "os.h" +#include "tglobal.h" +#include "tulog.h" + +void* taosLoadDll(const char *filename) { + return NULL; +} + +void* taosLoadSym(void* handle, char* name) { + return NULL; +} + +void taosCloseDll(void *handle) { +} + + diff --git a/src/os/src/linux/CMakeLists.txt b/src/os/src/linux/CMakeLists.txt index d1d95b0096124e122cd630df89ef1057def10373..f60c10b65a004735e4b76f5d170a65afc6508c36 100644 --- a/src/os/src/linux/CMakeLists.txt +++ b/src/os/src/linux/CMakeLists.txt @@ -4,4 +4,4 @@ PROJECT(TDengine) AUX_SOURCE_DIRECTORY(. SRC) ADD_LIBRARY(oslinux ${SRC}) -TARGET_LINK_LIBRARIES(oslinux m rt z) \ No newline at end of file +TARGET_LINK_LIBRARIES(oslinux m rt z dl) \ No newline at end of file diff --git a/src/os/src/linux/osSystem.c b/src/os/src/linux/osSystem.c new file mode 100644 index 0000000000000000000000000000000000000000..052b7a22a8e9fe5dafffc4a90c8efa3643e4a06c --- /dev/null +++ b/src/os/src/linux/osSystem.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "os.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tulog.h" + +void* taosLoadDll(const char *filename) { + void *handle = dlopen (filename, RTLD_LAZY); + if (!handle) { + uError("load dll:%s failed, error:%s", filename, dlerror()); + return NULL; + } + + uDebug("dll %s loaded", filename); + + return handle; +} + +void* taosLoadSym(void* handle, char* name) { + void* sym = dlsym(handle, name); + char* error = NULL; + + if ((error = dlerror()) != NULL) { + uWarn("load sym:%s failed, error:%s", name, dlerror()); + return NULL; + } + + uDebug("sym %s loaded", name) + + return sym; +} + +void taosCloseDll(void *handle) { + if (handle) { + dlclose(handle); + } +} + + diff --git a/src/os/src/windows/wSystem.c b/src/os/src/windows/wSystem.c new file mode 100644 index 0000000000000000000000000000000000000000..17cafdd6644ed2adbb0a402689f9f300fa615d03 --- /dev/null +++ b/src/os/src/windows/wSystem.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "os.h" +#include "tglobal.h" +#include "tulog.h" + +void* taosLoadDll(const char *filename) { + return NULL; +} + +void* taosLoadSym(void* handle, char* name) { + return NULL; +} + +void taosCloseDll(void *handle) { +} + + diff --git a/src/plugins/http/inc/httpParser.h b/src/plugins/http/inc/httpParser.h index c7cf7a9608bf1c25fa3fdec16810ff6df07d28f8..fbe1ecee7e59ee9f8f34a813d62832c3dbbd6d86 100644 --- a/src/plugins/http/inc/httpParser.h +++ b/src/plugins/http/inc/httpParser.h @@ -17,7 +17,7 @@ #define HTTP_PARSER_H #include "httpGzip.h" -#define HTTP_MAX_URL 5 // http url stack size +#define HTTP_MAX_URL 6 // http url stack size #define HTTP_CODE_CONTINUE 100 #define HTTP_CODE_SWITCHING_PROTOCOL 101 diff --git a/src/plugins/http/src/httpRestHandle.c b/src/plugins/http/src/httpRestHandle.c index 8728b9e37a1561dd545c6878756dcfbc909a27fd..a285670d20ae1e5a9c8bd6c41971fc57cda3320a 100644 --- a/src/plugins/http/src/httpRestHandle.c +++ b/src/plugins/http/src/httpRestHandle.c @@ -119,6 +119,90 @@ bool restProcessSqlRequest(HttpContext* pContext, int32_t timestampFmt) { return true; } +#define REST_FUNC_URL_POS 2 +#define REST_OUTP_URL_POS 3 +#define REST_AGGR_URL_POS 4 +#define REST_BUFF_URL_POS 5 + +#define HTTP_FUNC_LEN 32 +#define HTTP_OUTP_LEN 16 +#define HTTP_AGGR_LEN 2 +#define HTTP_BUFF_LEN 32 + +static int udfSaveFile(const char *fname, const char *content, long len) { + int fd = open(fname, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0755); + if (fd < 0) + return -1; + if (taosWrite(fd, (void *)content, len) < 0) + return -1; + + return 0; +} + +static bool restProcessUdfRequest(HttpContext* pContext) { + HttpParser* pParser = pContext->parser; + if (pParser->path[REST_FUNC_URL_POS].pos >= HTTP_FUNC_LEN || pParser->path[REST_FUNC_URL_POS].pos <= 0) { + return false; + } + + if (pParser->path[REST_OUTP_URL_POS].pos >= HTTP_OUTP_LEN || pParser->path[REST_OUTP_URL_POS].pos <= 0) { + return false; + } + + if (pParser->path[REST_AGGR_URL_POS].pos >= HTTP_AGGR_LEN || pParser->path[REST_AGGR_URL_POS].pos <= 0) { + return false; + } + + if (pParser->path[REST_BUFF_URL_POS].pos >= HTTP_BUFF_LEN || pParser->path[REST_BUFF_URL_POS].pos <= 0) { + return false; + } + + char* sql = pContext->parser->body.str; + int len = pContext->parser->body.pos; + if (sql == NULL) { + httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_SQL_INPUT); + return false; + } + + char udfDir[256] = {0}; + char buf[64] = "udf-"; + char funcName[64] = {0}; + int aggr = 0; + char outputType[16] = {0}; + char buffSize[32] = {0}; + + tstrncpy(funcName, pParser->path[REST_FUNC_URL_POS].str, HTTP_FUNC_LEN); + tstrncpy(buf + 4, funcName, HTTP_FUNC_LEN); + + if (pParser->path[REST_AGGR_URL_POS].str[0] != '0') { + aggr = 1; + } + + tstrncpy(outputType, pParser->path[REST_OUTP_URL_POS].str, HTTP_OUTP_LEN); + tstrncpy(buffSize, pParser->path[REST_BUFF_URL_POS].str, HTTP_BUFF_LEN); + + taosGetTmpfilePath(funcName, udfDir); + + udfSaveFile(udfDir, sql, len); + + tfree(sql); + pContext->parser->body.str = malloc(1024); + sql = pContext->parser->body.str; + int sqlLen = sprintf(sql, "create %s function %s as \"%s\" outputtype %s bufsize %s", + aggr == 1 ? "aggregate" : " ", funcName, udfDir, outputType, buffSize); + + pContext->parser->body.pos = sqlLen; + pContext->parser->body.size = sqlLen + 1; + + HttpSqlCmd* cmd = &(pContext->singleCmd); + cmd->nativSql = sql; + + pContext->reqType = HTTP_REQTYPE_SINGLE_SQL; + pContext->encodeMethod = &restEncodeSqlLocalTimeStringMethod; + + return true; +} + bool restProcessRequest(struct HttpContext* pContext) { if (httpUrlMatch(pContext, REST_ACTION_URL_POS, "login")) { restGetUserFromUrl(pContext); @@ -138,6 +222,8 @@ bool restProcessRequest(struct HttpContext* pContext) { return restProcessSqlRequest(pContext, REST_TIMESTAMP_FMT_UTC_STRING); } else if (httpUrlMatch(pContext, REST_ACTION_URL_POS, "login")) { return restProcessLoginRequest(pContext); + } else if (httpUrlMatch(pContext, REST_ACTION_URL_POS, "udf")) { + return restProcessUdfRequest(pContext); } else { } diff --git a/src/query/CMakeLists.txt b/src/query/CMakeLists.txt index d2411d47b52bac65e86852ef06116066e9b18774..fd730adee56c3d5edddb943303f5b6b24d9f019c 100644 --- a/src/query/CMakeLists.txt +++ b/src/query/CMakeLists.txt @@ -8,14 +8,14 @@ INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(src SRC) ADD_LIBRARY(query ${SRC}) SET_SOURCE_FILES_PROPERTIES(src/sql.c PROPERTIES COMPILE_FLAGS -w) -TARGET_LINK_LIBRARIES(query tsdb tutil) +TARGET_LINK_LIBRARIES(query tsdb tutil lua) IF (TD_LINUX) - TARGET_LINK_LIBRARIES(query m rt) + TARGET_LINK_LIBRARIES(query m rt lua) ADD_SUBDIRECTORY(tests) ENDIF () IF (TD_DARWIN) - TARGET_LINK_LIBRARIES(query m) + TARGET_LINK_LIBRARIES(query m lua) ADD_SUBDIRECTORY(tests) ENDIF () diff --git a/src/query/inc/qAggMain.h b/src/query/inc/qAggMain.h index 044c538f4708b606eb77b63ac68921bcb3877ba7..d4116fbfb2daec9b47c4a891c3c886728e6ca515 100644 --- a/src/query/inc/qAggMain.h +++ b/src/query/inc/qAggMain.h @@ -27,6 +27,7 @@ extern "C" { #include "trpc.h" #include "tvariant.h" #include "tsdb.h" +#include "qUdf.h" #define TSDB_FUNC_INVALID_ID -1 #define TSDB_FUNC_COUNT 0 @@ -201,10 +202,8 @@ typedef struct SAggFunctionInfo { int8_t stableFuncId; // transfer function for super table query uint16_t status; - bool (*init)(SQLFunctionCtx *pCtx); // setup the execute environment - + bool (*init)(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultCellInfo); // setup the execute environment void (*xFunction)(SQLFunctionCtx *pCtx); // blocks version function -// void (*xFunctionF)(SQLFunctionCtx *pCtx, int32_t position); // single-row function version, todo merge with blockwise function // finalizer must be called after all xFunction has been executed to generated final result. void (*xFinalize)(SQLFunctionCtx *pCtx); @@ -216,7 +215,7 @@ typedef struct SAggFunctionInfo { #define GET_RES_INFO(ctx) ((ctx)->resultInfo) int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, - int16_t *len, int32_t *interBytes, int16_t extLength, bool isSuperTable); + int16_t *len, int32_t *interBytes, int16_t extLength, bool isSuperTable, SUdfInfo* pUdfInfo); int32_t isValidFunction(const char* name, int32_t len); #define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0) @@ -262,9 +261,9 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const cha static FORCE_INLINE void initResultInfo(SResultRowCellInfo *pResInfo, int32_t bufLen) { pResInfo->initialized = true; // the this struct has been initialized flag - pResInfo->complete = false; + pResInfo->complete = false; pResInfo->hasResult = false; - pResInfo->numOfRes = 0; + pResInfo->numOfRes = 0; memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen); } diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index c4276bfe3781a97d91041fedfde7d67fcaa5a5d3..4581ba258d158c6cd929358a8ca15b1926397747 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -29,6 +29,7 @@ #include "tarray.h" #include "tlockfree.h" #include "tsdb.h" +#include "qUdf.h" struct SColumnFilterElem; typedef bool (*__filter_func_t)(struct SColumnFilterElem* pFilter, const char* val1, const char* val2, int16_t type); @@ -257,6 +258,7 @@ typedef struct SQueryAttr { SMemRef memRef; STableGroupInfo tableGroupInfo; // table list SArray int32_t vgId; + SArray *pUdfInfo; // no need to free } SQueryAttr; typedef SSDataBlock* (*__operator_fn_t)(void* param, bool* newgroup); @@ -297,6 +299,7 @@ typedef struct SQueryRuntimeEnv { STableQueryInfo *current; SRspResultInfo resultInfo; SHashObj *pTableRetrieveTsMap; + SUdfInfo *pUdfInfo; } SQueryRuntimeEnv; enum { @@ -392,6 +395,7 @@ typedef struct SQueryParam { SGroupbyExpr *pGroupbyExpr; int32_t tableScanOperator; SArray *pOperator; + SUdfInfo *pUdfInfo; } SQueryParam; typedef struct STableScanInfo { @@ -531,6 +535,7 @@ typedef struct SMultiwayMergeInfo { bool hasPrev; bool groupMix; + SArray *udfInfo; } SMultiwayMergeInfo; void appendUpstream(SOperatorInfo* p, SOperatorInfo* pUpstream); @@ -553,8 +558,8 @@ SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperat SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv); SOperatorInfo* createMultiwaySortOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput, int32_t numOfRows, void* merger, bool groupMix); +SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, void* param, SArray* pUdfInfo); SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); -SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, void* param); SOperatorInfo* createSLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, void* merger); SOperatorInfo* createFilterOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SColumnInfo* pCols, int32_t numOfFilter); @@ -578,18 +583,19 @@ void setInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SSDataBlo int32_t getNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx* pCtx, int32_t numOfOutput); void finalizeQueryResult(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset); void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOfInputRows); +void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity); void freeParam(SQueryParam *param); int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param); int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExprInfo** pExprInfo, - SSqlExpr** pExprMsg, SColumnInfo* pTagCols, int32_t queryType, void* pMsg); + SSqlExpr** pExprMsg, SColumnInfo* pTagCols, int32_t queryType, void* pMsg, SUdfInfo* pUdfInfo); int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, - SSqlExpr **pExpr, SExprInfo *prevExpr); + SSqlExpr **pExpr, SExprInfo *prevExpr, SUdfInfo *pUdfInfo); SGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code); SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs, - SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, int32_t vgId, char* sql, uint64_t qId); + SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, int32_t vgId, char* sql, uint64_t qId, SUdfInfo* pUdfInfo); int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* pQInfo, SQueryParam* param, char* start, int32_t prevResultLen, void* merger); @@ -608,6 +614,8 @@ bool doBuildResCheck(SQInfo* pQInfo); void setQueryStatus(SQueryRuntimeEnv *pRuntimeEnv, int8_t status); bool onlyQueryTags(SQueryAttr* pQueryAttr); +void destroyUdfInfo(SUdfInfo* pUdfInfo); + bool isValidQInfo(void *param); int32_t doDumpQueryResult(SQInfo *pQInfo, char *data); @@ -625,4 +633,6 @@ void freeQueryAttr(SQueryAttr *pQuery); int32_t getMaximumIdleDurationSec(); +void doInvokeUdf(SUdfInfo* pUdfInfo, SQLFunctionCtx *pCtx, int32_t idx, int32_t type); + #endif // TDENGINE_QEXECUTOR_H diff --git a/src/query/inc/qExtbuffer.h b/src/query/inc/qExtbuffer.h index b851fbb3e076db76a94b8542b83e6f3dc073f3f3..cf0e8ce31af91ad9d94feed2045265862a57545a 100644 --- a/src/query/inc/qExtbuffer.h +++ b/src/query/inc/qExtbuffer.h @@ -77,13 +77,13 @@ typedef struct tFilePagesItem { typedef struct SSchemaEx { struct SSchema field; - int16_t offset; + int32_t offset; } SSchemaEx; typedef struct SColumnModel { int32_t capacity; int32_t numOfCols; - int16_t rowSize; + int32_t rowSize; SSchemaEx *pFields; } SColumnModel; diff --git a/src/query/inc/qScript.h b/src/query/inc/qScript.h new file mode 100644 index 0000000000000000000000000000000000000000..574bb51368afeaeddef5fbd5c5bd8469fbe0cdef --- /dev/null +++ b/src/query/inc/qScript.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_QSCRIPT_H +#define TDENGINE_QSCRIPT_H + +#include +#include +#include + +#include "tutil.h" +#include "hash.h" +#include "tlist.h" +#include "qUdf.h" + +#define MAX_FUNC_NAME 64 + +#define USER_FUNC_NAME "funcName" +#define USER_FUNC_NAME_LIMIT 48 + +enum ScriptState { + SCRIPT_STATE_INIT, + SCRIPT_STATE_ADD, + SCRIPT_STATE_MERGE, + SCRIPT_STATE_FINALIZE +}; + + +typedef struct { + SHashObj *funcId; //func already registed in lua_env, may be no use + lua_State *lua_state; // lua env +} ScriptEnv; + +typedef struct ScriptCtx { + char funcName[USER_FUNC_NAME_LIMIT]; + int8_t state; + ScriptEnv *pEnv; + int8_t isAgg; // agg function or not + + // init value of udf script + int8_t resType; + int16_t resBytes; + + int32_t numOfOutput; + int32_t offset; + +} ScriptCtx; + +int taosLoadScriptInit(void *pInit); +void taosLoadScriptNormal(void *pInit, char *pInput, int16_t iType, int16_t iBytes, int32_t numOfRows, + int64_t *ptsList, int64_t key, char* pOutput, char *ptsOutput, int32_t *numOfOutput, int16_t oType, int16_t oBytes); +void taosLoadScriptFinalize(void *pInit, int64_t key, char *pOutput, int32_t *output); +void taosLoadScriptMerge(void *pCtx, char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput); +void taosLoadScriptDestroy(void *pInit); + +typedef struct { + SList *scriptEnvs; // + int32_t mSize; // pool limit + int32_t cSize; // current available size + pthread_mutex_t mutex; +} ScriptEnvPool; + +ScriptCtx* createScriptCtx(char *str, int8_t resType, int16_t resBytes); +void destroyScriptCtx(void *pScriptCtx); + +int32_t scriptEnvPoolInit(); +void scriptEnvPoolCleanup(); +bool isValidScript(char *script, int32_t len); + +#endif //TDENGINE_QSCRIPT_H diff --git a/src/query/inc/qSqlparser.h b/src/query/inc/qSqlparser.h index f9a9992b81aa30b15b042a96af343c9e943bd20b..f2ab2182a1c00e2d91cdf2199ff8cc8c42bfce2f 100644 --- a/src/query/inc/qSqlparser.h +++ b/src/query/inc/qSqlparser.h @@ -182,6 +182,15 @@ typedef struct SCreateDbInfo { int16_t partitions; } SCreateDbInfo; +typedef struct SCreateFuncInfo { + SStrToken name; + SStrToken path; + int32_t type; + int32_t bufSize; + TAOS_FIELD output; +} SCreateFuncInfo; + + typedef struct SCreateAcctInfo { int32_t maxUsers; int32_t maxDbs; @@ -214,10 +223,11 @@ typedef struct SMiscInfo { int16_t tableType; SUserInfo user; union { - SCreateDbInfo dbOpt; - SCreateAcctInfo acctOpt; - SShowInfo showOpt; - SStrToken id; + SCreateDbInfo dbOpt; + SCreateAcctInfo acctOpt; + SCreateFuncInfo funcOpt; + SShowInfo showOpt; + SStrToken id; }; } SMiscInfo; @@ -226,6 +236,7 @@ typedef struct SSqlInfo { bool valid; SArray *list; // todo refactor char msg[256]; + SArray *funcs; union { SCreateTableSql *pCreateTableInfo; SAlterTableInfo *pAlterInfo; @@ -271,6 +282,7 @@ SRelationInfo *addSubqueryElem(SRelationInfo* pRelationInfo, SArray* pSub, SStrT // sql expr leaf node tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType); tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType); +SArray *tStrTokenAppend(SArray *pList, SStrToken *pToken); tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType); tSqlExpr *tSqlExprClone(tSqlExpr *pSrc); diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index 3f17e62f1e1e7bed10b772797c5ba150c0cb3661..56eea6429f2406d07d532b6a9ef4910dfcc49413 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -125,8 +125,12 @@ typedef struct SQueryInfo { int32_t round; // 0/1/.... int32_t bufLen; char* buf; - struct SQInfo* pQInfo; // global merge operator - struct SQueryAttr* pQueryAttr; // query object + + bool udfCopy; + SArray *pUdfInfo; + + struct SQInfo *pQInfo; // global merge operator + struct SQueryAttr *pQueryAttr; // query object struct SQueryInfo *sibling; // sibling SArray *pUpstream; // SArray @@ -141,6 +145,7 @@ typedef struct SQueryInfo { bool onlyTagQuery; bool orderProjectQuery; bool stateWindow; + bool globalMerge; } SQueryInfo; /** diff --git a/src/query/inc/qUdf.h b/src/query/inc/qUdf.h new file mode 100644 index 0000000000000000000000000000000000000000..1083b1e698f7591aae4586c7722e5343cd9c4d86 --- /dev/null +++ b/src/query/inc/qUdf.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_QUDF_H +#define TDENGINE_QUDF_H + +enum { TSDB_UDF_FUNC_NORMAL = 0, TSDB_UDF_FUNC_INIT, TSDB_UDF_FUNC_FINALIZE, TSDB_UDF_FUNC_MERGE, TSDB_UDF_FUNC_DESTROY, TSDB_UDF_FUNC_MAX_NUM }; + + + +typedef struct SUdfInit{ + int32_t maybe_null; /* 1 if function can return NULL */ + uint32_t decimals; /* for real functions */ + uint64_t length; /* For string functions */ + char *ptr; /* free pointer for function data */ + int32_t const_item; /* 0 if result is independent of arguments */ + + // script like lua/javascript + void* script_ctx; + void (*destroyCtxFunc)(void *script_ctx); +} SUdfInit; + + +typedef struct SUdfInfo { + int32_t functionId; // system assigned function id + int32_t funcType; // scalar function or aggregate function + int8_t resType; // result type + int16_t resBytes; // result byte + int32_t contLen; // content length + int32_t bufSize; //interbuf size + char *name; // function name + void *handle; // handle loaded in mem + void *funcs[TSDB_UDF_FUNC_MAX_NUM]; // function ptr + + // for script like lua/javascript only + int isScript; + void *pScriptCtx; + + SUdfInit init; + char *content; + char *path; +} SUdfInfo; + +//script + +typedef int32_t (*scriptInitFunc)(void *pCtx); +typedef void (*scriptNormalFunc)(void *pCtx, char* data, int16_t iType, int16_t iBytes, int32_t numOfRows, + int64_t* ptList, int64_t key, char* dataOutput, char* tsOutput, int32_t* numOfOutput, int16_t oType, int16_t oBytes); +typedef void (*scriptFinalizeFunc)(void *pCtx, int64_t key, char* dataOutput, int32_t* numOfOutput); +typedef void (*scriptMergeFunc)(void *pCtx, char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput); +typedef void (*scriptDestroyFunc)(void* pCtx); + +// dynamic lib +typedef void (*udfNormalFunc)(char* data, int16_t itype, int16_t iBytes, int32_t numOfRows, int64_t* ts, char* dataOutput, char* interBuf, + char* tsOutput, int32_t* numOfOutput, int16_t oType, int16_t oBytes, SUdfInit* buf); +typedef int32_t (*udfInitFunc)(SUdfInit* data); +typedef void (*udfFinalizeFunc)(char* dataOutput, char *interBuf, int32_t* numOfOutput, SUdfInit* buf); +typedef void (*udfMergeFunc)(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf); +typedef void (*udfDestroyFunc)(SUdfInit* buf); + + +#endif // TDENGINE_QUDF_H diff --git a/src/query/inc/qUtil.h b/src/query/inc/qUtil.h index c8741030c06ac0e9463de85c2e1f358ed24fa649..d2802d9fe00be74f750abd39b81cc3585bcef773 100644 --- a/src/query/inc/qUtil.h +++ b/src/query/inc/qUtil.h @@ -66,7 +66,8 @@ static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int return pResultRowInfo->pResult[slot]; } -static FORCE_INLINE char *getPosInResultPage(SQueryAttr *pQueryAttr, tFilePage* page, int32_t rowOffset, int16_t offset) { +static FORCE_INLINE char* getPosInResultPage(SQueryAttr* pQueryAttr, tFilePage* page, int32_t rowOffset, + int32_t offset) { assert(rowOffset >= 0 && pQueryAttr != NULL); int32_t numOfRows = (int32_t)GET_ROW_PARAM_FOR_MULTIOUTPUT(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery); @@ -104,4 +105,6 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo); int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t* offset); +int32_t initUdfInfo(SUdfInfo* pUdfInfo); + #endif // TDENGINE_QUERYUTIL_H diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index abd7d06b6080f6361cb1504b8d86c62f11ee0bac..ecdde4f7076b10a98fc36d75ebe4bac3691379bb 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -65,6 +65,7 @@ program ::= cmd. {} //////////////////////////////////THE SHOW STATEMENT/////////////////////////////////////////// cmd ::= SHOW DATABASES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_DB, 0, 0);} cmd ::= SHOW TOPICS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_TP, 0, 0);} +cmd ::= SHOW FUNCTIONS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_FUNCTION, 0, 0);} cmd ::= SHOW MNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);} cmd ::= SHOW DNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);} cmd ::= SHOW ACCOUNTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);} @@ -147,6 +148,7 @@ cmd ::= DROP STABLE ifexists(Y) ids(X) cpxName(Z). { cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_DEFAULT, -1); } cmd ::= DROP TOPIC ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_TOPIC, -1); } +cmd ::= DROP FUNCTION ids(X). { setDropFuncInfo(pInfo, TSDB_SQL_DROP_FUNCTION, &X); } cmd ::= DROP DNODE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); } cmd ::= DROP USER ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); } @@ -200,8 +202,13 @@ cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);} cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);} cmd ::= CREATE TOPIC ifnotexists(Z) ids(X) topic_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);} +cmd ::= CREATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B). { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 1);} +cmd ::= CREATE AGGREGATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B). { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 2);} cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSql(pInfo, &X, &Y);} +bufsize(Y) ::= . { Y.n = 0; } +bufsize(Y) ::= BUFSIZE INTEGER(X). { Y = X; } + pps(Y) ::= . { Y.n = 0; } pps(Y) ::= PPS INTEGER(X). { Y = X; } @@ -704,10 +711,10 @@ expr(A) ::= BOOL(X). { A = tSqlExprCreateIdValue(&X, TK_BOOL);} expr(A) ::= NULL(X). { A = tSqlExprCreateIdValue(&X, TK_NULL);} // ordinary functions: min(x), max(x), top(k, 20) -expr(A) ::= ID(X) LP exprlist(Y) RP(E). { A = tSqlExprCreateFunction(Y, &X, &E, X.type); } +expr(A) ::= ID(X) LP exprlist(Y) RP(E). { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFunction(Y, &X, &E, X.type); } // for parsing sql functions with wildcard for parameters. e.g., count(*)/first(*)/last(*) operation -expr(A) ::= ID(X) LP STAR RP(Y). { A = tSqlExprCreateFunction(NULL, &X, &Y, X.type); } +expr(A) ::= ID(X) LP STAR RP(Y). { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFunction(NULL, &X, &Y, X.type); } // is (not) null expression expr(A) ::= expr(X) IS NULL. {A = tSqlExprCreate(X, NULL, TK_ISNULL);} diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 7412b5f021a7be21a3d60be5e75ee1d5cf6fc33f..d96b260b13cf8a1bbcbc9b329a51bc1a714aba8d 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -27,6 +27,7 @@ #include "qPercentile.h" #include "qTsbuf.h" #include "queryLog.h" +#include "qUdf.h" #define GET_INPUT_DATA_LIST(x) ((char *)((x)->pInput)) #define GET_INPUT_DATA(x, y) (GET_INPUT_DATA_LIST(x) + (y) * (x)->inputBytes) @@ -169,12 +170,13 @@ typedef struct SDerivInfo { } 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) { + int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable, SUdfInfo* pUdfInfo) { if (!isValidDataType(dataType)) { qError("Illegal data type %d or data type length %d", dataType, dataBytes); return TSDB_CODE_TSC_INVALID_OPERATION; } - + + if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_INTERP) { @@ -234,6 +236,20 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI } if (isSuperTable) { + if (functionId < 0) { + if (pUdfInfo->bufSize > 0) { + *type = TSDB_DATA_TYPE_BINARY; + *bytes = pUdfInfo->bufSize; + *interBytes = *bytes; + } else { + *type = pUdfInfo->resType; + *bytes = pUdfInfo->resBytes; + *interBytes = *bytes; + } + + return TSDB_CODE_SUCCESS; + } + if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) { *type = TSDB_DATA_TYPE_BINARY; *bytes = (int16_t)(dataBytes + DATA_SET_FLAG_SIZE); @@ -288,7 +304,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI return TSDB_CODE_SUCCESS; } } - + if (functionId == TSDB_FUNC_SUM) { if (IS_SIGNED_NUMERIC_TYPE(dataType)) { *type = TSDB_DATA_TYPE_BIGINT; @@ -313,7 +329,20 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI *interBytes = sizeof(STwaInfo); return TSDB_CODE_SUCCESS; } - + + if (functionId < 0) { + *type = pUdfInfo->resType; + *bytes = pUdfInfo->resBytes; + + if (pUdfInfo->bufSize > 0) { + *interBytes = pUdfInfo->bufSize; + } else { + *interBytes = *bytes; + } + + return TSDB_CODE_SUCCESS; + } + if (functionId == TSDB_FUNC_AVG) { *type = TSDB_DATA_TYPE_DOUBLE; *bytes = sizeof(double); @@ -390,14 +419,13 @@ int32_t isValidFunction(const char* name, int32_t len) { return -1; } -static bool function_setup(SQLFunctionCtx *pCtx) { - SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); - if (pResInfo->initialized) { +static bool function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultInfo) { + if (pResultInfo->initialized) { return false; } memset(pCtx->pOutput, 0, (size_t)pCtx->outputBytes); - initResultInfo(pResInfo, pCtx->interBufBytes); + initResultInfo(pResultInfo, pCtx->interBufBytes); return true; } @@ -985,8 +1013,8 @@ static void minMax_function(SQLFunctionCtx *pCtx, char *pOutput, int32_t isMin, } } -static bool min_func_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool min_func_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultInfo) { + if (!function_setup(pCtx, pResultInfo)) { return false; // not initialized since it has been initialized } @@ -1030,8 +1058,8 @@ static bool min_func_setup(SQLFunctionCtx *pCtx) { return true; } -static bool max_func_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool max_func_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultInfo) { + if (!function_setup(pCtx, pResultInfo)) { return false; // not initialized since it has been initialized } @@ -1435,8 +1463,8 @@ static void stddev_dst_finalizer(SQLFunctionCtx *pCtx) { } ////////////////////////////////////////////////////////////////////////////////////// -static bool first_last_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool first_last_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { + if (!function_setup(pCtx, pResInfo)) { return false; } @@ -1606,7 +1634,7 @@ static void last_function(SQLFunctionCtx *pCtx) { break; } } - + SET_VAL(pCtx, notNullElems, 1); } @@ -2007,7 +2035,7 @@ static void buildTopBotStruct(STopBotInfo *pTopBotInfo, SQLFunctionCtx *pCtx) { char *tmp = (char *)pTopBotInfo + sizeof(STopBotInfo); pTopBotInfo->res = (tValuePair**) tmp; tmp += POINTER_BYTES * pCtx->param[0].i64; - + size_t size = sizeof(tValuePair) + pCtx->tagInfo.tagsLen; for (int32_t i = 0; i < pCtx->param[0].i64; ++i) { @@ -2073,14 +2101,13 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const cha } } -static bool top_bottom_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool top_bottom_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { + if (!function_setup(pCtx, pResInfo)) { return false; } STopBotInfo *pInfo = getTopBotOutputInfo(pCtx); buildTopBotStruct(pInfo, pCtx); - return true; } @@ -2229,14 +2256,13 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) { } /////////////////////////////////////////////////////////////////////////////////////////////// -static bool percentile_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool percentile_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultInfo) { + if (!function_setup(pCtx, pResultInfo)) { return false; } // in the first round, get the min-max value of all involved data - SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); - SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); + SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResultInfo); SET_DOUBLE_VAL(&pInfo->minval, DBL_MAX); SET_DOUBLE_VAL(&pInfo->maxval, -DBL_MAX); pInfo->numOfElems = 0; @@ -2367,8 +2393,8 @@ static SAPercentileInfo *getAPerctInfo(SQLFunctionCtx *pCtx) { return pInfo; } -static bool apercentile_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool apercentile_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultInfo) { + if (!function_setup(pCtx, pResultInfo)) { return false; } @@ -2477,12 +2503,11 @@ static void apercentile_finalizer(SQLFunctionCtx *pCtx) { } ///////////////////////////////////////////////////////////////////////////////// -static bool leastsquares_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool leastsquares_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { + if (!function_setup(pCtx, pResInfo)) { return false; } - - SResultRowCellInfo * pResInfo = GET_RES_INFO(pCtx); + SLeastsquaresInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); // 2*3 matrix @@ -2706,8 +2731,8 @@ enum { INITIAL_VALUE_NOT_ASSIGNED = 0, }; -static bool diff_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool diff_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { + if (!function_setup(pCtx, pResInfo)) { return false; } @@ -2716,14 +2741,13 @@ static bool diff_function_setup(SQLFunctionCtx *pCtx) { return false; } -static bool deriv_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool deriv_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultInfo) { + if (!function_setup(pCtx, pResultInfo)) { return false; } // diff function require the value is set to -1 - SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); - SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo); + SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResultInfo); pDerivInfo->ignoreNegative = pCtx->param[1].i64; pDerivInfo->prevTs = -1; @@ -3130,12 +3154,12 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) { } ///////////////////////////////////////////////////////////////////////////////// -static bool spread_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool spread_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { + if (!function_setup(pCtx, pResInfo)) { return false; } - SSpreadInfo *pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + SSpreadInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); // this is the server-side setup function in client-side, the secondary merge do not need this procedure if (pCtx->currentStage == MERGE_STAGE) { @@ -3289,12 +3313,10 @@ void spread_function_finalizer(SQLFunctionCtx *pCtx) { * param[2]: end time * @param pCtx */ -static bool twa_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool twa_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { + if (!function_setup(pCtx, pResInfo)) { return false; } - - SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); STwaInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); pInfo->p.key = INT64_MIN; @@ -3726,14 +3748,12 @@ static void interp_function(SQLFunctionCtx *pCtx) { } } -static bool ts_comp_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool ts_comp_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { + if (!function_setup(pCtx, pResInfo)) { return false; // not initialized since it has been initialized } - - SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); + STSCompInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); - pInfo->pTSBuf = tsBufCreate(false, pCtx->order); pInfo->pTSBuf->tsOrder = pCtx->order; return true; @@ -3816,13 +3836,11 @@ static double do_calc_rate(const SRateInfo* pRateInfo, double tickPerSec) { return (duration > 0)? ((double)diff) / (duration/tickPerSec):0.0; } -static bool rate_function_setup(SQLFunctionCtx *pCtx) { - if (!function_setup(pCtx)) { +static bool rate_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { + if (!function_setup(pCtx, pResInfo)) { return false; } - SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); - SRateInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); pInfo->correctionValue = 0; pInfo->firstKey = INT64_MIN; @@ -3920,7 +3938,7 @@ static void irate_function(SQLFunctionCtx *pCtx) { int32_t notNullElems = 0; SRateInfo *pRateInfo = (SRateInfo *)GET_ROWCELL_INTERBUF(pResInfo); TSKEY *primaryKey = GET_TS_LIST(pCtx); - + for (int32_t i = pCtx->size - 1; i >= 0; --i) { char *pData = GET_INPUT_DATA(pCtx, i); if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { @@ -3964,7 +3982,7 @@ void blockInfo_func(SQLFunctionCtx* pCtx) { int32_t len = *(int32_t*) pCtx->pInput; blockDistInfoFromBinary((char*)pCtx->pInput + sizeof(int32_t), len, pDist); - pDist->rowSize = (int16_t) pCtx->param[0].i64; + pDist->rowSize = (uint16_t)pCtx->param[0].i64; memcpy(pCtx->pOutput, pCtx->pInput, sizeof(int32_t) + len); @@ -4111,7 +4129,7 @@ void blockinfo_func_finalizer(SQLFunctionCtx* pCtx) { SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); STableBlockDist* pDist = (STableBlockDist*) GET_ROWCELL_INTERBUF(pResInfo); - pDist->rowSize = (int16_t)pCtx->param[0].i64; + pDist->rowSize = (uint16_t)pCtx->param[0].i64; generateBlockDistResult(pDist, pCtx->pOutput); // cannot set the numOfIteratedElems again since it is set during previous iteration diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 739e9ff7ced258355273afbf719671e0d3203db9..288a2064915df70990350523a694fadcf878f7e0 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -29,10 +29,11 @@ #include "ttype.h" #include "tcompare.h" #include "tscompression.h" +#include "qScript.h" #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 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) @@ -212,24 +213,24 @@ SArray* getOrderCheckColumns(SQueryAttr* pQuery); typedef struct SRowCompSupporter { - SQueryRuntimeEnv *pRuntimeEnv; + SQueryRuntimeEnv *pRuntimeEnv; int16_t dataOffset; - __compar_fn_t comFunc; + __compar_fn_t comFunc; } SRowCompSupporter; static int compareRowData(const void *a, const void *b, const void *userData) { - const SResultRow *pRow1 = (const SResultRow *)a; + const SResultRow *pRow1 = (const SResultRow *)a; const SResultRow *pRow2 = (const SResultRow *)b; - SRowCompSupporter *supporter = (SRowCompSupporter *)userData; - SQueryRuntimeEnv* pRuntimeEnv = supporter->pRuntimeEnv; - + SRowCompSupporter *supporter = (SRowCompSupporter *)userData; + SQueryRuntimeEnv* pRuntimeEnv = supporter->pRuntimeEnv; + tFilePage *page1 = getResBufPage(pRuntimeEnv->pResultBuf, pRow1->pageId); tFilePage *page2 = getResBufPage(pRuntimeEnv->pResultBuf, pRow2->pageId); - int16_t offset = supporter->dataOffset; + int16_t offset = supporter->dataOffset; char *in1 = getPosInResultPage(pRuntimeEnv->pQueryAttr, page1, pRow1->offset, offset); - char *in2 = getPosInResultPage(pRuntimeEnv->pQueryAttr, page2, pRow2->offset, offset); + char *in2 = getPosInResultPage(pRuntimeEnv->pQueryAttr, page2, pRow2->offset, offset); return (in1 != NULL && in2 != NULL) ? supporter->comFunc(in1, in2) : 0; } @@ -250,7 +251,7 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeE bool found = false; int16_t dataOffset = 0; - + for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j); if (orderId == j) { @@ -259,15 +260,15 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeE } dataOffset += pColInfoData->info.bytes; - } + } if (found == false) { return; } int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderId].base.resType; - - SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)}; + + SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)}; taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support); } @@ -780,6 +781,79 @@ static int32_t getNumOfRowsInTimeWindow(SQueryRuntimeEnv* pRuntimeEnv, SDataBloc return num; } +void doInvokeUdf(SUdfInfo* pUdfInfo, SQLFunctionCtx *pCtx, int32_t idx, int32_t type) { + int32_t output = 0; + + if (pUdfInfo == NULL || pUdfInfo->funcs[type] == NULL) { + qError("empty udf function, type:%d", type); + return; + } + + qDebug("invoke udf function:%s,%p", pUdfInfo->name, pUdfInfo->funcs[type]); + + switch (type) { + case TSDB_UDF_FUNC_NORMAL: + if (pUdfInfo->isScript) { + (*(scriptNormalFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL])(pUdfInfo->pScriptCtx, + (char *)pCtx->pInput + idx * pCtx->inputType, pCtx->inputType, pCtx->inputBytes, pCtx->size, pCtx->ptsList, pCtx->startTs, pCtx->pOutput, + (char *)pCtx->ptsOutputBuf, &output, pCtx->outputType, pCtx->outputBytes); + } else { + SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); + + void *interBuf = (void *)GET_ROWCELL_INTERBUF(pResInfo); + + (*(udfNormalFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL])((char *)pCtx->pInput + idx * pCtx->inputType, pCtx->inputType, pCtx->inputBytes, pCtx->size, pCtx->ptsList, + pCtx->pOutput, interBuf, (char *)pCtx->ptsOutputBuf, &output, pCtx->outputType, pCtx->outputBytes, &pUdfInfo->init); + } + + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + pCtx->resultInfo->numOfRes = output; + } else { + pCtx->resultInfo->numOfRes += output; + } + + if (pCtx->resultInfo->numOfRes > 0) { + pCtx->resultInfo->hasResult = DATA_SET_FLAG; + } + + break; + + case TSDB_UDF_FUNC_MERGE: + if (pUdfInfo->isScript) { + (*(scriptMergeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE])(pUdfInfo->pScriptCtx, pCtx->pInput, pCtx->size, pCtx->pOutput, &output); + } else { + (*(udfMergeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE])(pCtx->pInput, pCtx->size, pCtx->pOutput, &output, &pUdfInfo->init); + } + + // set the output value exist + pCtx->resultInfo->numOfRes = output; + if (output > 0) { + pCtx->resultInfo->hasResult = DATA_SET_FLAG; + } + + break; + + case TSDB_UDF_FUNC_FINALIZE: { + SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); + void *interBuf = (void *)GET_ROWCELL_INTERBUF(pResInfo); + if (pUdfInfo->isScript) { + (*(scriptFinalizeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE])(pUdfInfo->pScriptCtx, pCtx->startTs, pCtx->pOutput, &output); + } else { + (*(udfFinalizeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE])(pCtx->pOutput, interBuf, &output, &pUdfInfo->init); + } + // set the output value exist + pCtx->resultInfo->numOfRes = output; + if (output > 0) { + pCtx->resultInfo->hasResult = DATA_SET_FLAG; + } + + break; + } + } + + return; +} + static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx, STimeWindow* pWin, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput) { SQueryAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; @@ -789,7 +863,7 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx pCtx[k].size = forwardStep; pCtx[k].startTs = pWin->skey; - // keep it temprarily + // keep it temporarialy char* start = pCtx[k].pInput; int32_t pos = (QUERY_IS_ASC_QUERY(pQueryAttr)) ? offset : offset - (forwardStep - 1); @@ -807,8 +881,14 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx pCtx[k].preAggVals.isSet = false; } + int32_t functionId = pCtx[k].functionId; if (functionNeedToExecute(pRuntimeEnv, &pCtx[k])) { - aAggs[pCtx[k].functionId].xFunction(&pCtx[k]); + if (functionId < 0) { // load the script and exec, pRuntimeEnv->pUdfInfo + SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo; + doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL); + } else { + aAggs[functionId].xFunction(&pCtx[k]); + } } // restore it @@ -1018,6 +1098,13 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, pCtx[i].pInput = p->pData; assert(p->info.colId == pColIndex->colId && pCtx[i].inputType == p->info.type); + if (pCtx[i].functionId < 0) { + SColumnInfoData* tsInfo = taosArrayGet(pBlock->pDataBlock, 0); + pCtx[i].ptsList = (int64_t*) tsInfo->pData; + + continue; + } + uint32_t status = aAggs[pCtx[i].functionId].status; if ((status & (TSDB_FUNCSTATE_SELECTIVITY | TSDB_FUNCSTATE_NEED_TS)) != 0) { SColumnInfoData* tsInfo = taosArrayGet(pBlock->pDataBlock, 0); @@ -1050,7 +1137,14 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SQLFunction for (int32_t k = 0; k < pOperator->numOfOutput; ++k) { if (functionNeedToExecute(pRuntimeEnv, &pCtx[k])) { pCtx[k].startTs = startTs;// this can be set during create the struct - aAggs[pCtx[k].functionId].xFunction(&pCtx[k]); + + int32_t functionId = pCtx[k].functionId; + if (functionId < 0) { + SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo; + doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL); + } else { + aAggs[functionId].xFunction(&pCtx[k]); + } } } } @@ -1066,7 +1160,15 @@ static void projectApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx pCtx[k].order = TSDB_ORDER_ASC; } - aAggs[pCtx[k].functionId].xFunction(&pCtx[k]); + pCtx[k].startTs = pQueryAttr->window.skey; + + if (pCtx[k].functionId < 0) { + // load the script and exec + SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo; + doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL); + } else { + aAggs[pCtx[k].functionId].xFunction(&pCtx[k]); + } } } @@ -1953,7 +2055,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf case OP_GlobalAggregate: { pRuntimeEnv->proot = createGlobalAggregateOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr3, - pQueryAttr->numOfExpr3, merger); + pQueryAttr->numOfExpr3, merger, pQueryAttr->pUdfInfo); break; } @@ -2024,6 +2126,8 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { tfree(pRuntimeEnv->sasArray); } + destroyUdfInfo(pRuntimeEnv->pUdfInfo); + destroyResultBuf(pRuntimeEnv->pResultBuf); doFreeQueryHandle(pRuntimeEnv); @@ -2234,7 +2338,7 @@ static bool onlyFirstQuery(SQueryAttr *pQueryAttr) { return onlyOneQueryType(pQu static bool onlyLastQuery(SQueryAttr *pQueryAttr) { return onlyOneQueryType(pQueryAttr, TSDB_FUNC_LAST, TSDB_FUNC_LAST_DST); } -static bool notContainSessionOrStateWindow(SQueryAttr *pQueryAttr) { return !(pQueryAttr->sw.gap > 0 || pQueryAttr->stateWindow); } +static bool notContainSessionOrStateWindow(SQueryAttr *pQueryAttr) { return !(pQueryAttr->sw.gap > 0 || pQueryAttr->stateWindow); } static int32_t updateBlockLoadStatus(SQueryAttr *pQuery, int32_t status) { bool hasFirstLastFunc = false; @@ -2444,14 +2548,14 @@ static bool doFilterByBlockStatistics(SQueryRuntimeEnv* pRuntimeEnv, SDataStatis } SDataStatis* pDataBlockst = &pDataStatis[index]; - + if (pFilterInfo->info.type == TSDB_DATA_TYPE_FLOAT) { float minval = (float)(*(double *)(&pDataBlockst->min)); float maxval = (float)(*(double *)(&pDataBlockst->max)); - + for (int32_t i = 0; i < pFilterInfo->numOfFilters; ++i) { if (pFilterInfo->pFilters[i].filterInfo.lowerRelOptr == TSDB_RELATION_IN) { - continue; + continue; } ret &= pFilterInfo->pFilters[i].fp(&pFilterInfo->pFilters[i], (char *)&minval, (char *)&maxval, TSDB_DATA_TYPE_FLOAT); if (ret == false) { @@ -2461,9 +2565,9 @@ static bool doFilterByBlockStatistics(SQueryRuntimeEnv* pRuntimeEnv, SDataStatis } else { for (int32_t i = 0; i < pFilterInfo->numOfFilters; ++i) { if (pFilterInfo->pFilters[i].filterInfo.lowerRelOptr == TSDB_RELATION_IN) { - continue; + continue; } - ret &= pFilterInfo->pFilters[i].fp(&pFilterInfo->pFilters[i], (char *)&pDataBlockst->min, (char *)&pDataBlockst->max, pFilterInfo->info.type); + ret &= pFilterInfo->pFilters[i].fp(&pFilterInfo->pFilters[i], (char *)&pDataBlockst->min, (char *)&pDataBlockst->max, pFilterInfo->info.type); if (ret == false) { return false; } @@ -2703,9 +2807,14 @@ static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSData int32_t colId = pTableScanInfo->pExpr[i].base.colInfo.colId; // group by + first/last should not apply the first/last block filter - status |= aAggs[functionId].dataReqFunc(&pTableScanInfo->pCtx[i], &pBlock->info.window, colId); - if ((status & BLK_DATA_ALL_NEEDED) == BLK_DATA_ALL_NEEDED) { + if (functionId < 0) { + status |= BLK_DATA_ALL_NEEDED; return status; + } else { + status |= aAggs[functionId].dataReqFunc(&pTableScanInfo->pCtx[i], &pBlock->info.window, colId); + if ((status & BLK_DATA_ALL_NEEDED) == BLK_DATA_ALL_NEEDED) { + return status; + } } } @@ -3010,8 +3119,8 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt doSetTagValueInParam(pTable, pLocalExprInfo->base.colInfo.colId, &pCtx[idx].tag, pLocalExprInfo->base.resType, pLocalExprInfo->base.resBytes); - if (IS_NUMERIC_TYPE(pLocalExprInfo->base.resType) - || pLocalExprInfo->base.resType == TSDB_DATA_TYPE_BOOL + if (IS_NUMERIC_TYPE(pLocalExprInfo->base.resType) + || pLocalExprInfo->base.resType == TSDB_DATA_TYPE_BOOL || pLocalExprInfo->base.resType == TSDB_DATA_TYPE_TIMESTAMP) { memcpy(pRuntimeEnv->tagVal + offset, &pCtx[idx].tag.i64, pLocalExprInfo->base.resBytes); } else { @@ -3299,6 +3408,21 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf } } +void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity) { + SSDataBlock* pDataBlock = pBInfo->pRes; + + for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { + SColumnInfoData *pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); + + int32_t functionId = pBInfo->pCtx[i].functionId; + if (functionId < 0) { + memset(pBInfo->pCtx[i].pOutput, 0, pColInfo->info.bytes * (*bufCapacity)); + } + } +} + + + void initCtxOutputBuffer(SQLFunctionCtx* pCtx, int32_t size) { for (int32_t j = 0; j < size; ++j) { SResultRowCellInfo* pResInfo = GET_RES_INFO(&pCtx[j]); @@ -3306,7 +3430,11 @@ void initCtxOutputBuffer(SQLFunctionCtx* pCtx, int32_t size) { continue; } - aAggs[pCtx[j].functionId].init(&pCtx[j]); + if (pCtx[j].functionId < 0) { // todo udf initialization + continue; + } else { + aAggs[pCtx[j].functionId].init(&pCtx[j], pCtx[j].resultInfo); + } } } @@ -3361,9 +3489,15 @@ void finalizeQueryResult(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SResult setResultOutputBuf(pRuntimeEnv, buf, pCtx, numOfOutput, rowCellInfoOffset); for (int32_t j = 0; j < numOfOutput; ++j) { - aAggs[pCtx[j].functionId].xFinalize(&pCtx[j]); + pCtx[j].startTs = buf->win.skey; + if (pCtx[j].functionId < 0) { + doInvokeUdf(pRuntimeEnv->pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_FINALIZE); + } else { + aAggs[pCtx[j].functionId].xFinalize(&pCtx[j]); + } } + /* * set the number of output results for group by normal columns, the number of output rows usually is 1 except * the top and bottom query @@ -3373,7 +3507,11 @@ void finalizeQueryResult(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SResult } else { for (int32_t j = 0; j < numOfOutput; ++j) { - aAggs[pCtx[j].functionId].xFinalize(&pCtx[j]); + if (pCtx[j].functionId < 0) { + doInvokeUdf(pRuntimeEnv->pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_FINALIZE); + } else { + aAggs[pCtx[j].functionId].xFinalize(&pCtx[j]); + } } } } @@ -3445,7 +3583,7 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe // Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group tFilePage* bufPage = getResBufPage(pRuntimeEnv->pResultBuf, pResult->pageId); - int16_t offset = 0; + int32_t offset = 0; for (int32_t i = 0; i < numOfOutput; ++i) { pCtx[i].resultInfo = getResultCell(pResult, i, rowCellInfoOffset); @@ -3459,12 +3597,16 @@ 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 || functionId == TSDB_FUNC_DERIVATIVE) { + if (functionId < 0) { + continue; + } + + if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { pCtx[i].ptsOutputBuf = pCtx[0].pOutput; } if (!pResInfo->initialized) { - aAggs[functionId].init(&pCtx[i]); + aAggs[functionId].init(&pCtx[i], pResInfo); } } } @@ -3755,7 +3897,7 @@ static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo* tFilePage *page = getResBufPage(pRuntimeEnv->pResultBuf, pRow->pageId); - int16_t offset = 0; + int32_t offset = 0; for (int32_t j = 0; j < pBlock->info.numOfCols; ++j) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, j); int32_t bytes = pColInfoData->info.bytes; @@ -3951,7 +4093,7 @@ void calculateOperatorProfResults(SQInfo* pQInfo) { qDebug("QInfo:0x%"PRIx64" operator prof results hash is null", pQInfo->qId); return; } - + SArray* opStack = taosArrayInit(32, sizeof(SOperatorStackItem)); if (opStack == NULL) { return; @@ -4803,7 +4945,7 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf pTableScanInfo->pResultRowInfo = &pInfo->binfo.resultRowInfo; pTableScanInfo->rowCellInfoOffset = pInfo->binfo.rowCellInfoOffset; } else if (pDownstream->operatorType == OP_StateWindow) { - SStateWindowOperatorInfo* pInfo = pDownstream->info; + SStateWindowOperatorInfo* pInfo = pDownstream->info; pTableScanInfo->pCtx = pInfo->binfo.pCtx; pTableScanInfo->pResultRowInfo = &pInfo->binfo.resultRowInfo; @@ -4923,7 +5065,7 @@ static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) { } SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, - SExprInfo* pExpr, int32_t numOfOutput, void* param) { + SExprInfo* pExpr, int32_t numOfOutput, void* param, SArray* pUdfInfo) { SMultiwayMergeInfo* pInfo = calloc(1, sizeof(SMultiwayMergeInfo)); pInfo->resultRowFactor = @@ -4933,6 +5075,7 @@ SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, pInfo->pMerge = param; pInfo->bufCapacity = 4096; + pInfo->udfInfo = pUdfInfo; pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pInfo->bufCapacity * pInfo->resultRowFactor); pInfo->binfo.pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); @@ -5462,7 +5605,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI TSKEY* tsList = (TSKEY*)pTsColInfoData->pData; if (IS_REPEAT_SCAN(pRuntimeEnv) && !pInfo->reptScan) { pInfo->reptScan = true; - tfree(pInfo->prevData); + tfree(pInfo->prevData); } pInfo->numOfRows = 0; @@ -5472,17 +5615,17 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI continue; } if (pInfo->prevData == NULL) { - pInfo->prevData = malloc(bytes); + pInfo->prevData = malloc(bytes); memcpy(pInfo->prevData, val, bytes); pInfo->numOfRows = 1; pInfo->curWindow.skey = tsList[j]; pInfo->curWindow.ekey = tsList[j]; - pInfo->start = j; - + pInfo->start = j; + } else if (memcmp(pInfo->prevData, val, bytes) == 0) { pInfo->curWindow.ekey = tsList[j]; pInfo->numOfRows += 1; - //pInfo->start = j; + //pInfo->start = j; if (j == 0 && pInfo->start != 0) { pInfo->numOfRows = 1; pInfo->start = 0; @@ -5504,7 +5647,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI memcpy(pInfo->prevData, val, bytes); pInfo->numOfRows = 1; pInfo->start = j; - + } } @@ -5557,10 +5700,10 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) { setInputDataBlock(pOperator, pBInfo->pCtx, pBlock, pQueryAttr->order.order); if (pWindowInfo->colIndex == -1) { pWindowInfo->colIndex = getGroupbyColumnIndex(pRuntimeEnv->pQueryAttr->pGroupbyExpr, pBlock); - } + } doStateWindowAggImpl(pOperator, pWindowInfo, pBlock); } - + // restore the value pQueryAttr->order.order = order; pQueryAttr->window = win; @@ -5578,7 +5721,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) { } return pBInfo->pRes->info.rows == 0? NULL:pBInfo->pRes; -} +} static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) { SOperatorInfo* pOperator = (SOperatorInfo*) param; if (pOperator->status == OP_EXEC_DONE) { @@ -5693,7 +5836,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) { sortGroupResByOrderList(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes); } toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes); - + if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -6088,8 +6231,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpe pOperator->cleanup = destroyStateWindowOperatorInfo; appendUpstream(pOperator, upstream); - return pOperator; - + return pOperator; + } SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SSWindowOperatorInfo* pInfo = calloc(1, sizeof(SSWindowOperatorInfo)); @@ -6099,7 +6242,7 @@ SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato initResultRowInfo(&pInfo->binfo.resultRowInfo, 8, TSDB_DATA_TYPE_INT); pInfo->prevTs = INT64_MIN; - pInfo->reptScan = false; + pInfo->reptScan = false; SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); pOperator->name = "SessionWindowAggOperator"; @@ -6690,6 +6833,9 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pQueryMsg->sw.primaryColId = htonl(pQueryMsg->sw.primaryColId); pQueryMsg->tableScanOperator = htonl(pQueryMsg->tableScanOperator); pQueryMsg->numOfOperator = htonl(pQueryMsg->numOfOperator); + pQueryMsg->udfContentOffset = htonl(pQueryMsg->udfContentOffset); + pQueryMsg->udfContentLen = htonl(pQueryMsg->udfContentLen); + pQueryMsg->udfNum = htonl(pQueryMsg->udfNum); // query msg safety check if (!validateQueryMsg(pQueryMsg)) { @@ -6933,6 +7079,33 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pMsg += sizeof(int32_t); } + if (pQueryMsg->udfContentLen > 0) { + param->pUdfInfo = calloc(1, sizeof(SUdfInfo)); + param->pUdfInfo->contLen = pQueryMsg->udfContentLen; + + pMsg = (char*)pQueryMsg + pQueryMsg->udfContentOffset; + param->pUdfInfo->resType = *(int8_t*) pMsg; + pMsg += sizeof(int8_t); + + param->pUdfInfo->resBytes = htons(*(int16_t*)pMsg); + pMsg += sizeof(int16_t); + + tstr* name = (tstr*)(pMsg); + param->pUdfInfo->name = strndup(name->data, name->len); + + pMsg += varDataTLen(name); + param->pUdfInfo->funcType = htonl(*(int32_t*)pMsg); + pMsg += sizeof(int32_t); + + param->pUdfInfo->bufSize = htonl(*(int32_t*)pMsg); + pMsg += sizeof(int32_t); + + param->pUdfInfo->content = malloc(pQueryMsg->udfContentLen); + memcpy(param->pUdfInfo->content, pMsg, pQueryMsg->udfContentLen); + + pMsg += pQueryMsg->udfContentLen; + } + param->sql = strndup(pMsg, pQueryMsg->sqlstrLen); SQueriedTableInfo info = { .numOfTags = pQueryMsg->numOfTags, .numOfCols = pQueryMsg->numOfCols, .colList = pQueryMsg->tableCols}; @@ -7023,7 +7196,7 @@ static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SCol } else { SColumnInfo* pCol = &pTableInfo->colList[j]; int32_t ret = getResultDataInfo(pCol->type, pCol->bytes, functId, (int32_t)pExprs[i].base.param[0].i64, - &pExprs[i].base.resType, &pExprs[i].base.resBytes, &pExprs[i].base.interBytes, tagLen, superTable); + &pExprs[i].base.resType, &pExprs[i].base.resBytes, &pExprs[i].base.interBytes, tagLen, superTable, NULL); assert(ret == TSDB_CODE_SUCCESS); } } @@ -7032,12 +7205,138 @@ static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SCol return TSDB_CODE_SUCCESS; } +void destroyUdfInfo(SUdfInfo* pUdfInfo) { + if (pUdfInfo == NULL) { + return; + } + + if (pUdfInfo->funcs[TSDB_UDF_FUNC_DESTROY]) { + if (pUdfInfo->isScript) { + (*(scriptDestroyFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_DESTROY])(pUdfInfo->pScriptCtx); + tfree(pUdfInfo->content); + }else{ + (*(udfDestroyFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_DESTROY])(&pUdfInfo->init); + } + } + + tfree(pUdfInfo->name); + + if (pUdfInfo->path) { + unlink(pUdfInfo->path); + } + + tfree(pUdfInfo->path); + tfree(pUdfInfo->content); + taosCloseDll(pUdfInfo->handle); + tfree(pUdfInfo); +} + +static char* getUdfFuncName(char* name, int type) { + char* funcname = calloc(1, TSDB_FUNCTIONS_NAME_MAX_LENGTH + 10); + + switch (type) { + case TSDB_UDF_FUNC_NORMAL: + strcpy(funcname, name); + break; + case TSDB_UDF_FUNC_INIT: + sprintf(funcname, "%s_init", name); + break; + case TSDB_UDF_FUNC_FINALIZE: + sprintf(funcname, "%s_finalize", name); + break; + case TSDB_UDF_FUNC_MERGE: + sprintf(funcname, "%s_merge", name); + break; + case TSDB_UDF_FUNC_DESTROY: + sprintf(funcname, "%s_destroy", name); + break; + default: + assert(0); + break; + } + + return funcname; +} + +int32_t initUdfInfo(SUdfInfo* pUdfInfo) { + if (pUdfInfo == NULL) { + return TSDB_CODE_SUCCESS; + } + //qError("script len: %d", pUdfInfo->contLen); + if (isValidScript(pUdfInfo->content, pUdfInfo->contLen)) { + pUdfInfo->isScript = 1; + pUdfInfo->pScriptCtx = createScriptCtx(pUdfInfo->content, pUdfInfo->resType, pUdfInfo->resBytes); + if (pUdfInfo->pScriptCtx == NULL) { + return TSDB_CODE_QRY_SYS_ERROR; + } + tfree(pUdfInfo->content); + + pUdfInfo->funcs[TSDB_UDF_FUNC_INIT] = taosLoadScriptInit; + if (pUdfInfo->funcs[TSDB_UDF_FUNC_INIT] == NULL + || (*(scriptInitFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_INIT])(pUdfInfo->pScriptCtx) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_QRY_SYS_ERROR; + } + + pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL] = taosLoadScriptNormal; + + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE] = taosLoadScriptFinalize; + pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE] = taosLoadScriptMerge; + } + pUdfInfo->funcs[TSDB_UDF_FUNC_DESTROY] = taosLoadScriptDestroy; + + } else { + char path[PATH_MAX] = {0}; + taosGetTmpfilePath("script", path); + + FILE* file = fopen(path, "w+"); + + // TODO check for failure of flush to disk + /*size_t t = */ fwrite(pUdfInfo->content, pUdfInfo->contLen, 1, file); + fclose(file); + tfree(pUdfInfo->content); + + pUdfInfo->path = strdup(path); + + pUdfInfo->handle = taosLoadDll(path); + + if (NULL == pUdfInfo->handle) { + return TSDB_CODE_QRY_SYS_ERROR; + } + + pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(pUdfInfo->name, TSDB_UDF_FUNC_NORMAL)); + if (NULL == pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL]) { + return TSDB_CODE_QRY_SYS_ERROR; + } + + pUdfInfo->funcs[TSDB_UDF_FUNC_INIT] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(pUdfInfo->name, TSDB_UDF_FUNC_INIT)); + + if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { + pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(pUdfInfo->name, TSDB_UDF_FUNC_FINALIZE)); + pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(pUdfInfo->name, TSDB_UDF_FUNC_MERGE)); + } + + pUdfInfo->funcs[TSDB_UDF_FUNC_DESTROY] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(pUdfInfo->name, TSDB_UDF_FUNC_DESTROY)); + + if (pUdfInfo->funcs[TSDB_UDF_FUNC_INIT]) { + return (*(udfInitFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_INIT])(&pUdfInfo->init); + } + } + + return TSDB_CODE_SUCCESS; +} + // TODO tag length should be passed from client, refactor int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExprInfo** pExprInfo, - SSqlExpr** pExprMsg, SColumnInfo* pTagCols, int32_t queryType, void* pMsg) { + SSqlExpr** pExprMsg, SColumnInfo* pTagCols, int32_t queryType, void* pMsg, SUdfInfo* pUdfInfo) { *pExprInfo = NULL; int32_t code = TSDB_CODE_SUCCESS; + code = initUdfInfo(pUdfInfo); + if (code) { + return code; + } + SExprInfo *pExprs = (SExprInfo *)calloc(numOfOutput, sizeof(SExprInfo)); if (pExprs == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; @@ -7126,7 +7425,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp // todo remove it if (getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].base.resType, &pExprs[i].base.resBytes, - &pExprs[i].base.interBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) { + &pExprs[i].base.interBytes, 0, isSuperTable, pUdfInfo) != TSDB_CODE_SUCCESS) { tfree(pExprs); return TSDB_CODE_QRY_INVALID_MSG; } @@ -7147,7 +7446,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp // todo refactor int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg* pQueryMsg, int32_t numOfOutput, SExprInfo** pExprInfo, - SSqlExpr** pExpr, SExprInfo* prevExpr) { + SSqlExpr** pExpr, SExprInfo* prevExpr, SUdfInfo *pUdfInfo) { *pExprInfo = NULL; int32_t code = TSDB_CODE_SUCCESS; @@ -7192,7 +7491,7 @@ int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg* pQueryMsg, int32_t nu int32_t param = (int32_t)pExprs[i].base.param[0].i64; if (getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].base.resType, &pExprs[i].base.resBytes, - &pExprs[i].base.interBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) { + &pExprs[i].base.interBytes, 0, isSuperTable, pUdfInfo) != TSDB_CODE_SUCCESS) { tfree(pExprs); return TSDB_CODE_QRY_INVALID_MSG; } @@ -7378,7 +7677,7 @@ FORCE_INLINE bool checkQIdEqual(void *qHandle, uint64_t qId) { SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, SExprInfo* pExprs, SExprInfo* pSecExprs, STableGroupInfo* pTableGroupInfo, SColumnInfo* pTagCols, int32_t vgId, - char* sql, uint64_t qId) { + char* sql, uint64_t qId, SUdfInfo* pUdfInfo) { int16_t numOfCols = pQueryMsg->numOfCols; int16_t numOfOutput = pQueryMsg->numOfOutput; @@ -7389,6 +7688,8 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S pQInfo->qId = qId; + pQInfo->runtimeEnv.pUdfInfo = pUdfInfo; + // to make sure third party won't overwrite this structure pQInfo->signature = pQInfo; SQueryAttr* pQueryAttr = &pQInfo->query; @@ -7412,6 +7713,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S pQueryAttr->prjInfo.vgroupLimit = pQueryMsg->vgroupLimit; pQueryAttr->prjInfo.ts = (pQueryMsg->order == TSDB_ORDER_ASC)? INT64_MIN:INT64_MAX; pQueryAttr->sw = pQueryMsg->sw; + pQueryAttr->vgId = vgId; pQueryAttr->stableQuery = pQueryMsg->stableQuery; pQueryAttr->topBotQuery = pQueryMsg->topBotQuery; @@ -7444,7 +7746,6 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S } } - // calculate the result row size for (int16_t col = 0; col < numOfOutput; ++col) { assert(pExprs[col].base.resBytes > 0); pQueryAttr->resultRowSize += pExprs[col].base.resBytes; @@ -7465,6 +7766,20 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S goto _cleanup; } + if (pSecExprs != NULL) { + int32_t resultRowSize = 0; + + // calculate the result row size + for (int16_t col = 0; col < pQueryAttr->numOfExpr2; ++col) { + assert(pSecExprs[col].base.resBytes > 0); + resultRowSize += pSecExprs[col].base.resBytes; + } + + if (resultRowSize > pQueryAttr->resultRowSize) { + pQueryAttr->resultRowSize = resultRowSize; + } + } + if (pQueryAttr->fillType != TSDB_FILL_NONE) { pQueryAttr->fillVal = malloc(sizeof(int64_t) * pQueryAttr->numOfOutput); if (pQueryAttr->fillVal == NULL) { @@ -7610,8 +7925,8 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* SArray* prevResult = NULL; if (prevResultLen > 0) { - prevResult = interResFromBinary(param->prevResult, prevResultLen); - + prevResult = interResFromBinary(param->prevResult, prevResultLen); + pRuntimeEnv->prevResult = prevResult; } diff --git a/src/query/src/qScript.c b/src/query/src/qScript.c new file mode 100644 index 0000000000000000000000000000000000000000..261164a84c0b347adc36e3e2abaf2113d5564436 --- /dev/null +++ b/src/query/src/qScript.c @@ -0,0 +1,443 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "os.h" +#include "qScript.h" +#include "ttype.h" +#include "tstrbuild.h" +#include "queryLog.h" +#include "ttokendef.h" + +static ScriptEnvPool *pool = NULL; + +static ScriptEnv* getScriptEnvFromPool(); +static void addScriptEnvToPool(ScriptEnv *pEnv); + +static lua_State* createLuaEnv(); +static void destroyLuaEnv(lua_State *state); + +static void destroyScriptEnv(ScriptEnv *pEnv); + +static void luaValueToTaosType(lua_State *lua, char *interBuf, int32_t *numOfOutput, int16_t oType, int16_t oBytes); +static void taosValueToLuaType(lua_State *lua, int32_t type, char *val); + +static bool hasBaseFuncDefinedInScript(lua_State *lua, const char *funcPrefix, int32_t len); + +static int userlib_exampleFunc(lua_State *lua) { + double op1 = luaL_checknumber(lua,1); + double op2 = luaL_checknumber(lua,2); + lua_pushnumber(lua, op1 * op2); + return 1; +} +void luaRegisterLibFunc(lua_State *lua) { + lua_register(lua, "exampleFunc", userlib_exampleFunc); +} + +void luaLoadLib(lua_State *lua, const char *libname, lua_CFunction luafunc) { + lua_pushcfunction(lua, luafunc); + lua_pushstring(lua, libname); + lua_call(lua, 1, 0); +} + +LUALIB_API int (luaopen_cjson) (lua_State *L); +LUALIB_API int (luaopen_struct) (lua_State *L); +LUALIB_API int (luaopen_cmsgpack) (lua_State *L); +LUALIB_API int (luaopen_bit) (lua_State *L); + + +static void luaLoadLibraries(lua_State *lua) { + luaLoadLib(lua, "", luaopen_base); + luaLoadLib(lua, LUA_TABLIBNAME, luaopen_table); + luaLoadLib(lua, LUA_STRLIBNAME, luaopen_string); + luaLoadLib(lua, LUA_MATHLIBNAME, luaopen_math); + luaLoadLib(lua, LUA_DBLIBNAME, luaopen_debug); +} +static void luaRemoveUnsupportedFunctions(lua_State *lua) { + lua_pushnil(lua); + lua_setglobal(lua,"loadfile"); + lua_pushnil(lua); + lua_setglobal(lua,"dofile"); +} +void taosValueToLuaType(lua_State *lua, int32_t type, char *val) { + //TODO(dengyihao): handle more data type + if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { + int64_t v; + GET_TYPED_DATA(v, int64_t, type, val); + lua_pushnumber(lua, (lua_Number)v); + } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { + uint64_t v; + GET_TYPED_DATA(v, uint64_t, type, val); + lua_pushnumber(lua,(lua_Number)v); + } else if (IS_FLOAT_TYPE(type)) { + double v; + GET_TYPED_DATA(v, double, type, val); + lua_pushnumber(lua,v); + } else if (type == TSDB_DATA_TYPE_BINARY) { + lua_pushlstring(lua, val, varDataLen(val)); + } else if (type == TSDB_DATA_TYPE_NCHAR) { + } +} +int taosLoadScriptInit(void* pInit) { + ScriptCtx *pCtx = pInit; + char funcName[MAX_FUNC_NAME] = {0}; + sprintf(funcName, "%s_init", pCtx->funcName); + + lua_State* lua = pCtx->pEnv->lua_state; + lua_getglobal(lua, funcName); + if (lua_pcall(lua, 0, -1, 0)) { + lua_pop(lua, -1); + } + lua_setglobal(lua, "global"); + return 0; +} +void taosLoadScriptNormal(void *pInit, char *pInput, int16_t iType, int16_t iBytes, int32_t numOfRows, + int64_t *ptsList, int64_t key, char* pOutput, char *ptsOutput, int32_t *numOfOutput, int16_t oType, int16_t oBytes) { + ScriptCtx* pCtx = pInit; + char funcName[MAX_FUNC_NAME] = {0}; + sprintf(funcName, "%s_add", pCtx->funcName); + + lua_State* lua = pCtx->pEnv->lua_state; + lua_getglobal(lua, funcName); + + // first param of script; + lua_newtable(lua); + int32_t offset = 0; + for (int32_t i = 0; i < numOfRows; i++) { + taosValueToLuaType(lua, iType, pInput + offset); + lua_rawseti(lua, -2, i+1); + offset += iBytes; + } + int isGlobalState = false; + lua_getglobal(lua, "global"); + if (lua_istable(lua, -1)) { + isGlobalState = true; + } + lua_pushnumber(lua, (lua_Number)key); + // do call lua script + if (lua_pcall(lua, 3, 1, 0) != 0) { + qError("SCRIPT ERROR: %s", lua_tostring(lua, -1)); + lua_pop(lua, -1); + return; + } + int tNumOfOutput = 0; + if (isGlobalState == false) { + luaValueToTaosType(lua, pOutput, &tNumOfOutput, oType, oBytes); + } else { + lua_setglobal(lua, "global"); + } + *numOfOutput = tNumOfOutput; +} + +void taosLoadScriptMerge(void *pInit, char* data, int32_t numOfRows, char* pOutput, int32_t* numOfOutput) { + ScriptCtx *pCtx = pInit; + char funcName[MAX_FUNC_NAME] = {0}; + sprintf(funcName, "%s_merge", pCtx->funcName); + + lua_State* lua = pCtx->pEnv->lua_state; + lua_getglobal(lua, funcName); + if (!lua_isfunction(lua, -1)) { + qError("SCRIPT ERROR: %s", lua_tostring(lua, -1)); + return; + } + + lua_getglobal(lua, "global"); + if (lua_pcall(lua, 1, 1, 0) != 0) { + qError("SCRIPT ERROR: %s", lua_tostring(lua, -1)); + lua_pop(lua, -1); + return; + } + int tNumOfOutput = 0; + luaValueToTaosType(lua, pOutput, &tNumOfOutput, pCtx->resType, pCtx->resBytes); + *numOfOutput = tNumOfOutput; +} + +//do not support agg now +void taosLoadScriptFinalize(void *pInit,int64_t key, char *pOutput, int32_t* numOfOutput) { + ScriptCtx *pCtx = pInit; + char funcName[MAX_FUNC_NAME] = {0}; + sprintf(funcName, "%s_finalize", pCtx->funcName); + + lua_State* lua = pCtx->pEnv->lua_state; + lua_getglobal(lua, funcName); + if (!lua_isfunction(lua, -1)) { + qError("SCRIPT ERROR: %s", lua_tostring(lua, -1)); + return; + } + + lua_getglobal(lua, "global"); + + lua_pushnumber(lua, (lua_Number)key); + if (lua_pcall(lua, 2, 2, 0) != 0) { + qError("SCRIPT ERROR: %s", lua_tostring(lua, -1)); + lua_pop(lua, -1); + return; + } + lua_setglobal(lua, "global"); + int tNumOfOutput = 0; + luaValueToTaosType(lua, pOutput, &tNumOfOutput, pCtx->resType, pCtx->resBytes); + *numOfOutput = tNumOfOutput; +} + +void taosLoadScriptDestroy(void *pInit) { + destroyScriptCtx(pInit); +} + +ScriptCtx* createScriptCtx(char *script, int8_t resType, int16_t resBytes) { + ScriptCtx *pCtx = (ScriptCtx *)calloc(1, sizeof(ScriptCtx)); + pCtx->state = SCRIPT_STATE_INIT; + pCtx->pEnv = getScriptEnvFromPool(); // + pCtx->resType = resType; + pCtx->resBytes = resBytes; + + if (pCtx->pEnv == NULL) { + destroyScriptCtx(pCtx); + return NULL; + } + + lua_State *lua = pCtx->pEnv->lua_state; + if (luaL_dostring(lua, script)) { + lua_pop(lua, 1); + qError("dynamic load script failed"); + destroyScriptCtx(pCtx); + return NULL; + } + lua_getglobal(lua, USER_FUNC_NAME); + const char *name = lua_tostring(lua, -1); + if (name == NULL) { + lua_pop(lua, 1); + qError("SCRIPT ERROR: invalid script"); + destroyScriptCtx(pCtx); + return NULL; + } + memcpy(pCtx->funcName, name, strlen(name)); + lua_pop(lua, 1); + + return pCtx; +} +void destroyScriptCtx(void *pCtx) { + if (pCtx == NULL) return; + addScriptEnvToPool(((ScriptCtx *)pCtx)->pEnv); + free(pCtx); +} + +void luaValueToTaosType(lua_State *lua, char *interBuf, int32_t *numOfOutput, int16_t oType, int16_t oBytes) { + int t = lua_type(lua,-1); + int32_t sz = 0; + switch (t) { + case LUA_TSTRING: + //TODO(yihaodeng): handle str type + { + const char *v = lua_tostring(lua, -1); + memcpy(interBuf, v, strlen(v)); + sz = 1; + } + break; + case LUA_TBOOLEAN: + { + double v = lua_tonumber(lua, -1); + memcpy(interBuf, (char *)&v, oBytes); + sz = 1; + } + break; + case LUA_TNUMBER: + { + if (oType == TSDB_DATA_TYPE_FLOAT) { + float v = (float)lua_tonumber(lua, -1); + memcpy(interBuf, (char *)&v, oBytes); + sz = 1; + } else if (oType == TSDB_DATA_TYPE_DOUBLE) { + double v = (double)lua_tonumber(lua, -1); + memcpy(interBuf, (char *)&v, oBytes); + sz = 1; + } else if (oType == TSDB_DATA_TYPE_BIGINT) { + int64_t v = (int64_t)lua_tonumber(lua, -1); + memcpy(interBuf, (char *)&v, oBytes); + sz = 1; + } else if (oType <= TSDB_DATA_TYPE_INT) { + int32_t v = (int32_t)lua_tonumber(lua, -1); + memcpy(interBuf, (char *)&v, oBytes); + sz = 1; + } + } + break; + case LUA_TTABLE: + { + lua_pushnil(lua); + int32_t offset = 0; + while(lua_next(lua, -2)) { + int32_t v = (int32_t)lua_tonumber(lua, -1); + memcpy(interBuf + offset, (char *)&v, oBytes); + offset += oBytes; + lua_pop(lua, 1); + sz += 1; + } + } + break; + default: + setNull(interBuf, oType, oBytes); + sz = 1; + break; + } + lua_pop(lua,1); // pop ret value from script + *numOfOutput = sz; +} + + +/* +*Initialize the scripting environment. +*/ +lua_State* createLuaEnv() { + lua_State *lua = lua_open(); + luaLoadLibraries(lua); + luaRemoveUnsupportedFunctions(lua); + + // register func in external lib + luaRegisterLibFunc(lua); + + { + char *errh_func = "local dbg = debug\n" + "function __taos__err__handler(err)\n" + " local i = dbg.getinfo(2,'nSl')\n" + " if i and i.what == 'C' then\n" + " i = dbg.getinfo(3,'nSl')\n" + " end\n" + " if i then\n" + " return i.source .. ':' .. i.currentline .. ': ' .. err\n" + " else\n" + " return err\n" + " end\n" + "end\n"; + luaL_loadbuffer(lua,errh_func,strlen(errh_func),"@err_handler_def"); + lua_pcall(lua,0,0,0); + } + + return lua; +} + +void destroyLuaEnv(lua_State *lua) { + lua_close(lua); +} + +int32_t scriptEnvPoolInit() { + const int size = 10; // configure or not + pool = malloc(sizeof(ScriptEnvPool)); + pthread_mutex_init(&pool->mutex, NULL); + + pool->scriptEnvs = tdListNew(sizeof(ScriptEnv *)); + for (int i = 0; i < size; i++) { + ScriptEnv *env = malloc(sizeof(ScriptEnv)); + env->funcId = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);; + env->lua_state = createLuaEnv(); + tdListAppend(pool->scriptEnvs, (void *)(&env)); + } + pool->mSize = size; + pool->cSize = size; + return 0; +} + +void scriptEnvPoolCleanup() { + if (pool == NULL) return; + + SListNode *pNode = NULL; + while ((pNode = tdListPopHead(pool->scriptEnvs)) != NULL) { + ScriptEnv *pEnv = NULL; + tdListNodeGetData(pool->scriptEnvs, pNode, (void *)(&pEnv)); + destroyScriptEnv(pEnv); + listNodeFree(pNode); + } + tdListFree(pool->scriptEnvs); + pthread_mutex_destroy(&pool->mutex); + free(pool); +} + +void destroyScriptEnv(ScriptEnv *pEnv) { + destroyLuaEnv(pEnv->lua_state); + taosHashCleanup(pEnv->funcId); + free(pEnv); +} + +ScriptEnv* getScriptEnvFromPool() { + ScriptEnv *pEnv = NULL; + + pthread_mutex_lock(&pool->mutex); + if (pool->cSize <= 0) { + pthread_mutex_unlock(&pool->mutex); + return NULL; + } + SListNode *pNode = tdListPopHead(pool->scriptEnvs); + tdListNodeGetData(pool->scriptEnvs, pNode, (void *)(&pEnv)); + listNodeFree(pNode); + + pool->cSize--; + pthread_mutex_unlock(&pool->mutex); + return pEnv; +} + +void addScriptEnvToPool(ScriptEnv *pEnv) { + if (pEnv == NULL) { + return; + } + pthread_mutex_lock(&pool->mutex); + lua_settop(pEnv->lua_state, 0); + tdListAppend(pool->scriptEnvs, (void *)(&pEnv)); + pool->cSize++; + pthread_mutex_unlock(&pool->mutex); +} + +bool hasBaseFuncDefinedInScript(lua_State *lua, const char *funcPrefix, int32_t len) { + bool ret = true; + char funcName[MAX_FUNC_NAME]; + memcpy(funcName, funcPrefix, len); + + const char *base[] = {"_init", "_add"}; + for (int i = 0; (i < sizeof(base)/sizeof(base[0])) && (ret == true); i++) { + memcpy(funcName + len, base[i], strlen(base[i])); + memset(funcName + len + strlen(base[i]), 0, MAX_FUNC_NAME - len - strlen(base[i])); + lua_getglobal(lua, funcName); + ret = lua_isfunction(lua, -1); // exsit function or not + lua_pop(lua, 1); + } + return ret; +} + +bool isValidScript(char *script, int32_t len) { + ScriptEnv *pEnv = getScriptEnvFromPool(); // + if (pEnv == NULL) { + return false; + } + lua_State *lua = pEnv->lua_state; + if (len < strlen(script)) { + script[len] = 0; + } + if (luaL_dostring(lua, script)) { + lua_pop(lua, 1); + addScriptEnvToPool(pEnv); + qError("error at %s and %d", script, (int)(strlen(script))); + return false; + } + lua_getglobal(lua, USER_FUNC_NAME); + const char *name = lua_tostring(lua, -1); + if (name == NULL || strlen(name) >= USER_FUNC_NAME_LIMIT) { + lua_pop(lua, 1); + addScriptEnvToPool(pEnv); + qError("error at %s name: %s, len = %d", script, name, (int)(strlen(name))); + return false; + } + bool ret = hasBaseFuncDefinedInScript(lua, name, (int32_t)strlen(name)); + lua_pop(lua, 1); // pop + addScriptEnvToPool(pEnv); + return ret; +} + diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index 4d23a9685c36853250aa21e2378cb01584798876..874ec7b692489373e297dea04ed69915e17024a8 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -28,6 +28,7 @@ SSqlInfo qSqlParse(const char *pStr) { SSqlInfo sqlInfo = {0}; sqlInfo.valid = true; + sqlInfo.funcs = taosArrayInit(4, sizeof(SStrToken)); int32_t i = 0; while (1) { @@ -120,6 +121,19 @@ void tSqlExprListDestroy(SArray *pList) { taosArrayDestroyEx(pList, freeExprElem); } + +SArray *tStrTokenAppend(SArray *pList, SStrToken *pToken) { + if (pList == NULL) { + pList = taosArrayInit(4, sizeof(tVariantListItem)); + } + + if (pToken) { + taosArrayPush(pList, pToken); + } + + return pList; +} + tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) { tSqlExpr *pSqlExpr = calloc(1, sizeof(tSqlExpr)); @@ -146,7 +160,8 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) { pSqlExpr->type = SQL_NODE_VALUE; pSqlExpr->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP; } else if (optrType == TK_VARIABLE) { - // use nanosecond by default TODO set value after getting database precision + // use nanosecond by default + // TODO set value after getting database precision int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64, TSDB_TIME_PRECISION_NANO); if (ret != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR; @@ -922,8 +937,8 @@ void* destroyCreateTableSql(SCreateTableSql* pCreate) { } void SqlInfoDestroy(SSqlInfo *pInfo) { - if (pInfo == NULL) return; - + if (pInfo == NULL) return;; + taosArrayDestroy(pInfo->funcs); if (pInfo->type == TSDB_SQL_SELECT) { destroyAllSqlNode(pInfo->list); } else if (pInfo->type == TSDB_SQL_CREATE_TABLE) { @@ -1018,6 +1033,18 @@ void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrTo pInfo->pMiscInfo->tableType = tableType; } +void setDropFuncInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken) { + pInfo->type = type; + + if (pInfo->pMiscInfo == NULL) { + pInfo->pMiscInfo = (SMiscInfo *)calloc(1, sizeof(SMiscInfo)); + pInfo->pMiscInfo->a = taosArrayInit(4, sizeof(SStrToken)); + } + + taosArrayPush(pInfo->pMiscInfo->a, pToken); +} + + void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns) { if (pInfo->pMiscInfo == NULL) { pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo)); @@ -1052,6 +1079,24 @@ void setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SStrToken *pToken, SCreateDb pInfo->pMiscInfo->dbOpt.ignoreExists = pIgExists->n; // sql.y has: ifnotexists(X) ::= IF NOT EXISTS. {X.n = 1;} } +void setCreateFuncInfo(SSqlInfo *pInfo, int32_t type, SStrToken *pName, SStrToken *pPath, TAOS_FIELD *output, SStrToken* bufSize, int32_t funcType) { + pInfo->type = type; + if (pInfo->pMiscInfo == NULL) { + pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo)); + } + + pInfo->pMiscInfo->funcOpt.name = *pName; + pInfo->pMiscInfo->funcOpt.path = *pPath; + pInfo->pMiscInfo->funcOpt.output = *output; + pInfo->pMiscInfo->funcOpt.type = funcType; + if (bufSize->n > 0) { + pInfo->pMiscInfo->funcOpt.bufSize = strtol(bufSize->z, NULL, 10); + } else { + pInfo->pMiscInfo->funcOpt.bufSize = 0; + } +} + + void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SStrToken *pName, SStrToken *pPwd, SCreateAcctInfo *pAcctInfo) { pInfo->type = type; if (pInfo->pMiscInfo == NULL) { diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index 27c877fafa8640ceb4c3b380d32784f188c4a5f8..825b7960defc2547dfd7248bdc15d157e5808b24 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -267,6 +267,10 @@ static void writeDataToDisk(STSBuf* pTSBuf) { if (pBlock->tag.nType == TSDB_DATA_TYPE_BINARY || pBlock->tag.nType == TSDB_DATA_TYPE_NCHAR) { metaLen += (int32_t)fwrite(&pBlock->tag.nLen, 1, sizeof(pBlock->tag.nLen), pTSBuf->f); metaLen += (int32_t)fwrite(pBlock->tag.pz, 1, (size_t)pBlock->tag.nLen, pTSBuf->f); + } else if (pBlock->tag.nType == TSDB_DATA_TYPE_FLOAT) { + metaLen += (int32_t)fwrite(&pBlock->tag.nLen, 1, sizeof(pBlock->tag.nLen), pTSBuf->f); + float tfloat = (float)pBlock->tag.dKey; + metaLen += (int32_t)fwrite(&tfloat, 1, (size_t) pBlock->tag.nLen, pTSBuf->f); } else if (pBlock->tag.nType != TSDB_DATA_TYPE_NULL) { metaLen += (int32_t)fwrite(&pBlock->tag.nLen, 1, sizeof(pBlock->tag.nLen), pTSBuf->f); metaLen += (int32_t)fwrite(&pBlock->tag.i64, 1, (size_t) pBlock->tag.nLen, pTSBuf->f); @@ -351,6 +355,11 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) { sz = fread(pBlock->tag.pz, (size_t)pBlock->tag.nLen, 1, pTSBuf->f); UNUSED(sz); + } else if (pBlock->tag.nType == TSDB_DATA_TYPE_FLOAT) { + float tfloat = 0; + sz = fread(&tfloat, (size_t) pBlock->tag.nLen, 1, pTSBuf->f); + pBlock->tag.dKey = (double)tfloat; + UNUSED(sz); } else if (pBlock->tag.nType != TSDB_DATA_TYPE_NULL) { //TODO check the return value sz = fread(&pBlock->tag.i64, (size_t) pBlock->tag.nLen, 1, pTSBuf->f); UNUSED(sz); diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index d4aa523bf8ed41a4e0e015d6ee0b4bbb67963754..0d140d5ffbca980f72576a39283b4765ed14da68 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -68,7 +68,7 @@ void freeParam(SQueryParam *param) { tfree(param->prevResult); } -int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qinfo_t* pQInfo, uint64_t *qId) { +int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qinfo_t* pQInfo, uint64_t qId) { assert(pQueryMsg != NULL && tsdb != NULL); int32_t code = TSDB_CODE_SUCCESS; @@ -93,12 +93,12 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi SQueriedTableInfo info = { .numOfTags = pQueryMsg->numOfTags, .numOfCols = pQueryMsg->numOfCols, .colList = pQueryMsg->tableCols}; if ((code = createQueryFunc(&info, pQueryMsg->numOfOutput, ¶m.pExprs, param.pExpr, param.pTagColumnInfo, - pQueryMsg->queryType, pQueryMsg)) != TSDB_CODE_SUCCESS) { + pQueryMsg->queryType, pQueryMsg, param.pUdfInfo)) != TSDB_CODE_SUCCESS) { goto _over; } if (param.pSecExpr != NULL) { - if ((code = createIndirectQueryFuncExprFromMsg(pQueryMsg, pQueryMsg->secondStageOutput, ¶m.pSecExprs, param.pSecExpr, param.pExprs)) != TSDB_CODE_SUCCESS) { + if ((code = createIndirectQueryFuncExprFromMsg(pQueryMsg, pQueryMsg->secondStageOutput, ¶m.pSecExprs, param.pSecExpr, param.pExprs, param.pUdfInfo)) != TSDB_CODE_SUCCESS) { goto _over; } } @@ -162,18 +162,14 @@ 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.pUdfInfo); param.sql = NULL; param.pExprs = NULL; param.pSecExprs = NULL; param.pGroupbyExpr = NULL; param.pTagColumnInfo = NULL; - - if ((*pQInfo) == NULL) { - code = TSDB_CODE_QRY_OUT_OF_MEMORY; - goto _over; - } + param.pUdfInfo = NULL; code = initQInfo(&pQueryMsg->tsBuf, tsdb, NULL, *pQInfo, ¶m, (char*)pQueryMsg, pQueryMsg->prevResultLen, NULL); @@ -182,6 +178,8 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi taosArrayDestroy(param.pGroupbyExpr->columnInfo); } + destroyUdfInfo(param.pUdfInfo); + taosArrayDestroy(param.pTableIdList); param.pTableIdList = NULL; diff --git a/src/query/src/sql.c b/src/query/src/sql.c index 7d5748e29fd3d17783b8bbc07ae7a43cd49efc2a..7a9183ac060b255c49def69fcea1c5cbd74c3226 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -97,28 +97,28 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 271 +#define YYNOCODE 277 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SStrToken typedef union { int yyinit; ParseTOKENTYPE yy0; - int yy112; - SCreateAcctInfo yy151; - tSqlExpr* yy166; - SCreateTableSql* yy182; - SSqlNode* yy236; - SRelationInfo* yy244; + TAOS_FIELD yy31; + int yy52; + SLimitVal yy126; + SWindowStateVal yy144; + SCreateTableSql* yy158; + SCreateDbInfo yy214; SSessionWindowVal yy259; - SIntervalVal yy340; - TAOS_FIELD yy343; - SWindowStateVal yy348; - int64_t yy369; - SCreateDbInfo yy382; - SLimitVal yy414; - SArray* yy441; - SCreatedTableInfo yy456; + tSqlExpr* yy370; + SRelationInfo* yy412; + SCreatedTableInfo yy432; + SSqlNode* yy464; + int64_t yy501; tVariant yy506; + SIntervalVal yy520; + SArray* yy525; + SCreateAcctInfo yy547; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -128,17 +128,17 @@ typedef union { #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 -#define YYNSTATE 347 -#define YYNRULE 283 -#define YYNTOKEN 190 -#define YY_MAX_SHIFT 346 -#define YY_MIN_SHIFTREDUCE 547 -#define YY_MAX_SHIFTREDUCE 829 -#define YY_ERROR_ACTION 830 -#define YY_ACCEPT_ACTION 831 -#define YY_NO_ACTION 832 -#define YY_MIN_REDUCE 833 -#define YY_MAX_REDUCE 1115 +#define YYNSTATE 362 +#define YYNRULE 289 +#define YYNTOKEN 195 +#define YY_MAX_SHIFT 361 +#define YY_MIN_SHIFTREDUCE 567 +#define YY_MAX_SHIFTREDUCE 855 +#define YY_ERROR_ACTION 856 +#define YY_ACCEPT_ACTION 857 +#define YY_NO_ACTION 858 +#define YY_MIN_REDUCE 859 +#define YY_MAX_REDUCE 1147 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -204,279 +204,288 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (731) +#define YY_ACTTAB_COUNT (753) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 23, 596, 1004, 596, 219, 344, 194, 831, 346, 597, - /* 10 */ 596, 597, 197, 54, 55, 225, 58, 59, 597, 982, - /* 20 */ 239, 48, 1091, 57, 302, 62, 60, 63, 61, 995, - /* 30 */ 995, 231, 233, 53, 52, 982, 982, 51, 50, 49, - /* 40 */ 54, 55, 35, 58, 59, 222, 223, 239, 48, 596, - /* 50 */ 57, 302, 62, 60, 63, 61, 995, 597, 152, 236, - /* 60 */ 53, 52, 235, 152, 51, 50, 49, 55, 1001, 58, - /* 70 */ 59, 770, 261, 239, 48, 240, 57, 302, 62, 60, - /* 80 */ 63, 61, 29, 83, 976, 221, 53, 52, 145, 979, - /* 90 */ 51, 50, 49, 548, 549, 550, 551, 552, 553, 554, - /* 100 */ 555, 556, 557, 558, 559, 560, 345, 771, 768, 220, - /* 110 */ 95, 77, 54, 55, 35, 58, 59, 42, 197, 239, - /* 120 */ 48, 197, 57, 302, 62, 60, 63, 61, 1092, 232, - /* 130 */ 1040, 1092, 53, 52, 197, 89, 51, 50, 49, 54, - /* 140 */ 56, 968, 58, 59, 1092, 970, 239, 48, 262, 57, - /* 150 */ 302, 62, 60, 63, 61, 268, 267, 229, 36, 53, - /* 160 */ 52, 979, 248, 51, 50, 49, 41, 298, 339, 338, - /* 170 */ 297, 296, 295, 337, 294, 293, 292, 336, 291, 335, - /* 180 */ 334, 944, 932, 933, 934, 935, 936, 937, 938, 939, - /* 190 */ 940, 941, 942, 943, 945, 946, 58, 59, 24, 980, - /* 200 */ 239, 48, 90, 57, 302, 62, 60, 63, 61, 51, - /* 210 */ 50, 49, 152, 53, 52, 205, 78, 51, 50, 49, - /* 220 */ 53, 52, 206, 300, 51, 50, 49, 129, 128, 204, - /* 230 */ 732, 238, 783, 307, 83, 772, 740, 775, 35, 778, - /* 240 */ 147, 238, 783, 116, 253, 772, 65, 775, 35, 778, - /* 250 */ 300, 332, 152, 257, 256, 35, 879, 62, 60, 63, - /* 260 */ 61, 179, 332, 217, 218, 53, 52, 303, 42, 51, - /* 270 */ 50, 49, 700, 217, 218, 697, 304, 698, 14, 699, - /* 280 */ 41, 230, 339, 338, 1041, 979, 280, 337, 340, 913, - /* 290 */ 260, 336, 75, 335, 334, 978, 1, 167, 311, 213, - /* 300 */ 628, 242, 979, 244, 245, 114, 108, 119, 94, 91, - /* 310 */ 64, 195, 118, 124, 127, 117, 952, 80, 950, 951, - /* 320 */ 64, 121, 282, 953, 88, 76, 247, 954, 35, 955, - /* 330 */ 956, 5, 38, 169, 92, 3, 180, 35, 168, 102, - /* 340 */ 97, 101, 784, 779, 35, 35, 35, 35, 716, 780, - /* 350 */ 676, 264, 784, 779, 188, 186, 184, 200, 967, 780, - /* 360 */ 35, 183, 132, 131, 130, 1088, 965, 966, 34, 969, - /* 370 */ 1087, 312, 243, 787, 241, 979, 310, 309, 322, 321, - /* 380 */ 313, 889, 701, 702, 979, 81, 179, 314, 318, 319, - /* 390 */ 320, 979, 979, 979, 979, 880, 774, 249, 777, 246, - /* 400 */ 179, 317, 316, 324, 773, 713, 776, 979, 343, 342, - /* 410 */ 137, 741, 143, 141, 140, 749, 750, 68, 71, 264, - /* 420 */ 686, 26, 237, 285, 16, 688, 15, 287, 720, 687, - /* 430 */ 36, 981, 9, 36, 33, 65, 804, 93, 785, 65, - /* 440 */ 595, 74, 6, 107, 1086, 106, 25, 18, 25, 17, - /* 450 */ 25, 705, 703, 706, 704, 20, 113, 19, 112, 72, - /* 460 */ 69, 215, 22, 288, 21, 126, 125, 216, 198, 675, - /* 470 */ 199, 201, 196, 202, 203, 208, 209, 210, 207, 193, - /* 480 */ 1111, 1103, 1051, 1050, 227, 1047, 1046, 228, 323, 45, - /* 490 */ 258, 144, 1003, 1014, 1011, 1012, 1016, 996, 142, 265, - /* 500 */ 146, 1033, 150, 274, 1032, 977, 163, 164, 269, 224, - /* 510 */ 781, 975, 165, 166, 892, 290, 731, 43, 782, 191, - /* 520 */ 283, 993, 39, 301, 154, 888, 308, 1110, 104, 1109, - /* 530 */ 1106, 170, 315, 73, 1102, 110, 271, 278, 70, 153, - /* 540 */ 47, 1101, 155, 1098, 281, 171, 910, 40, 279, 277, - /* 550 */ 37, 275, 44, 273, 192, 270, 156, 876, 120, 874, - /* 560 */ 122, 123, 872, 871, 250, 182, 869, 868, 867, 866, - /* 570 */ 865, 864, 185, 187, 861, 859, 857, 855, 189, 852, - /* 580 */ 190, 333, 263, 79, 46, 84, 115, 272, 1034, 325, - /* 590 */ 326, 327, 328, 329, 330, 331, 214, 341, 829, 234, - /* 600 */ 251, 252, 289, 828, 254, 255, 827, 211, 212, 809, - /* 610 */ 98, 810, 99, 259, 264, 284, 10, 82, 708, 266, - /* 620 */ 85, 30, 870, 174, 178, 863, 911, 172, 173, 175, - /* 630 */ 176, 4, 133, 177, 862, 912, 134, 135, 948, 136, - /* 640 */ 854, 733, 148, 853, 157, 158, 159, 160, 736, 161, - /* 650 */ 149, 162, 958, 2, 86, 226, 738, 87, 276, 31, - /* 660 */ 742, 151, 32, 13, 11, 27, 286, 28, 12, 641, - /* 670 */ 96, 94, 639, 638, 637, 635, 634, 633, 630, 299, - /* 680 */ 600, 100, 7, 305, 786, 788, 8, 306, 103, 105, - /* 690 */ 66, 67, 109, 111, 678, 36, 677, 674, 622, 620, - /* 700 */ 612, 618, 614, 616, 610, 608, 644, 643, 642, 640, - /* 710 */ 636, 632, 631, 181, 598, 564, 562, 833, 832, 832, - /* 720 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 138, - /* 730 */ 139, + /* 0 */ 206, 618, 245, 618, 618, 97, 244, 228, 359, 619, + /* 10 */ 1123, 619, 619, 56, 57, 152, 60, 61, 654, 1027, + /* 20 */ 248, 50, 1036, 59, 317, 64, 62, 65, 63, 984, + /* 30 */ 249, 982, 983, 55, 54, 231, 985, 53, 52, 51, + /* 40 */ 986, 1002, 987, 988, 53, 52, 51, 568, 569, 570, + /* 50 */ 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, + /* 60 */ 581, 360, 206, 257, 229, 159, 206, 56, 57, 37, + /* 70 */ 60, 61, 1124, 174, 248, 50, 1124, 59, 317, 64, + /* 80 */ 62, 65, 63, 277, 276, 29, 79, 55, 54, 1033, + /* 90 */ 206, 53, 52, 51, 56, 57, 315, 60, 61, 234, + /* 100 */ 1124, 248, 50, 1014, 59, 317, 64, 62, 65, 63, + /* 110 */ 358, 357, 144, 230, 55, 54, 85, 1011, 53, 52, + /* 120 */ 51, 56, 58, 240, 60, 61, 347, 1014, 248, 50, + /* 130 */ 94, 59, 317, 64, 62, 65, 63, 794, 1073, 242, + /* 140 */ 289, 55, 54, 1014, 618, 53, 52, 51, 57, 23, + /* 150 */ 60, 61, 619, 44, 248, 50, 1000, 59, 317, 64, + /* 160 */ 62, 65, 63, 997, 998, 34, 1001, 55, 54, 857, + /* 170 */ 361, 53, 52, 51, 43, 313, 354, 353, 312, 311, + /* 180 */ 310, 352, 309, 308, 307, 351, 306, 350, 349, 976, + /* 190 */ 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, + /* 200 */ 974, 975, 977, 978, 60, 61, 24, 1008, 248, 50, + /* 210 */ 257, 59, 317, 64, 62, 65, 63, 1027, 122, 1027, + /* 220 */ 175, 55, 54, 37, 209, 53, 52, 51, 247, 809, + /* 230 */ 347, 215, 798, 232, 801, 270, 804, 135, 134, 214, + /* 240 */ 315, 247, 809, 322, 85, 798, 14, 801, 37, 804, + /* 250 */ 93, 159, 726, 241, 203, 723, 800, 724, 803, 725, + /* 260 */ 226, 227, 257, 16, 318, 15, 37, 238, 5, 40, + /* 270 */ 178, 1011, 1012, 226, 227, 177, 103, 108, 99, 107, + /* 280 */ 96, 44, 204, 253, 254, 210, 64, 62, 65, 63, + /* 290 */ 355, 945, 159, 302, 55, 54, 1010, 251, 53, 52, + /* 300 */ 51, 1013, 78, 269, 256, 77, 120, 114, 125, 66, + /* 310 */ 239, 702, 222, 124, 1011, 130, 133, 123, 37, 197, + /* 320 */ 195, 193, 66, 127, 1072, 37, 192, 139, 138, 137, + /* 330 */ 136, 799, 159, 802, 37, 43, 999, 354, 353, 337, + /* 340 */ 336, 37, 352, 262, 810, 805, 351, 37, 350, 349, + /* 350 */ 37, 806, 266, 265, 742, 55, 54, 810, 805, 53, + /* 360 */ 52, 51, 326, 291, 806, 90, 1011, 727, 728, 327, + /* 370 */ 37, 37, 252, 1011, 250, 807, 325, 324, 328, 258, + /* 380 */ 82, 255, 1011, 332, 331, 329, 150, 148, 147, 1011, + /* 390 */ 907, 333, 83, 917, 334, 1011, 908, 188, 1011, 271, + /* 400 */ 188, 739, 92, 188, 70, 91, 1, 176, 3, 189, + /* 410 */ 775, 776, 758, 38, 335, 339, 80, 273, 1011, 1011, + /* 420 */ 766, 767, 73, 712, 294, 33, 154, 9, 714, 273, + /* 430 */ 296, 713, 796, 830, 67, 26, 246, 38, 38, 746, + /* 440 */ 811, 319, 67, 76, 95, 67, 71, 25, 1120, 617, + /* 450 */ 808, 132, 131, 113, 25, 112, 1119, 6, 297, 18, + /* 460 */ 1118, 17, 74, 25, 731, 729, 732, 730, 797, 20, + /* 470 */ 1083, 19, 119, 224, 118, 701, 22, 225, 21, 207, + /* 480 */ 208, 211, 205, 212, 213, 217, 218, 219, 216, 202, + /* 490 */ 1143, 1082, 1135, 236, 267, 1079, 1078, 237, 338, 151, + /* 500 */ 1035, 1046, 47, 1065, 1043, 149, 1064, 1025, 1028, 1044, + /* 510 */ 274, 1048, 153, 170, 157, 1009, 278, 283, 171, 1007, + /* 520 */ 172, 233, 166, 280, 161, 757, 160, 173, 162, 922, + /* 530 */ 163, 299, 300, 301, 304, 305, 287, 292, 45, 290, + /* 540 */ 75, 200, 288, 813, 272, 41, 72, 49, 316, 164, + /* 550 */ 916, 323, 1142, 110, 1141, 1138, 286, 179, 330, 1134, + /* 560 */ 284, 116, 1133, 1130, 180, 282, 942, 42, 39, 46, + /* 570 */ 201, 904, 279, 126, 48, 902, 128, 129, 900, 899, + /* 580 */ 259, 191, 897, 896, 895, 894, 893, 892, 891, 194, + /* 590 */ 196, 888, 886, 884, 882, 198, 879, 199, 303, 81, + /* 600 */ 86, 348, 281, 1066, 121, 340, 341, 342, 343, 344, + /* 610 */ 223, 345, 346, 356, 855, 243, 298, 260, 261, 854, + /* 620 */ 263, 220, 221, 264, 853, 836, 104, 921, 920, 105, + /* 630 */ 835, 268, 273, 10, 293, 734, 275, 84, 30, 87, + /* 640 */ 898, 890, 182, 943, 186, 181, 184, 140, 183, 187, + /* 650 */ 185, 141, 142, 889, 4, 143, 980, 881, 880, 944, + /* 660 */ 759, 165, 167, 168, 155, 169, 762, 156, 2, 990, + /* 670 */ 88, 235, 764, 89, 285, 31, 768, 158, 11, 12, + /* 680 */ 13, 32, 27, 295, 28, 96, 98, 101, 35, 100, + /* 690 */ 632, 36, 102, 667, 665, 664, 663, 661, 660, 659, + /* 700 */ 656, 314, 622, 106, 7, 320, 812, 814, 8, 321, + /* 710 */ 109, 111, 68, 69, 115, 704, 703, 38, 117, 700, + /* 720 */ 648, 646, 638, 644, 640, 642, 636, 634, 670, 669, + /* 730 */ 668, 666, 662, 658, 657, 190, 620, 585, 583, 859, + /* 740 */ 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, + /* 750 */ 858, 145, 146, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 259, 1, 194, 1, 193, 194, 259, 191, 192, 9, - /* 10 */ 1, 9, 259, 13, 14, 238, 16, 17, 9, 242, - /* 20 */ 20, 21, 269, 23, 24, 25, 26, 27, 28, 240, - /* 30 */ 240, 238, 238, 33, 34, 242, 242, 37, 38, 39, - /* 40 */ 13, 14, 194, 16, 17, 256, 256, 20, 21, 1, - /* 50 */ 23, 24, 25, 26, 27, 28, 240, 9, 194, 200, - /* 60 */ 33, 34, 200, 194, 37, 38, 39, 14, 260, 16, - /* 70 */ 17, 1, 256, 20, 21, 200, 23, 24, 25, 26, - /* 80 */ 27, 28, 80, 80, 194, 237, 33, 34, 194, 241, - /* 90 */ 37, 38, 39, 45, 46, 47, 48, 49, 50, 51, - /* 100 */ 52, 53, 54, 55, 56, 57, 58, 37, 81, 61, - /* 110 */ 201, 111, 13, 14, 194, 16, 17, 114, 259, 20, - /* 120 */ 21, 259, 23, 24, 25, 26, 27, 28, 269, 239, - /* 130 */ 266, 269, 33, 34, 259, 266, 37, 38, 39, 13, - /* 140 */ 14, 0, 16, 17, 269, 236, 20, 21, 81, 23, - /* 150 */ 24, 25, 26, 27, 28, 261, 262, 237, 91, 33, - /* 160 */ 34, 241, 194, 37, 38, 39, 92, 93, 94, 95, - /* 170 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, - /* 180 */ 106, 215, 216, 217, 218, 219, 220, 221, 222, 223, - /* 190 */ 224, 225, 226, 227, 228, 229, 16, 17, 44, 231, - /* 200 */ 20, 21, 243, 23, 24, 25, 26, 27, 28, 37, - /* 210 */ 38, 39, 194, 33, 34, 61, 257, 37, 38, 39, - /* 220 */ 33, 34, 68, 82, 37, 38, 39, 73, 74, 75, - /* 230 */ 81, 1, 2, 79, 80, 5, 81, 7, 194, 9, - /* 240 */ 91, 1, 2, 76, 137, 5, 91, 7, 194, 9, - /* 250 */ 82, 84, 194, 146, 147, 194, 199, 25, 26, 27, - /* 260 */ 28, 204, 84, 33, 34, 33, 34, 37, 114, 37, - /* 270 */ 38, 39, 2, 33, 34, 5, 15, 7, 80, 9, - /* 280 */ 92, 237, 94, 95, 266, 241, 268, 99, 213, 214, - /* 290 */ 136, 103, 138, 105, 106, 241, 202, 203, 237, 145, - /* 300 */ 5, 68, 241, 33, 34, 62, 63, 64, 110, 111, - /* 310 */ 80, 259, 69, 70, 71, 72, 215, 81, 217, 218, - /* 320 */ 80, 78, 264, 222, 266, 201, 68, 226, 194, 228, - /* 330 */ 229, 62, 63, 64, 201, 197, 198, 194, 69, 70, - /* 340 */ 71, 72, 112, 113, 194, 194, 194, 194, 37, 119, - /* 350 */ 5, 115, 112, 113, 62, 63, 64, 259, 234, 119, - /* 360 */ 194, 69, 70, 71, 72, 259, 233, 234, 235, 236, - /* 370 */ 259, 237, 139, 112, 141, 241, 143, 144, 33, 34, - /* 380 */ 237, 199, 112, 113, 241, 81, 204, 237, 237, 237, - /* 390 */ 237, 241, 241, 241, 241, 199, 5, 139, 7, 141, - /* 400 */ 204, 143, 144, 237, 5, 91, 7, 241, 65, 66, - /* 410 */ 67, 81, 62, 63, 64, 127, 128, 91, 91, 115, - /* 420 */ 81, 91, 60, 81, 140, 81, 142, 81, 117, 81, - /* 430 */ 91, 242, 118, 91, 80, 91, 81, 91, 81, 91, - /* 440 */ 81, 80, 80, 140, 259, 142, 91, 140, 91, 142, - /* 450 */ 91, 5, 5, 7, 7, 140, 140, 142, 142, 132, - /* 460 */ 134, 259, 140, 109, 142, 76, 77, 259, 259, 108, - /* 470 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 480 */ 242, 242, 232, 232, 232, 232, 232, 232, 232, 258, - /* 490 */ 194, 194, 194, 194, 194, 194, 194, 240, 60, 240, - /* 500 */ 194, 267, 194, 194, 267, 240, 244, 194, 263, 263, - /* 510 */ 119, 194, 194, 194, 194, 194, 119, 194, 119, 194, - /* 520 */ 125, 255, 194, 194, 253, 194, 194, 194, 194, 194, - /* 530 */ 194, 194, 194, 131, 194, 194, 263, 263, 133, 254, - /* 540 */ 130, 194, 252, 194, 129, 194, 194, 194, 124, 123, - /* 550 */ 194, 122, 194, 121, 194, 120, 251, 194, 194, 194, - /* 560 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 570 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 580 */ 194, 107, 195, 195, 135, 195, 90, 195, 195, 89, - /* 590 */ 50, 86, 88, 54, 87, 85, 195, 82, 5, 195, - /* 600 */ 148, 5, 195, 5, 148, 5, 5, 195, 195, 93, - /* 610 */ 201, 94, 201, 137, 115, 109, 80, 116, 81, 91, - /* 620 */ 91, 80, 195, 206, 205, 195, 212, 211, 210, 209, - /* 630 */ 207, 197, 196, 208, 195, 214, 196, 196, 230, 196, - /* 640 */ 195, 81, 80, 195, 250, 249, 248, 247, 81, 246, - /* 650 */ 91, 245, 230, 202, 80, 1, 81, 80, 80, 91, - /* 660 */ 81, 80, 91, 80, 126, 80, 109, 80, 126, 9, - /* 670 */ 76, 110, 5, 5, 5, 5, 5, 5, 5, 15, - /* 680 */ 83, 76, 80, 24, 81, 112, 80, 58, 142, 142, - /* 690 */ 16, 16, 142, 142, 5, 91, 5, 81, 5, 5, - /* 700 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - /* 710 */ 5, 5, 5, 91, 83, 60, 59, 0, 270, 270, - /* 720 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 21, - /* 730 */ 21, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 740 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 750 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 760 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 770 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 780 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 790 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 800 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 810 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 820 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 830 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 840 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 850 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 860 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 870 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 880 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 890 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 900 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 910 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 920 */ 270, + /* 0 */ 265, 1, 205, 1, 1, 206, 205, 198, 199, 9, + /* 10 */ 275, 9, 9, 13, 14, 199, 16, 17, 5, 246, + /* 20 */ 20, 21, 199, 23, 24, 25, 26, 27, 28, 222, + /* 30 */ 205, 224, 225, 33, 34, 262, 229, 37, 38, 39, + /* 40 */ 233, 242, 235, 236, 37, 38, 39, 45, 46, 47, + /* 50 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + /* 60 */ 58, 59, 265, 199, 62, 199, 265, 13, 14, 199, + /* 70 */ 16, 17, 275, 209, 20, 21, 275, 23, 24, 25, + /* 80 */ 26, 27, 28, 267, 268, 82, 86, 33, 34, 266, + /* 90 */ 265, 37, 38, 39, 13, 14, 84, 16, 17, 244, + /* 100 */ 275, 20, 21, 248, 23, 24, 25, 26, 27, 28, + /* 110 */ 66, 67, 68, 243, 33, 34, 82, 247, 37, 38, + /* 120 */ 39, 13, 14, 244, 16, 17, 90, 248, 20, 21, + /* 130 */ 206, 23, 24, 25, 26, 27, 28, 83, 272, 244, + /* 140 */ 274, 33, 34, 248, 1, 37, 38, 39, 14, 265, + /* 150 */ 16, 17, 9, 119, 20, 21, 0, 23, 24, 25, + /* 160 */ 26, 27, 28, 239, 240, 241, 242, 33, 34, 196, + /* 170 */ 197, 37, 38, 39, 98, 99, 100, 101, 102, 103, + /* 180 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 222, + /* 190 */ 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, + /* 200 */ 233, 234, 235, 236, 16, 17, 44, 199, 20, 21, + /* 210 */ 199, 23, 24, 25, 26, 27, 28, 246, 78, 246, + /* 220 */ 209, 33, 34, 199, 62, 37, 38, 39, 1, 2, + /* 230 */ 90, 69, 5, 262, 7, 262, 9, 75, 76, 77, + /* 240 */ 84, 1, 2, 81, 82, 5, 82, 7, 199, 9, + /* 250 */ 86, 199, 2, 245, 265, 5, 5, 7, 7, 9, + /* 260 */ 33, 34, 199, 145, 37, 147, 199, 243, 63, 64, + /* 270 */ 65, 247, 209, 33, 34, 70, 71, 72, 73, 74, + /* 280 */ 116, 119, 265, 33, 34, 265, 25, 26, 27, 28, + /* 290 */ 220, 221, 199, 88, 33, 34, 247, 69, 37, 38, + /* 300 */ 39, 248, 206, 141, 69, 143, 63, 64, 65, 82, + /* 310 */ 243, 5, 150, 70, 247, 72, 73, 74, 199, 63, + /* 320 */ 64, 65, 82, 80, 272, 199, 70, 71, 72, 73, + /* 330 */ 74, 5, 199, 7, 199, 98, 240, 100, 101, 33, + /* 340 */ 34, 199, 105, 142, 117, 118, 109, 199, 111, 112, + /* 350 */ 199, 124, 151, 152, 37, 33, 34, 117, 118, 37, + /* 360 */ 38, 39, 243, 270, 124, 272, 247, 117, 118, 243, + /* 370 */ 199, 199, 144, 247, 146, 124, 148, 149, 243, 144, + /* 380 */ 83, 146, 247, 148, 149, 243, 63, 64, 65, 247, + /* 390 */ 204, 243, 83, 204, 243, 247, 204, 211, 247, 83, + /* 400 */ 211, 97, 249, 211, 97, 272, 207, 208, 202, 203, + /* 410 */ 132, 133, 83, 97, 243, 243, 263, 120, 247, 247, + /* 420 */ 83, 83, 97, 83, 83, 82, 97, 123, 83, 120, + /* 430 */ 83, 83, 1, 83, 97, 97, 61, 97, 97, 122, + /* 440 */ 83, 15, 97, 82, 97, 97, 139, 97, 265, 83, + /* 450 */ 124, 78, 79, 145, 97, 147, 265, 82, 115, 145, + /* 460 */ 265, 147, 137, 97, 5, 5, 7, 7, 37, 145, + /* 470 */ 238, 147, 145, 265, 147, 114, 145, 265, 147, 265, + /* 480 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 490 */ 248, 238, 248, 238, 199, 238, 238, 238, 238, 199, + /* 500 */ 199, 199, 264, 273, 199, 61, 273, 261, 246, 199, + /* 510 */ 246, 199, 199, 250, 199, 246, 269, 199, 199, 199, + /* 520 */ 199, 269, 254, 269, 259, 124, 260, 199, 258, 199, + /* 530 */ 257, 199, 199, 199, 199, 199, 269, 130, 199, 134, + /* 540 */ 136, 199, 129, 117, 200, 199, 138, 135, 199, 256, + /* 550 */ 199, 199, 199, 199, 199, 199, 128, 199, 199, 199, + /* 560 */ 127, 199, 199, 199, 199, 126, 199, 199, 199, 199, + /* 570 */ 199, 199, 125, 199, 140, 199, 199, 199, 199, 199, + /* 580 */ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + /* 590 */ 199, 199, 199, 199, 199, 199, 199, 199, 89, 200, + /* 600 */ 200, 113, 200, 200, 96, 95, 51, 92, 94, 55, + /* 610 */ 200, 93, 91, 84, 5, 200, 200, 153, 5, 5, + /* 620 */ 153, 200, 200, 5, 5, 100, 206, 210, 210, 206, + /* 630 */ 99, 142, 120, 82, 115, 83, 97, 121, 82, 97, + /* 640 */ 200, 200, 217, 219, 215, 218, 216, 201, 213, 212, + /* 650 */ 214, 201, 201, 200, 202, 201, 237, 200, 200, 221, + /* 660 */ 83, 255, 253, 252, 82, 251, 83, 97, 207, 237, + /* 670 */ 82, 1, 83, 82, 82, 97, 83, 82, 131, 131, + /* 680 */ 82, 97, 82, 115, 82, 116, 78, 71, 87, 86, + /* 690 */ 5, 87, 86, 9, 5, 5, 5, 5, 5, 5, + /* 700 */ 5, 15, 85, 78, 82, 24, 83, 117, 82, 59, + /* 710 */ 147, 147, 16, 16, 147, 5, 5, 97, 147, 83, + /* 720 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + /* 730 */ 5, 5, 5, 5, 5, 97, 85, 61, 60, 0, + /* 740 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 750 */ 276, 21, 21, 276, 276, 276, 276, 276, 276, 276, + /* 760 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 770 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 780 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 790 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 800 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 810 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 820 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 830 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 840 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 850 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 860 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 870 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 880 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 890 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 900 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 910 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 920 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 930 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, + /* 940 */ 276, 276, 276, 276, 276, 276, 276, 276, }; -#define YY_SHIFT_COUNT (346) +#define YY_SHIFT_COUNT (361) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (717) +#define YY_SHIFT_MAX (739) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 154, 74, 74, 188, 188, 168, 230, 240, 240, 2, - /* 10 */ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - /* 20 */ 9, 9, 9, 0, 48, 240, 270, 270, 270, 3, - /* 30 */ 3, 9, 9, 9, 141, 9, 9, 167, 168, 178, - /* 40 */ 178, 295, 731, 731, 731, 240, 240, 240, 240, 240, + /* 0 */ 162, 76, 76, 237, 237, 12, 227, 240, 240, 3, + /* 10 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + /* 20 */ 143, 143, 143, 0, 2, 240, 250, 250, 250, 34, + /* 30 */ 34, 143, 143, 143, 156, 143, 143, 143, 143, 140, + /* 40 */ 12, 36, 36, 13, 753, 753, 753, 240, 240, 240, /* 50 */ 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, - /* 60 */ 240, 240, 240, 240, 240, 270, 270, 270, 345, 345, - /* 70 */ 345, 345, 345, 345, 345, 9, 9, 9, 311, 9, - /* 80 */ 9, 9, 3, 3, 9, 9, 9, 9, 288, 288, - /* 90 */ 314, 3, 9, 9, 9, 9, 9, 9, 9, 9, - /* 100 */ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - /* 110 */ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - /* 120 */ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - /* 130 */ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - /* 140 */ 9, 9, 9, 9, 438, 438, 438, 397, 397, 397, - /* 150 */ 438, 397, 438, 402, 405, 395, 410, 415, 424, 426, - /* 160 */ 429, 432, 435, 449, 438, 438, 438, 474, 168, 168, - /* 170 */ 438, 438, 496, 500, 540, 505, 504, 539, 507, 510, - /* 180 */ 474, 295, 438, 515, 515, 438, 515, 438, 515, 438, - /* 190 */ 438, 731, 731, 27, 99, 99, 126, 99, 53, 180, - /* 200 */ 232, 232, 232, 232, 243, 269, 292, 187, 187, 187, - /* 210 */ 187, 233, 258, 107, 198, 172, 172, 391, 399, 343, - /* 220 */ 350, 67, 236, 304, 149, 155, 330, 326, 327, 339, - /* 230 */ 342, 344, 346, 348, 354, 355, 357, 70, 362, 261, - /* 240 */ 359, 284, 303, 307, 446, 447, 315, 316, 361, 322, - /* 250 */ 389, 593, 452, 596, 598, 456, 600, 601, 517, 516, - /* 260 */ 476, 499, 506, 536, 501, 537, 541, 528, 529, 560, - /* 270 */ 562, 567, 559, 574, 575, 577, 654, 578, 579, 581, - /* 280 */ 568, 538, 571, 542, 583, 506, 585, 557, 587, 561, - /* 290 */ 594, 660, 667, 668, 669, 670, 671, 672, 673, 597, - /* 300 */ 664, 605, 602, 603, 573, 606, 659, 629, 674, 546, - /* 310 */ 547, 604, 604, 604, 604, 675, 550, 551, 604, 604, - /* 320 */ 604, 689, 691, 616, 604, 693, 694, 695, 696, 697, - /* 330 */ 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, - /* 340 */ 622, 631, 708, 709, 655, 657, 717, + /* 60 */ 240, 240, 240, 240, 240, 240, 240, 250, 250, 250, + /* 70 */ 306, 306, 306, 306, 306, 306, 306, 143, 143, 143, + /* 80 */ 317, 143, 143, 143, 34, 34, 143, 143, 143, 143, + /* 90 */ 278, 278, 304, 34, 143, 143, 143, 143, 143, 143, + /* 100 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + /* 110 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + /* 120 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + /* 130 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + /* 140 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + /* 150 */ 143, 444, 444, 444, 401, 401, 401, 444, 401, 444, + /* 160 */ 404, 408, 407, 412, 405, 413, 428, 433, 439, 447, + /* 170 */ 434, 444, 444, 444, 509, 509, 488, 12, 12, 444, + /* 180 */ 444, 508, 510, 555, 515, 514, 554, 518, 521, 488, + /* 190 */ 13, 444, 529, 529, 444, 529, 444, 529, 444, 444, + /* 200 */ 753, 753, 54, 81, 81, 108, 81, 134, 188, 205, + /* 210 */ 261, 261, 261, 261, 243, 256, 322, 322, 322, 322, + /* 220 */ 228, 235, 201, 164, 7, 7, 251, 326, 44, 323, + /* 230 */ 316, 297, 309, 329, 337, 338, 307, 325, 340, 341, + /* 240 */ 345, 347, 348, 343, 350, 357, 431, 375, 426, 366, + /* 250 */ 118, 308, 314, 459, 460, 324, 327, 361, 331, 373, + /* 260 */ 609, 464, 613, 614, 467, 618, 619, 525, 531, 489, + /* 270 */ 512, 519, 551, 516, 552, 556, 539, 542, 577, 582, + /* 280 */ 583, 570, 588, 589, 591, 670, 592, 593, 595, 578, + /* 290 */ 547, 584, 548, 598, 519, 600, 568, 602, 569, 608, + /* 300 */ 601, 603, 616, 685, 604, 606, 684, 689, 690, 691, + /* 310 */ 692, 693, 694, 695, 617, 686, 625, 622, 623, 590, + /* 320 */ 626, 681, 650, 696, 563, 564, 620, 620, 620, 620, + /* 330 */ 697, 567, 571, 620, 620, 620, 710, 711, 636, 620, + /* 340 */ 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, + /* 350 */ 725, 726, 727, 728, 729, 638, 651, 730, 731, 676, + /* 360 */ 678, 739, }; -#define YY_REDUCE_COUNT (192) -#define YY_REDUCE_MIN (-259) -#define YY_REDUCE_MAX (451) +#define YY_REDUCE_COUNT (201) +#define YY_REDUCE_MIN (-265) +#define YY_REDUCE_MAX (461) static const short yy_reduce_ofst[] = { - /* 0 */ -184, -34, -34, 101, 101, 133, -141, -138, -125, -106, - /* 10 */ -152, 18, 58, -80, 44, 61, 134, 143, 150, 151, - /* 20 */ 152, 153, 166, -192, -189, -247, -223, -207, -206, -211, - /* 30 */ -210, -136, -131, -110, -91, -32, 54, 57, 124, 182, - /* 40 */ 196, 75, -41, 94, 138, -259, -253, 52, 98, 106, - /* 50 */ 111, 185, 202, 208, 209, 211, 212, 213, 214, 215, - /* 60 */ 216, 217, 218, 219, 220, 189, 238, 239, 250, 251, - /* 70 */ 252, 253, 254, 255, 256, 296, 297, 298, 231, 299, - /* 80 */ 300, 301, 257, 259, 302, 306, 308, 309, 234, 237, - /* 90 */ 262, 265, 313, 317, 318, 319, 320, 321, 323, 325, - /* 100 */ 328, 329, 331, 332, 333, 334, 335, 336, 337, 338, - /* 110 */ 340, 341, 347, 349, 351, 352, 353, 356, 358, 360, - /* 120 */ 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - /* 130 */ 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - /* 140 */ 383, 384, 385, 386, 387, 388, 390, 245, 246, 273, - /* 150 */ 392, 274, 393, 266, 285, 271, 290, 305, 394, 396, - /* 160 */ 398, 400, 403, 406, 401, 404, 407, 408, 409, 411, - /* 170 */ 412, 413, 414, 416, 418, 417, 420, 423, 425, 419, - /* 180 */ 422, 421, 427, 436, 440, 430, 441, 439, 443, 445, - /* 190 */ 448, 451, 434, + /* 0 */ -27, -33, -33, -193, -193, -76, -203, -199, -175, -184, + /* 10 */ -130, -134, 93, 24, 67, 119, 126, 135, 142, 148, + /* 20 */ 151, 171, 172, -177, -191, -265, -145, -121, -105, -227, + /* 30 */ -29, 52, 133, 8, -201, -136, 11, 63, 49, 186, + /* 40 */ 96, 189, 192, 70, 153, 199, 206, -116, -11, 17, + /* 50 */ 20, 183, 191, 195, 208, 212, 214, 215, 216, 217, + /* 60 */ 218, 219, 220, 221, 222, 223, 224, 53, 242, 244, + /* 70 */ 232, 253, 255, 257, 258, 259, 260, 295, 300, 301, + /* 80 */ 238, 302, 305, 310, 262, 264, 312, 313, 315, 318, + /* 90 */ 230, 233, 263, 269, 319, 320, 321, 328, 330, 332, + /* 100 */ 333, 334, 335, 336, 339, 342, 346, 349, 351, 352, + /* 110 */ 353, 354, 355, 356, 358, 359, 360, 362, 363, 364, + /* 120 */ 365, 367, 368, 369, 370, 371, 372, 374, 376, 377, + /* 130 */ 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, + /* 140 */ 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + /* 150 */ 398, 344, 399, 400, 247, 252, 254, 402, 267, 403, + /* 160 */ 246, 266, 265, 270, 273, 293, 406, 268, 409, 411, + /* 170 */ 414, 410, 415, 416, 417, 418, 419, 420, 423, 421, + /* 180 */ 422, 424, 427, 425, 435, 430, 436, 429, 437, 432, + /* 190 */ 438, 440, 446, 450, 441, 451, 453, 454, 457, 458, + /* 200 */ 461, 452, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 830, 947, 890, 957, 877, 887, 1094, 1094, 1094, 830, - /* 10 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 20 */ 830, 830, 830, 1005, 849, 1094, 830, 830, 830, 830, - /* 30 */ 830, 830, 830, 830, 887, 830, 830, 893, 887, 893, - /* 40 */ 893, 830, 1000, 931, 949, 830, 830, 830, 830, 830, - /* 50 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 60 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 70 */ 830, 830, 830, 830, 830, 830, 830, 830, 1007, 1013, - /* 80 */ 1010, 830, 830, 830, 1015, 830, 830, 830, 1037, 1037, - /* 90 */ 998, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 100 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 110 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 120 */ 875, 830, 873, 830, 830, 830, 830, 830, 830, 830, - /* 130 */ 830, 830, 830, 830, 830, 830, 830, 860, 830, 830, - /* 140 */ 830, 830, 830, 830, 851, 851, 851, 830, 830, 830, - /* 150 */ 851, 830, 851, 1044, 1048, 1030, 1042, 1038, 1029, 1025, - /* 160 */ 1023, 1021, 1020, 1052, 851, 851, 851, 891, 887, 887, - /* 170 */ 851, 851, 909, 907, 905, 897, 903, 899, 901, 895, - /* 180 */ 878, 830, 851, 885, 885, 851, 885, 851, 885, 851, - /* 190 */ 851, 931, 949, 830, 1053, 1043, 830, 1093, 1083, 1082, - /* 200 */ 1089, 1081, 1080, 1079, 830, 830, 830, 1075, 1078, 1077, - /* 210 */ 1076, 830, 830, 830, 830, 1085, 1084, 830, 830, 830, - /* 220 */ 830, 830, 830, 830, 830, 830, 830, 1049, 1045, 830, - /* 230 */ 830, 830, 830, 830, 830, 830, 830, 830, 1055, 830, - /* 240 */ 830, 830, 830, 830, 830, 830, 830, 830, 959, 830, - /* 250 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 260 */ 830, 997, 830, 830, 830, 830, 830, 1009, 1008, 830, - /* 270 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 280 */ 1039, 830, 1031, 830, 830, 971, 830, 830, 830, 830, - /* 290 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 300 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 310 */ 830, 1112, 1107, 1108, 1105, 830, 830, 830, 1104, 1099, - /* 320 */ 1100, 830, 830, 830, 1097, 830, 830, 830, 830, 830, - /* 330 */ 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, - /* 340 */ 915, 830, 858, 856, 830, 847, 830, + /* 0 */ 856, 979, 918, 989, 905, 915, 1126, 1126, 1126, 856, + /* 10 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 20 */ 856, 856, 856, 1037, 876, 1126, 856, 856, 856, 856, + /* 30 */ 856, 856, 856, 856, 915, 856, 856, 856, 856, 925, + /* 40 */ 915, 925, 925, 856, 1032, 963, 981, 856, 856, 856, + /* 50 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 60 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 70 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 80 */ 1039, 1045, 1042, 856, 856, 856, 1047, 856, 856, 856, + /* 90 */ 1069, 1069, 1030, 856, 856, 856, 856, 856, 856, 856, + /* 100 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 110 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 120 */ 856, 856, 856, 856, 856, 856, 903, 856, 901, 856, + /* 130 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 140 */ 856, 856, 856, 856, 887, 856, 856, 856, 856, 856, + /* 150 */ 856, 878, 878, 878, 856, 856, 856, 878, 856, 878, + /* 160 */ 1076, 1080, 1062, 1074, 1070, 1061, 1057, 1055, 1053, 1052, + /* 170 */ 1084, 878, 878, 878, 923, 923, 919, 915, 915, 878, + /* 180 */ 878, 941, 939, 937, 929, 935, 931, 933, 927, 906, + /* 190 */ 856, 878, 913, 913, 878, 913, 878, 913, 878, 878, + /* 200 */ 963, 981, 856, 1085, 1075, 856, 1125, 1115, 1114, 856, + /* 210 */ 1121, 1113, 1112, 1111, 856, 856, 1107, 1110, 1109, 1108, + /* 220 */ 856, 856, 856, 856, 1117, 1116, 856, 856, 856, 856, + /* 230 */ 856, 856, 856, 856, 856, 856, 1081, 1077, 856, 856, + /* 240 */ 856, 856, 856, 856, 856, 856, 856, 1087, 856, 856, + /* 250 */ 856, 856, 856, 856, 856, 856, 856, 991, 856, 856, + /* 260 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 270 */ 1029, 856, 856, 856, 856, 856, 1041, 1040, 856, 856, + /* 280 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 1071, + /* 290 */ 856, 1063, 856, 856, 1003, 856, 856, 856, 856, 856, + /* 300 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 310 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 320 */ 856, 856, 856, 856, 856, 856, 1144, 1139, 1140, 1137, + /* 330 */ 856, 856, 856, 1136, 1131, 1132, 856, 856, 856, 1129, + /* 340 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 350 */ 856, 856, 856, 856, 856, 947, 856, 885, 883, 856, + /* 360 */ 874, 856, }; /********** End of lemon-generated parsing tables *****************************/ @@ -543,6 +552,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* SHOW => nothing */ 0, /* DATABASES => nothing */ 0, /* TOPICS => nothing */ + 0, /* FUNCTIONS => nothing */ 0, /* MNODES => nothing */ 0, /* DNODES => nothing */ 0, /* ACCOUNTS => nothing */ @@ -566,6 +576,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* VGROUPS => nothing */ 0, /* DROP => nothing */ 0, /* TOPIC => nothing */ + 0, /* FUNCTION => nothing */ 0, /* DNODE => nothing */ 0, /* USER => nothing */ 0, /* ACCOUNT => nothing */ @@ -580,6 +591,10 @@ static const YYCODETYPE yyFallback[] = { 0, /* RP => nothing */ 0, /* IF => nothing */ 0, /* EXISTS => nothing */ + 0, /* AS => nothing */ + 0, /* OUTPUTTYPE => nothing */ + 0, /* AGGREGATE => nothing */ + 0, /* BUFSIZE => nothing */ 0, /* PPS => nothing */ 0, /* TSERIES => nothing */ 0, /* DBS => nothing */ @@ -607,7 +622,6 @@ static const YYCODETYPE yyFallback[] = { 0, /* UNSIGNED => nothing */ 0, /* TAGS => nothing */ 0, /* USING => nothing */ - 0, /* AS => nothing */ 1, /* NULL => ID */ 1, /* NOW => ID */ 0, /* SELECT => nothing */ @@ -819,229 +833,235 @@ static const char *const yyTokenName[] = { /* 44 */ "SHOW", /* 45 */ "DATABASES", /* 46 */ "TOPICS", - /* 47 */ "MNODES", - /* 48 */ "DNODES", - /* 49 */ "ACCOUNTS", - /* 50 */ "USERS", - /* 51 */ "MODULES", - /* 52 */ "QUERIES", - /* 53 */ "CONNECTIONS", - /* 54 */ "STREAMS", - /* 55 */ "VARIABLES", - /* 56 */ "SCORES", - /* 57 */ "GRANTS", - /* 58 */ "VNODES", - /* 59 */ "IPTOKEN", - /* 60 */ "DOT", - /* 61 */ "CREATE", - /* 62 */ "TABLE", - /* 63 */ "STABLE", - /* 64 */ "DATABASE", - /* 65 */ "TABLES", - /* 66 */ "STABLES", - /* 67 */ "VGROUPS", - /* 68 */ "DROP", - /* 69 */ "TOPIC", - /* 70 */ "DNODE", - /* 71 */ "USER", - /* 72 */ "ACCOUNT", - /* 73 */ "USE", - /* 74 */ "DESCRIBE", - /* 75 */ "ALTER", - /* 76 */ "PASS", - /* 77 */ "PRIVILEGE", - /* 78 */ "LOCAL", - /* 79 */ "COMPACT", - /* 80 */ "LP", - /* 81 */ "RP", - /* 82 */ "IF", - /* 83 */ "EXISTS", - /* 84 */ "PPS", - /* 85 */ "TSERIES", - /* 86 */ "DBS", - /* 87 */ "STORAGE", - /* 88 */ "QTIME", - /* 89 */ "CONNS", - /* 90 */ "STATE", - /* 91 */ "COMMA", - /* 92 */ "KEEP", - /* 93 */ "CACHE", - /* 94 */ "REPLICA", - /* 95 */ "QUORUM", - /* 96 */ "DAYS", - /* 97 */ "MINROWS", - /* 98 */ "MAXROWS", - /* 99 */ "BLOCKS", - /* 100 */ "CTIME", - /* 101 */ "WAL", - /* 102 */ "FSYNC", - /* 103 */ "COMP", - /* 104 */ "PRECISION", - /* 105 */ "UPDATE", - /* 106 */ "CACHELAST", - /* 107 */ "PARTITIONS", - /* 108 */ "UNSIGNED", - /* 109 */ "TAGS", - /* 110 */ "USING", - /* 111 */ "AS", - /* 112 */ "NULL", - /* 113 */ "NOW", - /* 114 */ "SELECT", - /* 115 */ "UNION", - /* 116 */ "ALL", - /* 117 */ "DISTINCT", - /* 118 */ "FROM", - /* 119 */ "VARIABLE", - /* 120 */ "INTERVAL", - /* 121 */ "SESSION", - /* 122 */ "STATE_WINDOW", - /* 123 */ "FILL", - /* 124 */ "SLIDING", - /* 125 */ "ORDER", - /* 126 */ "BY", - /* 127 */ "ASC", - /* 128 */ "DESC", - /* 129 */ "GROUP", - /* 130 */ "HAVING", - /* 131 */ "LIMIT", - /* 132 */ "OFFSET", - /* 133 */ "SLIMIT", - /* 134 */ "SOFFSET", - /* 135 */ "WHERE", - /* 136 */ "RESET", - /* 137 */ "QUERY", - /* 138 */ "SYNCDB", - /* 139 */ "ADD", - /* 140 */ "COLUMN", - /* 141 */ "MODIFY", - /* 142 */ "TAG", - /* 143 */ "CHANGE", - /* 144 */ "SET", - /* 145 */ "KILL", - /* 146 */ "CONNECTION", - /* 147 */ "STREAM", - /* 148 */ "COLON", - /* 149 */ "ABORT", - /* 150 */ "AFTER", - /* 151 */ "ATTACH", - /* 152 */ "BEFORE", - /* 153 */ "BEGIN", - /* 154 */ "CASCADE", - /* 155 */ "CLUSTER", - /* 156 */ "CONFLICT", - /* 157 */ "COPY", - /* 158 */ "DEFERRED", - /* 159 */ "DELIMITERS", - /* 160 */ "DETACH", - /* 161 */ "EACH", - /* 162 */ "END", - /* 163 */ "EXPLAIN", - /* 164 */ "FAIL", - /* 165 */ "FOR", - /* 166 */ "IGNORE", - /* 167 */ "IMMEDIATE", - /* 168 */ "INITIALLY", - /* 169 */ "INSTEAD", - /* 170 */ "MATCH", - /* 171 */ "KEY", - /* 172 */ "OF", - /* 173 */ "RAISE", - /* 174 */ "REPLACE", - /* 175 */ "RESTRICT", - /* 176 */ "ROW", - /* 177 */ "STATEMENT", - /* 178 */ "TRIGGER", - /* 179 */ "VIEW", - /* 180 */ "SEMI", - /* 181 */ "NONE", - /* 182 */ "PREV", - /* 183 */ "LINEAR", - /* 184 */ "IMPORT", - /* 185 */ "TBNAME", - /* 186 */ "JOIN", - /* 187 */ "INSERT", - /* 188 */ "INTO", - /* 189 */ "VALUES", - /* 190 */ "error", - /* 191 */ "program", - /* 192 */ "cmd", - /* 193 */ "dbPrefix", - /* 194 */ "ids", - /* 195 */ "cpxName", - /* 196 */ "ifexists", - /* 197 */ "alter_db_optr", - /* 198 */ "alter_topic_optr", - /* 199 */ "acct_optr", - /* 200 */ "exprlist", - /* 201 */ "ifnotexists", - /* 202 */ "db_optr", - /* 203 */ "topic_optr", - /* 204 */ "pps", - /* 205 */ "tseries", - /* 206 */ "dbs", - /* 207 */ "streams", - /* 208 */ "storage", - /* 209 */ "qtime", - /* 210 */ "users", - /* 211 */ "conns", - /* 212 */ "state", - /* 213 */ "intitemlist", - /* 214 */ "intitem", - /* 215 */ "keep", - /* 216 */ "cache", - /* 217 */ "replica", - /* 218 */ "quorum", - /* 219 */ "days", - /* 220 */ "minrows", - /* 221 */ "maxrows", - /* 222 */ "blocks", - /* 223 */ "ctime", - /* 224 */ "wal", - /* 225 */ "fsync", - /* 226 */ "comp", - /* 227 */ "prec", - /* 228 */ "update", - /* 229 */ "cachelast", - /* 230 */ "partitions", - /* 231 */ "typename", - /* 232 */ "signed", - /* 233 */ "create_table_args", - /* 234 */ "create_stable_args", - /* 235 */ "create_table_list", - /* 236 */ "create_from_stable", - /* 237 */ "columnlist", - /* 238 */ "tagitemlist", - /* 239 */ "tagNamelist", - /* 240 */ "select", - /* 241 */ "column", - /* 242 */ "tagitem", - /* 243 */ "selcollist", - /* 244 */ "from", - /* 245 */ "where_opt", - /* 246 */ "interval_opt", - /* 247 */ "session_option", - /* 248 */ "windowstate_option", - /* 249 */ "fill_opt", - /* 250 */ "sliding_opt", - /* 251 */ "groupby_opt", - /* 252 */ "having_opt", - /* 253 */ "orderby_opt", - /* 254 */ "slimit_opt", - /* 255 */ "limit_opt", - /* 256 */ "union", - /* 257 */ "sclp", - /* 258 */ "distinct", - /* 259 */ "expr", - /* 260 */ "as", - /* 261 */ "tablelist", - /* 262 */ "sub", - /* 263 */ "tmvar", - /* 264 */ "sortlist", - /* 265 */ "sortitem", - /* 266 */ "item", - /* 267 */ "sortorder", - /* 268 */ "grouplist", - /* 269 */ "expritem", + /* 47 */ "FUNCTIONS", + /* 48 */ "MNODES", + /* 49 */ "DNODES", + /* 50 */ "ACCOUNTS", + /* 51 */ "USERS", + /* 52 */ "MODULES", + /* 53 */ "QUERIES", + /* 54 */ "CONNECTIONS", + /* 55 */ "STREAMS", + /* 56 */ "VARIABLES", + /* 57 */ "SCORES", + /* 58 */ "GRANTS", + /* 59 */ "VNODES", + /* 60 */ "IPTOKEN", + /* 61 */ "DOT", + /* 62 */ "CREATE", + /* 63 */ "TABLE", + /* 64 */ "STABLE", + /* 65 */ "DATABASE", + /* 66 */ "TABLES", + /* 67 */ "STABLES", + /* 68 */ "VGROUPS", + /* 69 */ "DROP", + /* 70 */ "TOPIC", + /* 71 */ "FUNCTION", + /* 72 */ "DNODE", + /* 73 */ "USER", + /* 74 */ "ACCOUNT", + /* 75 */ "USE", + /* 76 */ "DESCRIBE", + /* 77 */ "ALTER", + /* 78 */ "PASS", + /* 79 */ "PRIVILEGE", + /* 80 */ "LOCAL", + /* 81 */ "COMPACT", + /* 82 */ "LP", + /* 83 */ "RP", + /* 84 */ "IF", + /* 85 */ "EXISTS", + /* 86 */ "AS", + /* 87 */ "OUTPUTTYPE", + /* 88 */ "AGGREGATE", + /* 89 */ "BUFSIZE", + /* 90 */ "PPS", + /* 91 */ "TSERIES", + /* 92 */ "DBS", + /* 93 */ "STORAGE", + /* 94 */ "QTIME", + /* 95 */ "CONNS", + /* 96 */ "STATE", + /* 97 */ "COMMA", + /* 98 */ "KEEP", + /* 99 */ "CACHE", + /* 100 */ "REPLICA", + /* 101 */ "QUORUM", + /* 102 */ "DAYS", + /* 103 */ "MINROWS", + /* 104 */ "MAXROWS", + /* 105 */ "BLOCKS", + /* 106 */ "CTIME", + /* 107 */ "WAL", + /* 108 */ "FSYNC", + /* 109 */ "COMP", + /* 110 */ "PRECISION", + /* 111 */ "UPDATE", + /* 112 */ "CACHELAST", + /* 113 */ "PARTITIONS", + /* 114 */ "UNSIGNED", + /* 115 */ "TAGS", + /* 116 */ "USING", + /* 117 */ "NULL", + /* 118 */ "NOW", + /* 119 */ "SELECT", + /* 120 */ "UNION", + /* 121 */ "ALL", + /* 122 */ "DISTINCT", + /* 123 */ "FROM", + /* 124 */ "VARIABLE", + /* 125 */ "INTERVAL", + /* 126 */ "SESSION", + /* 127 */ "STATE_WINDOW", + /* 128 */ "FILL", + /* 129 */ "SLIDING", + /* 130 */ "ORDER", + /* 131 */ "BY", + /* 132 */ "ASC", + /* 133 */ "DESC", + /* 134 */ "GROUP", + /* 135 */ "HAVING", + /* 136 */ "LIMIT", + /* 137 */ "OFFSET", + /* 138 */ "SLIMIT", + /* 139 */ "SOFFSET", + /* 140 */ "WHERE", + /* 141 */ "RESET", + /* 142 */ "QUERY", + /* 143 */ "SYNCDB", + /* 144 */ "ADD", + /* 145 */ "COLUMN", + /* 146 */ "MODIFY", + /* 147 */ "TAG", + /* 148 */ "CHANGE", + /* 149 */ "SET", + /* 150 */ "KILL", + /* 151 */ "CONNECTION", + /* 152 */ "STREAM", + /* 153 */ "COLON", + /* 154 */ "ABORT", + /* 155 */ "AFTER", + /* 156 */ "ATTACH", + /* 157 */ "BEFORE", + /* 158 */ "BEGIN", + /* 159 */ "CASCADE", + /* 160 */ "CLUSTER", + /* 161 */ "CONFLICT", + /* 162 */ "COPY", + /* 163 */ "DEFERRED", + /* 164 */ "DELIMITERS", + /* 165 */ "DETACH", + /* 166 */ "EACH", + /* 167 */ "END", + /* 168 */ "EXPLAIN", + /* 169 */ "FAIL", + /* 170 */ "FOR", + /* 171 */ "IGNORE", + /* 172 */ "IMMEDIATE", + /* 173 */ "INITIALLY", + /* 174 */ "INSTEAD", + /* 175 */ "MATCH", + /* 176 */ "KEY", + /* 177 */ "OF", + /* 178 */ "RAISE", + /* 179 */ "REPLACE", + /* 180 */ "RESTRICT", + /* 181 */ "ROW", + /* 182 */ "STATEMENT", + /* 183 */ "TRIGGER", + /* 184 */ "VIEW", + /* 185 */ "SEMI", + /* 186 */ "NONE", + /* 187 */ "PREV", + /* 188 */ "LINEAR", + /* 189 */ "IMPORT", + /* 190 */ "TBNAME", + /* 191 */ "JOIN", + /* 192 */ "INSERT", + /* 193 */ "INTO", + /* 194 */ "VALUES", + /* 195 */ "error", + /* 196 */ "program", + /* 197 */ "cmd", + /* 198 */ "dbPrefix", + /* 199 */ "ids", + /* 200 */ "cpxName", + /* 201 */ "ifexists", + /* 202 */ "alter_db_optr", + /* 203 */ "alter_topic_optr", + /* 204 */ "acct_optr", + /* 205 */ "exprlist", + /* 206 */ "ifnotexists", + /* 207 */ "db_optr", + /* 208 */ "topic_optr", + /* 209 */ "typename", + /* 210 */ "bufsize", + /* 211 */ "pps", + /* 212 */ "tseries", + /* 213 */ "dbs", + /* 214 */ "streams", + /* 215 */ "storage", + /* 216 */ "qtime", + /* 217 */ "users", + /* 218 */ "conns", + /* 219 */ "state", + /* 220 */ "intitemlist", + /* 221 */ "intitem", + /* 222 */ "keep", + /* 223 */ "cache", + /* 224 */ "replica", + /* 225 */ "quorum", + /* 226 */ "days", + /* 227 */ "minrows", + /* 228 */ "maxrows", + /* 229 */ "blocks", + /* 230 */ "ctime", + /* 231 */ "wal", + /* 232 */ "fsync", + /* 233 */ "comp", + /* 234 */ "prec", + /* 235 */ "update", + /* 236 */ "cachelast", + /* 237 */ "partitions", + /* 238 */ "signed", + /* 239 */ "create_table_args", + /* 240 */ "create_stable_args", + /* 241 */ "create_table_list", + /* 242 */ "create_from_stable", + /* 243 */ "columnlist", + /* 244 */ "tagitemlist", + /* 245 */ "tagNamelist", + /* 246 */ "select", + /* 247 */ "column", + /* 248 */ "tagitem", + /* 249 */ "selcollist", + /* 250 */ "from", + /* 251 */ "where_opt", + /* 252 */ "interval_opt", + /* 253 */ "session_option", + /* 254 */ "windowstate_option", + /* 255 */ "fill_opt", + /* 256 */ "sliding_opt", + /* 257 */ "groupby_opt", + /* 258 */ "having_opt", + /* 259 */ "orderby_opt", + /* 260 */ "slimit_opt", + /* 261 */ "limit_opt", + /* 262 */ "union", + /* 263 */ "sclp", + /* 264 */ "distinct", + /* 265 */ "expr", + /* 266 */ "as", + /* 267 */ "tablelist", + /* 268 */ "sub", + /* 269 */ "tmvar", + /* 270 */ "sortlist", + /* 271 */ "sortitem", + /* 272 */ "item", + /* 273 */ "sortorder", + /* 274 */ "grouplist", + /* 275 */ "expritem", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1052,286 +1072,292 @@ static const char *const yyRuleName[] = { /* 0 */ "program ::= cmd", /* 1 */ "cmd ::= SHOW DATABASES", /* 2 */ "cmd ::= SHOW TOPICS", - /* 3 */ "cmd ::= SHOW MNODES", - /* 4 */ "cmd ::= SHOW DNODES", - /* 5 */ "cmd ::= SHOW ACCOUNTS", - /* 6 */ "cmd ::= SHOW USERS", - /* 7 */ "cmd ::= SHOW MODULES", - /* 8 */ "cmd ::= SHOW QUERIES", - /* 9 */ "cmd ::= SHOW CONNECTIONS", - /* 10 */ "cmd ::= SHOW STREAMS", - /* 11 */ "cmd ::= SHOW VARIABLES", - /* 12 */ "cmd ::= SHOW SCORES", - /* 13 */ "cmd ::= SHOW GRANTS", - /* 14 */ "cmd ::= SHOW VNODES", - /* 15 */ "cmd ::= SHOW VNODES IPTOKEN", - /* 16 */ "dbPrefix ::=", - /* 17 */ "dbPrefix ::= ids DOT", - /* 18 */ "cpxName ::=", - /* 19 */ "cpxName ::= DOT ids", - /* 20 */ "cmd ::= SHOW CREATE TABLE ids cpxName", - /* 21 */ "cmd ::= SHOW CREATE STABLE ids cpxName", - /* 22 */ "cmd ::= SHOW CREATE DATABASE ids", - /* 23 */ "cmd ::= SHOW dbPrefix TABLES", - /* 24 */ "cmd ::= SHOW dbPrefix TABLES LIKE ids", - /* 25 */ "cmd ::= SHOW dbPrefix STABLES", - /* 26 */ "cmd ::= SHOW dbPrefix STABLES LIKE ids", - /* 27 */ "cmd ::= SHOW dbPrefix VGROUPS", - /* 28 */ "cmd ::= SHOW dbPrefix VGROUPS ids", - /* 29 */ "cmd ::= DROP TABLE ifexists ids cpxName", - /* 30 */ "cmd ::= DROP STABLE ifexists ids cpxName", - /* 31 */ "cmd ::= DROP DATABASE ifexists ids", - /* 32 */ "cmd ::= DROP TOPIC ifexists ids", - /* 33 */ "cmd ::= DROP DNODE ids", - /* 34 */ "cmd ::= DROP USER ids", - /* 35 */ "cmd ::= DROP ACCOUNT ids", - /* 36 */ "cmd ::= USE ids", - /* 37 */ "cmd ::= DESCRIBE ids cpxName", - /* 38 */ "cmd ::= ALTER USER ids PASS ids", - /* 39 */ "cmd ::= ALTER USER ids PRIVILEGE ids", - /* 40 */ "cmd ::= ALTER DNODE ids ids", - /* 41 */ "cmd ::= ALTER DNODE ids ids ids", - /* 42 */ "cmd ::= ALTER LOCAL ids", - /* 43 */ "cmd ::= ALTER LOCAL ids ids", - /* 44 */ "cmd ::= ALTER DATABASE ids alter_db_optr", - /* 45 */ "cmd ::= ALTER TOPIC ids alter_topic_optr", - /* 46 */ "cmd ::= ALTER ACCOUNT ids acct_optr", - /* 47 */ "cmd ::= ALTER ACCOUNT ids PASS ids acct_optr", - /* 48 */ "cmd ::= COMPACT VNODES IN LP exprlist RP", - /* 49 */ "ids ::= ID", - /* 50 */ "ids ::= STRING", - /* 51 */ "ifexists ::= IF EXISTS", - /* 52 */ "ifexists ::=", - /* 53 */ "ifnotexists ::= IF NOT EXISTS", - /* 54 */ "ifnotexists ::=", - /* 55 */ "cmd ::= CREATE DNODE ids", - /* 56 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", - /* 57 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", - /* 58 */ "cmd ::= CREATE TOPIC ifnotexists ids topic_optr", - /* 59 */ "cmd ::= CREATE USER ids PASS ids", - /* 60 */ "pps ::=", - /* 61 */ "pps ::= PPS INTEGER", - /* 62 */ "tseries ::=", - /* 63 */ "tseries ::= TSERIES INTEGER", - /* 64 */ "dbs ::=", - /* 65 */ "dbs ::= DBS INTEGER", - /* 66 */ "streams ::=", - /* 67 */ "streams ::= STREAMS INTEGER", - /* 68 */ "storage ::=", - /* 69 */ "storage ::= STORAGE INTEGER", - /* 70 */ "qtime ::=", - /* 71 */ "qtime ::= QTIME INTEGER", - /* 72 */ "users ::=", - /* 73 */ "users ::= USERS INTEGER", - /* 74 */ "conns ::=", - /* 75 */ "conns ::= CONNS INTEGER", - /* 76 */ "state ::=", - /* 77 */ "state ::= STATE ids", - /* 78 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", - /* 79 */ "intitemlist ::= intitemlist COMMA intitem", - /* 80 */ "intitemlist ::= intitem", - /* 81 */ "intitem ::= INTEGER", - /* 82 */ "keep ::= KEEP intitemlist", - /* 83 */ "cache ::= CACHE INTEGER", - /* 84 */ "replica ::= REPLICA INTEGER", - /* 85 */ "quorum ::= QUORUM INTEGER", - /* 86 */ "days ::= DAYS INTEGER", - /* 87 */ "minrows ::= MINROWS INTEGER", - /* 88 */ "maxrows ::= MAXROWS INTEGER", - /* 89 */ "blocks ::= BLOCKS INTEGER", - /* 90 */ "ctime ::= CTIME INTEGER", - /* 91 */ "wal ::= WAL INTEGER", - /* 92 */ "fsync ::= FSYNC INTEGER", - /* 93 */ "comp ::= COMP INTEGER", - /* 94 */ "prec ::= PRECISION STRING", - /* 95 */ "update ::= UPDATE INTEGER", - /* 96 */ "cachelast ::= CACHELAST INTEGER", - /* 97 */ "partitions ::= PARTITIONS INTEGER", - /* 98 */ "db_optr ::=", - /* 99 */ "db_optr ::= db_optr cache", - /* 100 */ "db_optr ::= db_optr replica", - /* 101 */ "db_optr ::= db_optr quorum", - /* 102 */ "db_optr ::= db_optr days", - /* 103 */ "db_optr ::= db_optr minrows", - /* 104 */ "db_optr ::= db_optr maxrows", - /* 105 */ "db_optr ::= db_optr blocks", - /* 106 */ "db_optr ::= db_optr ctime", - /* 107 */ "db_optr ::= db_optr wal", - /* 108 */ "db_optr ::= db_optr fsync", - /* 109 */ "db_optr ::= db_optr comp", - /* 110 */ "db_optr ::= db_optr prec", - /* 111 */ "db_optr ::= db_optr keep", - /* 112 */ "db_optr ::= db_optr update", - /* 113 */ "db_optr ::= db_optr cachelast", - /* 114 */ "topic_optr ::= db_optr", - /* 115 */ "topic_optr ::= topic_optr partitions", - /* 116 */ "alter_db_optr ::=", - /* 117 */ "alter_db_optr ::= alter_db_optr replica", - /* 118 */ "alter_db_optr ::= alter_db_optr quorum", - /* 119 */ "alter_db_optr ::= alter_db_optr keep", - /* 120 */ "alter_db_optr ::= alter_db_optr blocks", - /* 121 */ "alter_db_optr ::= alter_db_optr comp", - /* 122 */ "alter_db_optr ::= alter_db_optr update", - /* 123 */ "alter_db_optr ::= alter_db_optr cachelast", - /* 124 */ "alter_topic_optr ::= alter_db_optr", - /* 125 */ "alter_topic_optr ::= alter_topic_optr partitions", - /* 126 */ "typename ::= ids", - /* 127 */ "typename ::= ids LP signed RP", - /* 128 */ "typename ::= ids UNSIGNED", - /* 129 */ "signed ::= INTEGER", - /* 130 */ "signed ::= PLUS INTEGER", - /* 131 */ "signed ::= MINUS INTEGER", - /* 132 */ "cmd ::= CREATE TABLE create_table_args", - /* 133 */ "cmd ::= CREATE TABLE create_stable_args", - /* 134 */ "cmd ::= CREATE STABLE create_stable_args", - /* 135 */ "cmd ::= CREATE TABLE create_table_list", - /* 136 */ "create_table_list ::= create_from_stable", - /* 137 */ "create_table_list ::= create_table_list create_from_stable", - /* 138 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", - /* 139 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", - /* 140 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP", - /* 141 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP", - /* 142 */ "tagNamelist ::= tagNamelist COMMA ids", - /* 143 */ "tagNamelist ::= ids", - /* 144 */ "create_table_args ::= ifnotexists ids cpxName AS select", - /* 145 */ "columnlist ::= columnlist COMMA column", - /* 146 */ "columnlist ::= column", - /* 147 */ "column ::= ids typename", - /* 148 */ "tagitemlist ::= tagitemlist COMMA tagitem", - /* 149 */ "tagitemlist ::= tagitem", - /* 150 */ "tagitem ::= INTEGER", - /* 151 */ "tagitem ::= FLOAT", - /* 152 */ "tagitem ::= STRING", - /* 153 */ "tagitem ::= BOOL", - /* 154 */ "tagitem ::= NULL", - /* 155 */ "tagitem ::= NOW", - /* 156 */ "tagitem ::= MINUS INTEGER", - /* 157 */ "tagitem ::= MINUS FLOAT", - /* 158 */ "tagitem ::= PLUS INTEGER", - /* 159 */ "tagitem ::= PLUS FLOAT", - /* 160 */ "select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", - /* 161 */ "select ::= LP select RP", - /* 162 */ "union ::= select", - /* 163 */ "union ::= union UNION ALL select", - /* 164 */ "cmd ::= union", - /* 165 */ "select ::= SELECT selcollist", - /* 166 */ "sclp ::= selcollist COMMA", - /* 167 */ "sclp ::=", - /* 168 */ "selcollist ::= sclp distinct expr as", - /* 169 */ "selcollist ::= sclp STAR", - /* 170 */ "as ::= AS ids", - /* 171 */ "as ::= ids", - /* 172 */ "as ::=", - /* 173 */ "distinct ::= DISTINCT", - /* 174 */ "distinct ::=", - /* 175 */ "from ::= FROM tablelist", - /* 176 */ "from ::= FROM sub", - /* 177 */ "sub ::= LP union RP", - /* 178 */ "sub ::= LP union RP ids", - /* 179 */ "sub ::= sub COMMA LP union RP ids", - /* 180 */ "tablelist ::= ids cpxName", - /* 181 */ "tablelist ::= ids cpxName ids", - /* 182 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 183 */ "tablelist ::= tablelist COMMA ids cpxName ids", - /* 184 */ "tmvar ::= VARIABLE", - /* 185 */ "interval_opt ::= INTERVAL LP tmvar RP", - /* 186 */ "interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP", - /* 187 */ "interval_opt ::=", - /* 188 */ "session_option ::=", - /* 189 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 190 */ "windowstate_option ::=", - /* 191 */ "windowstate_option ::= STATE_WINDOW LP ids RP", - /* 192 */ "fill_opt ::=", - /* 193 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 194 */ "fill_opt ::= FILL LP ID RP", - /* 195 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 196 */ "sliding_opt ::=", - /* 197 */ "orderby_opt ::=", - /* 198 */ "orderby_opt ::= ORDER BY sortlist", - /* 199 */ "sortlist ::= sortlist COMMA item sortorder", - /* 200 */ "sortlist ::= item sortorder", - /* 201 */ "item ::= ids cpxName", - /* 202 */ "sortorder ::= ASC", - /* 203 */ "sortorder ::= DESC", - /* 204 */ "sortorder ::=", - /* 205 */ "groupby_opt ::=", - /* 206 */ "groupby_opt ::= GROUP BY grouplist", - /* 207 */ "grouplist ::= grouplist COMMA item", - /* 208 */ "grouplist ::= item", - /* 209 */ "having_opt ::=", - /* 210 */ "having_opt ::= HAVING expr", - /* 211 */ "limit_opt ::=", - /* 212 */ "limit_opt ::= LIMIT signed", - /* 213 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 214 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 215 */ "slimit_opt ::=", - /* 216 */ "slimit_opt ::= SLIMIT signed", - /* 217 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 218 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 219 */ "where_opt ::=", - /* 220 */ "where_opt ::= WHERE expr", - /* 221 */ "expr ::= LP expr RP", - /* 222 */ "expr ::= ID", - /* 223 */ "expr ::= ID DOT ID", - /* 224 */ "expr ::= ID DOT STAR", - /* 225 */ "expr ::= INTEGER", - /* 226 */ "expr ::= MINUS INTEGER", - /* 227 */ "expr ::= PLUS INTEGER", - /* 228 */ "expr ::= FLOAT", - /* 229 */ "expr ::= MINUS FLOAT", - /* 230 */ "expr ::= PLUS FLOAT", - /* 231 */ "expr ::= STRING", - /* 232 */ "expr ::= NOW", - /* 233 */ "expr ::= VARIABLE", - /* 234 */ "expr ::= PLUS VARIABLE", - /* 235 */ "expr ::= MINUS VARIABLE", - /* 236 */ "expr ::= BOOL", - /* 237 */ "expr ::= NULL", - /* 238 */ "expr ::= ID LP exprlist RP", - /* 239 */ "expr ::= ID LP STAR RP", - /* 240 */ "expr ::= expr IS NULL", - /* 241 */ "expr ::= expr IS NOT NULL", - /* 242 */ "expr ::= expr LT expr", - /* 243 */ "expr ::= expr GT expr", - /* 244 */ "expr ::= expr LE expr", - /* 245 */ "expr ::= expr GE expr", - /* 246 */ "expr ::= expr NE expr", - /* 247 */ "expr ::= expr EQ expr", - /* 248 */ "expr ::= expr BETWEEN expr AND expr", - /* 249 */ "expr ::= expr AND expr", - /* 250 */ "expr ::= expr OR expr", - /* 251 */ "expr ::= expr PLUS expr", - /* 252 */ "expr ::= expr MINUS expr", - /* 253 */ "expr ::= expr STAR expr", - /* 254 */ "expr ::= expr SLASH expr", - /* 255 */ "expr ::= expr REM expr", - /* 256 */ "expr ::= expr LIKE expr", - /* 257 */ "expr ::= expr IN LP exprlist RP", - /* 258 */ "exprlist ::= exprlist COMMA expritem", - /* 259 */ "exprlist ::= expritem", - /* 260 */ "expritem ::= expr", - /* 261 */ "expritem ::=", - /* 262 */ "cmd ::= RESET QUERY CACHE", - /* 263 */ "cmd ::= SYNCDB ids REPLICA", - /* 264 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 265 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 266 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", - /* 267 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 268 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 269 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 270 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 271 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", - /* 272 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 273 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 274 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", - /* 275 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 276 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 277 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 278 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", - /* 279 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", - /* 280 */ "cmd ::= KILL CONNECTION INTEGER", - /* 281 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 282 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 3 */ "cmd ::= SHOW FUNCTIONS", + /* 4 */ "cmd ::= SHOW MNODES", + /* 5 */ "cmd ::= SHOW DNODES", + /* 6 */ "cmd ::= SHOW ACCOUNTS", + /* 7 */ "cmd ::= SHOW USERS", + /* 8 */ "cmd ::= SHOW MODULES", + /* 9 */ "cmd ::= SHOW QUERIES", + /* 10 */ "cmd ::= SHOW CONNECTIONS", + /* 11 */ "cmd ::= SHOW STREAMS", + /* 12 */ "cmd ::= SHOW VARIABLES", + /* 13 */ "cmd ::= SHOW SCORES", + /* 14 */ "cmd ::= SHOW GRANTS", + /* 15 */ "cmd ::= SHOW VNODES", + /* 16 */ "cmd ::= SHOW VNODES IPTOKEN", + /* 17 */ "dbPrefix ::=", + /* 18 */ "dbPrefix ::= ids DOT", + /* 19 */ "cpxName ::=", + /* 20 */ "cpxName ::= DOT ids", + /* 21 */ "cmd ::= SHOW CREATE TABLE ids cpxName", + /* 22 */ "cmd ::= SHOW CREATE STABLE ids cpxName", + /* 23 */ "cmd ::= SHOW CREATE DATABASE ids", + /* 24 */ "cmd ::= SHOW dbPrefix TABLES", + /* 25 */ "cmd ::= SHOW dbPrefix TABLES LIKE ids", + /* 26 */ "cmd ::= SHOW dbPrefix STABLES", + /* 27 */ "cmd ::= SHOW dbPrefix STABLES LIKE ids", + /* 28 */ "cmd ::= SHOW dbPrefix VGROUPS", + /* 29 */ "cmd ::= SHOW dbPrefix VGROUPS ids", + /* 30 */ "cmd ::= DROP TABLE ifexists ids cpxName", + /* 31 */ "cmd ::= DROP STABLE ifexists ids cpxName", + /* 32 */ "cmd ::= DROP DATABASE ifexists ids", + /* 33 */ "cmd ::= DROP TOPIC ifexists ids", + /* 34 */ "cmd ::= DROP FUNCTION ids", + /* 35 */ "cmd ::= DROP DNODE ids", + /* 36 */ "cmd ::= DROP USER ids", + /* 37 */ "cmd ::= DROP ACCOUNT ids", + /* 38 */ "cmd ::= USE ids", + /* 39 */ "cmd ::= DESCRIBE ids cpxName", + /* 40 */ "cmd ::= ALTER USER ids PASS ids", + /* 41 */ "cmd ::= ALTER USER ids PRIVILEGE ids", + /* 42 */ "cmd ::= ALTER DNODE ids ids", + /* 43 */ "cmd ::= ALTER DNODE ids ids ids", + /* 44 */ "cmd ::= ALTER LOCAL ids", + /* 45 */ "cmd ::= ALTER LOCAL ids ids", + /* 46 */ "cmd ::= ALTER DATABASE ids alter_db_optr", + /* 47 */ "cmd ::= ALTER TOPIC ids alter_topic_optr", + /* 48 */ "cmd ::= ALTER ACCOUNT ids acct_optr", + /* 49 */ "cmd ::= ALTER ACCOUNT ids PASS ids acct_optr", + /* 50 */ "cmd ::= COMPACT VNODES IN LP exprlist RP", + /* 51 */ "ids ::= ID", + /* 52 */ "ids ::= STRING", + /* 53 */ "ifexists ::= IF EXISTS", + /* 54 */ "ifexists ::=", + /* 55 */ "ifnotexists ::= IF NOT EXISTS", + /* 56 */ "ifnotexists ::=", + /* 57 */ "cmd ::= CREATE DNODE ids", + /* 58 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", + /* 59 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", + /* 60 */ "cmd ::= CREATE TOPIC ifnotexists ids topic_optr", + /* 61 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 62 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 63 */ "cmd ::= CREATE USER ids PASS ids", + /* 64 */ "bufsize ::=", + /* 65 */ "bufsize ::= BUFSIZE INTEGER", + /* 66 */ "pps ::=", + /* 67 */ "pps ::= PPS INTEGER", + /* 68 */ "tseries ::=", + /* 69 */ "tseries ::= TSERIES INTEGER", + /* 70 */ "dbs ::=", + /* 71 */ "dbs ::= DBS INTEGER", + /* 72 */ "streams ::=", + /* 73 */ "streams ::= STREAMS INTEGER", + /* 74 */ "storage ::=", + /* 75 */ "storage ::= STORAGE INTEGER", + /* 76 */ "qtime ::=", + /* 77 */ "qtime ::= QTIME INTEGER", + /* 78 */ "users ::=", + /* 79 */ "users ::= USERS INTEGER", + /* 80 */ "conns ::=", + /* 81 */ "conns ::= CONNS INTEGER", + /* 82 */ "state ::=", + /* 83 */ "state ::= STATE ids", + /* 84 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", + /* 85 */ "intitemlist ::= intitemlist COMMA intitem", + /* 86 */ "intitemlist ::= intitem", + /* 87 */ "intitem ::= INTEGER", + /* 88 */ "keep ::= KEEP intitemlist", + /* 89 */ "cache ::= CACHE INTEGER", + /* 90 */ "replica ::= REPLICA INTEGER", + /* 91 */ "quorum ::= QUORUM INTEGER", + /* 92 */ "days ::= DAYS INTEGER", + /* 93 */ "minrows ::= MINROWS INTEGER", + /* 94 */ "maxrows ::= MAXROWS INTEGER", + /* 95 */ "blocks ::= BLOCKS INTEGER", + /* 96 */ "ctime ::= CTIME INTEGER", + /* 97 */ "wal ::= WAL INTEGER", + /* 98 */ "fsync ::= FSYNC INTEGER", + /* 99 */ "comp ::= COMP INTEGER", + /* 100 */ "prec ::= PRECISION STRING", + /* 101 */ "update ::= UPDATE INTEGER", + /* 102 */ "cachelast ::= CACHELAST INTEGER", + /* 103 */ "partitions ::= PARTITIONS INTEGER", + /* 104 */ "db_optr ::=", + /* 105 */ "db_optr ::= db_optr cache", + /* 106 */ "db_optr ::= db_optr replica", + /* 107 */ "db_optr ::= db_optr quorum", + /* 108 */ "db_optr ::= db_optr days", + /* 109 */ "db_optr ::= db_optr minrows", + /* 110 */ "db_optr ::= db_optr maxrows", + /* 111 */ "db_optr ::= db_optr blocks", + /* 112 */ "db_optr ::= db_optr ctime", + /* 113 */ "db_optr ::= db_optr wal", + /* 114 */ "db_optr ::= db_optr fsync", + /* 115 */ "db_optr ::= db_optr comp", + /* 116 */ "db_optr ::= db_optr prec", + /* 117 */ "db_optr ::= db_optr keep", + /* 118 */ "db_optr ::= db_optr update", + /* 119 */ "db_optr ::= db_optr cachelast", + /* 120 */ "topic_optr ::= db_optr", + /* 121 */ "topic_optr ::= topic_optr partitions", + /* 122 */ "alter_db_optr ::=", + /* 123 */ "alter_db_optr ::= alter_db_optr replica", + /* 124 */ "alter_db_optr ::= alter_db_optr quorum", + /* 125 */ "alter_db_optr ::= alter_db_optr keep", + /* 126 */ "alter_db_optr ::= alter_db_optr blocks", + /* 127 */ "alter_db_optr ::= alter_db_optr comp", + /* 128 */ "alter_db_optr ::= alter_db_optr update", + /* 129 */ "alter_db_optr ::= alter_db_optr cachelast", + /* 130 */ "alter_topic_optr ::= alter_db_optr", + /* 131 */ "alter_topic_optr ::= alter_topic_optr partitions", + /* 132 */ "typename ::= ids", + /* 133 */ "typename ::= ids LP signed RP", + /* 134 */ "typename ::= ids UNSIGNED", + /* 135 */ "signed ::= INTEGER", + /* 136 */ "signed ::= PLUS INTEGER", + /* 137 */ "signed ::= MINUS INTEGER", + /* 138 */ "cmd ::= CREATE TABLE create_table_args", + /* 139 */ "cmd ::= CREATE TABLE create_stable_args", + /* 140 */ "cmd ::= CREATE STABLE create_stable_args", + /* 141 */ "cmd ::= CREATE TABLE create_table_list", + /* 142 */ "create_table_list ::= create_from_stable", + /* 143 */ "create_table_list ::= create_table_list create_from_stable", + /* 144 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", + /* 145 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", + /* 146 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP", + /* 147 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP", + /* 148 */ "tagNamelist ::= tagNamelist COMMA ids", + /* 149 */ "tagNamelist ::= ids", + /* 150 */ "create_table_args ::= ifnotexists ids cpxName AS select", + /* 151 */ "columnlist ::= columnlist COMMA column", + /* 152 */ "columnlist ::= column", + /* 153 */ "column ::= ids typename", + /* 154 */ "tagitemlist ::= tagitemlist COMMA tagitem", + /* 155 */ "tagitemlist ::= tagitem", + /* 156 */ "tagitem ::= INTEGER", + /* 157 */ "tagitem ::= FLOAT", + /* 158 */ "tagitem ::= STRING", + /* 159 */ "tagitem ::= BOOL", + /* 160 */ "tagitem ::= NULL", + /* 161 */ "tagitem ::= NOW", + /* 162 */ "tagitem ::= MINUS INTEGER", + /* 163 */ "tagitem ::= MINUS FLOAT", + /* 164 */ "tagitem ::= PLUS INTEGER", + /* 165 */ "tagitem ::= PLUS FLOAT", + /* 166 */ "select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", + /* 167 */ "select ::= LP select RP", + /* 168 */ "union ::= select", + /* 169 */ "union ::= union UNION ALL select", + /* 170 */ "cmd ::= union", + /* 171 */ "select ::= SELECT selcollist", + /* 172 */ "sclp ::= selcollist COMMA", + /* 173 */ "sclp ::=", + /* 174 */ "selcollist ::= sclp distinct expr as", + /* 175 */ "selcollist ::= sclp STAR", + /* 176 */ "as ::= AS ids", + /* 177 */ "as ::= ids", + /* 178 */ "as ::=", + /* 179 */ "distinct ::= DISTINCT", + /* 180 */ "distinct ::=", + /* 181 */ "from ::= FROM tablelist", + /* 182 */ "from ::= FROM sub", + /* 183 */ "sub ::= LP union RP", + /* 184 */ "sub ::= LP union RP ids", + /* 185 */ "sub ::= sub COMMA LP union RP ids", + /* 186 */ "tablelist ::= ids cpxName", + /* 187 */ "tablelist ::= ids cpxName ids", + /* 188 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 189 */ "tablelist ::= tablelist COMMA ids cpxName ids", + /* 190 */ "tmvar ::= VARIABLE", + /* 191 */ "interval_opt ::= INTERVAL LP tmvar RP", + /* 192 */ "interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP", + /* 193 */ "interval_opt ::=", + /* 194 */ "session_option ::=", + /* 195 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 196 */ "windowstate_option ::=", + /* 197 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 198 */ "fill_opt ::=", + /* 199 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 200 */ "fill_opt ::= FILL LP ID RP", + /* 201 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 202 */ "sliding_opt ::=", + /* 203 */ "orderby_opt ::=", + /* 204 */ "orderby_opt ::= ORDER BY sortlist", + /* 205 */ "sortlist ::= sortlist COMMA item sortorder", + /* 206 */ "sortlist ::= item sortorder", + /* 207 */ "item ::= ids cpxName", + /* 208 */ "sortorder ::= ASC", + /* 209 */ "sortorder ::= DESC", + /* 210 */ "sortorder ::=", + /* 211 */ "groupby_opt ::=", + /* 212 */ "groupby_opt ::= GROUP BY grouplist", + /* 213 */ "grouplist ::= grouplist COMMA item", + /* 214 */ "grouplist ::= item", + /* 215 */ "having_opt ::=", + /* 216 */ "having_opt ::= HAVING expr", + /* 217 */ "limit_opt ::=", + /* 218 */ "limit_opt ::= LIMIT signed", + /* 219 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 220 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 221 */ "slimit_opt ::=", + /* 222 */ "slimit_opt ::= SLIMIT signed", + /* 223 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 224 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 225 */ "where_opt ::=", + /* 226 */ "where_opt ::= WHERE expr", + /* 227 */ "expr ::= LP expr RP", + /* 228 */ "expr ::= ID", + /* 229 */ "expr ::= ID DOT ID", + /* 230 */ "expr ::= ID DOT STAR", + /* 231 */ "expr ::= INTEGER", + /* 232 */ "expr ::= MINUS INTEGER", + /* 233 */ "expr ::= PLUS INTEGER", + /* 234 */ "expr ::= FLOAT", + /* 235 */ "expr ::= MINUS FLOAT", + /* 236 */ "expr ::= PLUS FLOAT", + /* 237 */ "expr ::= STRING", + /* 238 */ "expr ::= NOW", + /* 239 */ "expr ::= VARIABLE", + /* 240 */ "expr ::= PLUS VARIABLE", + /* 241 */ "expr ::= MINUS VARIABLE", + /* 242 */ "expr ::= BOOL", + /* 243 */ "expr ::= NULL", + /* 244 */ "expr ::= ID LP exprlist RP", + /* 245 */ "expr ::= ID LP STAR RP", + /* 246 */ "expr ::= expr IS NULL", + /* 247 */ "expr ::= expr IS NOT NULL", + /* 248 */ "expr ::= expr LT expr", + /* 249 */ "expr ::= expr GT expr", + /* 250 */ "expr ::= expr LE expr", + /* 251 */ "expr ::= expr GE expr", + /* 252 */ "expr ::= expr NE expr", + /* 253 */ "expr ::= expr EQ expr", + /* 254 */ "expr ::= expr BETWEEN expr AND expr", + /* 255 */ "expr ::= expr AND expr", + /* 256 */ "expr ::= expr OR expr", + /* 257 */ "expr ::= expr PLUS expr", + /* 258 */ "expr ::= expr MINUS expr", + /* 259 */ "expr ::= expr STAR expr", + /* 260 */ "expr ::= expr SLASH expr", + /* 261 */ "expr ::= expr REM expr", + /* 262 */ "expr ::= expr LIKE expr", + /* 263 */ "expr ::= expr IN LP exprlist RP", + /* 264 */ "exprlist ::= exprlist COMMA expritem", + /* 265 */ "exprlist ::= expritem", + /* 266 */ "expritem ::= expr", + /* 267 */ "expritem ::=", + /* 268 */ "cmd ::= RESET QUERY CACHE", + /* 269 */ "cmd ::= SYNCDB ids REPLICA", + /* 270 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 271 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 272 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", + /* 273 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 274 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 275 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 276 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 277 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", + /* 278 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 279 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 280 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", + /* 281 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 282 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 283 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 284 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", + /* 285 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", + /* 286 */ "cmd ::= KILL CONNECTION INTEGER", + /* 287 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 288 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1452,58 +1478,58 @@ static void yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 200: /* exprlist */ - case 243: /* selcollist */ - case 257: /* sclp */ + case 205: /* exprlist */ + case 249: /* selcollist */ + case 263: /* sclp */ { -tSqlExprListDestroy((yypminor->yy441)); +tSqlExprListDestroy((yypminor->yy525)); } break; - case 213: /* intitemlist */ - case 215: /* keep */ - case 237: /* columnlist */ - case 238: /* tagitemlist */ - case 239: /* tagNamelist */ - case 249: /* fill_opt */ - case 251: /* groupby_opt */ - case 253: /* orderby_opt */ - case 264: /* sortlist */ - case 268: /* grouplist */ -{ -taosArrayDestroy((yypminor->yy441)); + case 220: /* intitemlist */ + case 222: /* keep */ + case 243: /* columnlist */ + case 244: /* tagitemlist */ + case 245: /* tagNamelist */ + case 255: /* fill_opt */ + case 257: /* groupby_opt */ + case 259: /* orderby_opt */ + case 270: /* sortlist */ + case 274: /* grouplist */ +{ +taosArrayDestroy((yypminor->yy525)); } break; - case 235: /* create_table_list */ + case 241: /* create_table_list */ { -destroyCreateTableSql((yypminor->yy182)); +destroyCreateTableSql((yypminor->yy158)); } break; - case 240: /* select */ + case 246: /* select */ { -destroySqlNode((yypminor->yy236)); +destroySqlNode((yypminor->yy464)); } break; - case 244: /* from */ - case 261: /* tablelist */ - case 262: /* sub */ + case 250: /* from */ + case 267: /* tablelist */ + case 268: /* sub */ { -destroyRelationInfo((yypminor->yy244)); +destroyRelationInfo((yypminor->yy412)); } break; - case 245: /* where_opt */ - case 252: /* having_opt */ - case 259: /* expr */ - case 269: /* expritem */ + case 251: /* where_opt */ + case 258: /* having_opt */ + case 265: /* expr */ + case 275: /* expritem */ { -tSqlExprDestroy((yypminor->yy166)); +tSqlExprDestroy((yypminor->yy370)); } break; - case 256: /* union */ + case 262: /* union */ { -destroyAllSqlNode((yypminor->yy441)); +destroyAllSqlNode((yypminor->yy525)); } break; - case 265: /* sortitem */ + case 271: /* sortitem */ { tVariantDestroy(&(yypminor->yy506)); } @@ -1799,289 +1825,295 @@ 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[] = { - { 191, -1 }, /* (0) program ::= cmd */ - { 192, -2 }, /* (1) cmd ::= SHOW DATABASES */ - { 192, -2 }, /* (2) cmd ::= SHOW TOPICS */ - { 192, -2 }, /* (3) cmd ::= SHOW MNODES */ - { 192, -2 }, /* (4) cmd ::= SHOW DNODES */ - { 192, -2 }, /* (5) cmd ::= SHOW ACCOUNTS */ - { 192, -2 }, /* (6) cmd ::= SHOW USERS */ - { 192, -2 }, /* (7) cmd ::= SHOW MODULES */ - { 192, -2 }, /* (8) cmd ::= SHOW QUERIES */ - { 192, -2 }, /* (9) cmd ::= SHOW CONNECTIONS */ - { 192, -2 }, /* (10) cmd ::= SHOW STREAMS */ - { 192, -2 }, /* (11) cmd ::= SHOW VARIABLES */ - { 192, -2 }, /* (12) cmd ::= SHOW SCORES */ - { 192, -2 }, /* (13) cmd ::= SHOW GRANTS */ - { 192, -2 }, /* (14) cmd ::= SHOW VNODES */ - { 192, -3 }, /* (15) cmd ::= SHOW VNODES IPTOKEN */ - { 193, 0 }, /* (16) dbPrefix ::= */ - { 193, -2 }, /* (17) dbPrefix ::= ids DOT */ - { 195, 0 }, /* (18) cpxName ::= */ - { 195, -2 }, /* (19) cpxName ::= DOT ids */ - { 192, -5 }, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */ - { 192, -5 }, /* (21) cmd ::= SHOW CREATE STABLE ids cpxName */ - { 192, -4 }, /* (22) cmd ::= SHOW CREATE DATABASE ids */ - { 192, -3 }, /* (23) cmd ::= SHOW dbPrefix TABLES */ - { 192, -5 }, /* (24) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - { 192, -3 }, /* (25) cmd ::= SHOW dbPrefix STABLES */ - { 192, -5 }, /* (26) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - { 192, -3 }, /* (27) cmd ::= SHOW dbPrefix VGROUPS */ - { 192, -4 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS ids */ - { 192, -5 }, /* (29) cmd ::= DROP TABLE ifexists ids cpxName */ - { 192, -5 }, /* (30) cmd ::= DROP STABLE ifexists ids cpxName */ - { 192, -4 }, /* (31) cmd ::= DROP DATABASE ifexists ids */ - { 192, -4 }, /* (32) cmd ::= DROP TOPIC ifexists ids */ - { 192, -3 }, /* (33) cmd ::= DROP DNODE ids */ - { 192, -3 }, /* (34) cmd ::= DROP USER ids */ - { 192, -3 }, /* (35) cmd ::= DROP ACCOUNT ids */ - { 192, -2 }, /* (36) cmd ::= USE ids */ - { 192, -3 }, /* (37) cmd ::= DESCRIBE ids cpxName */ - { 192, -5 }, /* (38) cmd ::= ALTER USER ids PASS ids */ - { 192, -5 }, /* (39) cmd ::= ALTER USER ids PRIVILEGE ids */ - { 192, -4 }, /* (40) cmd ::= ALTER DNODE ids ids */ - { 192, -5 }, /* (41) cmd ::= ALTER DNODE ids ids ids */ - { 192, -3 }, /* (42) cmd ::= ALTER LOCAL ids */ - { 192, -4 }, /* (43) cmd ::= ALTER LOCAL ids ids */ - { 192, -4 }, /* (44) cmd ::= ALTER DATABASE ids alter_db_optr */ - { 192, -4 }, /* (45) cmd ::= ALTER TOPIC ids alter_topic_optr */ - { 192, -4 }, /* (46) cmd ::= ALTER ACCOUNT ids acct_optr */ - { 192, -6 }, /* (47) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - { 192, -6 }, /* (48) cmd ::= COMPACT VNODES IN LP exprlist RP */ - { 194, -1 }, /* (49) ids ::= ID */ - { 194, -1 }, /* (50) ids ::= STRING */ - { 196, -2 }, /* (51) ifexists ::= IF EXISTS */ - { 196, 0 }, /* (52) ifexists ::= */ - { 201, -3 }, /* (53) ifnotexists ::= IF NOT EXISTS */ - { 201, 0 }, /* (54) ifnotexists ::= */ - { 192, -3 }, /* (55) cmd ::= CREATE DNODE ids */ - { 192, -6 }, /* (56) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 192, -5 }, /* (57) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 192, -5 }, /* (58) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ - { 192, -5 }, /* (59) cmd ::= CREATE USER ids PASS ids */ - { 204, 0 }, /* (60) pps ::= */ - { 204, -2 }, /* (61) pps ::= PPS INTEGER */ - { 205, 0 }, /* (62) tseries ::= */ - { 205, -2 }, /* (63) tseries ::= TSERIES INTEGER */ - { 206, 0 }, /* (64) dbs ::= */ - { 206, -2 }, /* (65) dbs ::= DBS INTEGER */ - { 207, 0 }, /* (66) streams ::= */ - { 207, -2 }, /* (67) streams ::= STREAMS INTEGER */ - { 208, 0 }, /* (68) storage ::= */ - { 208, -2 }, /* (69) storage ::= STORAGE INTEGER */ - { 209, 0 }, /* (70) qtime ::= */ - { 209, -2 }, /* (71) qtime ::= QTIME INTEGER */ - { 210, 0 }, /* (72) users ::= */ - { 210, -2 }, /* (73) users ::= USERS INTEGER */ - { 211, 0 }, /* (74) conns ::= */ - { 211, -2 }, /* (75) conns ::= CONNS INTEGER */ - { 212, 0 }, /* (76) state ::= */ - { 212, -2 }, /* (77) state ::= STATE ids */ - { 199, -9 }, /* (78) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 213, -3 }, /* (79) intitemlist ::= intitemlist COMMA intitem */ - { 213, -1 }, /* (80) intitemlist ::= intitem */ - { 214, -1 }, /* (81) intitem ::= INTEGER */ - { 215, -2 }, /* (82) keep ::= KEEP intitemlist */ - { 216, -2 }, /* (83) cache ::= CACHE INTEGER */ - { 217, -2 }, /* (84) replica ::= REPLICA INTEGER */ - { 218, -2 }, /* (85) quorum ::= QUORUM INTEGER */ - { 219, -2 }, /* (86) days ::= DAYS INTEGER */ - { 220, -2 }, /* (87) minrows ::= MINROWS INTEGER */ - { 221, -2 }, /* (88) maxrows ::= MAXROWS INTEGER */ - { 222, -2 }, /* (89) blocks ::= BLOCKS INTEGER */ - { 223, -2 }, /* (90) ctime ::= CTIME INTEGER */ - { 224, -2 }, /* (91) wal ::= WAL INTEGER */ - { 225, -2 }, /* (92) fsync ::= FSYNC INTEGER */ - { 226, -2 }, /* (93) comp ::= COMP INTEGER */ - { 227, -2 }, /* (94) prec ::= PRECISION STRING */ - { 228, -2 }, /* (95) update ::= UPDATE INTEGER */ - { 229, -2 }, /* (96) cachelast ::= CACHELAST INTEGER */ - { 230, -2 }, /* (97) partitions ::= PARTITIONS INTEGER */ - { 202, 0 }, /* (98) db_optr ::= */ - { 202, -2 }, /* (99) db_optr ::= db_optr cache */ - { 202, -2 }, /* (100) db_optr ::= db_optr replica */ - { 202, -2 }, /* (101) db_optr ::= db_optr quorum */ - { 202, -2 }, /* (102) db_optr ::= db_optr days */ - { 202, -2 }, /* (103) db_optr ::= db_optr minrows */ - { 202, -2 }, /* (104) db_optr ::= db_optr maxrows */ - { 202, -2 }, /* (105) db_optr ::= db_optr blocks */ - { 202, -2 }, /* (106) db_optr ::= db_optr ctime */ - { 202, -2 }, /* (107) db_optr ::= db_optr wal */ - { 202, -2 }, /* (108) db_optr ::= db_optr fsync */ - { 202, -2 }, /* (109) db_optr ::= db_optr comp */ - { 202, -2 }, /* (110) db_optr ::= db_optr prec */ - { 202, -2 }, /* (111) db_optr ::= db_optr keep */ - { 202, -2 }, /* (112) db_optr ::= db_optr update */ - { 202, -2 }, /* (113) db_optr ::= db_optr cachelast */ - { 203, -1 }, /* (114) topic_optr ::= db_optr */ - { 203, -2 }, /* (115) topic_optr ::= topic_optr partitions */ - { 197, 0 }, /* (116) alter_db_optr ::= */ - { 197, -2 }, /* (117) alter_db_optr ::= alter_db_optr replica */ - { 197, -2 }, /* (118) alter_db_optr ::= alter_db_optr quorum */ - { 197, -2 }, /* (119) alter_db_optr ::= alter_db_optr keep */ - { 197, -2 }, /* (120) alter_db_optr ::= alter_db_optr blocks */ - { 197, -2 }, /* (121) alter_db_optr ::= alter_db_optr comp */ - { 197, -2 }, /* (122) alter_db_optr ::= alter_db_optr update */ - { 197, -2 }, /* (123) alter_db_optr ::= alter_db_optr cachelast */ - { 198, -1 }, /* (124) alter_topic_optr ::= alter_db_optr */ - { 198, -2 }, /* (125) alter_topic_optr ::= alter_topic_optr partitions */ - { 231, -1 }, /* (126) typename ::= ids */ - { 231, -4 }, /* (127) typename ::= ids LP signed RP */ - { 231, -2 }, /* (128) typename ::= ids UNSIGNED */ - { 232, -1 }, /* (129) signed ::= INTEGER */ - { 232, -2 }, /* (130) signed ::= PLUS INTEGER */ - { 232, -2 }, /* (131) signed ::= MINUS INTEGER */ - { 192, -3 }, /* (132) cmd ::= CREATE TABLE create_table_args */ - { 192, -3 }, /* (133) cmd ::= CREATE TABLE create_stable_args */ - { 192, -3 }, /* (134) cmd ::= CREATE STABLE create_stable_args */ - { 192, -3 }, /* (135) cmd ::= CREATE TABLE create_table_list */ - { 235, -1 }, /* (136) create_table_list ::= create_from_stable */ - { 235, -2 }, /* (137) create_table_list ::= create_table_list create_from_stable */ - { 233, -6 }, /* (138) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 234, -10 }, /* (139) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 236, -10 }, /* (140) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ - { 236, -13 }, /* (141) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ - { 239, -3 }, /* (142) tagNamelist ::= tagNamelist COMMA ids */ - { 239, -1 }, /* (143) tagNamelist ::= ids */ - { 233, -5 }, /* (144) create_table_args ::= ifnotexists ids cpxName AS select */ - { 237, -3 }, /* (145) columnlist ::= columnlist COMMA column */ - { 237, -1 }, /* (146) columnlist ::= column */ - { 241, -2 }, /* (147) column ::= ids typename */ - { 238, -3 }, /* (148) tagitemlist ::= tagitemlist COMMA tagitem */ - { 238, -1 }, /* (149) tagitemlist ::= tagitem */ - { 242, -1 }, /* (150) tagitem ::= INTEGER */ - { 242, -1 }, /* (151) tagitem ::= FLOAT */ - { 242, -1 }, /* (152) tagitem ::= STRING */ - { 242, -1 }, /* (153) tagitem ::= BOOL */ - { 242, -1 }, /* (154) tagitem ::= NULL */ - { 242, -1 }, /* (155) tagitem ::= NOW */ - { 242, -2 }, /* (156) tagitem ::= MINUS INTEGER */ - { 242, -2 }, /* (157) tagitem ::= MINUS FLOAT */ - { 242, -2 }, /* (158) tagitem ::= PLUS INTEGER */ - { 242, -2 }, /* (159) tagitem ::= PLUS FLOAT */ - { 240, -14 }, /* (160) select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ - { 240, -3 }, /* (161) select ::= LP select RP */ - { 256, -1 }, /* (162) union ::= select */ - { 256, -4 }, /* (163) union ::= union UNION ALL select */ - { 192, -1 }, /* (164) cmd ::= union */ - { 240, -2 }, /* (165) select ::= SELECT selcollist */ - { 257, -2 }, /* (166) sclp ::= selcollist COMMA */ - { 257, 0 }, /* (167) sclp ::= */ - { 243, -4 }, /* (168) selcollist ::= sclp distinct expr as */ - { 243, -2 }, /* (169) selcollist ::= sclp STAR */ - { 260, -2 }, /* (170) as ::= AS ids */ - { 260, -1 }, /* (171) as ::= ids */ - { 260, 0 }, /* (172) as ::= */ - { 258, -1 }, /* (173) distinct ::= DISTINCT */ - { 258, 0 }, /* (174) distinct ::= */ - { 244, -2 }, /* (175) from ::= FROM tablelist */ - { 244, -2 }, /* (176) from ::= FROM sub */ - { 262, -3 }, /* (177) sub ::= LP union RP */ - { 262, -4 }, /* (178) sub ::= LP union RP ids */ - { 262, -6 }, /* (179) sub ::= sub COMMA LP union RP ids */ - { 261, -2 }, /* (180) tablelist ::= ids cpxName */ - { 261, -3 }, /* (181) tablelist ::= ids cpxName ids */ - { 261, -4 }, /* (182) tablelist ::= tablelist COMMA ids cpxName */ - { 261, -5 }, /* (183) tablelist ::= tablelist COMMA ids cpxName ids */ - { 263, -1 }, /* (184) tmvar ::= VARIABLE */ - { 246, -4 }, /* (185) interval_opt ::= INTERVAL LP tmvar RP */ - { 246, -6 }, /* (186) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ - { 246, 0 }, /* (187) interval_opt ::= */ - { 247, 0 }, /* (188) session_option ::= */ - { 247, -7 }, /* (189) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 248, 0 }, /* (190) windowstate_option ::= */ - { 248, -4 }, /* (191) windowstate_option ::= STATE_WINDOW LP ids RP */ - { 249, 0 }, /* (192) fill_opt ::= */ - { 249, -6 }, /* (193) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 249, -4 }, /* (194) fill_opt ::= FILL LP ID RP */ - { 250, -4 }, /* (195) sliding_opt ::= SLIDING LP tmvar RP */ - { 250, 0 }, /* (196) sliding_opt ::= */ - { 253, 0 }, /* (197) orderby_opt ::= */ - { 253, -3 }, /* (198) orderby_opt ::= ORDER BY sortlist */ - { 264, -4 }, /* (199) sortlist ::= sortlist COMMA item sortorder */ - { 264, -2 }, /* (200) sortlist ::= item sortorder */ - { 266, -2 }, /* (201) item ::= ids cpxName */ - { 267, -1 }, /* (202) sortorder ::= ASC */ - { 267, -1 }, /* (203) sortorder ::= DESC */ - { 267, 0 }, /* (204) sortorder ::= */ - { 251, 0 }, /* (205) groupby_opt ::= */ - { 251, -3 }, /* (206) groupby_opt ::= GROUP BY grouplist */ - { 268, -3 }, /* (207) grouplist ::= grouplist COMMA item */ - { 268, -1 }, /* (208) grouplist ::= item */ - { 252, 0 }, /* (209) having_opt ::= */ - { 252, -2 }, /* (210) having_opt ::= HAVING expr */ - { 255, 0 }, /* (211) limit_opt ::= */ - { 255, -2 }, /* (212) limit_opt ::= LIMIT signed */ - { 255, -4 }, /* (213) limit_opt ::= LIMIT signed OFFSET signed */ - { 255, -4 }, /* (214) limit_opt ::= LIMIT signed COMMA signed */ - { 254, 0 }, /* (215) slimit_opt ::= */ - { 254, -2 }, /* (216) slimit_opt ::= SLIMIT signed */ - { 254, -4 }, /* (217) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 254, -4 }, /* (218) slimit_opt ::= SLIMIT signed COMMA signed */ - { 245, 0 }, /* (219) where_opt ::= */ - { 245, -2 }, /* (220) where_opt ::= WHERE expr */ - { 259, -3 }, /* (221) expr ::= LP expr RP */ - { 259, -1 }, /* (222) expr ::= ID */ - { 259, -3 }, /* (223) expr ::= ID DOT ID */ - { 259, -3 }, /* (224) expr ::= ID DOT STAR */ - { 259, -1 }, /* (225) expr ::= INTEGER */ - { 259, -2 }, /* (226) expr ::= MINUS INTEGER */ - { 259, -2 }, /* (227) expr ::= PLUS INTEGER */ - { 259, -1 }, /* (228) expr ::= FLOAT */ - { 259, -2 }, /* (229) expr ::= MINUS FLOAT */ - { 259, -2 }, /* (230) expr ::= PLUS FLOAT */ - { 259, -1 }, /* (231) expr ::= STRING */ - { 259, -1 }, /* (232) expr ::= NOW */ - { 259, -1 }, /* (233) expr ::= VARIABLE */ - { 259, -2 }, /* (234) expr ::= PLUS VARIABLE */ - { 259, -2 }, /* (235) expr ::= MINUS VARIABLE */ - { 259, -1 }, /* (236) expr ::= BOOL */ - { 259, -1 }, /* (237) expr ::= NULL */ - { 259, -4 }, /* (238) expr ::= ID LP exprlist RP */ - { 259, -4 }, /* (239) expr ::= ID LP STAR RP */ - { 259, -3 }, /* (240) expr ::= expr IS NULL */ - { 259, -4 }, /* (241) expr ::= expr IS NOT NULL */ - { 259, -3 }, /* (242) expr ::= expr LT expr */ - { 259, -3 }, /* (243) expr ::= expr GT expr */ - { 259, -3 }, /* (244) expr ::= expr LE expr */ - { 259, -3 }, /* (245) expr ::= expr GE expr */ - { 259, -3 }, /* (246) expr ::= expr NE expr */ - { 259, -3 }, /* (247) expr ::= expr EQ expr */ - { 259, -5 }, /* (248) expr ::= expr BETWEEN expr AND expr */ - { 259, -3 }, /* (249) expr ::= expr AND expr */ - { 259, -3 }, /* (250) expr ::= expr OR expr */ - { 259, -3 }, /* (251) expr ::= expr PLUS expr */ - { 259, -3 }, /* (252) expr ::= expr MINUS expr */ - { 259, -3 }, /* (253) expr ::= expr STAR expr */ - { 259, -3 }, /* (254) expr ::= expr SLASH expr */ - { 259, -3 }, /* (255) expr ::= expr REM expr */ - { 259, -3 }, /* (256) expr ::= expr LIKE expr */ - { 259, -5 }, /* (257) expr ::= expr IN LP exprlist RP */ - { 200, -3 }, /* (258) exprlist ::= exprlist COMMA expritem */ - { 200, -1 }, /* (259) exprlist ::= expritem */ - { 269, -1 }, /* (260) expritem ::= expr */ - { 269, 0 }, /* (261) expritem ::= */ - { 192, -3 }, /* (262) cmd ::= RESET QUERY CACHE */ - { 192, -3 }, /* (263) cmd ::= SYNCDB ids REPLICA */ - { 192, -7 }, /* (264) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 192, -7 }, /* (265) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 192, -7 }, /* (266) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - { 192, -7 }, /* (267) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 192, -7 }, /* (268) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 192, -8 }, /* (269) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 192, -9 }, /* (270) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 192, -7 }, /* (271) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - { 192, -7 }, /* (272) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 192, -7 }, /* (273) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 192, -7 }, /* (274) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - { 192, -7 }, /* (275) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 192, -7 }, /* (276) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 192, -8 }, /* (277) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 192, -9 }, /* (278) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - { 192, -7 }, /* (279) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - { 192, -3 }, /* (280) cmd ::= KILL CONNECTION INTEGER */ - { 192, -5 }, /* (281) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 192, -5 }, /* (282) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + { 196, -1 }, /* (0) program ::= cmd */ + { 197, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 197, -2 }, /* (2) cmd ::= SHOW TOPICS */ + { 197, -2 }, /* (3) cmd ::= SHOW FUNCTIONS */ + { 197, -2 }, /* (4) cmd ::= SHOW MNODES */ + { 197, -2 }, /* (5) cmd ::= SHOW DNODES */ + { 197, -2 }, /* (6) cmd ::= SHOW ACCOUNTS */ + { 197, -2 }, /* (7) cmd ::= SHOW USERS */ + { 197, -2 }, /* (8) cmd ::= SHOW MODULES */ + { 197, -2 }, /* (9) cmd ::= SHOW QUERIES */ + { 197, -2 }, /* (10) cmd ::= SHOW CONNECTIONS */ + { 197, -2 }, /* (11) cmd ::= SHOW STREAMS */ + { 197, -2 }, /* (12) cmd ::= SHOW VARIABLES */ + { 197, -2 }, /* (13) cmd ::= SHOW SCORES */ + { 197, -2 }, /* (14) cmd ::= SHOW GRANTS */ + { 197, -2 }, /* (15) cmd ::= SHOW VNODES */ + { 197, -3 }, /* (16) cmd ::= SHOW VNODES IPTOKEN */ + { 198, 0 }, /* (17) dbPrefix ::= */ + { 198, -2 }, /* (18) dbPrefix ::= ids DOT */ + { 200, 0 }, /* (19) cpxName ::= */ + { 200, -2 }, /* (20) cpxName ::= DOT ids */ + { 197, -5 }, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ + { 197, -5 }, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ + { 197, -4 }, /* (23) cmd ::= SHOW CREATE DATABASE ids */ + { 197, -3 }, /* (24) cmd ::= SHOW dbPrefix TABLES */ + { 197, -5 }, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 197, -3 }, /* (26) cmd ::= SHOW dbPrefix STABLES */ + { 197, -5 }, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 197, -3 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ + { 197, -4 }, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ + { 197, -5 }, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ + { 197, -5 }, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ + { 197, -4 }, /* (32) cmd ::= DROP DATABASE ifexists ids */ + { 197, -4 }, /* (33) cmd ::= DROP TOPIC ifexists ids */ + { 197, -3 }, /* (34) cmd ::= DROP FUNCTION ids */ + { 197, -3 }, /* (35) cmd ::= DROP DNODE ids */ + { 197, -3 }, /* (36) cmd ::= DROP USER ids */ + { 197, -3 }, /* (37) cmd ::= DROP ACCOUNT ids */ + { 197, -2 }, /* (38) cmd ::= USE ids */ + { 197, -3 }, /* (39) cmd ::= DESCRIBE ids cpxName */ + { 197, -5 }, /* (40) cmd ::= ALTER USER ids PASS ids */ + { 197, -5 }, /* (41) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 197, -4 }, /* (42) cmd ::= ALTER DNODE ids ids */ + { 197, -5 }, /* (43) cmd ::= ALTER DNODE ids ids ids */ + { 197, -3 }, /* (44) cmd ::= ALTER LOCAL ids */ + { 197, -4 }, /* (45) cmd ::= ALTER LOCAL ids ids */ + { 197, -4 }, /* (46) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 197, -4 }, /* (47) cmd ::= ALTER TOPIC ids alter_topic_optr */ + { 197, -4 }, /* (48) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 197, -6 }, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 197, -6 }, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ + { 199, -1 }, /* (51) ids ::= ID */ + { 199, -1 }, /* (52) ids ::= STRING */ + { 201, -2 }, /* (53) ifexists ::= IF EXISTS */ + { 201, 0 }, /* (54) ifexists ::= */ + { 206, -3 }, /* (55) ifnotexists ::= IF NOT EXISTS */ + { 206, 0 }, /* (56) ifnotexists ::= */ + { 197, -3 }, /* (57) cmd ::= CREATE DNODE ids */ + { 197, -6 }, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 197, -5 }, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 197, -5 }, /* (60) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ + { 197, -8 }, /* (61) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 197, -9 }, /* (62) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 197, -5 }, /* (63) cmd ::= CREATE USER ids PASS ids */ + { 210, 0 }, /* (64) bufsize ::= */ + { 210, -2 }, /* (65) bufsize ::= BUFSIZE INTEGER */ + { 211, 0 }, /* (66) pps ::= */ + { 211, -2 }, /* (67) pps ::= PPS INTEGER */ + { 212, 0 }, /* (68) tseries ::= */ + { 212, -2 }, /* (69) tseries ::= TSERIES INTEGER */ + { 213, 0 }, /* (70) dbs ::= */ + { 213, -2 }, /* (71) dbs ::= DBS INTEGER */ + { 214, 0 }, /* (72) streams ::= */ + { 214, -2 }, /* (73) streams ::= STREAMS INTEGER */ + { 215, 0 }, /* (74) storage ::= */ + { 215, -2 }, /* (75) storage ::= STORAGE INTEGER */ + { 216, 0 }, /* (76) qtime ::= */ + { 216, -2 }, /* (77) qtime ::= QTIME INTEGER */ + { 217, 0 }, /* (78) users ::= */ + { 217, -2 }, /* (79) users ::= USERS INTEGER */ + { 218, 0 }, /* (80) conns ::= */ + { 218, -2 }, /* (81) conns ::= CONNS INTEGER */ + { 219, 0 }, /* (82) state ::= */ + { 219, -2 }, /* (83) state ::= STATE ids */ + { 204, -9 }, /* (84) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 220, -3 }, /* (85) intitemlist ::= intitemlist COMMA intitem */ + { 220, -1 }, /* (86) intitemlist ::= intitem */ + { 221, -1 }, /* (87) intitem ::= INTEGER */ + { 222, -2 }, /* (88) keep ::= KEEP intitemlist */ + { 223, -2 }, /* (89) cache ::= CACHE INTEGER */ + { 224, -2 }, /* (90) replica ::= REPLICA INTEGER */ + { 225, -2 }, /* (91) quorum ::= QUORUM INTEGER */ + { 226, -2 }, /* (92) days ::= DAYS INTEGER */ + { 227, -2 }, /* (93) minrows ::= MINROWS INTEGER */ + { 228, -2 }, /* (94) maxrows ::= MAXROWS INTEGER */ + { 229, -2 }, /* (95) blocks ::= BLOCKS INTEGER */ + { 230, -2 }, /* (96) ctime ::= CTIME INTEGER */ + { 231, -2 }, /* (97) wal ::= WAL INTEGER */ + { 232, -2 }, /* (98) fsync ::= FSYNC INTEGER */ + { 233, -2 }, /* (99) comp ::= COMP INTEGER */ + { 234, -2 }, /* (100) prec ::= PRECISION STRING */ + { 235, -2 }, /* (101) update ::= UPDATE INTEGER */ + { 236, -2 }, /* (102) cachelast ::= CACHELAST INTEGER */ + { 237, -2 }, /* (103) partitions ::= PARTITIONS INTEGER */ + { 207, 0 }, /* (104) db_optr ::= */ + { 207, -2 }, /* (105) db_optr ::= db_optr cache */ + { 207, -2 }, /* (106) db_optr ::= db_optr replica */ + { 207, -2 }, /* (107) db_optr ::= db_optr quorum */ + { 207, -2 }, /* (108) db_optr ::= db_optr days */ + { 207, -2 }, /* (109) db_optr ::= db_optr minrows */ + { 207, -2 }, /* (110) db_optr ::= db_optr maxrows */ + { 207, -2 }, /* (111) db_optr ::= db_optr blocks */ + { 207, -2 }, /* (112) db_optr ::= db_optr ctime */ + { 207, -2 }, /* (113) db_optr ::= db_optr wal */ + { 207, -2 }, /* (114) db_optr ::= db_optr fsync */ + { 207, -2 }, /* (115) db_optr ::= db_optr comp */ + { 207, -2 }, /* (116) db_optr ::= db_optr prec */ + { 207, -2 }, /* (117) db_optr ::= db_optr keep */ + { 207, -2 }, /* (118) db_optr ::= db_optr update */ + { 207, -2 }, /* (119) db_optr ::= db_optr cachelast */ + { 208, -1 }, /* (120) topic_optr ::= db_optr */ + { 208, -2 }, /* (121) topic_optr ::= topic_optr partitions */ + { 202, 0 }, /* (122) alter_db_optr ::= */ + { 202, -2 }, /* (123) alter_db_optr ::= alter_db_optr replica */ + { 202, -2 }, /* (124) alter_db_optr ::= alter_db_optr quorum */ + { 202, -2 }, /* (125) alter_db_optr ::= alter_db_optr keep */ + { 202, -2 }, /* (126) alter_db_optr ::= alter_db_optr blocks */ + { 202, -2 }, /* (127) alter_db_optr ::= alter_db_optr comp */ + { 202, -2 }, /* (128) alter_db_optr ::= alter_db_optr update */ + { 202, -2 }, /* (129) alter_db_optr ::= alter_db_optr cachelast */ + { 203, -1 }, /* (130) alter_topic_optr ::= alter_db_optr */ + { 203, -2 }, /* (131) alter_topic_optr ::= alter_topic_optr partitions */ + { 209, -1 }, /* (132) typename ::= ids */ + { 209, -4 }, /* (133) typename ::= ids LP signed RP */ + { 209, -2 }, /* (134) typename ::= ids UNSIGNED */ + { 238, -1 }, /* (135) signed ::= INTEGER */ + { 238, -2 }, /* (136) signed ::= PLUS INTEGER */ + { 238, -2 }, /* (137) signed ::= MINUS INTEGER */ + { 197, -3 }, /* (138) cmd ::= CREATE TABLE create_table_args */ + { 197, -3 }, /* (139) cmd ::= CREATE TABLE create_stable_args */ + { 197, -3 }, /* (140) cmd ::= CREATE STABLE create_stable_args */ + { 197, -3 }, /* (141) cmd ::= CREATE TABLE create_table_list */ + { 241, -1 }, /* (142) create_table_list ::= create_from_stable */ + { 241, -2 }, /* (143) create_table_list ::= create_table_list create_from_stable */ + { 239, -6 }, /* (144) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 240, -10 }, /* (145) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 242, -10 }, /* (146) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + { 242, -13 }, /* (147) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + { 245, -3 }, /* (148) tagNamelist ::= tagNamelist COMMA ids */ + { 245, -1 }, /* (149) tagNamelist ::= ids */ + { 239, -5 }, /* (150) create_table_args ::= ifnotexists ids cpxName AS select */ + { 243, -3 }, /* (151) columnlist ::= columnlist COMMA column */ + { 243, -1 }, /* (152) columnlist ::= column */ + { 247, -2 }, /* (153) column ::= ids typename */ + { 244, -3 }, /* (154) tagitemlist ::= tagitemlist COMMA tagitem */ + { 244, -1 }, /* (155) tagitemlist ::= tagitem */ + { 248, -1 }, /* (156) tagitem ::= INTEGER */ + { 248, -1 }, /* (157) tagitem ::= FLOAT */ + { 248, -1 }, /* (158) tagitem ::= STRING */ + { 248, -1 }, /* (159) tagitem ::= BOOL */ + { 248, -1 }, /* (160) tagitem ::= NULL */ + { 248, -1 }, /* (161) tagitem ::= NOW */ + { 248, -2 }, /* (162) tagitem ::= MINUS INTEGER */ + { 248, -2 }, /* (163) tagitem ::= MINUS FLOAT */ + { 248, -2 }, /* (164) tagitem ::= PLUS INTEGER */ + { 248, -2 }, /* (165) tagitem ::= PLUS FLOAT */ + { 246, -14 }, /* (166) select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + { 246, -3 }, /* (167) select ::= LP select RP */ + { 262, -1 }, /* (168) union ::= select */ + { 262, -4 }, /* (169) union ::= union UNION ALL select */ + { 197, -1 }, /* (170) cmd ::= union */ + { 246, -2 }, /* (171) select ::= SELECT selcollist */ + { 263, -2 }, /* (172) sclp ::= selcollist COMMA */ + { 263, 0 }, /* (173) sclp ::= */ + { 249, -4 }, /* (174) selcollist ::= sclp distinct expr as */ + { 249, -2 }, /* (175) selcollist ::= sclp STAR */ + { 266, -2 }, /* (176) as ::= AS ids */ + { 266, -1 }, /* (177) as ::= ids */ + { 266, 0 }, /* (178) as ::= */ + { 264, -1 }, /* (179) distinct ::= DISTINCT */ + { 264, 0 }, /* (180) distinct ::= */ + { 250, -2 }, /* (181) from ::= FROM tablelist */ + { 250, -2 }, /* (182) from ::= FROM sub */ + { 268, -3 }, /* (183) sub ::= LP union RP */ + { 268, -4 }, /* (184) sub ::= LP union RP ids */ + { 268, -6 }, /* (185) sub ::= sub COMMA LP union RP ids */ + { 267, -2 }, /* (186) tablelist ::= ids cpxName */ + { 267, -3 }, /* (187) tablelist ::= ids cpxName ids */ + { 267, -4 }, /* (188) tablelist ::= tablelist COMMA ids cpxName */ + { 267, -5 }, /* (189) tablelist ::= tablelist COMMA ids cpxName ids */ + { 269, -1 }, /* (190) tmvar ::= VARIABLE */ + { 252, -4 }, /* (191) interval_opt ::= INTERVAL LP tmvar RP */ + { 252, -6 }, /* (192) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + { 252, 0 }, /* (193) interval_opt ::= */ + { 253, 0 }, /* (194) session_option ::= */ + { 253, -7 }, /* (195) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 254, 0 }, /* (196) windowstate_option ::= */ + { 254, -4 }, /* (197) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 255, 0 }, /* (198) fill_opt ::= */ + { 255, -6 }, /* (199) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 255, -4 }, /* (200) fill_opt ::= FILL LP ID RP */ + { 256, -4 }, /* (201) sliding_opt ::= SLIDING LP tmvar RP */ + { 256, 0 }, /* (202) sliding_opt ::= */ + { 259, 0 }, /* (203) orderby_opt ::= */ + { 259, -3 }, /* (204) orderby_opt ::= ORDER BY sortlist */ + { 270, -4 }, /* (205) sortlist ::= sortlist COMMA item sortorder */ + { 270, -2 }, /* (206) sortlist ::= item sortorder */ + { 272, -2 }, /* (207) item ::= ids cpxName */ + { 273, -1 }, /* (208) sortorder ::= ASC */ + { 273, -1 }, /* (209) sortorder ::= DESC */ + { 273, 0 }, /* (210) sortorder ::= */ + { 257, 0 }, /* (211) groupby_opt ::= */ + { 257, -3 }, /* (212) groupby_opt ::= GROUP BY grouplist */ + { 274, -3 }, /* (213) grouplist ::= grouplist COMMA item */ + { 274, -1 }, /* (214) grouplist ::= item */ + { 258, 0 }, /* (215) having_opt ::= */ + { 258, -2 }, /* (216) having_opt ::= HAVING expr */ + { 261, 0 }, /* (217) limit_opt ::= */ + { 261, -2 }, /* (218) limit_opt ::= LIMIT signed */ + { 261, -4 }, /* (219) limit_opt ::= LIMIT signed OFFSET signed */ + { 261, -4 }, /* (220) limit_opt ::= LIMIT signed COMMA signed */ + { 260, 0 }, /* (221) slimit_opt ::= */ + { 260, -2 }, /* (222) slimit_opt ::= SLIMIT signed */ + { 260, -4 }, /* (223) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 260, -4 }, /* (224) slimit_opt ::= SLIMIT signed COMMA signed */ + { 251, 0 }, /* (225) where_opt ::= */ + { 251, -2 }, /* (226) where_opt ::= WHERE expr */ + { 265, -3 }, /* (227) expr ::= LP expr RP */ + { 265, -1 }, /* (228) expr ::= ID */ + { 265, -3 }, /* (229) expr ::= ID DOT ID */ + { 265, -3 }, /* (230) expr ::= ID DOT STAR */ + { 265, -1 }, /* (231) expr ::= INTEGER */ + { 265, -2 }, /* (232) expr ::= MINUS INTEGER */ + { 265, -2 }, /* (233) expr ::= PLUS INTEGER */ + { 265, -1 }, /* (234) expr ::= FLOAT */ + { 265, -2 }, /* (235) expr ::= MINUS FLOAT */ + { 265, -2 }, /* (236) expr ::= PLUS FLOAT */ + { 265, -1 }, /* (237) expr ::= STRING */ + { 265, -1 }, /* (238) expr ::= NOW */ + { 265, -1 }, /* (239) expr ::= VARIABLE */ + { 265, -2 }, /* (240) expr ::= PLUS VARIABLE */ + { 265, -2 }, /* (241) expr ::= MINUS VARIABLE */ + { 265, -1 }, /* (242) expr ::= BOOL */ + { 265, -1 }, /* (243) expr ::= NULL */ + { 265, -4 }, /* (244) expr ::= ID LP exprlist RP */ + { 265, -4 }, /* (245) expr ::= ID LP STAR RP */ + { 265, -3 }, /* (246) expr ::= expr IS NULL */ + { 265, -4 }, /* (247) expr ::= expr IS NOT NULL */ + { 265, -3 }, /* (248) expr ::= expr LT expr */ + { 265, -3 }, /* (249) expr ::= expr GT expr */ + { 265, -3 }, /* (250) expr ::= expr LE expr */ + { 265, -3 }, /* (251) expr ::= expr GE expr */ + { 265, -3 }, /* (252) expr ::= expr NE expr */ + { 265, -3 }, /* (253) expr ::= expr EQ expr */ + { 265, -5 }, /* (254) expr ::= expr BETWEEN expr AND expr */ + { 265, -3 }, /* (255) expr ::= expr AND expr */ + { 265, -3 }, /* (256) expr ::= expr OR expr */ + { 265, -3 }, /* (257) expr ::= expr PLUS expr */ + { 265, -3 }, /* (258) expr ::= expr MINUS expr */ + { 265, -3 }, /* (259) expr ::= expr STAR expr */ + { 265, -3 }, /* (260) expr ::= expr SLASH expr */ + { 265, -3 }, /* (261) expr ::= expr REM expr */ + { 265, -3 }, /* (262) expr ::= expr LIKE expr */ + { 265, -5 }, /* (263) expr ::= expr IN LP exprlist RP */ + { 205, -3 }, /* (264) exprlist ::= exprlist COMMA expritem */ + { 205, -1 }, /* (265) exprlist ::= expritem */ + { 275, -1 }, /* (266) expritem ::= expr */ + { 275, 0 }, /* (267) expritem ::= */ + { 197, -3 }, /* (268) cmd ::= RESET QUERY CACHE */ + { 197, -3 }, /* (269) cmd ::= SYNCDB ids REPLICA */ + { 197, -7 }, /* (270) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 197, -7 }, /* (271) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 197, -7 }, /* (272) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + { 197, -7 }, /* (273) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 197, -7 }, /* (274) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 197, -8 }, /* (275) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 197, -9 }, /* (276) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 197, -7 }, /* (277) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + { 197, -7 }, /* (278) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 197, -7 }, /* (279) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 197, -7 }, /* (280) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + { 197, -7 }, /* (281) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 197, -7 }, /* (282) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 197, -8 }, /* (283) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 197, -9 }, /* (284) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + { 197, -7 }, /* (285) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + { 197, -3 }, /* (286) cmd ::= KILL CONNECTION INTEGER */ + { 197, -5 }, /* (287) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 197, -5 }, /* (288) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2162,9 +2194,9 @@ static void yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ - case 132: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==132); - case 133: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==133); - case 134: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==134); + case 138: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==138); + case 139: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==139); + case 140: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==140); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -2173,502 +2205,516 @@ static void yy_reduce( case 2: /* cmd ::= SHOW TOPICS */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_TP, 0, 0);} break; - case 3: /* cmd ::= SHOW MNODES */ + case 3: /* cmd ::= SHOW FUNCTIONS */ +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_FUNCTION, 0, 0);} + break; + case 4: /* cmd ::= SHOW MNODES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);} break; - case 4: /* cmd ::= SHOW DNODES */ + case 5: /* cmd ::= SHOW DNODES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);} break; - case 5: /* cmd ::= SHOW ACCOUNTS */ + case 6: /* cmd ::= SHOW ACCOUNTS */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);} break; - case 6: /* cmd ::= SHOW USERS */ + case 7: /* cmd ::= SHOW USERS */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_USER, 0, 0);} break; - case 7: /* cmd ::= SHOW MODULES */ + case 8: /* cmd ::= SHOW MODULES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_MODULE, 0, 0); } break; - case 8: /* cmd ::= SHOW QUERIES */ + case 9: /* cmd ::= SHOW QUERIES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0); } break; - case 9: /* cmd ::= SHOW CONNECTIONS */ + case 10: /* cmd ::= SHOW CONNECTIONS */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);} break; - case 10: /* cmd ::= SHOW STREAMS */ + case 11: /* cmd ::= SHOW STREAMS */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); } break; - case 11: /* cmd ::= SHOW VARIABLES */ + case 12: /* cmd ::= SHOW VARIABLES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_VARIABLES, 0, 0); } break; - case 12: /* cmd ::= SHOW SCORES */ + case 13: /* cmd ::= SHOW SCORES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); } break; - case 13: /* cmd ::= SHOW GRANTS */ + case 14: /* cmd ::= SHOW GRANTS */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); } break; - case 14: /* cmd ::= SHOW VNODES */ + case 15: /* cmd ::= SHOW VNODES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); } break; - case 15: /* cmd ::= SHOW VNODES IPTOKEN */ + case 16: /* cmd ::= SHOW VNODES IPTOKEN */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &yymsp[0].minor.yy0, 0); } break; - case 16: /* dbPrefix ::= */ + case 17: /* dbPrefix ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.type = 0;} break; - case 17: /* dbPrefix ::= ids DOT */ + case 18: /* dbPrefix ::= ids DOT */ {yylhsminor.yy0 = yymsp[-1].minor.yy0; } yymsp[-1].minor.yy0 = yylhsminor.yy0; break; - case 18: /* cpxName ::= */ + case 19: /* cpxName ::= */ {yymsp[1].minor.yy0.n = 0; } break; - case 19: /* cpxName ::= DOT ids */ + case 20: /* cpxName ::= DOT ids */ {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n += 1; } break; - case 20: /* cmd ::= SHOW CREATE TABLE ids cpxName */ + case 21: /* cmd ::= SHOW CREATE TABLE ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &yymsp[-1].minor.yy0); } break; - case 21: /* cmd ::= SHOW CREATE STABLE ids cpxName */ + case 22: /* cmd ::= SHOW CREATE STABLE ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_STABLE, 1, &yymsp[-1].minor.yy0); } break; - case 22: /* cmd ::= SHOW CREATE DATABASE ids */ + case 23: /* cmd ::= SHOW CREATE DATABASE ids */ { setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &yymsp[0].minor.yy0); } break; - case 23: /* cmd ::= SHOW dbPrefix TABLES */ + case 24: /* cmd ::= SHOW dbPrefix TABLES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &yymsp[-1].minor.yy0, 0); } break; - case 24: /* cmd ::= SHOW dbPrefix TABLES LIKE ids */ + case 25: /* cmd ::= SHOW dbPrefix TABLES LIKE ids */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); } break; - case 25: /* cmd ::= SHOW dbPrefix STABLES */ + case 26: /* cmd ::= SHOW dbPrefix STABLES */ { setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &yymsp[-1].minor.yy0, 0); } break; - case 26: /* cmd ::= SHOW dbPrefix STABLES LIKE ids */ + case 27: /* cmd ::= SHOW dbPrefix STABLES LIKE ids */ { SStrToken token; tSetDbName(&token, &yymsp[-3].minor.yy0); setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &yymsp[0].minor.yy0); } break; - case 27: /* cmd ::= SHOW dbPrefix VGROUPS */ + case 28: /* cmd ::= SHOW dbPrefix VGROUPS */ { SStrToken token; tSetDbName(&token, &yymsp[-1].minor.yy0); setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0); } break; - case 28: /* cmd ::= SHOW dbPrefix VGROUPS ids */ + case 29: /* cmd ::= SHOW dbPrefix VGROUPS ids */ { SStrToken token; tSetDbName(&token, &yymsp[-2].minor.yy0); setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, &yymsp[0].minor.yy0); } break; - case 29: /* cmd ::= DROP TABLE ifexists ids cpxName */ + case 30: /* cmd ::= DROP TABLE ifexists ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &yymsp[-1].minor.yy0, &yymsp[-2].minor.yy0, -1, -1); } break; - case 30: /* cmd ::= DROP STABLE ifexists ids cpxName */ + case 31: /* cmd ::= DROP STABLE ifexists ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &yymsp[-1].minor.yy0, &yymsp[-2].minor.yy0, -1, TSDB_SUPER_TABLE); } break; - case 31: /* cmd ::= DROP DATABASE ifexists ids */ + case 32: /* cmd ::= DROP DATABASE ifexists ids */ { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &yymsp[0].minor.yy0, &yymsp[-1].minor.yy0, TSDB_DB_TYPE_DEFAULT, -1); } break; - case 32: /* cmd ::= DROP TOPIC ifexists ids */ + case 33: /* cmd ::= DROP TOPIC ifexists ids */ { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &yymsp[0].minor.yy0, &yymsp[-1].minor.yy0, TSDB_DB_TYPE_TOPIC, -1); } break; - case 33: /* cmd ::= DROP DNODE ids */ + case 34: /* cmd ::= DROP FUNCTION ids */ +{ setDropFuncInfo(pInfo, TSDB_SQL_DROP_FUNCTION, &yymsp[0].minor.yy0); } + break; + case 35: /* cmd ::= DROP DNODE ids */ { setDCLSqlElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &yymsp[0].minor.yy0); } break; - case 34: /* cmd ::= DROP USER ids */ + case 36: /* cmd ::= DROP USER ids */ { setDCLSqlElems(pInfo, TSDB_SQL_DROP_USER, 1, &yymsp[0].minor.yy0); } break; - case 35: /* cmd ::= DROP ACCOUNT ids */ + case 37: /* cmd ::= DROP ACCOUNT ids */ { setDCLSqlElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &yymsp[0].minor.yy0); } break; - case 36: /* cmd ::= USE ids */ + case 38: /* cmd ::= USE ids */ { setDCLSqlElems(pInfo, TSDB_SQL_USE_DB, 1, &yymsp[0].minor.yy0);} break; - case 37: /* cmd ::= DESCRIBE ids cpxName */ + case 39: /* cmd ::= DESCRIBE ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &yymsp[-1].minor.yy0); } break; - case 38: /* cmd ::= ALTER USER ids PASS ids */ + case 40: /* cmd ::= ALTER USER ids PASS ids */ { setAlterUserSql(pInfo, TSDB_ALTER_USER_PASSWD, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, NULL); } break; - case 39: /* cmd ::= ALTER USER ids PRIVILEGE ids */ + case 41: /* cmd ::= ALTER USER ids PRIVILEGE ids */ { setAlterUserSql(pInfo, TSDB_ALTER_USER_PRIVILEGES, &yymsp[-2].minor.yy0, NULL, &yymsp[0].minor.yy0);} break; - case 40: /* cmd ::= ALTER DNODE ids ids */ + case 42: /* cmd ::= ALTER DNODE ids ids */ { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 41: /* cmd ::= ALTER DNODE ids ids ids */ + case 43: /* cmd ::= ALTER DNODE ids ids ids */ { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 42: /* cmd ::= ALTER LOCAL ids */ + case 44: /* cmd ::= ALTER LOCAL ids */ { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &yymsp[0].minor.yy0); } break; - case 43: /* cmd ::= ALTER LOCAL ids ids */ + case 45: /* cmd ::= ALTER LOCAL ids ids */ { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } 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.yy382, &t);} + case 46: /* cmd ::= ALTER DATABASE ids alter_db_optr */ + case 47: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==47); +{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy214, &t);} break; - case 46: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy151);} + case 48: /* cmd ::= ALTER ACCOUNT ids acct_optr */ +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy547);} 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.yy151);} + case 49: /* 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.yy547);} break; - case 48: /* cmd ::= COMPACT VNODES IN LP exprlist RP */ -{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy441);} + case 50: /* cmd ::= COMPACT VNODES IN LP exprlist RP */ +{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy525);} break; - case 49: /* ids ::= ID */ - case 50: /* ids ::= STRING */ yytestcase(yyruleno==50); + case 51: /* ids ::= ID */ + case 52: /* ids ::= STRING */ yytestcase(yyruleno==52); {yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 51: /* ifexists ::= IF EXISTS */ + case 53: /* ifexists ::= IF EXISTS */ { yymsp[-1].minor.yy0.n = 1;} break; - case 52: /* ifexists ::= */ - case 54: /* ifnotexists ::= */ yytestcase(yyruleno==54); - case 174: /* distinct ::= */ yytestcase(yyruleno==174); + case 54: /* ifexists ::= */ + case 56: /* ifnotexists ::= */ yytestcase(yyruleno==56); + case 180: /* distinct ::= */ yytestcase(yyruleno==180); { yymsp[1].minor.yy0.n = 0;} break; - case 53: /* ifnotexists ::= IF NOT EXISTS */ + case 55: /* ifnotexists ::= IF NOT EXISTS */ { yymsp[-2].minor.yy0.n = 1;} break; - case 55: /* cmd ::= CREATE DNODE ids */ + case 57: /* cmd ::= CREATE DNODE ids */ { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; - case 56: /* 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.yy151);} + case 58: /* 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.yy547);} + break; + case 59: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + case 60: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==60); +{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy214, &yymsp[-2].minor.yy0);} + break; + case 61: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ +{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy31, &yymsp[0].minor.yy0, 1);} break; - case 57: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - case 58: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==58); -{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy382, &yymsp[-2].minor.yy0);} + case 62: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ +{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy31, &yymsp[0].minor.yy0, 2);} break; - case 59: /* cmd ::= CREATE USER ids PASS ids */ + case 63: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 60: /* pps ::= */ - case 62: /* tseries ::= */ yytestcase(yyruleno==62); - case 64: /* dbs ::= */ yytestcase(yyruleno==64); - case 66: /* streams ::= */ yytestcase(yyruleno==66); - case 68: /* storage ::= */ yytestcase(yyruleno==68); - case 70: /* qtime ::= */ yytestcase(yyruleno==70); - case 72: /* users ::= */ yytestcase(yyruleno==72); - case 74: /* conns ::= */ yytestcase(yyruleno==74); - case 76: /* state ::= */ yytestcase(yyruleno==76); + case 64: /* bufsize ::= */ + case 66: /* pps ::= */ yytestcase(yyruleno==66); + case 68: /* tseries ::= */ yytestcase(yyruleno==68); + case 70: /* dbs ::= */ yytestcase(yyruleno==70); + case 72: /* streams ::= */ yytestcase(yyruleno==72); + case 74: /* storage ::= */ yytestcase(yyruleno==74); + case 76: /* qtime ::= */ yytestcase(yyruleno==76); + case 78: /* users ::= */ yytestcase(yyruleno==78); + case 80: /* conns ::= */ yytestcase(yyruleno==80); + case 82: /* state ::= */ yytestcase(yyruleno==82); { yymsp[1].minor.yy0.n = 0; } break; - case 61: /* pps ::= PPS INTEGER */ - case 63: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==63); - case 65: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==65); - case 67: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==67); - case 69: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==69); - case 71: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==71); - case 73: /* users ::= USERS INTEGER */ yytestcase(yyruleno==73); - case 75: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==75); - case 77: /* state ::= STATE ids */ yytestcase(yyruleno==77); + case 65: /* bufsize ::= BUFSIZE INTEGER */ + case 67: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==67); + case 69: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==69); + case 71: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==71); + case 73: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==73); + case 75: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==75); + case 77: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==77); + case 79: /* users ::= USERS INTEGER */ yytestcase(yyruleno==79); + case 81: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==81); + case 83: /* state ::= STATE ids */ yytestcase(yyruleno==83); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 78: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ -{ - yylhsminor.yy151.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yylhsminor.yy151.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yylhsminor.yy151.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yylhsminor.yy151.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yylhsminor.yy151.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yylhsminor.yy151.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy151.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy151.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yylhsminor.yy151.stat = yymsp[0].minor.yy0; -} - yymsp[-8].minor.yy151 = yylhsminor.yy151; - break; - case 79: /* intitemlist ::= intitemlist COMMA intitem */ - case 148: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==148); -{ yylhsminor.yy441 = tVariantListAppend(yymsp[-2].minor.yy441, &yymsp[0].minor.yy506, -1); } - yymsp[-2].minor.yy441 = yylhsminor.yy441; - break; - case 80: /* intitemlist ::= intitem */ - case 149: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==149); -{ yylhsminor.yy441 = tVariantListAppend(NULL, &yymsp[0].minor.yy506, -1); } - yymsp[0].minor.yy441 = yylhsminor.yy441; - break; - case 81: /* intitem ::= INTEGER */ - case 150: /* tagitem ::= INTEGER */ yytestcase(yyruleno==150); - case 151: /* tagitem ::= FLOAT */ yytestcase(yyruleno==151); - case 152: /* tagitem ::= STRING */ yytestcase(yyruleno==152); - case 153: /* tagitem ::= BOOL */ yytestcase(yyruleno==153); + case 84: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ +{ + yylhsminor.yy547.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy547.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy547.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy547.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy547.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy547.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy547.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy547.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy547.stat = yymsp[0].minor.yy0; +} + yymsp[-8].minor.yy547 = yylhsminor.yy547; + break; + case 85: /* intitemlist ::= intitemlist COMMA intitem */ + case 154: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==154); +{ yylhsminor.yy525 = tVariantListAppend(yymsp[-2].minor.yy525, &yymsp[0].minor.yy506, -1); } + yymsp[-2].minor.yy525 = yylhsminor.yy525; + break; + case 86: /* intitemlist ::= intitem */ + case 155: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==155); +{ yylhsminor.yy525 = tVariantListAppend(NULL, &yymsp[0].minor.yy506, -1); } + yymsp[0].minor.yy525 = yylhsminor.yy525; + break; + case 87: /* intitem ::= INTEGER */ + case 156: /* tagitem ::= INTEGER */ yytestcase(yyruleno==156); + case 157: /* tagitem ::= FLOAT */ yytestcase(yyruleno==157); + case 158: /* tagitem ::= STRING */ yytestcase(yyruleno==158); + case 159: /* tagitem ::= BOOL */ yytestcase(yyruleno==159); { toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy506, &yymsp[0].minor.yy0); } yymsp[0].minor.yy506 = yylhsminor.yy506; break; - case 82: /* keep ::= KEEP intitemlist */ -{ yymsp[-1].minor.yy441 = yymsp[0].minor.yy441; } - break; - case 83: /* cache ::= CACHE INTEGER */ - case 84: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==84); - case 85: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==85); - case 86: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==86); - case 87: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==87); - case 88: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==88); - case 89: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==89); - case 90: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==90); - case 91: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==91); - case 92: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==92); - case 93: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==93); - case 94: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==94); - case 95: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==95); - case 96: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==96); - case 97: /* partitions ::= PARTITIONS INTEGER */ yytestcase(yyruleno==97); + case 88: /* keep ::= KEEP intitemlist */ +{ yymsp[-1].minor.yy525 = yymsp[0].minor.yy525; } + break; + case 89: /* cache ::= CACHE INTEGER */ + case 90: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==90); + case 91: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==91); + case 92: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==92); + case 93: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==93); + case 94: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==94); + case 95: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==95); + case 96: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==96); + case 97: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==97); + case 98: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==98); + case 99: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==99); + case 100: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==100); + case 101: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==101); + case 102: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==102); + case 103: /* partitions ::= PARTITIONS INTEGER */ yytestcase(yyruleno==103); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 98: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy382); yymsp[1].minor.yy382.dbType = TSDB_DB_TYPE_DEFAULT;} - break; - case 99: /* db_optr ::= db_optr cache */ -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 100: /* db_optr ::= db_optr replica */ - case 117: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==117); -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 101: /* db_optr ::= db_optr quorum */ - case 118: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==118); -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 102: /* db_optr ::= db_optr days */ -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 103: /* db_optr ::= db_optr minrows */ -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 104: /* db_optr ::= db_optr maxrows */ -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 105: /* db_optr ::= db_optr blocks */ - case 120: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==120); -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 106: /* db_optr ::= db_optr ctime */ -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 107: /* db_optr ::= db_optr wal */ -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 108: /* db_optr ::= db_optr fsync */ -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 109: /* db_optr ::= db_optr comp */ - case 121: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==121); -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 110: /* db_optr ::= db_optr prec */ -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.precision = yymsp[0].minor.yy0; } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 111: /* db_optr ::= db_optr keep */ - case 119: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==119); -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.keep = yymsp[0].minor.yy441; } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 112: /* db_optr ::= db_optr update */ - case 122: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==122); -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 113: /* db_optr ::= db_optr cachelast */ - case 123: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==123); -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 114: /* topic_optr ::= db_optr */ - case 124: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==124); -{ yylhsminor.yy382 = yymsp[0].minor.yy382; yylhsminor.yy382.dbType = TSDB_DB_TYPE_TOPIC; } - yymsp[0].minor.yy382 = yylhsminor.yy382; - break; - case 115: /* topic_optr ::= topic_optr partitions */ - case 125: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==125); -{ yylhsminor.yy382 = yymsp[-1].minor.yy382; yylhsminor.yy382.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy382 = yylhsminor.yy382; - break; - case 116: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy382); yymsp[1].minor.yy382.dbType = TSDB_DB_TYPE_DEFAULT;} - break; - case 126: /* typename ::= ids */ + case 104: /* db_optr ::= */ +{setDefaultCreateDbOption(&yymsp[1].minor.yy214); yymsp[1].minor.yy214.dbType = TSDB_DB_TYPE_DEFAULT;} + break; + case 105: /* db_optr ::= db_optr cache */ +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 106: /* db_optr ::= db_optr replica */ + case 123: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==123); +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 107: /* db_optr ::= db_optr quorum */ + case 124: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==124); +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 108: /* db_optr ::= db_optr days */ +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 109: /* db_optr ::= db_optr minrows */ +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 110: /* db_optr ::= db_optr maxrows */ +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 111: /* db_optr ::= db_optr blocks */ + case 126: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==126); +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 112: /* db_optr ::= db_optr ctime */ +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 113: /* db_optr ::= db_optr wal */ +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 114: /* db_optr ::= db_optr fsync */ +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 115: /* db_optr ::= db_optr comp */ + case 127: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==127); +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 116: /* db_optr ::= db_optr prec */ +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 117: /* db_optr ::= db_optr keep */ + case 125: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==125); +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.keep = yymsp[0].minor.yy525; } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 118: /* db_optr ::= db_optr update */ + case 128: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==128); +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 119: /* db_optr ::= db_optr cachelast */ + case 129: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==129); +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 120: /* topic_optr ::= db_optr */ + case 130: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==130); +{ yylhsminor.yy214 = yymsp[0].minor.yy214; yylhsminor.yy214.dbType = TSDB_DB_TYPE_TOPIC; } + yymsp[0].minor.yy214 = yylhsminor.yy214; + break; + case 121: /* topic_optr ::= topic_optr partitions */ + case 131: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==131); +{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy214 = yylhsminor.yy214; + break; + case 122: /* alter_db_optr ::= */ +{ setDefaultCreateDbOption(&yymsp[1].minor.yy214); yymsp[1].minor.yy214.dbType = TSDB_DB_TYPE_DEFAULT;} + break; + case 132: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yylhsminor.yy343, &yymsp[0].minor.yy0); + tSetColumnType (&yylhsminor.yy31, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy343 = yylhsminor.yy343; + yymsp[0].minor.yy31 = yylhsminor.yy31; break; - case 127: /* typename ::= ids LP signed RP */ + case 133: /* typename ::= ids LP signed RP */ { - if (yymsp[-1].minor.yy369 <= 0) { + if (yymsp[-1].minor.yy501 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yylhsminor.yy343, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy31, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy369; // negative value of name length - tSetColumnType(&yylhsminor.yy343, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy501; // negative value of name length + tSetColumnType(&yylhsminor.yy31, &yymsp[-3].minor.yy0); } } - yymsp[-3].minor.yy343 = yylhsminor.yy343; + yymsp[-3].minor.yy31 = yylhsminor.yy31; break; - case 128: /* typename ::= ids UNSIGNED */ + case 134: /* 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.yy343, &yymsp[-1].minor.yy0); + tSetColumnType (&yylhsminor.yy31, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy343 = yylhsminor.yy343; + yymsp[-1].minor.yy31 = yylhsminor.yy31; break; - case 129: /* signed ::= INTEGER */ -{ yylhsminor.yy369 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[0].minor.yy369 = yylhsminor.yy369; + case 135: /* signed ::= INTEGER */ +{ yylhsminor.yy501 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy501 = yylhsminor.yy501; break; - case 130: /* signed ::= PLUS INTEGER */ -{ yymsp[-1].minor.yy369 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 136: /* signed ::= PLUS INTEGER */ +{ yymsp[-1].minor.yy501 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 131: /* signed ::= MINUS INTEGER */ -{ yymsp[-1].minor.yy369 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} + case 137: /* signed ::= MINUS INTEGER */ +{ yymsp[-1].minor.yy501 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; - case 135: /* cmd ::= CREATE TABLE create_table_list */ -{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy182;} + case 141: /* cmd ::= CREATE TABLE create_table_list */ +{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy158;} break; - case 136: /* create_table_list ::= create_from_stable */ + case 142: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); - taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy456); + taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy432); pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE; - yylhsminor.yy182 = pCreateTable; + yylhsminor.yy158 = pCreateTable; } - yymsp[0].minor.yy182 = yylhsminor.yy182; + yymsp[0].minor.yy158 = yylhsminor.yy158; break; - case 137: /* create_table_list ::= create_table_list create_from_stable */ + case 143: /* create_table_list ::= create_table_list create_from_stable */ { - taosArrayPush(yymsp[-1].minor.yy182->childTableInfo, &yymsp[0].minor.yy456); - yylhsminor.yy182 = yymsp[-1].minor.yy182; + taosArrayPush(yymsp[-1].minor.yy158->childTableInfo, &yymsp[0].minor.yy432); + yylhsminor.yy158 = yymsp[-1].minor.yy158; } - yymsp[-1].minor.yy182 = yylhsminor.yy182; + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 138: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + case 144: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yylhsminor.yy182 = tSetCreateTableInfo(yymsp[-1].minor.yy441, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yylhsminor.yy182, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy158 = tSetCreateTableInfo(yymsp[-1].minor.yy525, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy158, 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.yy182 = yylhsminor.yy182; + yymsp[-5].minor.yy158 = yylhsminor.yy158; break; - case 139: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + case 145: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yylhsminor.yy182 = tSetCreateTableInfo(yymsp[-5].minor.yy441, yymsp[-1].minor.yy441, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy182, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy158 = tSetCreateTableInfo(yymsp[-5].minor.yy525, yymsp[-1].minor.yy525, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy158, 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.yy182 = yylhsminor.yy182; + yymsp[-9].minor.yy158 = yylhsminor.yy158; break; - case 140: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + case 146: /* 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.yy456 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy441, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yylhsminor.yy432 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy525, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy456 = yylhsminor.yy456; + yymsp[-9].minor.yy432 = yylhsminor.yy432; break; - case 141: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + case 147: /* 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.yy456 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy441, yymsp[-1].minor.yy441, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yylhsminor.yy432 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy525, yymsp[-1].minor.yy525, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } - yymsp[-12].minor.yy456 = yylhsminor.yy456; + yymsp[-12].minor.yy432 = yylhsminor.yy432; break; - case 142: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy441, &yymsp[0].minor.yy0); yylhsminor.yy441 = yymsp[-2].minor.yy441; } - yymsp[-2].minor.yy441 = yylhsminor.yy441; + case 148: /* tagNamelist ::= tagNamelist COMMA ids */ +{taosArrayPush(yymsp[-2].minor.yy525, &yymsp[0].minor.yy0); yylhsminor.yy525 = yymsp[-2].minor.yy525; } + yymsp[-2].minor.yy525 = yylhsminor.yy525; break; - case 143: /* tagNamelist ::= ids */ -{yylhsminor.yy441 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy441, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy441 = yylhsminor.yy441; + case 149: /* tagNamelist ::= ids */ +{yylhsminor.yy525 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy525, &yymsp[0].minor.yy0);} + yymsp[0].minor.yy525 = yylhsminor.yy525; break; - case 144: /* create_table_args ::= ifnotexists ids cpxName AS select */ + case 150: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yylhsminor.yy182 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy236, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy182, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy158 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy464, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yylhsminor.yy158, 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.yy182 = yylhsminor.yy182; + yymsp[-4].minor.yy158 = yylhsminor.yy158; break; - case 145: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy441, &yymsp[0].minor.yy343); yylhsminor.yy441 = yymsp[-2].minor.yy441; } - yymsp[-2].minor.yy441 = yylhsminor.yy441; + case 151: /* columnlist ::= columnlist COMMA column */ +{taosArrayPush(yymsp[-2].minor.yy525, &yymsp[0].minor.yy31); yylhsminor.yy525 = yymsp[-2].minor.yy525; } + yymsp[-2].minor.yy525 = yylhsminor.yy525; break; - case 146: /* columnlist ::= column */ -{yylhsminor.yy441 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy441, &yymsp[0].minor.yy343);} - yymsp[0].minor.yy441 = yylhsminor.yy441; + case 152: /* columnlist ::= column */ +{yylhsminor.yy525 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy525, &yymsp[0].minor.yy31);} + yymsp[0].minor.yy525 = yylhsminor.yy525; break; - case 147: /* column ::= ids typename */ + case 153: /* column ::= ids typename */ { - tSetColumnInfo(&yylhsminor.yy343, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy343); + tSetColumnInfo(&yylhsminor.yy31, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy31); } - yymsp[-1].minor.yy343 = yylhsminor.yy343; + yymsp[-1].minor.yy31 = yylhsminor.yy31; break; - case 154: /* tagitem ::= NULL */ + case 160: /* tagitem ::= NULL */ { yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy506, &yymsp[0].minor.yy0); } yymsp[0].minor.yy506 = yylhsminor.yy506; break; - case 155: /* tagitem ::= NOW */ + case 161: /* tagitem ::= NOW */ { yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&yylhsminor.yy506, &yymsp[0].minor.yy0);} yymsp[0].minor.yy506 = yylhsminor.yy506; break; - case 156: /* tagitem ::= MINUS INTEGER */ - case 157: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==157); - case 158: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==158); - case 159: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==159); + case 162: /* tagitem ::= MINUS INTEGER */ + case 163: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==163); + case 164: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==164); + case 165: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==165); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; @@ -2677,179 +2723,179 @@ static void yy_reduce( } yymsp[-1].minor.yy506 = yylhsminor.yy506; break; - case 160: /* select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + case 166: /* select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ { - yylhsminor.yy236 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy441, yymsp[-11].minor.yy244, yymsp[-10].minor.yy166, yymsp[-4].minor.yy441, yymsp[-2].minor.yy441, &yymsp[-9].minor.yy340, &yymsp[-8].minor.yy259, &yymsp[-7].minor.yy348, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy441, &yymsp[0].minor.yy414, &yymsp[-1].minor.yy414, yymsp[-3].minor.yy166); + yylhsminor.yy464 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy525, yymsp[-11].minor.yy412, yymsp[-10].minor.yy370, yymsp[-4].minor.yy525, yymsp[-2].minor.yy525, &yymsp[-9].minor.yy520, &yymsp[-8].minor.yy259, &yymsp[-7].minor.yy144, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy525, &yymsp[0].minor.yy126, &yymsp[-1].minor.yy126, yymsp[-3].minor.yy370); } - yymsp[-13].minor.yy236 = yylhsminor.yy236; + yymsp[-13].minor.yy464 = yylhsminor.yy464; break; - case 161: /* select ::= LP select RP */ -{yymsp[-2].minor.yy236 = yymsp[-1].minor.yy236;} + case 167: /* select ::= LP select RP */ +{yymsp[-2].minor.yy464 = yymsp[-1].minor.yy464;} break; - case 162: /* union ::= select */ -{ yylhsminor.yy441 = setSubclause(NULL, yymsp[0].minor.yy236); } - yymsp[0].minor.yy441 = yylhsminor.yy441; + case 168: /* union ::= select */ +{ yylhsminor.yy525 = setSubclause(NULL, yymsp[0].minor.yy464); } + yymsp[0].minor.yy525 = yylhsminor.yy525; break; - case 163: /* union ::= union UNION ALL select */ -{ yylhsminor.yy441 = appendSelectClause(yymsp[-3].minor.yy441, yymsp[0].minor.yy236); } - yymsp[-3].minor.yy441 = yylhsminor.yy441; + case 169: /* union ::= union UNION ALL select */ +{ yylhsminor.yy525 = appendSelectClause(yymsp[-3].minor.yy525, yymsp[0].minor.yy464); } + yymsp[-3].minor.yy525 = yylhsminor.yy525; break; - case 164: /* cmd ::= union */ -{ setSqlInfo(pInfo, yymsp[0].minor.yy441, NULL, TSDB_SQL_SELECT); } + case 170: /* cmd ::= union */ +{ setSqlInfo(pInfo, yymsp[0].minor.yy525, NULL, TSDB_SQL_SELECT); } break; - case 165: /* select ::= SELECT selcollist */ + case 171: /* select ::= SELECT selcollist */ { - yylhsminor.yy236 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy441, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy464 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy525, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - yymsp[-1].minor.yy236 = yylhsminor.yy236; + yymsp[-1].minor.yy464 = yylhsminor.yy464; break; - case 166: /* sclp ::= selcollist COMMA */ -{yylhsminor.yy441 = yymsp[-1].minor.yy441;} - yymsp[-1].minor.yy441 = yylhsminor.yy441; + case 172: /* sclp ::= selcollist COMMA */ +{yylhsminor.yy525 = yymsp[-1].minor.yy525;} + yymsp[-1].minor.yy525 = yylhsminor.yy525; break; - case 167: /* sclp ::= */ - case 197: /* orderby_opt ::= */ yytestcase(yyruleno==197); -{yymsp[1].minor.yy441 = 0;} + case 173: /* sclp ::= */ + case 203: /* orderby_opt ::= */ yytestcase(yyruleno==203); +{yymsp[1].minor.yy525 = 0;} break; - case 168: /* selcollist ::= sclp distinct expr as */ + case 174: /* selcollist ::= sclp distinct expr as */ { - yylhsminor.yy441 = tSqlExprListAppend(yymsp[-3].minor.yy441, yymsp[-1].minor.yy166, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy525 = tSqlExprListAppend(yymsp[-3].minor.yy525, yymsp[-1].minor.yy370, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } - yymsp[-3].minor.yy441 = yylhsminor.yy441; + yymsp[-3].minor.yy525 = yylhsminor.yy525; break; - case 169: /* selcollist ::= sclp STAR */ + case 175: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); - yylhsminor.yy441 = tSqlExprListAppend(yymsp[-1].minor.yy441, pNode, 0, 0); + yylhsminor.yy525 = tSqlExprListAppend(yymsp[-1].minor.yy525, pNode, 0, 0); } - yymsp[-1].minor.yy441 = yylhsminor.yy441; + yymsp[-1].minor.yy525 = yylhsminor.yy525; break; - case 170: /* as ::= AS ids */ + case 176: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 171: /* as ::= ids */ + case 177: /* as ::= ids */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 172: /* as ::= */ + case 178: /* as ::= */ { yymsp[1].minor.yy0.n = 0; } break; - case 173: /* distinct ::= DISTINCT */ + case 179: /* distinct ::= DISTINCT */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 175: /* from ::= FROM tablelist */ - case 176: /* from ::= FROM sub */ yytestcase(yyruleno==176); -{yymsp[-1].minor.yy244 = yymsp[0].minor.yy244;} + case 181: /* from ::= FROM tablelist */ + case 182: /* from ::= FROM sub */ yytestcase(yyruleno==182); +{yymsp[-1].minor.yy412 = yymsp[0].minor.yy412;} break; - case 177: /* sub ::= LP union RP */ -{yymsp[-2].minor.yy244 = addSubqueryElem(NULL, yymsp[-1].minor.yy441, NULL);} + case 183: /* sub ::= LP union RP */ +{yymsp[-2].minor.yy412 = addSubqueryElem(NULL, yymsp[-1].minor.yy525, NULL);} break; - case 178: /* sub ::= LP union RP ids */ -{yymsp[-3].minor.yy244 = addSubqueryElem(NULL, yymsp[-2].minor.yy441, &yymsp[0].minor.yy0);} + case 184: /* sub ::= LP union RP ids */ +{yymsp[-3].minor.yy412 = addSubqueryElem(NULL, yymsp[-2].minor.yy525, &yymsp[0].minor.yy0);} break; - case 179: /* sub ::= sub COMMA LP union RP ids */ -{yylhsminor.yy244 = addSubqueryElem(yymsp[-5].minor.yy244, yymsp[-2].minor.yy441, &yymsp[0].minor.yy0);} - yymsp[-5].minor.yy244 = yylhsminor.yy244; + case 185: /* sub ::= sub COMMA LP union RP ids */ +{yylhsminor.yy412 = addSubqueryElem(yymsp[-5].minor.yy412, yymsp[-2].minor.yy525, &yymsp[0].minor.yy0);} + yymsp[-5].minor.yy412 = yylhsminor.yy412; break; - case 180: /* tablelist ::= ids cpxName */ + case 186: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy244 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy412 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } - yymsp[-1].minor.yy244 = yylhsminor.yy244; + yymsp[-1].minor.yy412 = yylhsminor.yy412; break; - case 181: /* tablelist ::= ids cpxName ids */ + case 187: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy244 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy412 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy244 = yylhsminor.yy244; + yymsp[-2].minor.yy412 = yylhsminor.yy412; break; - case 182: /* tablelist ::= tablelist COMMA ids cpxName */ + case 188: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy244 = setTableNameList(yymsp[-3].minor.yy244, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy412 = setTableNameList(yymsp[-3].minor.yy412, &yymsp[-1].minor.yy0, NULL); } - yymsp[-3].minor.yy244 = yylhsminor.yy244; + yymsp[-3].minor.yy412 = yylhsminor.yy412; break; - case 183: /* tablelist ::= tablelist COMMA ids cpxName ids */ + case 189: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy244 = setTableNameList(yymsp[-4].minor.yy244, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy412 = setTableNameList(yymsp[-4].minor.yy412, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-4].minor.yy244 = yylhsminor.yy244; + yymsp[-4].minor.yy412 = yylhsminor.yy412; break; - case 184: /* tmvar ::= VARIABLE */ + case 190: /* 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.yy340.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy340.offset.n = 0;} + case 191: /* interval_opt ::= INTERVAL LP tmvar RP */ +{yymsp[-3].minor.yy520.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy520.offset.n = 0;} break; - case 186: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ -{yymsp[-5].minor.yy340.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy340.offset = yymsp[-1].minor.yy0;} + case 192: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ +{yymsp[-5].minor.yy520.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy520.offset = yymsp[-1].minor.yy0;} break; - case 187: /* interval_opt ::= */ -{memset(&yymsp[1].minor.yy340, 0, sizeof(yymsp[1].minor.yy340));} + case 193: /* interval_opt ::= */ +{memset(&yymsp[1].minor.yy520, 0, sizeof(yymsp[1].minor.yy520));} break; - case 188: /* session_option ::= */ + case 194: /* session_option ::= */ {yymsp[1].minor.yy259.col.n = 0; yymsp[1].minor.yy259.gap.n = 0;} break; - case 189: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 195: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-6].minor.yy259.col = yymsp[-4].minor.yy0; yymsp[-6].minor.yy259.gap = yymsp[-1].minor.yy0; } break; - case 190: /* windowstate_option ::= */ -{ yymsp[1].minor.yy348.col.n = 0; yymsp[1].minor.yy348.col.z = NULL;} + case 196: /* windowstate_option ::= */ +{ yymsp[1].minor.yy144.col.n = 0; yymsp[1].minor.yy144.col.z = NULL;} break; - case 191: /* windowstate_option ::= STATE_WINDOW LP ids RP */ -{ yymsp[-3].minor.yy348.col = yymsp[-1].minor.yy0; } + case 197: /* windowstate_option ::= STATE_WINDOW LP ids RP */ +{ yymsp[-3].minor.yy144.col = yymsp[-1].minor.yy0; } break; - case 192: /* fill_opt ::= */ -{ yymsp[1].minor.yy441 = 0; } + case 198: /* fill_opt ::= */ +{ yymsp[1].minor.yy525 = 0; } break; - case 193: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 199: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { tVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); tVariantCreate(&A, &yymsp[-3].minor.yy0); - tVariantListInsert(yymsp[-1].minor.yy441, &A, -1, 0); - yymsp[-5].minor.yy441 = yymsp[-1].minor.yy441; + tVariantListInsert(yymsp[-1].minor.yy525, &A, -1, 0); + yymsp[-5].minor.yy525 = yymsp[-1].minor.yy525; } break; - case 194: /* fill_opt ::= FILL LP ID RP */ + case 200: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yymsp[-3].minor.yy441 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy525 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 195: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 201: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 196: /* sliding_opt ::= */ + case 202: /* sliding_opt ::= */ {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.yy441 = yymsp[0].minor.yy441;} + case 204: /* orderby_opt ::= ORDER BY sortlist */ +{yymsp[-2].minor.yy525 = yymsp[0].minor.yy525;} break; - case 199: /* sortlist ::= sortlist COMMA item sortorder */ + case 205: /* sortlist ::= sortlist COMMA item sortorder */ { - yylhsminor.yy441 = tVariantListAppend(yymsp[-3].minor.yy441, &yymsp[-1].minor.yy506, yymsp[0].minor.yy112); + yylhsminor.yy525 = tVariantListAppend(yymsp[-3].minor.yy525, &yymsp[-1].minor.yy506, yymsp[0].minor.yy52); } - yymsp[-3].minor.yy441 = yylhsminor.yy441; + yymsp[-3].minor.yy525 = yylhsminor.yy525; break; - case 200: /* sortlist ::= item sortorder */ + case 206: /* sortlist ::= item sortorder */ { - yylhsminor.yy441 = tVariantListAppend(NULL, &yymsp[-1].minor.yy506, yymsp[0].minor.yy112); + yylhsminor.yy525 = tVariantListAppend(NULL, &yymsp[-1].minor.yy506, yymsp[0].minor.yy52); } - yymsp[-1].minor.yy441 = yylhsminor.yy441; + yymsp[-1].minor.yy525 = yylhsminor.yy525; break; - case 201: /* item ::= ids cpxName */ + case 207: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; @@ -2858,227 +2904,227 @@ static void yy_reduce( } yymsp[-1].minor.yy506 = yylhsminor.yy506; break; - case 202: /* sortorder ::= ASC */ -{ yymsp[0].minor.yy112 = TSDB_ORDER_ASC; } + case 208: /* sortorder ::= ASC */ +{ yymsp[0].minor.yy52 = TSDB_ORDER_ASC; } break; - case 203: /* sortorder ::= DESC */ -{ yymsp[0].minor.yy112 = TSDB_ORDER_DESC;} + case 209: /* sortorder ::= DESC */ +{ yymsp[0].minor.yy52 = TSDB_ORDER_DESC;} break; - case 204: /* sortorder ::= */ -{ yymsp[1].minor.yy112 = TSDB_ORDER_ASC; } + case 210: /* sortorder ::= */ +{ yymsp[1].minor.yy52 = TSDB_ORDER_ASC; } break; - case 205: /* groupby_opt ::= */ -{ yymsp[1].minor.yy441 = 0;} + case 211: /* groupby_opt ::= */ +{ yymsp[1].minor.yy525 = 0;} break; - case 206: /* groupby_opt ::= GROUP BY grouplist */ -{ yymsp[-2].minor.yy441 = yymsp[0].minor.yy441;} + case 212: /* groupby_opt ::= GROUP BY grouplist */ +{ yymsp[-2].minor.yy525 = yymsp[0].minor.yy525;} break; - case 207: /* grouplist ::= grouplist COMMA item */ + case 213: /* grouplist ::= grouplist COMMA item */ { - yylhsminor.yy441 = tVariantListAppend(yymsp[-2].minor.yy441, &yymsp[0].minor.yy506, -1); + yylhsminor.yy525 = tVariantListAppend(yymsp[-2].minor.yy525, &yymsp[0].minor.yy506, -1); } - yymsp[-2].minor.yy441 = yylhsminor.yy441; + yymsp[-2].minor.yy525 = yylhsminor.yy525; break; - case 208: /* grouplist ::= item */ + case 214: /* grouplist ::= item */ { - yylhsminor.yy441 = tVariantListAppend(NULL, &yymsp[0].minor.yy506, -1); + yylhsminor.yy525 = tVariantListAppend(NULL, &yymsp[0].minor.yy506, -1); } - yymsp[0].minor.yy441 = yylhsminor.yy441; + yymsp[0].minor.yy525 = yylhsminor.yy525; break; - case 209: /* having_opt ::= */ - case 219: /* where_opt ::= */ yytestcase(yyruleno==219); - case 261: /* expritem ::= */ yytestcase(yyruleno==261); -{yymsp[1].minor.yy166 = 0;} + case 215: /* having_opt ::= */ + case 225: /* where_opt ::= */ yytestcase(yyruleno==225); + case 267: /* expritem ::= */ yytestcase(yyruleno==267); +{yymsp[1].minor.yy370 = 0;} break; - case 210: /* having_opt ::= HAVING expr */ - case 220: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==220); -{yymsp[-1].minor.yy166 = yymsp[0].minor.yy166;} + case 216: /* having_opt ::= HAVING expr */ + case 226: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==226); +{yymsp[-1].minor.yy370 = yymsp[0].minor.yy370;} break; - case 211: /* limit_opt ::= */ - case 215: /* slimit_opt ::= */ yytestcase(yyruleno==215); -{yymsp[1].minor.yy414.limit = -1; yymsp[1].minor.yy414.offset = 0;} + case 217: /* limit_opt ::= */ + case 221: /* slimit_opt ::= */ yytestcase(yyruleno==221); +{yymsp[1].minor.yy126.limit = -1; yymsp[1].minor.yy126.offset = 0;} break; - case 212: /* limit_opt ::= LIMIT signed */ - case 216: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==216); -{yymsp[-1].minor.yy414.limit = yymsp[0].minor.yy369; yymsp[-1].minor.yy414.offset = 0;} + case 218: /* limit_opt ::= LIMIT signed */ + case 222: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==222); +{yymsp[-1].minor.yy126.limit = yymsp[0].minor.yy501; yymsp[-1].minor.yy126.offset = 0;} break; - case 213: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yymsp[-3].minor.yy414.limit = yymsp[-2].minor.yy369; yymsp[-3].minor.yy414.offset = yymsp[0].minor.yy369;} + case 219: /* limit_opt ::= LIMIT signed OFFSET signed */ +{ yymsp[-3].minor.yy126.limit = yymsp[-2].minor.yy501; yymsp[-3].minor.yy126.offset = yymsp[0].minor.yy501;} break; - case 214: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yymsp[-3].minor.yy414.limit = yymsp[0].minor.yy369; yymsp[-3].minor.yy414.offset = yymsp[-2].minor.yy369;} + case 220: /* limit_opt ::= LIMIT signed COMMA signed */ +{ yymsp[-3].minor.yy126.limit = yymsp[0].minor.yy501; yymsp[-3].minor.yy126.offset = yymsp[-2].minor.yy501;} break; - case 217: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yymsp[-3].minor.yy414.limit = yymsp[-2].minor.yy369; yymsp[-3].minor.yy414.offset = yymsp[0].minor.yy369;} + case 223: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ +{yymsp[-3].minor.yy126.limit = yymsp[-2].minor.yy501; yymsp[-3].minor.yy126.offset = yymsp[0].minor.yy501;} break; - case 218: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yymsp[-3].minor.yy414.limit = yymsp[0].minor.yy369; yymsp[-3].minor.yy414.offset = yymsp[-2].minor.yy369;} + case 224: /* slimit_opt ::= SLIMIT signed COMMA signed */ +{yymsp[-3].minor.yy126.limit = yymsp[0].minor.yy501; yymsp[-3].minor.yy126.offset = yymsp[-2].minor.yy501;} break; - case 221: /* expr ::= LP expr RP */ -{yylhsminor.yy166 = yymsp[-1].minor.yy166; yylhsminor.yy166->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy166->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 227: /* expr ::= LP expr RP */ +{yylhsminor.yy370 = yymsp[-1].minor.yy370; yylhsminor.yy370->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy370->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 222: /* expr ::= ID */ -{ yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 228: /* expr ::= ID */ +{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy370 = yylhsminor.yy370; break; - case 223: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 229: /* expr ::= ID DOT ID */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 224: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 230: /* expr ::= ID DOT STAR */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 225: /* expr ::= INTEGER */ -{ yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 231: /* expr ::= INTEGER */ +{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy370 = yylhsminor.yy370; 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.yy166 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} - yymsp[-1].minor.yy166 = yylhsminor.yy166; + case 232: /* expr ::= MINUS INTEGER */ + case 233: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==233); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy370 = yylhsminor.yy370; break; - case 228: /* expr ::= FLOAT */ -{ yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 234: /* expr ::= FLOAT */ +{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy370 = yylhsminor.yy370; 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.yy166 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} - yymsp[-1].minor.yy166 = yylhsminor.yy166; + case 235: /* expr ::= MINUS FLOAT */ + case 236: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==236); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy370 = yylhsminor.yy370; break; - case 231: /* expr ::= STRING */ -{ yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 237: /* expr ::= STRING */ +{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy370 = yylhsminor.yy370; break; - case 232: /* expr ::= NOW */ -{ yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 238: /* expr ::= NOW */ +{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy370 = yylhsminor.yy370; break; - case 233: /* expr ::= VARIABLE */ -{ yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 239: /* expr ::= VARIABLE */ +{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy370 = yylhsminor.yy370; 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.yy166 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} - yymsp[-1].minor.yy166 = yylhsminor.yy166; + case 240: /* expr ::= PLUS VARIABLE */ + case 241: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==241); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} + yymsp[-1].minor.yy370 = yylhsminor.yy370; break; - case 236: /* expr ::= BOOL */ -{ yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 242: /* expr ::= BOOL */ +{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy370 = yylhsminor.yy370; break; - case 237: /* expr ::= NULL */ -{ yylhsminor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 243: /* expr ::= NULL */ +{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} + yymsp[0].minor.yy370 = yylhsminor.yy370; break; - case 238: /* expr ::= ID LP exprlist RP */ -{ yylhsminor.yy166 = tSqlExprCreateFunction(yymsp[-1].minor.yy441, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy166 = yylhsminor.yy166; + case 244: /* expr ::= ID LP exprlist RP */ +{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy370 = tSqlExprCreateFunction(yymsp[-1].minor.yy525, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy370 = yylhsminor.yy370; break; - case 239: /* expr ::= ID LP STAR RP */ -{ yylhsminor.yy166 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy166 = yylhsminor.yy166; + case 245: /* expr ::= ID LP STAR RP */ +{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy370 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy370 = yylhsminor.yy370; break; - case 240: /* expr ::= expr IS NULL */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, NULL, TK_ISNULL);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 246: /* expr ::= expr IS NULL */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, NULL, TK_ISNULL);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 241: /* expr ::= expr IS NOT NULL */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-3].minor.yy166, NULL, TK_NOTNULL);} - yymsp[-3].minor.yy166 = yylhsminor.yy166; + case 247: /* expr ::= expr IS NOT NULL */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-3].minor.yy370, NULL, TK_NOTNULL);} + yymsp[-3].minor.yy370 = yylhsminor.yy370; break; - case 242: /* expr ::= expr LT expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_LT);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 248: /* expr ::= expr LT expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_LT);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 243: /* expr ::= expr GT expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_GT);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 249: /* expr ::= expr GT expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_GT);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 244: /* expr ::= expr LE expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_LE);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 250: /* expr ::= expr LE expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_LE);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 245: /* expr ::= expr GE expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_GE);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 251: /* expr ::= expr GE expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_GE);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 246: /* expr ::= expr NE expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_NE);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 252: /* expr ::= expr NE expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_NE);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 247: /* expr ::= expr EQ expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_EQ);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 253: /* expr ::= expr EQ expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_EQ);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 248: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy166); yylhsminor.yy166 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy166, yymsp[-2].minor.yy166, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy166, TK_LE), TK_AND);} - yymsp[-4].minor.yy166 = yylhsminor.yy166; + case 254: /* expr ::= expr BETWEEN expr AND expr */ +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy370); yylhsminor.yy370 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy370, yymsp[-2].minor.yy370, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy370, TK_LE), TK_AND);} + yymsp[-4].minor.yy370 = yylhsminor.yy370; break; - case 249: /* expr ::= expr AND expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_AND);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 255: /* expr ::= expr AND expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_AND);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 250: /* expr ::= expr OR expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_OR); } - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 256: /* expr ::= expr OR expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_OR); } + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 251: /* expr ::= expr PLUS expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_PLUS); } - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 257: /* expr ::= expr PLUS expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_PLUS); } + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 252: /* expr ::= expr MINUS expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_MINUS); } - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 258: /* expr ::= expr MINUS expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_MINUS); } + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 253: /* expr ::= expr STAR expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_STAR); } - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 259: /* expr ::= expr STAR expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_STAR); } + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 254: /* expr ::= expr SLASH expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_DIVIDE);} - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 260: /* expr ::= expr SLASH expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_DIVIDE);} + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 255: /* expr ::= expr REM expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_REM); } - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 261: /* expr ::= expr REM expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_REM); } + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 256: /* expr ::= expr LIKE expr */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_LIKE); } - yymsp[-2].minor.yy166 = yylhsminor.yy166; + case 262: /* expr ::= expr LIKE expr */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_LIKE); } + yymsp[-2].minor.yy370 = yylhsminor.yy370; break; - case 257: /* expr ::= expr IN LP exprlist RP */ -{yylhsminor.yy166 = tSqlExprCreate(yymsp[-4].minor.yy166, (tSqlExpr*)yymsp[-1].minor.yy441, TK_IN); } - yymsp[-4].minor.yy166 = yylhsminor.yy166; + case 263: /* expr ::= expr IN LP exprlist RP */ +{yylhsminor.yy370 = tSqlExprCreate(yymsp[-4].minor.yy370, (tSqlExpr*)yymsp[-1].minor.yy525, TK_IN); } + yymsp[-4].minor.yy370 = yylhsminor.yy370; break; - case 258: /* exprlist ::= exprlist COMMA expritem */ -{yylhsminor.yy441 = tSqlExprListAppend(yymsp[-2].minor.yy441,yymsp[0].minor.yy166,0, 0);} - yymsp[-2].minor.yy441 = yylhsminor.yy441; + case 264: /* exprlist ::= exprlist COMMA expritem */ +{yylhsminor.yy525 = tSqlExprListAppend(yymsp[-2].minor.yy525,yymsp[0].minor.yy370,0, 0);} + yymsp[-2].minor.yy525 = yylhsminor.yy525; break; - case 259: /* exprlist ::= expritem */ -{yylhsminor.yy441 = tSqlExprListAppend(0,yymsp[0].minor.yy166,0, 0);} - yymsp[0].minor.yy441 = yylhsminor.yy441; + case 265: /* exprlist ::= expritem */ +{yylhsminor.yy525 = tSqlExprListAppend(0,yymsp[0].minor.yy370,0, 0);} + yymsp[0].minor.yy525 = yylhsminor.yy525; break; - case 260: /* expritem ::= expr */ -{yylhsminor.yy166 = yymsp[0].minor.yy166;} - yymsp[0].minor.yy166 = yylhsminor.yy166; + case 266: /* expritem ::= expr */ +{yylhsminor.yy370 = yymsp[0].minor.yy370;} + yymsp[0].minor.yy370 = yylhsminor.yy370; break; - case 262: /* cmd ::= RESET QUERY CACHE */ + case 268: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 263: /* cmd ::= SYNCDB ids REPLICA */ + case 269: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 264: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 270: /* 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.yy441, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 265: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 271: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3089,21 +3135,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 266: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + case 272: /* 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.yy441, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, 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 */ + case 273: /* 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.yy441, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 268: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 274: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3114,7 +3160,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 269: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 275: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3128,7 +3174,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 270: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 276: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3140,21 +3186,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 271: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + case 277: /* 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.yy441, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, 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 */ + case 278: /* 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.yy441, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 273: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 279: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3165,21 +3211,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 274: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + case 280: /* 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.yy441, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, 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 */ + case 281: /* 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.yy441, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 276: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 282: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3190,7 +3236,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 277: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 283: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3204,7 +3250,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 278: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + case 284: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3216,20 +3262,20 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 279: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + case 285: /* 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.yy441, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 280: /* cmd ::= KILL CONNECTION INTEGER */ + case 286: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 281: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 287: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 282: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 288: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: diff --git a/src/tsdb/inc/tsdbMemTable.h b/src/tsdb/inc/tsdbMemTable.h index babb7024b2500f3b8418fa5404bb593c768d8f1f..67e9976c704e15ae33174ff50ffdf1a289b5182a 100644 --- a/src/tsdb/inc/tsdbMemTable.h +++ b/src/tsdb/inc/tsdbMemTable.h @@ -71,27 +71,27 @@ int tsdbLoadDataFromCache(STable* pTable, SSkipListIterator* pIter, TSKEY maxK TKEY* filterKeys, int nFilterKeys, bool keepDup, SMergeInfo* pMergeInfo); void* tsdbCommitData(STsdbRepo* pRepo); -static FORCE_INLINE SDataRow tsdbNextIterRow(SSkipListIterator* pIter) { +static FORCE_INLINE SMemRow tsdbNextIterRow(SSkipListIterator* pIter) { if (pIter == NULL) return NULL; SSkipListNode* node = tSkipListIterGet(pIter); if (node == NULL) return NULL; - return (SDataRow)SL_GET_NODE_DATA(node); + return (SMemRow)SL_GET_NODE_DATA(node); } static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator* pIter) { - SDataRow row = tsdbNextIterRow(pIter); + SMemRow row = tsdbNextIterRow(pIter); if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL; - return dataRowKey(row); + return memRowKey(row); } static FORCE_INLINE TKEY tsdbNextIterTKey(SSkipListIterator* pIter) { - SDataRow row = tsdbNextIterRow(pIter); + SMemRow row = tsdbNextIterRow(pIter); if (row == NULL) return TKEY_NULL; - return dataRowTKey(row); + return memRowTKey(row); } #endif /* _TD_TSDB_MEMTABLE_H_ */ \ No newline at end of file diff --git a/src/tsdb/inc/tsdbMeta.h b/src/tsdb/inc/tsdbMeta.h index 45bbd5a7c6911fed4ea7309a77d3ac144109a34b..9a8de01f71331d091e75fedac61cc333dca165cc 100644 --- a/src/tsdb/inc/tsdbMeta.h +++ b/src/tsdb/inc/tsdbMeta.h @@ -32,7 +32,7 @@ typedef struct STable { void* eventHandler; // TODO void* streamHandler; // TODO TSKEY lastKey; - SDataRow lastRow; + SMemRow lastRow; char* sql; void* cqhandle; SRWLatch latch; // TODO: implementa latch functions @@ -148,7 +148,7 @@ static FORCE_INLINE STSchema *tsdbGetTableTagSchema(STable *pTable) { } static FORCE_INLINE TSKEY tsdbGetTableLastKeyImpl(STable* pTable) { - ASSERT(pTable->lastRow == NULL || pTable->lastKey == dataRowKey(pTable->lastRow)); + ASSERT((pTable->lastRow == NULL) || (pTable->lastKey == memRowKey(pTable->lastRow))); return pTable->lastKey; } diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index 75b072b063772f898753ac46ef8f05ccb490007c..6330da60585afb590ee82018b3204280f62e5f1c 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -920,7 +920,8 @@ int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDataCo SDataCol * pDataCol = pDataCols->cols + ncol; SBlockCol *pBlockCol = pBlockData->cols + nColsNotAllNull; - if (isNEleNull(pDataCol, rowsToWrite)) { // all data to commit are NULL, just ignore it + // if (isNEleNull(pDataCol, rowsToWrite)) { // all data to commit are NULL, just ignore it + if (isAllRowsNull(pDataCol)) { // all data to commit are NULL, just ignore it continue; } @@ -1264,12 +1265,12 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt while (true) { key1 = (*iter >= pDataCols->numOfRows) ? INT64_MAX : dataColsKeyAt(pDataCols, *iter); bool isRowDel = false; - SDataRow row = tsdbNextIterRow(pCommitIter->pIter); - if (row == NULL || dataRowKey(row) > maxKey) { + SMemRow row = tsdbNextIterRow(pCommitIter->pIter); + if (row == NULL || memRowKey(row) > maxKey) { key2 = INT64_MAX; } else { - key2 = dataRowKey(row); - isRowDel = dataRowDeleted(row); + key2 = memRowKey(row); + isRowDel = memRowDeleted(row); } if (key1 == INT64_MAX && key2 == INT64_MAX) break; @@ -1284,24 +1285,24 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt (*iter)++; } else if (key1 > key2) { if (!isRowDel) { - if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) { - pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, dataRowVersion(row)); + if (pSchema == NULL || schemaVersion(pSchema) != memRowVersion(row)) { + pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, memRowVersion(row)); ASSERT(pSchema != NULL); } - tdAppendDataRowToDataCol(row, pSchema, pTarget); + tdAppendMemRowToDataCol(row, pSchema, pTarget); } tSkipListIterNext(pCommitIter->pIter); } else { if (update) { if (!isRowDel) { - if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) { - pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, dataRowVersion(row)); + if (pSchema == NULL || schemaVersion(pSchema) != memRowVersion(row)) { + pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, memRowVersion(row)); ASSERT(pSchema != NULL); } - tdAppendDataRowToDataCol(row, pSchema, pTarget); + tdAppendMemRowToDataCol(row, pSchema, pTarget); } } else { ASSERT(!isRowDel); diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 09f3585b9d60151edc56995ba25ac063297dad5d..8266a7c20fd8286afa11e4c3ddbbeed51b503ee6 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -641,7 +641,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea int numColumns; int32_t blockIdx; SDataStatis* pBlockStatis = NULL; - SDataRow row = NULL; + SMemRow row = NULL; // restore last column data with last schema int err = 0; @@ -657,13 +657,15 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea } } - row = taosTMalloc(dataRowMaxBytesFromSchema(pSchema)); + row = taosTMalloc(memRowMaxBytesFromSchema(pSchema)); if (row == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; err = -1; goto out; } - tdInitDataRow(row, pSchema); + + memRowSetType(row, SMEM_ROW_DATA); + tdInitDataRow(memRowDataBody(row), pSchema); // first load block index info if (tsdbLoadBlockInfo(pReadh, NULL) < 0) { @@ -720,9 +722,9 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea // OK,let's load row from backward to get not-null column for (int32_t rowId = pBlock->numOfRows - 1; rowId >= 0; rowId--) { SDataCol *pDataCol = pReadh->pDCols[0]->cols + i; - tdAppendColVal(row, tdGetColDataOfRow(pDataCol, rowId), pCol->type, pCol->bytes, pCol->offset); + tdAppendColVal(memRowDataBody(row), tdGetColDataOfRow(pDataCol, rowId), pCol->type, pCol->offset); //SDataCol *pDataCol = readh.pDCols[0]->cols + j; - void* value = tdGetRowDataOfCol(row, (int8_t)pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset); + void *value = tdGetRowDataOfCol(memRowDataBody(row), (int8_t)pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset); if (isNull(value, pCol->type)) { continue; } @@ -742,8 +744,8 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea // save row ts(in column 0) pDataCol = pReadh->pDCols[0]->cols + 0; pCol = schemaColAt(pSchema, 0); - tdAppendColVal(row, tdGetColDataOfRow(pDataCol, rowId), pCol->type, pCol->bytes, pCol->offset); - pLastCol->ts = dataRowKey(row); + tdAppendColVal(memRowDataBody(row), tdGetColDataOfRow(pDataCol, rowId), pCol->type, pCol->offset); + pLastCol->ts = memRowKey(row); pTable->restoreColumnNum += 1; @@ -779,18 +781,18 @@ static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh, // Get the data in row STSchema *pSchema = tsdbGetTableSchema(pTable); - pTable->lastRow = taosTMalloc(dataRowMaxBytesFromSchema(pSchema)); + pTable->lastRow = taosTMalloc(memRowMaxBytesFromSchema(pSchema)); if (pTable->lastRow == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } - - tdInitDataRow(pTable->lastRow, pSchema); + memRowSetType(pTable->lastRow, SMEM_ROW_DATA); + tdInitDataRow(memRowDataBody(pTable->lastRow), pSchema); for (int icol = 0; icol < schemaNCols(pSchema); icol++) { STColumn *pCol = schemaColAt(pSchema, icol); SDataCol *pDataCol = pReadh->pDCols[0]->cols + icol; - tdAppendColVal(pTable->lastRow, tdGetColDataOfRow(pDataCol, pBlock->numOfRows - 1), pCol->type, pCol->bytes, - pCol->offset); + tdAppendColVal(memRowDataBody(pTable->lastRow), tdGetColDataOfRow(pDataCol, pBlock->numOfRows - 1), pCol->type, + pCol->offset); } return 0; diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 50b5d321773f6d9d51d29759eb16a9b07bc7e1d8..9ac5503e5f9dae8012c0ee76ec088c25cf43fb59 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -21,7 +21,7 @@ typedef struct { int32_t totalLen; int32_t len; - SDataRow row; + SMemRow row; } SSubmitBlkIter; typedef struct { @@ -36,20 +36,19 @@ static STableData *tsdbNewTableData(STsdbCfg *pCfg, STable *pTable); static void tsdbFreeTableData(STableData *pTableData); static char * tsdbGetTsTupleKey(const void *data); static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables); -static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, SDataRow row); +static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, SMemRow row); static int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter); -static SDataRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter); +static SMemRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter); static int tsdbScanAndConvertSubmitMsg(STsdbRepo *pRepo, SSubmitMsg *pMsg); static int tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, int32_t *affectedrows); -static int tsdbCopyRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable, void **ppRow); +static int tsdbCopyRowToMem(STsdbRepo *pRepo, SMemRow row, STable *pTable, void **ppRow); static int tsdbInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIter); static int tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock); static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pTable); static int tsdbInsertDataToTableImpl(STsdbRepo *pRepo, STable *pTable, void **rows, int rowCounter); static void tsdbFreeRows(STsdbRepo *pRepo, void **rows, int rowCounter); -static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SDataRow row); - -static FORCE_INLINE int tsdbCheckRowRange(STsdbRepo *pRepo, STable *pTable, SDataRow row, TSKEY minKey, TSKEY maxKey, +static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SMemRow row); +static FORCE_INLINE int tsdbCheckRowRange(STsdbRepo *pRepo, STable *pTable, SMemRow row, TSKEY minKey, TSKEY maxKey, TSKEY now); int32_t tsdbInsertData(STsdbRepo *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *pRsp) { @@ -354,7 +353,7 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey TSKEY fKey = 0; bool isRowDel = false; int filterIter = 0; - SDataRow row = NULL; + SMemRow row = NULL; SMergeInfo mInfo; if (pMergeInfo == NULL) pMergeInfo = &mInfo; @@ -365,12 +364,12 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey if (pCols) tdResetDataCols(pCols); row = tsdbNextIterRow(pIter); - if (row == NULL || dataRowKey(row) > maxKey) { + if (row == NULL || memRowKey(row) > maxKey) { rowKey = INT64_MAX; isRowDel = false; } else { - rowKey = dataRowKey(row); - isRowDel = dataRowDeleted(row); + rowKey = memRowKey(row); + isRowDel = memRowDeleted(row); } if (filterIter >= nFilterKeys) { @@ -407,12 +406,12 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey tSkipListIterNext(pIter); row = tsdbNextIterRow(pIter); - if (row == NULL || dataRowKey(row) > maxKey) { + if (row == NULL || memRowKey(row) > maxKey) { rowKey = INT64_MAX; isRowDel = false; } else { - rowKey = dataRowKey(row); - isRowDel = dataRowDeleted(row); + rowKey = memRowKey(row); + isRowDel = memRowDeleted(row); } } else { if (isRowDel) { @@ -437,12 +436,12 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey tSkipListIterNext(pIter); row = tsdbNextIterRow(pIter); - if (row == NULL || dataRowKey(row) > maxKey) { + if (row == NULL || memRowKey(row) > maxKey) { rowKey = INT64_MAX; isRowDel = false; } else { - rowKey = dataRowKey(row); - isRowDel = dataRowDeleted(row); + rowKey = memRowKey(row); + isRowDel = memRowDeleted(row); } filterIter++; @@ -548,7 +547,7 @@ static void tsdbFreeTableData(STableData *pTableData) { } } -static char *tsdbGetTsTupleKey(const void *data) { return dataRowTuple((SDataRow)data); } +static char *tsdbGetTsTupleKey(const void *data) { return memRowTuple((SMemRow)data); } static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables) { ASSERT(pMemTable->maxTables < maxTables); @@ -572,17 +571,17 @@ static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables) { return 0; } -static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, SDataRow row) { +static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, SMemRow row) { if (pCols) { - if (*ppSchema == NULL || schemaVersion(*ppSchema) != dataRowVersion(row)) { - *ppSchema = tsdbGetTableSchemaImpl(pTable, false, false, dataRowVersion(row)); + if (*ppSchema == NULL || schemaVersion(*ppSchema) != memRowVersion(row)) { + *ppSchema = tsdbGetTableSchemaImpl(pTable, false, false, memRowVersion(row)); if (*ppSchema == NULL) { ASSERT(false); return -1; } } - tdAppendDataRowToDataCol(row, *ppSchema, pCols); + tdAppendMemRowToDataCol(row, *ppSchema, pCols); } return 0; @@ -592,31 +591,32 @@ static int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter) { if (pBlock->dataLen <= 0) return -1; pIter->totalLen = pBlock->dataLen; pIter->len = 0; - pIter->row = (SDataRow)(pBlock->data+pBlock->schemaLen); + pIter->row = (SMemRow)(pBlock->data + pBlock->schemaLen); return 0; } -static SDataRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter) { - SDataRow row = pIter->row; +static SMemRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter) { + SMemRow row = pIter->row; // firstly, get current row if (row == NULL) return NULL; - pIter->len += dataRowLen(row); - if (pIter->len >= pIter->totalLen) { + pIter->len += memRowTLen(row); + if (pIter->len >= pIter->totalLen) { // reach the end pIter->row = NULL; } else { - pIter->row = (char *)row + dataRowLen(row); + pIter->row = (char *)row + memRowTLen(row); // secondly, move to next row } return row; } -static FORCE_INLINE int tsdbCheckRowRange(STsdbRepo *pRepo, STable *pTable, SDataRow row, TSKEY minKey, TSKEY maxKey, +static FORCE_INLINE int tsdbCheckRowRange(STsdbRepo *pRepo, STable *pTable, SMemRow row, TSKEY minKey, TSKEY maxKey, TSKEY now) { - if (dataRowKey(row) < minKey || dataRowKey(row) > maxKey) { + TSKEY rowKey = memRowKey(row); + if (rowKey < minKey || rowKey > maxKey) { tsdbError("vgId:%d table %s tid %d uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64 " maxKey %" PRId64 " row key %" PRId64, REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), now, minKey, maxKey, - dataRowKey(row)); + rowKey); terrno = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE; return -1; } @@ -630,7 +630,7 @@ static int tsdbScanAndConvertSubmitMsg(STsdbRepo *pRepo, SSubmitMsg *pMsg) { SSubmitMsgIter msgIter = {0}; SSubmitBlk * pBlock = NULL; SSubmitBlkIter blkIter = {0}; - SDataRow row = NULL; + SMemRow row = NULL; TSKEY now = taosGetTimestamp(pRepo->config.precision); TSKEY minKey = now - tsTickPerDay[pRepo->config.precision] * pRepo->config.keep; TSKEY maxKey = now + tsTickPerDay[pRepo->config.precision] * pRepo->config.daysPerFile; @@ -698,7 +698,7 @@ static int tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, int32_t * int64_t points = 0; STable * pTable = NULL; SSubmitBlkIter blkIter = {0}; - SDataRow row = NULL; + SMemRow row = NULL; void * rows[TSDB_MAX_INSERT_BATCH] = {0}; int rowCounter = 0; @@ -744,10 +744,10 @@ _err: return -1; } -static int tsdbCopyRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable, void **ppRow) { +static int tsdbCopyRowToMem(STsdbRepo *pRepo, SMemRow row, STable *pTable, void **ppRow) { STsdbCfg * pCfg = &pRepo->config; - TKEY tkey = dataRowTKey(row); - TSKEY key = dataRowKey(row); + TKEY tkey = memRowTKey(row); + TSKEY key = memRowKey(row); bool isRowDelete = TKEY_IS_DELETED(tkey); if (isRowDelete) { @@ -765,15 +765,15 @@ static int tsdbCopyRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable, void } } - void *pRow = tsdbAllocBytes(pRepo, dataRowLen(row)); + void *pRow = tsdbAllocBytes(pRepo, memRowTLen(row)); if (pRow == NULL) { - tsdbError("vgId:%d failed to insert row with key %" PRId64 " to table %s while allocate %d bytes since %s", - REPO_ID(pRepo), key, TABLE_CHAR_NAME(pTable), dataRowLen(row), tstrerror(terrno)); + tsdbError("vgId:%d failed to insert row with key %" PRId64 " to table %s while allocate %" PRIu32 " bytes since %s", + REPO_ID(pRepo), key, TABLE_CHAR_NAME(pTable), memRowTLen(row), tstrerror(terrno)); return -1; } - dataRowCpy(pRow, row); - ppRow[0] = pRow; + memRowCpy(pRow, row); + ppRow[0] = pRow; // save the memory address of data rows tsdbTrace("vgId:%d a row is %s table %s tid %d uid %" PRIu64 " key %" PRIu64, REPO_ID(pRepo), isRowDelete ? "deleted from" : "updated in", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), @@ -932,13 +932,15 @@ static int tsdbInsertDataToTableImpl(STsdbRepo *pRepo, STable *pTable, void **ro int64_t osize = SL_SIZE(pTableData->pData); tSkipListPutBatch(pTableData->pData, rows, rowCounter); int64_t dsize = SL_SIZE(pTableData->pData) - osize; + TSKEY keyFirstRow = memRowKey(rows[0]); + TSKEY keyLastRow = memRowKey(rows[rowCounter - 1]); - if (pMemTable->keyFirst > dataRowKey(rows[0])) pMemTable->keyFirst = dataRowKey(rows[0]); - if (pMemTable->keyLast < dataRowKey(rows[rowCounter - 1])) pMemTable->keyLast = dataRowKey(rows[rowCounter - 1]); + if (pMemTable->keyFirst > keyFirstRow) pMemTable->keyFirst = keyFirstRow; + if (pMemTable->keyLast < keyLastRow) pMemTable->keyLast = keyLastRow; pMemTable->numOfRows += dsize; - if (pTableData->keyFirst > dataRowKey(rows[0])) pTableData->keyFirst = dataRowKey(rows[0]); - if (pTableData->keyLast < dataRowKey(rows[rowCounter - 1])) pTableData->keyLast = dataRowKey(rows[rowCounter - 1]); + if (pTableData->keyFirst > keyFirstRow) pTableData->keyFirst = keyFirstRow; + if (pTableData->keyLast < keyLastRow) pTableData->keyLast = keyLastRow; pTableData->numOfRows += dsize; // update table latest info @@ -954,8 +956,8 @@ static void tsdbFreeRows(STsdbRepo *pRepo, void **rows, int rowCounter) { STsdbBufPool *pBufPool = pRepo->pPool; for (int i = rowCounter - 1; i >= 0; --i) { - SDataRow row = (SDataRow)rows[i]; - int bytes = (int)dataRowLen(row); + SMemRow row = (SMemRow)rows[i]; + int bytes = (int)memRowTLen(row); if (pRepo->mem->extraBuffList == NULL) { STsdbBufBlock *pBufBlock = tsdbGetCurrBufBlock(pRepo); @@ -988,21 +990,23 @@ static void tsdbFreeRows(STsdbRepo *pRepo, void **rows, int rowCounter) { } } -static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, SDataRow row) { - tsdbDebug("vgId:%d updateTableLatestColumn, %s row version:%d", REPO_ID(pRepo), pTable->name->data, dataRowVersion(row)); +static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, SMemRow row) { + tsdbDebug("vgId:%d updateTableLatestColumn, %s row version:%d", REPO_ID(pRepo), pTable->name->data, + memRowVersion(row)); STSchema* pSchema = tsdbGetTableLatestSchema(pTable); if (tsdbUpdateLastColSchema(pTable, pSchema) < 0) { return; } - pSchema = tsdbGetTableSchemaByVersion(pTable, dataRowVersion(row)); + pSchema = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row)); if (pSchema == NULL) { return; } SDataCol *pLatestCols = pTable->lastCols; + bool isDataRow = isDataRow(row); for (int16_t j = 0; j < schemaNCols(pSchema); j++) { STColumn *pTCol = schemaColAt(pSchema, j); // ignore not exist colId @@ -1010,9 +1014,21 @@ static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, SDataRow r if (idx == -1) { continue; } - - void* value = tdGetRowDataOfCol(row, (int8_t)pTCol->type, TD_DATA_ROW_HEAD_SIZE + pSchema->columns[j].offset); - if (isNull(value, pTCol->type)) { + + void *value = NULL; + + if (isDataRow) { + value = tdGetRowDataOfCol(memRowDataBody(row), (int8_t)pTCol->type, + TD_DATA_ROW_HEAD_SIZE + pSchema->columns[j].offset); + } else { + // SKVRow + SColIdx *pColIdx = tdGetKVRowIdxOfCol(memRowKvBody(row), pTCol->colId); + if (pColIdx) { + value = tdGetKvRowDataOfCol(memRowKvBody(row), pColIdx->offset); + } + } + + if ((value == NULL) || isNull(value, pTCol->type)) { continue; } @@ -1027,11 +1043,11 @@ static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, SDataRow r memcpy(pDataCol->pData, value, pDataCol->bytes); //tsdbInfo("updateTableLatestColumn vgId:%d cache column %d for %d,%s", REPO_ID(pRepo), j, pDataCol->bytes, (char*)pDataCol->pData); - pDataCol->ts = dataRowKey(row); + pDataCol->ts = memRowKey(row); } } -static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SDataRow row) { +static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SMemRow row) { STsdbCfg *pCfg = &pRepo->config; // if cacheLastRow config has been reset, free the lastRow @@ -1042,31 +1058,31 @@ static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SDataRow TSDB_WUNLOCK_TABLE(pTable); } - if (tsdbGetTableLastKeyImpl(pTable) < dataRowKey(row)) { + if (tsdbGetTableLastKeyImpl(pTable) < memRowKey(row)) { if (CACHE_LAST_ROW(pCfg) || pTable->lastRow != NULL) { - SDataRow nrow = pTable->lastRow; - if (taosTSizeof(nrow) < dataRowLen(row)) { - SDataRow orow = nrow; - nrow = taosTMalloc(dataRowLen(row)); + SMemRow nrow = pTable->lastRow; + if (taosTSizeof(nrow) < memRowTLen(row)) { + SMemRow orow = nrow; + nrow = taosTMalloc(memRowTLen(row)); if (nrow == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } - dataRowCpy(nrow, row); + memRowCpy(nrow, row); TSDB_WLOCK_TABLE(pTable); - pTable->lastKey = dataRowKey(row); + pTable->lastKey = memRowKey(row); pTable->lastRow = nrow; TSDB_WUNLOCK_TABLE(pTable); taosTZfree(orow); } else { TSDB_WLOCK_TABLE(pTable); - pTable->lastKey = dataRowKey(row); - dataRowCpy(nrow, row); + pTable->lastKey = memRowKey(row); + memRowCpy(nrow, row); TSDB_WUNLOCK_TABLE(pTable); } } else { - pTable->lastKey = dataRowKey(row); + pTable->lastKey = memRowKey(row); } if (CACHE_LAST_NULL_COLUMN(pCfg)) { diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 1eafb5e23371da93454e8b6b8700341c02d38441..c48851df45722b32196f6ad141f2d59ea541898b 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -147,7 +147,7 @@ typedef struct STableGroupSupporter { static STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList); static int32_t checkForCachedLastRow(STsdbQueryHandle* pQueryHandle, STableGroupInfo *groupList); static int32_t checkForCachedLast(STsdbQueryHandle* pQueryHandle); -static int32_t tsdbGetCachedLastRow(STable* pTable, SDataRow* pRes, TSKEY* lastKey); +static int32_t tsdbGetCachedLastRow(STable* pTable, SMemRow* pRes, TSKEY* lastKey); static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle); static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock); @@ -734,8 +734,8 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter); assert(node != NULL); - SDataRow row = (SDataRow)SL_GET_NODE_DATA(node); - TSKEY key = dataRowKey(row); // first timestamp in buffer + SMemRow row = (SMemRow)SL_GET_NODE_DATA(node); + TSKEY key = memRowKey(row); // first timestamp in buffer tsdbDebug("%p uid:%" PRId64 ", tid:%d check data in mem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%"PRId64", 0x%"PRIx64, pHandle, pCheckInfo->tableId.uid, pCheckInfo->tableId.tid, key, order, pMem->keyFirst, pMem->keyLast, @@ -756,8 +756,8 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter); assert(node != NULL); - SDataRow row = (SDataRow)SL_GET_NODE_DATA(node); - TSKEY key = dataRowKey(row); // first timestamp in buffer + SMemRow row = (SMemRow)SL_GET_NODE_DATA(node); + TSKEY key = memRowKey(row); // first timestamp in buffer tsdbDebug("%p uid:%" PRId64 ", tid:%d check data in imem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%"PRId64", 0x%"PRIx64, pHandle, pCheckInfo->tableId.uid, pCheckInfo->tableId.tid, key, order, pIMem->keyFirst, pIMem->keyLast, @@ -781,19 +781,19 @@ static void destroyTableMemIterator(STableCheckInfo* pCheckInfo) { tSkipListDestroyIter(pCheckInfo->iiter); } -static SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update) { - SDataRow rmem = NULL, rimem = NULL; +static SMemRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update) { + SMemRow rmem = NULL, rimem = NULL; if (pCheckInfo->iter) { SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter); if (node != NULL) { - rmem = (SDataRow)SL_GET_NODE_DATA(node); + rmem = (SMemRow)SL_GET_NODE_DATA(node); } } if (pCheckInfo->iiter) { SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter); if (node != NULL) { - rimem = (SDataRow)SL_GET_NODE_DATA(node); + rimem = (SMemRow)SL_GET_NODE_DATA(node); } } @@ -811,8 +811,8 @@ static SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order return rimem; } - TSKEY r1 = dataRowKey(rmem); - TSKEY r2 = dataRowKey(rimem); + TSKEY r1 = memRowKey(rmem); + TSKEY r2 = memRowKey(rimem); if (r1 == r2) { // data ts are duplicated, ignore the data in mem if (!update) { @@ -891,12 +891,12 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) { initTableMemIterator(pHandle, pCheckInfo); } - SDataRow row = getSDataRowInTableMem(pCheckInfo, pHandle->order, pCfg->update); + SMemRow row = getSDataRowInTableMem(pCheckInfo, pHandle->order, pCfg->update); if (row == NULL) { return false; } - pCheckInfo->lastKey = dataRowKey(row); // first timestamp in buffer + pCheckInfo->lastKey = memRowKey(row); // first timestamp in buffer tsdbDebug("%p uid:%" PRId64", tid:%d check data in buffer from skey:%" PRId64 ", order:%d, 0x%"PRIx64, pHandle, pCheckInfo->tableId.uid, pCheckInfo->tableId.tid, pCheckInfo->lastKey, pHandle->order, pHandle->qId); @@ -1155,11 +1155,11 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p int32_t code = TSDB_CODE_SUCCESS; /*bool hasData = */ initTableMemIterator(pQueryHandle, pCheckInfo); - SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update); + SMemRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update); assert(cur->pos >= 0 && cur->pos <= binfo.rows); - TSKEY key = (row != NULL)? dataRowKey(row):TSKEY_INITIAL_VAL; + TSKEY key = (row != NULL) ? memRowKey(row) : TSKEY_INITIAL_VAL; if (key != TSKEY_INITIAL_VAL) { tsdbDebug("%p key in mem:%"PRId64", 0x%"PRIx64, pQueryHandle, key, pQueryHandle->qId); } else { @@ -1401,7 +1401,7 @@ int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t capacity // todo refactor, only copy one-by-one for (int32_t k = start; k < num + start; ++k) { - char* p = tdGetColDataOfRow(src, k); + const char* p = tdGetColDataOfRow(src, k); memcpy(dst, p, varDataTLen(p)); dst += bytes; } @@ -1452,88 +1452,170 @@ int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t capacity return numOfRows + num; } -static void copyOneRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity, int32_t numOfRows, SDataRow row, +static void copyOneRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity, int32_t numOfRows, SMemRow row, int32_t numOfCols, STable* pTable, STSchema* pSchema) { char* pData = NULL; - // the schema version info is embeded in SDataRow + // the schema version info is embedded in SDataRow, and use latest schema version for SKVRow int32_t numOfRowCols = 0; if (pSchema == NULL) { - pSchema = tsdbGetTableSchemaByVersion(pTable, dataRowVersion(row)); + pSchema = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row)); numOfRowCols = schemaNCols(pSchema); } else { numOfRowCols = schemaNCols(pSchema); } - - int32_t i = 0, j = 0; - while(i < numOfCols && j < numOfRowCols) { - SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); - if (pSchema->columns[j].colId < pColInfo->info.colId) { - j++; - continue; - } - if (ASCENDING_TRAVERSE(pQueryHandle->order)) { - pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; - } else { - pData = (char*)pColInfo->pData + (capacity - numOfRows - 1) * pColInfo->info.bytes; + int32_t i = 0; + + if (isDataRow(row)) { + SDataRow dataRow = memRowDataBody(row); + int32_t j = 0; + while (i < numOfCols && j < numOfRowCols) { + SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); + if (pSchema->columns[j].colId < pColInfo->info.colId) { + j++; + continue; + } + + if (ASCENDING_TRAVERSE(pQueryHandle->order)) { + pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; + } else { + pData = (char*)pColInfo->pData + (capacity - numOfRows - 1) * pColInfo->info.bytes; + } + + if (pSchema->columns[j].colId == pColInfo->info.colId) { + void* value = + tdGetRowDataOfCol(dataRow, (int8_t)pColInfo->info.type, TD_DATA_ROW_HEAD_SIZE + pSchema->columns[j].offset); + switch (pColInfo->info.type) { + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + memcpy(pData, value, varDataTLen(value)); + break; + case TSDB_DATA_TYPE_NULL: + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + *(uint8_t*)pData = *(uint8_t*)value; + break; + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + *(uint16_t*)pData = *(uint16_t*)value; + break; + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + *(uint32_t*)pData = *(uint32_t*)value; + break; + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + *(uint64_t*)pData = *(uint64_t*)value; + break; + case TSDB_DATA_TYPE_FLOAT: + SET_FLOAT_PTR(pData, value); + break; + case TSDB_DATA_TYPE_DOUBLE: + SET_DOUBLE_PTR(pData, value); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + if (pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { + *(TSKEY*)pData = tdGetKey(*(TKEY*)value); + } else { + *(TSKEY*)pData = *(TSKEY*)value; + } + break; + default: + memcpy(pData, value, pColInfo->info.bytes); + } + + j++; + i++; + } else { // pColInfo->info.colId < pSchema->columns[j].colId, it is a NULL data + if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { + setVardataNull(pData, pColInfo->info.type); + } else { + setNull(pData, pColInfo->info.type, pColInfo->info.bytes); + } + i++; + } } + } else if (isKvRow(row)) { + SKVRow kvRow = memRowKvBody(row); + int32_t k = 0; + int32_t nKvRowCols = kvRowNCols(kvRow); - if (pSchema->columns[j].colId == pColInfo->info.colId) { - void* value = tdGetRowDataOfCol(row, (int8_t)pColInfo->info.type, TD_DATA_ROW_HEAD_SIZE + pSchema->columns[j].offset); - switch (pColInfo->info.type) { - case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_NCHAR: - memcpy(pData, value, varDataTLen(value)); - break; - case TSDB_DATA_TYPE_NULL: - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: - *(uint8_t *)pData = *(uint8_t *)value; - break; - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: - *(uint16_t *)pData = *(uint16_t *)value; - break; - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: - *(uint32_t *)pData = *(uint32_t *)value; - break; - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - *(uint64_t *)pData = *(uint64_t *)value; - break; - case TSDB_DATA_TYPE_FLOAT: - SET_FLOAT_PTR(pData, value); - break; - case TSDB_DATA_TYPE_DOUBLE: - SET_DOUBLE_PTR(pData, value); - break; - case TSDB_DATA_TYPE_TIMESTAMP: - if (pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { - *(TSKEY *)pData = tdGetKey(*(TKEY *)value); - } else { - *(TSKEY *)pData = *(TSKEY *)value; - } - break; - default: - memcpy(pData, value, pColInfo->info.bytes); + while (i < numOfCols && k < nKvRowCols) { + SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); + SColIdx* pColIdx = kvRowColIdxAt(kvRow, k); + + if (pColIdx->colId < pColInfo->info.colId) { + ++k; + continue; } - j++; - i++; - } else { // pColInfo->info.colId < pSchema->columns[j].colId, it is a NULL data + if (ASCENDING_TRAVERSE(pQueryHandle->order)) { + pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; + } else { + pData = (char*)pColInfo->pData + (capacity - numOfRows - 1) * pColInfo->info.bytes; + } + + if (pColIdx->colId == pColInfo->info.colId) { + // offset of pColIdx for SKVRow including the TD_KV_ROW_HEAD_SIZE + void* value = tdGetKvRowDataOfCol(kvRow, pColIdx->offset); + switch (pColInfo->info.type) { + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + memcpy(pData, value, varDataTLen(value)); + break; + case TSDB_DATA_TYPE_NULL: + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + *(uint8_t*)pData = *(uint8_t*)value; + break; + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + *(uint16_t*)pData = *(uint16_t*)value; + break; + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + *(uint32_t*)pData = *(uint32_t*)value; + break; + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + *(uint64_t*)pData = *(uint64_t*)value; + break; + case TSDB_DATA_TYPE_FLOAT: + SET_FLOAT_PTR(pData, value); + break; + case TSDB_DATA_TYPE_DOUBLE: + SET_DOUBLE_PTR(pData, value); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + if (pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { + *(TSKEY*)pData = tdGetKey(*(TKEY*)value); + } else { + *(TSKEY*)pData = *(TSKEY*)value; + } + break; + default: + memcpy(pData, value, pColInfo->info.bytes); + } + ++k; + ++i; + continue; + } + // If (pColInfo->info.colId < pColIdx->colId), it is NULL data if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { setVardataNull(pData, pColInfo->info.type); } else { setNull(pData, pColInfo->info.type, pColInfo->info.bytes); } - i++; + ++i; } + } else { + ASSERT(0); } - while (i < numOfCols) { // the remain columns are all null data + while (i < numOfCols) { // the remain columns are all null data SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); if (ASCENDING_TRAVERSE(pQueryHandle->order)) { pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; @@ -1550,7 +1632,6 @@ static void copyOneRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity, i++; } } - static void moveDataToFront(STsdbQueryHandle* pQueryHandle, int32_t numOfRows, int32_t numOfCols) { if (numOfRows == 0 || ASCENDING_TRAVERSE(pQueryHandle->order)) { return; @@ -1730,12 +1811,12 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* } else if (pCheckInfo->iter != NULL || pCheckInfo->iiter != NULL) { SSkipListNode* node = NULL; do { - SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update); + SMemRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update); if (row == NULL) { break; } - TSKEY key = dataRowKey(row); + TSKEY key = memRowKey(row); if ((key > pQueryHandle->window.ekey && ASCENDING_TRAVERSE(pQueryHandle->order)) || (key < pQueryHandle->window.ekey && !ASCENDING_TRAVERSE(pQueryHandle->order))) { break; @@ -1748,11 +1829,11 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* if ((key < tsArray[pos] && ASCENDING_TRAVERSE(pQueryHandle->order)) || (key > tsArray[pos] && !ASCENDING_TRAVERSE(pQueryHandle->order))) { - if (rv != dataRowVersion(row)) { - pSchema = tsdbGetTableSchemaByVersion(pTable, dataRowVersion(row)); - rv = dataRowVersion(row); - } - + if (rv != memRowVersion(row)) { + pSchema = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row)); + rv = memRowVersion(row); + } + copyOneRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, row, numOfCols, pTable, pSchema); numOfRows += 1; if (cur->win.skey == TSKEY_INITIAL_VAL) { @@ -1766,11 +1847,11 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* moveToNextRowInMem(pCheckInfo); } else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it if (pCfg->update) { - if (rv != dataRowVersion(row)) { - pSchema = tsdbGetTableSchemaByVersion(pTable, dataRowVersion(row)); - rv = dataRowVersion(row); + if (rv != memRowVersion(row)) { + pSchema = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row)); + rv = memRowVersion(row); } - + copyOneRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, row, numOfCols, pTable, pSchema); numOfRows += 1; if (cur->win.skey == TSKEY_INITIAL_VAL) { @@ -1820,8 +1901,10 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* * copy them all to result buffer, since it may be overlapped with file data block. */ if (node == NULL || - ((dataRowKey((SDataRow)SL_GET_NODE_DATA(node)) > pQueryHandle->window.ekey) && ASCENDING_TRAVERSE(pQueryHandle->order)) || - ((dataRowKey((SDataRow)SL_GET_NODE_DATA(node)) < pQueryHandle->window.ekey) && !ASCENDING_TRAVERSE(pQueryHandle->order))) { + ((memRowKey((SMemRow)SL_GET_NODE_DATA(node)) > pQueryHandle->window.ekey) && + ASCENDING_TRAVERSE(pQueryHandle->order)) || + ((memRowKey((SMemRow)SL_GET_NODE_DATA(node)) < pQueryHandle->window.ekey) && + !ASCENDING_TRAVERSE(pQueryHandle->order))) { // no data in cache or data in cache is greater than the ekey of time window, load data from file block if (cur->win.skey == TSKEY_INITIAL_VAL) { cur->win.skey = tsArray[pos]; @@ -2407,12 +2490,12 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int STSchema* pSchema = NULL; do { - SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update); + SMemRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update); if (row == NULL) { break; } - TSKEY key = dataRowKey(row); + TSKEY key = memRowKey(row); if ((key > maxKey && ASCENDING_TRAVERSE(pQueryHandle->order)) || (key < maxKey && !ASCENDING_TRAVERSE(pQueryHandle->order))) { tsdbDebug("%p key:%"PRIu64" beyond qrange:%"PRId64" - %"PRId64", no more data in buffer", pQueryHandle, key, pQueryHandle->window.skey, pQueryHandle->window.ekey); @@ -2425,9 +2508,9 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int } win->ekey = key; - if (rv != dataRowVersion(row)) { - pSchema = tsdbGetTableSchemaByVersion(pTable, dataRowVersion(row)); - rv = dataRowVersion(row); + if (rv != memRowVersion(row)) { + pSchema = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row)); + rv = memRowVersion(row); } copyOneRowFromMem(pQueryHandle, maxRowsToRead, numOfRows, row, numOfCols, pTable, pSchema); @@ -2544,7 +2627,7 @@ static bool loadCachedLastRow(STsdbQueryHandle* pQueryHandle) { SQueryFilePos* cur = &pQueryHandle->cur; - SDataRow pRow = NULL; + SMemRow pRow = NULL; TSKEY key = TSKEY_INITIAL_VAL; int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order)? 1:-1; @@ -2954,7 +3037,7 @@ bool tsdbGetExternalRow(TsdbQueryHandleT pHandle) { * if lastRow == NULL, return TSDB_CODE_TDB_NO_CACHE_LAST_ROW * else set pRes and return TSDB_CODE_SUCCESS and save lastKey */ -int32_t tsdbGetCachedLastRow(STable* pTable, SDataRow* pRes, TSKEY* lastKey) { +int32_t tsdbGetCachedLastRow(STable* pTable, SMemRow* pRes, TSKEY* lastKey) { int32_t code = TSDB_CODE_SUCCESS; TSDB_RLOCK_TABLE(pTable); @@ -2965,7 +3048,7 @@ int32_t tsdbGetCachedLastRow(STable* pTable, SDataRow* pRes, TSKEY* lastKey) { } if (pRes) { - *pRes = tdDataRowDup(pTable->lastRow); + *pRes = tdMemRowDup(pTable->lastRow); if (*pRes == NULL) { code = TSDB_CODE_TDB_OUT_OF_MEMORY; } @@ -3698,6 +3781,10 @@ static void* doFreeColumnInfoData(SArray* pColumnInfoData) { } static void* destroyTableCheckInfo(SArray* pTableCheckInfo) { + if (pTableCheckInfo == NULL) { + return NULL; + } + size_t size = taosArrayGetSize(pTableCheckInfo); for (int32_t i = 0; i < size; ++i) { STableCheckInfo* p = taosArrayGet(pTableCheckInfo, i); diff --git a/src/tsdb/tests/tsdbTests.cpp b/src/tsdb/tests/tsdbTests.cpp index ac254d6c34ecd152e28bb621348312b938fecd20..dc804856fdf1e288f2a70a2813639c1324f42851 100644 --- a/src/tsdb/tests/tsdbTests.cpp +++ b/src/tsdb/tests/tsdbTests.cpp @@ -55,10 +55,10 @@ static int insertData(SInsertInfo *pInfo) { for (int j = 0; j < schemaNCols(pInfo->pSchema); j++) { STColumn *pTCol = schemaColAt(pInfo->pSchema, j); if (j == 0) { // Just for timestamp - tdAppendColVal(row, (void *)(&start_time), pTCol->type, pTCol->bytes, pTCol->offset); + tdAppendColVal(row, (void *)(&start_time), pTCol->type, pTCol->offset); } else { // For int int val = 10; - tdAppendColVal(row, (void *)(&val), pTCol->type, pTCol->bytes, pTCol->offset); + tdAppendColVal(row, (void *)(&val), pTCol->type, pTCol->offset); } } pBlock->dataLen += dataRowLen(row); diff --git a/src/util/src/terror.c b/src/util/src/terror.c index 6cb508ebae38d16d781e2ae731c372eb398d5514..e36ab94844d205949f68f507f03572953d1092f4 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -109,11 +109,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_SQL_SYNTAX_ERROR, "Syntax error in SQL") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DB_NOT_SELECTED, "Database not specified or available") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_NAME, "Table does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_EXCEED_SQL_LIMIT, "SQL statement too long, check maxSQLLength config") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_FILE_EMPTY, "File is empty") // mnode TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, "Message not processed") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_IN_PROGRESS, "Message is progressing") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_NEED_REPROCESSED, "Messag need to be reprocessed") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_NEED_REPROCESSED, "Message need to be reprocessed") TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_RIGHTS, "Insufficient privilege for operation") TAOS_DEFINE_ERROR(TSDB_CODE_MND_APP_ERROR, "Unexpected generic error in mnode") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONNECTION, "Invalid message connection") @@ -183,6 +184,13 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, "Field does not exist" TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STABLE_NAME, "Super table does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG, "Invalid create table message") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_NAME, "Invalid func name") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_LEN, "Invalid func length") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_CODE, "Invalid func code") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_FUNC_ALREADY_EXIST, "Func already exists") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC, "Invalid func") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_BUFSIZE, "Invalid func bufSize") + TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_NOT_SELECTED, "Database not specified or available") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_ALREADY_EXIST, "Database already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION, "Invalid database options") @@ -269,6 +277,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_IN_EXEC, "Multiple retrieval of TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW, "Too many time window in query") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NOT_ENOUGH_BUFFER, "Query buffer limit has reached") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INCONSISTAN, "File inconsistance in replica") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_SYS_ERROR, "System error") // grant diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 842ded19a652fdfad7cb6b35c536f760ae866618..a88fee51d7faee65311b46404a72e9fe97407c8c 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -546,7 +546,6 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) { const uint32_t factor = 4; int32_t n = 1; - #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) while ((rand() % factor) == 0 && n <= pSkipList->maxLevel) { #else diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index 88c2a3369bb101ce6b7ae6d72fa1a7973ca732e4..c4d05b2d5a851ee4c2a8232095dd6ea5567213ab 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -219,8 +219,13 @@ static SKeyword keywordTable[] = { {"PARTITIONS", TK_PARTITIONS}, {"TOPIC", TK_TOPIC}, {"TOPICS", TK_TOPICS}, - {"COMPACT", TK_COMPACT}, - {"MODIFY", TK_MODIFY} + {"COMPACT", TK_COMPACT}, + {"MODIFY", TK_MODIFY}, + {"FUNCTION", TK_FUNCTION}, + {"FUNCTIONS", TK_FUNCTIONS}, + {"OUTPUTTYPE", TK_OUTPUTTYPE}, + {"AGGREGATE", TK_AGGREGATE}, + {"BUFSIZE", TK_BUFSIZE}, }; static const char isIdChar[] = { @@ -269,7 +274,7 @@ static int32_t tKeywordCode(const char* z, int n) { if (keywordHashTable == NULL) { return TK_ILLEGAL; } - + SKeyword** pKey = (SKeyword**)taosHashGet(keywordHashTable, key, n); return (pKey != NULL)? (*pKey)->type:TK_ID; } diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index 3964975e355db3ced1c86e28611ef202dd24d9e3..6bc009209be5788146e6d3f65439a266d7ce0522 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -231,7 +231,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pRead) { if (contLen != 0) { qinfo_t pQInfo = NULL; uint64_t qId = genQueryId(); - code = qCreateQueryInfo(pVnode->tsdb, pVnode->vgId, pQueryTableMsg, &pQInfo, &qId); + code = qCreateQueryInfo(pVnode->tsdb, pVnode->vgId, pQueryTableMsg, &pQInfo, qId); SQueryTableRsp *pRsp = (SQueryTableRsp *)rpcMallocCont(sizeof(SQueryTableRsp)); pRsp->code = code; diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index a7c418711de5bae2e1e98c90a72a1b2a9aa06d6f..743398d8344b8430a71633fe2455bca4e5ae1682 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -90,7 +90,7 @@ int32_t vnodeProcessWrite(void *vparam, void *wparam, int32_t qtype, void *rpara // forward to peers, even it is WAL/FWD, it shall be called to update version in sync int32_t syncCode = 0; - bool force = (pWrite == NULL ? false : pWrite->pHead.msgType != TSDB_MSG_TYPE_SUBMIT); + bool force = (pWrite == NULL ? false : pWrite->walHead.msgType != TSDB_MSG_TYPE_SUBMIT); syncCode = syncForwardToPeer(pVnode->sync, pHead, pWrite, qtype, force); if (syncCode < 0) { pHead->version = 0; @@ -237,7 +237,7 @@ static SVWriteMsg *vnodeBuildVWriteMsg(SVnodeObj *pVnode, SWalHead *pHead, int32 return NULL; } - int32_t size = sizeof(SVWriteMsg) + sizeof(SWalHead) + pHead->len; + int32_t size = sizeof(SVWriteMsg) + pHead->len; SVWriteMsg *pWrite = taosAllocateQitem(size); if (pWrite == NULL) { terrno = TSDB_CODE_VND_OUT_OF_MEMORY; @@ -248,7 +248,7 @@ static SVWriteMsg *vnodeBuildVWriteMsg(SVnodeObj *pVnode, SWalHead *pHead, int32 pWrite->rpcMsg = *pRpcMsg; } - memcpy(&pWrite->pHead, pHead, sizeof(SWalHead) + pHead->len); + memcpy(&pWrite->walHead, pHead, sizeof(SWalHead) + pHead->len); pWrite->pVnode = pVnode; pWrite->qtype = qtype; @@ -286,7 +286,7 @@ static int32_t vnodeWriteToWQueueImp(SVWriteMsg *pWrite) { } int32_t queued = atomic_add_fetch_32(&pVnode->queuedWMsg, 1); - int64_t queuedSize = atomic_add_fetch_64(&pVnode->queuedWMsgSize, pWrite->pHead.len); + int64_t queuedSize = atomic_add_fetch_64(&pVnode->queuedWMsgSize, pWrite->walHead.len); if (queued > MAX_QUEUED_MSG_NUM || queuedSize > MAX_QUEUED_MSG_SIZE) { int32_t ms = (queued / MAX_QUEUED_MSG_NUM) * 10 + 3; @@ -330,7 +330,7 @@ void vnodeFreeFromWQueue(void *vparam, SVWriteMsg *pWrite) { SVnodeObj *pVnode = vparam; if (pVnode) { int32_t queued = atomic_sub_fetch_32(&pVnode->queuedWMsg, 1); - int64_t queuedSize = atomic_sub_fetch_64(&pVnode->queuedWMsgSize, pWrite->pHead.len); + int64_t queuedSize = atomic_sub_fetch_64(&pVnode->queuedWMsgSize, pWrite->walHead.len); vTrace("vgId:%d, msg:%p, app:%p, free from vwqueue, queued:%d size:%" PRId64, pVnode->vgId, pWrite, pWrite->rpcMsg.ahandle, queued, queuedSize); diff --git a/src/wal/src/walMgmt.c b/src/wal/src/walMgmt.c index 55ab9b031beaa35da49523af21c581a5aae47e3b..9bd5cdf1750b106df9eed8c033c1adff91d9b8e5 100644 --- a/src/wal/src/walMgmt.c +++ b/src/wal/src/walMgmt.c @@ -36,9 +36,16 @@ static int32_t walInitObj(SWal *pWal); static void walFreeObj(void *pWal); int32_t walInit() { + int32_t code = 0; tsWal.refId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj); - int32_t code = walCreateThread(); + code = pthread_mutex_init(&tsWal.mutex, NULL); + if (code) { + wError("failed to init wal mutex since %s", tstrerror(code)); + return code; + } + + code = walCreateThread(); if (code != TSDB_CODE_SUCCESS) { wError("failed to init wal module since %s", tstrerror(code)); return code; @@ -51,6 +58,7 @@ int32_t walInit() { void walCleanUp() { walStopThread(); taosCloseRef(tsWal.refId); + pthread_mutex_destroy(&tsWal.mutex); wInfo("wal module is cleaned up"); } @@ -183,10 +191,15 @@ static void walFsyncAll() { } static void *walThreadFunc(void *param) { + int stop = 0; while (1) { walUpdateSeq(); walFsyncAll(); - if (tsWal.stop) break; + + pthread_mutex_lock(&tsWal.mutex); + stop = tsWal.stop; + pthread_mutex_unlock(&tsWal.mutex); + if (stop) break; } return NULL; @@ -209,7 +222,10 @@ static int32_t walCreateThread() { } static void walStopThread() { + pthread_mutex_lock(&tsWal.mutex); tsWal.stop = 1; + pthread_mutex_unlock(&tsWal.mutex); + if (taosCheckPthreadValid(tsWal.thread)) { pthread_join(tsWal.thread, NULL); } diff --git a/tests/examples/c/CMakeLists.txt b/tests/examples/c/CMakeLists.txt index 7f941b8c87a2c256a82aa37f9e937a41cd9a4c77..906ca2dd41c3fb222c816f49dd23af41cc81cffe 100644 --- a/tests/examples/c/CMakeLists.txt +++ b/tests/examples/c/CMakeLists.txt @@ -8,13 +8,13 @@ IF (TD_LINUX) ADD_EXECUTABLE(subscribe subscribe.c) TARGET_LINK_LIBRARIES(subscribe taos_static trpc tutil pthread ) ADD_EXECUTABLE(epoll epoll.c) - TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread ) + TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua) ENDIF () IF (TD_DARWIN) INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc) AUX_SOURCE_DIRECTORY(. SRC) ADD_EXECUTABLE(demo demo.c) - TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread ) + TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua) ADD_EXECUTABLE(epoll epoll.c) - TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread ) + TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua) ENDIF () diff --git a/tests/examples/lua/luaconnector.so b/tests/examples/lua/luaconnector.so new file mode 100755 index 0000000000000000000000000000000000000000..08bf6a6156aebe053132545193cd111fb436bc4b Binary files /dev/null and b/tests/examples/lua/luaconnector.so differ diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index ac22d3ee4aa3fa1eb3b5571b02720f0576d3464a..80d45fbc31ad45855cf131f24c2bd7bc12307033 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -352,7 +352,7 @@ python3 ./test.py -f alter/alter_debugFlag.py python3 ./test.py -f query/queryBetweenAnd.py python3 ./test.py -f tag_lite/alter_tag.py -python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py +# python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py python3 test.py -f tools/taosdemoAllTest/TD-4985/query-limit-offset.py python3 ./test.py -f tag_lite/drop_auto_create.py diff --git a/tests/pytest/query/nestquery_last_row.py b/tests/pytest/query/nestquery_last_row.py index a04cb173af25a5cb1b02cb7227f13426503d080e..3c4ada51744f620ca589266113acf1e3d8cfef43 100644 --- a/tests/pytest/query/nestquery_last_row.py +++ b/tests/pytest/query/nestquery_last_row.py @@ -160,22 +160,23 @@ class TDTestCase: tdSql.checkData(0,9,9.000000000) tdSql.checkData(0,10,'2020-09-13 20:26:40.009') + # incorrect result, not support nest > 2 sql = '''select last_row(*) from ((select * from table_0) union all (select * from table_1) union all (select * from table_2));''' - tdSql.query(sql) - tdSql.checkRows(1) - tdSql.checkData(0,1,self.num-1) - tdSql.checkData(0,2,self.num-1) - tdSql.checkData(0,3,self.num-1) - tdSql.checkData(0,4,self.num-1) - tdSql.checkData(0,5,'False') - tdSql.checkData(0,6,'binary.9') - tdSql.checkData(0,7,'nchar.9') - tdSql.checkData(0,8,9.00000) - tdSql.checkData(0,9,9.000000000) - tdSql.checkData(0,10,'2020-09-13 20:26:40.009') + tdSql.error(sql) + #tdSql.checkRows(1) + #tdSql.checkData(0,1,self.num-1) + #tdSql.checkData(0,2,self.num-1) + #tdSql.checkData(0,3,self.num-1) + #tdSql.checkData(0,4,self.num-1) + #tdSql.checkData(0,5,'False') + #tdSql.checkData(0,6,'binary.9') + #tdSql.checkData(0,7,'nchar.9') + #tdSql.checkData(0,8,9.00000) + #tdSql.checkData(0,9,9.000000000) + #tdSql.checkData(0,10,'2020-09-13 20:26:40.009') # bug 5055 # sql = '''select last_row(*) from @@ -189,18 +190,18 @@ class TDTestCase: ((select last_row(*) from table_0) union all (select last_row(*) from table_1) union all (select last_row(*) from table_2));''' - tdSql.query(sql) - tdSql.checkRows(1) - tdSql.checkData(0,1,self.num-1) - tdSql.checkData(0,2,self.num-1) - tdSql.checkData(0,3,self.num-1) - tdSql.checkData(0,4,self.num-1) - tdSql.checkData(0,5,'False') - tdSql.checkData(0,6,'binary.9') - tdSql.checkData(0,7,'nchar.9') - tdSql.checkData(0,8,9.00000) - tdSql.checkData(0,9,9.000000000) - tdSql.checkData(0,10,'2020-09-13 20:26:40.009') + tdSql.error(sql) + #tdSql.checkRows(1) + #tdSql.checkData(0,1,self.num-1) + #tdSql.checkData(0,2,self.num-1) + #tdSql.checkData(0,3,self.num-1) + #tdSql.checkData(0,4,self.num-1) + #tdSql.checkData(0,5,'False') + #tdSql.checkData(0,6,'binary.9') + #tdSql.checkData(0,7,'nchar.9') + #tdSql.checkData(0,8,9.00000) + #tdSql.checkData(0,9,9.000000000) + #tdSql.checkData(0,10,'2020-09-13 20:26:40.009') # bug 5055 # sql = '''select last_row(*) from @@ -214,18 +215,18 @@ class TDTestCase: ((select * from table_0 limit 5 offset 5) union all (select * from table_1 limit 5 offset 5) union all (select * from regular_table_1 limit 5 offset 5));''' - tdSql.query(sql) - tdSql.checkRows(1) - tdSql.checkData(0,1,self.num-1) - tdSql.checkData(0,2,self.num-1) - tdSql.checkData(0,3,self.num-1) - tdSql.checkData(0,4,self.num-1) - tdSql.checkData(0,5,'False') - tdSql.checkData(0,6,'binary.9') - tdSql.checkData(0,7,'nchar.9') - tdSql.checkData(0,8,9.00000) - tdSql.checkData(0,9,9.000000000) - tdSql.checkData(0,10,'2020-09-13 20:26:40.009') + tdSql.error(sql) + #tdSql.checkRows(1) + #tdSql.checkData(0,1,self.num-1) + #tdSql.checkData(0,2,self.num-1) + #tdSql.checkData(0,3,self.num-1) + #tdSql.checkData(0,4,self.num-1) + #tdSql.checkData(0,5,'False') + #tdSql.checkData(0,6,'binary.9') + #tdSql.checkData(0,7,'nchar.9') + #tdSql.checkData(0,8,9.00000) + #tdSql.checkData(0,9,9.000000000) + #tdSql.checkData(0,10,'2020-09-13 20:26:40.009') sql = '''select last_row(*) from @@ -260,4 +261,4 @@ class TDTestCase: tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/query/queryPerformance.py b/tests/pytest/query/queryPerformance.py index 742a3c2cd1907107c7cca54c7fb37862227b077f..2aa760624fcfdb511b92d511326df8938dc45c2d 100644 --- a/tests/pytest/query/queryPerformance.py +++ b/tests/pytest/query/queryPerformance.py @@ -73,10 +73,11 @@ class taosdemoQueryPerformace: sql = "select avg(f1), max(f2), min(f3) from meters where ts <= '2017-07-15 10:40:01.000' and ts <= '2017-07-15 14:00:40.000'" tableid = 8 cursor.execute("create table if not exists %s%d using %s tags(%d, \"%s\")" % (self.tbPerfix, tableid, self.stbName, tableid, sql)) - + sql = "select last(*) from meters" tableid = 9 cursor.execute("create table if not exists %s%d using %s tags(%d, '%s')" % (self.tbPerfix, tableid, self.stbName, tableid, sql)) + cursor.close() def query(self): diff --git a/tests/pytest/table/max_table_length.py b/tests/pytest/table/max_table_length.py index ec34f3008fccdb200e645183a5cfdf577fc27503..366e20456ddbf71eabe7ff64c8d0597c3d5b5f6e 100644 --- a/tests/pytest/table/max_table_length.py +++ b/tests/pytest/table/max_table_length.py @@ -42,7 +42,7 @@ class TDTestCase: print("==============step3") tdLog.info("check int & binary") - tdSql.error("create table anal2 (ts timestamp ,i binary(16371),j int)") + # tdSql.error("create table anal2 (ts timestamp ,i binary(16371),j int)") tdSql.execute("create table anal2 (ts timestamp ,i binary(16370),j int)") tdSql.execute("create table anal3 (ts timestamp ,i binary(16366), j int, k int)") diff --git a/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.csv b/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.csv new file mode 100755 index 0000000000000000000000000000000000000000..078c3b93dfb91e1e691da3c3da4d3df27d0eedb7 --- /dev/null +++ b/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.csv @@ -0,0 +1,10 @@ +0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +7,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +8,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +9,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, \ No newline at end of file diff --git a/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json b/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json new file mode 100755 index 0000000000000000000000000000000000000000..e2b15b83a7742c76159617ddd7b7e08103e53537 --- /dev/null +++ b/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json @@ -0,0 +1,112 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 10, + "thread_count_create_tbl": 10, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 10, + "num_of_records_per_req": 1, + "max_sql_len": 102400000, + "databases": [{ + "dbinfo": { + "name": "db", + "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": "stb_old", + "child_table_exists":"no", + "childtable_count": 10, + "childtable_prefix": "stb_old_", + "auto_create_table": "no", + "batch_create_tbl_num": 5, + "data_source": "sample", + "insert_mode": "taosc", + "insert_rows": 100, + "childtable_limit": 0, + "childtable_offset":0, + "multi_thread_write_one_tbl": "no", + "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": "./tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.csv", + "tags_file": "", + "columns": [{"type": "INT","count":4000}, {"type": "BINARY", "len": 16, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + },{ + "name": "stb_new", + "child_table_exists":"no", + "childtable_count": 10, + "childtable_prefix": "stb_new_", + "auto_create_table": "no", + "batch_create_tbl_num": 5, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 100, + "childtable_limit": 0, + "childtable_offset":0, + "multi_thread_write_one_tbl": "no", + "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": "./tools/taosdemoAllTest/sample.csv", + "tags_file": "", + "columns": [{"type": "DOUBLE","count":1020}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + },{ + "name": "stb_int", + "child_table_exists":"no", + "childtable_count": 10, + "childtable_prefix": "stb_int_", + "auto_create_table": "no", + "batch_create_tbl_num": 5, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 100, + "childtable_limit": 0, + "childtable_offset":0, + "multi_thread_write_one_tbl": "no", + "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": "./tools/taosdemoAllTest/sample.csv", + "tags_file": "", + "columns": [{"type": "int","count":1020}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py b/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py new file mode 100755 index 0000000000000000000000000000000000000000..b710e34d8c06c85fd9a1ba06763939e7c4fdcdfd --- /dev/null +++ b/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py @@ -0,0 +1,137 @@ +################################################################### +# 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 os +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + + +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): + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + binPath = buildPath+ "/build/bin/" + + # insert: create one or mutiple tables per sql and insert multiple rows per sql + # test case for https://jira.taosdata.com:18080/browse/TD-5213 + os.system("%staosdemo -f tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json -y " % binPath) + tdSql.execute("use db") + tdSql.query("select count (tbname) from stb_old") + tdSql.checkData(0, 0, 10) + + # tdSql.query("select * from stb_old") + # tdSql.checkRows(10) + # tdSql.checkCols(1024) + + # tdSql.query("select count (tbname) from stb_new") + # tdSql.checkData(0, 0, 10) + + # tdSql.query("select * from stb_new") + # tdSql.checkRows(10) + # tdSql.checkCols(4096) + + # tdLog.info("stop dnode to commit data to disk") + # tdDnodes.stop(1) + # tdDnodes.start(1) + + #regular table + sql = "create table tb(ts timestamp, " + for i in range(1022): + sql += "col%d binary(14), " % (i + 1) + sql += "col1023 binary(22))" + tdSql.execute(sql) + + for i in range(4): + sql = "insert into tb values(%d, " + for j in range(1022): + str = "'%s', " % self.get_random_string(14) + sql += str + sql += "'%s')" % self.get_random_string(22) + tdSql.execute(sql % (self.ts + i)) + + time.sleep(10) + tdSql.query("select count(*) from tb") + tdSql.checkData(0, 0, 4) + + tdDnodes.stop(1) + tdDnodes.start(1) + + time.sleep(1) + tdSql.query("select count(*) from tb") + tdSql.checkData(0, 0, 4) + + + sql = "create table tb1(ts timestamp, " + for i in range(4094): + sql += "col%d binary(14), " % (i + 1) + sql += "col4095 binary(22))" + tdSql.execute(sql) + + for i in range(4): + sql = "insert into tb1 values(%d, " + for j in range(4094): + str = "'%s', " % self.get_random_string(14) + sql += str + sql += "'%s')" % self.get_random_string(22) + tdSql.execute(sql % (self.ts + i)) + + time.sleep(10) + tdSql.query("select count(*) from tb1") + tdSql.checkData(0, 0, 4) + + tdDnodes.stop(1) + tdDnodes.start(1) + + time.sleep(1) + tdSql.query("select count(*) from tb1") + tdSql.checkData(0, 0, 4) + + + + #os.system("rm -rf tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py.sql") + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/tools/taosdemoPerformance.py b/tests/pytest/tools/taosdemoPerformance.py index 90d2c52c15bfc9b5d8c72f3eaa5719f08da19367..fb7458898405d986fce8ecab4272c10b3831653a 100644 --- a/tests/pytest/tools/taosdemoPerformance.py +++ b/tests/pytest/tools/taosdemoPerformance.py @@ -19,7 +19,6 @@ import json from util.log import tdLog from util.sql import tdSql - class taosdemoPerformace: def __init__(self, commitID, dbName): self.commitID = commitID @@ -124,6 +123,7 @@ class taosdemoPerformace: def insertData(self): tdSql.prepare() + buildPath = self.getBuildPath() if (buildPath == ""): tdLog.exit("taosdemo not found!") diff --git a/tests/pytest/tools/taosdumpTest.py b/tests/pytest/tools/taosdumpTest.py index b2c9eb3ec148cd5f28311131e2f07e15de330521..0dfc42f331b1a1c59d71268985d6a72d4d652856 100644 --- a/tests/pytest/tools/taosdumpTest.py +++ b/tests/pytest/tools/taosdumpTest.py @@ -105,7 +105,6 @@ class TDTestCase: # 6--days,7--keep0,keep1,keep, 12--block, isCommunity = self.checkCommunity() - print("iscommunity: %d" % isCommunity) for i in range(len(dbresult)): if dbresult[i][0] == 'db': diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index a485276e018e80c83ec6a1d34e4d597b85118a2a..a3470b1763e30b8c6c6baa7b897de40910a84743 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -1132,4 +1132,19 @@ if $data92 != t1 then return -1 endi +print =========================>TD-5190 +sql select stddev(f1) from st1 where ts>'2021-07-01 1:1:1' and ts<'2021-07-30 00:00:00' interval(1d) fill(NULL); +if $rows != 29 then + return -1 +endi + +if $data00 != @21-07-01 00:00:00.000@ then + return -1 +endi + +if $data01 != NULL then + return -1 +endi + + sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s)); diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim index d7f06769a8bc2afe3c2f95acc16953ddd3b188da..fcd9d49fe555ae749da0fcd799e1866a8a05f656 100644 --- a/tests/script/general/parser/testSuite.sim +++ b/tests/script/general/parser/testSuite.sim @@ -12,7 +12,7 @@ run general/parser/create_tb.sim run general/parser/dbtbnameValidate.sim run general/parser/fill.sim run general/parser/fill_stb.sim -run general/parser/fill_us.sim +#run general/parser/fill_us.sim # run general/parser/first_last.sim run general/parser/import_commit1.sim run general/parser/import_commit2.sim @@ -39,7 +39,6 @@ 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 @@ -61,5 +60,9 @@ run general/parser/slimit_alter_tags.sim run general/parser/binary_escapeCharacter.sim run general/parser/between_and.sim run general/parser/last_cache.sim +run general/parser/slimit_alter_tags.sim +run general/parser/udf.sim +run general/parser/udf_dll.sim +run general/parser/udf_dll_stable.sim run general/parser/nestquery.sim run general/parser/precision_ns.sim diff --git a/tests/script/general/parser/udf.sim b/tests/script/general/parser/udf.sim new file mode 100644 index 0000000000000000000000000000000000000000..c048a7c37a82b8591f60c209cf49cc40bdfd10f1 --- /dev/null +++ b/tests/script/general/parser/udf.sim @@ -0,0 +1,637 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 2 +system sh/exec.sh -n dnode1 -s start +system sh/prepare_udf.sh + +sleep 100 +sql connect +print ======================== dnode1 start + +sql create function n01 as '/tmp/normal' outputtype int; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n01 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != INT then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n01; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + +sql create function n02 as '/tmp/normal' outputtype bool; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n02 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != BOOL then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n02; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + + +sql create function n03 as '/tmp/normal' outputtype TINYINT; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n03 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != TINYINT then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n03; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + + + +sql create function n04 as '/tmp/normal' outputtype SMALLINT; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n04 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != SMALLINT then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n04; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + + + + +sql create function n05 as '/tmp/normal' outputtype INT; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n05 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != INT then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n05; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + + + + + + + + +sql create function n06 as '/tmp/normal' outputtype BIGINT; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n06 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != BIGINT then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n06; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + + + + + + +sql create function n07 as '/tmp/normal' outputtype FLOAT; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n07 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != FLOAT then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n07; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + + + + + +sql create function n08 as '/tmp/normal' outputtype DOUBLE; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n08 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != DOUBLE then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n08; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + + + + + +sql create function n09 as '/tmp/normal' outputtype BINARY; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n09 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != BINARY(0) then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n09; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + +sql create function n10 as '/tmp/normal' outputtype BINARY(10); +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n10 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != BINARY(10) then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n10; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + +sql create function n11 as '/tmp/normal' outputtype TIMESTAMP; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n11 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != TIMESTAMP then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n11; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + +sql create function n12 as '/tmp/normal' outputtype NCHAR; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n12 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != NCHAR(0) then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n12; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + +sql create function n13 as '/tmp/normal' outputtype NCHAR(10); +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n13 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != NCHAR(10) then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n13; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + + +sql create function n14 as '/tmp/normal' outputtype TINYINT UNSIGNED; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n14 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n14; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + +sql create function n15 as '/tmp/normal' outputtype SMALLINT UNSIGNED; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n15 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n15; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + +sql create function n16 as '/tmp/normal' outputtype INT UNSIGNED; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n16 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n16; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + + +sql create function n17 as '/tmp/normal' outputtype BIGINT UNSIGNED; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n17 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n17; + +sql show functions; +if $rows != 0 then + return -1 +endi + + +sql create aggregate function n18 as '/tmp/normal' outputtype BIGINT UNSIGNED; +sql show functions; +if $rows != 1 then + return -1 +endi + + +if $data00 != n18 then + return -1 +endi +if $data01 != /tmp/normal then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data05 != 5 then + return -1 +endi + +sql drop function n18; + +sql show functions; +if $rows != 0 then + return -1 +endi + + + +sql create function t01 as '/tmp/normal' outputtype INT; +sql_error create function t01 as '/tmp/normal' outputtype SMALLINT; +sql drop function t01; +sql create function t01 as '/tmp/normal' outputtype INT; +sql create function t02 as '/tmp/normal' outputtype SMALLINT; +sql show functions; +if $rows != 2 then + return -1 +endi + + + + + + +sql_error create function e1 as '/tmp/normal'; +sql_error create function e2 as '/tmp/normal' outputtype; +sql_error create function e3 as '/tmp/normal' a; +sql_error create function e4 as '/tmp/normal' outputtype a; +sql_error create function e5 as '/tmp/normal' outputtype bool int; +sql_error create function as '/tmp/normal' outputtype; +sql_error create function e6 as '/tmp/empty' outputtype int; +sql_error create function e7 as '/tmp/big' outputtype int; +sql_error create function e8 as '/tmp/noexistfile' outputtype int; +sql_error create function e0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 as '/tmp/normal' outputtype int; +sql_error create function e9 as outputtype int; + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/udf_dll.sim b/tests/script/general/parser/udf_dll.sim new file mode 100644 index 0000000000000000000000000000000000000000..0f9436762adb645785ddcf9a4abaf4a5be810a34 --- /dev/null +++ b/tests/script/general/parser/udf_dll.sim @@ -0,0 +1,494 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 2 +system sh/exec.sh -n dnode1 -s start +system sh/prepare_udf.sh + +sleep 100 +sql connect +print ======================== dnode1 start + +sql create function add_one as '/tmp/add_one.so' outputtype int; +sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int; +sql show functions; +if $rows != 2 then + return -1 +endi + +sql create database db; +sql use db; +sql create table tb1 (ts timestamp, f1 int, f2 bool, f3 binary(10)); +sql insert into tb1 values ('2021-03-23 17:17:19.660', 1, true, 'tb1-1'); +sql insert into tb1 values ('2021-03-23 19:23:28.595', 2, false, 'tb1-2'); +sql insert into tb1 values ('2021-03-23 19:33:39.070', 3, true, 'tb1-3'); +sql insert into tb1 values ('2021-03-23 19:34:37.670', 4, false, 'tb1-4'); +sql insert into tb1 values ('2021-03-24 19:08:06.609', 5, true, 'tb1-5'); +sql insert into tb1 values ('2021-03-24 19:26:38.231', 6, false, 'tb1-6'); +sql insert into tb1 values ('2021-03-25 10:03:17.688', 7, true, 'tb1-7'); + +sql select add_one(f1) from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi + + +sql select sum_double(f1) from tb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 56 then + return -1 +endi + + +sql select ts,add_one(f1),f1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data12 != 2 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data22 != 3 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data32 != 4 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data42 != 5 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data52 != 6 then + return -1 +endi +if $data60 != @21-03-25 10:03:17.688@ then + return -1 +endi +if $data61 != 8 then + return -1 +endi +if $data62 != 7 then + return -1 +endi + + + + +sql select add_one(f1),add_one(f1) from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi +if $data61 != 8 then + return -1 +endi + + +sql select add_one(f1)+1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi + + +sql select sum_double(f1)+1 from tb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 57.000000000 then + return -1 +endi + + +sql select add_one(f1)+1,f1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data31 != 4 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data41 != 5 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi +if $data61 != 7 then + return -1 +endi + + +sql select sum_double(f1) from tb1 interval (10a); +if $rows != 7 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.590@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 8 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.600@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.230@ then + return -1 +endi +if $data51 != 12 then + return -1 +endi +if $data60 != @21-03-25 10:03:17.680@ then + return -1 +endi +if $data61 != 14 then + return -1 +endi + +sql select ts,add_one(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000"; +if $rows != 6 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi + +sql select sum_double(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h); +if $rows != 3 then + return -1 +endi + +if $data00 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data11 != 18 then + return -1 +endi +if $data20 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data21 != 22 then + return -1 +endi + + +sql select sum_double(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h) fill(value,999); +if $rows != 28 then + return -1 +endi + +sql_error select add_one(f1) from tb1 group by f1; + +sql select sum_double(f1) from tb1 group by f1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 4 then + return -1 +endi +if $data20 != 6 then + return -1 +endi +if $data30 != 8 then + return -1 +endi +if $data40 != 10 then + return -1 +endi +if $data50 != 12 then + return -1 +endi +if $data60 != 14 then + return -1 +endi + +sql select sum_double(f1) from tb1 interval (1h) order by ts desc; +if $rows != 4 then + return -1 +endi + +if $data00 != @21-03-25 10:00:00.000@ then + return -1 +endi +if $data01 != 14 then + return -1 +endi +if $data10 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data11 != 22 then + return -1 +endi +if $data20 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data21 != 18 then + return -1 +endi +if $data30 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data31 != 2 then + return -1 +endi + + +sql select add_one(f1) from tb1 limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi + + +sql select sum_double(f1) from tb1 interval (1d) limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != @21-03-23 00:00:00.000@ then + return -1 +endi +if $data01 != 20 then + return -1 +endi +if $data10 != @21-03-24 00:00:00.000@ then + return -1 +endi +if $data11 != 22 then + return -1 +endi + + +sql_error select ts,sum_double(f1),f1 from tb1; +sql_error select add_one(f1),count(f1) from tb1; +sql_error select sum_double(f1),count(f1) from tb1; +sql_error select add_one(f1),top(f1,3) from tb1; +sql_error select add_one(f1) from tb1 interval(10a); + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/udf_dll_stable.sim b/tests/script/general/parser/udf_dll_stable.sim new file mode 100644 index 0000000000000000000000000000000000000000..b8da57467e912ff27f4fbda7226c75e089f04808 --- /dev/null +++ b/tests/script/general/parser/udf_dll_stable.sim @@ -0,0 +1,1163 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1 +system sh/exec.sh -n dnode1 -s start +system sh/prepare_udf.sh + +sleep 100 +sql connect +print ======================== dnode1 start + +sql create function add_one as '/tmp/add_one.so' outputtype int; +sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int; +sql show functions; +if $rows != 2 then + return -1 +endi + +sql create database db; +sql use db; +sql create stable stb1 (ts timestamp, f1 int, f2 bool, f3 binary(10)) tags(id1 int); +sql create table tb1 using stb1 tags(1); +sql insert into tb1 values ('2021-03-23 17:17:19.660', 1, true, 'tb1-1'); +sql insert into tb1 values ('2021-03-23 19:23:28.595', 2, false, 'tb1-2'); +sql insert into tb1 values ('2021-03-23 19:33:39.070', 3, true, 'tb1-3'); +sql insert into tb1 values ('2021-03-23 19:34:37.670', 4, false, 'tb1-4'); +sql insert into tb1 values ('2021-03-24 19:08:06.609', 5, true, 'tb1-5'); +sql insert into tb1 values ('2021-03-24 19:26:38.231', 6, false, 'tb1-6'); +sql insert into tb1 values ('2021-03-25 10:03:17.688', 7, true, 'tb1-7'); +sql create table tb2 using stb1 tags(2); +sql create table tb3 using stb1 tags(3); +sql create table tb4 using stb1 tags(4); +sql create table tb5 using stb1 tags(5); +sql create table tb6 using stb1 tags(6); +sql create table tb7 using stb1 tags(7); +sql create table tb8 using stb1 tags(8); +sql create table tb9 using stb1 tags(9); +sql insert into tb2 values ('2021-03-03 17:17:19.660', 1, true, 'tb2-1'); +sql insert into tb2 values ('2021-03-13 19:23:28.595', 2, false, 'tb2-2'); +sql insert into tb3 values ('2021-03-23 19:33:39.070', 3, true, 'tb3-1'); +sql insert into tb3 values ('2021-03-24 19:34:37.670', 4, false, 'tb3-2'); +sql insert into tb5 values ('2021-03-25 19:08:06.609', 1, true, 'tb5-1'); +sql insert into tb5 values ('2021-04-01 19:26:38.231', 2, false, 'tb5-2'); +sql insert into tb5 values ('2021-04-08 10:03:17.688', 3, true, 'tb5-3'); +sql insert into tb6 values ('2021-04-08 11:03:17.688', 1, true, 'tb6-1'); +sql insert into tb6 values ('2021-04-08 12:03:17.688', 2, true, 'tb6-2'); +sql insert into tb9 values ('2021-04-08 16:03:17.688', 4, true, 'tb9-1'); + +sql select add_one(f1) from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi + + +sql select sum_double(f1) from tb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 56 then + return -1 +endi + + +sql select ts,add_one(f1),f1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data12 != 2 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data22 != 3 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data32 != 4 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data42 != 5 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data52 != 6 then + return -1 +endi +if $data60 != @21-03-25 10:03:17.688@ then + return -1 +endi +if $data61 != 8 then + return -1 +endi +if $data62 != 7 then + return -1 +endi + + + + +sql select add_one(f1),add_one(f1) from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi +if $data61 != 8 then + return -1 +endi + + +sql select add_one(f1)+1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi + + +sql select sum_double(f1)+1 from tb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 57.000000000 then + return -1 +endi + + +sql select add_one(f1)+1,f1 from tb1; +if $rows != 7 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data31 != 4 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data41 != 5 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi +if $data61 != 7 then + return -1 +endi + + +sql select sum_double(f1) from tb1 interval (10a); +if $rows != 7 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.590@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 8 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.600@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.230@ then + return -1 +endi +if $data51 != 12 then + return -1 +endi +if $data60 != @21-03-25 10:03:17.680@ then + return -1 +endi +if $data61 != 14 then + return -1 +endi + +sql select ts,add_one(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000"; +if $rows != 6 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi + +sql select sum_double(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h); +if $rows != 3 then + return -1 +endi + +if $data00 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data11 != 18 then + return -1 +endi +if $data20 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data21 != 22 then + return -1 +endi + + +sql select sum_double(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h) fill(value,999); +if $rows != 28 then + return -1 +endi + +sql_error select add_one(f1) from tb1 group by f1; + +sql select sum_double(f1) from tb1 group by f1; +if $rows != 7 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 4 then + return -1 +endi +if $data20 != 6 then + return -1 +endi +if $data30 != 8 then + return -1 +endi +if $data40 != 10 then + return -1 +endi +if $data50 != 12 then + return -1 +endi +if $data60 != 14 then + return -1 +endi + +sql select sum_double(f1) from tb1 interval (1h) order by ts desc; +if $rows != 4 then + return -1 +endi + +if $data00 != @21-03-25 10:00:00.000@ then + return -1 +endi +if $data01 != 14 then + return -1 +endi +if $data10 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data11 != 22 then + return -1 +endi +if $data20 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data21 != 18 then + return -1 +endi +if $data30 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data31 != 2 then + return -1 +endi + + +sql select add_one(f1) from tb1 limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi + + +sql select sum_double(f1) from tb1 interval (1d) limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != @21-03-23 00:00:00.000@ then + return -1 +endi +if $data01 != 20 then + return -1 +endi +if $data10 != @21-03-24 00:00:00.000@ then + return -1 +endi +if $data11 != 22 then + return -1 +endi + + +sql_error select ts,sum_double(f1),f1 from tb1; +sql_error select add_one(f1),count(f1) from tb1; +sql_error select sum_double(f1),count(f1) from tb1; +sql_error select add_one(f1),top(f1,3) from tb1; +sql_error select add_one(f1) from tb1 interval(10a); + + +sql select add_one(f1) from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi +if $data70 != 2 then + return -1 +endi +if $data80 != 3 then + return -1 +endi +if $data90 != 4 then + return -1 +endi + + +sql select sum_double(f1) from stb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 102 then + return -1 +endi + + +sql select ts,add_one(f1),f1 from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data12 != 2 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data22 != 3 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data32 != 4 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data42 != 5 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data52 != 6 then + return -1 +endi +if $data60 != @21-03-25 10:03:17.688@ then + return -1 +endi +if $data61 != 8 then + return -1 +endi +if $data62 != 7 then + return -1 +endi + + + + +sql select add_one(f1),add_one(f1) from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != 7 then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data60 != 8 then + return -1 +endi +if $data61 != 8 then + return -1 +endi + +sql select add_one(f1)+1 from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi + + +sql select sum_double(f1)+1 from stb1; +if $rows != 1 then + return -1 +endi + +if $data00 != 103.000000000 then + return -1 +endi + + +sql select add_one(f1)+1,f1 from stb1; +if $rows != 17 then + return -1 +endi + +if $data00 != 3.000000000 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != 6.000000000 then + return -1 +endi +if $data31 != 4 then + return -1 +endi +if $data40 != 7.000000000 then + return -1 +endi +if $data41 != 5 then + return -1 +endi +if $data50 != 8.000000000 then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != 9.000000000 then + return -1 +endi +if $data61 != 7 then + return -1 +endi + + +sql select sum_double(f1) from stb1 interval (10a); +if $rows != 16 then + return -1 +endi + +if $data00 != @21-03-03 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-13 19:23:28.590@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data20 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data30 != @21-03-23 19:23:28.590@ then + return -1 +endi +if $data31 != 4 then + return -1 +endi +if $data40 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data41 != 12 then + return -1 +endi +if $data50 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data51 != 8 then + return -1 +endi +if $data60 != @21-03-24 19:08:06.600@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-03-24 19:26:38.230@ then + return -1 +endi +if $data71 != 12 then + return -1 +endi +if $data80 != @21-03-24 19:34:37.670@ then + return -1 +endi +if $data81 != 8 then + return -1 +endi +if $data90 != @21-03-25 10:03:17.680@ then + return -1 +endi +if $data91 != 14 then + return -1 +endi + + +sql select ts,add_one(f1) from stb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000"; +if $rows != 8 then + return -1 +endi + +if $data00 != @21-03-23 17:17:19.660@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:23:28.595@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-03-23 19:34:37.670@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != @21-03-24 19:08:06.609@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-03-24 19:26:38.231@ then + return -1 +endi +if $data51 != 7 then + return -1 +endi +if $data60 != @21-03-23 19:33:39.070@ then + return -1 +endi +if $data61 != 4 then + return -1 +endi +if $data70 != @21-03-24 19:34:37.670@ then + return -1 +endi +if $data71 != 5 then + return -1 +endi + +sql select sum_double(f1) from stb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h); +if $rows != 3 then + return -1 +endi + +if $data00 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data11 != 24 then + return -1 +endi +if $data20 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data21 != 30 then + return -1 +endi + + +sql select sum_double(f1) from stb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h) fill(value,999); +if $rows != 28 then + return -1 +endi +if $data00 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 18:00:00.000@ then + return -1 +endi +if $data11 != 999 then + return -1 +endi +if $data20 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data21 != 24 then + return -1 +endi + +sql_error select add_one(f1) from stb1 group by f1; + +sql select sum_double(f1) from stb1 group by f1; +if $rows != 7 then + return -1 +endi + +if $data00 != 8 then + return -1 +endi +if $data10 != 16 then + return -1 +endi +if $data20 != 18 then + return -1 +endi +if $data30 != 24 then + return -1 +endi +if $data40 != 10 then + return -1 +endi +if $data50 != 12 then + return -1 +endi +if $data60 != 14 then + return -1 +endi + +sql select sum_double(f1) from stb1 interval (1h) order by ts desc; +if $rows != 12 then + return -1 +endi + +if $data00 != @21-04-08 16:00:00.000@ then + return -1 +endi +if $data01 != 8 then + return -1 +endi +if $data10 != @21-04-08 12:00:00.000@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data20 != @21-04-08 11:00:00.000@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data30 != @21-04-08 10:00:00.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-04-01 19:00:00.000@ then + return -1 +endi +if $data41 != 4 then + return -1 +endi +if $data50 != @21-03-25 19:00:00.000@ then + return -1 +endi +if $data51 != 2 then + return -1 +endi +if $data60 != @21-03-25 10:00:00.000@ then + return -1 +endi +if $data61 != 14 then + return -1 +endi +if $data70 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data71 != 30 then + return -1 +endi +if $data80 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data81 != 24 then + return -1 +endi +if $data90 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data91 != 2 then + return -1 +endi + + +sql select add_one(f1) from stb1 limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi + + +sql select sum_double(f1) from stb1 interval (1d) limit 2; +if $rows != 2 then + return -1 +endi + +if $data00 != @21-03-03 00:00:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-13 00:00:00.000@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi + +sql select sum_double(f1) from stb1 group by id1; + +if $rows != 6 then + return -1 +endi + +if $data00 != 56 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data10 != 6 then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data20 != 14 then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != 12 then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data40 != 6 then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != 8 then + return -1 +endi +if $data51 != 9 then + return -1 +endi + + +sql select sum_double(f1) from tb1 where ts>="2021-03-23 17:00:00.000" and ts<="2021-03-24 20:00:00.000" interval (1h) sliding (30m); +if $rows != 7 then + return -1 +endi + +if $data00 != @21-03-23 16:30:00.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-03-23 17:00:00.000@ then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data20 != @21-03-23 18:30:00.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-03-23 19:00:00.000@ then + return -1 +endi +if $data31 != 18 then + return -1 +endi +if $data40 != @21-03-23 19:30:00.000@ then + return -1 +endi +if $data41 != 14 then + return -1 +endi +if $data50 != @21-03-24 18:30:00.000@ then + return -1 +endi +if $data51 != 22 then + return -1 +endi +if $data60 != @21-03-24 19:00:00.000@ then + return -1 +endi +if $data61 != 22 then + return -1 +endi + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT + + + + + + diff --git a/tests/script/sh/abs_max.c b/tests/script/sh/abs_max.c new file mode 100644 index 0000000000000000000000000000000000000000..cd8ba0ff15c135bdf845af57e39d5085c0fbcb20 --- /dev/null +++ b/tests/script/sh/abs_max.c @@ -0,0 +1,88 @@ +#include +#include +#include + +typedef struct SUdfInit{ + int maybe_null; /* 1 if function can return NULL */ + int decimals; /* for real functions */ + long long length; /* For string functions */ + char *ptr; /* free pointer for function data */ + int const_item; /* 0 if result is independent of arguments */ +} SUdfInit; + + +#define TSDB_DATA_INT_NULL 0x80000000L +#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L + +void abs_max(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput, + int* numOfOutput, short otype, short obytes, SUdfInit* buf) { + int i; + int r = 0; + printf("abs_max input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); + if (itype == 5) { + r=*(long *)dataOutput; + *numOfOutput=0; + + for(i=0;i r) { + r = v; + } + } + + *(long *)dataOutput=r; + + printf("abs_max out, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput); + } +} + + + +void abs_max_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf) { + int i; + int r = 0; + printf("abs_max_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p\n", dataOutput, *dataOutput, *numOfOutput, buf); + *numOfOutput=1; + printf("abs_max finalize, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput); +} + +void abs_max_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) { + int r = 0; + + if (numOfRows > 0) { + r = *((long *)data); + } + printf("abs_max_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf); + for (int i = 1; i < numOfRows; ++i) { + printf("abs_max_merge %d - %ld\n", i, *((long *)data + i)); + if (*((long*)data + i) > r) { + r= *((long*)data + i); + } + } + + *(long*)dataOutput=r; + if (numOfRows > 0) { + *numOfOutput=1; + } else { + *numOfOutput=0; + } + + printf("abs_max_merge, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput); +} + + +int abs_max_init(SUdfInit* buf) { + printf("abs_max init\n"); + return 0; +} + + +void abs_max_destroy(SUdfInit* buf) { + printf("abs_max destroy\n"); +} + diff --git a/tests/script/sh/add_one.c b/tests/script/sh/add_one.c new file mode 100644 index 0000000000000000000000000000000000000000..e12cf8f26f6ddad67f9f7b091c033de46a3f6f50 --- /dev/null +++ b/tests/script/sh/add_one.c @@ -0,0 +1,33 @@ +#include +#include +#include + +typedef struct SUdfInit{ + int maybe_null; /* 1 if function can return NULL */ + int decimals; /* for real functions */ + long long length; /* For string functions */ + char *ptr; /* free pointer for function data */ + int const_item; /* 0 if result is independent of arguments */ +} SUdfInit; + +void add_one(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBUf, char* tsOutput, + int* numOfOutput, short otype, short obytes, SUdfInit* buf) { + int i; + int r = 0; + printf("add_one input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); + if (itype == 4) { + for(i=0;i> $TAOS_CFG +echo " " >> $TAOS_CFG echo "masterIp $MASTER_IP" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG diff --git a/tests/script/sh/demo.c b/tests/script/sh/demo.c new file mode 100644 index 0000000000000000000000000000000000000000..23d217444892e5bd8dc1c83b569dc22616c42e78 --- /dev/null +++ b/tests/script/sh/demo.c @@ -0,0 +1,112 @@ +#include +#include +#include + +typedef struct SUdfInit{ + int maybe_null; /* 1 if function can return NULL */ + int decimals; /* for real functions */ + long long length; /* For string functions */ + char *ptr; /* free pointer for function data */ + int const_item; /* 0 if result is independent of arguments */ +} SUdfInit; + +typedef struct SDemo{ + double sum; + int num; + short otype; +}SDemo; + +#define FLOAT_NULL 0x7FF00000 // it is an NAN +#define DOUBLE_NULL 0x7FFFFF0000000000L // it is an NAN + + +void demo(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput, + int* numOfOutput, short otype, short obytes, SUdfInit* buf) { + int i; + double r = 0; + SDemo *p = (SDemo *)interBuf; + SDemo *q = (SDemo *)dataOutput; + printf("demo input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, interBUf:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, interBuf, tsOutput, numOfOutput, buf); + + for(i=0;isum += r*r; + } + + p->otype = otype; + p->num += numOfRows; + + q->sum = p->sum; + q->num = p->num; + q->otype = p->otype; + + *numOfOutput=1; + + printf("demo out, sum:%f, num:%d, numOfOutput:%d\n", p->sum, p->num, *numOfOutput); +} + + +void demo_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) { + int i; + SDemo *p = (SDemo *)data; + SDemo res = {0}; + printf("demo_merge input data:%p, rows:%d, dataoutput:%p, numOfOutput:%p, buf:%p\n", data, numOfRows, dataOutput, numOfOutput, buf); + + for(i=0;isum * p->sum; + res.num += p->num; + p++; + } + + p->sum = res.sum; + p->num = res.num; + + *numOfOutput=1; + + printf("demo out, sum:%f, num:%d, numOfOutput:%d\n", p->sum, p->num, *numOfOutput); +} + + + +void demo_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf) { + SDemo *p = (SDemo *)interBuf; + printf("demo_finalize interbuf:%p, numOfOutput:%p, buf:%p, sum:%f, num:%d\n", interBuf, numOfOutput, buf, p->sum, p->num); + if (p->otype == 6) { + if (p->num != 30000) { + *(unsigned int *)dataOutput = FLOAT_NULL; + } else { + *(float *)dataOutput = (float)(p->sum / p->num); + } + printf("finalize values:%f\n", *(float *)dataOutput); + } else if (p->otype == 7) { + if (p->num != 30000) { + *(unsigned long long *)dataOutput = DOUBLE_NULL; + } else { + *(double *)dataOutput = (double)(p->sum / p->num); + } + printf("finalize values:%f\n", *(double *)dataOutput); + } + + *numOfOutput=1; + + printf("demo finalize, numOfOutput:%d\n", *numOfOutput); +} + + +int demo_init(SUdfInit* buf) { + printf("demo init\n"); + return 0; +} + + +void demo_destroy(SUdfInit* buf) { + printf("demo destroy\n"); +} + diff --git a/tests/script/sh/demo.lua b/tests/script/sh/demo.lua new file mode 100644 index 0000000000000000000000000000000000000000..c5e5582fc30b58db30a5b18faa4ccfd0a5f656d0 --- /dev/null +++ b/tests/script/sh/demo.lua @@ -0,0 +1,43 @@ +funcName = "test" + +global = {} + +function test_init() + return global +end + +function test_add(rows, ans, key) + t = {} + t["sum"] = 0.0 + t["num"] = 0 + for i=1, #rows do + t["sum"] = t["sum"] + rows[i] * rows[i] + end + t["num"] = #rows + + + if (ans[key] ~= nil) + then + ans[key]["sum"] = ans[key]["sum"] + t["sum"] + ans[key]["num"] = ans[key]["num"] + t["num"] + else + ans[key] = t + end + + return ans; +end + +function test_finalize(ans, key) + local ret = 0.0 + + if (ans[key] ~= nil and ans[key]["num"] == 30000) + then + ret = ans[key]["sum"]/ans[key]["num"] + ans[key]["sum"] = 0.0 + ans[key]["num"] = 0 + else + ret = inf + end + + return ret, ans +end diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 9b61a33d45f69a200b3f364f1553bdec5a3f52b5..cde27d7dc3fa00258d9d9d50ee3dfc82f858b138 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -2,16 +2,18 @@ echo "Executing deploy.sh" -if [ $# != 4 ]; then +if [ $# != 4 ]; then echo "argument list need input : " echo " -n nodeName" echo " -i nodePort" exit 1 fi +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` NODE_NAME= NODE= -while getopts "n:i:" arg +while getopts "n:i:" arg do case $arg in n) @@ -29,7 +31,7 @@ done SCRIPT_DIR=`dirname $0` cd $SCRIPT_DIR/../ SCRIPT_DIR=`pwd` -echo "SCRIPT_DIR: $SCRIPT_DIR" +echo "SCRIPT_DIR: $SCRIPT_DIR" IN_TDINTERNAL="community" if [[ "$SCRIPT_DIR" == *"$IN_TDINTERNAL"* ]]; then @@ -41,10 +43,16 @@ fi TAOS_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec-default.sh b/tests/script/sh/exec-default.sh index 1c84a6b10ed3f958e096d32eda727441ff2591da..f648315c6745f63cfba9eb06ecfd53a9ccef1fed 100755 --- a/tests/script/sh/exec-default.sh +++ b/tests/script/sh/exec-default.sh @@ -1,6 +1,6 @@ #!/bin/bash -# if [ $# != 4 || $# != 5 ]; then +# if [ $# != 4 || $# != 5 ]; then # echo "argument list need input : " # echo " -n nodeName" # echo " -s start/stop" @@ -8,10 +8,12 @@ # exit 1 # fi +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` NODE_NAME= EXEC_OPTON= CLEAR_OPTION="false" -while getopts "n:s:u:x:ct" arg +while getopts "n:s:u:x:ct" arg do case $arg in n) @@ -52,10 +54,16 @@ fi TAOS_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec-no-random-fail.sh b/tests/script/sh/exec-no-random-fail.sh index 2bd0a64923f73df010e40f427d40cb9e212480d7..e01b18a8e6bb0d4631a28c64c6accd57bceb9076 100755 --- a/tests/script/sh/exec-no-random-fail.sh +++ b/tests/script/sh/exec-no-random-fail.sh @@ -1,6 +1,6 @@ #!/bin/bash -# if [ $# != 4 || $# != 5 ]; then +# if [ $# != 4 || $# != 5 ]; then # echo "argument list need input : " # echo " -n nodeName" # echo " -s start/stop" @@ -8,10 +8,12 @@ # exit 1 # fi +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` NODE_NAME= EXEC_OPTON= CLEAR_OPTION="false" -while getopts "n:s:u:x:ct" arg +while getopts "n:s:u:x:ct" arg do case $arg in n) @@ -52,10 +54,16 @@ fi TAOS_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build @@ -78,23 +86,23 @@ if [ -f "$TAOS_FLAG" ]; then EXE_DIR=/usr/local/bin/taos fi -if [ "$CLEAR_OPTION" = "clear" ]; then - echo rm -rf $MGMT_DIR $TSDB_DIR +if [ "$CLEAR_OPTION" = "clear" ]; then + echo rm -rf $MGMT_DIR $TSDB_DIR rm -rf $TSDB_DIR rm -rf $MGMT_DIR fi -if [ "$EXEC_OPTON" = "start" ]; then +if [ "$EXEC_OPTON" = "start" ]; then echo "ExcuteCmd:" $EXE_DIR/taosd -c $CFG_DIR - - if [ "$SHELL_OPTION" = "true" ]; then + + if [ "$SHELL_OPTION" = "true" ]; then TT=`date +%s` mkdir ${LOG_DIR}/${TT} - nohup valgrind --log-file=${LOG_DIR}/${TT}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 & + nohup valgrind --log-file=${LOG_DIR}/${TT}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 & else - nohup $EXE_DIR/taosd -c $CFG_DIR --random-file-fail-factor 0 > /dev/null 2>&1 & + nohup $EXE_DIR/taosd -c $CFG_DIR --random-file-fail-factor 0 > /dev/null 2>&1 & fi - + else #relative path RCFG_DIR=sim/$NODE_NAME/cfg @@ -110,6 +118,6 @@ else fi sleep 1 PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` - done + done fi diff --git a/tests/script/sh/exec-random-fail.sh b/tests/script/sh/exec-random-fail.sh index 3761498859591188799d1ad3814ed3b01372269d..1f31899e3ac26861fc1860d10cb0a4899ff7bf36 100755 --- a/tests/script/sh/exec-random-fail.sh +++ b/tests/script/sh/exec-random-fail.sh @@ -1,6 +1,6 @@ #!/bin/bash -# if [ $# != 4 || $# != 5 ]; then +# if [ $# != 4 || $# != 5 ]; then # echo "argument list need input : " # echo " -n nodeName" # echo " -s start/stop" @@ -8,10 +8,12 @@ # exit 1 # fi +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` NODE_NAME= EXEC_OPTON= CLEAR_OPTION="false" -while getopts "n:s:u:x:ct" arg +while getopts "n:s:u:x:ct" arg do case $arg in n) @@ -52,10 +54,16 @@ fi TAOS_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index 1c84a6b10ed3f958e096d32eda727441ff2591da..80b8cda428da72daf55fc6e0d4c47867ce191d35 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -1,6 +1,6 @@ #!/bin/bash -# if [ $# != 4 || $# != 5 ]; then +# if [ $# != 4 || $# != 5 ]; then # echo "argument list need input : " # echo " -n nodeName" # echo " -s start/stop" @@ -8,10 +8,13 @@ # exit 1 # fi +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` + NODE_NAME= EXEC_OPTON= CLEAR_OPTION="false" -while getopts "n:s:u:x:ct" arg +while getopts "n:s:u:x:ct" arg do case $arg in n) @@ -52,10 +55,16 @@ fi TAOS_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec_tarbitrator.sh b/tests/script/sh/exec_tarbitrator.sh index 496b3e4ed6011ace67e5f33330d99bf02e611673..e985bd65856025b2db8dfef724fdc652b2a03392 100755 --- a/tests/script/sh/exec_tarbitrator.sh +++ b/tests/script/sh/exec_tarbitrator.sh @@ -1,13 +1,15 @@ #!/bin/bash -# if [ $# != 2 || $# != 3 ]; then +# if [ $# != 2 || $# != 3 ]; then # echo "argument list need input : " # echo " -s start/stop" # exit 1 # fi +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` EXEC_OPTON= -while getopts "n:s:u:x:ct" arg +while getopts "n:s:u:x:ct" arg do case $arg in n) @@ -49,10 +51,16 @@ fi TAOS_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/move_dnode.sh b/tests/script/sh/move_dnode.sh index d6dc4bc3eb24fe094067cffcb51a7c335a512a94..d3650c18ad0f49185ce1e1268273b8a44e3cdc14 100755 --- a/tests/script/sh/move_dnode.sh +++ b/tests/script/sh/move_dnode.sh @@ -2,10 +2,13 @@ echo "Executing move_dnode.sh" +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` + SCRIPT_DIR=`dirname $0` cd $SCRIPT_DIR/../ SCRIPT_DIR=`pwd` -echo "SCRIPT_DIR: $SCRIPT_DIR" +echo "SCRIPT_DIR: $SCRIPT_DIR" IN_TDINTERNAL="community" if [[ "$SCRIPT_DIR" == *"$IN_TDINTERNAL"* ]]; then @@ -17,10 +20,16 @@ fi TAOS_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/mv_old_data.sh b/tests/script/sh/mv_old_data.sh index 606ee171f1e6b8605fd19d542e0b0dce5dfdda28..3f4be6714fd757ee60d21ee97be5d411e3f95bdd 100755 --- a/tests/script/sh/mv_old_data.sh +++ b/tests/script/sh/mv_old_data.sh @@ -2,10 +2,13 @@ echo "Executing mv_old_data.sh" +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` + SCRIPT_DIR=`dirname $0` cd $SCRIPT_DIR/../ SCRIPT_DIR=`pwd` -echo "SCRIPT_DIR: $SCRIPT_DIR" +echo "SCRIPT_DIR: $SCRIPT_DIR" IN_TDINTERNAL="community" if [[ "$SCRIPT_DIR" == *"$IN_TDINTERNAL"* ]]; then @@ -17,10 +20,16 @@ fi TAOS_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/prepare_udf.sh b/tests/script/sh/prepare_udf.sh new file mode 100644 index 0000000000000000000000000000000000000000..ecfc53660ee33c65540638354c4f44119b76034d --- /dev/null +++ b/tests/script/sh/prepare_udf.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +echo -n "hello" > /tmp/normal +echo -n "" > /tmp/empty +dd if=/dev/zero bs=3584 of=/tmp/big count=1 + +rm -rf /tmp/sum_double.so /tmp/add_one.so + +gcc -g -O0 -fPIC -shared sh/sum_double.c -o /tmp/sum_double.so +gcc -g -O0 -fPIC -shared sh/add_one.c -o /tmp/add_one.so +gcc -g -O0 -fPIC -shared sh/demo.c -o /tmp/demo.so +gcc -g -O0 -fPIC -shared sh/abs_max.c -o /tmp/abs_max.so diff --git a/tests/script/sh/scalar_demo.lua b/tests/script/sh/scalar_demo.lua new file mode 100644 index 0000000000000000000000000000000000000000..cecaff90b01534316821b0a025a3fc66f9b219cf --- /dev/null +++ b/tests/script/sh/scalar_demo.lua @@ -0,0 +1,14 @@ +funcName = "test" + +ans = 1 + +function test_init() + return ans +end + +function test_add(rows, ans) + for i=1, #rows do + rows[i] = rows[i] + ans + end + return rows +end diff --git a/tests/script/sh/stop_dnodes.sh b/tests/script/sh/stop_dnodes.sh index 1a6e7153c39d1be84b2d8a4bf13338564d685a2f..430f39901e62415e780999171139fcd961cdd54c 100755 --- a/tests/script/sh/stop_dnodes.sh +++ b/tests/script/sh/stop_dnodes.sh @@ -1,24 +1,36 @@ #!/bin/sh +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` + PID=`ps -ef|grep /usr/bin/taosd | grep -v grep | awk '{print $2}'` -if [ -n "$PID" ]; then - echo systemctl stop taosd - systemctl stop taosd +if [ -n "$PID" ]; then + echo systemctl stop taosd + systemctl stop taosd fi - + PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` while [ -n "$PID" ]; do - echo kill -9 $PID - pkill -9 taosd - fuser -k -n tcp 6030 + echo kill -9 $PID + pkill -9 taosd + echo "Killing processes locking on port 6030" + if [[ "$OS_TYPE" != "Darwin" ]]; then + fuser -k -n tcp 6030 + else + lsof -nti:6030 | xargs kill -9 + fi PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` done PID=`ps -ef|grep -w tarbitrator | grep -v grep | awk '{print $2}'` while [ -n "$PID" ]; do - echo kill -9 $PID - pkill -9 tarbitrator - fuser -k -n tcp 6040 + echo kill -9 $PID + pkill -9 tarbitrator + if [[ "$OS_TYPE" != "Darwin" ]]; then + fuser -k -n tcp 6040 + else + lsof -nti:6040 | xargs kill -9 + fi PID=`ps -ef|grep -w tarbitrator | grep -v grep | awk '{print $2}'` done diff --git a/tests/script/sh/sum_double.c b/tests/script/sh/sum_double.c new file mode 100644 index 0000000000000000000000000000000000000000..b4b0b81a0677b7de102dcfd228d09e53e3edda62 --- /dev/null +++ b/tests/script/sh/sum_double.c @@ -0,0 +1,84 @@ +#include +#include +#include + +typedef struct SUdfInit{ + int maybe_null; /* 1 if function can return NULL */ + int decimals; /* for real functions */ + long long length; /* For string functions */ + char *ptr; /* free pointer for function data */ + int const_item; /* 0 if result is independent of arguments */ +} SUdfInit; + +#define TSDB_DATA_INT_NULL 0x80000000L + + +void sum_double(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput, + int* numOfOutput, short otype, short obytes, SUdfInit* buf) { + int i; + int r = 0; + printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); + if (itype == 4) { + r=*(int *)dataOutput; + *numOfOutput=0; + + for(i=0;iptr)=*(int*)dataOutput*2; + *(int*)dataOutput=*(int*)(buf->ptr); + printf("sum_double finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); +} + +void sum_double_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) { + int r = 0; + int sum = 0; + + printf("sum_double_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf); + for (int i = 0; i < numOfRows; ++i) { + printf("sum_double_merge %d - %d\n", i, *((int*)data + i)); + sum +=*((int*)data + i); + } + + *(int*)dataOutput+=sum; + if (numOfRows > 0) { + *numOfOutput=1; + } else { + *numOfOutput=0; + } + + printf("sum_double_merge, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); +} + + +int sum_double_init(SUdfInit* buf) { + buf->maybe_null=1; + buf->ptr = malloc(sizeof(int)); + printf("sum_double init\n"); + return 0; +} + + +void sum_double_destroy(SUdfInit* buf) { + free(buf->ptr); + printf("sum_double destroy\n"); +} + diff --git a/tests/script/test.sh b/tests/script/test.sh index a092a38a2d9491b49b64c80a42c74ebdd41236f3..29a15db4dc953818afa6de9abb3f4f8edc42173d 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -1,8 +1,8 @@ #!/bin/bash ################################################## -# -# Do simulation test +# +# Do simulation test # ################################################## @@ -14,6 +14,8 @@ RELEASE=0 ASYNC=0 VALGRIND=0 UNIQUE=0 +UNAME_BIN=`which uname` +OS_TYPE=`$UNAME_BIN` while getopts "f:avu" arg do case $arg in @@ -51,10 +53,16 @@ fi TOP_DIR=`pwd` TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +if [[ "$OS_TYPE" != "Darwin" ]]; then + cut_opt="--field=" +else + cut_opt="-f " +fi + if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2` + BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TOP_DIR/$BIN_DIR/build @@ -117,7 +125,7 @@ echo "wal 0" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG echo "enableCoreFile 1" >> $TAOS_CFG -echo " " >> $TAOS_CFG +echo " " >> $TAOS_CFG ulimit -n 600000 ulimit -c unlimited